Alternc  latest
Alternc logiel libre pour l'hébergement
m_aws Class Reference

This class manage awstats statistic sets. More...

Public Member Functions

 m_aws ()
 Constructor. More...
 
 hook_menu ()
 
 alternc_password_policy ()
 Password kind used in this class (hook for admin class) More...
 
 alternc_module_description ()
 Name of the module function. More...
 
 get_list ()
 Returns an array with all the statistics of a member. More...
 
 get_stats_details ($id)
 Return an array with the details for 1 statistic set. More...
 
 host_list ()
 Return the list of domains / subdomains allowed for this member with the type (MX,URL,...) More...
 
 prefix_list ()
 Returns the list of prefixes that can be used on current account. More...
 
 select_prefix_list ($current)
 Echoes <option> tags of all the domains hosted on the account + the login of the account They can be used as a root for the login that may have access to web statistics hosted on an account $current will be the selected value. More...
 
 select_host_list ($current)
 Draw options for a select html code with the list of allowed and availables domains for this member. More...
 
 check_host_available ($current)
 Check if hosts is already used by awstats of available for this member. More...
 
 get_hostaliases ($id)
 Return the hostaliases list with an id. More...
 
 put_stats_details ($id, $users, $hostaliases, $public)
 Edit a statistic set (change allowed user list) More...
 
 delete_stats ($id)
 Delete a statistic set. More...
 
 add_stats ($hostname, $users="", $hostaliases, $public)
 Create a new statistic set. More...
 
 list_login ()
 
 list_allowed_login ($id)
 
 get_view_public ($id)
 
 login_exists ($login, $exists=1)
 
 del_login ($login)
 
 add_login ($login, $pass)
 
 change_pass ($login, $pass)
 
 allow_login ($login, $id, $noconf=0)
 
 delete_allowed_login ($id, $noconf=0)
 
 deny_login ($login, $id, $noconf=0)
 
 alternc_del_member ()
 
 alternc_del_domain ($dom)
 This function is called on each class when a domain name is uninstalled. More...
 
 hook_quota_get ()
 This function is called when we are asked to compute the used quota for a service. More...
 
 _check ($login)
 
 _delconf ($hostname)
 Delete the awstats configuration file for a statistic set. More...
 
 _createconf ($id, $nochk=0)
 Create a configuration file for a statistic set. More...
 
 _createhtpasswd ()
 
 alternc_export ()
 Exports all the aws related information for an account. More...
 
 crypt_apr1_md5 ($plainpasswd)
 from http://php.net/crypt#73619 More...
 

Public Attributes

 $CONFDIR ="/etc/awstats"
 Where are the awstats configuration files : @access private. More...
 
 $HTAFILE ="/etc/alternc/awstats.htpasswd"
 
 $CACHEDIR ="/var/cache/awstats"
 
 $TEMPLATEFILE ="/etc/alternc/templates/awstats/awstats.template.conf"
 Where is the template for conf files : @access private. More...
 

Detailed Description

This class manage awstats statistic sets.

Copyleft AlternC Team

Definition at line 33 of file m_aws.php.

Member Function Documentation

◆ _check()

m_aws::_check (   $login)

Definition at line 664 of file m_aws.php.

664  {
665  global $msg,$mem;
666  $login=trim($login);
667  $login=strtolower($login);
668  if ($c=strpos($login,"_")) {
669  $prefix=substr($login,0,$c);
670  $postfix=substr($login,$c+1);
671  } else {
672  $prefix=$login;
673  $postfix="";
674  }
675  $r=$this->prefix_list();
676  if (!in_array($prefix,$r)) {
677  $msg->raise('Error', "aws",_("prefix not allowed.")); // prefix not allowed.
678  return false;
679  }
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)"));
682  return false;
683  }
684  return $login;
685  }
$mem
Definition: bootstrap.php:71
$msg
Definition: bootstrap.php:75
$c
Definition: bootstrap.php:47
$r
Definition: aws_add.php:75
prefix_list()
Returns the list of prefixes that can be used on current account.
Definition: m_aws.php:199
$login

References $c, $login, $mem, $msg, $r, and prefix_list().

Referenced by add_login(), allow_login(), change_pass(), and deny_login().

◆ _createconf()

m_aws::_createconf (   $id,
  $nochk = 0 
)

Create a configuration file for a statistic set.

if nochk==1, does not check the owner of the stat set (for admin only) @access private

Definition at line 707 of file m_aws.php.

707  {
708  global $db,$msg,$cuid,$L_ALTERNC_LOGS;
709  $s=@implode("",file($this->TEMPLATEFILE));
710  if (!$s) {
711  $msg->raise('Error', "aws",_("Problem to create the configuration"));
712  return false;
713  }
714  if ($nochk) {
715  $db->query("SELECT * FROM aws WHERE id='$id';");
716  } else {
717  $db->query("SELECT * FROM aws WHERE id='$id' AND uid='$cuid';");
718  }
719  if (!$db->num_rows()) {
720  $msg->raise('Error', "aws",_("This statistic does not exist"));
721  return false;
722  }
723  $db->next_record();
724  $uid = $db->f('uid');
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'");
729  $db->next_record();
730  $username = $db->f('login');
731  $db->query("SELECT login FROM aws_access WHERE id='$id';");
732  $users="";
733  while ($db->next_record()) {
734  $users.=$db->f("login")." ";
735  }
736 
737  $replace_vars = array(
738  '%%UID%%' => $uid,
739  '%%USER%%' => $username,
740  '%%ALTERNC_LOGS%%' => $L_ALTERNC_LOGS,
741  '%%PUBLIC%%' => $public,
742  '%%HOSTNAME%%' => $hostname,
743  '%%HOSTALIASES%%' => $hostaliases,
744  '%%USERS%%' => $users,
745  );
746  foreach ($replace_vars as $k=>$v){
747  $s=str_replace($k,$v,$s);
748  }
749 
750  $f=fopen($this->CONFDIR."/awstats.".$hostname.".conf","wb");
751  fputs($f,$s,strlen($s));
752  fclose($f);
753 
754  return true;
755  }
global $db
Definition: bootstrap.php:26
$cuid
Definition: bootstrap.php:43
global $username
Definition: change.php:59
$uid

References $cuid, $db, $f, $msg, $uid, and $username.

Referenced by add_stats(), allow_login(), delete_allowed_login(), deny_login(), and put_stats_details().

◆ _createhtpasswd()

m_aws::_createhtpasswd ( )

Definition at line 759 of file m_aws.php.

759  {
760  global $db, $msg;
761  $f=@fopen($this->HTAFILE,"wb");
762  if ($f) {
763  $db->query("SELECT login,pass FROM aws_users;");
764  while ($db->next_record()) {
765  fputs($f,$db->f("login").":".$db->f("pass")."\n");
766  }
767  fclose($f);
768  return true;
769  } else {
770  $msg->raise('Error', "aws", _("Problem to edit file %s"), $this->HTAFILE);
771  return false;
772  }
773  }

References $db, $f, and $msg.

Referenced by add_login(), add_stats(), allow_login(), alternc_del_domain(), alternc_del_member(), change_pass(), del_login(), delete_allowed_login(), deny_login(), and put_stats_details().

◆ _delconf()

m_aws::_delconf (   $hostname)

Delete the awstats configuration file for a statistic set.

@access private

Definition at line 692 of file m_aws.php.

692  {
693  global $msg,$action;
694  if (!preg_match('/^[._a-z0-9-]*$/', $hostname)){
695  $msg->raise('Error', "aws",_("Hostname is incorrect"));
696  return false;
697  }
698  $action->del($this->CONFDIR. DIRECTORY_SEPARATOR . "awstats.".$hostname.".conf");
699  }

References $msg.

Referenced by alternc_del_domain(), alternc_del_member(), and delete_stats().

◆ add_login()

m_aws::add_login (   $login,
  $pass 
)

Definition at line 468 of file m_aws.php.

468  {
469  global $db,$msg,$cuid,$admin;
470  $msg->log("aws","add_login");
471 
472  if (!($login=$this->_check($login))) {
473  return false;
474  }
475  if ($this->login_exists($login,1)) {
476  $msg->raise('Error', "aws",_("Login already exist"));
477  return false;
478  }
479  // Check this password against the password policy using common API :
480  if (is_callable(array($admin, "checkPolicy"))) {
481  if (!$admin->checkPolicy("aws", $login, $pass)) {
482  return false; // The error has been raised by checkPolicy()
483  }
484  }
485  $pass=$this->crypt_apr1_md5($pass);
486  // FIXME retourner une erreur l'insert se passe pas bien
487  $db->query("INSERT INTO aws_users (uid,login,pass) VALUES ('$cuid','$login','$pass');");
488  return $this->_createhtpasswd();
489  }
crypt_apr1_md5($plainpasswd)
from http://php.net/crypt#73619
Definition: m_aws.php:812
_createhtpasswd()
Definition: m_aws.php:759
_check($login)
Definition: m_aws.php:664
login_exists($login, $exists=1)
Definition: m_aws.php:440

References $cuid, $db, $login, $msg, _check(), _createhtpasswd(), crypt_apr1_md5(), and login_exists().

◆ add_stats()

m_aws::add_stats (   $hostname,
  $users = "",
  $hostaliases,
  $public 
)

Create a new statistic set.

Parameters
string$hostnameThe domain name
$uersarray the array of users that will be allowed
$hostaliasesarray an array of host aliases
$publicboolean Shall this statistic set be public ?
Returns
boolean TRUE if the set has been created

Definition at line 347 of file m_aws.php.

347  {
348  global $db,$msg,$quota,$mem,$cuid;
349  $msg->log("aws","add_stats",$hostname);
350  $ha="";
351  $r=$this->host_list();
352  $hosts=array();
353  foreach ($r as $key=>$val) {
354  $hosts[]=$val["hostname"];
355  }
356  reset($hosts);
357  if (!in_array($hostname,$hosts) || $hostname=="") {
358  $msg->raise('Error', "aws",_("This hostname does not exist (Domain name)"));
359  return false;
360  }
361 
362  // Parse the hostaliases array (it should contains valid domains)
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)"));
367  return false;
368  }
369  $ha .= "$ho ";
370  }
371  }
372 
373  if ($quota->cancreate("aws")) {
374  $db->query("INSERT INTO aws (hostname,uid,hostaliases,public) VALUES ('$hostname','$cuid','$ha','$public')");
375  $id=$db->lastid();
376  if (is_array($users)) {
377  foreach($users as $v) {
378  $this->allow_login($v,$id, 1);
379  }
380  }
381  if (!$this->_createconf($id) ) return false;
382  if (!$this->_createhtpasswd() ) return false;
383  mkdir($this->CACHEDIR."/".$hostname,0777);
384  return true;
385  } else {
386  $msg->raise('Alert', "aws",_("Your stat quota is over..."));
387  return false;
388  }
389  }
host_list()
Return the list of domains / subdomains allowed for this member with the type (MX,...
Definition: m_aws.php:172
_createconf($id, $nochk=0)
Create a configuration file for a statistic set.
Definition: m_aws.php:707
allow_login($login, $id, $noconf=0)
Definition: m_aws.php:518
if(!isset($is_include)) if(! $key &&! $crt) $id
$val
Definition: tempovars.php:15
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14

References $cuid, $db, $id, $key, $mem, $msg, $r, $val, _createconf(), _createhtpasswd(), allow_login(), and host_list().

◆ allow_login()

m_aws::allow_login (   $login,
  $id,
  $noconf = 0 
)

Definition at line 518 of file m_aws.php.

518  { // allow user $login to access stats $id.
519  global $db,$msg,$cuid;
520  $msg->log("aws","allow_login");
521 
522  if (!($login=$this->_check($login))) {
523  $msg->raise('Error', "aws",_("Login incorrect"));
524  return false;
525  }
526  if (!$this->login_exists($login)) {
527  $msg->raise('Error', "aws",_("Login does not exist"));
528  return false;
529  }
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."));
533  return false;
534  }
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."));
538  return false;
539  }
540  $db->query("INSERT INTO aws_access (uid,id,login) VALUES ('$cuid','$id','$login');");
541  if (!$noconf) {
542  $this->_createconf($id);
543  $this->_createhtpasswd();
544  }
545  return true;
546  }

References $cuid, $db, $id, $login, $msg, _check(), _createconf(), _createhtpasswd(), and login_exists().

Referenced by add_stats(), and put_stats_details().

◆ alternc_del_domain()

m_aws::alternc_del_domain (   $dom)

This function is called on each class when a domain name is uninstalled.

Parameters
string$domthe domain to uninstall

Definition at line 628 of file m_aws.php.

628  {
629  global $msg,$cuid;
630  $msg->log("aws","alternc_del_domain",$dom);
631  $db=new DB_System();
632  $db->query("SELECT id,hostname FROM aws WHERE uid='$cuid' AND (hostname='$dom' OR hostname like '%.$dom')");
633  $t=array();
634  while ($db->next_record()) {
635  $t[]=array($db->f("hostname"),$db->f("id"));
636  }
637  foreach ($t as $i) {
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]."';");
640  $this->_delconf($i[0]);
641  }
642  return $this->_createhtpasswd();
643  }
_delconf($hostname)
Delete the awstats configuration file for a statistic set.
Definition: m_aws.php:692
foreach($domaines_user as $domaine) $t
$i
$dom
Definition: whois_test.php:10

References $cuid, $db, $dom, $i, $msg, $t, _createhtpasswd(), and _delconf().

◆ alternc_del_member()

m_aws::alternc_del_member ( )

Definition at line 605 of file m_aws.php.

605  {
606  global $db,$msg,$cuid;
607  $msg->log("aws","del_member");
608  $db->query("SELECT * FROM aws WHERE uid='$cuid';");
609  $t=array();
610  while ($db->next_record()) {
611  $t[]=$db->f("hostname");
612  }
613  $db->query("DELETE FROM aws WHERE uid='$cuid';");
614  foreach ($t as $i) {
615  $this->_delconf($i);
616  }
617  $db->query("DELETE FROM aws_access WHERE uid='$cuid'");
618  $db->query("DELETE FROM aws_users WHERE uid='$cuid';");
619  return $this->_createhtpasswd();
620  }

References $cuid, $db, $i, $msg, $t, _createhtpasswd(), and _delconf().

◆ alternc_export()

m_aws::alternc_export ( )

Exports all the aws related information for an account.

@access private EXPERIMENTAL 'sid' function ;)

Definition at line 782 of file m_aws.php.

782  {
783  global $db,$msg,$cuid;
784  $msg->log("aws","export");
785  $str="<aws>\n";
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";
789  }
790  $r=array();
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"];
794  }
795  foreach($r as $id=>$host) {
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";
800  }
801  $str.=" </domain>\n";
802  }
803  $str.="</aws>\n";
804  return $str;
805  }
$host
Definition: config.php:71

References $cuid, $db, $host, $id, $msg, and $r.

◆ alternc_module_description()

m_aws::alternc_module_description ( )

Name of the module function.

Definition at line 81 of file m_aws.php.

81  {
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."));
83  }

◆ alternc_password_policy()

m_aws::alternc_password_policy ( )

Password kind used in this class (hook for admin class)

Definition at line 72 of file m_aws.php.

72  {
73  return array("aws"=>"Awstats Web Statistics");
74  }

◆ change_pass()

m_aws::change_pass (   $login,
  $pass 
)

Definition at line 493 of file m_aws.php.

493  {
494  global $db,$msg,$cuid,$admin;
495  $msg->log("aws","change_pass");
496 
497  if (!($login=$this->_check($login))) {
498  $msg->raise('Error', "aws",_("Login incorrect")); // Login incorrect
499  return false;
500  }
501  if (!($this->login_exists($login))) {
502  $msg->raise('Error', "aws",_("Login does not exists")); // Login does not exists
503  return false;
504  }
505  // Check this password against the password policy using common API :
506  if (is_callable(array($admin, "checkPolicy"))) {
507  if (!$admin->checkPolicy("aws", $login, $pass)) {
508  return false; // The error has been raised by checkPolicy()
509  }
510  }
511  $pass=$this->crypt_apr1_md5($pass);
512  $db->query("UPDATE aws_users SET pass='$pass' WHERE login='$login';");
513  return $this->_createhtpasswd();
514  }

References $cuid, $db, $login, $msg, _check(), _createhtpasswd(), crypt_apr1_md5(), and login_exists().

◆ check_host_available()

m_aws::check_host_available (   $current)

Check if hosts is already used by awstats of available for this member.

Definition at line 253 of file m_aws.php.

253  {
254  global $msg;
255  $msg->log("aws","check_host_available",$current);
256  $r=$this->get_list();
257  if(is_array($r)){
258  reset($r);
259  while (list($key,$val)=each($r)) {
260  if ($current==$val["hostname"]) {
261  $msg->raise('Alert', "aws",_("Host already managed by awstats!"));
262  return false;
263  }
264  }
265  }
266  return true;
267  }
get_list()
Returns an array with all the statistics of a member.
Definition: m_aws.php:96

References $key, $msg, $r, $val, and get_list().

Referenced by select_host_list().

◆ crypt_apr1_md5()

m_aws::crypt_apr1_md5 (   $plainpasswd)

from http://php.net/crypt#73619

Definition at line 812 of file m_aws.php.

812  {
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));
826  }
827  for ($i = 0; $i < 5; $i++) {
828  $k = $i + 6;
829  $j = $i + 12;
830  if ($j == 16) $j = 5;
831  $tmp = $bin[$i].$bin[$k].$bin[$j].$tmp;
832  }
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;
838  }
$len

References $i, and $len.

Referenced by add_login(), and change_pass().

◆ del_login()

m_aws::del_login (   $login)

Definition at line 453 of file m_aws.php.

453  {
454  global $db,$msg,$cuid;
455  $msg->log("aws","del_login");
456  if (!$this->login_exists($login,1)) {
457  $msg->raise('Error', "aws",_("Login does not exist"));
458  return false;
459  }
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';");
462  $this->_createhtpasswd();
463  return true;
464  }

References $cuid, $db, $login, $msg, _createhtpasswd(), and login_exists().

◆ delete_allowed_login()

m_aws::delete_allowed_login (   $id,
  $noconf = 0 
)
Parameters
integer$id

Definition at line 554 of file m_aws.php.

554  {
555  global $db,$msg,$cuid;
556  $msg->log("aws","delete_allowed_login");
557 
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."));
561  return false;
562  }
563  $db->query("DELETE FROM aws_access WHERE id='$id';");
564  if (!$noconf) {
565  $this->_createconf($id);
566  $this->_createhtpasswd();
567  }
568  return true;
569  }

References $cuid, $db, $id, $msg, _createconf(), and _createhtpasswd().

Referenced by delete_stats(), and put_stats_details().

◆ delete_stats()

m_aws::delete_stats (   $id)

Delete a statistic set.

Parameters
integer$idThe statistic set ID
Returns
string the domain name of the deleted statistic set, or FALSE if an error occurred

Definition at line 319 of file m_aws.php.

319  {
320  global $db,$msg,$cuid,$action;
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"));
325  return false;
326  }
327  $db->next_record();
328  $hostname=$db->f("hostname");
329  $this->delete_allowed_login($id,1);
330  $this->_delconf($hostname);
331  $db->query("DELETE FROM aws WHERE id='$id'");
332  $action->del($this->CACHEDIR. DIRECTORY_SEPARATOR . $hostname . DIRECTORY_SEPARATOR);
333  return $hostname;
334 
335  }
delete_allowed_login($id, $noconf=0)
Definition: m_aws.php:554

References $cuid, $db, $id, $msg, _delconf(), and delete_allowed_login().

◆ deny_login()

m_aws::deny_login (   $login,
  $id,
  $noconf = 0 
)

Definition at line 573 of file m_aws.php.

573  { // deny user $login to access stats $id.
574  global $db,$msg,$cuid;
575  $msg->log("aws","deny_login");
576 
577  if (!($login=$this->_check($login))) {
578  $msg->raise('Error', "aws",_("Login incorrect")); // Login incorrect
579  return false;
580  }
581  if (!$this->login_exists($login,0)) {
582  $msg->raise('Error', "aws",_("Login does not exists")); // Login does not exists
583  return false;
584  }
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."));
588  return false;
589  }
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."));
593  return false;
594  }
595  $db->query("DELETE FROM aws_access WHERE id='$id' AND login='$login';");
596  if (!$noconf) {
597  $this->_createconf($id);
598  $this->_createhtpasswd();
599  }
600  return true;
601  }

References $cuid, $db, $id, $login, $msg, _check(), _createconf(), _createhtpasswd(), and login_exists().

◆ get_hostaliases()

m_aws::get_hostaliases (   $id)

Return the hostaliases list with an id.

Definition at line 274 of file m_aws.php.

274  {
275  global $db,$msg,$cuid;
276  $r=array();
277  if ($id == NULL)
278  return $r;
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");
282  }
283 
284  return $r;
285  }

References $cuid, $db, $id, $msg, and $r.

◆ get_list()

m_aws::get_list ( )

Returns an array with all the statistics of a member.

Returns
array Returns an indexed array of associative arrays like that : $r[0-n]["id"] = Id of the stat set $r[0-n]["hostname"]= domain $r[0-n]["users"]= list of allowed users separated with ' '

Definition at line 96 of file m_aws.php.

96  {
97  global $db,$msg,$cuid;
98  $msg->log("aws","get_list");
99  $r=array();
100  $db->query("SELECT id, hostname FROM aws WHERE uid='$cuid' ORDER BY hostname;");
101  if ($db->num_rows()) {
102  while ($db->next_record()) {
103  $r[]=array(
104  "id"=>$db->f("id"),
105  "hostname"=>$db->f("hostname")
106  );
107  }
108  $t=array();
109  foreach ($r as $v) {
110  $db->query("SELECT login FROM aws_access WHERE id='".$v["id"]."';");
111  $u="";
112  while ($db->next_record()) {
113  $u.=$db->f("login")." ";
114  }
115  $t[]=array(
116  "id"=>$v["id"],
117  "hostname"=>$v["hostname"],
118  "users"=>$u
119  );
120  }
121  return $t;
122  } else {
123  return false;
124  }
125  }

References $cuid, $db, $msg, $r, and $t.

Referenced by check_host_available().

◆ get_stats_details()

m_aws::get_stats_details (   $id)

Return an array with the details for 1 statistic set.

Parameters
integer$idID of the set we want.
Returns
array Returns an associative array as follow : $r["id"] = Id $r["hostname"]= domain $r["users"] = List of allowed users, separated by ' '

Definition at line 138 of file m_aws.php.

138  {
139  global $db,$msg,$cuid;
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()) {
143  $db->next_record();
144  $id=$db->f("id");
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';");
149  $u="";
150  while ($db->next_record()) {
151  $u.=$db->f("login")." ";
152  }
153  return array(
154  "id"=>$id,
155  "hostname"=>$hostname,
156  "users"=>$u,
157  "hostaliases"=>$hostaliases,
158  "public"=>$public
159  );
160  } else {
161  $msg->raise('Error', "aws",_("This statistic does not exist"));
162  return false;
163  }
164  }

References $cuid, $db, $id, and $msg.

Referenced by put_stats_details().

◆ get_view_public()

m_aws::get_view_public (   $id)

Definition at line 425 of file m_aws.php.

425  {
426  global $db,$msg,$cuid;
427  $db->query("SELECT public FROM aws WHERE id='$id' and uid='$cuid';");
428  if ($db->num_rows()) {
429  $db->next_record();
430  $pub=$db->f("public");
431  } else {
432  $pub=1;
433  }
434  return $pub;
435  }

References $cuid, $db, and $msg.

◆ hook_menu()

m_aws::hook_menu ( )

Definition at line 57 of file m_aws.php.

57  {
58  $obj = array(
59  'title' => _("Web Statistics"),
60  'ico' => 'images/stat.png',
61  'link' => 'aws_list.php',
62  'pos' => 80,
63  ) ;
64 
65  return $obj;
66  }

◆ hook_quota_get()

m_aws::hook_quota_get ( )

This function is called when we are asked to compute the used quota for a service.

Definition at line 651 of file m_aws.php.

651  {
652  global $db,$msg,$cuid;
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");
658  }
659  return $q;
660  }
$q
Definition: menu_aws.php:32

References $cuid, $db, $msg, and $q.

◆ host_list()

m_aws::host_list ( )

Return the list of domains / subdomains allowed for this member with the type (MX,URL,...)

Returns
array an array of allowed domains / subdomains.

Definition at line 172 of file m_aws.php.

172  {
173  global $db,$msg,$cuid;
174  $r=array();
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()) {
177  if ($db->f("sub")) {
178  $r[]=array(
179  "hostname"=>$db->f("sub").".".$db->f("domaine"),
180  "type"=>$db->f("name"),
181  "desc"=>$db->f("description")
182  );
183  } else {
184  $r[]=array(
185  "hostname"=>$db->f("domaine"),
186  "type"=>$db->f("name"),
187  "desc"=>$db->f("description")
188  );
189  }
190  }
191  return $r;
192  }

References $cuid, $db, $msg, and $r.

Referenced by add_stats(), and select_host_list().

◆ list_allowed_login()

m_aws::list_allowed_login (   $id)

Definition at line 410 of file m_aws.php.

410  {
411  global $db,$msg,$cuid;
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';");
414  $res=array();
415  if (!$db->next_record()) {
416  return false;
417  }
418  do {
419  $res[]=array("login"=>$db->f("login"),"selected"=>($db->f("id")));
420  } while ($db->next_record());
421  return $res;
422  }
$res
Definition: index.php:111

References $cuid, $db, $msg, and $res.

◆ list_login()

m_aws::list_login ( )

Definition at line 393 of file m_aws.php.

393  {
394  global $db,$msg,$cuid;
395  $msg->log("aws","list_login");
396  $db->query("SELECT login FROM aws_users WHERE uid='$cuid';");
397  $res=array();
398  if (!$db->next_record()) {
399  $msg->raise('Info', "aws",_("No user currently defined"));
400  return false;
401  }
402  do {
403  $res[]=$db->f("login");
404  } while ($db->next_record());
405  return $res;
406  }

References $cuid, $db, $msg, and $res.

◆ login_exists()

m_aws::login_exists (   $login,
  $exists = 1 
)

Definition at line 440 of file m_aws.php.

440  {
441  global $db,$msg,$cuid;
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()) {
445  return ($exists==0);
446  } else {
447  return ($exists==1);
448  }
449  }

References $cuid, $db, and $msg.

Referenced by add_login(), allow_login(), change_pass(), del_login(), and deny_login().

◆ m_aws()

m_aws::m_aws ( )

Constructor.

Definition at line 54 of file m_aws.php.

54  {
55  }

◆ prefix_list()

m_aws::prefix_list ( )

Returns the list of prefixes that can be used on current account.

Returns
array an arry with the list of domains + the login of the account

Definition at line 199 of file m_aws.php.

199  {
200  global $db,$mem,$cuid;
201  $r=array();
202  $r[]=$mem->user["login"];
203  $db->query("SELECT domaine FROM domaines WHERE compte='$cuid' ORDER BY domaine;");
204  while ($db->next_record()) {
205  $r[]=$db->f("domaine");
206  }
207  return $r;
208  }

References $cuid, $db, $mem, and $r.

Referenced by _check(), and select_prefix_list().

◆ put_stats_details()

m_aws::put_stats_details (   $id,
  $users,
  $hostaliases,
  $public 
)

Edit a statistic set (change allowed user list)

Parameters
integer$idthe stat number we change
array$usersthe list of allowed users

Definition at line 294 of file m_aws.php.

294  {
295  global $msg,$db,$cuid;
296  if ($this->get_stats_details($id)) {
297  $this->delete_allowed_login($id, 1);
298  if (is_array($users)) {
299  foreach($users as $v) {
300  $this->allow_login($v,$id,1);
301  }
302  }
303  $db->query("UPDATE aws SET hostaliases='$hostaliases', public='$public' where id='$id';");
304  $this->_createconf($id);
305  $this->_createhtpasswd();
306  return true;
307  } else {
308  return false;
309  }
310  }
get_stats_details($id)
Return an array with the details for 1 statistic set.
Definition: m_aws.php:138

References $cuid, $db, $id, $msg, _createconf(), _createhtpasswd(), allow_login(), delete_allowed_login(), and get_stats_details().

◆ select_host_list()

m_aws::select_host_list (   $current)

Draw options for a select html code with the list of allowed and availables domains for this member.

Definition at line 235 of file m_aws.php.

235  {
236  $r=$this->host_list();
237  reset($r);
238  while (list($key,$val)=each($r)) {
239  $ho=$val["hostname"];
240  $ty=$val["desc"];
241  if ($current==$ho) $c=" selected=\"selected\""; else $c="";
242  if ($this->check_host_available($ho)) echo "<option value=\"$ho\"$c>$ho ("._($ty).")</option>";
243  }
244  return true;
245  }
check_host_available($current)
Check if hosts is already used by awstats of available for this member.
Definition: m_aws.php:253

References $c, $key, $r, $val, check_host_available(), and host_list().

◆ select_prefix_list()

m_aws::select_prefix_list (   $current)

Echoes <option> tags of all the domains hosted on the account + the login of the account They can be used as a root for the login that may have access to web statistics hosted on an account $current will be the selected value.

Parameters
string$currentThe default selected value
Returns
boolean TRUE.

Definition at line 219 of file m_aws.php.

219  {
220  $r=$this->prefix_list();
221  reset($r);
222  while (list($key,$val)=each($r)) {
223  if ($current==$val) $c=" selected=\"selected\""; else $c="";
224  echo "<option$c>$val</option>";
225  }
226  return true;
227  }

References $c, $key, $r, $val, and prefix_list().

Member Data Documentation

◆ $CACHEDIR

m_aws::$CACHEDIR ="/var/cache/awstats"

Definition at line 41 of file m_aws.php.

◆ $CONFDIR

m_aws::$CONFDIR ="/etc/awstats"

Where are the awstats configuration files : @access private.

Definition at line 39 of file m_aws.php.

◆ $HTAFILE

m_aws::$HTAFILE ="/etc/alternc/awstats.htpasswd"

Definition at line 40 of file m_aws.php.

◆ $TEMPLATEFILE

m_aws::$TEMPLATEFILE ="/etc/alternc/templates/awstats/awstats.template.conf"

Where is the template for conf files : @access private.

Definition at line 47 of file m_aws.php.


The documentation for this class was generated from the following file: