32 return str_replace(
"<",
"<", str_replace(
"\"",
""", $str));
50 global $L_NS1, $L_NS2,
$db,
$dom;
53 $db->query(
"SELECT tld,mode FROM tld;");
54 while (
$db->next_record()) {
57 if ($sizefound < strlen(
$key)) {
58 $sizefound = strlen(
$key);
64 if (
$dom->tld_no_check_at_all) {
67 if (!
$found || $fmode == 0) {
70 if (($fmode != 4) && (!is_array($dns))) {
78 for (
$i = 0;
$i < count($dns);
$i++) {
79 if (strtolower($dns[
$i]) == strtolower($L_NS1)) {
82 if (strtolower($dns[
$i]) == strtolower($L_NS2)) {
86 if ($fmode == 1 && $n1) {
89 if ($fmode == 2 && $n1 && $n2) {
107 $db->query(
"SELECT tld,mode FROM tld;");
108 while (
$db->next_record()) {
111 if ($sizefound < strlen(
$key)) {
112 $sizefound = strlen(
$key);
119 if (!
$found || $fmode == 0) {
122 if (count(explode(
".", substr(
$domain, 0, -$sizefound))) > 2) {
135 return getenv(
'REMOTE_ADDR');
147 if (substr($url, 0, 7) !=
"http://" && substr($url, 0, 8) !=
"https://" && substr($url, 0, 6) !=
"ftp://") {
150 if (substr($url, 0, 7) ==
"http://") {
151 $fq = substr($url, 7);
153 if (substr($url, 0, 8) ==
"https://") {
154 $fq = substr($url, 8);
156 if (substr($url, 0, 6) ==
"ftp://") {
157 $fq = substr($url, 6);
159 $f = explode(
"/", $fq);
185 if (($check =
checkfqdn(rtrim($cname,
".")))) {
190 if (substr($cname, -1) !=
".") {
192 if (strpos($cname,
".") ===
false) {
212 return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
223 return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
245 if (filter_var($mail, FILTER_VALIDATE_EMAIL)) {
265 if (strlen($fqdn) > 255) {
268 $members = explode(
".", $fqdn);
269 if (count($members) > 1) {
275 while (list (
$key,
$val) = each($members)) {
276 if (strlen(
$val) > 63) {
281 if (!preg_match(
"#^[a-z0-9_]([a-z0-9-]*[a-z0-9])?$#i",
$val)) {
300 $usar = substr(
$user, 0, 1);
301 if (substr($path, 0, 1) !=
"/") {
309 if (strpos($rpath, $userpath) === 0) {
330 if (is_null(
$user)) {
345 function cbox($test, $echo =
true) {
347 $return =
" checked=\"checked\"";
368 $return =
" selected=\"selected\"";
387 function ecif($test, $tr, $fa =
"", $affiche = 1) {
416 function ife($test, $tr, $fa =
"") {
435 $size = (float) $size;
439 $r.=
" " . _(
"Bytes");
444 $size = $size / 1024;
446 $r = round($size, 2) .
" " . _(
"Kb");
448 $size = $size / 1024;
450 $r = round($size, 2) .
" " . _(
"Mb");
452 $size = $size / 1024;
454 $r = round($size, 2) .
" " . _(
"Gb");
456 $r = round($size / 1024, 2) .
" " . _(
"Tb");
462 return str_replace(
" ",
" ",
$r);
475 return "(<a href=\"javascript:help($hid);\">?</a>)";
495 $d = substr($date, 8, 2);
496 $m = substr($date, 5, 2);
497 $y = substr($date, 0, 4);
498 $h = substr($date, 11, 2);
499 $i = substr($date, 14, 2);
509 $format=str_replace(
'$d',
'$s', $format);
510 return sprintf($format,
$d, $m, $y, $h,
$i, $hh, $am);
520 if (get_magic_quotes_gpc()) {
521 return stripslashes($str);
535 $chars =
"./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
536 for (
$i = 0;
$i < 12;
$i++) {
537 $salt.=substr($chars, (mt_rand(0, strlen($chars))), 1);
539 $salt =
"$1$" . $salt;
541 return crypt($pass, $salt);
549 $db_exploded_name = explode(
"_", $dbname);
550 return array($db_exploded_name[0],
551 implode(
"_", array_slice($db_exploded_name, 1)));
561 return str_replace(
"<",
"<", str_replace(
">",
">", str_replace(
"&",
"&",
$string)));
571 if ($months % 12 == 0 && $months > 11) {
572 $years = $months / 12;
573 return "$years " . ($years > 1 ? _(
"years") : _(
"year"));
575 return "$months " . ($months > 1 ? _(
"months") : _(
"month"));
587 $res =
"<select name=\"$name\" id=\"$name\" class=\"inl\">";
589 foreach (array(0, 1, 2, 3, 4, 6, 12, 24) as $dur) {
590 $res .=
"<option value=\"$dur\"";
591 if ($selected == $dur) {
592 $res .=
' selected="selected" ';
598 $res .= _(
'Not managed');
619 function eoption($values, $cur, $onedim =
false) {
620 if (is_array($values)) {
621 foreach ($values as $k => $v) {
625 echo
"<option value=\"$k\"";
627 echo
" selected=\"selected\"";
629 echo
">" . $v .
"</option>";
647 function ehe($str, $display = TRUE) {
649 $quoted = htmlspecialchars($str, ENT_QUOTES|ENT_SUBSTITUTE, $charset);
670 function eue($str, $display = TRUE) {
672 $quoted = urlencode($str);
690 $methodType = array(
"get",
"post",
"request",
"files",
"server");
692 foreach (
$fields AS $name => $options) {
693 if (in_array(strtolower($options[0]), $methodType) ===
false) {
694 die(
"Unrecognized method type used for field " . $name .
" : " . $options[0]);
696 if ($requestOnly ===
true) {
697 $method =
"_REQUEST";
699 $method =
"_" . strtoupper($options[0]);
701 switch ($options[1]) {
703 $vars[$name] = (isset($GLOBALS[$method][$name]) && is_numeric($GLOBALS[$method][$name]) ? intval($GLOBALS[$method][$name]) : $options[2]);
706 $vars[$name] = (isset($GLOBALS[$method][$name]) && is_numeric($GLOBALS[$method][$name]) ? floatval($GLOBALS[$method][$name]) : $options[2]);
709 $vars[$name] = (isset($GLOBALS[$method][$name]) ? trim($GLOBALS[$method][$name]) : $options[2]);
712 $vars[$name] = (isset($GLOBALS[$method][$name]) && is_array($GLOBALS[$method][$name]) ? $GLOBALS[$method][$name] : $options[2]);
715 $vars[$name] = (isset($GLOBALS[$method][$name]) ? $GLOBALS[$method][$name] : $options[2]);
718 $vars[$name] = (isset($GLOBALS[$method][$name]) ? $GLOBALS[$method][$name] : $options[2]);
721 die(
"Illegal method type used for field " . $name .
" : " . $options[1]);
726 foreach ($vars AS $var =>
$value) {
738 echo
"<pre style=\"border: 1px solid black; text-align: left; font-size: 9px\">\n";
751 if ($a[
'label'] == $b[
'label']) {
754 return ($a[
'label'] < $b[
'label']) ? -1 : 1;
777 function pager($offset, $count,
$total, $url, $before =
"", $after =
"", $echo =
true) {
779 $offset = intval($offset);
780 $count = intval($count);
792 $offset = max(0,
$total - $count);
800 $o = max($offset - $count, 0);
801 $return .=
"<a href=\"" . str_replace(
"%%offset%%", $o, $url) .
"\" alt=\"(Ctl/Alt-p)\" title=\"(Alt-p)\" accesskey=\"p\">" . _(
"Previous Page") .
"</a> ";
803 $return .= _(
"Previous Page") .
" ";
806 if (
$total > (2 * $count)) {
814 $return .=
"<a href = \"" . str_replace(
"%%offset%%", $o, $url) .
"\">$i</a> ";
818 for (
$i = 0;
$i <= 2;
$i++) {
823 $return .=
"<a href=\"" . str_replace(
"%%offset%%", $o, $url) .
"\">$i</a> ";
826 if ($offset >= $count && $offset < (
$total - 2 * $count)) {
828 $start = max(3, intval($offset / $count) - 2);
829 $end = min(intval($offset / $count) + 3, intval(
$total / $count) - 3);
833 for (
$i = $start;
$i < $end;
$i++) {
838 $return .=
"<a href=\"" . str_replace(
"%%offset%%", $o, $url) .
"\">$i</a> ";
841 if ($end != intval(
$total / $count) - 3) {
852 $return .=
"<a href=\"" . str_replace(
"%%offset%%", $o, $url) .
"\">$i</a> ";
859 if ($offset + $count <
$total) {
860 $o = $offset + $count;
861 $return .=
"<a href=\"" . str_replace(
"%%offset%%", $o, $url) .
"\" alt=\"(Ctl/Alt-s)\" title=\"(Alt-s)\" accesskey=\"s\">" . _(
"Next Page") .
"</a> ";
863 $return .= _(
"Next Page") .
" ";
884 $available_sets=
'lud';
886 $available_sets=
'luds';
888 if(strpos($available_sets,
'l') !==
false)
889 $sets[] =
'abcdefghijklmnopqrstuvwxyz';
890 if(strpos($available_sets,
'u') !==
false)
891 $sets[] =
'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
892 if(strpos($available_sets,
'd') !==
false)
893 $sets[] =
'0123456789';
894 if(strpos($available_sets,
's') !==
false)
895 $sets[] =
'(!#$%)*+,-./:;<=>?@[\]^_';
899 foreach($sets as $set) {
900 $password .= $set[array_rand(str_split($set))];
904 $all = str_split($all);
905 for(
$i = 0;
$i < $length - count($sets);
$i++)
924 echo
"<div id='z$id' style='display:none;'><a href=\"javascript:generate_password_html('$id',$pass_size,'$fields_to_fill1','$fields_to_fill2',$classcount);\">";
925 __(
"Click here to generate a password");
927 echo
"<script type='text/javascript'>$('#z$id').show();</script>";
941 function display_browser($dir =
"", $caller =
"main.dir", $width = 350, $height = 450) {
946 echo
"<script type=\"text/javascript\">
949 $( \"#" . $bid .
"\" ).dialog({
951 width: " . $width .
",
952 height: " . $height .
",
956 $('.ui-widget-overlay').css('opacity', .70);
957 $('.ui-dialog-content').css('background-color', '#F0F0FA');
961 $( \"#bt" . $bid .
"\" )
963 .attr(\"class\", \"ina\")
965 $( \"#" . $bid .
"\" ).dialog( \"open\" );
971 document.write(' <input type=\"button\" id=\"bt" . $bid .
"\" value=\"" . _(
"Choose a folder...") .
"\" class=\"ina\">');
972 document.write('<div id=\"" . $bid .
"\" title=\"" . _(
"Choose a folder...") .
"\" style=\"display: none; bgcolor:red;\">');
973 document.write(' <iframe src=\"/browseforfolder2.php?caller=" . $caller .
"&file=" .
ehe($dir,
false) .
"&bid=" . $bid .
"\" width=\"" . ($width - 40) .
"\" height=\"" . ($height - 64) .
"\" frameborder=\"no\" id=\"browseiframe\"></iframe>');
974 document.write('</div>');
1025 while ($dT >= 2.0) {
1028 $dX = $dC * (1 - abs($dT - 1));
1031 case($dH >= 0.0 && $dH < 1.0):
1036 case($dH >= 1.0 && $dH < 2.0):
1041 case($dH >= 2.0 && $dH < 3.0):
1046 case($dH >= 3.0 && $dH < 4.0):
1051 case($dH >= 4.0 && $dH < 5.0):
1056 case($dH >= 5.0 && $dH < 6.0):
1076 return array(
'r' => round($dR),
'g' => round($dG),
'b' => round($dB));
1086 $num = dechex($hex);
1087 return (strlen(
"$num") >= 2) ?
"$num" :
"0$num";
1104 $h = 1 + ((100 -
$p) * 130 / 100);
1107 $color =
"#" .
hexa($rvb[
'r']) .
hexa($rvb[
'g']) .
hexa($rvb[
'b']);
1122 if (
$cuid != 2000) {
1138 if (
$cuid != 2000) {
1162 if (!isset($_SESSION[
"csrf"])) {
1163 $_SESSION[
"csrf"]=md5(mt_rand().mt_rand().mt_rand());
1166 $token=md5(mt_rand().mt_rand().mt_rand());
1167 $db->query(
"INSERT INTO csrf SET cookie=?, token=?, created=NOW(), used=0;",array($_SESSION[
"csrf"],$token));
1171 echo
'<input type="hidden" name="csrf" value="'.$token.
'" />';
1185 if (is_null($token)) $token=$_POST[
"csrf"];
1187 if (!isset($_SESSION[
"csrf"])) {
1188 $msg->raise(
"ERROR",
"functions", _(
"The posted form token is incorrect. Maybe you need to allow cookies"));
1191 if (strlen($token)!=32 || strlen($_SESSION[
"csrf"])!=32) {
1192 unset($_SESSION[
"csrf"]);
1193 $msg->raise(
"ERROR",
"functions", _(
"Your cookie or token is invalid"));
1196 $db->query(
"SELECT used FROM csrf WHERE cookie=? AND token=?;",array($_SESSION[
"csrf"],$token));
1197 if (!
$db->next_record()) {
1198 $msg->raise(
"ERROR",
"functions", _(
"You can't post twice the same form, please retry."));
1201 if (
$db->f(
"used")) {
1202 $msg->raise(
"ERROR",
"functions", _(
"You can't post twice the same form, please retry."));
1205 $db->query(
"UPDATE csrf SET used=1 WHERE cookie=? AND token=?;",array($_SESSION[
"csrf"],$token));
1206 $db->exec(
"DELETE FROM csrf WHERE created<DATE_SUB(NOW(), INTERVAL 1 DAY);");
1217 if (function_exists(
'random_bytes')) {
1219 $salt = base64_encode(random_bytes(12));
1221 else if (function_exists(
'mcrypt_create_iv')) {
1222 $salt = base64_encode(mcrypt_create_iv(12, MCRYPT_DEV_URANDOM));
1224 else if (function_exists(
'openssl_random_pseudo_bytes')) {
1225 $salt = base64_encode(openssl_random_pseudo_bytes(12));
1228 throw Exception(
'Unable to generate salt');
1231 $salt =
'$6$rounds=20000$' . $salt;
1246 return '{SHA512-CRYPT}' . $hash;
1259 $f=fopen($file,
"rb");
1261 while($s=fgets(
$f,1024)) {
1262 if (trim($s)==$line) {
1268 $f=fopen($file,
"ab");
1269 fputs(
$f,trim($line).
"\n");
1283 $f=fopen($file,
"rb");
1284 $g=fopen($file.
".new",
"wb");
1286 while($s=fgets(
$f,1024)) {
1287 if (trim($s)!=$line) {
1295 rename($file.
".new",$file);
const DEFAULT_PASS_SIZE
Define constants from vars of /etc/alternc/local.sh The you can't choose where is the AlternC Panel.
display_div_generate_password($pass_size=DEFAULT_PASS_SIZE, $fields_to_fill1="", $fields_to_fill2="", $classcount=3)
Show a button to set a random password for a password field.
checkloginmail($mail)
Check a login mail, cf http://www.bortzmeyer.org/arreter-d-interdire-des-adresses-legales....
eoption($values, $cur, $onedim=false)
select_values($arr,$cur) echo des <option> du tableau $values ou de la table sql $values selectionne ...
checkcname($cname)
Check that CNAME domain is correct.
pager($offset, $count, $total, $url, $before="", $after="", $echo=true)
Shows a pager : Previous page 0 1 2 ...
checkipv6($ip)
Check that $ip is a correct ipv6 ip.
duration_list($name, $selected=0)
split_mysql_database_name($dbname)
split mysql database name between username and custom database name
ehe($str, $display=TRUE)
Echo the HTMLSpecialChars version of a value.
format_date($format, $date)
checkfqdn($fqdn)
Check that a domain name is fqdn compliant.
ssla($str)
Strip slashes if needed :
_md5cr($pass, $salt="")
Hashe a password using proper crypto function.
_dovecot_hash($password)
Create a password hash for use with dovecot.
selected($bool, $echo=TRUE)
ECHOes selected="selected" only if the parameter is true useful for checkboxes and radio buttons.
fl($str)
Format a field value for input or textarea :
del_line_from_file($file, $line)
Remove the line of text $line from file $file.
checksubtxt($txt)
Check that TXT domain is correct.
format_size($size, $html=0)
checkhostallow($domain, $dns)
Check if a domain can be hosted on this server : Return a negative value in case of an error,...
pretty_months($months)
Converti un nombre de mois en une chaine plus lisible.
create_pass($length=10, $classcount=3)
Create a password compatible with the password policy.
eue($str, $display=TRUE)
Echo the URLENCODED version of a value.
display_browser($dir="", $caller="main.dir", $width=350, $height=450)
Show a button to select a folder on the server.
xml_entities($string)
Echappe les caract�res pouvant perturber un flux XML standard :
add_line_to_file($file, $line)
Add the line of text $line into file $file.
checkmail($mail)
Check an email address, use filter_var with emails, which works great ;)
cbox($test, $echo=true)
ECHOes checked="checked" only if the parameter is true useful for checkboxes and radio buttons.
getFields($fields, $requestOnly=false)
Get the Fields of the posted form from $_REQUEST or POST or GET and check their type.
getuserpath($user=null)
get the home of the user
_sha512cr($password, $salt=NULL)
Create a SHA512-CRYPT hash of a string.
get_remote_ip()
Return the remote IP.
csrf_check($token=null)
Check a CSRF token against the current session a token can be only checked once, it's disabled then.
checkhostallow_nodns($domain)
Check that a domain can be hosted in that server, without DNS managment.
checkip($ip)
Check that $ip is a correct 4 Dotted ip.
list_properties_order($a, $b)
ecif($test, $tr, $fa="", $affiche=1)
csrf_get($return=false)
Give a new CSRF uniq token for a form the session must be up since the CSRF is linked to the session ...
checkurl($url)
Check that $url is a correct url (http:// or https:// or ftp://)
foreach($domaines_user as $domaine) $t
if(!isset($is_include)) if(! $key &&! $crt) $id
if(empty($_POST['key'])||empty($_POST['val'])) $key