| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | $Id: m_sta2.php,v 1.2 2004/05/27 08:02:15 anonymous 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_sta2 { |
|---|
| 41 | |
|---|
| 42 | /* ----------------------------------------------------------------- */ |
|---|
| 43 | /** |
|---|
| 44 | * Constructeur |
|---|
| 45 | */ |
|---|
| 46 | function m_sta2() { |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | /* ----------------------------------------------------------------- */ |
|---|
| 50 | /** |
|---|
| 51 | * Nom du quota |
|---|
| 52 | */ |
|---|
| 53 | function alternc_quota_names() { |
|---|
| 54 | return "sta2"; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | /* ----------------------------------------------------------------- */ |
|---|
| 59 | /** Retourne la liste des domaines / sous-domaines autorisés pour le membre. |
|---|
| 60 | * |
|---|
| 61 | * @return array retourne un tableau indexé des domaines / sous-domaines utilisables. |
|---|
| 62 | */ |
|---|
| 63 | function host_list() { |
|---|
| 64 | global $db,$err,$cuid; |
|---|
| 65 | $r=array(); |
|---|
| 66 | $db->query("SELECT domaine,sub FROM sub_domaines WHERE compte='$cuid' ORDER BY domaine,sub;"); |
|---|
| 67 | while ($db->next_record()) { |
|---|
| 68 | if ($db->f("sub")) { |
|---|
| 69 | $r[]=$db->f("sub").".".$db->f("domaine"); |
|---|
| 70 | } else { |
|---|
| 71 | $r[]=$db->f("domaine"); |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | return $r; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | /* ----------------------------------------------------------------- */ |
|---|
| 78 | /** |
|---|
| 79 | * Affiche des options select de la liste des noms de domaines autorisés pour |
|---|
| 80 | * le membre. sous forme de champs d'options (select) |
|---|
| 81 | */ |
|---|
| 82 | function select_host_list($current) { |
|---|
| 83 | $r=$this->host_list(); |
|---|
| 84 | reset($r); |
|---|
| 85 | while (list($key,$val)=each($r)) { |
|---|
| 86 | if ($current==$val) $c=" selected=\"selected\""; else $c=""; |
|---|
| 87 | echo "<option$c>$val</option>"; |
|---|
| 88 | } |
|---|
| 89 | return true; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | function alternc_del_member() { |
|---|
| 93 | global $db,$quota,$err,$cuid; |
|---|
| 94 | $err->log("sta2","del_member"); |
|---|
| 95 | $db->query("DELETE FROM stats2 WHERE mid='$cuid';"); |
|---|
| 96 | return true; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | /* ----------------------------------------------------------------- */ |
|---|
| 100 | /** |
|---|
| 101 | * Fonction appellée par m_dom lorsqu'un domaine est supprimé. |
|---|
| 102 | * @param string $dom est le domaine à supprimer. |
|---|
| 103 | */ |
|---|
| 104 | function alternc_del_domain($dom) { |
|---|
| 105 | global $db,$quota,$err,$cuid; |
|---|
| 106 | $err->log("sta2","del_dom",$dom); |
|---|
| 107 | // Suppression des stats apache brutes : |
|---|
| 108 | $db->query("SELECT * FROM stats2 WHERE mid='$cuid' AND hostname like '%$dom'"); |
|---|
| 109 | $cnt=0; |
|---|
| 110 | $t=array(); |
|---|
| 111 | while ($db->next_record()) { |
|---|
| 112 | $cnt++; |
|---|
| 113 | $t[]=$db->f("hostname"); |
|---|
| 114 | } |
|---|
| 115 | $r=$quota->getquota("sta2"); |
|---|
| 116 | $quota->setquota("sta2",$r["u"]-$cnt,1); |
|---|
| 117 | // on détruit les jeux de stats associés au préfixe correspondant : |
|---|
| 118 | for($i=0;$i<cnt;$i++) { |
|---|
| 119 | $db->query("DELETE FROM stats2 WHERE mid='$cuid' AND hostname='".$t[$i]."';"); |
|---|
| 120 | } |
|---|
| 121 | return true; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | /* ----------------------------------------------------------------- */ |
|---|
| 125 | /** |
|---|
| 126 | * Recalcule le quota complet de l'utilisateur courant, ou de l'utilisateur $id |
|---|
| 127 | * @param integer $id Numéro de l'utilisateur (facultatif) |
|---|
| 128 | */ |
|---|
| 129 | function alternc_quota_check() { |
|---|
| 130 | global $db,$err,$quota,$cuid; |
|---|
| 131 | $err->log("sta2","checkquota"); |
|---|
| 132 | $db->query("SELECT COUNT(*) AS cnt FROM stats2 WHERE mid='$cuid'"); |
|---|
| 133 | $db->next_record(); |
|---|
| 134 | $ss+=intval($db->f("cnt")); |
|---|
| 135 | $quota->setquota("sta2",$ss,1); |
|---|
| 136 | return true; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | /* ----------------------------------------------------------------- */ |
|---|
| 140 | /** Retourne un tableau contenant les jeux de stats APACHE |
|---|
| 141 | * d'un membre. Le tableau est de la forme |
|---|
| 142 | * $r[0-n]["id"] = numéros du jeu |
|---|
| 143 | * $r[0-n]["hostname"]= domaine concerné |
|---|
| 144 | * $r[0-n]["folder"]= Répertoire destination (dans le dossier du membre) |
|---|
| 145 | * |
|---|
| 146 | * @return array Tableau de résultat, ou FALSE si une erreur est survenue |
|---|
| 147 | */ |
|---|
| 148 | function get_list_raw() { |
|---|
| 149 | global $db,$err,$cuid; |
|---|
| 150 | $err->log("stats","get_list_raw"); |
|---|
| 151 | $r=array(); |
|---|
| 152 | $db->query("SELECT id, hostname, folder FROM stats2 WHERE mid='$cuid' ORDER BY hostname;"); |
|---|
| 153 | if ($db->num_rows()) { |
|---|
| 154 | while ($db->next_record()) { |
|---|
| 155 | // On passe /var/alternc/html/u/user |
|---|
| 156 | preg_match("/^\/var\/alternc\/html\/.\/[^\/]*\/(.*)/", $db->f("folder"),$match); |
|---|
| 157 | $r[]=array( |
|---|
| 158 | "id"=>$db->f("id"), |
|---|
| 159 | "hostname"=>$db->f("hostname"), |
|---|
| 160 | "folder"=>$match[1] |
|---|
| 161 | ); |
|---|
| 162 | } |
|---|
| 163 | return $r; |
|---|
| 164 | } else { |
|---|
| 165 | $err->raise("stats",2); |
|---|
| 166 | return false; |
|---|
| 167 | } |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | /* ----------------------------------------------------------------- */ |
|---|
| 171 | /** |
|---|
| 172 | * retourne un tableau contenant les details d'un |
|---|
| 173 | * jeu de statistiques apache brut géré par le membre. |
|---|
| 174 | * $id est un id de jeu de stats. Retourne un tableau associatif sous la forme : |
|---|
| 175 | * "id" = numéro du jeu |
|---|
| 176 | * "hostname"= domaine concerné |
|---|
| 177 | * "folder"= Répertoire destination (dans le dossier du membre) |
|---|
| 178 | * @param string $id Numéro du jeu de stats brutes dont on veut les détails |
|---|
| 179 | * @return array Tableau contenant les détails du jeu, ou FALSE en cas d'erreur |
|---|
| 180 | */ |
|---|
| 181 | function get_stats_details_raw($id) { |
|---|
| 182 | global $db,$err,$cuid; |
|---|
| 183 | $err->log("stats","get_stats_details_raw",$id); |
|---|
| 184 | $r=array(); |
|---|
| 185 | $db->query("SELECT id, hostname, folder FROM stats2 WHERE mid='$cuid' AND id='$id';"); |
|---|
| 186 | if ($db->num_rows()) { |
|---|
| 187 | $db->next_record(); |
|---|
| 188 | // On passe /var/alternc/html/u/user |
|---|
| 189 | preg_match("/^\/var\/alternc\/html\/.\/[^\/]*\/(.*)/", $db->f("folder"),$match); |
|---|
| 190 | return array( |
|---|
| 191 | "id"=>$db->f("id"), |
|---|
| 192 | "hostname"=> $db->f("hostname"), |
|---|
| 193 | "folder"=>$match[1] |
|---|
| 194 | ); |
|---|
| 195 | } else { |
|---|
| 196 | $err->raise("stats",3); |
|---|
| 197 | return false; |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | /* ----------------------------------------------------------------- */ |
|---|
| 202 | /** |
|---|
| 203 | * Modifie un jeu de statistiques apache brutes existant |
|---|
| 204 | * $id est le numéro du jeu de statistiques |
|---|
| 205 | * $folder est un chemin relatif à "/var/alternc/html/u/user" |
|---|
| 206 | * @param integer $id Numéro du jeu de stats brutes à modifier |
|---|
| 207 | * @param string $folder Dossier destination des stats |
|---|
| 208 | * @return boolean TRUE si le jeu a été modifié, FALSE sinon. |
|---|
| 209 | */ |
|---|
| 210 | function put_stats_details_raw($id,$folder) { |
|---|
| 211 | global $db,$err,$bro,$mem,$cuid; |
|---|
| 212 | $err->log("stats","put_stats_details_raw",$id); |
|---|
| 213 | $db->query("SELECT count(*) AS cnt FROM stats2 WHERE id='$id' and mid='$cuid';"); |
|---|
| 214 | $db->next_record(); |
|---|
| 215 | if (!$db->f("cnt")) { |
|---|
| 216 | $err->raise("stats",3); |
|---|
| 217 | return false; |
|---|
| 218 | } |
|---|
| 219 | // TODO : replace with ,1 on convertabsolute call, and delete "/Var/alternc.../" at the query. |
|---|
| 220 | $folder=$bro->convertabsolute($folder); |
|---|
| 221 | if (substr($folder,0,1)=="/") { |
|---|
| 222 | $folder=substr($folder,1); |
|---|
| 223 | } |
|---|
| 224 | $lo=$mem->user["login"]; |
|---|
| 225 | $l=substr($lo,0,1); |
|---|
| 226 | $db->query("UPDATE stats2 SET folder='/var/alternc/html/$l/$lo/$folder', mid='$cuid' WHERE id='$id';"); |
|---|
| 227 | return true; |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | /* ----------------------------------------------------------------- */ |
|---|
| 231 | /** |
|---|
| 232 | * Efface un jeu de statistiques apache brut existant |
|---|
| 233 | * @param integer $id est un id de jeu de statistiques |
|---|
| 234 | * @return boolean TRUE si le jeu a été effacé, FALSE sinon. |
|---|
| 235 | */ |
|---|
| 236 | function delete_stats_raw($id) { |
|---|
| 237 | global $db,$err,$quota,$cuid; |
|---|
| 238 | $err->log("stats","delete_stats_raw",$id); |
|---|
| 239 | $db->query("SELECT hostname FROM stats2 WHERE id='$id' and mid='$cuid';"); |
|---|
| 240 | if (!$db->num_rows()) { |
|---|
| 241 | $err->raise("stats",3); |
|---|
| 242 | return false; |
|---|
| 243 | } |
|---|
| 244 | $db->next_record(); |
|---|
| 245 | $db->query("DELETE FROM stats2 WHERE id='$id'"); |
|---|
| 246 | $quota->dec("stats"); |
|---|
| 247 | return true; |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | /* ----------------------------------------------------------------- */ |
|---|
| 251 | /** |
|---|
| 252 | * Crée un nouveau jeu de statistiques brutes apache. |
|---|
| 253 | * @param string $hostname est le domaine concerné |
|---|
| 254 | * @param string $dir est le chemin d'accès racine des stats dans le compte |
|---|
| 255 | * @return boolean TRUE si le jeu a été créé, FALSE si un erreur est survenue |
|---|
| 256 | */ |
|---|
| 257 | function add_stats_raw($hostname,$dir) { |
|---|
| 258 | global $db,$err,$quota,$bro,$mem,$cuid; |
|---|
| 259 | $err->log("stats","add_stats_raw",$hostname); |
|---|
| 260 | // TODO : utiliser le second param de convertabsolute pour simplification. |
|---|
| 261 | $dir=$bro->convertabsolute($dir); |
|---|
| 262 | if (substr($dir,0,1)=="/") { |
|---|
| 263 | $dir=substr($dir,1); |
|---|
| 264 | } |
|---|
| 265 | $lo=$mem->user["login"]; |
|---|
| 266 | $l=substr($lo,0,1); |
|---|
| 267 | if ($quota->cancreate("stats")) { |
|---|
| 268 | $quota->inc("stats"); |
|---|
| 269 | $db->query("INSERT INTO stats2 (hostname,folder,mid) VALUES ('$hostname','/var/alternc/html/$l/$lo/$dir','$cuid')"); |
|---|
| 270 | return true; |
|---|
| 271 | } else { |
|---|
| 272 | $err->raise("stats",1); |
|---|
| 273 | return false; |
|---|
| 274 | } |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | } /* CLASSE m_sta2 */ |
|---|
| 278 | |
|---|
| 279 | ?> |
|---|