REFACTORING: code formatting of the panel + braces on if/while/for + fixe some missing or too many Globals in functions

This commit is contained in:
Benjamin Sonntag 2015-09-25 00:01:04 +02:00
parent d4be9fddbf
commit 3e42567048
11 changed files with 1556 additions and 1524 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
/* /*
$Id: config.php,v 1.12 2005/12/18 09:51:32 benjamin Exp $ $Id: config.php,v 1.12 2005/12/18 09:51:32 benjamin Exp $
---------------------------------------------------------------------- ----------------------------------------------------------------------
@ -29,7 +30,9 @@
*/ */
define('DO_XHPROF_STATS', FALSE); define('DO_XHPROF_STATS', FALSE);
if (DO_XHPROF_STATS) require_once('/usr/share/alternc/panel/admin/xhprof_header.php'); if (DO_XHPROF_STATS) {
require_once('/usr/share/alternc/panel/admin/xhprof_header.php');
}
// To enable the display of the alternc debug error, do the following : // To enable the display of the alternc debug error, do the following :
// # touch /etc/alternc/alternc_display_php_error // # touch /etc/alternc/alternc_display_php_error
@ -58,7 +61,8 @@ if (ini_get("safe_mode")) {
} }
// For people who want to authenticate with HTTP AUTH // For people who want to authenticate with HTTP AUTH
if (isset($_GET['http_auth'])) $http_auth=strval($_GET['http_auth']); if (isset($_GET['http_auth']))
$http_auth = strval($_GET['http_auth']);
if (isset($http_auth)) { if (isset($http_auth)) {
if (empty($_SERVER['PHP_AUTH_USER']) || empty($_SERVER['PHP_AUTH_PW'])) { if (empty($_SERVER['PHP_AUTH_USER']) || empty($_SERVER['PHP_AUTH_PW'])) {
header('WWW-Authenticate: Basic realm="AlternC Authentication"'); header('WWW-Authenticate: Basic realm="AlternC Authentication"');
@ -89,8 +93,9 @@ require_once(dirname(__FILE__)."/local.php");
define("DEFAULT_PASS_SIZE", 8); 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)) {
define('ALTERNC_LOGS_ARCHIVE', "$L_ALTERNC_LOGS_ARCHIVE"); define('ALTERNC_LOGS_ARCHIVE', "$L_ALTERNC_LOGS_ARCHIVE");
}
define('ALTERNC_LOGS', "$L_ALTERNC_LOGS"); define('ALTERNC_LOGS', "$L_ALTERNC_LOGS");
define('ALTERNC_PANEL', "/usr/share/alternc/panel"); define('ALTERNC_PANEL', "/usr/share/alternc/panel");
define('ALTERNC_LOCALES', ALTERNC_PANEL . "/locales"); define('ALTERNC_LOCALES', ALTERNC_PANEL . "/locales");
@ -114,16 +119,15 @@ if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"]=="on" && $host!=$L_FQDN) {
header("Location: https://$L_FQDN/"); header("Location: https://$L_FQDN/");
} }
// child class of the phplib parent DB class
// Classe h<>rit<69>e de la classe db de la phplib.
/** /**
* Class for MySQL management in the bureau * Class for MySQL management in the bureau
* *
* This class heriting from the db class of the phplib manages * This class heriting from the db class of the phplib manages
* the connection to the MySQL database. * the connection to the MySQL database.
*/ */
class DB_system extends DB_Sql { class DB_system extends DB_Sql {
var $Host = null; var $Host = null;
var $Database = null; var $Database = null;
var $User = null; var $User = null;
@ -139,6 +143,7 @@ class DB_system extends DB_Sql {
$this->User = $L_MYSQL_LOGIN; $this->User = $L_MYSQL_LOGIN;
$this->Password = $L_MYSQL_PWD; $this->Password = $L_MYSQL_PWD;
} }
} }
$db = new DB_system(); $db = new DB_system();
@ -165,7 +170,8 @@ foreach ( glob( $root."class/m_*.php") as $di ) {
// or files operations // or files operations
// We can imagine load those class only for command-line scripts. // We can imagine load those class only for command-line scripts.
foreach (glob($root . "class/class_system_*.php") as $fcs) { foreach (glob($root . "class/class_system_*.php") as $fcs) {
if (is_readable($fcs)) require_once($fcs); if (is_readable($fcs))
require_once($fcs);
} }
/* Language */ /* Language */
@ -192,14 +198,16 @@ if (!defined('NOCHECK')) {
for ($i = 0; $i < count($classes); $i++) { for ($i = 0; $i < count($classes); $i++) {
$name2 = $classes[$i]; $name2 = $classes[$i];
if (isset($$name2)) continue; // for already instancied class like mem, err or authip if (isset($$name2))
continue; // for already instancied class like mem, err or authip
$name1 = "m_" . $name2; $name1 = "m_" . $name2;
$$name2 = new $name1(); $$name2 = new $name1();
} }
$oldid = intval(isset($_COOKIE['oldid']) ? $_COOKIE['oldid'] : ''); $oldid = intval(isset($_COOKIE['oldid']) ? $_COOKIE['oldid'] : '');
$isinvited = false; $isinvited = false;
if ($admin->enabled) $isinvited=true; if ($admin->enabled)
$isinvited = true;
if ($oldid && $oldid != $cuid) { if ($oldid && $oldid != $cuid) {
$isinvited = true; $isinvited = true;
@ -213,5 +221,3 @@ variable_get('hosting_tld', '','This is a FQDN that designates the main hostname
variable_get('subadmin_restriction', '0', "This variable set the way the account list works for accounts other than 'admin' (2000). 0 (default) = admin other than admin/2000 can see their own account, but not the other one 1 = admin other than admin/2000 can see any account by clicking the ''show all accounts'' link.", array('desc' => 'Shared access activated?', 'type' => 'boolean')); variable_get('subadmin_restriction', '0', "This variable set the way the account list works for accounts other than 'admin' (2000). 0 (default) = admin other than admin/2000 can see their own account, but not the other one 1 = admin other than admin/2000 can see any account by clicking the ''show all accounts'' link.", array('desc' => 'Shared access activated?', 'type' => 'boolean'));
variable_get('auth_ip_ftp_default_yes', '1', "This variable set if you want to allow all IP address to access FTP by default. If the user start to define some IP or subnet in the allow list, only those he defined will be allowed.", array('desc' => 'Allow by default?', 'type' => 'boolean')); variable_get('auth_ip_ftp_default_yes', '1', "This variable set if you want to allow all IP address to access FTP by default. If the user start to define some IP or subnet in the allow list, only those he defined will be allowed.", array('desc' => 'Allow by default?', 'type' => 'boolean'));
?>

View File

@ -1,4 +1,5 @@
<?php <?php
/* /*
$Id: config_nochk.php,v 1.2 2004/11/04 06:56:49 anonymous Exp $ $Id: config_nochk.php,v 1.2 2004/11/04 06:56:49 anonymous Exp $
---------------------------------------------------------------------- ----------------------------------------------------------------------
@ -31,4 +32,3 @@
define('NOCHECK', 1); define('NOCHECK', 1);
require_once("config.php"); require_once("config.php");
?>

View File

@ -9,10 +9,9 @@
* $Id: db_mysql.php,v 1.3 2005/03/05 16:27:30 said Exp $ * $Id: db_mysql.php,v 1.3 2005/03/05 16:27:30 said Exp $
* *
*/ */
class DB_Sql { class DB_Sql {
/* public: connection parameters */ /* public: connection parameters */
var $Host = ""; var $Host = "";
var $Database = ""; var $Database = "";
var $User = ""; var $User = "";
@ -42,8 +41,6 @@ class DB_Sql {
var $Query_ID = 0; var $Query_ID = 0;
var $Query_String = ""; var $Query_String = "";
/** /**
* Constructor * Constructor
*/ */
@ -79,14 +76,18 @@ class DB_Sql {
*/ */
function connect($Database = "", $Host = "", $User = "", $Password = "") { function connect($Database = "", $Host = "", $User = "", $Password = "") {
/* Handle defaults */ /* Handle defaults */
if ("" == $Database) if ("" == $Database) {
$Database = $this->Database; $Database = $this->Database;
if ("" == $Host) }
if ("" == $Host) {
$Host = $this->Host; $Host = $this->Host;
if ("" == $User) }
if ("" == $User) {
$User = $this->User; $User = $this->User;
if ("" == $Password) }
if ("" == $Password) {
$Password = $this->Password; $Password = $this->Password;
}
/* establish connection, select database */ /* establish connection, select database */
if (0 == $this->Link_ID) { if (0 == $this->Link_ID) {
@ -134,16 +135,17 @@ class DB_Sql {
global $debug_alternc; global $debug_alternc;
/* No empty queries, please, since PHP4 chokes on them. */ /* No empty queries, please, since PHP4 chokes on them. */
if ($Query_String == "") if ($Query_String == "") {
/* The empty query string is passed on from the constructor, /* The empty query string is passed on from the constructor,
* when calling the class without a query, e.g. in situations * when calling the class without a query, e.g. in situations
* like these: '$db = new DB_Sql_Subclass;' * like these: '$db = new DB_Sql_Subclass;'
*/ */
return 0; return 0;
}
if (!$this->connect()) { if (!$this->connect()) {
return 0; /* we already complained in connect() about that. */ return 0; /* we already complained in connect() about that. */
}; }
# New query, discard previous result. # New query, discard previous result.
if ($this->Query_ID) { if ($this->Query_ID) {
@ -151,8 +153,9 @@ class DB_Sql {
$this->Query_String = $Query_String; $this->Query_String = $Query_String;
} }
if ($this->Debug) if ($this->Debug) {
printf("Debug: query = %s<br />\n", $Query_String); printf("Debug: query = %s<br />\n", $Query_String);
}
$debug_chrono_start = microtime(true); $debug_chrono_start = microtime(true);
$this->Query_ID = @mysql_query($Query_String, $this->Link_ID); $this->Query_ID = @mysql_query($Query_String, $this->Link_ID);
@ -211,12 +214,11 @@ class DB_Sql {
* *
* public: position in result set * public: position in result set
*/ */
function seek($pos = 0) { function seek($pos = 0) {
$status = @mysql_data_seek($this->Query_ID, $pos); $status = @mysql_data_seek($this->Query_ID, $pos);
if ($status) if ($status) {
$this->Row = $pos; $this->Row = $pos;
else { } else {
$this->halt("seek($pos) failed: result has " . $this->num_rows() . " rows"); $this->halt("seek($pos) failed: result has " . $this->num_rows() . " rows");
/* half assed attempt to save the day, /* half assed attempt to save the day,
@ -231,7 +233,7 @@ class DB_Sql {
return 1; return 1;
} }
/* public: table locking */ /** public: table locking */
function lock($table, $mode = "write") { function lock($table, $mode = "write") {
$this->connect(); $this->connect();
@ -267,8 +269,7 @@ class DB_Sql {
return $res; return $res;
} }
/** public: evaluate the result (size, width) */
/* public: evaluate the result (size, width) */
function affected_rows() { function affected_rows() {
return @mysql_affected_rows($this->Link_ID); return @mysql_affected_rows($this->Link_ID);
} }
@ -281,7 +282,7 @@ class DB_Sql {
return @mysql_num_fields($this->Query_ID); return @mysql_num_fields($this->Query_ID);
} }
/* public: shorthand notation */ /** public: shorthand notation */
function nf() { function nf() {
return $this->num_rows(); return $this->num_rows();
} }
@ -309,34 +310,26 @@ class DB_Sql {
return @mysql_insert_id($this->Link_ID); return @mysql_insert_id($this->Link_ID);
} }
/* public: sequence numbers */ /** public: sequence numbers */
function nextid($seq_name) { function nextid($seq_name) {
$this->connect(); $this->connect();
if ($this->lock($this->Seq_Table)) { if ($this->lock($this->Seq_Table)) {
/* get sequence number (locked) and increment */ /* get sequence number (locked) and increment */
$q = sprintf("select nextid from %s where seq_name = '%s'", $q = sprintf("select nextid from %s where seq_name = '%s'", $this->Seq_Table, $seq_name);
$this->Seq_Table,
$seq_name);
$id = @mysql_query($q, $this->Link_ID); $id = @mysql_query($q, $this->Link_ID);
$res = @mysql_fetch_array($id); $res = @mysql_fetch_array($id);
/* No current value, make one */ /* No current value, make one */
if (!is_array($res)) { if (!is_array($res)) {
$currentid = 0; $currentid = 0;
$q = sprintf("insert into %s values('%s', %s)", $q = sprintf("insert into %s values('%s', %s)", $this->Seq_Table, $seq_name, $currentid);
$this->Seq_Table,
$seq_name,
$currentid);
@mysql_query($q, $this->Link_ID); @mysql_query($q, $this->Link_ID);
} else { } else {
$currentid = $res["nextid"]; $currentid = $res["nextid"];
} }
$nextid = $currentid + 1; $nextid = $currentid + 1;
$q = sprintf("update %s set nextid = '%s' where seq_name = '%s'", $q = sprintf("update %s set nextid = '%s' where seq_name = '%s'", $this->Seq_Table, $nextid, $seq_name);
$this->Seq_Table,
$nextid,
$seq_name);
@mysql_query($q, $this->Link_ID); @mysql_query($q, $this->Link_ID);
$this->unlock(); $this->unlock();
} else { } else {
@ -346,7 +339,7 @@ class DB_Sql {
return $nextid; return $nextid;
} }
/* public: return table metadata */ /** public: return table metadata */
function metadata($table = '', $full = false) { function metadata($table = '', $full = false) {
$res = array(); $res = array();
@ -414,51 +407,13 @@ class DB_Sql {
} }
// free the result only if we were called on a table // free the result only if we were called on a table
if ($table) @mysql_free_result($id); if ($table) {
@mysql_free_result($id);
}
return $res; return $res;
} }
/********************************************************************************************************/ /** private: error handling */
// AJOUT PERSO : TEST
/* public: return table metadata
function retourneNameField($this->Query_ID,$full=false) {
$count = 0;
$id = 0;
$res = array();
$count = @mysql_num_fields($this->Query_ID);
// made this IF due to performance (one if is faster than $count if's)
if (!$full) {
for ($i=0; $i<$count; $i++) {
$res[$i]["table"] = @mysql_field_table ($id, $i);
$res[$i]["name"] = @mysql_field_name ($id, $i);
$res[$i]["type"] = @mysql_field_type ($id, $i);
$res[$i]["len"] = @mysql_field_len ($id, $i);
$res[$i]["flags"] = @mysql_field_flags ($id, $i);
}
} else { // full
$res["num_fields"]= $count;
for ($i=0; $i<$count; $i++) {
$res[$i]["table"] = @mysql_field_table ($id, $i);
$res[$i]["name"] = @mysql_field_name ($id, $i);
$res[$i]["type"] = @mysql_field_type ($id, $i);
$res[$i]["len"] = @mysql_field_len ($id, $i);
$res[$i]["flags"] = @mysql_field_flags ($id, $i);
$res["meta"][$res[$i]["name"]] = $i;
}
}
// free the result only if we were called on a table
if ($table) @mysql_free_result($id);
return $res;
}*/
/********************************************************************************************************/
/* private: error handling */
function halt($msg) { function halt($msg) {
$this->Error = @mysql_error($this->Link_ID); $this->Error = @mysql_error($this->Link_ID);
$this->Errno = @mysql_errno($this->Link_ID); $this->Errno = @mysql_errno($this->Link_ID);
@ -467,23 +422,21 @@ class DB_Sql {
$this->haltmsg($msg); $this->haltmsg($msg);
if ($this->Halt_On_Error != "report") if ($this->Halt_On_Error != "report") {
die("Session halted."); die("Session halted.");
} }
}
function haltmsg($msg) { function haltmsg($msg) {
printf("</td></tr></table><b>Database error:</b> %s<br />\n", $msg); printf("</td></tr></table><b>Database error:</b> %s<br />\n", $msg);
printf("<b>MySQL Error</b>: %s (%s)<br />\n", printf("<b>MySQL Error</b>: %s (%s)<br />\n", $this->Errno, $this->Error);
$this->Errno,
$this->Error);
} }
function table_names() { function table_names() {
$this->query("SHOW TABLES"); $this->query("SHOW TABLES");
$i = 0; $i = 0;
$return = array(); $return = array();
while ($info=mysql_fetch_row($this->Query_ID)) while ($info = mysql_fetch_row($this->Query_ID)) {
{
$return[$i]["table_name"] = $info[0]; $return[$i]["table_name"] = $info[0];
$return[$i]["tablespace_name"] = $this->Database; $return[$i]["tablespace_name"] = $this->Database;
$return[$i]["database"] = $this->Database; $return[$i]["database"] = $this->Database;
@ -491,5 +444,5 @@ class DB_Sql {
} }
return $return; return $return;
} }
} }
?>

View File

@ -1,4 +1,5 @@
<?php <?php
/* /*
---------------------------------------------------------------------- ----------------------------------------------------------------------
AlternC - Web Hosting System AlternC - Web Hosting System
@ -33,8 +34,9 @@ mt_srand((float) $sec + ((float) $usec * 100000));
* @param string $str * @param string $str
* @return string * @return string
*/ */
function fl($str) { return str_replace("<","&lt;",str_replace("\"","&quot;",$str)); } function fl($str) {
return str_replace("<", "&lt;", str_replace("\"", "&quot;", $str));
}
/** /**
* Check if a domain can be hosted on this server : * Check if a domain can be hosted on this server :
@ -64,24 +66,34 @@ function checkhostallow($domain,$dns) {
} }
} }
} }
if ( $dom->tld_no_check_at_all ) if ($dom->tld_no_check_at_all) {
return 0; // OK , the boss say that you can. return 0; // OK , the boss say that you can.
if (!$found || $fmode==0) // TLD not allowed at all
return -1;
if (($fmode!=4) && (!is_array($dns))) // NO dns found in the whois, and domain MUST exists
return -2;
if ($fmode>2) // OK, in the case 3 4 5
return $found;
$n1 = false; $n2 = false;
for ($i = 0;$i<count($dns);$i++) {
if (strtolower($dns[$i])==strtolower($L_NS1)) $n1 = true;
if (strtolower($dns[$i])==strtolower($L_NS2)) $n2 = true;
} }
if ($fmode==1 && $n1) // OK if (!$found || $fmode == 0) { // TLD not allowed at all
return -1;
}
if (($fmode != 4) && (!is_array($dns))) { // NO dns found in the whois, and domain MUST exists
return -2;
}
if ($fmode > 2) { // OK, in the case 3 4 5
return $found; return $found;
if ($fmode==2 && $n1 && $n2) // OK }
$n1 = false;
$n2 = false;
for ($i = 0; $i < count($dns); $i++) {
if (strtolower($dns[$i]) == strtolower($L_NS1)) {
$n1 = true;
}
if (strtolower($dns[$i]) == strtolower($L_NS2)) {
$n2 = true;
}
}
if ($fmode == 1 && $n1) {
return $found; return $found;
}
if ($fmode == 2 && $n1 && $n2) {
return $found;
}
return -3; // DNS incorrect in the whois return -3; // DNS incorrect in the whois
} }
@ -108,8 +120,9 @@ function checkhostallow_nodns($domain) {
} }
} }
// If we found a correct tld, let's find how many . before ;) // If we found a correct tld, let's find how many . before ;)
if (!$found || $fmode==0) // TLD not allowed at all if (!$found || $fmode == 0) { // TLD not allowed at all
return 1; return 1;
}
if (count(explode(".", substr($domain, 0, -$sizefound))) > 2) { if (count(explode(".", substr($domain, 0, -$sizefound))) > 2) {
return 1; return 1;
} }
@ -117,11 +130,11 @@ function checkhostallow_nodns($domain) {
} }
/** /**
* Return the remote IP.
* If you are behind a proxy, use X_FORWARDED_FOR instead of REMOTE_ADDR
* @return string * @return string
*/ */
function get_remote_ip() { 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'); return getenv('REMOTE_ADDR');
} }
@ -133,15 +146,24 @@ function get_remote_ip() {
*/ */
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://") {
if (substr($url,0,7)=="http://" ) $fq = substr($url,7); return false;
if (substr($url,0,8)=="https://") $fq = substr($url,8); }
if (substr($url,0,6)=="ftp://" ) $fq = substr($url,6); if (substr($url, 0, 7) == "http://") {
$fq = substr($url, 7);
}
if (substr($url, 0, 8) == "https://") {
$fq = substr($url, 8);
}
if (substr($url, 0, 6) == "ftp://") {
$fq = substr($url, 6);
}
$f = explode("/", $fq); $f = explode("/", $fq);
if (!is_array($f)) $f = array($f); if (!is_array($f)) {
$f = array($f);
}
$t = checkfqdn($f[0]); $t = checkfqdn($f[0]);
if ($t) return false; return !$t;
return true;
} }
/** /**
@ -153,13 +175,14 @@ function checkurl($url) {
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 * @param string $cname
* @return boolean * @return boolean
*/ */
function checkcname($cname) { function checkcname($cname) {
if ($check=checkfqdn(rtrim($cname,"."))) { if (($check = checkfqdn(rtrim($cname, ".")))) {
if ($check != 4) { // ALLOW non-fully qualified (no .) if ($check != 4) { // ALLOW non-fully qualified (no .)
return false; // bad FQDN return false; // bad FQDN
} }
@ -234,15 +257,20 @@ function checkfqdn($fqdn) {
// 2. L'un des membres est trop long. // 2. L'un des membres est trop long.
// 3. Caractere interdit dans l'un des membres. // 3. Caractere interdit dans l'un des membres.
// 4. Le fqdn ne fait qu'un seul membre (il n'est donc pas fq...) // 4. Le fqdn ne fait qu'un seul membre (il n'est donc pas fq...)
if (strlen($fqdn)>255) if (strlen($fqdn) > 255) {
return 1; return 1;
}
$members = explode(".", $fqdn); $members = explode(".", $fqdn);
if (count($members)>1) $ret = 0; else $ret = 4; if (count($members) > 1) {
$ret = 0;
} else {
$ret = 4;
}
reset($members); reset($members);
while (list ($key, $val) = each($members)) { while (list ($key, $val) = each($members)) {
if (strlen($val)>63) if (strlen($val) > 63) {
return 2; return 2;
}
// Note: a.foo.net is a valid domain // Note: a.foo.net is a valid domain
// Note: RFC1035 tells us that a domain should not start by a digit, but every registrar allows such a domain to be created ... too bad. // Note: RFC1035 tells us that a domain should not start by a digit, but every registrar allows such a domain to be created ... too bad.
if (!preg_match("#^[a-z0-9_]([a-z0-9-_]*[a-z0-9_])?$#i", $val)) { if (!preg_match("#^[a-z0-9_]([a-z0-9-_]*[a-z0-9_])?$#i", $val)) {
@ -253,7 +281,6 @@ function checkfqdn($fqdn) {
} }
/** /**
*
* @global m_mem $mem * @global m_mem $mem
* @param string $path * @param string $path
* @return int * @return int
@ -265,9 +292,9 @@ 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);
if (substr($path,0,1)!="/") if (substr($path, 0, 1) != "/") {
$path = "/" . $path; $path = "/" . $path;
}
$rpath = realpath(ALTERNC_HTML . "/$usar/$user$path"); $rpath = realpath(ALTERNC_HTML . "/$usar/$user$path");
if (!$rpath) { // if file or directory does not exist if (!$rpath) { // if file or directory does not exist
return 1; // FIXME is it safe to say OK in this case ? return 1; // FIXME is it safe to say OK in this case ?
@ -307,7 +334,7 @@ function getuserpath($user = null) {
* @param boolean $test * @param boolean $test
* @param boolean $echo * @param boolean $echo
*/ */
function cbox($test, $echo = TRUE) { function cbox($test, $echo = true) {
if ($test) { if ($test) {
$return = " checked=\"checked\""; $return = " checked=\"checked\"";
} else { } else {
@ -319,7 +346,6 @@ function cbox($test, $echo = TRUE) {
return $return; return $return;
} }
/** /**
* ECHOes selected="selected" only if the parameter is true * ECHOes selected="selected" only if the parameter is true
* useful for checkboxes and radio buttons * useful for checkboxes and radio buttons
@ -351,8 +377,7 @@ function selected($bool, $echo = TRUE) {
function ecif($test, $tr, $fa = "", $affiche = 1) { function ecif($test, $tr, $fa = "", $affiche = 1) {
if ($test) { if ($test) {
$retour = $tr; $retour = $tr;
} } else {
else{
$retour = $fa; $retour = $fa;
} }
if ($affiche) { if ($affiche) {
@ -435,6 +460,7 @@ function format_size($size,$html = 0) {
function getlinkhelp($hid) { function getlinkhelp($hid) {
return "(<a href=\"javascript:help($hid);\">?</a>)"; return "(<a href=\"javascript:help($hid);\">?</a>)";
} }
/** /**
* *
* @param int $hid * @param int $hid
@ -442,6 +468,7 @@ function getlinkhelp($hid) {
function linkhelp($hid) { function linkhelp($hid) {
echo getlinkhelp($hid); echo getlinkhelp($hid);
} }
/** /**
* *
* @param string $format * @param string $format
@ -478,6 +505,7 @@ function ssla($str) {
} }
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
/** Hashe un mot de passe en clair en MD5 avec un salt al<EFBFBD>atoire /** Hashe un mot de passe en clair en MD5 avec un salt al<EFBFBD>atoire
* @param string $pass Mot de passe <EFBFBD> crypter (max 32 caract<EFBFBD>res) * @param string $pass Mot de passe <EFBFBD> crypter (max 32 caract<EFBFBD>res)
* @return string Retourne le mot de passe crypt<EFBFBD> * @return string Retourne le mot de passe crypt<EFBFBD>
@ -504,8 +532,8 @@ function split_mysql_database_name($dbname) {
implode("_", array_slice($db_exploded_name, 1))); implode("_", array_slice($db_exploded_name, 1)));
} }
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
/** Echappe les caract<EFBFBD>res pouvant perturber un flux XML standard : /** Echappe les caract<EFBFBD>res pouvant perturber un flux XML standard :
* @param string $string Chaine de caract<EFBFBD>re <EFBFBD> encoder en valeur xml. * @param string $string Chaine de caract<EFBFBD>re <EFBFBD> encoder en valeur xml.
* @return string Retourne la cha<EFBFBD>ne modifi<EFBFBD>e si besoin. * @return string Retourne la cha<EFBFBD>ne modifi<EFBFBD>e si besoin.
@ -516,6 +544,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 integer $months Nombre de mois * @param integer $months Nombre de mois
* @return string Cha<EFBFBD>ne repr<EFBFBD>sentant le nombre de mois * @return string Cha<EFBFBD>ne repr<EFBFBD>sentant le nombre de mois
@ -531,6 +560,7 @@ function pretty_months($months) {
} }
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
/** Fabrique un drop-down pour les dur<EFBFBD>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<EFBFBD>e du composant * @selected number Option selection<EFBFBD>e du composant
@ -572,15 +602,18 @@ function duration_list($name, $selected = 0) {
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) {
if ( $onedim ) $k = $v; if ($onedim) {
$k = $v;
}
echo "<option value=\"$k\""; echo "<option value=\"$k\"";
if ($k==$cur) echo " selected=\"selected\""; if ($k == $cur) {
echo " selected=\"selected\"";
}
echo ">" . $v . "</option>"; echo ">" . $v . "</option>";
} }
} }
} }
/** /**
/* 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 :
@ -604,6 +637,7 @@ function ehe($str,$affiche = TRUE) {
/* 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 array $fields
@ -615,14 +649,14 @@ function getFields($fields, $requestOnly = false) {
$methodType = array("get", "post", "request", "files", "server"); $methodType = array("get", "post", "request", "files", "server");
foreach ($fields AS $name => $options) { foreach ($fields AS $name => $options) {
if (in_array(strtolower($options[0]), $methodType) === false) if (in_array(strtolower($options[0]), $methodType) === false) {
die("Unrecognized method type used for field " . $name . " : " . $options[0]); die("Unrecognized method type used for field " . $name . " : " . $options[0]);
}
if ($requestOnly === true) if ($requestOnly === true) {
$method = "_REQUEST"; $method = "_REQUEST";
else } else {
$method = "_" . strtoupper($options[0]); $method = "_" . strtoupper($options[0]);
}
switch ($options[1]) { switch ($options[1]) {
case "integer": case "integer":
$vars[$name] = (isset($GLOBALS[$method][$name]) && is_numeric($GLOBALS[$method][$name]) ? intval($GLOBALS[$method][$name]) : $options[2]); $vars[$name] = (isset($GLOBALS[$method][$name]) && is_numeric($GLOBALS[$method][$name]) ? intval($GLOBALS[$method][$name]) : $options[2]);
@ -648,9 +682,9 @@ function getFields($fields, $requestOnly = false) {
} }
// Insert into $GLOBALS. // Insert into $GLOBALS.
foreach ($vars AS $var => $value) foreach ($vars AS $var => $value) {
$GLOBALS[$var] = $value; $GLOBALS[$var] = $value;
}
return $vars; return $vars;
} }
@ -663,6 +697,7 @@ function printVar($array) {
print_r($array); print_r($array);
echo "</pre>\n"; echo "</pre>\n";
} }
/** /**
* *
* @param array $a * @param array $a
@ -674,9 +709,7 @@ function list_properties_order($a, $b) {
return 0; return 0;
} }
return ($a['label'] < $b['label']) ? -1 : 1; return ($a['label'] < $b['label']) ? -1 : 1;
} // end private function list_properties_order }
/** /**
* Shows a pager : Previous page 0 1 2 ... 16 17 18 19 20 ... 35 36 37 Next page * Shows a pager : Previous page 0 1 2 ... 16 17 18 19 20 ... 35 36 37 Next page
@ -698,16 +731,23 @@ function list_properties_order($a, $b) {
* @param boolean $echo * @param boolean $echo
* @return string * @return string
*/ */
function pager($offset,$count,$total,$url,$before = "",$after = "",$echo = TRUE) { function pager($offset, $count, $total, $url, $before = "", $after = "", $echo = true) {
$return = ""; $return = "";
$offset = intval($offset); $offset = intval($offset);
$count = intval($count); $count = intval($count);
$total = intval($total); $total = intval($total);
if ($offset<=0) $offset = "0"; if ($offset <= 0) {
if ($count<=1) $count = "1"; $offset = "0";
if ($total<=0) $total = "0"; }
if ($total<$offset) $offset = max(0,$total-$count); if ($count <= 1) {
$count = "1";
}
if ($total <= 0) {
$total = "0";
}
if ($total < $offset) {
$offset = max(0, $total - $count);
}
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;
} }
@ -744,7 +784,9 @@ function pager($offset,$count,$total,$url,$before = "",$after = "",$echo = TRUE)
// On affiche 2 avant jusque 2 apr<70>s l'offset courant mais sans d<>border sur les indices affich<63>s autour // On affiche 2 avant jusque 2 apr<70>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) $return .= " ... "; 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) {
@ -753,7 +795,9 @@ function pager($offset,$count,$total,$url,$before = "",$after = "",$echo = TRUE)
$return .= "<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) $return .= " ... "; if ($end != intval($total / $count) - 3) {
$return .= " ... ";
}
} else { } else {
$return .= " ... "; $return .= " ... ";
} }
@ -780,7 +824,6 @@ function pager($offset,$count,$total,$url,$before = "",$after = "",$echo = TRUE)
echo $return; echo $return;
} }
return $return; return $return;
} }
/** /**
@ -799,8 +842,6 @@ function create_pass($length = 8){
return $password; return $password;
} }
/** /**
* Affiche un bouton qui permet de generer automatiquement des mots de passes * Affiche un bouton qui permet de generer automatiquement des mots de passes
* *
@ -861,7 +902,6 @@ function display_browser($dir = "", $caller = "main.dir", $width = 350, $height
// --> // -->
</script> </script>
"; ";
} }
/** /**
@ -883,12 +923,24 @@ function display_browser($dir = "", $caller = "main.dir", $width = 350, $height
*/ */
function fHSVtoRGB($iH, $iS, $iV) { function fHSVtoRGB($iH, $iS, $iV) {
if($iH < 0) $iH = 0; // Hue: if ($iH < 0) {
if($iH > 360) $iH = 360; // 0-360 $iH = 0; // Hue:
if($iS < 0) $iS = 0; // Saturation: }
if($iS > 100) $iS = 100; // 0-100 if ($iH > 360) {
if($iV < 0) $iV = 0; // Lightness: $iH = 360; // 0-360
if($iV > 100) $iV = 100; // 0-100 }
if ($iS < 0) {
$iS = 0; // Saturation:
}
if ($iS > 100) {
$iS = 100; // 0-100
}
if ($iV < 0) {
$iV = 0; // Lightness:
}
if ($iV > 100) {
$iV = 100; // 0-100
}
$dS = $iS / 100.0; // Saturation: 0.0-1.0 $dS = $iS / 100.0; // Saturation: 0.0-1.0
$dV = $iV / 100.0; // Lightness: 0.0-1.0 $dV = $iV / 100.0; // Lightness: 0.0-1.0
@ -896,29 +948,56 @@ function fHSVtoRGB($iH, $iS, $iV) {
$dH = $iH / 60.0; // H-Prime: 0.0-6.0 $dH = $iH / 60.0; // H-Prime: 0.0-6.0
$dT = $dH; // Temp variable $dT = $dH; // Temp variable
while($dT >= 2.0) $dT -= 2.0; // php modulus does not work with float while ($dT >= 2.0) {
$dT -= 2.0; // php modulus does not work with float
}
$dX = $dC * (1 - abs($dT - 1)); // as used in the Wikipedia link $dX = $dC * (1 - abs($dT - 1)); // as used in the Wikipedia link
switch ($dH) { switch ($dH) {
case($dH >= 0.0 && $dH < 1.0): case($dH >= 0.0 && $dH < 1.0):
$dR = $dC; $dG = $dX; $dB = 0.0; break; $dR = $dC;
$dG = $dX;
$dB = 0.0;
break;
case($dH >= 1.0 && $dH < 2.0): case($dH >= 1.0 && $dH < 2.0):
$dR = $dX; $dG = $dC; $dB = 0.0; break; $dR = $dX;
$dG = $dC;
$dB = 0.0;
break;
case($dH >= 2.0 && $dH < 3.0): case($dH >= 2.0 && $dH < 3.0):
$dR = 0.0; $dG = $dC; $dB = $dX; break; $dR = 0.0;
$dG = $dC;
$dB = $dX;
break;
case($dH >= 3.0 && $dH < 4.0): case($dH >= 3.0 && $dH < 4.0):
$dR = 0.0; $dG = $dX; $dB = $dC; break; $dR = 0.0;
$dG = $dX;
$dB = $dC;
break;
case($dH >= 4.0 && $dH < 5.0): case($dH >= 4.0 && $dH < 5.0):
$dR = $dX; $dG = 0.0; $dB = $dC; break; $dR = $dX;
$dG = 0.0;
$dB = $dC;
break;
case($dH >= 5.0 && $dH < 6.0): case($dH >= 5.0 && $dH < 6.0):
$dR = $dC; $dG = 0.0; $dB = $dX; break; $dR = $dC;
$dG = 0.0;
$dB = $dX;
break;
default: default:
$dR = 0.0; $dG = 0.0; $dB = 0.0; break; $dR = 0.0;
$dG = 0.0;
$dB = 0.0;
break;
} }
$dM = $dV - $dC; $dM = $dV - $dC;
$dR += $dM; $dG += $dM; $dB += $dM; $dR += $dM;
$dR *= 255; $dG *= 255; $dB *= 255; $dG += $dM;
$dB += $dM;
$dR *= 255;
$dG *= 255;
$dB *= 255;
return array('r' => round($dR), 'g' => round($dG), 'b' => round($dB)); return array('r' => round($dR), 'g' => round($dG), 'b' => round($dB));
} }
@ -928,8 +1007,7 @@ function fHSVtoRGB($iH, $iS, $iV) {
* @param int $hex * @param int $hex
* @return int * @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";
} }
@ -940,8 +1018,12 @@ function hexa($hex)
* @return string * @return string
*/ */
function PercentToColor($p = 0) { function PercentToColor($p = 0) {
if ($p>100) $p = 100; if ($p > 100) {
if ($p<0) $p = 0; $p = 100;
}
if ($p < 0) {
$p = 0;
}
// Pour aller de vert a rouge en passant par jaune et orange // Pour aller de vert a rouge en passant par jaune et orange
$h = 1 + ((100 - $p) * 130 / 100); $h = 1 + ((100 - $p) * 130 / 100);
@ -959,8 +1041,10 @@ function PercentToColor($p = 0) {
* @return boolean * @return boolean
*/ */
function panel_lock() { function panel_lock() {
global $err,$mem,$cuid; global $cuid;
if ($cuid!=2000) return false; if ($cuid != 2000) {
return false;
}
return touch(ALTERNC_LOCK_PANEL); return touch(ALTERNC_LOCK_PANEL);
} }
@ -972,8 +1056,10 @@ function panel_lock() {
* @return boolean * @return boolean
*/ */
function panel_unlock() { function panel_unlock() {
global $err,$mem,$cuid; global $cuid;
if ($cuid!=2000) return false; if ($cuid != 2000) {
return false;
}
return unlink(ALTERNC_LOCK_PANEL); return unlink(ALTERNC_LOCK_PANEL);
} }
@ -984,5 +1070,3 @@ function panel_unlock() {
function panel_islocked() { function panel_islocked() {
return file_exists(ALTERNC_LOCK_PANEL); return file_exists(ALTERNC_LOCK_PANEL);
} }
?>

View File

@ -17,10 +17,14 @@ function update_locale($langpath) {
global $arr_lang_translation; global $arr_lang_translation;
$locales = array(); $locales = array();
$file = file("/etc/locale.gen", FILE_SKIP_EMPTY_LINES); $file = file("/etc/locale.gen", FILE_SKIP_EMPTY_LINES);
if (! is_array($file) ) return $locales; if (!is_array($file)) {
return $locales;
}
foreach ($file as $v) { foreach ($file as $v) {
if ((preg_match("/^([a-z][a-z]_[A-Z][A-Z])/", trim($v), $mat) && file_exists($langpath . '/' . $mat[1]))) { if ((preg_match("/^([a-z][a-z]_[A-Z][A-Z])/", trim($v), $mat) && file_exists($langpath . '/' . $mat[1]))) {
if (! array_key_exists($mat[1], $arr_lang_translation) ) continue; if (!array_key_exists($mat[1], $arr_lang_translation)) {
continue;
}
$locales[$mat[1]] = $mat[1]; $locales[$mat[1]] = $mat[1];
} }
} }
@ -64,8 +68,9 @@ if (! isset($locales[$lang])) { // Requested language not found in locales
} }
} }
if (!isset($locales[$lang])) list($lang)=each($locales); if (!isset($locales[$lang])) {
list($lang) = each($locales);
}
if (isset($setlang) && isset($lang)) { if (isset($setlang) && isset($lang)) {
setcookie("lang", $lang); setcookie("lang", $lang);
} }
@ -87,7 +92,7 @@ $empty="";
if (_($empty) && preg_match("#charset=([A-Za-z0-9\.-]*)#", _($empty), $mat)) { if (_($empty) && preg_match("#charset=([A-Za-z0-9\.-]*)#", _($empty), $mat)) {
$charset = $mat[1]; $charset = $mat[1];
} }
if (! isset($charset) || !$charset) $charset="UTF-8"; if (!isset($charset) || !$charset) {
$charset = "UTF-8";
}
bind_textdomain_codeset("alternc", "$charset"); bind_textdomain_codeset("alternc", "$charset");
?>

View File

@ -28,7 +28,7 @@ while (FALSE !== ($line = fgets($config_file))) {
fclose($config_file); fclose($config_file);
$config_file = fopen('/etc/alternc/my.cnf', 'r'); $config_file = fopen('/etc/alternc/my.cnf', 'r');
while (FALSE !== ($line = fgets($config_file))) { while (false!== ($line = fgets($config_file))) {
if (preg_match('/^([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $regs)) { if (preg_match('/^([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $regs)) {
switch ($regs[1]) { switch ($regs[1]) {
case "user": case "user":
@ -48,4 +48,3 @@ while (FALSE !== ($line = fgets($config_file))) {
} }
fclose($config_file); fclose($config_file);
?>

View File

@ -270,7 +270,6 @@ class m_action {
return false; return false;
} }
return $db->num_rows($result); return $db->num_rows($result);
} }
/** /**
@ -352,7 +351,7 @@ class m_action {
* @return boolean * @return boolean
*/ */
function get_job() { function get_job() {
global $db, $err; global $db;
$tab = array(); $tab = array();
$db->query("Select * from actions where begin !=0 and end = 0 ;"); $db->query("Select * from actions where begin !=0 and end = 0 ;");
if ($db->next_record()) { if ($db->next_record()) {
@ -371,7 +370,6 @@ class m_action {
* @return boolean * @return boolean
*/ */
function cancel($id) { function cancel($id) {
global $db;
$this->finish($id, 666); $this->finish($id, 666);
return true; return true;
} }

View File

@ -79,9 +79,9 @@ class m_admin {
*/ */
function hook_menu() { function hook_menu() {
global $mem, $cuid, $debug_alternc, $L_INOTIFY_UPDATE_DOMAIN; global $mem, $cuid, $debug_alternc, $L_INOTIFY_UPDATE_DOMAIN;
if (!$mem->checkRight()) if (!$mem->checkRight()) {
return false; return false;
}
$obj = array( $obj = array(
'title' => _("Administration"), 'title' => _("Administration"),
'ico' => 'images/admin.png', 'ico' => 'images/admin.png',
@ -343,38 +343,36 @@ class m_admin {
$request = 'SELECT compte AS uid FROM domaines WHERE 1'; $request = 'SELECT compte AS uid FROM domaines WHERE 1';
if ($pattern && preg_match('/[.a-zA-Z0-9]+/', $pattern)) if ($pattern && preg_match('/[.a-zA-Z0-9]+/', $pattern)) {
$request .= sprintf(' AND domaine LIKE "%%%s%%"', $pattern); $request .= sprintf(' AND domaine LIKE "%%%s%%"', $pattern);
}
if ($creator) if ($creator) {
$request .= sprintf(' AND compte in (select uid from membres where creator = "%s" ) ', $creator); $request .= sprintf(' AND compte in (select uid from membres where creator = "%s" ) ', $creator);
}
if ($mem->user['uid'] != 2000 && !$all) if ($mem->user['uid'] != 2000 && !$all) {
$request .= sprintf(' AND compte in (select uid from membres where creator = "%s") ', $cuid); $request .= sprintf(' AND compte in (select uid from membres where creator = "%s") ', $cuid);
}
$request .= ' GROUP BY uid'; $request .= ' GROUP BY uid';
} elseif ($pattern_type === 'login') { } elseif ($pattern_type === 'login') {
$request = 'SELECT uid FROM membres WHERE 1'; $request = 'SELECT uid FROM membres WHERE 1';
if ($pattern && preg_match('/[a-zA-Z0-9]+/', $pattern)) if ($pattern && preg_match('/[a-zA-Z0-9]+/', $pattern)) {
$request .= sprintf(' AND login LIKE "%%%s%%"', $pattern); $request .= sprintf(' AND login LIKE "%%%s%%"', $pattern);
}
if ($creator) if ($creator) {
$request .= sprintf(' AND creator = "%s"', $creator); $request .= sprintf(' AND creator = "%s"', $creator);
}
if ($mem->user['uid'] != 2000 && !$all) if ($mem->user['uid'] != 2000 && !$all) {
$request .= sprintf(' AND creator = "%s"', $cuid); $request .= sprintf(' AND creator = "%s"', $cuid);
}
$request .= ' ORDER BY login;'; $request .= ' ORDER BY login;';
} else { } else {
$err->raise("admin", _("Invalid pattern type provided. Are you even performing a legitimate action?")); $err->raise("admin", _("Invalid pattern type provided. Are you even performing a legitimate action?"));
return FALSE; return FALSE;
} }
} else { } else {
if ($creator) { if ($creator) {
// Limit listing to a specific reseller // Limit listing to a specific reseller
$request = "SELECT uid FROM membres WHERE creator='" . $creator . "' ORDER BY login;"; $request = "SELECT uid FROM membres WHERE creator='" . $creator . "' ORDER BY login;";
@ -411,7 +409,7 @@ class m_admin {
* @return boolean * @return boolean
*/ */
function mailallmembers($subject, $message, $from) { function mailallmembers($subject, $message, $from) {
global $err, $mem, $cuid, $db; global $err, $db;
$err->log("admin", "mailallmembers"); $err->log("admin", "mailallmembers");
if (!$this->enabled) { if (!$this->enabled) {
$err->raise("admin", _("-- Only administrators can access this page! --")); $err->raise("admin", _("-- Only administrators can access this page! --"));
@ -453,7 +451,7 @@ class m_admin {
* @return boolean * @return boolean
*/ */
function get_creator_list() { function get_creator_list() {
global $err, $mem, $cuid; global $err, $cuid;
$creators = array(); $creators = array();
@ -488,7 +486,7 @@ class m_admin {
* @return boolean TRUE if I am the creator of that account. FALSE else. * @return boolean TRUE if I am the creator of that account. FALSE else.
*/ */
function checkcreator($uid) { function checkcreator($uid) {
global $err, $mem, $db, $cuid; global $err, $db, $cuid;
if ($cuid == 2000) { if ($cuid == 2000) {
return true; return true;
} }
@ -514,7 +512,7 @@ class m_admin {
* @return boolean * @return boolean
*/ */
function add_shared_domain($u, $domain_name) { function add_shared_domain($u, $domain_name) {
global $db, $err, $dom, $mem, $cuid; global $err, $dom, $mem;
$err->log("admin", "add_shared_domain", $u . "/" . $domain_name); $err->log("admin", "add_shared_domain", $u . "/" . $domain_name);
if (!$mem->checkright()) { if (!$mem->checkright()) {
@ -575,7 +573,7 @@ class m_admin {
* @return boolean Returns FALSE if an error occurs, TRUE if not. * @return boolean Returns FALSE if an error occurs, TRUE if not.
*/ */
function add_mem($login, $pass, $nom, $prenom, $mail, $canpass = 1, $type = 'default', $duration = 0, $notes = "", $force = 0, $create_dom = '', $db_server_id) { function add_mem($login, $pass, $nom, $prenom, $mail, $canpass = 1, $type = 'default', $duration = 0, $notes = "", $force = 0, $create_dom = '', $db_server_id) {
global $err, $quota, $classes, $cuid, $mem, $L_MYSQL_DATABASE, $L_MYSQL_LOGIN, $hooks, $action; global $err, $cuid, $mem, $L_MYSQL_DATABASE, $L_MYSQL_LOGIN, $hooks, $action;
$err->log("admin", "add_mem", $login . "/" . $mail); $err->log("admin", "add_mem", $login . "/" . $mail);
if (!$this->enabled) { if (!$this->enabled) {
$err->raise("admin", _("-- Only administrators can access this page! --")); $err->raise("admin", _("-- Only administrators can access this page! --"));
@ -629,9 +627,10 @@ class m_admin {
$uid = 2000; $uid = 2000;
} else { } else {
$uid = $db->Record["nextid"]; $uid = $db->Record["nextid"];
if ($uid <= 2000) if ($uid <= 2000) {
$uid = 2000; $uid = 2000;
} }
}
$db->query("INSERT INTO membres (uid,login,pass,mail,creator,canpass,type,created,notes,db_server_id) VALUES ('$uid','$login','$pass','$mail','$cuid','$canpass', '$type', NOW(), '$notes', '$db_server_id');"); $db->query("INSERT INTO membres (uid,login,pass,mail,creator,canpass,type,created,notes,db_server_id) VALUES ('$uid','$login','$pass','$mail','$cuid','$canpass', '$type', NOW(), '$notes', '$db_server_id');");
$db->query("INSERT INTO local(uid,nom,prenom) VALUES('$uid','$nom','$prenom');"); $db->query("INSERT INTO local(uid,nom,prenom) VALUES('$uid','$nom','$prenom');");
$this->renew_update($uid, $duration); $this->renew_update($uid, $duration);
@ -749,8 +748,7 @@ EOF;
* @return boolean Returns FALSE if an error occurs, TRUE if not * @return boolean Returns FALSE if an error occurs, TRUE if not
*/ */
function update_mem($uid, $mail, $nom, $prenom, $pass, $enabled, $canpass, $type = 'default', $duration = 0, $notes = "", $reset_quotas = false) { function update_mem($uid, $mail, $nom, $prenom, $pass, $enabled, $canpass, $type = 'default', $duration = 0, $notes = "", $reset_quotas = false) {
global $err, $db; global $err, $db, $quota;
global $cuid, $quota;
$notes = addslashes($notes); $notes = addslashes($notes);
@ -853,7 +851,7 @@ EOF;
* @return boolean Returns FALSE if an error occurs, TRUE if not. * @return boolean Returns FALSE if an error occurs, TRUE if not.
*/ */
function del_mem($uid) { function del_mem($uid) {
global $err, $quota, $classes, $cuid, $mem, $dom, $hooks, $action; global $err, $mem, $dom, $hooks, $action;
$err->log("admin", "del_mem", $uid); $err->log("admin", "del_mem", $uid);
if (!$this->enabled) { if (!$this->enabled) {
@ -904,9 +902,9 @@ EOF;
global $err, $db; global $err, $db;
$periods = intval($periods); $periods = intval($periods);
if ($periods == 0) if ($periods == 0) {
return false; return false;
}
$query = "UPDATE membres SET renewed = renewed + INTERVAL (duration * $periods) MONTH WHERE uid=${uid};"; $query = "UPDATE membres SET renewed = renewed + INTERVAL (duration * $periods) MONTH WHERE uid=${uid};";
if ($db->query($query)) { if ($db->query($query)) {
return true; return true;
@ -929,13 +927,15 @@ EOF;
global $err, $db; global $err, $db;
if ($duration == 0) { if ($duration == 0) {
if ($db->query("UPDATE membres SET duration = NULL, renewed = NULL WHERE uid=$uid;")) if ($db->query("UPDATE membres SET duration = NULL, renewed = NULL WHERE uid=$uid;")) {
return true; return true;
}
} else { } else {
if ($db->query("UPDATE membres SET duration = $duration WHERE uid=$uid") && if ($db->query("UPDATE membres SET duration = $duration WHERE uid=$uid") &&
$db->query("UPDATE membres SET renewed = NOW() WHERE uid=$uid and renewed is null;")) $db->query("UPDATE membres SET renewed = NOW() WHERE uid=$uid and renewed is null;")) {
return true; return true;
} }
}
$err->raise("admin", _("Account not found")); $err->raise("admin", _("Account not found"));
return false; return false;
@ -992,12 +992,13 @@ EOF;
" WHEN m.renewed <= NOW() THEN 2" . " WHEN m.renewed <= NOW() THEN 2" .
" ELSE 1 END 'status' FROM membres m, local l" . " ELSE 1 END 'status' FROM membres m, local l" .
" WHERE m.uid = l.uid" . " WHERE m.uid = l.uid" .
" HAVING status=2 or status=3 ORDER BY status DESC, expiry;")) " HAVING status=2 or status=3 ORDER BY status DESC, expiry;")) {
return false; return false;
else { } else {
$res = array(); $res = array();
while ($db->next_record()) while ($db->next_record()) {
$res[] = $db->Record; $res[] = $db->Record;
}
return $res; return $res;
} }
} }
@ -1025,7 +1026,6 @@ EOF;
return true; return true;
} }
/** /**
* Turns a super-admin account into a common account * Turns a super-admin account into a common account
* *
@ -1238,8 +1238,9 @@ EOF;
function selecttldmode($current = false) { function selecttldmode($current = false) {
for ($i = 0; $i < count($this->tldmode); $i++) { for ($i = 0; $i < count($this->tldmode); $i++) {
echo "<option value=\"$i\""; echo "<option value=\"$i\"";
if ($current == $i) if ($current == $i) {
echo " selected=\"selected\""; echo " selected=\"selected\"";
}
echo ">" . _($this->tldmode[$i]) . "</option>\n"; echo ">" . _($this->tldmode[$i]) . "</option>\n";
} }
} }
@ -1294,11 +1295,13 @@ EOF;
$err->raise("admin", _("This TLD already exist")); $err->raise("admin", _("This TLD already exist"));
return false; return false;
} }
if (substr($tld, 0, 1) == ".") if (substr($tld, 0, 1) == ".") {
$tld = substr($tld, 1); $tld = substr($tld, 1);
}
$mode = intval($mode); $mode = intval($mode);
if ($mode == 0) if ($mode == 0) {
$mode = "0"; $mode = "0";
}
$db->query("INSERT INTO tld (tld,mode) VALUES ('$tld','$mode');"); $db->query("INSERT INTO tld (tld,mode) VALUES ('$tld','$mode');");
return true; return true;
} }
@ -1322,8 +1325,9 @@ EOF;
return false; return false;
} }
$mode = intval($mode); $mode = intval($mode);
if ($mode == 0) if ($mode == 0) {
$mode = "0"; $mode = "0";
}
$db->query("UPDATE tld SET mode='$mode' WHERE tld='$tld';"); $db->query("UPDATE tld SET mode='$mode' WHERE tld='$tld';");
return true; return true;
} }
@ -1350,7 +1354,7 @@ EOF;
* @return array an indexed array of associative array from the MySQL "policy" table * @return array an indexed array of associative array from the MySQL "policy" table
*/ */
function listPasswordPolicies() { function listPasswordPolicies() {
global $db, $classes, $hooks; global $db, $hooks;
$tmp1 = array(); $tmp1 = array();
$tmp2 = array(); $tmp2 = array();
$policies = array(); $policies = array();
@ -1358,16 +1362,6 @@ EOF;
while ($db->next_record()) { while ($db->next_record()) {
$tmp1[$db->Record["name"]] = $db->Record; $tmp1[$db->Record["name"]] = $db->Record;
} }
/* * /
foreach($classes as $c) {
if (method_exists($GLOBALS[$c],"alternc_password_policy")) {
$res=$GLOBALS[$c]->alternc_password_policy(); // returns an array
foreach($res as $k=>$v) {
$tmp2[$k]=$v;
}
}
}
/* */
$tmp3 = $hooks->invoke("alternc_password_policy"); $tmp3 = $hooks->invoke("alternc_password_policy");
foreach ($tmp3 as $v) { foreach ($tmp3 as $v) {
foreach ($v as $l => $m) { foreach ($v as $l => $m) {
@ -1433,7 +1427,7 @@ EOF;
* @return boolean TRUE if the password if OK for this login and this policy, FALSE if it is not. * @return boolean TRUE if the password if OK for this login and this policy, FALSE if it is not.
*/ */
function checkPolicy($policy, $login, $password) { function checkPolicy($policy, $login, $password) {
global $db, $err; global $err;
if (empty($login)) { if (empty($login)) {
$err->raise("admin", _("Please enter a login")); $err->raise("admin", _("Please enter a login"));
@ -1468,7 +1462,9 @@ EOF;
$logins = preg_split("/[@_-]/", $login); $logins = preg_split("/[@_-]/", $login);
$logins[] = $login; $logins[] = $login;
foreach ($logins as $l) { foreach ($logins as $l) {
if (!$l) continue; if (!$l) {
continue;
}
if (strpos($password, $l) !== false || strpos($l, $password) !== false) { if (strpos($password, $l) !== false || strpos($l, $password) !== false) {
$err->raise("admin", _("The password policy prevents you to use your login name inside your password or the other way around")); $err->raise("admin", _("The password policy prevents you to use your login name inside your password or the other way around"));
return false; return false;

View File

@ -1,4 +1,5 @@
<?php <?php
/* /*
$Id: mime.php,v 1.3 2004/06/03 14:32:20 anonymous Exp $ $Id: mime.php,v 1.3 2004/06/03 14:32:20 anonymous Exp $
---------------------------------------------------------------------- ----------------------------------------------------------------------
@ -42,8 +43,7 @@
if (!IsSet($MIME_H)) { if (!IsSet($MIME_H)) {
$MIME_H = 1; $MIME_H = 1;
$bro_mime= $bro_mime = array(
array(
"css" => "text/css", "css" => "text/css",
"csv" => "text/comma-separated-values", "csv" => "text/comma-separated-values",
"dia" => "application/x-dia", "dia" => "application/x-dia",
@ -86,8 +86,7 @@ $MIME_H=1;
"zip" => "application/zip", "zip" => "application/zip",
); );
$bro_icon= $bro_icon = array(
array(
"css" => "txt", "css" => "txt",
"csv" => "xls", "csv" => "xls",
"dia" => "jpg", "dia" => "jpg",
@ -130,8 +129,7 @@ $MIME_H=1;
"zip" => "zip", "zip" => "zip",
); );
$bro_type= $bro_type = array(
array(
"css" => _("CSS Stylesheet"), "css" => _("CSS Stylesheet"),
"csv" => _("Comma Separated Values data"), "csv" => _("Comma Separated Values data"),
"dia" => _("DIA Diagram"), "dia" => _("DIA Diagram"),
@ -173,6 +171,4 @@ $MIME_H=1;
"rm" => _("Real Media File"), "rm" => _("Real Media File"),
"ram" => _("Real Media File"), "ram" => _("Real Media File"),
); );
} }
?>

View File

@ -13,8 +13,7 @@ while ($db->next_record()) {
$d[] = $db->Record; $d[] = $db->Record;
} }
foreach ($d as $r) { foreach ($d as $r) {
echo "Stats de ".$r[0]." ".$r[1]." <br>\n"; flush(); echo "Stats de " . $r[0] . " " . $r[1] . " <br>\n";
flush();
$stats->_createconf($r[0], 1); $stats->_createconf($r[0], 1);
} }
?>

View File

@ -143,9 +143,7 @@ function variable_set($name, $value, $comment=null) {
*/ */
function variable_del($name) { function variable_del($name) {
global $conf, $db; global $conf, $db;
$db->query("DELETE FROM `variable` WHERE name = '" . $name . "'"); $db->query("DELETE FROM `variable` WHERE name = '" . $name . "'");
unset($conf[$name]); unset($conf[$name]);
} }
@ -158,5 +156,3 @@ function variables_list() {
} }
return $t; return $t;
} }
?>