[fix] code documentation, comments and cosmetic changes
This commit is contained in:
parent
3b1e0a359d
commit
6adef177c9
|
@ -17,11 +17,20 @@ class system_bind {
|
||||||
var $cache_domain_summary = array();
|
var $cache_domain_summary = array();
|
||||||
var $zone_file_directory = '/var/lib/alternc/bind/zones/';
|
var $zone_file_directory = '/var/lib/alternc/bind/zones/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
function system_bind() {
|
function system_bind() {
|
||||||
// Constructeur
|
// 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) {
|
function conf_from_db($domain=false) {
|
||||||
global $db;
|
global $db;
|
||||||
// Use cache, fill cache if empty
|
// Use cache, fill cache if empty
|
||||||
|
@ -53,11 +62,21 @@ class system_bind {
|
||||||
return $this->cache_conf_db;
|
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) {
|
function get_zone_file_uri($domain) {
|
||||||
return $this->zone_file_directory.$domain;
|
return $this->zone_file_directory.$domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $domain
|
||||||
|
* @return string zone file path
|
||||||
|
*/
|
||||||
function get_zone_file($domain) {
|
function get_zone_file($domain) {
|
||||||
// Use cache, fill cache if empty
|
// Use cache, fill cache if empty
|
||||||
if (!isset($this->cache_zone_file[$domain]) ) {
|
if (!isset($this->cache_zone_file[$domain]) ) {
|
||||||
|
@ -70,6 +89,11 @@ class system_bind {
|
||||||
return $this->cache_zone_file[$domain] ;
|
return $this->cache_zone_file[$domain] ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $domain
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
function get_serial($domain) {
|
function get_serial($domain) {
|
||||||
// Return the next serial the domain must have.
|
// Return the next serial the domain must have.
|
||||||
// Choose between a generated and an incremented.
|
// Choose between a generated and an incremented.
|
||||||
|
@ -89,7 +113,12 @@ class system_bind {
|
||||||
return max(array($calc,$old)) + 1 ;
|
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) {
|
function get_persistent($domain) {
|
||||||
if ( ! isset($this->cache_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);
|
preg_match_all('/\;\s*END\sALTERNC\sAUTOGENERATE\sCONFIGURATION(.*)/s', $this->get_zone_file($domain), $output_array);
|
||||||
|
@ -102,10 +131,21 @@ class system_bind {
|
||||||
return $this->cache_get_persistent[$domain];
|
return $this->cache_get_persistent[$domain];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $domain
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
function get_zone_header($domain) {
|
function get_zone_header($domain) {
|
||||||
return file_get_contents($this->ZONE_TEMPLATE);
|
return file_get_contents($this->ZONE_TEMPLATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @global m_dom $dom
|
||||||
|
* @param string $domain
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
function get_domain_summary($domain=false) {
|
function get_domain_summary($domain=false) {
|
||||||
global $dom;
|
global $dom;
|
||||||
|
|
||||||
|
@ -118,6 +158,11 @@ class system_bind {
|
||||||
else return $this->cache_domain_summary;
|
else return $this->cache_domain_summary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $domain
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function dkim_delete($domain) {
|
function dkim_delete($domain) {
|
||||||
$target_dir = "/etc/opendkim/keys/$domain";
|
$target_dir = "/etc/opendkim/keys/$domain";
|
||||||
if (file_exists($target_dir)) {
|
if (file_exists($target_dir)) {
|
||||||
|
@ -128,7 +173,12 @@ class system_bind {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate the domain DKIM key
|
/**
|
||||||
|
* Generate the domain DKIM key
|
||||||
|
*
|
||||||
|
* @param string $domain
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function dkim_generate_key($domain) {
|
function dkim_generate_key($domain) {
|
||||||
// Stop here if we do not manage the mail
|
// Stop here if we do not manage the mail
|
||||||
if ( ! $this->get_domain_summary($domain)['gesmx'] ) return;
|
if ( ! $this->get_domain_summary($domain)['gesmx'] ) return;
|
||||||
|
@ -152,8 +202,11 @@ class system_bind {
|
||||||
return true; // FIXME handle error
|
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";
|
$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";
|
$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";
|
$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) {
|
function dkim_entry($domain) {
|
||||||
$keyfile="/etc/opendkim/keys/$domain/alternc.txt";
|
$keyfile="/etc/opendkim/keys/$domain/alternc.txt";
|
||||||
if (! file_exists($keyfile) && $this->get_domain_summary($domain)['gesmx'] ) {
|
if (! file_exists($keyfile) && $this->get_domain_summary($domain)['gesmx'] ) {
|
||||||
|
@ -215,8 +272,13 @@ class system_bind {
|
||||||
return @file_get_contents($keyfile);
|
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) {
|
function mail_autoconfig_entry($domain) {
|
||||||
$zone= implode("\n",$this->conf_from_db($domain))."\n".$this->get_persistent($domain);
|
$zone= implode("\n",$this->conf_from_db($domain))."\n".$this->get_persistent($domain);
|
||||||
|
|
||||||
|
@ -236,7 +298,20 @@ class system_bind {
|
||||||
return $entry;
|
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) {
|
function get_zone($domain) {
|
||||||
global $L_FQDN, $L_NS1_HOSTNAME, $L_NS2_HOSTNAME, $L_DEFAULT_MX, $L_DEFAULT_SECONDARY_MX, $L_PUBLIC_IP;
|
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;
|
return $zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $domain
|
||||||
|
*/
|
||||||
function reload_zone($domain) {
|
function reload_zone($domain) {
|
||||||
exec($this->RNDC." reload ".escapeshellarg($domain), $output, $return_value);
|
exec($this->RNDC." reload ".escapeshellarg($domain), $output, $return_value);
|
||||||
if ($return_value != 0 ) {
|
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) {
|
function is_locked($domain) {
|
||||||
preg_match_all("/(\;\s*LOCKED:YES)/i", $this->get_zone_file($domain), $output_array);
|
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])) {
|
if (isset($output_array[1][0]) && !empty($output_array[1][0])) {
|
||||||
|
@ -287,6 +371,13 @@ class system_bind {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @global m_mysql $db
|
||||||
|
* @global m_dom $dom
|
||||||
|
* @param string $domain
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function save_zone($domain) {
|
function save_zone($domain) {
|
||||||
global $db, $dom;
|
global $db, $dom;
|
||||||
|
|
||||||
|
@ -307,16 +398,26 @@ class system_bind {
|
||||||
return true; // fixme add tests
|
return true; // fixme add tests
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the zone configuration file
|
/**
|
||||||
|
* Delete the zone configuration file
|
||||||
|
*
|
||||||
|
* @param string $domain
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function delete_zone($domain) {
|
function delete_zone($domain) {
|
||||||
$file=$this->get_zone_file_uri($domain);
|
$file=$this->get_zone_file_uri($domain);
|
||||||
if (file_exists($file)) {
|
if (file_exists($file)) {
|
||||||
unlink($file);
|
unlink($file);
|
||||||
}
|
}
|
||||||
$this->dkim_delete($domain);
|
$this->dkim_delete($domain);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @global m_hooks $hooks
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function reload_named() {
|
function reload_named() {
|
||||||
global $hooks;
|
global $hooks;
|
||||||
// Generate the new conf file
|
// Generate the new conf file
|
||||||
|
@ -342,7 +443,13 @@ class system_bind {
|
||||||
return true;
|
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) {
|
function regenerate_conf($all=false) {
|
||||||
global $hooks;
|
global $hooks;
|
||||||
|
|
||||||
|
@ -365,10 +472,12 @@ class system_bind {
|
||||||
|
|
||||||
$this->dkim_refresh_list();
|
$this->dkim_refresh_list();
|
||||||
$this->reload_named();
|
$this->reload_named();
|
||||||
|
return true;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
private function dummy_for_translation() {
|
private function dummy_for_translation() {
|
||||||
_("The zone file of this domain is locked. Contact your administrator.");
|
_("The zone file of this domain is locked. Contact your administrator.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,8 @@ session_name('AlternC_Panel');
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Si vous voulez mettre le bureau en maintenance, décommentez le code ci-dessous
|
Si vous voulez mettre le bureau en maintenance, d<EFBFBD>commentez le code ci-dessous
|
||||||
et mettez votre ip dans le IF pour que seule votre ip puisse accéder au bureau :
|
et mettez votre ip dans le IF pour que seule votre ip puisse acc<EFBFBD>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
|
/* Toutes les pages du bureau passent ici. On utilise une s<EFBFBD>maphore pour
|
||||||
s'assurer que personne ne pourra accéder à 2 pages du bureau en même temps.
|
s'assurer que personne ne pourra acc<EFBFBD>der <EFBFBD> 2 pages du bureau en m<EFBFBD>me temps.
|
||||||
*/
|
*/
|
||||||
/* * /
|
/* * /
|
||||||
// 1. Get a semaphore id for the alternc magic number (18577)
|
// 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
|
// Define constants from vars of /etc/alternc/local.sh
|
||||||
// The you can't choose where is the AlternC Panel
|
// The you can't choose where is the AlternC Panel
|
||||||
|
define("DEFAULT_PASS_SIZE", 8);
|
||||||
define('ALTERNC_MAIL', "$L_ALTERNC_MAIL");
|
define('ALTERNC_MAIL', "$L_ALTERNC_MAIL");
|
||||||
define('ALTERNC_HTML', "$L_ALTERNC_HTML");
|
define('ALTERNC_HTML', "$L_ALTERNC_HTML");
|
||||||
if(isset($L_ALTERNC_LOGS_ARCHIVE))
|
if(isset($L_ALTERNC_LOGS_ARCHIVE))
|
||||||
|
@ -121,13 +122,13 @@ $root=ALTERNC_PANEL."/";
|
||||||
require_once($root."/class/db_mysql.php");
|
require_once($root."/class/db_mysql.php");
|
||||||
require_once($root."/class/functions.php");
|
require_once($root."/class/functions.php");
|
||||||
|
|
||||||
// Redirection si appel à https://(!fqdn)/
|
// Redirection si appel <EFBFBD> https://(!fqdn)/
|
||||||
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"]=="on" && $host!=$L_FQDN) {
|
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"]=="on" && $host!=$L_FQDN) {
|
||||||
header("Location: https://$L_FQDN/");
|
header("Location: https://$L_FQDN/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Classe héritée de la classe db de la phplib.
|
// Classe h<EFBFBD>rit<EFBFBD>e de la classe db de la phplib.
|
||||||
/**
|
/**
|
||||||
* Class for MySQL management in the bureau
|
* Class for MySQL management in the bureau
|
||||||
*
|
*
|
||||||
|
|
|
@ -27,19 +27,43 @@
|
||||||
list($usec, $sec) = explode(' ', microtime());
|
list($usec, $sec) = explode(' ', microtime());
|
||||||
mt_srand((float) $sec + ((float) $usec * 100000));
|
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)); }
|
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) {
|
function variable_get($name, $default = null, $createit_comment = null, $type=null) {
|
||||||
global $variables;
|
global $variables;
|
||||||
return $variables->variable_get($name, $default, $createit_comment, $type);
|
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) {
|
function checkhostallow($domain,$dns) {
|
||||||
global $L_NS1,$L_NS2,$db,$dom;
|
global $L_NS1,$L_NS2,$db,$dom;
|
||||||
$sizefound=0;
|
$sizefound=0;
|
||||||
|
@ -76,9 +100,13 @@ function checkhostallow($domain,$dns) {
|
||||||
return -3; // DNS incorrect in the whois
|
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) {
|
function checkhostallow_nodns($domain) {
|
||||||
global $db;
|
global $db;
|
||||||
$sizefound=0;
|
$sizefound=0;
|
||||||
|
@ -103,13 +131,21 @@ function checkhostallow_nodns($domain) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
function get_remote_ip() {
|
function get_remote_ip() {
|
||||||
// Return the remote IP.
|
// Return the remote IP.
|
||||||
// If you are behind a proxy, use X_FORWARDED_FOR instead of REMOTE_ADDR
|
// If you are behind a proxy, use X_FORWARDED_FOR instead of REMOTE_ADDR
|
||||||
return getenv('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) {
|
function checkurl($url) {
|
||||||
// TODO : add a path/file check
|
// TODO : add a path/file check
|
||||||
if (substr($url,0,7)!="http://" && substr($url,0,8)!="https://" && substr($url,0,6)!="ftp://") return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check that TXT domain is correct */
|
/**
|
||||||
|
* Check that TXT domain is correct
|
||||||
|
*
|
||||||
|
* @param string $txt
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function checksubtxt($txt) {
|
function checksubtxt($txt) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/* Check that CNAME domain is correct */
|
/**
|
||||||
|
* Check that CNAME domain is correct
|
||||||
|
* @param string $cname
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function checkcname($cname) {
|
function checkcname($cname) {
|
||||||
return true;
|
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) {
|
function checkip($ip) {
|
||||||
// return true or false whether the ip is correctly formatted
|
// return true or false whether the ip is correctly formatted
|
||||||
return filter_var($ip,FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
|
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) {
|
function checkipv6($ip) {
|
||||||
// return true or false whether the ip is correctly formatted
|
// return true or false whether the ip is correctly formatted
|
||||||
return filter_var($ip,FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
|
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) {
|
function checkloginmail($mail) {
|
||||||
return true;
|
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) {
|
function checkmail($mail) {
|
||||||
if (filter_var($mail,FILTER_VALIDATE_EMAIL)) {
|
if (filter_var($mail,FILTER_VALIDATE_EMAIL)) {
|
||||||
return 0;
|
return FALSE;
|
||||||
} else {
|
} 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) {
|
function checkfqdn($fqdn) {
|
||||||
// (RFC 1035 http://www.ietf.org/rfc/rfc1035.txt)
|
// (RFC 1035 http://www.ietf.org/rfc/rfc1035.txt)
|
||||||
// Retourne 0 si tout va bien, sinon, retourne un code erreur...
|
// Retourne 0 si tout va bien, sinon, retourne un code erreur...
|
||||||
|
@ -186,12 +251,16 @@ function checkfqdn($fqdn) {
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkuserpath($path) {
|
/**
|
||||||
/*
|
*
|
||||||
return 0 if the path is not in the user's space
|
* @global m_mem $mem
|
||||||
return 1 if this is a directory
|
* @param string $path
|
||||||
return 2 if this is a regular file
|
* @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) {
|
||||||
global $mem;
|
global $mem;
|
||||||
$user=$mem->user["login"];
|
$user=$mem->user["login"];
|
||||||
$usar=substr($user,0,1);
|
$usar=substr($user,0,1);
|
||||||
|
@ -217,9 +286,10 @@ function checkuserpath($path) {
|
||||||
/**
|
/**
|
||||||
* get the home of the user
|
* get the home of the user
|
||||||
*
|
*
|
||||||
|
* @global m_mem $mem
|
||||||
* @args string $user the username, if null will use the global $mem. no
|
* @args string $user the username, if null will use the global $mem. no
|
||||||
* security checks performed on path
|
* security checks performed on path
|
||||||
* @returns string the actual absolute path
|
* @return string the actual absolute path
|
||||||
*/
|
*/
|
||||||
function getuserpath($user = null) {
|
function getuserpath($user = null) {
|
||||||
if (is_null($user)) {
|
if (is_null($user)) {
|
||||||
|
@ -229,48 +299,93 @@ function getuserpath($user = null) {
|
||||||
return rtrim(ALTERNC_HTML,"/")."/".substr($user,0,1)."/".$user;
|
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
|
* useful for checkboxes and radio buttons
|
||||||
|
*
|
||||||
|
* @param boolean $test
|
||||||
|
* @param boolean $echo
|
||||||
*/
|
*/
|
||||||
function cbox($test) {
|
function cbox($test, $echo = TRUE) {
|
||||||
if ($test) echo (" checked=\"checked\"");
|
if ($test) {
|
||||||
}
|
$return = " 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\"";
|
|
||||||
}
|
}
|
||||||
|
if( $echo ){
|
||||||
|
echo $return;
|
||||||
|
}
|
||||||
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ecif($test,$tr,$fa="",$affiche=1) {
|
|
||||||
if ($test)
|
|
||||||
$retour = $tr;
|
|
||||||
else
|
|
||||||
$retour = $fa;
|
|
||||||
|
|
||||||
if ($affiche)
|
/**
|
||||||
|
* 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;
|
echo $retour;
|
||||||
else
|
}
|
||||||
return $retour;
|
return $retour;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $str
|
||||||
|
*/
|
||||||
function __($str) {
|
function __($str) {
|
||||||
echo _($str);
|
echo _($str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param boolean $test
|
||||||
|
* @param string $tr
|
||||||
|
* @param string $fa
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
function ife($test,$tr,$fa="") {
|
function ife($test,$tr,$fa="") {
|
||||||
if ($test)
|
if ($test){
|
||||||
return $tr;
|
return $tr;
|
||||||
else
|
}
|
||||||
return $fa;
|
return $fa;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param int|string $size
|
||||||
|
* @param string $html
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
function format_size($size,$html=0) {
|
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<EFBFBD>e en Octets, Kilo-octets, M<>ga-octets ou Giga-Octets, avec 2 d<>cimales.
|
||||||
if ("-" == $size) {
|
if ("-" == $size) {
|
||||||
return $size;
|
return $size;
|
||||||
}
|
}
|
||||||
|
@ -307,13 +422,27 @@ function format_size($size,$html=0) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param int $hid
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
function getlinkhelp($hid) {
|
function getlinkhelp($hid) {
|
||||||
return "(<a href=\"javascript:help($hid);\">?</a>)";
|
return "(<a href=\"javascript:help($hid);\">?</a>)";
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param int $hid
|
||||||
|
*/
|
||||||
function linkhelp($hid) {
|
function linkhelp($hid) {
|
||||||
echo getlinkhelp($hid);
|
echo getlinkhelp($hid);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $format
|
||||||
|
* @param string $date
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
function format_date($format,$date) {
|
function format_date($format,$date) {
|
||||||
$d=substr($date,8,2);
|
$d=substr($date,8,2);
|
||||||
$m=substr($date,5,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);
|
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) {
|
function ssla($str) {
|
||||||
if (get_magic_quotes_gpc()) {
|
if (get_magic_quotes_gpc()) {
|
||||||
return stripslashes($str);
|
return stripslashes($str);
|
||||||
|
@ -340,9 +473,9 @@ function ssla($str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Hashe un mot de passe en clair en MD5 avec un salt aléatoire
|
/** Hashe un mot de passe en clair en MD5 avec un salt al<EFBFBD>atoire
|
||||||
* @param string $pass Mot de passe à crypter (max 32 caractères)
|
* @param string $pass Mot de passe <EFBFBD> crypter (max 32 caract<EFBFBD>res)
|
||||||
* @return string Retourne le mot de passe crypté
|
* @return string Retourne le mot de passe crypt<EFBFBD>
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function _md5cr($pass,$salt="") {
|
function _md5cr($pass,$salt="") {
|
||||||
|
@ -368,9 +501,9 @@ function split_mysql_database_name($dbname) {
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Echappe les caractères pouvant perturber un flux XML standard :
|
/** Echappe les caract<EFBFBD>res pouvant perturber un flux XML standard :
|
||||||
* @param string $string Chaine de caractère à encoder en valeur xml.
|
* @param string $string Chaine de caract<EFBFBD>re <EFBFBD> encoder en valeur xml.
|
||||||
* @return string Retourne la chaîne modifiée si besoin.
|
* @return string Retourne la cha<EFBFBD>ne modifi<EFBFBD>e si besoin.
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function xml_entities($string) {
|
function xml_entities($string) {
|
||||||
|
@ -380,7 +513,7 @@ function xml_entities($string) {
|
||||||
/* ----------------------------------------------------------------- */
|
/* ----------------------------------------------------------------- */
|
||||||
/** Converti un nombre de mois en une chaine plus lisible
|
/** Converti un nombre de mois en une chaine plus lisible
|
||||||
* @param number $months Nombre de mois
|
* @param number $months Nombre de mois
|
||||||
* @return string Chaîne représentant le nombre de mois
|
* @return string Cha<EFBFBD>ne repr<EFBFBD>sentant le nombre de mois
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function pretty_months($months) {
|
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<EFBFBD>es de comptes
|
||||||
* @name string $name Nom pour le composasnt
|
* @name string $name Nom pour le composasnt
|
||||||
* @selected number Option selectionée du composant
|
* @selected number Option selection<EFBFBD>e du composant
|
||||||
* @return string Code html pour le drop-down
|
* @return string Code html pour le drop-down
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
|
@ -422,10 +555,15 @@ function duration_list($name, $selected=0) {
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* select_values($arr,$cur) echo des <option> du tableau $values ou de la table sql $values
|
/**
|
||||||
selectionne $current par defaut.
|
* select_values($arr,$cur) echo des <option> du tableau $values ou de la table sql $values
|
||||||
Si on lui demande poliement, il prend un tableau a une dimension
|
* selectionne $current par defaut.
|
||||||
*/
|
* Si on lui demande poliement, il prend un tableau a une dimension
|
||||||
|
*
|
||||||
|
* @param array $values
|
||||||
|
* @param string $cur
|
||||||
|
* @param boolean $onedim
|
||||||
|
*/
|
||||||
function eoption($values,$cur,$onedim=false) {
|
function eoption($values,$cur,$onedim=false) {
|
||||||
if (is_array($values)) {
|
if (is_array($values)) {
|
||||||
foreach ($values as $k=>$v) {
|
foreach ($values as $k=>$v) {
|
||||||
|
@ -438,24 +576,35 @@ function eoption($values,$cur,$onedim=false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
/* Echo the HTMLSpecialChars version of a value.
|
/* Echo the HTMLSpecialChars version of a value.
|
||||||
* Must be called when pre-filling fields values in forms such as :
|
* Must be called when pre-filling fields values in forms such as :
|
||||||
* <input type="text" name="toto" value="<?php ehe($toto); ?>" />
|
* <input type="text" name="toto" value="<?php ehe($toto); ?>" />
|
||||||
* Use the charset of the current language for transcription
|
* Use the charset of the current language for transcription
|
||||||
|
*
|
||||||
|
* @global string $charset
|
||||||
|
* @param string $str
|
||||||
|
* @param boolean $affiche
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
function ehe($str,$affiche=1) {
|
function ehe($str,$affiche = TRUE) {
|
||||||
global $charset;
|
global $charset;
|
||||||
$retour = htmlspecialchars($str,ENT_QUOTES,$charset);
|
$retour = htmlspecialchars($str,ENT_QUOTES,$charset);
|
||||||
if ($affiche) {
|
if ($affiche) {
|
||||||
echo $retour;
|
echo $retour;
|
||||||
} else {
|
|
||||||
return $retour;
|
|
||||||
}
|
}
|
||||||
|
return $retour;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the Fields of the posted form from $_REQUEST or POST or GET
|
/* Get the Fields of the posted form from $_REQUEST or POST or GET
|
||||||
* and check their type
|
* and check their type
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param array $fields
|
||||||
|
* @param boolean $requestOnly
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
function getFields($fields, $requestOnly = false) {
|
function getFields($fields, $requestOnly = false) {
|
||||||
$vars = array();
|
$vars = array();
|
||||||
$methodType = array ("get", "post", "request", "files", "server");
|
$methodType = array ("get", "post", "request", "files", "server");
|
||||||
|
@ -500,11 +649,21 @@ function getFields($fields, $requestOnly = false) {
|
||||||
return $vars;
|
return $vars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param array $array
|
||||||
|
*/
|
||||||
function printVar($array) {
|
function printVar($array) {
|
||||||
echo "<pre style=\"border: 1px solid black; text-align: left; font-size: 9px\">\n";
|
echo "<pre style=\"border: 1px solid black; text-align: left; font-size: 9px\">\n";
|
||||||
print_r($array);
|
print_r($array);
|
||||||
echo "</pre>\n";
|
echo "</pre>\n";
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param array $a
|
||||||
|
* @param array $b
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
function list_properties_order($a, $b) {
|
function list_properties_order($a, $b) {
|
||||||
if ( $a['label'] == $b['label']) {
|
if ( $a['label'] == $b['label']) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -513,16 +672,29 @@ function list_properties_order($a, $b) {
|
||||||
} // end private function list_properties_order
|
} // end private function list_properties_order
|
||||||
|
|
||||||
|
|
||||||
/** Show a pager as
|
|
||||||
Previous page 0 1 2 ... 16 17 18 19 20 ... 35 36 37 Next page
|
/**
|
||||||
Arguments are as follow :
|
* Shows a pager : Previous page 0 1 2 ... 16 17 18 19 20 ... 35 36 37 Next page
|
||||||
$offset = the current offset from 0
|
*
|
||||||
$count = The number of elements shown per page
|
*
|
||||||
$total = The total number of elements
|
* Arguments are as follow :
|
||||||
$url = The url to show for each page. %%offset%% will be replace by the proper offset
|
* $offset = the current offset from 0
|
||||||
$before & $after are HTML code to show before and after the pager **only if the pager is to be shown**
|
* $count = The number of elements shown per page
|
||||||
|
* $total = The total number of elements
|
||||||
|
* $url = The url to show for each page. %%offset%% will be replace by the proper offset
|
||||||
|
* $before & $after are HTML code to show before and after the pager **only if the pager is to be shown
|
||||||
|
*
|
||||||
|
* @param int $offset
|
||||||
|
* @param int $count
|
||||||
|
* @param int $total
|
||||||
|
* @param string $url
|
||||||
|
* @param string $before
|
||||||
|
* @param string $after
|
||||||
|
* @param boolean $echo
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
function pager($offset,$count,$total,$url,$before="",$after="") {
|
function pager($offset,$count,$total,$url,$before="",$after="",$echo = TRUE) {
|
||||||
|
$return = "";
|
||||||
$offset=intval($offset);
|
$offset=intval($offset);
|
||||||
$count=intval($count);
|
$count=intval($count);
|
||||||
$total=intval($total);
|
$total=intval($total);
|
||||||
|
@ -534,73 +706,83 @@ function pager($offset,$count,$total,$url,$before="",$after="") {
|
||||||
if ($total<=$count) { // When there is less element than 1 complete page, just don't do anything :-D
|
if ($total<=$count) { // When there is less element than 1 complete page, just don't do anything :-D
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
echo $before;
|
$return .= $before;
|
||||||
// Shall-we show previous page link ?
|
// Shall-we show previous page link ?
|
||||||
if ($offset) {
|
if ($offset) {
|
||||||
$o=max($offset-$count,0);
|
$o = max($offset-$count,0);
|
||||||
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\" alt=\"(Ctl/Alt-p)\" title=\"(Alt-p)\" accesskey=\"p\">"._("Previous Page")."</a> ";
|
$return .= "<a href=\"".str_replace("%%offset%%",$o,$url)."\" alt=\"(Ctl/Alt-p)\" title=\"(Alt-p)\" accesskey=\"p\">"._("Previous Page")."</a> ";
|
||||||
} else {
|
} else {
|
||||||
echo _("Previous Page")." ";
|
$return .= _("Previous Page")." ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($total>(2*$count)) { // On n'affiche le pager central (0 1 2 ...) s'il y a au moins 2 pages.
|
if ($total>(2*$count)) { // On n'affiche le pager central (0 1 2 ...) s'il y a au moins 2 pages.
|
||||||
echo " - ";
|
$return .= " - ";
|
||||||
if (($total<($count*10)) && ($total>$count)) { // moins de 10 pages :
|
if (($total<($count*10)) && ($total>$count)) { // moins de 10 pages :
|
||||||
for($i=0;$i<$total/$count;$i++) {
|
for($i=0;$i<$total/$count;$i++) {
|
||||||
$o=$i*$count;
|
$o=$i*$count;
|
||||||
if ($offset==$o) {
|
if ($offset==$o) {
|
||||||
echo $i." ";
|
$return .= $i." ";
|
||||||
} else {
|
} else {
|
||||||
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\">$i</a> ";
|
$return .= "<a href=\"".str_replace("%%offset%%",$o,$url)."\">$i</a> ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // Plus de 10 pages, on affiche 0 1 2 , 2 avant et 2 après la page courante, et les 3 dernieres
|
} else { // Plus de 10 pages, on affiche 0 1 2 , 2 avant et 2 apr<EFBFBD>s la page courante, et les 3 dernieres
|
||||||
for($i=0;$i<=2;$i++) {
|
for($i=0;$i<=2;$i++) {
|
||||||
$o=$i*$count;
|
$o=$i*$count;
|
||||||
if ($offset==$o) {
|
if ($offset==$o) {
|
||||||
echo $i." ";
|
$return .= $i." ";
|
||||||
} else {
|
} else {
|
||||||
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\">$i</a> ";
|
$return .= "<a href=\"".str_replace("%%offset%%",$o,$url)."\">$i</a> ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($offset>=$count && $offset<($total-2*$count)) { // On est entre les milieux ...
|
if ($offset>=$count && $offset<($total-2*$count)) { // On est entre les milieux ...
|
||||||
// On affiche 2 avant jusque 2 après l'offset courant mais sans déborder sur les indices affichés autour
|
// On affiche 2 avant jusque 2 apr<EFBFBD>s l'offset courant mais sans d<>border sur les indices affich<63>s autour
|
||||||
$start=max(3,intval($offset/$count)-2);
|
$start=max(3,intval($offset/$count)-2);
|
||||||
$end=min(intval($offset/$count)+3,intval($total/$count)-3);
|
$end=min(intval($offset/$count)+3,intval($total/$count)-3);
|
||||||
if ($start!=3) echo " ... ";
|
if ($start!=3) $return .= " ... ";
|
||||||
for($i=$start;$i<$end;$i++) {
|
for($i=$start;$i<$end;$i++) {
|
||||||
$o=$i*$count;
|
$o=$i*$count;
|
||||||
if ($offset==$o) {
|
if ($offset==$o) {
|
||||||
echo $i." ";
|
$return .= $i." ";
|
||||||
} else {
|
} else {
|
||||||
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\">$i</a> ";
|
$return .= "<a href=\"".str_replace("%%offset%%",$o,$url)."\">$i</a> ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($end!=intval($total/$count)-3) echo " ... ";
|
if ($end!=intval($total/$count)-3) $return .= " ... ";
|
||||||
} else {
|
} else {
|
||||||
echo " ... ";
|
$return .= " ... ";
|
||||||
}
|
}
|
||||||
for($i=intval($total/$count)-3;$i<$total/$count;$i++) {
|
for($i=intval($total/$count)-3;$i<$total/$count;$i++) {
|
||||||
$o=$i*$count;
|
$o=$i*$count;
|
||||||
if ($offset==$o) {
|
if ($offset==$o) {
|
||||||
echo $i." ";
|
$return .= $i." ";
|
||||||
} else {
|
} else {
|
||||||
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\">$i</a> ";
|
$return .= "<a href=\"".str_replace("%%offset%%",$o,$url)."\">$i</a> ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo " - ";
|
$return .= " - ";
|
||||||
} // More than 10 pages?
|
} // More than 10 pages?
|
||||||
}
|
}
|
||||||
// Shall-we show the next page link ?
|
// Shall-we show the next page link ?
|
||||||
if ($offset+$count<$total) {
|
if ($offset+$count<$total) {
|
||||||
$o=$offset+$count;
|
$o=$offset+$count;
|
||||||
echo "<a href=\"".str_replace("%%offset%%",$o,$url)."\" alt=\"(Ctl/Alt-s)\" title=\"(Alt-s)\" accesskey=\"s\">"._("Next Page")."</a> ";
|
$return .= "<a href=\"".str_replace("%%offset%%",$o,$url)."\" alt=\"(Ctl/Alt-s)\" title=\"(Alt-s)\" accesskey=\"s\">"._("Next Page")."</a> ";
|
||||||
} else {
|
} else {
|
||||||
echo _("Next Page")." ";
|
$return .= _("Next Page")." ";
|
||||||
}
|
}
|
||||||
echo $after;
|
$return .= $after;
|
||||||
|
if( $echo ){
|
||||||
|
echo $return;
|
||||||
|
}
|
||||||
|
return $return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param int $length
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
function create_pass($length = 8){
|
function create_pass($length = 8){
|
||||||
$chars = "1234567890abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
$chars = "1234567890abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
@ -612,9 +794,16 @@ function create_pass($length = 8){
|
||||||
return $password;
|
return $password;
|
||||||
}
|
}
|
||||||
|
|
||||||
define("DEFAULT_PASS_SIZE", 8);
|
|
||||||
|
|
||||||
/* Affiche un bouton qui permet de generer automatiquement des mots de passes */
|
|
||||||
|
/**
|
||||||
|
* Affiche un bouton qui permet de generer automatiquement des mots de passes
|
||||||
|
*
|
||||||
|
* @param int $pass_size
|
||||||
|
* @param string $fields_to_fill1
|
||||||
|
* @param string $fields_to_fill2
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
function display_div_generate_password($pass_size=DEFAULT_PASS_SIZE, $fields_to_fill1="", $fields_to_fill2="") {
|
function display_div_generate_password($pass_size=DEFAULT_PASS_SIZE, $fields_to_fill1="", $fields_to_fill2="") {
|
||||||
$id=rand(1,1000);
|
$id=rand(1,1000);
|
||||||
echo "<div id='z$id' style='display:none;'><a href=\"javascript:generate_password_html('$id',$pass_size,'$fields_to_fill1','$fields_to_fill2');\">";
|
echo "<div id='z$id' style='display:none;'><a href=\"javascript:generate_password_html('$id',$pass_size,'$fields_to_fill1','$fields_to_fill2');\">";
|
||||||
|
@ -624,7 +813,14 @@ function display_div_generate_password($pass_size=DEFAULT_PASS_SIZE, $fields_to_
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Affiche un bouton pour selectionner un dossier sur le serveur */
|
/**
|
||||||
|
* Affiche un bouton pour selectionner un dossier sur le serveur
|
||||||
|
*
|
||||||
|
* @param string $dir
|
||||||
|
* @param string $caller
|
||||||
|
* @param int $width
|
||||||
|
* @param int $height
|
||||||
|
*/
|
||||||
function display_browser($dir="", $caller="main.dir", $width=350, $height=450) {
|
function display_browser($dir="", $caller="main.dir", $width=350, $height=450) {
|
||||||
// Browser id
|
// Browser id
|
||||||
$bid="b".rand(1,1000);
|
$bid="b".rand(1,1000);
|
||||||
|
@ -663,7 +859,14 @@ function display_browser($dir="", $caller="main.dir", $width=350, $height=450) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insere un $wrap_string tous les $max caracteres dans $message
|
/**
|
||||||
|
* Insere un $wrap_string tous les $max caracteres dans $message
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
* @param int $max
|
||||||
|
* @param string $wrap_string
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
function auto_wrap($message="",$max=10,$wrap_string="<wbr/>") {
|
function auto_wrap($message="",$max=10,$wrap_string="<wbr/>") {
|
||||||
$cpt = 0;
|
$cpt = 0;
|
||||||
$mot = split(" ",$message);
|
$mot = split(" ",$message);
|
||||||
|
@ -677,19 +880,23 @@ function auto_wrap($message="",$max=10,$wrap_string="<wbr/>") {
|
||||||
return $message;
|
return $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
** Converts HSV to RGB values
|
* Converts HSV to RGB values
|
||||||
** -----------------------------------------------------
|
* -----------------------------------------------------
|
||||||
** Reference: http://en.wikipedia.org/wiki/HSL_and_HSV
|
* Reference: http://en.wikipedia.org/wiki/HSL_and_HSV
|
||||||
** Purpose: Useful for generating colours with
|
* Purpose: Useful for generating colours with
|
||||||
** same hue-value for web designs.
|
* same hue-value for web designs.
|
||||||
** Input: Hue (H) Integer 0-360
|
* Input: Hue (H) Integer 0-360
|
||||||
** Saturation (S) Integer 0-100
|
* Saturation (S) Integer 0-100
|
||||||
** Lightness (V) Integer 0-100
|
* Lightness (V) Integer 0-100
|
||||||
** Output: String "R,G,B"
|
* Output: String "R,G,B"
|
||||||
** Suitable for CSS function RGB().
|
* Suitable for CSS function RGB().
|
||||||
*/
|
*
|
||||||
|
* @param int $iH
|
||||||
|
* @param int $iS
|
||||||
|
* @param int $iV
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
function fHSVtoRGB($iH, $iS, $iV) {
|
function fHSVtoRGB($iH, $iS, $iV) {
|
||||||
|
|
||||||
if($iH < 0) $iH = 0; // Hue:
|
if($iH < 0) $iH = 0; // Hue:
|
||||||
|
@ -732,12 +939,22 @@ function fHSVtoRGB($iH, $iS, $iV) {
|
||||||
return array('r'=>round($dR), 'g'=>round($dG), 'b'=>round($dB) );
|
return array('r'=>round($dR), 'g'=>round($dG), 'b'=>round($dB) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param int $hex
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
function hexa($hex)
|
function hexa($hex)
|
||||||
{
|
{
|
||||||
$num = dechex($hex);
|
$num = dechex($hex);
|
||||||
return (strlen("$num") >= 2) ? "$num" : "0$num";
|
return (strlen("$num") >= 2) ? "$num" : "0$num";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param int $p
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
function PercentToColor($p=0) {
|
function PercentToColor($p=0) {
|
||||||
if ($p>100) $p=100;
|
if ($p>100) $p=100;
|
||||||
if ($p<0) $p=0;
|
if ($p<0) $p=0;
|
||||||
|
@ -750,18 +967,36 @@ function PercentToColor($p=0) {
|
||||||
return $color;
|
return $color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @global m_err $err
|
||||||
|
* @global m_mem $mem
|
||||||
|
* @global int $cuid
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function panel_lock() {
|
function panel_lock() {
|
||||||
global $err,$mem,$cuid;
|
global $err,$mem,$cuid;
|
||||||
if ($cuid!=2000) return false;
|
if ($cuid!=2000) return false;
|
||||||
return touch(ALTERNC_LOCK_PANEL);
|
return touch(ALTERNC_LOCK_PANEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @global m_err $err
|
||||||
|
* @global m_mem $mem
|
||||||
|
* @global int $cuid
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function panel_unlock() {
|
function panel_unlock() {
|
||||||
global $err,$mem,$cuid;
|
global $err,$mem,$cuid;
|
||||||
if ($cuid!=2000) return false;
|
if ($cuid!=2000) return false;
|
||||||
return unlink(ALTERNC_LOCK_PANEL);
|
return unlink(ALTERNC_LOCK_PANEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function panel_islocked() {
|
function panel_islocked() {
|
||||||
return file_exists(ALTERNC_LOCK_PANEL);
|
return file_exists(ALTERNC_LOCK_PANEL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -380,7 +380,7 @@ class m_admin {
|
||||||
$err->raise("admin",_("Subject, message and sender are mandatory"));
|
$err->raise("admin",_("Subject, message and sender are mandatory"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
//@todo remove cf functions.php
|
||||||
if (checkmail($from) != 0) {
|
if (checkmail($from) != 0) {
|
||||||
$err->raise("admin",_("Sender is syntaxically incorrect"));
|
$err->raise("admin",_("Sender is syntaxically incorrect"));
|
||||||
return false;
|
return false;
|
||||||
|
@ -512,6 +512,7 @@ class m_admin {
|
||||||
$err->raise("admin",_("All fields are mandatory"));
|
$err->raise("admin",_("All fields are mandatory"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
//@todo remove cf functions.php
|
||||||
if (checkmail($mail)!=0){
|
if (checkmail($mail)!=0){
|
||||||
$err->raise("admin",_("Please enter a valid email address"));
|
$err->raise("admin",_("Please enter a valid email address"));
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -129,6 +129,8 @@ class m_cron {
|
||||||
$user=urlencode($user);
|
$user=urlencode($user);
|
||||||
if (empty($user)) $password='';
|
if (empty($user)) $password='';
|
||||||
$password=urlencode($password);
|
$password=urlencode($password);
|
||||||
|
|
||||||
|
//@todo remove checkmail cf functions.php
|
||||||
if (!empty($email) && ! checkmail($email) == 0 ){
|
if (!empty($email) && ! checkmail($email) == 0 ){
|
||||||
$err->raise("cron",_("Email address is not valid"));
|
$err->raise("cron",_("Email address is not valid"));
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -178,7 +178,7 @@ class m_hta {
|
||||||
if (!$file) {
|
if (!$file) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// TODO: Tester la validité du .htpasswd
|
// TODO: Tester la validit<EFBFBD> du .htpasswd
|
||||||
while (!feof($file)) {
|
while (!feof($file)) {
|
||||||
$s=fgets($file,1024);
|
$s=fgets($file,1024);
|
||||||
$t=explode(":",$s);
|
$t=explode(":",$s);
|
||||||
|
@ -242,6 +242,7 @@ class m_hta {
|
||||||
$err->raise("hta",printf(("The folder '%s' does not exist"),$dir));
|
$err->raise("hta",printf(("The folder '%s' does not exist"),$dir));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// @todo delete cf!. functions.php checkloginemail definition
|
||||||
if (checkloginmail($user)){
|
if (checkloginmail($user)){
|
||||||
// Check this password against the password policy using common API :
|
// Check this password against the password policy using common API :
|
||||||
if (is_callable(array($admin,"checkPolicy"))) {
|
if (is_callable(array($admin,"checkPolicy"))) {
|
||||||
|
|
Loading…
Reference in New Issue