| 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 |
list($usec, $sec) = explode(' ', microtime()); |
|---|
| 33 |
mt_srand((float) $sec + ((float) $usec * 100000)); |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
function fl($str) { return str_replace("<","<",str_replace("\"",""",$str)); } |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
function checkhostallow($domain,$dns) { |
|---|
| 44 |
global $L_NS1,$L_NS2,$db; |
|---|
| 45 |
$sizefound=0; |
|---|
| 46 |
$found=""; |
|---|
| 47 |
$db->query("SELECT tld,mode FROM tld;"); |
|---|
| 48 |
while ($db->next_record()) { |
|---|
| 49 |
list($key,$val)=$db->Record; |
|---|
| 50 |
if (substr($domain,-1-strlen($key))==".".$key) { |
|---|
| 51 |
if ($sizefound<strlen($key)) { |
|---|
| 52 |
$sizefound=strlen($key); |
|---|
| 53 |
$found=$key; |
|---|
| 54 |
$fmode=$val; |
|---|
| 55 |
} |
|---|
| 56 |
} |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
if (!$found || $fmode==0) |
|---|
| 60 |
return -1; |
|---|
| 61 |
if (($fmode!=4) && (!is_array($dns))) |
|---|
| 62 |
return -2; |
|---|
| 63 |
if ($fmode>2) |
|---|
| 64 |
return $found; |
|---|
| 65 |
$n1=false; $n2=false; |
|---|
| 66 |
for ($i=0;$i<count($dns);$i++) { |
|---|
| 67 |
if ($dns[$i]==$L_NS1) $n1=true; |
|---|
| 68 |
if ($dns[$i]==$L_NS2) $n2=true; |
|---|
| 69 |
} |
|---|
| 70 |
if ($fmode==1 && $n1) |
|---|
| 71 |
return $found; |
|---|
| 72 |
if ($fmode==2 && $n1 && $n2) |
|---|
| 73 |
return $found; |
|---|
| 74 |
return -3; |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
function checkhostallow_nodns($domain) { |
|---|
| 81 |
global $db; |
|---|
| 82 |
$sizefound=0; |
|---|
| 83 |
$found=""; |
|---|
| 84 |
$db->query("SELECT tld,mode FROM tld;"); |
|---|
| 85 |
while ($db->next_record()) { |
|---|
| 86 |
list($key,$val)=$db->Record; |
|---|
| 87 |
if (substr($domain,-1-strlen($key))==".".$key) { |
|---|
| 88 |
if ($sizefound<strlen($key)) { |
|---|
| 89 |
$sizefound=strlen($key); |
|---|
| 90 |
$found=$key; |
|---|
| 91 |
$fmode=$val; |
|---|
| 92 |
} |
|---|
| 93 |
} |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
if (!$found || $fmode==0) |
|---|
| 97 |
return 1; |
|---|
| 98 |
if (count(explode(".",substr($domain,0,-$sizefound)))>2) { |
|---|
| 99 |
return 1; |
|---|
| 100 |
} |
|---|
| 101 |
return 0; |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
function checkurl($url) { |
|---|
| 106 |
|
|---|
| 107 |
if (substr($url,0,7)!="http://" && substr($url,0,8)!="https://" && substr($url,0,6)!="ftp://") return false; |
|---|
| 108 |
if (substr($url,0,7)=="http://" ) $fq=substr($url,7); |
|---|
| 109 |
if (substr($url,0,8)=="https://") $fq=substr($url,8); |
|---|
| 110 |
if (substr($url,0,6)=="ftp://" ) $fq=substr($url,6); |
|---|
| 111 |
$f=explode("/",$fq); |
|---|
| 112 |
if (!is_array($f)) $f=array($f); |
|---|
| 113 |
$t=checkfqdn($f[0]); |
|---|
| 114 |
if ($t) return false; |
|---|
| 115 |
return true; |
|---|
| 116 |
} |
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
function checkip($ip) { |
|---|
| 120 |
|
|---|
| 121 |
if (!ereg("[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*",$ip)) return false; |
|---|
| 122 |
$l=explode(".",$ip); |
|---|
| 123 |
if ($l[0]>255 || $l[1]>255 || $l[2]>255 || $l[3]>255) return false; |
|---|
| 124 |
return true; |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
function checkloginmail($mail) { |
|---|
| 129 |
if (!preg_match("/^[a-zA-Z0-9_\.:\+\-]+$/",$mail)) { |
|---|
| 130 |
return false; |
|---|
| 131 |
} else { |
|---|
| 132 |
return true; |
|---|
| 133 |
} |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
function checkmail($mail) { |
|---|
| 139 |
|
|---|
| 140 |
// 1 s'il n'y a rien devant l'@ |
|---|
| 141 |
// 2 3 ou 4 si le domaine est incorrect. |
|---|
| 142 |
// 5 s'il y a caractères interdits dans la partie gauche du @ |
|---|
| 143 |
// 6 si le mail contient aucun ou plus d'un @ |
|---|
| 144 |
$t=explode("@",$mail); |
|---|
| 145 |
if (count($t)!=2) { |
|---|
| 146 |
return 6; |
|---|
| 147 |
} |
|---|
| 148 |
$c=checkfqdn($t[1]); |
|---|
| 149 |
if ($c) |
|---|
| 150 |
return $c; |
|---|
| 151 |
|
|---|
| 152 |
if (!checkloginmail($t[0])) { |
|---|
| 153 |
if ($t[0]=="") { |
|---|
| 154 |
return 1; |
|---|
| 155 |
} else { |
|---|
| 156 |
return 5; |
|---|
| 157 |
} |
|---|
| 158 |
} |
|---|
| 159 |
return 0; |
|---|
| 160 |
} |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
function checkfqdn($fqdn) { |
|---|
| 164 |
|
|---|
| 165 |
// Retourne 0 si tout va bien, sinon, retourne un code erreur... |
|---|
| 166 |
// 1. Nom de domaine complet trop long. |
|---|
| 167 |
// 2. L'un des membres est trop long. |
|---|
| 168 |
// 3. Caractere interdit dans l'un des membres. |
|---|
| 169 |
// 4. Le fqdn ne fait qu'un seul membre (il n'est donc pas fq...) |
|---|
| 170 |
if (strlen($fqdn)>255) |
|---|
| 171 |
return 1; |
|---|
| 172 |
$members=explode(".", $fqdn); |
|---|
| 173 |
if (count($members)>1) $ret=0; else $ret=4; |
|---|
| 174 |
reset($members); |
|---|
| 175 |
while (list ($key, $val) = each ($members)) { |
|---|
| 176 |
if (strlen($val)>63) |
|---|
| 177 |
return 2; |
|---|
| 178 |
if (!eregi("^[a-z0-9][a-z0-9-]*[a-z0-9]$",$val)) { |
|---|
| 179 |
return 3; |
|---|
| 180 |
} |
|---|
| 181 |
} |
|---|
| 182 |
return $ret; |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
function checkuserpath($path) { |
|---|
| 186 |
|
|---|
| 187 |
return 0 if the path is not in the user's space |
|---|
| 188 |
return 1 if this is a directory |
|---|
| 189 |
return 2 if this is a regular file |
|---|
| 190 |
*/ |
|---|
| 191 |
global $mem; |
|---|
| 192 |
$user=$mem->user["login"]; |
|---|
| 193 |
$usar=substr($user,0,1); |
|---|
| 194 |
if (substr($path,0,1)=="/") |
|---|
| 195 |
$path="/".$path; |
|---|
| 196 |
|
|---|
| 197 |
$rpath = realpath("/var/alternc/html/$usar/$user$path"); |
|---|
| 198 |
$userpath = realpath("/var/alternc/html/$usar/$user"); |
|---|
| 199 |
if(strpos($rpath,$userpath) === 0){ |
|---|
| 200 |
if (is_dir("/var/alternc/html/$usar/$user$path")) { |
|---|
| 201 |
return 1; |
|---|
| 202 |
} |
|---|
| 203 |
if (is_file("/var/alternc/html/$usar/$user$path")) { |
|---|
| 204 |
return 2; |
|---|
| 205 |
} |
|---|
| 206 |
} |
|---|
| 207 |
return 0; |
|---|
| 208 |
} |
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
function getuserpath($user = null) { |
|---|
| 219 |
global $L_ALTERNC_LOC; |
|---|
| 220 |
if (is_null($user)) { |
|---|
| 221 |
global $mem; |
|---|
| 222 |
$user = $mem->user['login']; |
|---|
| 223 |
} |
|---|
| 224 |
return $L_ALTERNC_LOC . "/html/".substr($user,0,1)."/".$user; |
|---|
| 225 |
} |
|---|
| 226 |
|
|---|
| 227 |
function cbox($test) { |
|---|
| 228 |
if ($test) echo (" checked=\"checked\""); |
|---|
| 229 |
} |
|---|
| 230 |
|
|---|
| 231 |
function ecif($test,$tr,$fa="") { |
|---|
| 232 |
if ($test) |
|---|
| 233 |
echo $tr; |
|---|
| 234 |
else |
|---|
| 235 |
echo $fa; |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
function __($str) { |
|---|
| 239 |
echo _($str); |
|---|
| 240 |
} |
|---|
| 241 |
|
|---|
| 242 |
function ife($test,$tr,$fa="") { |
|---|
| 243 |
if ($test) |
|---|
| 244 |
return $tr; |
|---|
| 245 |
else |
|---|
| 246 |
return $fa; |
|---|
| 247 |
} |
|---|
| 248 |
|
|---|
| 249 |
function format_size($size) { |
|---|
| 250 |
|
|---|
| 251 |
if ("-" == $size) { |
|---|
| 252 |
return $size; |
|---|
| 253 |
} |
|---|
| 254 |
$size=(float)$size; |
|---|
| 255 |
if ($size<1024) { |
|---|
| 256 |
$r=$size; |
|---|
| 257 |
if ($size!=1) { |
|---|
| 258 |
$r.=" "._("Bytes"); |
|---|
| 259 |
} else { |
|---|
| 260 |
$r.=" "._("Byte"); |
|---|
| 261 |
} |
|---|
| 262 |
} else { |
|---|
| 263 |
$size=$size/1024; |
|---|
| 264 |
if ($size<1024) { |
|---|
| 265 |
$r=round($size,2)." "._("Kb"); |
|---|
| 266 |
} else { |
|---|
| 267 |
$size=$size/1024; |
|---|
| 268 |
if ($size<1024) { |
|---|
| 269 |
$r=round($size,2)." "._("Mb"); |
|---|
| 270 |
} else { |
|---|
| 271 |
$size=$size/1024; |
|---|
| 272 |
if ($size<1024) { |
|---|
| 273 |
$r=round($size,2)." "._("Gb"); |
|---|
| 274 |
} else { |
|---|
| 275 |
$r=round($size/1024,2)." "._("Tb"); |
|---|
| 276 |
} |
|---|
| 277 |
} |
|---|
| 278 |
} |
|---|
| 279 |
} |
|---|
| 280 |
return $r; |
|---|
| 281 |
} |
|---|
| 282 |
|
|---|
| 283 |
function getlinkhelp($hid) { |
|---|
| 284 |
return "(<a href=\"javascript:help($hid);\">?</a>)"; |
|---|
| 285 |
} |
|---|
| 286 |
function linkhelp($hid) { |
|---|
| 287 |
echo getlinkhelp($hid); |
|---|
| 288 |
} |
|---|
| 289 |
|
|---|
| 290 |
function format_date($format,$date) { |
|---|
| 291 |
$d=substr($date,8,2); |
|---|
| 292 |
$m=substr($date,5,2); |
|---|
| 293 |
$y=substr($date,0,4); |
|---|
| 294 |
$h=substr($date,11,2); |
|---|
| 295 |
$i=substr($date,14,2); |
|---|
| 296 |
if ($h>12) { |
|---|
| 297 |
$hh=$h-12; |
|---|
| 298 |
$am="pm"; |
|---|
| 299 |
} else { |
|---|
| 300 |
$hh=$h; |
|---|
| 301 |
$am="am"; |
|---|
| 302 |
} |
|---|
| 303 |
return sprintf(_($format),$d,$m,$y,$h,$i,$hh,$am); |
|---|
| 304 |
} |
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
function ssla($str) { |
|---|
| 308 |
if (get_magic_quotes_gpc()) { |
|---|
| 309 |
return stripslashes($str); |
|---|
| 310 |
} else { |
|---|
| 311 |
return $str; |
|---|
| 312 |
} |
|---|
| 313 |
} |
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
/** Hashe un mot de passe en clair en MD5 avec un salt aléatoire |
|---|
| 317 |
* @param string $pass Mot de passe à crypter (max 32 caractères) |
|---|
| 318 |
* @return string Retourne le mot de passe crypté |
|---|
| 319 |
* @access private |
|---|
| 320 |
*/ |
|---|
| 321 |
function _md5cr($pass,$salt="") { |
|---|
| 322 |
if (!$salt) { |
|---|
| 323 |
$chars="./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|---|
| 324 |
for ($i=0;$i<12;$i++) { |
|---|
| 325 |
$salt.=substr($chars,(mt_rand(0,strlen($chars))),1); |
|---|
| 326 |
} |
|---|
| 327 |
$salt="$1$".$salt; |
|---|
| 328 |
} |
|---|
| 329 |
return crypt($pass,$salt); |
|---|
| 330 |
} |
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
|
|---|
| 335 |
|
|---|
| 336 |
function split_mysql_database_name($dbname) { |
|---|
| 337 |
$db_exploded_name = explode("_",$dbname); |
|---|
| 338 |
return array($db_exploded_name[0], |
|---|
| 339 |
implode("_", array_slice($db_exploded_name, 1))); |
|---|
| 340 |
} |
|---|
| 341 |
|
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
function xml_entities($string) { |
|---|
| 350 |
return str_replace("<","<",str_replace(">",">",str_replace("&","&",$string))); |
|---|
| 351 |
} |
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
function pretty_months($months) { |
|---|
| 360 |
if( $months % 12 == 0 && $months > 11) { |
|---|
| 361 |
$years = $months / 12; |
|---|
| 362 |
return "$years " . ($years > 1 ? _("years") : _("year")); |
|---|
| 363 |
} else { |
|---|
| 364 |
return "$months " . ($months > 1 ? _("months") : _("month")); |
|---|
| 365 |
} |
|---|
| 366 |
} |
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 |
function duration_list($name, $selected=0) { |
|---|
| 376 |
$res = "<select name=\"$name\" id=\"$name\">"; |
|---|
| 377 |
|
|---|
| 378 |
foreach(array(0, 1, 2, 3, 4, 6, 12, 24) as $dur) { |
|---|
| 379 |
$res .= "<option value=\"$dur\""; |
|---|
| 380 |
if($selected == $dur) { |
|---|
| 381 |
$res .= ' selected'; |
|---|
| 382 |
} |
|---|
| 383 |
|
|---|
| 384 |
$res .= '>'; |
|---|
| 385 |
|
|---|
| 386 |
if($dur == 0) { |
|---|
| 387 |
$res .= _('Not managed'); |
|---|
| 388 |
} else { |
|---|
| 389 |
$res .= pretty_months($dur); |
|---|
| 390 |
} |
|---|
| 391 |
$res .= '</option>'; |
|---|
| 392 |
} |
|---|
| 393 |
|
|---|
| 394 |
$res .= '</select>'; |
|---|
| 395 |
return $res; |
|---|
| 396 |
} |
|---|
| 397 |
|
|---|
| 398 |
|
|---|
| 399 |
?> |
|---|
| 400 |
|
|---|