Alternc  latest
Alternc logiel libre pour l'hébergement
m_aws.php
Go to the documentation of this file.
1 <?php
2 /*
3  ----------------------------------------------------------------------
4  AlternC - Web Hosting System
5  Copyright (C) 2000-2012 by the AlternC Development Team.
6  https://alternc.org/
7  ----------------------------------------------------------------------
8  LICENSE
9 
10  This program is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License (GPL)
12  as published by the Free Software Foundation; either version 2
13  of the License, or (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  To read the license please visit http://www.gnu.org/copyleft/gpl.html
21  ----------------------------------------------------------------------
22  Purpose of file: Gestion des statistiques web par Awstats
23  ----------------------------------------------------------------------
24 */
25 /**
26 * This class manage awstats statistic sets.
27 *
28 * Copyleft {@link http://alternc.org/ AlternC Team}
29 *
30 * @copyright AlternC-Team 2004-09-01 http://alternc.org/
31 *
32 */
33 class m_aws {
34 
35 
36  /** Where are the awstats configuration files :
37  * @access private
38  */
39  var $CONFDIR="/etc/awstats";
40  var $HTAFILE="/etc/alternc/awstats.htpasswd";
41  var $CACHEDIR="/var/cache/awstats";
42 
43 
44  /** Where is the template for conf files :
45  * @access private
46  */
47  var $TEMPLATEFILE="/etc/alternc/templates/awstats/awstats.template.conf";
48 
49 
50  /* ----------------------------------------------------------------- */
51  /**
52  * Constructor
53  */
54  function m_aws() {
55  }
56 
57  function hook_menu() {
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  }
67 
68  /* ----------------------------------------------------------------- */
69  /**
70  * Password kind used in this class (hook for admin class)
71  */
73  return array("aws"=>"Awstats Web Statistics");
74  }
75 
76 
77  /* ----------------------------------------------------------------- */
78  /**
79  * Name of the module function
80  */
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  }
84 
85 
86  /* ----------------------------------------------------------------- */
87  /**
88  * Returns an array with all the statistics of a member.
89  *
90  * @return array Returns an indexed array of associative arrays
91  * like that :
92  * $r[0-n]["id"] = Id of the stat set
93  * $r[0-n]["hostname"]= domain
94  * $r[0-n]["users"]= list of allowed users separated with ' '
95  */
96  function get_list() {
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  }
126 
127 
128  /* ----------------------------------------------------------------- */
129  /**
130  * Return an array with the details for 1 statistic set
131  *
132  * @param integer $id ID of the set we want.
133  * @return array Returns an associative array as follow :
134  * $r["id"] = Id
135  * $r["hostname"]= domain
136  * $r["users"] = List of allowed users, separated by ' '
137  */
138  function get_stats_details($id) {
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  }
165 
166 
167 /* ----------------------------------------------------------------- */
168  /** Return the list of domains / subdomains allowed for this member with the type (MX,URL,...)
169  *
170  * @return array an array of allowed domains / subdomains.
171  */
172  function host_list() {
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  }
193 
194 
195  /* ----------------------------------------------------------------- */
196  /** Returns the list of prefixes that can be used on current account
197  * @return array an arry with the list of domains + the login of the account
198  */
199  function prefix_list() {
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  }
209 
210 
211  /* ----------------------------------------------------------------- */
212  /** Echoes <option> tags of all the domains hosted on the account + the login of the account
213  * They can be used as a root for the login that may have access to web statistics
214  * hosted on an account
215  * $current will be the selected value.
216  * @param string $current The default selected value
217  * @return boolean TRUE.
218  */
219  function select_prefix_list($current) {
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  }
228 
229 
230  /* ----------------------------------------------------------------- */
231  /**
232  * Draw options for a select html code with the list of allowed and availables domains
233  * for this member.
234  */
235  function select_host_list($current) {
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  }
246 
247 
248  /* ----------------------------------------------------------------- */
249  /**
250  * Check if hosts is already used by awstats
251  * of available for this member.
252  */
253  function check_host_available($current) {
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  }
268 
269 
270  /* ----------------------------------------------------------------- */
271  /**
272  * Return the hostaliases list with an id.
273  */
274  function get_hostaliases($id) {
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  }
286 
287 
288  /* ----------------------------------------------------------------- */
289  /**
290  * Edit a statistic set (change allowed user list)
291  * @param integer $id the stat number we change
292  * @param array $users the list of allowed users
293  */
294  function put_stats_details($id,$users,$hostaliases,$public) {
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  }
311 
312 
313  /* ----------------------------------------------------------------- */
314  /**
315  * Delete a statistic set.
316  * @param integer $id The statistic set ID
317  * @return string the domain name of the deleted statistic set, or FALSE if an error occurred
318  */
319  function delete_stats($id) {
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  }
336 
337 
338  /* ----------------------------------------------------------------- */
339  /**
340  * Create a new statistic set
341  * @param string $hostname The domain name
342  * @param $uers array the array of users that will be allowed
343  * @param $hostaliases array an array of host aliases
344  * @param $public boolean Shall this statistic set be public ?
345  * @return boolean TRUE if the set has been created
346  */
347  function add_stats($hostname,$users="", $hostaliases,$public) {
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  }
390 
391 
392  /* ----------------------------------------------------------------- */
393  function list_login() {
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  }
407 
408 
409  /* ----------------------------------------------------------------- */
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  }
423 
424  /* ----------------------------------------------------------------- */
425  function get_view_public($id) {
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  }
436 
437 
438  /* ----------------------------------------------------------------- */
439  /* Check that a login exists ($exists=1) or doesn't exist ($exists=0) */
440  function login_exists($login,$exists=1) {
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  }
450 
451 
452  /* ----------------------------------------------------------------- */
453  function del_login($login) {
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  }
465 
466 
467  /* ----------------------------------------------------------------- */
468  function add_login($login,$pass) {
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  }
490 
491 
492  /* ----------------------------------------------------------------- */
493  function change_pass($login,$pass) {
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  }
515 
516 
517  /* ----------------------------------------------------------------- */
518  function allow_login($login,$id,$noconf=0) { // 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  }
547 
548 
549  /* ----------------------------------------------------------------- */
550 
551  /**
552  * @param integer $id
553  */
554  function delete_allowed_login($id,$noconf=0) {
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  }
570 
571 
572  /* ----------------------------------------------------------------- */
573  function deny_login($login,$id,$noconf=0) { // 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  }
602 
603 
604  /* ----------------------------------------------------------------- */
605  function alternc_del_member() {
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  }
621 
622 
623  /* ----------------------------------------------------------------- */
624  /**
625  * This function is called on each class when a domain name is uninstalled
626  * @param string $dom the domain to uninstall
627  */
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  }
644 
645 
646  /* ----------------------------------------------------------------- */
647  /**
648  * This function is called when we are asked to compute the used quota
649  * for a service
650  */
651  function hook_quota_get() {
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  }
661 
662 
663  /* ----------------------------------------------------------------- */
664  function _check($login) {
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  }
686 
687 
688  /* ----------------------------------------------------------------- */
689  /** Delete the awstats configuration file for a statistic set.
690  * @access private
691  */
692  function _delconf($hostname) {
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  }
700 
701 
702  /* ----------------------------------------------------------------- */
703  /** Create a configuration file for a statistic set.
704  * if nochk==1, does not check the owner of the stat set (for admin only)
705  * @access private
706  */
707  function _createconf($id,$nochk=0) {
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  }
756 
757 
758  /* ----------------------------------------------------------------- */
759  function _createhtpasswd() {
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  }
774 
775 
776  /* ----------------------------------------------------------------- */
777  /**
778  * Exports all the aws related information for an account.
779  * @access private
780  * EXPERIMENTAL 'sid' function ;)
781  */
782  function alternc_export() {
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  }
806 
807 
808  /* ----------------------------------------------------------------- */
809  /**
810  * from http://php.net/crypt#73619
811  */
812  function crypt_apr1_md5($plainpasswd) {
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  }
839 
840 
841 
842 
843 } /* CLASSE m_aws */
844 
845 ?>
global $db
Definition: bootstrap.php:26
$mem
Definition: bootstrap.php:71
$msg
Definition: bootstrap.php:75
$c
Definition: bootstrap.php:47
$cuid
Definition: bootstrap.php:43
$r
Definition: aws_add.php:75
$res
Definition: index.php:111
global $username
Definition: change.php:59
This class manage awstats statistic sets.
Definition: m_aws.php:33
list_allowed_login($id)
Definition: m_aws.php:410
_delconf($hostname)
Delete the awstats configuration file for a statistic set.
Definition: m_aws.php:692
$TEMPLATEFILE
Where is the template for conf files : @access private.
Definition: m_aws.php:47
crypt_apr1_md5($plainpasswd)
from http://php.net/crypt#73619
Definition: m_aws.php:812
del_login($login)
Definition: m_aws.php:453
hook_quota_get()
This function is called when we are asked to compute the used quota for a service.
Definition: m_aws.php:651
alternc_password_policy()
Password kind used in this class (hook for admin class)
Definition: m_aws.php:72
_createhtpasswd()
Definition: m_aws.php:759
delete_allowed_login($id, $noconf=0)
Definition: m_aws.php:554
_check($login)
Definition: m_aws.php:664
alternc_export()
Exports all the aws related information for an account.
Definition: m_aws.php:782
add_stats($hostname, $users="", $hostaliases, $public)
Create a new statistic set.
Definition: m_aws.php:347
deny_login($login, $id, $noconf=0)
Definition: m_aws.php:573
alternc_del_domain($dom)
This function is called on each class when a domain name is uninstalled.
Definition: m_aws.php:628
prefix_list()
Returns the list of prefixes that can be used on current account.
Definition: m_aws.php:199
delete_stats($id)
Delete a statistic set.
Definition: m_aws.php:319
get_view_public($id)
Definition: m_aws.php:425
check_host_available($current)
Check if hosts is already used by awstats of available for this member.
Definition: m_aws.php:253
add_login($login, $pass)
Definition: m_aws.php:468
put_stats_details($id, $users, $hostaliases, $public)
Edit a statistic set (change allowed user list)
Definition: m_aws.php:294
get_stats_details($id)
Return an array with the details for 1 statistic set.
Definition: m_aws.php:138
hook_menu()
Definition: m_aws.php:57
$CACHEDIR
Definition: m_aws.php:41
get_list()
Returns an array with all the statistics of a member.
Definition: m_aws.php:96
host_list()
Return the list of domains / subdomains allowed for this member with the type (MX,...
Definition: m_aws.php:172
select_prefix_list($current)
Echoes <option> tags of all the domains hosted on the account + the login of the account They can be ...
Definition: m_aws.php:219
$HTAFILE
Definition: m_aws.php:40
$CONFDIR
Where are the awstats configuration files : @access private.
Definition: m_aws.php:39
alternc_module_description()
Name of the module function.
Definition: m_aws.php:81
change_pass($login, $pass)
Definition: m_aws.php:493
_createconf($id, $nochk=0)
Create a configuration file for a statistic set.
Definition: m_aws.php:707
login_exists($login, $exists=1)
Definition: m_aws.php:440
alternc_del_member()
Definition: m_aws.php:605
get_hostaliases($id)
Return the hostaliases list with an id.
Definition: m_aws.php:274
m_aws()
Constructor.
Definition: m_aws.php:54
list_login()
Definition: m_aws.php:393
allow_login($login, $id, $noconf=0)
Definition: m_aws.php:518
select_host_list($current)
Draw options for a select html code with the list of allowed and availables domains for this member.
Definition: m_aws.php:235
$host
Definition: config.php:71
$uid
$q
Definition: menu_aws.php:32
foreach($domaines_user as $domaine) $t
$login
$i
$len
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
$dom
Definition: whois_test.php:10