| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
class m_sta2 { |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
/** |
|---|
| 45 |
* Constructor, dummy |
|---|
| 46 |
*/ |
|---|
| 47 |
function m_sta2() { |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
/** Hook function that returns the quota names for this class |
|---|
| 52 |
* |
|---|
| 53 |
* @return string the quota names for this class |
|---|
| 54 |
*/ |
|---|
| 55 |
function alternc_quota_names() { |
|---|
| 56 |
return "sta2"; |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
/** Returns the list of domains and/or subdomains for this account |
|---|
| 62 |
* |
|---|
| 63 |
* @return array returns an array with all the domains / subdomains for this account. |
|---|
| 64 |
*/ |
|---|
| 65 |
function host_list() { |
|---|
| 66 |
global $db,$err,$cuid; |
|---|
| 67 |
$r=array(); |
|---|
| 68 |
$db->query("SELECT domaine,sub FROM sub_domaines WHERE compte='$cuid' ORDER BY domaine,sub;"); |
|---|
| 69 |
while ($db->next_record()) { |
|---|
| 70 |
if ($db->f("sub")) { |
|---|
| 71 |
$r[]=$db->f("sub").".".$db->f("domaine"); |
|---|
| 72 |
} else { |
|---|
| 73 |
$r[]=$db->f("domaine"); |
|---|
| 74 |
} |
|---|
| 75 |
} |
|---|
| 76 |
return $r; |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
/** Draw option html tags of ths allowed domains / subdomains for the account. |
|---|
| 81 |
* |
|---|
| 82 |
* @param $current string The current selected value in the list |
|---|
| 83 |
*/ |
|---|
| 84 |
function select_host_list($current) { |
|---|
| 85 |
$r=$this->host_list(); |
|---|
| 86 |
reset($r); |
|---|
| 87 |
while (list($key,$val)=each($r)) { |
|---|
| 88 |
if ($current==$val) $c=" selected=\"selected\""; else $c=""; |
|---|
| 89 |
echo "<option$c>$val</option>"; |
|---|
| 90 |
} |
|---|
| 91 |
return true; |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
/** Hook function that delete a user's raw stats. |
|---|
| 96 |
*/ |
|---|
| 97 |
function alternc_del_member() { |
|---|
| 98 |
global $db,$err,$cuid; |
|---|
| 99 |
$err->log("sta2","del_member"); |
|---|
| 100 |
$db->query("DELETE FROM stats2 WHERE mid='$cuid';"); |
|---|
| 101 |
return true; |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
/** Hook function that delete a user's domain, called by m_dom. |
|---|
| 106 |
* @param string $dom is the domain that is to be deleted. |
|---|
| 107 |
*/ |
|---|
| 108 |
function alternc_del_domain($dom) { |
|---|
| 109 |
global $db,$err,$cuid; |
|---|
| 110 |
$err->log("sta2","del_dom",$dom); |
|---|
| 111 |
|
|---|
| 112 |
$db->query("SELECT * FROM stats2 WHERE mid='$cuid' AND hostname like '%$dom'"); |
|---|
| 113 |
$cnt=0; |
|---|
| 114 |
$t=array(); |
|---|
| 115 |
while ($db->next_record()) { |
|---|
| 116 |
$cnt++; |
|---|
| 117 |
$t[]=$db->f("hostname"); |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
for($i=0;$i<cnt;$i++) { |
|---|
| 121 |
$db->query("DELETE FROM stats2 WHERE mid='$cuid' AND hostname='".$t[$i]."';"); |
|---|
| 122 |
} |
|---|
| 123 |
return true; |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
/** Returns an array with the user's raw stat list |
|---|
| 128 |
* The returned array is as follow : |
|---|
| 129 |
* $r[0-n]["id"] = Id of the raw stat set. |
|---|
| 130 |
* $r[0-n]["hostname"]= Domain |
|---|
| 131 |
* $r[0-n]["folder"]= Destination's folder (in the user space) |
|---|
| 132 |
* |
|---|
| 133 |
* @return array Returns the array or FALSE if an error occured. |
|---|
| 134 |
*/ |
|---|
| 135 |
function get_list_raw() { |
|---|
| 136 |
global $db,$err,$cuid; |
|---|
| 137 |
$err->log("sta2","get_list_raw"); |
|---|
| 138 |
$r=array(); |
|---|
| 139 |
$db->query("SELECT id, hostname, folder FROM stats2 WHERE mid='$cuid' ORDER BY hostname;"); |
|---|
| 140 |
if ($db->num_rows()) { |
|---|
| 141 |
while ($db->next_record()) { |
|---|
| 142 |
|
|---|
| 143 |
preg_match("/^\/var\/alternc\/html\/.\/[^\/]*\/(.*)/", $db->f("folder"),$match); |
|---|
| 144 |
$r[]=array( |
|---|
| 145 |
"id"=>$db->f("id"), |
|---|
| 146 |
"hostname"=>$db->f("hostname"), |
|---|
| 147 |
"folder"=>$match[1] |
|---|
| 148 |
); |
|---|
| 149 |
} |
|---|
| 150 |
return $r; |
|---|
| 151 |
} else { |
|---|
| 152 |
$err->raise("sta2",2); |
|---|
| 153 |
return false; |
|---|
| 154 |
} |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
/** Get the details of a raw statistic set. |
|---|
| 159 |
* |
|---|
| 160 |
* This function returns the details of a raw statistic set (raw logs) |
|---|
| 161 |
* The returned value is an associative array as follow : |
|---|
| 162 |
* $ret["id"] = raw stat id. |
|---|
| 163 |
* $ret["hostname"] = the domain we get the raw log. |
|---|
| 164 |
* $ret["folder"] = the destination folder for the logs (inside the user space) |
|---|
| 165 |
* @param $id string The raw stat number we want details of. |
|---|
| 166 |
* @return array returns an array with the raw log parameters or FALSE if an error occured. |
|---|
| 167 |
*/ |
|---|
| 168 |
function get_stats_details_raw($id) { |
|---|
| 169 |
global $db,$err,$cuid; |
|---|
| 170 |
$err->log("sta2","get_stats_details_raw",$id); |
|---|
| 171 |
$r=array(); |
|---|
| 172 |
$db->query("SELECT id, hostname, folder FROM stats2 WHERE mid='$cuid' AND id='$id';"); |
|---|
| 173 |
if ($db->num_rows()) { |
|---|
| 174 |
$db->next_record(); |
|---|
| 175 |
|
|---|
| 176 |
preg_match("/^\/var\/alternc\/html\/.\/[^\/]*\/(.*)/", $db->f("folder"),$match); |
|---|
| 177 |
return array( |
|---|
| 178 |
"id"=>$db->f("id"), |
|---|
| 179 |
"hostname"=> $db->f("hostname"), |
|---|
| 180 |
"folder"=>$match[1] |
|---|
| 181 |
); |
|---|
| 182 |
} else { |
|---|
| 183 |
$err->raise("sta2",3); |
|---|
| 184 |
return false; |
|---|
| 185 |
} |
|---|
| 186 |
} |
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
/** Edit a raw statistic set. |
|---|
| 190 |
* |
|---|
| 191 |
* This function edit a raw statistic set. |
|---|
| 192 |
* $folder is the new destination folder inside the user space where the log |
|---|
| 193 |
* file will be put. |
|---|
| 194 |
* @param $id integer The raw statistic number we are changing |
|---|
| 195 |
* @param $folder string new destination folder |
|---|
| 196 |
* @return boolean TRUE if the set has been changed, FALSE if an error occured. |
|---|
| 197 |
*/ |
|---|
| 198 |
function put_stats_details_raw($id,$folder) { |
|---|
| 199 |
global $db,$err,$bro,$mem,$cuid; |
|---|
| 200 |
$err->log("sta2","put_stats_details_raw",$id); |
|---|
| 201 |
$db->query("SELECT count(*) AS cnt FROM stats2 WHERE id='$id' and mid='$cuid';"); |
|---|
| 202 |
$db->next_record(); |
|---|
| 203 |
if (!$db->f("cnt")) { |
|---|
| 204 |
$err->raise("sta2",3); |
|---|
| 205 |
return false; |
|---|
| 206 |
} |
|---|
| 207 |
|
|---|
| 208 |
$folder=$bro->convertabsolute($folder); |
|---|
| 209 |
if (substr($folder,0,1)=="/") { |
|---|
| 210 |
$folder=substr($folder,1); |
|---|
| 211 |
} |
|---|
| 212 |
$lo=$mem->user["login"]; |
|---|
| 213 |
$l=substr($lo,0,1); |
|---|
| 214 |
$db->query("UPDATE stats2 SET folder='/var/alternc/html/$l/$lo/$folder', mid='$cuid' WHERE id='$id';"); |
|---|
| 215 |
return true; |
|---|
| 216 |
} |
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
/** Delete a raw statistic set |
|---|
| 220 |
* |
|---|
| 221 |
* This function erase the raw statistic set pointed to by $id. |
|---|
| 222 |
* The raw log files that may be present in the folder will NOT be deleted. |
|---|
| 223 |
* @param $id integer is the set that has to be deleted. |
|---|
| 224 |
* @return boolean TRUE if the raw stat has been deleted, FALSE if an error occured. |
|---|
| 225 |
*/ |
|---|
| 226 |
function delete_stats_raw($id) { |
|---|
| 227 |
global $db,$err,$cuid; |
|---|
| 228 |
$err->log("sta2","delete_stats_raw",$id); |
|---|
| 229 |
$db->query("SELECT hostname FROM stats2 WHERE id='$id' and mid='$cuid';"); |
|---|
| 230 |
if (!$db->num_rows()) { |
|---|
| 231 |
$err->raise("sta2",3); |
|---|
| 232 |
return false; |
|---|
| 233 |
} |
|---|
| 234 |
$db->next_record(); |
|---|
| 235 |
$db->query("DELETE FROM stats2 WHERE id='$id'"); |
|---|
| 236 |
return true; |
|---|
| 237 |
} |
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
/** Create a new raw statistic set (raw log) |
|---|
| 241 |
* This function create a new raw log set for the current user. |
|---|
| 242 |
* The raw statistics allow any user to get its raw apache log put daily in |
|---|
| 243 |
* one of its folders in its user space. |
|---|
| 244 |
* @param $hostname string this is the domain name (hosted by the current user) |
|---|
| 245 |
* for which we want raw logs |
|---|
| 246 |
* @param $dir string this is the folder where we will put the raw log files. |
|---|
| 247 |
* @return boolean TRUE if the set has been created, or FALSE if an error occured. |
|---|
| 248 |
*/ |
|---|
| 249 |
function add_stats_raw($hostname,$dir) { |
|---|
| 250 |
global $db,$err,$quota,$bro,$mem,$cuid; |
|---|
| 251 |
$err->log("sta2","add_stats_raw",$hostname); |
|---|
| 252 |
|
|---|
| 253 |
$dir=$bro->convertabsolute($dir); |
|---|
| 254 |
if (substr($dir,0,1)=="/") { |
|---|
| 255 |
$dir=substr($dir,1); |
|---|
| 256 |
} |
|---|
| 257 |
$lo=$mem->user["login"]; |
|---|
| 258 |
$l=substr($lo,0,1); |
|---|
| 259 |
if ($quota->cancreate("sta2")) { |
|---|
| 260 |
$db->query("INSERT INTO stats2 (hostname,folder,mid) VALUES ('$hostname','/var/alternc/html/$l/$lo/$dir','$cuid')"); |
|---|
| 261 |
return true; |
|---|
| 262 |
} else { |
|---|
| 263 |
$err->raise("sta2",1); |
|---|
| 264 |
return false; |
|---|
| 265 |
} |
|---|
| 266 |
} |
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
/** Quota computing Hook function |
|---|
| 270 |
* This is the quota computing hook function for sta2. It computes the |
|---|
| 271 |
* used quota of raw stats for the current user. |
|---|
| 272 |
* @param $name string name of the quota |
|---|
| 273 |
* @return integer the number of service used or false if an error occured |
|---|
| 274 |
* @access private |
|---|
| 275 |
*/ |
|---|
| 276 |
function alternc_get_quota($name) { |
|---|
| 277 |
global $db,$err,$cuid; |
|---|
| 278 |
if ($name=="sta2") { |
|---|
| 279 |
$err->log("sta2","get_quota"); |
|---|
| 280 |
$db->query("SELECT COUNT(*) AS cnt FROM stats2 WHERE mid='$cuid'"); |
|---|
| 281 |
$db->next_record(); |
|---|
| 282 |
return $db->f("cnt"); |
|---|
| 283 |
} else return false; |
|---|
| 284 |
} |
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
/** |
|---|
| 289 |
* Exporte toutes les informations states brutes du compte. |
|---|
| 290 |
* @access private |
|---|
| 291 |
* EXPERIMENTAL 'sid' function ;) |
|---|
| 292 |
*/ |
|---|
| 293 |
function alternc_export($tmpdir) { |
|---|
| 294 |
global $db,$err; |
|---|
| 295 |
$err->log("sta2","export"); |
|---|
| 296 |
$this->get_list_raw(); |
|---|
| 297 |
$str="<sta2>\n"; |
|---|
| 298 |
foreach ($f as $d) { |
|---|
| 299 |
$str.=" <stats>\n"; |
|---|
| 300 |
$str.=" <hostname>".xml_entities($s[hostname])."</hostname>\n"; |
|---|
| 301 |
$str.=" <folder>".xml_entities($s[folder])."</folder>\n"; |
|---|
| 302 |
$str.=" </stats>\n"; |
|---|
| 303 |
} |
|---|
| 304 |
$str.="</sta2>\n"; |
|---|
| 305 |
return $str; |
|---|
| 306 |
} |
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
} |
|---|
| 310 |
|
|---|
| 311 |
?> |
|---|