47 var
$TEMPLATEFILE=
"/etc/alternc/templates/awstats/awstats.template.conf";
59 'title' => _(
"Web Statistics"),
60 'ico' =>
'images/stat.png',
61 'link' =>
'aws_list.php',
73 return array(
"aws"=>
"Awstats Web Statistics");
82 return array(
"aws"=>_(
"The stats module allows any user to ask for statistics about his web site. Statistics are web pages generated daily based on the visits of the day before. Awstats is the soft used to produce those stats. The statistics are then protected by a login and a password."));
98 $msg->log(
"aws",
"get_list");
100 $db->query(
"SELECT id, hostname FROM aws WHERE uid='$cuid' ORDER BY hostname;");
101 if (
$db->num_rows()) {
102 while (
$db->next_record()) {
105 "hostname"=>
$db->f(
"hostname")
110 $db->query(
"SELECT login FROM aws_access WHERE id='".$v[
"id"].
"';");
112 while (
$db->next_record()) {
113 $u.=
$db->f(
"login").
" ";
117 "hostname"=>$v[
"hostname"],
140 $msg->log(
"aws",
"get_stats_details",
$id);
141 $db->query(
"SELECT id, hostname, hostaliases, public FROM aws WHERE uid='$cuid' AND id='$id';");
142 if (
$db->num_rows()) {
145 $hostname=
$db->f(
"hostname");
146 $hostaliases=
$db->f(
"hostaliases");
147 $public=
$db->f(
"public");
148 $db->query(
"SELECT login FROM aws_access WHERE id='$id';");
150 while (
$db->next_record()) {
151 $u.=
$db->f(
"login").
" ";
155 "hostname"=>$hostname,
157 "hostaliases"=>$hostaliases,
161 $msg->raise(
'Error',
"aws",_(
"This statistic does not exist"));
175 $db->query(
"SELECT sd.domaine, sd.sub, dt.name, dt.description FROM sub_domaines sd, domaines_type dt WHERE compte='$cuid' AND lower(sd.type) = lower(dt.name) AND dt.only_dns = false ORDER BY domaine,sub;");
176 while (
$db->next_record()) {
179 "hostname"=>
$db->f(
"sub").
".".
$db->f(
"domaine"),
180 "type"=>
$db->f(
"name"),
181 "desc"=>
$db->f(
"description")
185 "hostname"=>
$db->f(
"domaine"),
186 "type"=>
$db->f(
"name"),
187 "desc"=>
$db->f(
"description")
203 $db->query(
"SELECT domaine FROM domaines WHERE compte='$cuid' ORDER BY domaine;");
204 while (
$db->next_record()) {
205 $r[]=
$db->f(
"domaine");
223 if ($current==
$val)
$c=
" selected=\"selected\"";
else $c=
"";
224 echo
"<option$c>$val</option>";
239 $ho=
$val[
"hostname"];
241 if ($current==$ho)
$c=
" selected=\"selected\"";
else $c=
"";
255 $msg->log(
"aws",
"check_host_available",$current);
260 if ($current==
$val[
"hostname"]) {
261 $msg->raise(
'Alert',
"aws",_(
"Host already managed by awstats!"));
279 $db->query(
"SELECT hostaliases FROM aws WHERE uid='$cuid' and id='$id' ORDER by hostaliases;");
280 while (
$db->next_record()) {
281 $r[]=
$db->f(
"hostaliases");
298 if (is_array($users)) {
299 foreach($users as $v) {
303 $db->query(
"UPDATE aws SET hostaliases='$hostaliases', public='$public' where id='$id';");
321 $msg->log(
"aws",
"delete_stats",
$id);
322 $db->query(
"SELECT hostname FROM aws WHERE id='$id' and uid='$cuid';");
323 if (!
$db->num_rows()) {
324 $msg->raise(
'Error',
"aws",_(
"This statistic does not exist"));
328 $hostname=
$db->f(
"hostname");
331 $db->query(
"DELETE FROM aws WHERE id='$id'");
332 $action->del($this->CACHEDIR. DIRECTORY_SEPARATOR . $hostname . DIRECTORY_SEPARATOR);
347 function add_stats($hostname,$users=
"", $hostaliases,$public) {
349 $msg->log(
"aws",
"add_stats",$hostname);
354 $hosts[]=
$val[
"hostname"];
357 if (!in_array($hostname,$hosts) || $hostname==
"") {
358 $msg->raise(
'Error',
"aws",_(
"This hostname does not exist (Domain name)"));
363 if (is_array($hostaliases)) {
364 foreach($hostaliases as $ho) {
365 if (!in_array($ho,$hosts) || $hostname==
"") {
366 $msg->raise(
'Error',
"aws",_(
"This hostname does not exist (Hostaliases)"));
373 if ($quota->cancreate(
"aws")) {
374 $db->query(
"INSERT INTO aws (hostname,uid,hostaliases,public) VALUES ('$hostname','$cuid','$ha','$public')");
376 if (is_array($users)) {
377 foreach($users as $v) {
383 mkdir($this->CACHEDIR.
"/".$hostname,0777);
386 $msg->raise(
'Alert',
"aws",_(
"Your stat quota is over..."));
395 $msg->log(
"aws",
"list_login");
396 $db->query(
"SELECT login FROM aws_users WHERE uid='$cuid';");
398 if (!
$db->next_record()) {
399 $msg->raise(
'Info',
"aws",_(
"No user currently defined"));
404 }
while (
$db->next_record());
412 $msg->log(
"aws",
"list_allowed_login");
413 $db->query(
"SELECT u.login,a.id FROM aws_users u LEFT JOIN aws_access a ON a.id='$id' AND a.login=u.login WHERE u.uid='$cuid';");
415 if (!
$db->next_record()) {
419 $res[]=array(
"login"=>
$db->f(
"login"),
"selected"=>(
$db->f(
"id")));
420 }
while (
$db->next_record());
427 $db->query(
"SELECT public FROM aws WHERE id='$id' and uid='$cuid';");
428 if (
$db->num_rows()) {
430 $pub=
$db->f(
"public");
442 $msg->log(
"aws",
"list_login");
443 $db->query(
"SELECT login FROM aws_users WHERE uid='$cuid' AND login='$login';");
444 if (!
$db->next_record()) {
455 $msg->log(
"aws",
"del_login");
457 $msg->raise(
'Error',
"aws",_(
"Login does not exist"));
460 $db->query(
"DELETE FROM aws_users WHERE uid='$cuid' AND login='$login';");
461 $db->query(
"DELETE FROM aws_access WHERE uid='$cuid' AND login='$login';");
470 $msg->log(
"aws",
"add_login");
476 $msg->raise(
'Error',
"aws",_(
"Login already exist"));
480 if (is_callable(array($admin,
"checkPolicy"))) {
481 if (!$admin->checkPolicy(
"aws",
$login, $pass)) {
487 $db->query(
"INSERT INTO aws_users (uid,login,pass) VALUES ('$cuid','$login','$pass');");
495 $msg->log(
"aws",
"change_pass");
498 $msg->raise(
'Error',
"aws",_(
"Login incorrect"));
502 $msg->raise(
'Error',
"aws",_(
"Login does not exists"));
506 if (is_callable(array($admin,
"checkPolicy"))) {
507 if (!$admin->checkPolicy(
"aws",
$login, $pass)) {
512 $db->query(
"UPDATE aws_users SET pass='$pass' WHERE login='$login';");
520 $msg->log(
"aws",
"allow_login");
523 $msg->raise(
'Error',
"aws",_(
"Login incorrect"));
527 $msg->raise(
'Error',
"aws",_(
"Login does not exist"));
530 $db->query(
"SELECT id FROM aws WHERE id='$id' AND uid='$cuid'");
531 if (!
$db->next_record()) {
532 $msg->raise(
'Error',
"aws",_(
"The requested statistic does not exist."));
535 $db->query(
"SELECT login FROM aws_access WHERE id='$id' AND login='$login'");
536 if (
$db->next_record()) {
537 $msg->raise(
'Error',
"aws",_(
"This login is already allowed for this statistics."));
540 $db->query(
"INSERT INTO aws_access (uid,id,login) VALUES ('$cuid','$id','$login');");
556 $msg->log(
"aws",
"delete_allowed_login");
558 $db->query(
"SELECT id FROM aws WHERE id='$id' AND uid='$cuid'");
559 if (!
$db->next_record()) {
560 $msg->raise(
'Error',
"aws",_(
"The requested statistic does not exist."));
563 $db->query(
"DELETE FROM aws_access WHERE id='$id';");
575 $msg->log(
"aws",
"deny_login");
578 $msg->raise(
'Error',
"aws",_(
"Login incorrect"));
582 $msg->raise(
'Error',
"aws",_(
"Login does not exists"));
585 $db->query(
"SELECT id FROM aws WHERE id='$id' AND uid='$cuid'");
586 if (!
$db->next_record()) {
587 $msg->raise(
'Error',
"aws",_(
"The requested statistic does not exist."));
590 $db->query(
"SELECT login FROM aws_access WHERE id='$id' AND login='$login'");
591 if (!
$db->next_record()) {
592 $msg->raise(
'Error',
"aws",_(
"This login is already denied for this statistics."));
595 $db->query(
"DELETE FROM aws_access WHERE id='$id' AND login='$login';");
607 $msg->log(
"aws",
"del_member");
608 $db->query(
"SELECT * FROM aws WHERE uid='$cuid';");
610 while (
$db->next_record()) {
611 $t[]=
$db->f(
"hostname");
613 $db->query(
"DELETE FROM aws WHERE uid='$cuid';");
617 $db->query(
"DELETE FROM aws_access WHERE uid='$cuid'");
618 $db->query(
"DELETE FROM aws_users WHERE uid='$cuid';");
630 $msg->log(
"aws",
"alternc_del_domain",
$dom);
632 $db->query(
"SELECT id,hostname FROM aws WHERE uid='$cuid' AND (hostname='$dom' OR hostname like '%.$dom')");
634 while (
$db->next_record()) {
635 $t[]=array(
$db->f(
"hostname"),
$db->f(
"id"));
638 $db->query(
"DELETE FROM aws WHERE uid='$cuid' AND hostname='".
$i[0].
"';");
639 $db->query(
"DELETE FROM aws_access WHERE uid='$cuid' AND id='".
$i[1].
"';");
653 $msg->log(
"aws",
"get_quota");
654 $db->query(
"SELECT COUNT(*) AS cnt FROM aws WHERE uid='$cuid'");
655 $q=Array(
"name"=>
"aws",
"description"=>_(
"Awstats"),
"used"=>0);
656 if (
$db->next_record()) {
657 $q[
'used']=
$db->f(
"cnt");
676 if (!in_array($prefix,
$r)) {
677 $msg->raise(
'Error',
"aws",_(
"prefix not allowed."));
680 if (!preg_match(
'/^[0-9a-z_-]*$/', $postfix)){
681 $msg->raise(
'Error',
"aws", _(
"There are forbidden characters in the login (only A-Z 0-9 _ and - are allowed)"));
694 if (!preg_match(
'/^[._a-z0-9-]*$/', $hostname)){
695 $msg->raise(
'Error',
"aws",_(
"Hostname is incorrect"));
698 $action->del($this->CONFDIR. DIRECTORY_SEPARATOR .
"awstats.".$hostname.
".conf");
709 $s=@implode(
"",file($this->TEMPLATEFILE));
711 $msg->raise(
'Error',
"aws",_(
"Problem to create the configuration"));
715 $db->query(
"SELECT * FROM aws WHERE id='$id';");
717 $db->query(
"SELECT * FROM aws WHERE id='$id' AND uid='$cuid';");
719 if (!
$db->num_rows()) {
720 $msg->raise(
'Error',
"aws",_(
"This statistic does not exist"));
725 $hostname=
$db->f(
"hostname");
726 $hostaliases=
$db->f(
"hostaliases");
727 $public=
$db->f(
"public");
728 $db->query(
"SELECT login FROM membres WHERE uid = '$uid'");
731 $db->query(
"SELECT login FROM aws_access WHERE id='$id';");
733 while (
$db->next_record()) {
734 $users.=
$db->f(
"login").
" ";
737 $replace_vars = array(
740 '%%ALTERNC_LOGS%%' => $L_ALTERNC_LOGS,
741 '%%PUBLIC%%' => $public,
742 '%%HOSTNAME%%' => $hostname,
743 '%%HOSTALIASES%%' => $hostaliases,
744 '%%USERS%%' => $users,
746 foreach ($replace_vars as $k=>$v){
747 $s=str_replace($k,$v,$s);
750 $f=fopen($this->CONFDIR.
"/awstats.".$hostname.
".conf",
"wb");
751 fputs(
$f,$s,strlen($s));
761 $f=@fopen($this->HTAFILE,
"wb");
763 $db->query(
"SELECT login,pass FROM aws_users;");
764 while (
$db->next_record()) {
765 fputs(
$f,
$db->f(
"login").
":".
$db->f(
"pass").
"\n");
770 $msg->raise(
'Error',
"aws", _(
"Problem to edit file %s"), $this->HTAFILE);
784 $msg->log(
"aws",
"export");
786 $db->query(
"SELECT login,pass FROM aws_users WHERE uid='$cuid';");
787 while (
$db->next_record()) {
788 $str.=
" <user><login>".$db->Record[
"login"].
"</login><pass hash=\"des\">".
$db->Record[
"pass"].
"</pass></user>\n";
791 $db->query(
"SELECT id, hostname FROM aws WHERE uid='$cuid' ORDER BY hostname;");
792 while (
$db->next_record()) {
793 $r[
$db->Record[
"id"]]=
$db->Record[
"hostname"];
796 $str.=
" <domain>\n <name>".$host.
"</name>\n";
797 $db->query(
"SELECT login FROM aws_access WHERE id='$id';");
798 while (
$db->next_record()) {
799 $str.=
" <user>".$db->Record[
"login"].
"</user>\n";
801 $str.=
" </domain>\n";
813 $salt = substr(str_shuffle(
"abcdefghijklmnopqrstuvwxyz0123456789"), 0, 8);
814 $len = strlen($plainpasswd);
815 $text = $plainpasswd.
'$apr1$'.$salt;
816 $bin = pack(
"H32", md5($plainpasswd.$salt.$plainpasswd));
817 for(
$i =
$len;
$i > 0;
$i -= 16) { $text .= substr($bin, 0, min(16,
$i)); }
818 for(
$i =
$len;
$i > 0;
$i >>= 1) { $text .= (
$i & 1) ? chr(0) : $plainpasswd{0}; }
819 $bin = pack(
"H32", md5($text));
820 for(
$i = 0;
$i < 1000;
$i++) {
821 $new = (
$i & 1) ? $plainpasswd : $bin;
822 if (
$i % 3) $new .= $salt;
823 if (
$i % 7) $new .= $plainpasswd;
824 $new .= (
$i & 1) ? $bin : $plainpasswd;
825 $bin = pack(
"H32", md5($new));
827 for (
$i = 0;
$i < 5;
$i++) {
830 if ($j == 16) $j = 5;
831 $tmp = $bin[
$i].$bin[$k].$bin[$j].$tmp;
833 $tmp = chr(0).chr(0).$bin[11].$tmp;
834 $tmp = strtr(strrev(substr(base64_encode($tmp), 2)),
835 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
836 "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
837 return "$".
"apr1".
"$".$salt.
"$".$tmp;
This class manage awstats statistic sets.
_delconf($hostname)
Delete the awstats configuration file for a statistic set.
$TEMPLATEFILE
Where is the template for conf files : @access private.
crypt_apr1_md5($plainpasswd)
from http://php.net/crypt#73619
hook_quota_get()
This function is called when we are asked to compute the used quota for a service.
alternc_password_policy()
Password kind used in this class (hook for admin class)
delete_allowed_login($id, $noconf=0)
alternc_export()
Exports all the aws related information for an account.
add_stats($hostname, $users="", $hostaliases, $public)
Create a new statistic set.
deny_login($login, $id, $noconf=0)
alternc_del_domain($dom)
This function is called on each class when a domain name is uninstalled.
prefix_list()
Returns the list of prefixes that can be used on current account.
delete_stats($id)
Delete a statistic set.
check_host_available($current)
Check if hosts is already used by awstats of available for this member.
put_stats_details($id, $users, $hostaliases, $public)
Edit a statistic set (change allowed user list)
get_stats_details($id)
Return an array with the details for 1 statistic set.
get_list()
Returns an array with all the statistics of a member.
host_list()
Return the list of domains / subdomains allowed for this member with the type (MX,...
select_prefix_list($current)
Echoes <option> tags of all the domains hosted on the account + the login of the account They can be ...
$CONFDIR
Where are the awstats configuration files : @access private.
alternc_module_description()
Name of the module function.
change_pass($login, $pass)
_createconf($id, $nochk=0)
Create a configuration file for a statistic set.
login_exists($login, $exists=1)
get_hostaliases($id)
Return the hostaliases list with an id.
allow_login($login, $id, $noconf=0)
select_host_list($current)
Draw options for a select html code with the list of allowed and availables domains for this member.
foreach($domaines_user as $domaine) $t
if(!isset($is_include)) if(! $key &&! $crt) $id
if(empty($_POST['key'])||empty($_POST['val'])) $key