From 6adef177c98f39b0c0dea81eff2d2b46269912fd Mon Sep 17 00:00:00 2001 From: alban Date: Wed, 26 Mar 2014 14:29:00 +0100 Subject: [PATCH] [fix] code documentation, comments and cosmetic changes --- bureau/class/class_system_bind.php | 145 +++++++-- bureau/class/config.php | 13 +- bureau/class/functions.php | 479 +++++++++++++++++++++-------- bureau/class/m_admin.php | 3 +- bureau/class/m_cron.php | 2 + bureau/class/m_hta.php | 3 +- 6 files changed, 497 insertions(+), 148 deletions(-) diff --git a/bureau/class/class_system_bind.php b/bureau/class/class_system_bind.php index 5798ba28..ea3ee011 100644 --- a/bureau/class/class_system_bind.php +++ b/bureau/class/class_system_bind.php @@ -17,11 +17,20 @@ class system_bind { var $cache_domain_summary = array(); var $zone_file_directory = '/var/lib/alternc/bind/zones/'; + /** + * + */ function system_bind() { // Constructeur } - // Return the part of the conf we got from the database + /** + * Return the part of the conf we got from the database + * + * @global m_mysql $db + * @param string $domain + * @return array $this->cache_conf_db + */ function conf_from_db($domain=false) { global $db; // Use cache, fill cache if empty @@ -53,11 +62,21 @@ class system_bind { return $this->cache_conf_db; } - // Return full path of the zone configuration file + /** + * Return full path of the zone configuration file + * + * @param string $domain + * @return string + */ function get_zone_file_uri($domain) { return $this->zone_file_directory.$domain; } + /** + * + * @param string $domain + * @return string zone file path + */ function get_zone_file($domain) { // Use cache, fill cache if empty if (!isset($this->cache_zone_file[$domain]) ) { @@ -70,6 +89,11 @@ class system_bind { return $this->cache_zone_file[$domain] ; } + /** + * + * @param string $domain + * @return string + */ function get_serial($domain) { // Return the next serial the domain must have. // Choose between a generated and an incremented. @@ -89,7 +113,12 @@ class system_bind { return max(array($calc,$old)) + 1 ; } - // Return lines that are after ;;;END ALTERNC AUTOGENERATE CONFIGURATION + /** + * Return lines that are after ;;;END ALTERNC AUTOGENERATE CONFIGURATION + * + * @param string $domain + * @return string + */ function get_persistent($domain) { if ( ! isset($this->cache_get_persistent[$domain] )) { preg_match_all('/\;\s*END\sALTERNC\sAUTOGENERATE\sCONFIGURATION(.*)/s', $this->get_zone_file($domain), $output_array); @@ -101,11 +130,22 @@ class system_bind { } // isset return $this->cache_get_persistent[$domain]; } - + + /** + * + * @param string $domain + * @return string + */ function get_zone_header($domain) { return file_get_contents($this->ZONE_TEMPLATE); } - + + /** + * + * @global m_dom $dom + * @param string $domain + * @return string + */ function get_domain_summary($domain=false) { global $dom; @@ -118,6 +158,11 @@ class system_bind { else return $this->cache_domain_summary; } + /** + * + * @param string $domain + * @return boolean + */ function dkim_delete($domain) { $target_dir = "/etc/opendkim/keys/$domain"; if (file_exists($target_dir)) { @@ -128,7 +173,12 @@ class system_bind { return true; } - // Generate the domain DKIM key + /** + * Generate the domain DKIM key + * + * @param string $domain + * @return boolean + */ function dkim_generate_key($domain) { // Stop here if we do not manage the mail if ( ! $this->get_domain_summary($domain)['gesmx'] ) return; @@ -152,8 +202,11 @@ class system_bind { return true; // FIXME handle error } - // Refresh DKIM configuration: be sure to list the domain having a private key (and only them) - function dkim_refresh_list() { // so ugly... but there is only 1 pass, not 3. Still ugly. + /** + * Refresh DKIM configuration: be sure to list the domain having a private key (and only them) + */ + function dkim_refresh_list() { + // so ugly... but there is only 1 pass, not 3. Still ugly. $trusted_host_new = "# WARNING: this file is auto generated by AlternC.\n# Add your changes after the last line\n"; $keytable_new = "# WARNING: this file is auto generated by AlternC.\n# Add your changes after the last line\n"; $signingtable_new = "# WARNING: this file is auto generated by AlternC.\n# Add your changes after the last line\n"; @@ -206,7 +259,11 @@ class system_bind { } } - + /** + * + * @param string $domain + * @return string + */ function dkim_entry($domain) { $keyfile="/etc/opendkim/keys/$domain/alternc.txt"; if (! file_exists($keyfile) && $this->get_domain_summary($domain)['gesmx'] ) { @@ -215,8 +272,13 @@ class system_bind { return @file_get_contents($keyfile); } - // Conditionnal generation autoconfig entry for outlook / thunderbird - // If entry with the same name allready exist, skip it. + /** + * Conditionnal generation autoconfig entry for outlook / thunderbird + * If entry with the same name allready exist, skip it. + * + * @param string $domain + * @return string + */ function mail_autoconfig_entry($domain) { $zone= implode("\n",$this->conf_from_db($domain))."\n".$this->get_persistent($domain); @@ -236,7 +298,20 @@ class system_bind { return $entry; } - // Return a fully generated zone + + /** + * + * Return a fully generated zone + * + * @global string $L_FQDN + * @global string $L_NS1_HOSTNAME + * @global string $L_NS2_HOSTNAME + * @global string $L_DEFAULT_MX + * @global string $L_DEFAULT_SECONDARY_MX + * @global string $L_PUBLIC_IP + * @param string $domain + * @return string + */ function get_zone($domain) { global $L_FQDN, $L_NS1_HOSTNAME, $L_NS2_HOSTNAME, $L_DEFAULT_MX, $L_DEFAULT_SECONDARY_MX, $L_PUBLIC_IP; @@ -271,6 +346,10 @@ class system_bind { return $zone; } + /** + * + * @param string $domain + */ function reload_zone($domain) { exec($this->RNDC." reload ".escapeshellarg($domain), $output, $return_value); if ($return_value != 0 ) { @@ -278,7 +357,12 @@ class system_bind { } } - // return true if zone is locked + /** + * return true if zone is locked + * + * @param string $domain + * @return boolean + */ function is_locked($domain) { preg_match_all("/(\;\s*LOCKED:YES)/i", $this->get_zone_file($domain), $output_array); if (isset($output_array[1][0]) && !empty($output_array[1][0])) { @@ -287,6 +371,13 @@ class system_bind { return false; } + /** + * + * @global m_mysql $db + * @global m_dom $dom + * @param string $domain + * @return boolean + */ function save_zone($domain) { global $db, $dom; @@ -307,16 +398,26 @@ class system_bind { return true; // fixme add tests } - // Delete the zone configuration file + /** + * Delete the zone configuration file + * + * @param string $domain + * @return boolean + */ function delete_zone($domain) { $file=$this->get_zone_file_uri($domain); if (file_exists($file)) { unlink($file); } $this->dkim_delete($domain); - return; + return true; } + /** + * + * @global m_hooks $hooks + * @return boolean + */ function reload_named() { global $hooks; // Generate the new conf file @@ -342,7 +443,13 @@ class system_bind { return true; } - // Regenerate bind configuration and load it + /** + * Regenerate bind configuration and load it + * + * @global m_hooks $hooks + * @param boolean $all + * @return boolean + */ function regenerate_conf($all=false) { global $hooks; @@ -365,10 +472,12 @@ class system_bind { $this->dkim_refresh_list(); $this->reload_named(); - - return; + return true; } + /** + * + */ private function dummy_for_translation() { _("The zone file of this domain is locked. Contact your administrator."); } diff --git a/bureau/class/config.php b/bureau/class/config.php index dc0071ff..31c6ef7a 100644 --- a/bureau/class/config.php +++ b/bureau/class/config.php @@ -40,8 +40,8 @@ session_name('AlternC_Panel'); session_start(); /* - Si vous voulez mettre le bureau en maintenance, décommentez le code ci-dessous - et mettez votre ip dans le IF pour que seule votre ip puisse accéder au bureau : + Si vous voulez mettre le bureau en maintenance, d�commentez le code ci-dessous + et mettez votre ip dans le IF pour que seule votre ip puisse acc�der au bureau : */ /* * / @@ -52,8 +52,8 @@ Merci de revenir plus tard."; } /* */ -/* Toutes les pages du bureau passent ici. On utilise une sémaphore pour - s'assurer que personne ne pourra accéder à 2 pages du bureau en même temps. +/* Toutes les pages du bureau passent ici. On utilise une s�maphore pour + s'assurer que personne ne pourra acc�der � 2 pages du bureau en m�me temps. */ /* * / // 1. Get a semaphore id for the alternc magic number (18577) @@ -100,6 +100,7 @@ require_once(dirname(__FILE__)."/local.php"); // Define constants from vars of /etc/alternc/local.sh // The you can't choose where is the AlternC Panel +define("DEFAULT_PASS_SIZE", 8); define('ALTERNC_MAIL', "$L_ALTERNC_MAIL"); define('ALTERNC_HTML', "$L_ALTERNC_HTML"); if(isset($L_ALTERNC_LOGS_ARCHIVE)) @@ -121,13 +122,13 @@ $root=ALTERNC_PANEL."/"; require_once($root."/class/db_mysql.php"); require_once($root."/class/functions.php"); -// Redirection si appel à https://(!fqdn)/ +// Redirection si appel � https://(!fqdn)/ if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"]=="on" && $host!=$L_FQDN) { header("Location: https://$L_FQDN/"); } -// Classe héritée de la classe db de la phplib. +// Classe h�rit�e de la classe db de la phplib. /** * Class for MySQL management in the bureau * diff --git a/bureau/class/functions.php b/bureau/class/functions.php index 906ca090..d01cbd20 100644 --- a/bureau/class/functions.php +++ b/bureau/class/functions.php @@ -27,19 +27,43 @@ list($usec, $sec) = explode(' ', microtime()); mt_srand((float) $sec + ((float) $usec * 100000)); -/* Format a field value for input or textarea : */ +/** + * Format a field value for input or textarea : + * + * @param string $str + * @return string + */ function fl($str) { return str_replace("<","<",str_replace("\"",""",$str)); } +/** + * + * @global array $variables + * @param string $name + * @param mixed $default + * @param string $createit_comment + * @param struing $type + * @return mixed + */ function variable_get($name, $default = null, $createit_comment = null, $type=null) { global $variables; return $variables->variable_get($name, $default, $createit_comment, $type); } -/* - Check if a domain can be hosted on this server : - Return a negative value in case of an error, - or a string for the index in $tld -*/ + + +/** + * Check if a domain can be hosted on this server : + * Return a negative value in case of an error, + * or a string for the index in $tld + * + * @global string $L_NS1 + * @global string $L_NS2 + * @global m_mysql $db + * @global m_dom $dom + * @param string $domain + * @param array $dns + * @return int + */ function checkhostallow($domain,$dns) { global $L_NS1,$L_NS2,$db,$dom; $sizefound=0; @@ -76,9 +100,13 @@ function checkhostallow($domain,$dns) { return -3; // DNS incorrect in the whois } -/* Check that a domain can be hosted in that server, -without DNS managment. -*/ +/** + * Check that a domain can be hosted in that server, + * without DNS managment. + * @global m_mysql $db + * @param type $domain + * @return int + */ function checkhostallow_nodns($domain) { global $db; $sizefound=0; @@ -103,13 +131,21 @@ function checkhostallow_nodns($domain) { return 0; } +/** + * @return string + */ function get_remote_ip() { // Return the remote IP. // If you are behind a proxy, use X_FORWARDED_FOR instead of REMOTE_ADDR return getenv('REMOTE_ADDR'); } -/* Check that $url is a correct url (http:// or https:// or ftp://) */ +/** + * Check that $url is a correct url (http:// or https:// or ftp://) + * + * @param type $url + * @return boolean + */ function checkurl($url) { // TODO : add a path/file check if (substr($url,0,7)!="http://" && substr($url,0,8)!="https://" && substr($url,0,6)!="ftp://") return false; @@ -123,44 +159,73 @@ function checkurl($url) { return true; } -/* Check that TXT domain is correct */ +/** + * Check that TXT domain is correct + * + * @param string $txt + * @return boolean + */ function checksubtxt($txt) { return true; } -/* Check that CNAME domain is correct */ +/** + * Check that CNAME domain is correct + * @param string $cname + * @return boolean + */ function checkcname($cname) { return true; } -/* Check that $ip is a correct 4 Dotted ip */ +/** + * Check that $ip is a correct 4 Dotted ip + * @param string $ip + * @return type + */ function checkip($ip) { // return true or false whether the ip is correctly formatted return filter_var($ip,FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); } -/* Check that $ip is a correct ipv6 ip */ +/** + * Check that $ip is a correct ipv6 ip + * @param string $ip + * @return type + */ function checkipv6($ip) { // return true or false whether the ip is correctly formatted return filter_var($ip,FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); } -/* Check a login mail, cf http://www.bortzmeyer.org/arreter-d-interdire-des-adresses-legales.html */ -/* FIXME: check who is using that function and delete it when unused */ +/** + * Check a login mail, cf http://www.bortzmeyer.org/arreter-d-interdire-des-adresses-legales.html + * @todo Check who is using that function and delete it when unused + * @param string $mail + * @return boolean + */ function checkloginmail($mail) { return true; } -/* Check an email address, use filter_var with emails, which works great ;) */ -/* FIXME: check who is using that function and delete it when unused */ +/** + * Check an email address, use filter_var with emails, which works great ;) + * @todo check who is using that function and delete it when unused + * @param string $mail + * @return boolean + */ function checkmail($mail) { if (filter_var($mail,FILTER_VALIDATE_EMAIL)) { - return 0; + return FALSE; } else { - return 1; + return TRUE; } } -/* Check that a domain name is fqdn compliant */ +/** + * Check that a domain name is fqdn compliant + * @param string $fqdn + * @return int + */ function checkfqdn($fqdn) { // (RFC 1035 http://www.ietf.org/rfc/rfc1035.txt) // Retourne 0 si tout va bien, sinon, retourne un code erreur... @@ -186,12 +251,16 @@ function checkfqdn($fqdn) { return $ret; } +/** + * + * @global m_mem $mem + * @param string $path + * @return int + * return 0 if the path is not in the user's space + * return 1 if this is a directory + * return 2 if this is a regular file + */ function checkuserpath($path) { - /* - return 0 if the path is not in the user's space - return 1 if this is a directory - return 2 if this is a regular file - */ global $mem; $user=$mem->user["login"]; $usar=substr($user,0,1); @@ -217,9 +286,10 @@ function checkuserpath($path) { /** * get the home of the user * + * @global m_mem $mem * @args string $user the username, if null will use the global $mem. no * security checks performed on path - * @returns string the actual absolute path + * @return string the actual absolute path */ function getuserpath($user = null) { if (is_null($user)) { @@ -229,48 +299,93 @@ function getuserpath($user = null) { return rtrim(ALTERNC_HTML,"/")."/".substr($user,0,1)."/".$user; } -/* ECHOes checked="checked" only if the parameter is true +/** +* ECHOes checked="checked" only if the parameter is true * useful for checkboxes and radio buttons + * + * @param boolean $test + * @param boolean $echo */ -function cbox($test) { - if ($test) echo (" checked=\"checked\""); -} - - -/* ECHOes selected="selected" only if the parameter is true - * useful for checkboxes and radio buttons - */ -function selected($bool) { - if ($bool) { - echo " selected=\"selected\""; +function cbox($test, $echo = TRUE) { + if ($test) { + $return = " checked=\"checked\""; } + if( $echo ){ + echo $return; + } + return $return; } + +/** + * ECHOes selected="selected" only if the parameter is true + * useful for checkboxes and radio buttons + * + * @param boolean $bool + * @param boolean $echo + * @return string + */ +function selected($bool, $echo = TRUE) { + if ($bool) { + $return = " selected=\"selected\""; + } + if( $echo ){ + echo $return; + } + return $return; +} + +/** + * + * @param boolean $test + * @param string $tr + * @param string $fa + * @param boolean $affiche + * @return string + */ function ecif($test,$tr,$fa="",$affiche=1) { - if ($test) - $retour = $tr; - else - $retour = $fa; - - if ($affiche) - echo $retour; - else + if ($test){ + $retour = $tr; + } + else{ + $retour = $fa; + } + if ($affiche) { + echo $retour; + } return $retour; } +/** + * + * @param string $str + */ function __($str) { echo _($str); } +/** + * + * @param boolean $test + * @param string $tr + * @param string $fa + * @return string + */ function ife($test,$tr,$fa="") { - if ($test) - return $tr; - else + if ($test){ + return $tr; + } return $fa; } +/** + * + * @param int|string $size + * @param string $html + * @return string + */ function format_size($size,$html=0) { - // Retourne une taille formattée en Octets, Kilo-octets, Méga-octets ou Giga-Octets, avec 2 décimales. + // Retourne une taille formatt�e en Octets, Kilo-octets, M�ga-octets ou Giga-Octets, avec 2 d�cimales. if ("-" == $size) { return $size; } @@ -307,13 +422,27 @@ function format_size($size,$html=0) { } } +/** + * + * @param int $hid + * @return string + */ function getlinkhelp($hid) { return "(?)"; } +/** + * + * @param int $hid + */ function linkhelp($hid) { echo getlinkhelp($hid); } - +/** + * + * @param string $format + * @param string $date + * @return string + */ function format_date($format,$date) { $d=substr($date,8,2); $m=substr($date,5,2); @@ -330,7 +459,11 @@ function format_date($format,$date) { return sprintf($format,$d,$m,$y,$h,$i,$hh,$am); } -/* Strip slashes if needed : */ +/** + * Strip slashes if needed : + * @param string $str + * @return string + */ function ssla($str) { if (get_magic_quotes_gpc()) { return stripslashes($str); @@ -340,9 +473,9 @@ function ssla($str) { } /* ----------------------------------------------------------------- */ - /** Hashe un mot de passe en clair en MD5 avec un salt aléatoire - * @param string $pass Mot de passe à crypter (max 32 caractères) - * @return string Retourne le mot de passe crypté + /** Hashe un mot de passe en clair en MD5 avec un salt al�atoire + * @param string $pass Mot de passe � crypter (max 32 caract�res) + * @return string Retourne le mot de passe crypt� * @access private */ function _md5cr($pass,$salt="") { @@ -368,9 +501,9 @@ function split_mysql_database_name($dbname) { /* ----------------------------------------------------------------- */ -/** Echappe les caractères pouvant perturber un flux XML standard : - * @param string $string Chaine de caractère à encoder en valeur xml. - * @return string Retourne la chaîne modifiée si besoin. +/** Echappe les caract�res pouvant perturber un flux XML standard : + * @param string $string Chaine de caract�re � encoder en valeur xml. + * @return string Retourne la cha�ne modifi�e si besoin. * @access private */ function xml_entities($string) { @@ -380,7 +513,7 @@ function xml_entities($string) { /* ----------------------------------------------------------------- */ /** Converti un nombre de mois en une chaine plus lisible * @param number $months Nombre de mois - * @return string Chaîne représentant le nombre de mois + * @return string Cha�ne repr�sentant le nombre de mois * @access private */ function pretty_months($months) { @@ -393,9 +526,9 @@ function pretty_months($months) { } /* ----------------------------------------------------------------- */ -/** Fabrique un drop-down pour les durées de comptes +/** Fabrique un drop-down pour les dur�es de comptes * @name string $name Nom pour le composasnt - * @selected number Option selectionée du composant + * @selected number Option selection�e du composant * @return string Code html pour le drop-down * @access private */ @@ -422,10 +555,15 @@ function duration_list($name, $selected=0) { return $res; } -/* select_values($arr,$cur) echo des