Alternc  3.2
Alternc logiel libre pour l'hébergement
 All Data Structures Namespaces Files Functions Variables Pages
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,$err,$cuid;
98  $err->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  $err->raise("aws",_("No statistics currently defined"));
124  return false;
125  }
126  }
127 
128 
129  /* ----------------------------------------------------------------- */
130  /**
131  * Return an array with the details for 1 statistic set
132  *
133  * @param integer $id ID of the set we want.
134  * @return array Returns an associative array as follow :
135  * $r["id"] = Id
136  * $r["hostname"]= domain
137  * $r["users"] = List of allowed users, separated by ' '
138  */
139  function get_stats_details($id) {
140  global $db,$err,$cuid;
141  $err->log("aws","get_stats_details",$id);
142  $r=array();
143  $db->query("SELECT id, hostname, hostaliases, public FROM aws WHERE uid='$cuid' AND id='$id';");
144  if ($db->num_rows()) {
145  $db->next_record();
146  $id=$db->f("id");
147  $hostname=$db->f("hostname");
148  $hostaliases=$db->f("hostaliases");
149  $public=$db->f("public");
150  $db->query("SELECT login FROM aws_access WHERE id='$id';");
151  $u="";
152  while ($db->next_record()) {
153  $u.=$db->f("login")." ";
154  }
155  return array(
156  "id"=>$id,
157  "hostname"=>$hostname,
158  "users"=>$u,
159  "hostaliases"=>$hostaliases,
160  "public"=>$public
161  );
162  } else {
163  $err->raise("aws",_("This statistic does not exist"));
164  return false;
165  }
166  }
167 
168 
169 /* ----------------------------------------------------------------- */
170  /** Return the list of domains / subdomains allowed for this member with the type (MX,URL,...)
171  *
172  * @return array an array of allowed domains / subdomains.
173  */
174  function host_list() {
175  global $db,$err,$cuid;
176  $r=array();
177  $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;");
178  while ($db->next_record()) {
179  if ($db->f("sub")) {
180  $r[]=array(
181  "hostname"=>$db->f("sub").".".$db->f("domaine"),
182  "type"=>$db->f("name"),
183  "desc"=>$db->f("description")
184  );
185  } else {
186  $r[]=array(
187  "hostname"=>$db->f("domaine"),
188  "type"=>$db->f("name"),
189  "desc"=>$db->f("description")
190  );
191  }
192  }
193  return $r;
194  }
195 
196 
197  /* ----------------------------------------------------------------- */
198  /** Returns the list of prefixes that can be used on current account
199  * @return array an arry with the list of domains + the login of the account
200  */
201  function prefix_list() {
202  global $db,$mem,$cuid;
203  $r=array();
204  $r[]=$mem->user["login"];
205  $db->query("SELECT domaine FROM domaines WHERE compte='$cuid' ORDER BY domaine;");
206  while ($db->next_record()) {
207  $r[]=$db->f("domaine");
208  }
209  return $r;
210  }
211 
212 
213  /* ----------------------------------------------------------------- */
214  /** Echoes <option> tags of all the domains hosted on the account + the login of the account
215  * They can be used as a root for the login that may have access to web statistics
216  * hosted on an account
217  * $current will be the selected value.
218  * @param string $current The default selected value
219  * @return boolean TRUE.
220  */
221  function select_prefix_list($current) {
222  $r=$this->prefix_list();
223  reset($r);
224  while (list($key,$val)=each($r)) {
225  if ($current==$val) $c=" selected=\"selected\""; else $c="";
226  echo "<option$c>$val</option>";
227  }
228  return true;
229  }
230 
231 
232  /* ----------------------------------------------------------------- */
233  /**
234  * Draw options for a select html code with the list of allowed and availables domains
235  * for this member.
236  */
237  function select_host_list($current) {
238  $r=$this->host_list();
239  reset($r);
240  while (list($key,$val)=each($r)) {
241  $ho=$val["hostname"];
242  $ty=$val["desc"];
243  if ($current==$ho) $c=" selected=\"selected\""; else $c="";
244  if ($this->check_host_available($ho)) echo "<option value=\"$ho\"$c>$ho ("._($ty).")</option>";
245  }
246  return true;
247  }
248 
249 
250  /* ----------------------------------------------------------------- */
251  /**
252  * Check if hosts is already used by awstats
253  * of available for this member.
254  */
255  function check_host_available($current) {
256  global $err;
257  $err->log("aws","check_host_available",$current);
258  $r=$this->get_list();
259  if(is_array($r)){
260  reset($r);
261  while (list($key,$val)=each($r)) {
262  if ($current==$val["hostname"]) {
263  $err->raise("aws",_("Host already managed by awstats!"));
264  return false;
265  }
266  }
267  }
268  return true;
269  }
270 
271 
272  /* ----------------------------------------------------------------- */
273  /**
274  * Return the hostaliases list with an id.
275  */
276  function get_hostaliases($id) {
277  global $db,$err,$cuid;
278  $r=array();
279  if ($id == NULL)
280  return $r;
281  $db->query("SELECT hostaliases FROM aws WHERE uid='$cuid' and id='$id' ORDER by hostaliases;");
282  while ($db->next_record()) {
283  $r[]=$db->f("hostaliases");
284  }
285 
286  return $r;
287  }
288 
289 
290  /* ----------------------------------------------------------------- */
291  /**
292  * Edit a statistic set (change allowed user list)
293  * @param integer $id the stat number we change
294  * @param array $users the list of allowed users
295  */
296  function put_stats_details($id,$users,$hostaliases,$public) {
297  global $err,$db,$cuid;
298  if ($c=$this->get_stats_details($id)) {
299  $this->delete_allowed_login($id, 1);
300  if (is_array($users)) {
301  foreach($users as $v) {
302  $this->allow_login($v,$id,1);
303  }
304  }
305  $db->query("UPDATE aws SET hostaliases='$hostaliases', public='$public' where id='$id';");
306  $this->_createconf($id);
307  $this->_createhtpasswd();
308  return true;
309  } else return false;
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,$err,$cuid,$action;
321  $err->log("aws","delete_stats",$id);
322  $db->query("SELECT hostname FROM aws WHERE id='$id' and uid='$cuid';");
323  if (!$db->num_rows()) {
324  $err->raise("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,$err,$quota,$mem,$cuid;
349  $err->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  $err->raise("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  $err->raise("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  $err->raise("aws",_("Your stat quota is over..."));
387  return false;
388  }
389  }
390 
391 
392  /* ----------------------------------------------------------------- */
393  function list_login() {
394  global $db,$err,$cuid;
395  $err->log("aws","list_login");
396  $db->query("SELECT login FROM aws_users WHERE uid='$cuid';");
397  $res=array();
398  if (!$db->next_record()) {
399  $err->raise("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  /* ----------------------------------------------------------------- */
410  function list_allowed_login($id) {
411  global $db,$err,$cuid;
412  $err->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,$err,$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,$err,$cuid;
442  $err->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,$err,$cuid;
455  $err->log("aws","del_login");
456  if (!$this->login_exists($login,1)) {
457  $err->raise("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,$err,$cuid;
470  $err->log("aws","add_login");
471 
472  if (!($login=$this->_check($login))) {
473  $err->raise("aws",_("Login incorrect"));
474  return false;
475  }
476  if ($this->login_exists($login,1)) {
477  $err->raise("aws",_("Login already exist"));
478  return false;
479  }
480  $pass=_md5cr($pass);
481  // FIXME retourner une erreur l'insert se passe pas bien
482  $db->query("INSERT INTO aws_users (uid,login,pass) VALUES ('$cuid','$login','$pass');");
483  return $this->_createhtpasswd();
484  }
485 
486 
487  /* ----------------------------------------------------------------- */
488  function change_pass($login,$pass) {
489  global $db,$err,$cuid;
490  $err->log("aws","change_pass");
491 
492  if (!($login=$this->_check($login))) {
493  $err->raise("aws",_("Login incorrect")); // Login incorrect
494  return false;
495  }
496  if (!($this->login_exists($login))) {
497  $err->raise("aws",_("Login does not exists")); // Login does not exists
498  return false;
499  }
500  $pass=_md5c($pass);
501  $db->query("UPDATE aws_users SET pass='$pass' WHERE login='$login';");
502  return $this->_createhtpasswd();
503  }
504 
505 
506  /* ----------------------------------------------------------------- */
507  function allow_login($login,$id,$noconf=0) { // allow user $login to access stats $id.
508  global $db,$err,$cuid;
509  $err->log("aws","allow_login");
510 
511  if (!($login=$this->_check($login))) {
512  $err->raise("aws",_("Login incorrect"));
513  return false;
514  }
515  if (!$this->login_exists($login)) {
516  $err->raise("aws",_("Login does not exist"));
517  return false;
518  }
519  $db->query("SELECT id FROM aws WHERE id='$id' AND uid='$cuid'");
520  if (!$db->next_record()) {
521  $err->raise("aws",_("The requested statistic does not exist."));
522  return false;
523  }
524  $db->query("SELECT login FROM aws_access WHERE id='$id' AND login='$login'");
525  if ($db->next_record()) {
526  $err->raise("aws",_("This login is already allowed for this statistics."));
527  return false;
528  }
529  $db->query("INSERT INTO aws_access (uid,id,login) VALUES ('$cuid','$id','$login');");
530  if (!$noconf) {
531  $this->_createconf($id);
532  $this->_createhtpasswd();
533  }
534  return true;
535  }
536 
537 
538  /* ----------------------------------------------------------------- */
539  function delete_allowed_login($id,$noconf=0) {
540  global $db,$err,$cuid;
541  $err->log("aws","delete_allowed_login");
542 
543  $db->query("SELECT id FROM aws WHERE id='$id' AND uid='$cuid'");
544  if (!$db->next_record()) {
545  $err->raise("aws",_("The requested statistic does not exist."));
546  return false;
547  }
548  $db->query("DELETE FROM aws_access WHERE id='$id';");
549  if (!$noconf) {
550  $this->_createconf($id);
551  $this->_createhtpasswd();
552  }
553  return true;
554  }
555 
556 
557  /* ----------------------------------------------------------------- */
558  function deny_login($login,$id,$noconf=0) { // deny user $login to access stats $id.
559  global $db,$err,$cuid;
560  $err->log("aws","deny_login");
561 
562  if (!($login=$this->_check($login))) {
563  $err->raise("aws",_("Login incorrect")); // Login incorrect
564  return false;
565  }
566  if (!$this->login_exists($login,0)) {
567  $err->raise("aws",_("Login does not exists")); // Login does not exists
568  return false;
569  }
570  $db->query("SELECT id FROM aws WHERE id='$id' AND uid='$cuid'");
571  if (!$db->next_record()) {
572  $err->raise("aws",_("The requested statistic does not exist."));
573  return false;
574  }
575  $db->query("SELECT login FROM aws_access WHERE id='$id' AND login='$login'");
576  if (!$db->next_record()) {
577  $err->raise("aws",_("This login is already denied for this statistics."));
578  return false;
579  }
580  $db->query("DELETE FROM aws_access WHERE id='$id' AND login='$login';");
581  if (!$noconf) {
582  $this->_createconf($id);
583  $this->_createhtpasswd();
584  }
585  return true;
586  }
587 
588 
589  /* ----------------------------------------------------------------- */
590  function alternc_del_member() {
591  global $db,$err,$cuid;
592  $err->log("aws","del_member");
593  $db->query("SELECT * FROM aws WHERE uid='$cuid';");
594  $t=array();
595  while ($db->next_record()) {
596  $t[]=$db->f("hostname");
597  }
598  $db->query("DELETE FROM aws WHERE uid='$cuid';");
599  foreach ($t as $i) {
600  $this->_delconf($i);
601  }
602  $db->query("DELETE FROM aws_access WHERE uid='$cuid'");
603  $db->query("DELETE FROM aws_users WHERE uid='$cuid';");
604  return $this->_createhtpasswd();
605  }
606 
607 
608  /* ----------------------------------------------------------------- */
609  /**
610  * This function is called on each class when a domain name is uninstalled
611  * @param string $dom the domain to uninstall
612  */
614  global $db,$err,$cuid;
615  $err->log("aws","alternc_del_domain",$dom);
616  $db=new DB_System();
617  $db->query("SELECT id,hostname FROM aws WHERE uid='$cuid' AND (hostname='$dom' OR hostname like '%.$dom')");
618  $t=array();
619  while ($db->next_record()) {
620  $t[]=array($db->f("hostname"),$db->f("id"));
621  }
622  foreach ($t as $i) {
623  $db->query("DELETE FROM aws WHERE uid='$cuid' AND hostname='".$i[0]."';");
624  $db->query("DELETE FROM aws_access WHERE uid='$cuid' AND id='".$i[1]."';");
625  $this->_delconf($i[0]);
626  }
627  return $this->_createhtpasswd();
628  }
629 
630 
631  /* ----------------------------------------------------------------- */
632  /**
633  * This function is called when we are asked to compute the used quota
634  * for a service
635  * @param integer $id The userid whose quota should be computed.
636  */
637  function hook_quota_get() {
638  global $db,$err,$cuid;
639  $err->log("aws","get_quota");
640  $db->query("SELECT COUNT(*) AS cnt FROM aws WHERE uid='$cuid'");
641  $q=Array("name"=>"aws", "description"=>_("Awstats"), "used"=>0);
642  if ($db->next_record()) {
643  $q['used']=$db->f("cnt");
644  }
645  return $q;
646  }
647 
648 
649  /* ----------------------------------------------------------------- */
650  function _check($login) {
651  global $err,$mem;
652  $login=trim($login);
653  $login=strtolower($login);
654  if ($c=strpos($login,"_")) {
655  $prefix=substr($login,0,$c);
656  $postfix=substr($login,$c+1);
657  } else {
658  $prefix=$login;
659  $postfix="";
660  }
661  $r=$this->prefix_list();
662  if (!in_array($prefix,$r)) {
663  $err->raise("aws",_("prefix not allowed.")); // prefix not allowed.
664  return false;
665  }
666  if (!preg_match('/^[0-9a-z_-]*$/', $postfix)){
667  $err->raise("aws",_("Forbidden caracters in the postfix."));
668  return false;
669  }
670  return $login;
671  }
672 
673 
674  /* ----------------------------------------------------------------- */
675  /** Delete the awstats configuration file for a statistic set.
676  * @access private
677  */
678  function _delconf($hostname) {
679  global $err,$action;
680  if (!preg_match('/^[._a-z0-9-]*$/', $hostname)){
681  $err->raise("aws",_("Hostname is incorrect"));
682  return false;
683  }
684  $action->del($this->CONFDIR. DIRECTORY_SEPARATOR . "awstats.".$hostname.".conf");
685  }
686 
687 
688  /* ----------------------------------------------------------------- */
689  /** Create a configuration file for a statistic set.
690  * if nochk==1, does not check the owner of the stat set (for admin only)
691  * @access private
692  */
693  function _createconf($id,$nochk=0) {
694  global $db,$err,$cuid,$L_ALTERNC_LOGS;
695  $s=@implode("",file($this->TEMPLATEFILE));
696  if (!$s) {
697  $err->raise("aws",_("Problem to create the configuration"));
698  return false;
699  }
700  if ($nochk) {
701  $db->query("SELECT * FROM aws WHERE id='$id';");
702  } else {
703  $db->query("SELECT * FROM aws WHERE id='$id' AND uid='$cuid';");
704  }
705  if (!$db->num_rows()) {
706  $err->raise("aws",_("This statistic does not exist"));
707  return false;
708  }
709  $db->next_record();
710  $uid = $db->f('uid');
711  $hostname=$db->f("hostname");
712  $hostaliases=$db->f("hostaliases");
713  $public=$db->f("public");
714  $db->query("SELECT login FROM membres WHERE uid = '$uid'");
715  $db->next_record();
716  $username = $db->f('login');
717  $db->query("SELECT login FROM aws_access WHERE id='$id';");
718  $users="";
719  while ($db->next_record()) {
720  $users.=$db->f("login")." ";
721  }
722 
723  $replace_vars = array(
724  '%%UID%%' => $uid,
725  '%%USER%%' => $username,
726  '%%ALTERNC_LOGS%%' => $L_ALTERNC_LOGS,
727  '%%PUBLIC%%' => $public,
728  '%%HOSTNAME%%' => $hostname,
729  '%%HOSTALIASES%%' => $hostaliases,
730  '%%USERS%%' => $users,
731  );
732  foreach ($replace_vars as $k=>$v){
733  $s=str_replace($k,$v,$s);
734  }
735 
736  $f=fopen($this->CONFDIR."/awstats.".$hostname.".conf","wb");
737  fputs($f,$s,strlen($s));
738  fclose($f);
739 
740  return true;
741  }
742 
743 
744  /* ----------------------------------------------------------------- */
745  function _createhtpasswd() {
746  global $db, $err;
747  $f=@fopen($this->HTAFILE,"wb");
748  if ($f) {
749  $db->query("SELECT login,pass FROM aws_users;");
750  while ($db->next_record()) {
751  fputs($f,$db->f("login").":".$db->f("pass")."\n");
752  }
753  fclose($f);
754  return true;
755  } else {
756  $err->raise("aws",sprintf(_("Problem to edit file %s"), $this->HTAFILE));
757  return false;
758  }
759  }
760 
761 
762  /* ----------------------------------------------------------------- */
763  /**
764  * Exports all the aws related information for an account.
765  * @access private
766  * EXPERIMENTAL 'sid' function ;)
767  */
768  function alternc_export() {
769  global $db,$err,$cuid;
770  $err->log("aws","export");
771  $str="<aws>\n";
772  $db->query("SELECT login,pass FROM aws_users WHERE uid='$cuid';");
773  while ($db->next_record()) {
774  $str.=" <user><login>".$db->Record["login"]."</login><pass hash=\"des\">".$db->Record["pass"]."</pass></user>\n";
775  }
776  $r=array();
777  $db->query("SELECT id, hostname FROM aws WHERE uid='$cuid' ORDER BY hostname;");
778  while ($db->next_record()) {
779  $r[$db->Record["id"]]=$db->Record["hostname"];
780  }
781  foreach($r as $id=>$host) {
782  $str.=" <domain>\n <name>".$host."</name>\n";
783  $db->query("SELECT login FROM aws_access WHERE id='$id';");
784  while ($db->next_record()) {
785  $str.=" <user>".$db->Record["login"]."</user>\n";
786  }
787  $str.=" </domain>\n";
788  }
789  $str.="</aws>\n";
790  return $str;
791  }
792 
793 } /* CLASSE m_aws */
794 
795 ?>