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
/*
$Id: config.php,v 1.12 2005/12/18 09:51:32 benjamin Exp $
----------------------------------------------------------------------
@ -26,10 +27,12 @@
Original Author of file: Benjamin Sonntag
Purpose of file: General configuration file for AlternC Desktop
----------------------------------------------------------------------
*/
*/
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 :
// # touch /etc/alternc/alternc_display_php_error
@ -42,15 +45,15 @@ session_start();
/*
Si vous voulez mettre le bureau en maintenance, decommentez le code ci-dessous
et mettez votre ip dans le IF pour que seule votre ip puisse acceder au bureau :
*/
*/
/* * /
if (getenv("REMOTE_ADDR")!="127.0.0.1") {
if (getenv("REMOTE_ADDR")!="127.0.0.1") {
echo "Le bureau AlternC est en vacances jusqu'a minuit pour maintenance.<br>
Merci de revenir plus tard.";
Merci de revenir plus tard.";
exit();
}
/* */
}
/* */
if (ini_get("safe_mode")) {
echo "SAFE MODE IS ENABLED for the web panel ! It's a bug in your php or apache configuration, please fix it !!";
@ -58,7 +61,8 @@ if (ini_get("safe_mode")) {
}
// 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 (empty($_SERVER['PHP_AUTH_USER']) || empty($_SERVER['PHP_AUTH_PW'])) {
header('WWW-Authenticate: Basic realm="AlternC Authentication"');
@ -68,62 +72,62 @@ if (isset($http_auth)) {
}
if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
// Gruiiik
$_REQUEST["username"]=$_SERVER['PHP_AUTH_USER'];
$_REQUEST["password"]=$_SERVER['PHP_AUTH_PW'];
$_REQUEST["username"] = $_SERVER['PHP_AUTH_USER'];
$_REQUEST["password"] = $_SERVER['PHP_AUTH_PW'];
}
// proper srand (not using time(), which is what PHP does!)
list($usec, $sec) = explode(" ", microtime());
srand($usec*1000000);
srand($usec * 1000000);
$help_baseurl="http://www.aide-alternc.org/";
$help_baseurl = "http://www.aide-alternc.org/";
/* Server Domain Name */
$host=getenv("HTTP_HOST");
$host = getenv("HTTP_HOST");
/* Global variables (AlternC configuration) */
require_once(dirname(__FILE__)."/local.php");
require_once(dirname(__FILE__) . "/local.php");
// Define constants from vars of /etc/alternc/local.sh
// The you can't choose where is the AlternC Panel
define("DEFAULT_PASS_SIZE", 8);
define('ALTERNC_MAIL', "$L_ALTERNC_MAIL");
define('ALTERNC_HTML', "$L_ALTERNC_HTML");
if(isset($L_ALTERNC_LOGS_ARCHIVE))
if (isset($L_ALTERNC_LOGS_ARCHIVE)) {
define('ALTERNC_LOGS_ARCHIVE', "$L_ALTERNC_LOGS_ARCHIVE");
}
define('ALTERNC_LOGS', "$L_ALTERNC_LOGS");
define('ALTERNC_PANEL', "/usr/share/alternc/panel");
define('ALTERNC_LOCALES', ALTERNC_PANEL."/locales");
define('ALTERNC_LOCALES', ALTERNC_PANEL . "/locales");
define('ALTERNC_LOCK_JOBS', '/var/run/alternc/jobs-lock');
define('ALTERNC_LOCK_PANEL', '/var/lib/alternc/panel/nologin.lock');
define('ALTERNC_APACHE2_GEN_TMPL_DIR', '/etc/alternc/templates/apache2/');
define('ALTERNC_VHOST_DIR',"/var/lib/alternc/apache-vhost/");
define('ALTERNC_VHOST_FILE',ALTERNC_VHOST_DIR."vhosts_all.conf");
define('ALTERNC_VHOST_MANUALCONF',ALTERNC_VHOST_DIR."manual/");
define('ALTERNC_VHOST_DIR', "/var/lib/alternc/apache-vhost/");
define('ALTERNC_VHOST_FILE', ALTERNC_VHOST_DIR . "vhosts_all.conf");
define('ALTERNC_VHOST_MANUALCONF', ALTERNC_VHOST_DIR . "manual/");
/* PHPLIB inclusions : */
$root=ALTERNC_PANEL."/";
$root = ALTERNC_PANEL . "/";
require_once($root."/class/db_mysql.php");
require_once($root."/class/functions.php");
require_once($root."/class/variables.php");
require_once($root . "/class/db_mysql.php");
require_once($root . "/class/functions.php");
require_once($root . "/class/variables.php");
// Redirection si appel <20> 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/");
}
// Classe h<>rit<69>e de la classe db de la phplib.
// child class of the phplib parent DB class
/**
* Class for MySQL management in the bureau
*
* This class heriting from the db class of the phplib manages
* the connection to the MySQL database.
*/
* Class for MySQL management in the bureau
*
* This class heriting from the db class of the phplib manages
* the connection to the MySQL database.
*/
class DB_system extends DB_Sql {
var $Host = null;
var $Database = null;
var $User = null;
@ -133,48 +137,50 @@ class DB_system extends DB_Sql {
* Creator
*/
function DB_system() {
global $L_MYSQL_HOST,$L_MYSQL_DATABASE,$L_MYSQL_LOGIN,$L_MYSQL_PWD;
global $L_MYSQL_HOST, $L_MYSQL_DATABASE, $L_MYSQL_LOGIN, $L_MYSQL_PWD;
$this->Host = $L_MYSQL_HOST;
$this->Database = $L_MYSQL_DATABASE;
$this->User = $L_MYSQL_LOGIN;
$this->Password = $L_MYSQL_PWD;
}
}
$db= new DB_system();
$db = new DB_system();
// Current User ID = the user whose commands are made on behalf of.
$cuid=0;
$cuid = 0;
$classes=array();
$classes = array();
/* CLASSES PHP : automatic include : */
foreach ( glob( $root."class/m_*.php") as $di ) {
if (preg_match("#${root}class/m_(.*)\\.php$#",$di,$match)) { // $
$classes[]=$match[1];
foreach (glob($root . "class/m_*.php") as $di) {
if (preg_match("#${root}class/m_(.*)\\.php$#", $di, $match)) { // $
$classes[] = $match[1];
require_once($di);
}
}
/* THE DEFAULT CLASSES ARE :
dom, ftp, mail, quota, bro, admin, mem, mysql, err, variables
*/
*/
// Load file for the system class.
// Those class will not be build by default.
// They may contain forbidden action for the panel, for example: exec, system
// or files operations
// We can imagine load those class only for command-line scripts.
foreach ( glob( $root."class/class_system_*.php") as $fcs ) {
if (is_readable($fcs)) require_once($fcs);
foreach (glob($root . "class/class_system_*.php") as $fcs) {
if (is_readable($fcs))
require_once($fcs);
}
/* Language */
include_once("lang_env.php");
$mem=new m_mem();
$err=new m_err();
$authip=new m_authip();
$hooks=new m_hooks();
$mem = new m_mem();
$err = new m_err();
$authip = new m_authip();
$hooks = new m_hooks();
/* Check the User identity (if required) */
if (!defined('NOCHECK')) {
@ -184,34 +190,34 @@ if (!defined('NOCHECK')) {
header('HTTP/1.0 401 Unauthorized');
exit();
}
$error=$err->errstr();
$error = $err->errstr();
include("$root/admin/index.php");
exit();
}
}
for($i=0;$i<count($classes);$i++) {
$name2=$classes[$i];
if (isset($$name2)) continue; // for already instancied class like mem, err or authip
$name1="m_".$name2;
$$name2= new $name1();
for ($i = 0; $i < count($classes); $i++) {
$name2 = $classes[$i];
if (isset($$name2))
continue; // for already instancied class like mem, err or authip
$name1 = "m_" . $name2;
$$name2 = new $name1();
}
$oldid=intval(isset($_COOKIE['oldid'])?$_COOKIE['oldid']:'');
$isinvited=false;
if ($admin->enabled) $isinvited=true;
$oldid = intval(isset($_COOKIE['oldid']) ? $_COOKIE['oldid'] : '');
$isinvited = false;
if ($admin->enabled)
$isinvited = true;
if ($oldid && $oldid!=$cuid) {
$isinvited=true;
if ($oldid && $oldid != $cuid) {
$isinvited = true;
}
variable_get('aaa1', '','plop');
variable_get('aaa1', '', 'plop');
// Init some vars
variable_get('hosting_tld', '','This is a FQDN that designates the main hostname of the service. For example, hosting_tld determines in what TLD the "free" user domain is created. If this is set to "example.com", a checkbox will appear in the user creation dialog requesting the creator if he wants to create the domain "username.example.com".', array('desc'=>'Wanted FQDN','type'=>'string'));
variable_get('hosting_tld', '', 'This is a FQDN that designates the main hostname of the service. For example, hosting_tld determines in what TLD the "free" user domain is created. If this is set to "example.com", a checkbox will appear in the user creation dialog requesting the creator if he wants to create the domain "username.example.com".', array('desc' => 'Wanted FQDN', 'type' => 'string'));
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
/*
$Id: config_nochk.php,v 1.2 2004/11/04 06:56:49 anonymous Exp $
----------------------------------------------------------------------
@ -26,9 +27,8 @@
Original Author of file: Benjamin Sonntag
Purpose of file: General configuration file for AlternC Desktop
----------------------------------------------------------------------
*/
*/
define('NOCHECK', 1);
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 $
*
*/
class DB_Sql {
/* public: connection parameters */
var $Host = "";
var $Database = "";
var $User = "";
@ -42,8 +41,6 @@ class DB_Sql {
var $Query_ID = 0;
var $Query_String = "";
/**
* Constructor
*/
@ -79,35 +76,39 @@ class DB_Sql {
*/
function connect($Database = "", $Host = "", $User = "", $Password = "") {
/* Handle defaults */
if ("" == $Database)
if ("" == $Database) {
$Database = $this->Database;
if ("" == $Host)
}
if ("" == $Host) {
$Host = $this->Host;
if ("" == $User)
}
if ("" == $User) {
$User = $this->User;
if ("" == $Password)
}
if ("" == $Password) {
$Password = $this->Password;
}
/* establish connection, select database */
if ( 0 == $this->Link_ID ) {
if (0 == $this->Link_ID) {
$this->Link_ID=mysql_pconnect($Host, $User, $Password);
$this->Link_ID = mysql_pconnect($Host, $User, $Password);
if (!$this->Link_ID) {
$this->halt("pconnect($Host, $User, \$Password) failed.");
return 0;
}
if (!@mysql_select_db($Database,$this->Link_ID)) {
$this->halt("cannot use database ".$this->Database);
if (!@mysql_select_db($Database, $this->Link_ID)) {
$this->halt("cannot use database " . $this->Database);
return 0;
}
}
//persistent connection don't conserve database selection
//if needed do a correct database selection
$db_connected = @mysql_fetch_array(@mysql_query("SELECT DATABASE();",$this->Link_ID));
$db_connected = @mysql_fetch_array(@mysql_query("SELECT DATABASE();", $this->Link_ID));
if ($db_connected[0] != $this->Database)
mysql_select_db($Database,$this->Link_ID);
mysql_select_db($Database, $this->Link_ID);
return $this->Link_ID;
}
@ -134,16 +135,17 @@ class DB_Sql {
global $debug_alternc;
/* 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,
* when calling the class without a query, e.g. in situations
* like these: '$db = new DB_Sql_Subclass;'
*/
return 0;
}
if (!$this->connect()) {
return 0; /* we already complained in connect() about that. */
};
}
# New query, discard previous result.
if ($this->Query_ID) {
@ -151,28 +153,29 @@ class DB_Sql {
$this->Query_String = $Query_String;
}
if ($this->Debug)
if ($this->Debug) {
printf("Debug: query = %s<br />\n", $Query_String);
}
$debug_chrono_start = microtime(true);
$this->Query_ID = @mysql_query($Query_String,$this->Link_ID);
$debug_chrono_start = (microtime(true) - $debug_chrono_start)*1000;
$this->Query_ID = @mysql_query($Query_String, $this->Link_ID);
$debug_chrono_start = (microtime(true) - $debug_chrono_start) * 1000;
$this->Row = 0;
$this->Errno = mysql_errno();
$this->Error = mysql_error();
if( 0 != $this->Errno ){
if( defined("THROW_EXCEPTIONS") && THROW_EXCEPTIONS ){
if (0 != $this->Errno) {
if (defined("THROW_EXCEPTIONS") && THROW_EXCEPTIONS) {
throw new \Exception("Mysql query failed : $this->Error");
}
$this->halt("SQL Error: ".$Query_String);
$this->halt("SQL Error: " . $Query_String);
return FALSE;
}
if (!$this->Query_ID) {
$this->halt("Invalid SQL: ".$Query_String);
$this->halt("Invalid SQL: " . $Query_String);
}
if (isset($debug_alternc)) {
$debug_alternc->add("SQL Query : (".substr($debug_chrono_start,0,5)." ms)\t $Query_String");
$debug_alternc->add("SQL Query : (" . substr($debug_chrono_start, 0, 5) . " ms)\t $Query_String");
$debug_alternc->nb_sql_query++;
$debug_alternc->tps_sql_query += $debug_chrono_start;
}
@ -211,13 +214,12 @@ class DB_Sql {
*
* public: position in result set
*/
function seek($pos = 0) {
$status = @mysql_data_seek($this->Query_ID, $pos);
if ($status)
if ($status) {
$this->Row = $pos;
else {
$this->halt("seek($pos) failed: result has ".$this->num_rows()." rows");
} else {
$this->halt("seek($pos) failed: result has " . $this->num_rows() . " rows");
/* half assed attempt to save the day,
* but do not consider this documented or even
@ -231,20 +233,20 @@ class DB_Sql {
return 1;
}
/* public: table locking */
function lock($table, $mode="write") {
/** public: table locking */
function lock($table, $mode = "write") {
$this->connect();
$query="lock tables ";
$query = "lock tables ";
if (is_array($table)) {
while (list($key,$value)=each($table)) {
if ($key=="read" && $key!=0) {
while (list($key, $value) = each($table)) {
if ($key == "read" && $key != 0) {
$query.="$value read, ";
} else {
$query.="$value $mode, ";
}
}
$query=substr($query,0,-2);
$query = substr($query, 0, -2);
} else {
$query.="$table $mode";
}
@ -267,8 +269,7 @@ class DB_Sql {
return $res;
}
/* public: evaluate the result (size, width) */
/** public: evaluate the result (size, width) */
function affected_rows() {
return @mysql_affected_rows($this->Link_ID);
}
@ -281,7 +282,7 @@ class DB_Sql {
return @mysql_num_fields($this->Query_ID);
}
/* public: shorthand notation */
/** public: shorthand notation */
function nf() {
return $this->num_rows();
}
@ -309,45 +310,37 @@ class DB_Sql {
return @mysql_insert_id($this->Link_ID);
}
/* public: sequence numbers */
/** public: sequence numbers */
function nextid($seq_name) {
$this->connect();
if ($this->lock($this->Seq_Table)) {
/* get sequence number (locked) and increment */
$q = sprintf("select nextid from %s where seq_name = '%s'",
$this->Seq_Table,
$seq_name);
$q = sprintf("select nextid from %s where seq_name = '%s'", $this->Seq_Table, $seq_name);
$id = @mysql_query($q, $this->Link_ID);
$res = @mysql_fetch_array($id);
/* No current value, make one */
if (!is_array($res)) {
$currentid = 0;
$q = sprintf("insert into %s values('%s', %s)",
$this->Seq_Table,
$seq_name,
$currentid);
$q = sprintf("insert into %s values('%s', %s)", $this->Seq_Table, $seq_name, $currentid);
@mysql_query($q, $this->Link_ID);
} else {
$currentid = $res["nextid"];
}
$nextid = $currentid + 1;
$q = sprintf("update %s set nextid = '%s' where seq_name = '%s'",
$this->Seq_Table,
$nextid,
$seq_name);
$q = sprintf("update %s set nextid = '%s' where seq_name = '%s'", $this->Seq_Table, $nextid, $seq_name);
@mysql_query($q, $this->Link_ID);
$this->unlock();
} else {
$this->halt("cannot lock ".$this->Seq_Table." - has it been created?");
$this->halt("cannot lock " . $this->Seq_Table . " - has it been created?");
return 0;
}
return $nextid;
}
/* public: return table metadata */
function metadata($table='',$full=false) {
/** public: return table metadata */
function metadata($table = '', $full = false) {
$res = array();
/*
@ -393,72 +386,34 @@ class DB_Sql {
// 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);
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;
$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);
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);
if ($table) {
@mysql_free_result($id);
}
return $res;
}
/********************************************************************************************************/
// 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 */
/** private: error handling */
function halt($msg) {
$this->Error = @mysql_error($this->Link_ID);
$this->Errno = @mysql_errno($this->Link_ID);
@ -467,29 +422,27 @@ class DB_Sql {
$this->haltmsg($msg);
if ($this->Halt_On_Error != "report")
if ($this->Halt_On_Error != "report") {
die("Session halted.");
}
}
function haltmsg($msg) {
printf("</td></tr></table><b>Database error:</b> %s<br />\n", $msg);
printf("<b>MySQL Error</b>: %s (%s)<br />\n",
$this->Errno,
$this->Error);
printf("<b>MySQL Error</b>: %s (%s)<br />\n", $this->Errno, $this->Error);
}
function table_names() {
$this->query("SHOW TABLES");
$i=0;
$return=array();
while ($info=mysql_fetch_row($this->Query_ID))
{
$return[$i]["table_name"]= $info[0];
$return[$i]["tablespace_name"]=$this->Database;
$return[$i]["database"]=$this->Database;
$i = 0;
$return = array();
while ($info = mysql_fetch_row($this->Query_ID)) {
$return[$i]["table_name"] = $info[0];
$return[$i]["tablespace_name"] = $this->Database;
$return[$i]["database"] = $this->Database;
$i++;
}
return $return;
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
<?php
$lang_translation=array( # If you comment lang here, it won't be displayed.
$lang_translation = array(# If you comment lang here, it won't be displayed.
"fr_FR" => "Français",
"en_US" => "English",
# "es_ES" => "Español",
@ -8,34 +8,38 @@ $lang_translation=array( # If you comment lang here, it won't be displayed.
# "de_DE" => "Deutsch",
# "pt_BR" => "Portuguese",
"nl_NL" => "Dutch",
);
);
global $arr_lang_translation ;
global $arr_lang_translation;
$arr_lang_translation = $lang_translation; // not pretty but I don't want side effect right now
function update_locale($langpath) {
global $arr_lang_translation;
$locales=array();
$file=file("/etc/locale.gen", FILE_SKIP_EMPTY_LINES);
if (! is_array($file) ) return $locales;
foreach ($file as $v ) {
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;
$locales[$mat[1]]=$mat[1];
$locales = array();
$file = file("/etc/locale.gen", FILE_SKIP_EMPTY_LINES);
if (!is_array($file)) {
return $locales;
}
foreach ($file as $v) {
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;
}
$locales[$mat[1]] = $mat[1];
}
}
if (!count($locales)) {
$locales=array("en_US"=>"en_US");
$locales = array("en_US" => "en_US");
}
return $locales;
}
// setlang is on the link at the login page
if (isset($_REQUEST["setlang"])) {
$lang=$_REQUEST["setlang"];
$setlang=$_REQUEST["setlang"];
$lang = $_REQUEST["setlang"];
$setlang = $_REQUEST["setlang"];
} elseif (isset($_COOKIE['lang'])) {
$lang=$_COOKIE['lang'];
$lang = $_COOKIE['lang'];
}
$langpath = bindtextdomain("alternc", ALTERNC_LOCALES);
@ -45,29 +49,30 @@ $locales = update_locale($langpath);
// Default to en_US :
if (!isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
$_SERVER["HTTP_ACCEPT_LANGUAGE"]="en_US";
$_SERVER["HTTP_ACCEPT_LANGUAGE"] = "en_US";
}
if (!(isset($lang))) { // Use the browser first preferred language
$lang=strtolower(substr(trim($_SERVER["HTTP_ACCEPT_LANGUAGE"]),0,5));
$lang = strtolower(substr(trim($_SERVER["HTTP_ACCEPT_LANGUAGE"]), 0, 5));
}
if (! isset($locales[$lang])) { // Requested language not found in locales
if (!isset($locales[$lang])) { // Requested language not found in locales
// treat special cases such as en_AU or fr_BF : use the language only, not the country.
$ll=substr($lang,0,2);
foreach($locales as $l) {
if (substr($l,0,2)==$ll) {
$lang=$l;
$ll = substr($lang, 0, 2);
foreach ($locales as $l) {
if (substr($l, 0, 2) == $ll) {
$lang = $l;
break;
}
}
}
if (!isset($locales[$lang])) list($lang)=each($locales);
if (!isset($locales[$lang])) {
list($lang) = each($locales);
}
if (isset($setlang) && isset($lang)) {
setcookie("lang",$lang);
setcookie("lang", $lang);
}
// User chose a non existent language, select the first available one
@ -76,18 +81,18 @@ if ($lang == NULL) {
}
/* Language ok, set the locale environment */
putenv("LC_MESSAGES=".$lang);
putenv("LANG=".$lang);
putenv("LANGUAGE=".$lang);
putenv("LC_MESSAGES=" . $lang);
putenv("LANG=" . $lang);
putenv("LANGUAGE=" . $lang);
// this locale MUST be selected in "dpkg-reconfigure locales"
setlocale(LC_ALL,$lang);
setlocale(LC_ALL, $lang);
textdomain("alternc");
$empty="";
if (_($empty) && preg_match("#charset=([A-Za-z0-9\.-]*)#",_($empty),$mat)) {
$charset=$mat[1];
}
if (! isset($charset) || !$charset) $charset="UTF-8";
bind_textdomain_codeset("alternc","$charset");
?>
$empty = "";
if (_($empty) && preg_match("#charset=([A-Za-z0-9\.-]*)#", _($empty), $mat)) {
$charset = $mat[1];
}
if (!isset($charset) || !$charset) {
$charset = "UTF-8";
}
bind_textdomain_codeset("alternc", "$charset");

View File

@ -1,11 +1,11 @@
<?php
/* Read global variables (AlternC configuration) */
$L_VERSION="@@REPLACED_DURING_BUILD@@";
$L_VERSION = "@@REPLACED_DURING_BUILD@@";
// To be able to have displayer version != help version
// (usefull during RC, etc...)
$L_VERSION_HELP="3.0";
$L_VERSION_HELP = "3.0";
/* To ease the transition, we define a lookup table for old names */
$compat = array('DEFAULT_MX' => 'MX',
@ -18,9 +18,9 @@ $compat = array('DEFAULT_MX' => 'MX',
$config_file = fopen('/etc/alternc/local.sh', 'r');
while (FALSE !== ($line = fgets($config_file))) {
if (preg_match('/^([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $regs)) {
$GLOBALS['L_'.$regs[1]] = $regs[2];
$GLOBALS['L_' . $regs[1]] = $regs[2];
if (isset($compat[$regs[1]])) {
$GLOBALS['L_'.$compat[$regs[1]]] = $regs[2];
$GLOBALS['L_' . $compat[$regs[1]]] = $regs[2];
}
}
}
@ -28,7 +28,7 @@ while (FALSE !== ($line = fgets($config_file))) {
fclose($config_file);
$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)) {
switch ($regs[1]) {
case "user":
@ -48,4 +48,3 @@ while (FALSE !== ($line = fgets($config_file))) {
}
fclose($config_file);
?>

View File

@ -50,7 +50,7 @@ class m_action {
function do_action() {
global $err, $L_INOTIFY_DO_ACTION;
$err->log("action", "do_action");
if( ! @touch($L_INOTIFY_DO_ACTION) ){
if (!@touch($L_INOTIFY_DO_ACTION)) {
return FALSE;
}
return TRUE;
@ -77,7 +77,7 @@ class m_action {
* @return boolean
*/
function chmod($filename, $perms, $user = "root") {
return $this->set('chmod', $user, array('filename' => $filename,"perms"=>$perms));
return $this->set('chmod', $user, array('filename' => $filename, "perms" => $perms));
}
/**
@ -243,11 +243,11 @@ class m_action {
$purge = "select * from actions where TO_DAYS(curdate()) - TO_DAYS(creation) > 2;";
$result = $db->query($purge);
if (! $result) {
if (!$result) {
$err->raise("action", _("Error selecting old actions"));
return false;
}
return $db->num_rows($result) ;
return $db->num_rows($result);
}
/**
@ -265,12 +265,11 @@ class m_action {
$purge = "delete from actions where TO_DAYS(curdate()) - TO_DAYS(creation) > 2;";
}
$result = $db->query($purge);
if (! $result) {
if (!$result) {
$err->raise("action", _("Error purging old actions"));
return false;
}
return $db->num_rows($result) ;
return $db->num_rows($result);
}
/**
@ -352,7 +351,7 @@ class m_action {
* @return boolean
*/
function get_job() {
global $db, $err;
global $db;
$tab = array();
$db->query("Select * from actions where begin !=0 and end = 0 ;");
if ($db->next_record()) {
@ -371,7 +370,6 @@ class m_action {
* @return boolean
*/
function cancel($id) {
global $db;
$this->finish($id, 666);
return true;
}

View File

@ -79,9 +79,9 @@ class m_admin {
*/
function hook_menu() {
global $mem, $cuid, $debug_alternc, $L_INOTIFY_UPDATE_DOMAIN;
if (!$mem->checkRight())
if (!$mem->checkRight()) {
return false;
}
$obj = array(
'title' => _("Administration"),
'ico' => 'images/admin.png',
@ -343,38 +343,36 @@ class m_admin {
$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);
if ($creator)
}
if ($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 .= ' GROUP BY uid';
} elseif ($pattern_type === 'login') {
$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);
if ($creator)
}
if ($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 .= ' ORDER BY login;';
} else {
$err->raise("admin", _("Invalid pattern type provided. Are you even performing a legitimate action?"));
return FALSE;
}
} else {
if ($creator) {
// Limit listing to a specific reseller
$request = "SELECT uid FROM membres WHERE creator='" . $creator . "' ORDER BY login;";
@ -411,7 +409,7 @@ class m_admin {
* @return boolean
*/
function mailallmembers($subject, $message, $from) {
global $err, $mem, $cuid, $db;
global $err, $db;
$err->log("admin", "mailallmembers");
if (!$this->enabled) {
$err->raise("admin", _("-- Only administrators can access this page! --"));
@ -453,7 +451,7 @@ class m_admin {
* @return boolean
*/
function get_creator_list() {
global $err, $mem, $cuid;
global $err, $cuid;
$creators = array();
@ -488,7 +486,7 @@ class m_admin {
* @return boolean TRUE if I am the creator of that account. FALSE else.
*/
function checkcreator($uid) {
global $err, $mem, $db, $cuid;
global $err, $db, $cuid;
if ($cuid == 2000) {
return true;
}
@ -514,7 +512,7 @@ class m_admin {
* @return boolean
*/
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);
if (!$mem->checkright()) {
@ -575,7 +573,7 @@ class m_admin {
* @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) {
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);
if (!$this->enabled) {
$err->raise("admin", _("-- Only administrators can access this page! --"));
@ -629,9 +627,10 @@ class m_admin {
$uid = 2000;
} else {
$uid = $db->Record["nextid"];
if ($uid <= 2000)
if ($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 local(uid,nom,prenom) VALUES('$uid','$nom','$prenom');");
$this->renew_update($uid, $duration);
@ -749,8 +748,7 @@ EOF;
* @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) {
global $err, $db;
global $cuid, $quota;
global $err, $db, $quota;
$notes = addslashes($notes);
@ -853,7 +851,7 @@ EOF;
* @return boolean Returns FALSE if an error occurs, TRUE if not.
*/
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);
if (!$this->enabled) {
@ -904,9 +902,9 @@ EOF;
global $err, $db;
$periods = intval($periods);
if ($periods == 0)
if ($periods == 0) {
return false;
}
$query = "UPDATE membres SET renewed = renewed + INTERVAL (duration * $periods) MONTH WHERE uid=${uid};";
if ($db->query($query)) {
return true;
@ -929,13 +927,15 @@ EOF;
global $err, $db;
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;
}
} else {
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;
}
}
$err->raise("admin", _("Account not found"));
return false;
@ -992,12 +992,13 @@ EOF;
" WHEN m.renewed <= NOW() THEN 2" .
" ELSE 1 END 'status' FROM membres m, local l" .
" 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;
else {
} else {
$res = array();
while ($db->next_record())
while ($db->next_record()) {
$res[] = $db->Record;
}
return $res;
}
}
@ -1025,7 +1026,6 @@ EOF;
return true;
}
/**
* Turns a super-admin account into a common account
*
@ -1238,8 +1238,9 @@ EOF;
function selecttldmode($current = false) {
for ($i = 0; $i < count($this->tldmode); $i++) {
echo "<option value=\"$i\"";
if ($current == $i)
if ($current == $i) {
echo " selected=\"selected\"";
}
echo ">" . _($this->tldmode[$i]) . "</option>\n";
}
}
@ -1294,11 +1295,13 @@ EOF;
$err->raise("admin", _("This TLD already exist"));
return false;
}
if (substr($tld, 0, 1) == ".")
if (substr($tld, 0, 1) == ".") {
$tld = substr($tld, 1);
}
$mode = intval($mode);
if ($mode == 0)
if ($mode == 0) {
$mode = "0";
}
$db->query("INSERT INTO tld (tld,mode) VALUES ('$tld','$mode');");
return true;
}
@ -1322,8 +1325,9 @@ EOF;
return false;
}
$mode = intval($mode);
if ($mode == 0)
if ($mode == 0) {
$mode = "0";
}
$db->query("UPDATE tld SET mode='$mode' WHERE tld='$tld';");
return true;
}
@ -1350,7 +1354,7 @@ EOF;
* @return array an indexed array of associative array from the MySQL "policy" table
*/
function listPasswordPolicies() {
global $db, $classes, $hooks;
global $db, $hooks;
$tmp1 = array();
$tmp2 = array();
$policies = array();
@ -1358,16 +1362,6 @@ EOF;
while ($db->next_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");
foreach ($tmp3 as $v) {
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.
*/
function checkPolicy($policy, $login, $password) {
global $db, $err;
global $err;
if (empty($login)) {
$err->raise("admin", _("Please enter a login"));
@ -1468,8 +1462,10 @@ EOF;
$logins = preg_split("/[@_-]/", $login);
$logins[] = $login;
foreach ($logins as $l) {
if (!$l) continue;
if (strpos($password, $l) !== false || strpos($l,$password) !== false) {
if (!$l) {
continue;
}
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"));
return false;
}

View File

@ -1,4 +1,5 @@
<?php
/*
$Id: mime.php,v 1.3 2004/06/03 14:32:20 anonymous Exp $
----------------------------------------------------------------------
@ -26,7 +27,7 @@
Original Author of file: Benjamin Sonntag 23/12/2001
Purpose of file: Brouteur php3 pour AlternC
----------------------------------------------------------------------
*/
*/
/*
Brouteur php3 pour AlternC (voir http://www.alternc.org)
@ -38,12 +39,11 @@
Fichier :
mime.php3 : gestion de la liste des types mime des fichiers.
*/
*/
if (!IsSet($MIME_H)) {
$MIME_H=1;
$MIME_H = 1;
$bro_mime=
array(
$bro_mime = array(
"css" => "text/css",
"csv" => "text/comma-separated-values",
"dia" => "application/x-dia",
@ -53,7 +53,7 @@ $MIME_H=1;
"gif" => "image/gif",
"hqx" => "application/mac-binhex40",
"htm" => "text/html",
"html"=> "text/html",
"html" => "text/html",
"jpeg" => "image/jpeg",
"jpg" => "image/jpeg",
"m3u" => "audio/mpegurl",
@ -86,8 +86,7 @@ $MIME_H=1;
"zip" => "application/zip",
);
$bro_icon=
array(
$bro_icon = array(
"css" => "txt",
"csv" => "xls",
"dia" => "jpg",
@ -97,7 +96,7 @@ $MIME_H=1;
"gif" => "jpg",
"hqx" => "exe",
"htm" => "htm",
"html"=> "htm",
"html" => "htm",
"jpeg" => "jpg",
"jpg" => "jpg",
"m3u" => "m3u",
@ -130,8 +129,7 @@ $MIME_H=1;
"zip" => "zip",
);
$bro_type=
array(
$bro_type = array(
"css" => _("CSS Stylesheet"),
"csv" => _("Comma Separated Values data"),
"dia" => _("DIA Diagram"),
@ -141,7 +139,7 @@ $MIME_H=1;
"gif" => _("GIF Image"),
"hqx" => _("Macintosh Executable"),
"htm" => _("HTML Document"),
"html"=> _("HTML Document"),
"html" => _("HTML Document"),
"jpeg" => _("JPEG Image"),
"jpg" => _("JPEG Image"),
"m3u" => _("Music Playlist"),
@ -173,6 +171,4 @@ $MIME_H=1;
"rm" => _("Real Media File"),
"ram" => _("Real Media File"),
);
}
?>

View File

@ -8,13 +8,12 @@ if (!$admin->enabled) {
}
$db->query("SELECT id,hostname FROM stats;");
$d=array();
$d = array();
while ($db->next_record()) {
$d[]=$db->Record;
$d[] = $db->Record;
}
foreach ($d as $r) {
echo "Stats de ".$r[0]." ".$r[1]." <br>\n"; flush();
$stats->_createconf($r[0],1);
echo "Stats de " . $r[0] . " " . $r[1] . " <br>\n";
flush();
$stats->_createconf($r[0], 1);
}
?>

View File

@ -108,30 +108,30 @@ function variable_get($name, $default = null, $createit_comment = null) {
* The value to set. This can be any PHP data type; these functions take care
* of serialization as necessary.
*/
function variable_set($name, $value, $comment=null) {
function variable_set($name, $value, $comment = null) {
global $conf, $db, $err, $hooks;
$err->log('variable', 'variable_set', '+'.serialize($value).'+'.$comment.'+');
$err->log('variable', 'variable_set', '+' . serialize($value) . '+' . $comment . '+');
variable_init_maybe();
if (is_object($value) || is_array($value)) {
$value2 = serialize($value);
}
if (array_key_exists($name,$conf)) {
$previous=$conf[$name];
if (array_key_exists($name, $conf)) {
$previous = $conf[$name];
} else {
$previous=null;
$previous = null;
}
if (!array_key_exists($name,$conf) || $value!=$conf[$name]) {
if (!array_key_exists($name, $conf) || $value != $conf[$name]) {
$conf[$name] = $value;
if ( empty($comment) ) {
$query = "INSERT INTO variable (name, value) values ('".$name."', '".addslashes($value2)."') on duplicate key update name='$name', value='$value';";
if (empty($comment)) {
$query = "INSERT INTO variable (name, value) values ('" . $name . "', '" . addslashes($value2) . "') on duplicate key update name='$name', value='$value';";
} else {
$comment=mysql_real_escape_string($comment);
$query = "INSERT INTO variable (name, value, comment) values ('".$name."', '".addslashes($value2)."', '$comment') on duplicate key update name='$name', value='$value', comment='$comment';";
$comment = mysql_real_escape_string($comment);
$query = "INSERT INTO variable (name, value, comment) values ('" . $name . "', '" . addslashes($value2) . "', '$comment') on duplicate key update name='$name', value='$value', comment='$comment';";
}
$db->query($query);
$hooks->invoke("hook_variable_set", array("name" => $name, "old"=> $previous, "new"=>$value ) );
$hooks->invoke("hook_variable_set", array("name" => $name, "old" => $previous, "new" => $value));
}
}
@ -143,20 +143,16 @@ function variable_set($name, $value, $comment=null) {
*/
function variable_del($name) {
global $conf, $db;
$db->query("DELETE FROM `variable` WHERE name = '".$name."'");
$db->query("DELETE FROM `variable` WHERE name = '" . $name . "'");
unset($conf[$name]);
}
function variables_list() {
global $db;
$t=array();
$t = array();
$db->query("SELECT * FROM `variable` WHERE `comment` IS NOT NULL ORDER BY `name`");
while ($db->next_record()) {
$t[]=$db->Record;
$t[] = $db->Record;
}
return $t;
}
?>