| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | $Id: m_stats.php,v 1.3 2003/04/19 13:44:33 benjamin Exp $ |
|---|
| 4 | ---------------------------------------------------------------------- |
|---|
| 5 | AlternC - Web Hosting System |
|---|
| 6 | Copyright (C) 2002 by the AlternC Development Team. |
|---|
| 7 | http://alternc.org/ |
|---|
| 8 | ---------------------------------------------------------------------- |
|---|
| 9 | Based on: |
|---|
| 10 | Valentin Lacambre's web hosting softwares: http://altern.org/ |
|---|
| 11 | ---------------------------------------------------------------------- |
|---|
| 12 | LICENSE |
|---|
| 13 | |
|---|
| 14 | This program is free software; you can redistribute it and/or |
|---|
| 15 | modify it under the terms of the GNU General Public License (GPL) |
|---|
| 16 | as published by the Free Software Foundation; either version 2 |
|---|
| 17 | of the License, or (at your option) any later version. |
|---|
| 18 | |
|---|
| 19 | This program is distributed in the hope that it will be useful, |
|---|
| 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 22 | GNU General Public License for more details. |
|---|
| 23 | |
|---|
| 24 | To read the license please visit http://www.gnu.org/copyleft/gpl.html |
|---|
| 25 | ---------------------------------------------------------------------- |
|---|
| 26 | Original Author of file: Benjamin Sonntag |
|---|
| 27 | Purpose of file: Gestion des statistiques web par Webalizer. |
|---|
| 28 | ---------------------------------------------------------------------- |
|---|
| 29 | */ |
|---|
| 30 | /** |
|---|
| 31 | * Classe de gestion des statistiques web webalizer / apache des hébergés |
|---|
| 32 | * |
|---|
| 33 | * Cette classe permet de gérer les statistiques web générées par webalizer |
|---|
| 34 | * dans la langue de votre choix, ainsi que les fichiers logs bruts d'apache.<br> |
|---|
| 35 | * Copyleft {@link http://alternc.net/ AlternC Team} |
|---|
| 36 | * |
|---|
| 37 | * @copyright AlternC-Team 2002-11-01 http://alternc.net/ |
|---|
| 38 | * |
|---|
| 39 | */ |
|---|
| 40 | class m_stats { |
|---|
| 41 | |
|---|
| 42 | /** Membre actuellement connecté */ |
|---|
| 43 | var $uid=0; |
|---|
| 44 | |
|---|
| 45 | var $alternc_quota_name="stats"; |
|---|
| 46 | |
|---|
| 47 | /** Emplacement des fichiers de conf webalizer |
|---|
| 48 | * @access private |
|---|
| 49 | */ |
|---|
| 50 | var $CONFDIR="/etc/webalizer/"; |
|---|
| 51 | |
|---|
| 52 | /** Emplacement du fichier patron pour recopie. |
|---|
| 53 | * @access private |
|---|
| 54 | */ |
|---|
| 55 | var $TEMPLATEFILE="/etc/webalizer/template.conf"; |
|---|
| 56 | |
|---|
| 57 | /** Nom des langues disponibles */ |
|---|
| 58 | var $langname=array( |
|---|
| 59 | "FR"=>"Français", |
|---|
| 60 | "EN"=>"English" |
|---|
| 61 | ); |
|---|
| 62 | |
|---|
| 63 | /* ----------------------------------------------------------------- */ |
|---|
| 64 | /** |
|---|
| 65 | * Constructeur |
|---|
| 66 | */ |
|---|
| 67 | function m_stats($membre=0) { |
|---|
| 68 | $this->uid=$membre; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | /* ----------------------------------------------------------------- */ |
|---|
| 72 | /** |
|---|
| 73 | * Retourne un tableau contenant les jeux de statistiques d'un membre. |
|---|
| 74 | * |
|---|
| 75 | * @return array retourne un tableau indexé de tableaux associatif de la |
|---|
| 76 | * forme : |
|---|
| 77 | * $r[0-n]["id"] = numéros du jeu |
|---|
| 78 | * $r[0-n]["hostname"]= domaine concerné |
|---|
| 79 | * $r[0-n]["dir"]= Répertoire destination (dans le dossier du membre) |
|---|
| 80 | * $r[0-n]["lang"]= Langue de production des statistiques |
|---|
| 81 | */ |
|---|
| 82 | function get_list() { |
|---|
| 83 | global $db,$err; |
|---|
| 84 | $err->log("stats","get_list"); |
|---|
| 85 | $r=array(); |
|---|
| 86 | $db->query("SELECT id, hostname, dir, lang FROM stats WHERE uid=".$this->uid." ORDER BY hostname;"); |
|---|
| 87 | if ($db->num_rows()) { |
|---|
| 88 | while ($db->next_record()) { |
|---|
| 89 | // On passe /var/alternc/html/u/user |
|---|
| 90 | preg_match("/^\/var\/alternc\/html\/.\/[^\/]*\/(.*)/", $db->f("dir"),$match); |
|---|
| 91 | $r[]=array( |
|---|
| 92 | "id"=>$db->f("id"), |
|---|
| 93 | "hostname"=>$db->f("hostname"), |
|---|
| 94 | "lang"=>$db->f("lang"), |
|---|
| 95 | "dir"=>$match[1] |
|---|
| 96 | ); |
|---|
| 97 | } |
|---|
| 98 | return $r; |
|---|
| 99 | } else { |
|---|
| 100 | $err->raise("stats",1); |
|---|
| 101 | return false; |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | /* ----------------------------------------------------------------- */ |
|---|
| 106 | /** |
|---|
| 107 | * Retourne un tableau contenant les détails d'un jeu de statistiques |
|---|
| 108 | * d'un membre. |
|---|
| 109 | * |
|---|
| 110 | * @param integer $id Numéro du jeu de stats dont on veut les infos. |
|---|
| 111 | * @return array retourne un tableau associatif de la forme : |
|---|
| 112 | * $r["id"] = numéros du jeu |
|---|
| 113 | * $r["hostname"]= domaine concerné |
|---|
| 114 | * $r["dir"]= Répertoire destination (dans le dossier du membre) |
|---|
| 115 | * $r["lang"]= Langue de production des statistiques |
|---|
| 116 | */ |
|---|
| 117 | function get_stats_details($id) { |
|---|
| 118 | global $db,$err; |
|---|
| 119 | $err->log("stats","get_stats_details",$id); |
|---|
| 120 | $r=array(); |
|---|
| 121 | $db->query("SELECT id, hostname, dir, lang FROM stats WHERE uid=".$this->uid." AND id=$id;"); |
|---|
| 122 | if ($db->num_rows()) { |
|---|
| 123 | $db->next_record(); |
|---|
| 124 | // On passe /var/alternc/html/u/user |
|---|
| 125 | preg_match("/^\/var\/alternc\/html\/.\/[^\/]*\/(.*)/", $db->f("dir"),$match); |
|---|
| 126 | return array( |
|---|
| 127 | "id"=>$db->f("id"), |
|---|
| 128 | "hostname"=> $db->f("hostname"), |
|---|
| 129 | "lang"=>$db->f("lang"), |
|---|
| 130 | "dir"=>$match[1] |
|---|
| 131 | ); |
|---|
| 132 | } else { |
|---|
| 133 | $err->raise("stats",2); |
|---|
| 134 | return false; |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | /* ----------------------------------------------------------------- */ |
|---|
| 140 | /** Retourne la liste des domaines / sous-domaines autorisés pour le membre. |
|---|
| 141 | * |
|---|
| 142 | * @return array retourne un tableau indexé des domaines / sous-domaines utilisables. |
|---|
| 143 | */ |
|---|
| 144 | function host_list() { |
|---|
| 145 | global $db,$err; |
|---|
| 146 | $r=array(); |
|---|
| 147 | $db->query("SELECT domaine,sub FROM sub_domaines WHERE compte=".$this->uid." ORDER BY domaine,sub;"); |
|---|
| 148 | while ($db->next_record()) { |
|---|
| 149 | if ($db->f("sub")) { |
|---|
| 150 | $r[]=$db->f("sub").".".$db->f("domaine"); |
|---|
| 151 | } else { |
|---|
| 152 | $r[]=$db->f("domaine"); |
|---|
| 153 | } |
|---|
| 154 | } |
|---|
| 155 | return $r; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | /* ----------------------------------------------------------------- */ |
|---|
| 159 | /** |
|---|
| 160 | * Affiche des options select de la liste des noms de domaines autorisés pour |
|---|
| 161 | * le membre. sous forme de champs d'options (select) |
|---|
| 162 | */ |
|---|
| 163 | function select_host_list($current) { |
|---|
| 164 | global $db,$err; |
|---|
| 165 | $r=$this->host_list(); |
|---|
| 166 | reset($r); |
|---|
| 167 | while (list($key,$val)=each($r)) { |
|---|
| 168 | if ($current==$val) $c=" selected"; else $c=""; |
|---|
| 169 | echo "<option$c>$val</option>"; |
|---|
| 170 | } |
|---|
| 171 | return true; |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | /* ----------------------------------------------------------------- */ |
|---|
| 175 | /** |
|---|
| 176 | * Affiche des options select de la liste des langues autorisées pour |
|---|
| 177 | * le membre. sous forme de champs d'options (select) |
|---|
| 178 | */ |
|---|
| 179 | function select_lang_list($current) { |
|---|
| 180 | reset($this->langname); |
|---|
| 181 | while (list($key,$val)=each($this->langname)) { |
|---|
| 182 | if ($current==$val) $c=" selected"; else $c=""; |
|---|
| 183 | echo "<option value=\"$key\"$c>$val</option>"; |
|---|
| 184 | } |
|---|
| 185 | return true; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | /* ----------------------------------------------------------------- */ |
|---|
| 189 | /** |
|---|
| 190 | * Modifie un jeu de statistiques existant |
|---|
| 191 | * @param integer $id est le numéro du jeu de statistiques |
|---|
| 192 | * @param string $dir est un chemin relatif à "/var/alternc/html/u/user" |
|---|
| 193 | * @param string $stlang est la langue de production des statistiques (code à 2 lettres) |
|---|
| 194 | */ |
|---|
| 195 | function put_stats_details($id,$dir,$stlang) { |
|---|
| 196 | global $db,$err,$bro,$mem; |
|---|
| 197 | $err->log("stats","put_stats_details",$id); |
|---|
| 198 | $db->query("SELECT count(*) AS cnt FROM stats WHERE id=$id and uid=".$this->uid.";"); |
|---|
| 199 | $db->next_record(); |
|---|
| 200 | if (!$db->f("cnt")) { |
|---|
| 201 | $err->raise("stats",2); |
|---|
| 202 | return false; |
|---|
| 203 | } |
|---|
| 204 | $dir=$bro->convertabsolute($dir); |
|---|
| 205 | if (substr($dir,0,1)=="/") { |
|---|
| 206 | $dir=substr($dir,1); |
|---|
| 207 | } |
|---|
| 208 | // On a épuré $dir des problèmes eventuels ... On est en DESSOUS du dossier de l'utilisateur. |
|---|
| 209 | if (!$this->langname[$stlang]) { |
|---|
| 210 | $err->raise("stats",6); |
|---|
| 211 | return false; |
|---|
| 212 | } |
|---|
| 213 | $lo=$mem->user["login"]; |
|---|
| 214 | $l=substr($lo,0,1); |
|---|
| 215 | $db->query("UPDATE stats SET lang='$stlang', dir='/var/alternc/html/$l/$lo/$dir', uid=".$this->uid." WHERE id=$id;"); |
|---|
| 216 | $this->_createconf($id); |
|---|
| 217 | return true; |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | /* ----------------------------------------------------------------- */ |
|---|
| 221 | /** |
|---|
| 222 | * Efface un jeu de statistiques existant. |
|---|
| 223 | * @param integer $id est le numéro du jeu de statistiques à supprimer |
|---|
| 224 | * @return string le nom du domaine du jeu ainsi effacé, ou FALSE si une erreur est survenue. |
|---|
| 225 | */ |
|---|
| 226 | function delete_stats($id) { |
|---|
| 227 | global $db,$err,$quota; |
|---|
| 228 | $err->log("stats","delete_stats",$id); |
|---|
| 229 | $db->query("SELECT hostname FROM stats WHERE id=$id and uid=".$this->uid.";"); |
|---|
| 230 | if (!$db->num_rows()) { |
|---|
| 231 | $err->raise("stats",2); |
|---|
| 232 | return false; |
|---|
| 233 | } |
|---|
| 234 | $db->next_record(); |
|---|
| 235 | $this->_delconf($db->f("hostname")); |
|---|
| 236 | $db->query("DELETE FROM stats WHERE id=$id"); |
|---|
| 237 | $quota->dec("stats"); |
|---|
| 238 | return $name; |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | /* ----------------------------------------------------------------- */ |
|---|
| 242 | /** |
|---|
| 243 | * Cree un nouveau jeu de statistiques |
|---|
| 244 | * @param string $dir est le chemin d'accès racine du compte ftp dans le compte du membre |
|---|
| 245 | * @param string $lang est la langue choisie |
|---|
| 246 | * @param string $hostname est le nom de domaine sur lequel on fait des stats |
|---|
| 247 | * @return boolean TRUE si le jeu de stats a été créé avec succès, FALSE sinon. |
|---|
| 248 | */ |
|---|
| 249 | function add_stats($hostname,$dir,$lang) { |
|---|
| 250 | global $db,$err,$quota,$bro,$mem; |
|---|
| 251 | $err->log("stats","add_stats",$hostname); |
|---|
| 252 | $dir=$bro->convertabsolute($dir); |
|---|
| 253 | if (substr($dir,0,1)=="/") { |
|---|
| 254 | $dir=substr($dir,1); |
|---|
| 255 | } |
|---|
| 256 | // On a épuré $dir des problèmes eventuels ... On est en DESSOUS du dossier de l'utilisateur. |
|---|
| 257 | $r=$this->host_list(); |
|---|
| 258 | if (!in_array($hostname,$r) || $hostname=="") { |
|---|
| 259 | $err->raise("stats",3); |
|---|
| 260 | return false; |
|---|
| 261 | } |
|---|
| 262 | if (!$this->langname[$lang]) { |
|---|
| 263 | $err->raise("stats",6); |
|---|
| 264 | return false; |
|---|
| 265 | } |
|---|
| 266 | $lo=$mem->user; |
|---|
| 267 | $l=substr($lo,0,1); |
|---|
| 268 | // Le compte n'existe pas, on le crée. |
|---|
| 269 | if ($quota->cancreate("stats")) { |
|---|
| 270 | $quota->inc("stats"); |
|---|
| 271 | $db->query("INSERT INTO stats (hostname,lang,dir,uid) VALUES ('$hostname','$lang','/var/alternc/html/$l/$lo/$dir',".$this->uid.")"); |
|---|
| 272 | $this->_createconf($db->lastid()); |
|---|
| 273 | return true; |
|---|
| 274 | } else { |
|---|
| 275 | $err->raise("stats",5); |
|---|
| 276 | return false; |
|---|
| 277 | } |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | /* ----------------------------------------------------------------- */ |
|---|
| 281 | /** |
|---|
| 282 | * Fonction appellée par m_dom lorsqu'un domaine est supprimé. |
|---|
| 283 | * @param string $dom est le domaine à supprimer. |
|---|
| 284 | */ |
|---|
| 285 | function alternc_del_domain($dom) { |
|---|
| 286 | global $db,$quota,$err; |
|---|
| 287 | $err->log("stats","del_dom",$dom); |
|---|
| 288 | // on remonte les quotas ;) |
|---|
| 289 | $db=new DB_System(); |
|---|
| 290 | $db->query("SELECT * FROM stats WHERE uid=".$this->uid." AND hostname like '%$dom'"); |
|---|
| 291 | $cnt=0; |
|---|
| 292 | $t=array(); |
|---|
| 293 | while ($db->next_record()) { |
|---|
| 294 | $cnt++; |
|---|
| 295 | $t[]=$db->f("hostname"); |
|---|
| 296 | } |
|---|
| 297 | $r=$quota->getquota("stats"); |
|---|
| 298 | $quota->setquota("stats",$r["u"]-$cnt,1); |
|---|
| 299 | // on détruit les jeux de stats associés au préfixe correspondant : |
|---|
| 300 | for($i=0;$i<cnt;$i++) { |
|---|
| 301 | $db->query("DELETE FROM stats WHERE uid=".$this->uid." AND hostname='".$t[$i]."';"); |
|---|
| 302 | $this->_delconf($t[$i]); |
|---|
| 303 | } |
|---|
| 304 | // Suppression des stats apache brutes : |
|---|
| 305 | $db->query("SELECT * FROM stats2 WHERE mid=".$this->uid." AND hostname like '%$dom'"); |
|---|
| 306 | $cnt=0; |
|---|
| 307 | $t=array(); |
|---|
| 308 | while ($db->next_record()) { |
|---|
| 309 | $cnt++; |
|---|
| 310 | $t[]=$db->f("hostname"); |
|---|
| 311 | } |
|---|
| 312 | $r=$quota->getquota("stats"); |
|---|
| 313 | $quota->setquota("stats",$r["u"]-$cnt,1); |
|---|
| 314 | // on détruit les jeux de stats associés au préfixe correspondant : |
|---|
| 315 | for($i=0;$i<cnt;$i++) { |
|---|
| 316 | $db->query("DELETE FROM stats2 WHERE uid=".$this->uid." AND hostname='".$t[$i]."';"); |
|---|
| 317 | } |
|---|
| 318 | return true; |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | /* ----------------------------------------------------------------- */ |
|---|
| 322 | /** |
|---|
| 323 | * Recalcule le quota complet de l'utilisateur courant, ou de l'utilisateur $id |
|---|
| 324 | * @param integer $id Numéro de l'utilisateur (facultatif) |
|---|
| 325 | */ |
|---|
| 326 | function alternc_quota_check($id=-1) { |
|---|
| 327 | global $db,$err,$quota; |
|---|
| 328 | $err->log("stats","checkquota"); |
|---|
| 329 | if (!$id==-1) $id=$this->uid; |
|---|
| 330 | $db->query("SELECT COUNT(*) AS cnt FROM stats WHERE uid=$id"); |
|---|
| 331 | $db->next_record(); |
|---|
| 332 | $ss=intval($db->f("cnt")); |
|---|
| 333 | $db->query("SELECT COUNT(*) AS cnt FROM stats2 WHERE mid=$id"); |
|---|
| 334 | $db->next_record(); |
|---|
| 335 | $ss+=intval($db->f("cnt")); |
|---|
| 336 | $quota->setquota("stats",$ss,1,$id); |
|---|
| 337 | return true; |
|---|
| 338 | } |
|---|
| 339 | |
|---|
| 340 | /* ----------------------------------------------------------------- */ |
|---|
| 341 | /** Retourne un tableau contenant les jeux de stats APACHE |
|---|
| 342 | * d'un membre. Le tableau est de la forme |
|---|
| 343 | * $r[0-n]["id"] = numéros du jeu |
|---|
| 344 | * $r[0-n]["hostname"]= domaine concerné |
|---|
| 345 | * $r[0-n]["folder"]= Répertoire destination (dans le dossier du membre) |
|---|
| 346 | * |
|---|
| 347 | * @return array Tableau de résultat, ou FALSE si une erreur est survenue |
|---|
| 348 | */ |
|---|
| 349 | function get_list_raw() { |
|---|
| 350 | global $db,$err; |
|---|
| 351 | $err->log("stats","get_list_raw"); |
|---|
| 352 | $r=array(); |
|---|
| 353 | $db->query("SELECT id, hostname, folder FROM stats2 WHERE mid=".$this->uid." ORDER BY hostname;"); |
|---|
| 354 | if ($db->num_rows()) { |
|---|
| 355 | while ($db->next_record()) { |
|---|
| 356 | // On passe /var/alternc/html/u/user |
|---|
| 357 | preg_match("/^\/var\/alternc\/html\/.\/[^\/]*\/(.*)/", $db->f("folder"),$match); |
|---|
| 358 | $r[]=array( |
|---|
| 359 | "id"=>$db->f("id"), |
|---|
| 360 | "hostname"=>$db->f("hostname"), |
|---|
| 361 | "folder"=>$match[1] |
|---|
| 362 | ); |
|---|
| 363 | } |
|---|
| 364 | return $r; |
|---|
| 365 | } else { |
|---|
| 366 | $err->raise("stats",7); |
|---|
| 367 | return false; |
|---|
| 368 | } |
|---|
| 369 | } |
|---|
| 370 | |
|---|
| 371 | /* ----------------------------------------------------------------- */ |
|---|
| 372 | /** |
|---|
| 373 | * retourne un tableau contenant les details d'un |
|---|
| 374 | * jeu de statistiques apache brut géré par le membre. |
|---|
| 375 | * $id est un id de jeu de stats. Retourne un tableau associatif sous la forme : |
|---|
| 376 | * "id" = numéro du jeu |
|---|
| 377 | * "hostname"= domaine concerné |
|---|
| 378 | * "folder"= Répertoire destination (dans le dossier du membre) |
|---|
| 379 | * @param string $id Numéro du jeu de stats brutes dont on veut les détails |
|---|
| 380 | * @return array Tableau contenant les détails du jeu, ou FALSE en cas d'erreur |
|---|
| 381 | */ |
|---|
| 382 | function get_stats_details_raw($id) { |
|---|
| 383 | global $db,$err; |
|---|
| 384 | $err->log("stats","get_stats_details_raw",$id); |
|---|
| 385 | $r=array(); |
|---|
| 386 | $db->query("SELECT id, hostname, folder FROM stats2 WHERE mid=".$this->uid." AND id=$id;"); |
|---|
| 387 | if ($db->num_rows()) { |
|---|
| 388 | $db->next_record(); |
|---|
| 389 | // On passe /var/alternc/html/u/user |
|---|
| 390 | preg_match("/^\/var\/alternc\/html\/.\/[^\/]*\/(.*)/", $db->f("folder"),$match); |
|---|
| 391 | return array( |
|---|
| 392 | "id"=>$db->f("id"), |
|---|
| 393 | "hostname"=> $db->f("hostname"), |
|---|
| 394 | "folder"=>$match[1] |
|---|
| 395 | ); |
|---|
| 396 | } else { |
|---|
| 397 | $err->raise("stats",8); |
|---|
| 398 | return false; |
|---|
| 399 | } |
|---|
| 400 | } |
|---|
| 401 | |
|---|
| 402 | /* ----------------------------------------------------------------- */ |
|---|
| 403 | /** |
|---|
| 404 | * Modifie un jeu de statistiques apache brutes existant |
|---|
| 405 | * $id est le numéro du jeu de statistiques |
|---|
| 406 | * $folder est un chemin relatif à "/var/alternc/html/u/user" |
|---|
| 407 | * @param integer $id Numéro du jeu de stats brutes à modifier |
|---|
| 408 | * @param string $folder Dossier destination des stats |
|---|
| 409 | * @return boolean TRUE si le jeu a été modifié, FALSE sinon. |
|---|
| 410 | */ |
|---|
| 411 | function put_stats_details_raw($id,$folder) { |
|---|
| 412 | global $db,$err,$bro,$mem; |
|---|
| 413 | $err->log("stats","put_stats_details_raw",$id); |
|---|
| 414 | $db->query("SELECT count(*) AS cnt FROM stats2 WHERE id=$id and mid=".$this->uid.";"); |
|---|
| 415 | $db->next_record(); |
|---|
| 416 | if (!$db->f("cnt")) { |
|---|
| 417 | $err->raise("stats",8); |
|---|
| 418 | return false; |
|---|
| 419 | } |
|---|
| 420 | // TODO : replace with ,1 on convertabsolute call, and delete "/Var/alternc.../" at the query. |
|---|
| 421 | $folder=$bro->convertabsolute($folder); |
|---|
| 422 | if (substr($folder,0,1)=="/") { |
|---|
| 423 | $folder=substr($folder,1); |
|---|
| 424 | } |
|---|
| 425 | $lo=$mem->user["login"]; |
|---|
| 426 | $l=substr($lo,0,1); |
|---|
| 427 | $db->query("UPDATE stats2 SET folder='/var/alternc/html/$l/$lo/$folder', mid=".$this->uid." WHERE id=$id;"); |
|---|
| 428 | return true; |
|---|
| 429 | } |
|---|
| 430 | |
|---|
| 431 | /* ----------------------------------------------------------------- */ |
|---|
| 432 | /** |
|---|
| 433 | * Efface un jeu de statistiques apache brut existant |
|---|
| 434 | * @param integer $id est un id de jeu de statistiques |
|---|
| 435 | * @return boolean TRUE si le jeu a été effacé, FALSE sinon. |
|---|
| 436 | */ |
|---|
| 437 | function delete_stats_raw($id) { |
|---|
| 438 | global $db,$err,$quota; |
|---|
| 439 | $err->log("stats","delete_stats_raw",$id); |
|---|
| 440 | $db->query("SELECT hostname FROM stats2 WHERE id=$id and mid=".$this->uid.";"); |
|---|
| 441 | if (!$db->num_rows()) { |
|---|
| 442 | $err->raise("stats",8); |
|---|
| 443 | return false; |
|---|
| 444 | } |
|---|
| 445 | $db->next_record(); |
|---|
| 446 | $db->query("DELETE FROM stats2 WHERE id=$id"); |
|---|
| 447 | $quota->dec("stats"); |
|---|
| 448 | return $name; |
|---|
| 449 | } |
|---|
| 450 | |
|---|
| 451 | /* ----------------------------------------------------------------- */ |
|---|
| 452 | /** |
|---|
| 453 | * Crée un nouveau jeu de statistiques brutes apache. |
|---|
| 454 | * @param string $hostname est le domaine concerné |
|---|
| 455 | * @param string $dir est le chemin d'accès racine des stats dans le compte |
|---|
| 456 | * @return boolean TRUE si le jeu a été créé, FALSE si un erreur est survenue |
|---|
| 457 | */ |
|---|
| 458 | function add_stats_raw($hostname,$dir) { |
|---|
| 459 | global $db,$err,$quota,$bro,$mem; |
|---|
| 460 | $err->log("stats","add_stats_raw",$hostname); |
|---|
| 461 | // TODO : utiliser le second param de convertabsolute pour simplification. |
|---|
| 462 | $dir=$bro->convertabsolute($dir); |
|---|
| 463 | if (substr($dir,0,1)=="/") { |
|---|
| 464 | $dir=substr($dir,1); |
|---|
| 465 | } |
|---|
| 466 | $lo=$mem->user["login"]; |
|---|
| 467 | $l=substr($lo,0,1); |
|---|
| 468 | if ($quota->cancreate("stats")) { |
|---|
| 469 | $quota->inc("stats"); |
|---|
| 470 | $db->query("INSERT INTO stats2 (hostname,folder,mid) VALUES ('$hostname','/var/alternc/html/$l/$lo/$dir',".$this->uid.")"); |
|---|
| 471 | return true; |
|---|
| 472 | } else { |
|---|
| 473 | $err->raise("stats",5); |
|---|
| 474 | return false; |
|---|
| 475 | } |
|---|
| 476 | } |
|---|
| 477 | |
|---|
| 478 | /* ----------------------------------------------------------------- */ |
|---|
| 479 | /** Effacement du fichier de conf webalizer du domaine $hostname |
|---|
| 480 | * @access private |
|---|
| 481 | */ |
|---|
| 482 | function _delconf($hostname) { |
|---|
| 483 | @unlink($this->CONFDIR."/".$hostname.".conf"); |
|---|
| 484 | } |
|---|
| 485 | |
|---|
| 486 | /* ----------------------------------------------------------------- */ |
|---|
| 487 | /** Création du fichier de configuration Webalizer du domaine $id |
|---|
| 488 | * @access private |
|---|
| 489 | */ |
|---|
| 490 | function _createconf($id) { |
|---|
| 491 | global $db,$err; |
|---|
| 492 | $s=implode("",file($this->TEMPLATEFILE)); |
|---|
| 493 | $db->query("SELECT * FROM stats WHERE id=$id AND uid=".$this->uid.";"); |
|---|
| 494 | if (!$db->num_rows()) { |
|---|
| 495 | $err->raise("stats",2); |
|---|
| 496 | return false; |
|---|
| 497 | } |
|---|
| 498 | $db->next_record(); |
|---|
| 499 | $s=str_replace("%OUTPUTDIR%",$db->f("dir"),$s); |
|---|
| 500 | $s=str_replace("%HOSTNAME%",$db->f("hostname"),$s); |
|---|
| 501 | $f=fopen($this->CONFDIR."/".$db->f("hostname").".conf","wb"); |
|---|
| 502 | fputs($f,$s,strlen($s)); |
|---|
| 503 | fclose($f); |
|---|
| 504 | } |
|---|
| 505 | |
|---|
| 506 | } /* CLASSE m_stats */ |
|---|
| 507 | |
|---|
| 508 | ?> |
|---|