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:
parent
d4be9fddbf
commit
3e42567048
|
@ -1,217 +1,223 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
$Id: config.php,v 1.12 2005/12/18 09:51:32 benjamin Exp $
|
||||
----------------------------------------------------------------------
|
||||
AlternC - Web Hosting System
|
||||
Copyright (C) 2002 by the AlternC Development Team.
|
||||
http://alternc.org/
|
||||
----------------------------------------------------------------------
|
||||
Based on:
|
||||
Valentin Lacambre's web hosting softwares: http://altern.org/
|
||||
----------------------------------------------------------------------
|
||||
LICENSE
|
||||
$Id: config.php,v 1.12 2005/12/18 09:51:32 benjamin Exp $
|
||||
----------------------------------------------------------------------
|
||||
AlternC - Web Hosting System
|
||||
Copyright (C) 2002 by the AlternC Development Team.
|
||||
http://alternc.org/
|
||||
----------------------------------------------------------------------
|
||||
Based on:
|
||||
Valentin Lacambre's web hosting softwares: http://altern.org/
|
||||
----------------------------------------------------------------------
|
||||
LICENSE
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License (GPL)
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License (GPL)
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
||||
----------------------------------------------------------------------
|
||||
Original Author of file: Benjamin Sonntag
|
||||
Purpose of file: General configuration file for AlternC Desktop
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
||||
----------------------------------------------------------------------
|
||||
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
|
||||
if (file_exists('/etc/alternc/alternc_display_php_error')) {
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_errors', '1');
|
||||
}
|
||||
session_name('AlternC_Panel');
|
||||
session_name('AlternC_Panel');
|
||||
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 :
|
||||
*/
|
||||
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 !!";
|
||||
exit();
|
||||
echo "SAFE MODE IS ENABLED for the web panel ! It's a bug in your php or apache configuration, please fix it !!";
|
||||
exit();
|
||||
}
|
||||
|
||||
// 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"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
exit();
|
||||
}
|
||||
if (empty($_SERVER['PHP_AUTH_USER']) || empty($_SERVER['PHP_AUTH_PW'])) {
|
||||
header('WWW-Authenticate: Basic realm="AlternC Authentication"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
|
||||
// Gruiiik
|
||||
$_REQUEST["username"]=$_SERVER['PHP_AUTH_USER'];
|
||||
$_REQUEST["password"]=$_SERVER['PHP_AUTH_PW'];
|
||||
// Gruiiik
|
||||
$_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))
|
||||
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_MAIL', "$L_ALTERNC_MAIL");
|
||||
define('ALTERNC_HTML', "$L_ALTERNC_HTML");
|
||||
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_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) {
|
||||
header("Location: https://$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;
|
||||
var $Password = null;
|
||||
|
||||
/**
|
||||
* Creator
|
||||
*/
|
||||
function DB_system() {
|
||||
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;
|
||||
}
|
||||
var $Host = null;
|
||||
var $Database = null;
|
||||
var $User = null;
|
||||
var $Password = null;
|
||||
|
||||
/**
|
||||
* Creator
|
||||
*/
|
||||
function DB_system() {
|
||||
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];
|
||||
require_once($di);
|
||||
}
|
||||
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
|
||||
*/
|
||||
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')) {
|
||||
if (!$mem->checkid()) {
|
||||
if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
|
||||
header('WWW-Authenticate: Basic realm="AlternC Authentication"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
exit();
|
||||
if (!$mem->checkid()) {
|
||||
if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
|
||||
header('WWW-Authenticate: Basic realm="AlternC Authentication"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
exit();
|
||||
}
|
||||
$error = $err->errstr();
|
||||
include("$root/admin/index.php");
|
||||
exit();
|
||||
}
|
||||
$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();
|
||||
}
|
||||
|
||||
$oldid=intval(isset($_COOKIE['oldid'])?$_COOKIE['oldid']:'');
|
||||
$isinvited=false;
|
||||
if ($admin->enabled) $isinvited=true;
|
||||
|
||||
if ($oldid && $oldid!=$cuid) {
|
||||
$isinvited=true;
|
||||
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();
|
||||
}
|
||||
|
||||
variable_get('aaa1', '','plop');
|
||||
$oldid = intval(isset($_COOKIE['oldid']) ? $_COOKIE['oldid'] : '');
|
||||
$isinvited = false;
|
||||
if ($admin->enabled)
|
||||
$isinvited = true;
|
||||
|
||||
if ($oldid && $oldid != $cuid) {
|
||||
$isinvited = true;
|
||||
}
|
||||
|
||||
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'));
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
$Id: config_nochk.php,v 1.2 2004/11/04 06:56:49 anonymous Exp $
|
||||
----------------------------------------------------------------------
|
||||
AlternC - Web Hosting System
|
||||
Copyright (C) 2002 by the AlternC Development Team.
|
||||
http://alternc.org/
|
||||
----------------------------------------------------------------------
|
||||
Based on:
|
||||
Valentin Lacambre's web hosting softwares: http://altern.org/
|
||||
----------------------------------------------------------------------
|
||||
LICENSE
|
||||
$Id: config_nochk.php,v 1.2 2004/11/04 06:56:49 anonymous Exp $
|
||||
----------------------------------------------------------------------
|
||||
AlternC - Web Hosting System
|
||||
Copyright (C) 2002 by the AlternC Development Team.
|
||||
http://alternc.org/
|
||||
----------------------------------------------------------------------
|
||||
Based on:
|
||||
Valentin Lacambre's web hosting softwares: http://altern.org/
|
||||
----------------------------------------------------------------------
|
||||
LICENSE
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License (GPL)
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License (GPL)
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
||||
----------------------------------------------------------------------
|
||||
Original Author of file: Benjamin Sonntag
|
||||
Purpose of file: General configuration file for AlternC Desktop
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
||||
----------------------------------------------------------------------
|
||||
Original Author of file: Benjamin Sonntag
|
||||
Purpose of file: General configuration file for AlternC Desktop
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
define('NOCHECK', 1);
|
||||
require_once("config.php");
|
||||
|
||||
?>
|
||||
|
|
|
@ -8,488 +8,441 @@
|
|||
*
|
||||
* $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 = "";
|
||||
var $Password = "";
|
||||
/* public: connection parameters */
|
||||
|
||||
/* public: configuration parameters */
|
||||
var $Auto_Free = 0; ## Set to 1 for automatic mysql_free_result()
|
||||
var $Debug = 0; ## Set to 1 for debugging messages.
|
||||
var $Halt_On_Error = "no"; ## "yes" (halt with message), "no" (ignore errors quietly), "report" (ignore errror, but spit a warning)
|
||||
var $Seq_Table = "db_sequence";
|
||||
var $Host = "";
|
||||
var $Database = "";
|
||||
var $User = "";
|
||||
var $Password = "";
|
||||
|
||||
/* public: result array and current row number */
|
||||
var $Record = array();
|
||||
var $Row;
|
||||
var $num_rows;
|
||||
/* public: configuration parameters */
|
||||
var $Auto_Free = 0; ## Set to 1 for automatic mysql_free_result()
|
||||
var $Debug = 0; ## Set to 1 for debugging messages.
|
||||
var $Halt_On_Error = "no"; ## "yes" (halt with message), "no" (ignore errors quietly), "report" (ignore errror, but spit a warning)
|
||||
var $Seq_Table = "db_sequence";
|
||||
|
||||
/* public: current error number and error text */
|
||||
var $Errno = 0;
|
||||
var $Error = "";
|
||||
/* public: result array and current row number */
|
||||
var $Record = array();
|
||||
var $Row;
|
||||
var $num_rows;
|
||||
|
||||
/* public: this is an api revision, not a CVS revision. */
|
||||
var $type = "mysql";
|
||||
var $revision = "1.2";
|
||||
/* public: current error number and error text */
|
||||
var $Errno = 0;
|
||||
var $Error = "";
|
||||
|
||||
/* private: link and query handles */
|
||||
var $Link_ID = 0;
|
||||
var $Query_ID = 0;
|
||||
var $Query_String = "";
|
||||
|
||||
/* public: this is an api revision, not a CVS revision. */
|
||||
var $type = "mysql";
|
||||
var $revision = "1.2";
|
||||
|
||||
/* private: link and query handles */
|
||||
var $Link_ID = 0;
|
||||
var $Query_ID = 0;
|
||||
var $Query_String = "";
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function DB_Sql($query = "") {
|
||||
$this->query($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return resource class variable Link_ID
|
||||
*/
|
||||
function link_id() {
|
||||
return $this->Link_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer class variable Query_ID
|
||||
*/
|
||||
function query_id() {
|
||||
return $this->Query_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* function for MySQL database connection management
|
||||
*
|
||||
* This function manages the connection to the MySQL database.
|
||||
*
|
||||
* @param $Database name of the database
|
||||
* @param $Host DNS of the MySQL hosting server
|
||||
* @param $User the user's name
|
||||
* @param $Password the user's password
|
||||
*
|
||||
* @return the class variable $Link_ID
|
||||
*/
|
||||
function connect($Database = "", $Host = "", $User = "", $Password = "") {
|
||||
/* Handle defaults */
|
||||
if ("" == $Database)
|
||||
$Database = $this->Database;
|
||||
if ("" == $Host)
|
||||
$Host = $this->Host;
|
||||
if ("" == $User)
|
||||
$User = $this->User;
|
||||
if ("" == $Password)
|
||||
$Password = $this->Password;
|
||||
|
||||
/* establish connection, select database */
|
||||
if ( 0 == $this->Link_ID ) {
|
||||
|
||||
$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);
|
||||
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));
|
||||
if ($db_connected[0] != $this->Database)
|
||||
mysql_select_db($Database,$this->Link_ID);
|
||||
|
||||
return $this->Link_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Discard the query result
|
||||
*
|
||||
* This function discards the last query result.
|
||||
*/
|
||||
function free() {
|
||||
@mysql_free_result($this->Query_ID);
|
||||
$this->Query_ID = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a query
|
||||
*
|
||||
* This function performs the MySQL query described in the string parameter
|
||||
*
|
||||
* @param a string describing the MySQL query
|
||||
* @return the $Query_ID class variable (null if fails)
|
||||
*/
|
||||
function query($Query_String) {
|
||||
global $debug_alternc;
|
||||
|
||||
/* No empty queries, please, since PHP4 chokes on them. */
|
||||
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) {
|
||||
$this->free();
|
||||
$this->Query_String = $Query_String;
|
||||
}
|
||||
|
||||
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->Row = 0;
|
||||
$this->Errno = mysql_errno();
|
||||
$this->Error = mysql_error();
|
||||
if( 0 != $this->Errno ){
|
||||
if( defined("THROW_EXCEPTIONS") && THROW_EXCEPTIONS ){
|
||||
throw new \Exception("Mysql query failed : $this->Error");
|
||||
}
|
||||
$this->halt("SQL Error: ".$Query_String);
|
||||
return FALSE;
|
||||
}
|
||||
if (!$this->Query_ID) {
|
||||
$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->nb_sql_query++;
|
||||
$debug_alternc->tps_sql_query += $debug_chrono_start;
|
||||
}
|
||||
|
||||
# Will return nada if it fails. That's fine.
|
||||
return $this->Query_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* walk result set
|
||||
*
|
||||
* This function tests if a new record is available in the current
|
||||
* query result.
|
||||
*
|
||||
* @return TRUE if a new record is available
|
||||
*/
|
||||
function next_record() {
|
||||
if (!$this->Query_ID) {
|
||||
$this->halt("next_record called with no query pending.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->Record = @mysql_fetch_array($this->Query_ID);
|
||||
$this->Row += 1;
|
||||
$this->Errno = mysql_errno();
|
||||
$this->Error = mysql_error();
|
||||
|
||||
$stat = is_array($this->Record);
|
||||
if (!$stat && $this->Auto_Free) {
|
||||
$this->free();
|
||||
}
|
||||
return $stat;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* public: position in result set
|
||||
*/
|
||||
|
||||
function seek($pos = 0) {
|
||||
$status = @mysql_data_seek($this->Query_ID, $pos);
|
||||
if ($status)
|
||||
$this->Row = $pos;
|
||||
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
|
||||
* desireable behaviour.
|
||||
*/
|
||||
@mysql_data_seek($this->Query_ID, $this->num_rows());
|
||||
$this->Row = $this->num_rows;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* public: table locking */
|
||||
function lock($table, $mode="write") {
|
||||
$this->connect();
|
||||
|
||||
$query="lock tables ";
|
||||
if (is_array($table)) {
|
||||
while (list($key,$value)=each($table)) {
|
||||
if ($key=="read" && $key!=0) {
|
||||
$query.="$value read, ";
|
||||
} else {
|
||||
$query.="$value $mode, ";
|
||||
}
|
||||
}
|
||||
$query=substr($query,0,-2);
|
||||
} else {
|
||||
$query.="$table $mode";
|
||||
}
|
||||
$res = @mysql_query($query, $this->Link_ID);
|
||||
if (!$res) {
|
||||
$this->halt("lock($table, $mode) failed.");
|
||||
return 0;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
function unlock() {
|
||||
$this->connect();
|
||||
|
||||
$res = @mysql_query("unlock tables", $this->Link_ID);
|
||||
if (!$res) {
|
||||
$this->halt("unlock() failed.");
|
||||
return 0;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/* public: evaluate the result (size, width) */
|
||||
function affected_rows() {
|
||||
return @mysql_affected_rows($this->Link_ID);
|
||||
}
|
||||
|
||||
function num_rows() {
|
||||
return @mysql_num_rows($this->Query_ID);
|
||||
}
|
||||
|
||||
function num_fields() {
|
||||
return @mysql_num_fields($this->Query_ID);
|
||||
}
|
||||
|
||||
/* public: shorthand notation */
|
||||
function nf() {
|
||||
return $this->num_rows();
|
||||
}
|
||||
|
||||
function np() {
|
||||
print $this->num_rows();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $Name
|
||||
* @return integer
|
||||
*/
|
||||
function f($Name) {
|
||||
if (isset($this->Record[$Name]))
|
||||
return $this->Record[$Name];
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function p($Name) {
|
||||
print $this->Record[$Name];
|
||||
}
|
||||
|
||||
function lastid() {
|
||||
return @mysql_insert_id($this->Link_ID);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
$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);
|
||||
@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);
|
||||
@mysql_query($q, $this->Link_ID);
|
||||
$this->unlock();
|
||||
} else {
|
||||
$this->halt("cannot lock ".$this->Seq_Table." - has it been created?");
|
||||
return 0;
|
||||
}
|
||||
return $nextid;
|
||||
}
|
||||
|
||||
/* public: return table metadata */
|
||||
function metadata($table='',$full=false) {
|
||||
$res = array();
|
||||
|
||||
/*
|
||||
* Due to compatibility problems with Table we changed the behavior
|
||||
* of metadata();
|
||||
* depending on $full, metadata returns the following values:
|
||||
*
|
||||
* - full is false (default):
|
||||
* $result[]:
|
||||
* [0]["table"] table name
|
||||
* [0]["name"] field name
|
||||
* [0]["type"] field type
|
||||
* [0]["len"] field length
|
||||
* [0]["flags"] field flags
|
||||
*
|
||||
* - full is true
|
||||
* $result[]:
|
||||
* ["num_fields"] number of metadata records
|
||||
* [0]["table"] table name
|
||||
* [0]["name"] field name
|
||||
* [0]["type"] field type
|
||||
* [0]["len"] field length
|
||||
* [0]["flags"] field flags
|
||||
* ["meta"][field name] index of field named "field name"
|
||||
* The last one is used, if you have a field name, but no index.
|
||||
* Test: if (isset($result['meta']['myfield'])) { ...
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
// if no $table specified, assume that we are working with a query
|
||||
// result
|
||||
if ($table) {
|
||||
$this->connect();
|
||||
$id = @mysql_list_fields($this->Database, $table);
|
||||
if (!$id)
|
||||
$this->halt("Metadata query failed.");
|
||||
} else {
|
||||
$id = $this->Query_ID;
|
||||
if (!$id)
|
||||
$this->halt("No query specified.");
|
||||
}
|
||||
|
||||
$count = @mysql_num_fields($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;
|
||||
}
|
||||
function DB_Sql($query = "") {
|
||||
$this->query($query);
|
||||
}
|
||||
|
||||
// free the result only if we were called on a table
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* @return resource class variable Link_ID
|
||||
*/
|
||||
function link_id() {
|
||||
return $this->Link_ID;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
$this->Error = @mysql_error($this->Link_ID);
|
||||
$this->Errno = @mysql_errno($this->Link_ID);
|
||||
if ($this->Halt_On_Error == "no")
|
||||
return;
|
||||
/**
|
||||
* @return integer class variable Query_ID
|
||||
*/
|
||||
function query_id() {
|
||||
return $this->Query_ID;
|
||||
}
|
||||
|
||||
$this->haltmsg($msg);
|
||||
/**
|
||||
* function for MySQL database connection management
|
||||
*
|
||||
* This function manages the connection to the MySQL database.
|
||||
*
|
||||
* @param $Database name of the database
|
||||
* @param $Host DNS of the MySQL hosting server
|
||||
* @param $User the user's name
|
||||
* @param $Password the user's password
|
||||
*
|
||||
* @return the class variable $Link_ID
|
||||
*/
|
||||
function connect($Database = "", $Host = "", $User = "", $Password = "") {
|
||||
/* Handle defaults */
|
||||
if ("" == $Database) {
|
||||
$Database = $this->Database;
|
||||
}
|
||||
if ("" == $Host) {
|
||||
$Host = $this->Host;
|
||||
}
|
||||
if ("" == $User) {
|
||||
$User = $this->User;
|
||||
}
|
||||
if ("" == $Password) {
|
||||
$Password = $this->Password;
|
||||
}
|
||||
|
||||
if ($this->Halt_On_Error != "report")
|
||||
die("Session halted.");
|
||||
}
|
||||
/* establish connection, select database */
|
||||
if (0 == $this->Link_ID) {
|
||||
|
||||
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);
|
||||
}
|
||||
$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);
|
||||
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));
|
||||
if ($db_connected[0] != $this->Database)
|
||||
mysql_select_db($Database, $this->Link_ID);
|
||||
|
||||
return $this->Link_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Discard the query result
|
||||
*
|
||||
* This function discards the last query result.
|
||||
*/
|
||||
function free() {
|
||||
@mysql_free_result($this->Query_ID);
|
||||
$this->Query_ID = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a query
|
||||
*
|
||||
* This function performs the MySQL query described in the string parameter
|
||||
*
|
||||
* @param a string describing the MySQL query
|
||||
* @return the $Query_ID class variable (null if fails)
|
||||
*/
|
||||
function query($Query_String) {
|
||||
global $debug_alternc;
|
||||
|
||||
/* No empty queries, please, since PHP4 chokes on them. */
|
||||
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) {
|
||||
$this->free();
|
||||
$this->Query_String = $Query_String;
|
||||
}
|
||||
|
||||
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->Row = 0;
|
||||
$this->Errno = mysql_errno();
|
||||
$this->Error = mysql_error();
|
||||
if (0 != $this->Errno) {
|
||||
if (defined("THROW_EXCEPTIONS") && THROW_EXCEPTIONS) {
|
||||
throw new \Exception("Mysql query failed : $this->Error");
|
||||
}
|
||||
$this->halt("SQL Error: " . $Query_String);
|
||||
return FALSE;
|
||||
}
|
||||
if (!$this->Query_ID) {
|
||||
$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->nb_sql_query++;
|
||||
$debug_alternc->tps_sql_query += $debug_chrono_start;
|
||||
}
|
||||
|
||||
# Will return nada if it fails. That's fine.
|
||||
return $this->Query_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* walk result set
|
||||
*
|
||||
* This function tests if a new record is available in the current
|
||||
* query result.
|
||||
*
|
||||
* @return TRUE if a new record is available
|
||||
*/
|
||||
function next_record() {
|
||||
if (!$this->Query_ID) {
|
||||
$this->halt("next_record called with no query pending.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->Record = @mysql_fetch_array($this->Query_ID);
|
||||
$this->Row += 1;
|
||||
$this->Errno = mysql_errno();
|
||||
$this->Error = mysql_error();
|
||||
|
||||
$stat = is_array($this->Record);
|
||||
if (!$stat && $this->Auto_Free) {
|
||||
$this->free();
|
||||
}
|
||||
return $stat;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* public: position in result set
|
||||
*/
|
||||
function seek($pos = 0) {
|
||||
$status = @mysql_data_seek($this->Query_ID, $pos);
|
||||
if ($status) {
|
||||
$this->Row = $pos;
|
||||
} 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
|
||||
* desireable behaviour.
|
||||
*/
|
||||
@mysql_data_seek($this->Query_ID, $this->num_rows());
|
||||
$this->Row = $this->num_rows;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** public: table locking */
|
||||
function lock($table, $mode = "write") {
|
||||
$this->connect();
|
||||
|
||||
$query = "lock tables ";
|
||||
if (is_array($table)) {
|
||||
while (list($key, $value) = each($table)) {
|
||||
if ($key == "read" && $key != 0) {
|
||||
$query.="$value read, ";
|
||||
} else {
|
||||
$query.="$value $mode, ";
|
||||
}
|
||||
}
|
||||
$query = substr($query, 0, -2);
|
||||
} else {
|
||||
$query.="$table $mode";
|
||||
}
|
||||
$res = @mysql_query($query, $this->Link_ID);
|
||||
if (!$res) {
|
||||
$this->halt("lock($table, $mode) failed.");
|
||||
return 0;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
function unlock() {
|
||||
$this->connect();
|
||||
|
||||
$res = @mysql_query("unlock tables", $this->Link_ID);
|
||||
if (!$res) {
|
||||
$this->halt("unlock() failed.");
|
||||
return 0;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/** public: evaluate the result (size, width) */
|
||||
function affected_rows() {
|
||||
return @mysql_affected_rows($this->Link_ID);
|
||||
}
|
||||
|
||||
function num_rows() {
|
||||
return @mysql_num_rows($this->Query_ID);
|
||||
}
|
||||
|
||||
function num_fields() {
|
||||
return @mysql_num_fields($this->Query_ID);
|
||||
}
|
||||
|
||||
/** public: shorthand notation */
|
||||
function nf() {
|
||||
return $this->num_rows();
|
||||
}
|
||||
|
||||
function np() {
|
||||
print $this->num_rows();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $Name
|
||||
* @return integer
|
||||
*/
|
||||
function f($Name) {
|
||||
if (isset($this->Record[$Name]))
|
||||
return $this->Record[$Name];
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function p($Name) {
|
||||
print $this->Record[$Name];
|
||||
}
|
||||
|
||||
function lastid() {
|
||||
return @mysql_insert_id($this->Link_ID);
|
||||
}
|
||||
|
||||
/** 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);
|
||||
$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);
|
||||
@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);
|
||||
@mysql_query($q, $this->Link_ID);
|
||||
$this->unlock();
|
||||
} else {
|
||||
$this->halt("cannot lock " . $this->Seq_Table . " - has it been created?");
|
||||
return 0;
|
||||
}
|
||||
return $nextid;
|
||||
}
|
||||
|
||||
/** public: return table metadata */
|
||||
function metadata($table = '', $full = false) {
|
||||
$res = array();
|
||||
|
||||
/*
|
||||
* Due to compatibility problems with Table we changed the behavior
|
||||
* of metadata();
|
||||
* depending on $full, metadata returns the following values:
|
||||
*
|
||||
* - full is false (default):
|
||||
* $result[]:
|
||||
* [0]["table"] table name
|
||||
* [0]["name"] field name
|
||||
* [0]["type"] field type
|
||||
* [0]["len"] field length
|
||||
* [0]["flags"] field flags
|
||||
*
|
||||
* - full is true
|
||||
* $result[]:
|
||||
* ["num_fields"] number of metadata records
|
||||
* [0]["table"] table name
|
||||
* [0]["name"] field name
|
||||
* [0]["type"] field type
|
||||
* [0]["len"] field length
|
||||
* [0]["flags"] field flags
|
||||
* ["meta"][field name] index of field named "field name"
|
||||
* The last one is used, if you have a field name, but no index.
|
||||
* Test: if (isset($result['meta']['myfield'])) { ...
|
||||
*/
|
||||
|
||||
// if no $table specified, assume that we are working with a query
|
||||
// result
|
||||
if ($table) {
|
||||
$this->connect();
|
||||
$id = @mysql_list_fields($this->Database, $table);
|
||||
if (!$id)
|
||||
$this->halt("Metadata query failed.");
|
||||
} else {
|
||||
$id = $this->Query_ID;
|
||||
if (!$id)
|
||||
$this->halt("No query specified.");
|
||||
}
|
||||
|
||||
$count = @mysql_num_fields($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) {
|
||||
$this->Error = @mysql_error($this->Link_ID);
|
||||
$this->Errno = @mysql_errno($this->Link_ID);
|
||||
if ($this->Halt_On_Error == "no")
|
||||
return;
|
||||
|
||||
$this->haltmsg($msg);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,41 +1,45 @@
|
|||
<?php
|
||||
|
||||
$lang_translation=array( # If you comment lang here, it won't be displayed.
|
||||
"fr_FR" => "Français",
|
||||
"en_US" => "English",
|
||||
$lang_translation = array(# If you comment lang here, it won't be displayed.
|
||||
"fr_FR" => "Français",
|
||||
"en_US" => "English",
|
||||
# "es_ES" => "Español",
|
||||
# "it_IT" => "Italiano",
|
||||
# "de_DE" => "Deutsch",
|
||||
# "pt_BR" => "Portuguese",
|
||||
"nl_NL" => "Dutch",
|
||||
);
|
||||
"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];
|
||||
global $arr_lang_translation;
|
||||
$locales = array();
|
||||
$file = file("/etc/locale.gen", FILE_SKIP_EMPTY_LINES);
|
||||
if (!is_array($file)) {
|
||||
return $locales;
|
||||
}
|
||||
}
|
||||
if (!count($locales)) {
|
||||
$locales=array("en_US"=>"en_US");
|
||||
}
|
||||
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");
|
||||
}
|
||||
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,49 +49,50 @@ $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
|
||||
// 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;
|
||||
break;
|
||||
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;
|
||||
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
|
||||
if ($lang == NULL) {
|
||||
$lang = "en_US";
|
||||
$lang = "en_US";
|
||||
}
|
||||
|
||||
/* 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");
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
<?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',
|
||||
'MYSQL_USER' => 'MYSQL_LOGIN',
|
||||
'MYSQL_PASS' => 'MYSQL_PWD',
|
||||
'NS1_HOSTNAME' => 'NS1',
|
||||
'NS2_HOSTNAME' => 'NS2');
|
||||
$compat = array('DEFAULT_MX' => 'MX',
|
||||
'MYSQL_USER' => 'MYSQL_LOGIN',
|
||||
'MYSQL_PASS' => 'MYSQL_PWD',
|
||||
'NS1_HOSTNAME' => 'NS1',
|
||||
'NS2_HOSTNAME' => 'NS2');
|
||||
|
||||
|
||||
$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,24 +28,23 @@ 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":
|
||||
$GLOBALS['L_MYSQL_LOGIN'] = $regs[2];
|
||||
break;
|
||||
case "password":
|
||||
$GLOBALS['L_MYSQL_PWD'] = $regs[2];
|
||||
break;
|
||||
case "host":
|
||||
$GLOBALS['L_MYSQL_HOST'] = $regs[2];
|
||||
break;
|
||||
case "database":
|
||||
$GLOBALS['L_MYSQL_DATABASE'] = $regs[2];
|
||||
break;
|
||||
case "user":
|
||||
$GLOBALS['L_MYSQL_LOGIN'] = $regs[2];
|
||||
break;
|
||||
case "password":
|
||||
$GLOBALS['L_MYSQL_PWD'] = $regs[2];
|
||||
break;
|
||||
case "host":
|
||||
$GLOBALS['L_MYSQL_HOST'] = $regs[2];
|
||||
break;
|
||||
case "database":
|
||||
$GLOBALS['L_MYSQL_DATABASE'] = $regs[2];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose($config_file);
|
||||
?>
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
class m_action {
|
||||
/* --------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function m_action() {
|
||||
|
@ -48,9 +48,9 @@ class m_action {
|
|||
* @return boolean
|
||||
*/
|
||||
function do_action() {
|
||||
global $err, $L_INOTIFY_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,9 +77,9 @@ 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));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Plans the creation of a dir
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -327,7 +326,7 @@ class m_action {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @global m_mysql $db
|
||||
|
@ -343,7 +342,7 @@ class m_action {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a list of actions marked as executable and ready for execution
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,8 +627,9 @@ 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');");
|
||||
|
@ -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,12 +927,14 @@ 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"));
|
||||
|
@ -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,14 +1462,16 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($pol["classcount"] > 0) {
|
||||
$cls = array(0, 0, 0, 0, 0);
|
||||
for ($i = 0; $i < strlen($password); $i++) {
|
||||
|
|
|
@ -1,178 +1,174 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
$Id: mime.php,v 1.3 2004/06/03 14:32:20 anonymous Exp $
|
||||
----------------------------------------------------------------------
|
||||
AlternC - Web Hosting System
|
||||
Copyright (C) 2002 by the AlternC Development Team.
|
||||
http://alternc.org/
|
||||
----------------------------------------------------------------------
|
||||
Based on:
|
||||
Valentin Lacambre's web hosting softwares: http://altern.org/
|
||||
----------------------------------------------------------------------
|
||||
LICENSE
|
||||
$Id: mime.php,v 1.3 2004/06/03 14:32:20 anonymous Exp $
|
||||
----------------------------------------------------------------------
|
||||
AlternC - Web Hosting System
|
||||
Copyright (C) 2002 by the AlternC Development Team.
|
||||
http://alternc.org/
|
||||
----------------------------------------------------------------------
|
||||
Based on:
|
||||
Valentin Lacambre's web hosting softwares: http://altern.org/
|
||||
----------------------------------------------------------------------
|
||||
LICENSE
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License (GPL)
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License (GPL)
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
||||
----------------------------------------------------------------------
|
||||
Original Author of file: Benjamin Sonntag 23/12/2001
|
||||
Purpose of file: Brouteur php3 pour AlternC
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
||||
----------------------------------------------------------------------
|
||||
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)
|
||||
|
||||
Version 0.1
|
||||
Brouteur php3 pour AlternC (voir http://www.alternc.org)
|
||||
|
||||
Notes :
|
||||
Benjamin Sonntag 23/12/2001 Version initiale
|
||||
|
||||
Fichier :
|
||||
mime.php3 : gestion de la liste des types mime des fichiers.
|
||||
Version 0.1
|
||||
|
||||
*/
|
||||
Notes :
|
||||
Benjamin Sonntag 23/12/2001 Version initiale
|
||||
|
||||
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(
|
||||
"css" => "text/css",
|
||||
"csv" => "text/comma-separated-values",
|
||||
"dia" => "application/x-dia",
|
||||
"doc" => "application/msword",
|
||||
"dot" => "application/msword",
|
||||
"epf" => "application/postscript",
|
||||
"gif" => "image/gif",
|
||||
"hqx" => "application/mac-binhex40",
|
||||
"htm" => "text/html",
|
||||
"html"=> "text/html",
|
||||
"jpeg" => "image/jpeg",
|
||||
"jpg" => "image/jpeg",
|
||||
"m3u" => "audio/mpegurl",
|
||||
"mp3" => "audio/mpeg",
|
||||
"ogg" => "application/ogg",
|
||||
"pdf" => "application/pdf",
|
||||
"php" => "text/plain",
|
||||
"png" => "image/png",
|
||||
"pps" => "application/powerpoint",
|
||||
"ppt" => "application/powerpoint",
|
||||
"ps" => "application/postscript",
|
||||
"psd" => "image/psd",
|
||||
"ra" => "audio/x-pn-realaudio",
|
||||
"ram" => "audio/x-pn-realaudio",
|
||||
"rar" => "application/rar",
|
||||
"rm" => "audio/x-pn-realaudio",
|
||||
"rtf" => "text/rtf",
|
||||
"swf" => "application/x-shockwave-flash",
|
||||
"sxc" => "application/vnd.sun.xml.calc",
|
||||
"sxd" => "application/vnd.sun.xml.draw",
|
||||
"sxi" => "application/vnd.sun.xml.impress",
|
||||
"sxw" => "application/vnd.sun.xml.writer",
|
||||
"tif" => "image/tiff",
|
||||
"tiff" => "image/tiff",
|
||||
"txt" => "text/plain",
|
||||
"vcf" => "text/x-vCard",
|
||||
"vcs" => "text/x-vCalendar",
|
||||
"xcf" => "image/xcf",
|
||||
"xls" => "application/vnd.ms-excel",
|
||||
"zip" => "application/zip",
|
||||
);
|
||||
$bro_mime = array(
|
||||
"css" => "text/css",
|
||||
"csv" => "text/comma-separated-values",
|
||||
"dia" => "application/x-dia",
|
||||
"doc" => "application/msword",
|
||||
"dot" => "application/msword",
|
||||
"epf" => "application/postscript",
|
||||
"gif" => "image/gif",
|
||||
"hqx" => "application/mac-binhex40",
|
||||
"htm" => "text/html",
|
||||
"html" => "text/html",
|
||||
"jpeg" => "image/jpeg",
|
||||
"jpg" => "image/jpeg",
|
||||
"m3u" => "audio/mpegurl",
|
||||
"mp3" => "audio/mpeg",
|
||||
"ogg" => "application/ogg",
|
||||
"pdf" => "application/pdf",
|
||||
"php" => "text/plain",
|
||||
"png" => "image/png",
|
||||
"pps" => "application/powerpoint",
|
||||
"ppt" => "application/powerpoint",
|
||||
"ps" => "application/postscript",
|
||||
"psd" => "image/psd",
|
||||
"ra" => "audio/x-pn-realaudio",
|
||||
"ram" => "audio/x-pn-realaudio",
|
||||
"rar" => "application/rar",
|
||||
"rm" => "audio/x-pn-realaudio",
|
||||
"rtf" => "text/rtf",
|
||||
"swf" => "application/x-shockwave-flash",
|
||||
"sxc" => "application/vnd.sun.xml.calc",
|
||||
"sxd" => "application/vnd.sun.xml.draw",
|
||||
"sxi" => "application/vnd.sun.xml.impress",
|
||||
"sxw" => "application/vnd.sun.xml.writer",
|
||||
"tif" => "image/tiff",
|
||||
"tiff" => "image/tiff",
|
||||
"txt" => "text/plain",
|
||||
"vcf" => "text/x-vCard",
|
||||
"vcs" => "text/x-vCalendar",
|
||||
"xcf" => "image/xcf",
|
||||
"xls" => "application/vnd.ms-excel",
|
||||
"zip" => "application/zip",
|
||||
);
|
||||
|
||||
$bro_icon=
|
||||
array(
|
||||
"css" => "txt",
|
||||
"csv" => "xls",
|
||||
"dia" => "jpg",
|
||||
"doc" => "doc",
|
||||
"dot" => "doc",
|
||||
"epf" => "txt",
|
||||
"gif" => "jpg",
|
||||
"hqx" => "exe",
|
||||
"htm" => "htm",
|
||||
"html"=> "htm",
|
||||
"jpeg" => "jpg",
|
||||
"jpg" => "jpg",
|
||||
"m3u" => "m3u",
|
||||
"mp3" => "wav",
|
||||
"ogg" => "wav",
|
||||
"pdf" => "pdf",
|
||||
"php" => "php",
|
||||
"png" => "jpg",
|
||||
"pps" => "ppt",
|
||||
"ppt" => "ppt",
|
||||
"ps" => "txt",
|
||||
"psd" => "jpg",
|
||||
"ra" => "ra",
|
||||
"ram" => "ra",
|
||||
"rar" => "zip",
|
||||
"rm" => "ra",
|
||||
"rtf" => "doc",
|
||||
"swf" => "swf",
|
||||
"sxc" => "sxc",
|
||||
"sxd" => "sxd",
|
||||
"sxi" => "sxi",
|
||||
"sxw" => "sxw",
|
||||
"tif" => "jpg",
|
||||
"tiff" => "jpg",
|
||||
"txt" => "txt",
|
||||
"vcf" => "file",
|
||||
"vcs" => "file",
|
||||
"xcf" => "jpg",
|
||||
"xls" => "xls",
|
||||
"zip" => "zip",
|
||||
);
|
||||
|
||||
$bro_type=
|
||||
array(
|
||||
"css" => _("CSS Stylesheet"),
|
||||
"csv" => _("Comma Separated Values data"),
|
||||
"dia" => _("DIA Diagram"),
|
||||
"doc" => _("Word Document"),
|
||||
"dot" => _("Word Document Template"),
|
||||
"epf" => _("Encapsulated Postscript"),
|
||||
"gif" => _("GIF Image"),
|
||||
"hqx" => _("Macintosh Executable"),
|
||||
"htm" => _("HTML Document"),
|
||||
"html"=> _("HTML Document"),
|
||||
"jpeg" => _("JPEG Image"),
|
||||
"jpg" => _("JPEG Image"),
|
||||
"m3u" => _("Music Playlist"),
|
||||
"mp3" => _("MP3 Music File"),
|
||||
"ogg" => _("Ogg Music File"),
|
||||
"pdf" => _("Acrobat PDF"),
|
||||
"php" => _("PHP Source"),
|
||||
"png" => _("PNG Image"),
|
||||
"pps" => _("Powerpoint Slideshow"),
|
||||
"ppt" => _("Powerpoint Slideshow"),
|
||||
"ps" => _("Postscript Document"),
|
||||
"psd" => _("Photoshop Image"),
|
||||
"rar" => _("Rar Compressed Files"),
|
||||
"rtf" => _("Rich Text Document"),
|
||||
"sxc" => _("OpenOffice Spreadsheet"),
|
||||
"sxd" => _("OpenOffice Drawing"),
|
||||
"sxi" => _("OpenOffice Presentation"),
|
||||
"sxw" => _("OpenOffice Writer"),
|
||||
"tif" => _("TIFF Image"),
|
||||
"tiff" => _("TIFF Image"),
|
||||
"txt" => _("Text Document"),
|
||||
"vcf" => _("Virtual Card"),
|
||||
"vcs" => _("Virtual Card"),
|
||||
"xcf" => _("Gimp Image"),
|
||||
"xls" => _("Excel Spreadsheet"),
|
||||
"zip" => _("Zip Compressed Files"),
|
||||
"sxw" => _("Flash Animation"),
|
||||
"ra" => _("Real Media File"),
|
||||
"rm" => _("Real Media File"),
|
||||
"ram" => _("Real Media File"),
|
||||
);
|
||||
$bro_icon = array(
|
||||
"css" => "txt",
|
||||
"csv" => "xls",
|
||||
"dia" => "jpg",
|
||||
"doc" => "doc",
|
||||
"dot" => "doc",
|
||||
"epf" => "txt",
|
||||
"gif" => "jpg",
|
||||
"hqx" => "exe",
|
||||
"htm" => "htm",
|
||||
"html" => "htm",
|
||||
"jpeg" => "jpg",
|
||||
"jpg" => "jpg",
|
||||
"m3u" => "m3u",
|
||||
"mp3" => "wav",
|
||||
"ogg" => "wav",
|
||||
"pdf" => "pdf",
|
||||
"php" => "php",
|
||||
"png" => "jpg",
|
||||
"pps" => "ppt",
|
||||
"ppt" => "ppt",
|
||||
"ps" => "txt",
|
||||
"psd" => "jpg",
|
||||
"ra" => "ra",
|
||||
"ram" => "ra",
|
||||
"rar" => "zip",
|
||||
"rm" => "ra",
|
||||
"rtf" => "doc",
|
||||
"swf" => "swf",
|
||||
"sxc" => "sxc",
|
||||
"sxd" => "sxd",
|
||||
"sxi" => "sxi",
|
||||
"sxw" => "sxw",
|
||||
"tif" => "jpg",
|
||||
"tiff" => "jpg",
|
||||
"txt" => "txt",
|
||||
"vcf" => "file",
|
||||
"vcs" => "file",
|
||||
"xcf" => "jpg",
|
||||
"xls" => "xls",
|
||||
"zip" => "zip",
|
||||
);
|
||||
|
||||
$bro_type = array(
|
||||
"css" => _("CSS Stylesheet"),
|
||||
"csv" => _("Comma Separated Values data"),
|
||||
"dia" => _("DIA Diagram"),
|
||||
"doc" => _("Word Document"),
|
||||
"dot" => _("Word Document Template"),
|
||||
"epf" => _("Encapsulated Postscript"),
|
||||
"gif" => _("GIF Image"),
|
||||
"hqx" => _("Macintosh Executable"),
|
||||
"htm" => _("HTML Document"),
|
||||
"html" => _("HTML Document"),
|
||||
"jpeg" => _("JPEG Image"),
|
||||
"jpg" => _("JPEG Image"),
|
||||
"m3u" => _("Music Playlist"),
|
||||
"mp3" => _("MP3 Music File"),
|
||||
"ogg" => _("Ogg Music File"),
|
||||
"pdf" => _("Acrobat PDF"),
|
||||
"php" => _("PHP Source"),
|
||||
"png" => _("PNG Image"),
|
||||
"pps" => _("Powerpoint Slideshow"),
|
||||
"ppt" => _("Powerpoint Slideshow"),
|
||||
"ps" => _("Postscript Document"),
|
||||
"psd" => _("Photoshop Image"),
|
||||
"rar" => _("Rar Compressed Files"),
|
||||
"rtf" => _("Rich Text Document"),
|
||||
"sxc" => _("OpenOffice Spreadsheet"),
|
||||
"sxd" => _("OpenOffice Drawing"),
|
||||
"sxi" => _("OpenOffice Presentation"),
|
||||
"sxw" => _("OpenOffice Writer"),
|
||||
"tif" => _("TIFF Image"),
|
||||
"tiff" => _("TIFF Image"),
|
||||
"txt" => _("Text Document"),
|
||||
"vcf" => _("Virtual Card"),
|
||||
"vcs" => _("Virtual Card"),
|
||||
"xcf" => _("Gimp Image"),
|
||||
"xls" => _("Excel Spreadsheet"),
|
||||
"zip" => _("Zip Compressed Files"),
|
||||
"sxw" => _("Flash Animation"),
|
||||
"ra" => _("Real Media File"),
|
||||
"rm" => _("Real Media File"),
|
||||
"ram" => _("Real Media File"),
|
||||
);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -3,18 +3,17 @@
|
|||
include("config.php");
|
||||
|
||||
if (!$admin->enabled) {
|
||||
__("This page is restricted to authorized staff");
|
||||
exit();
|
||||
__("This page is restricted to authorized staff");
|
||||
exit();
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,28 +2,28 @@
|
|||
|
||||
/*
|
||||
* $Id: variables.php,v 1.8 2005/04/02 00:26:36 anarcat Exp $
|
||||
----------------------------------------------------------------------
|
||||
AlternC - Web Hosting System
|
||||
Copyright (C) 2002 by the AlternC Development Team.
|
||||
http://alternc.org/
|
||||
----------------------------------------------------------------------
|
||||
Based on:
|
||||
Valentin Lacambre's web hosting softwares: http://altern.org/
|
||||
----------------------------------------------------------------------
|
||||
LICENSE
|
||||
----------------------------------------------------------------------
|
||||
AlternC - Web Hosting System
|
||||
Copyright (C) 2002 by the AlternC Development Team.
|
||||
http://alternc.org/
|
||||
----------------------------------------------------------------------
|
||||
Based on:
|
||||
Valentin Lacambre's web hosting softwares: http://altern.org/
|
||||
----------------------------------------------------------------------
|
||||
LICENSE
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License (GPL)
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License (GPL)
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
||||
----------------------------------------------------------------------
|
||||
To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -41,21 +41,21 @@
|
|||
* file.
|
||||
*/
|
||||
function variable_init($conf = array()) {
|
||||
global $db;
|
||||
$result = $db->query('SELECT * FROM `variable`');
|
||||
while ($db->next_record($result)) {
|
||||
/* maybe the data is *not* serialized, in that case, take it verbatim */
|
||||
$variable = $db->Record;
|
||||
if (($variables[$variable['name']] = @unserialize($variable['value'])) === FALSE) {
|
||||
$variables[$variable['name']] = $variable['value'];
|
||||
global $db;
|
||||
$result = $db->query('SELECT * FROM `variable`');
|
||||
while ($db->next_record($result)) {
|
||||
/* maybe the data is *not* serialized, in that case, take it verbatim */
|
||||
$variable = $db->Record;
|
||||
if (($variables[$variable['name']] = @unserialize($variable['value'])) === FALSE) {
|
||||
$variables[$variable['name']] = $variable['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($conf as $name => $value) {
|
||||
$variables[$name] = $value;
|
||||
}
|
||||
|
||||
return $variables;
|
||||
foreach ($conf as $name => $value) {
|
||||
$variables[$name] = $value;
|
||||
}
|
||||
|
||||
return $variables;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,10 +65,10 @@ function variable_init($conf = array()) {
|
|||
* @uses variable_init()
|
||||
*/
|
||||
function variable_init_maybe() {
|
||||
global $conf;
|
||||
if (!isset($conf)) {
|
||||
$conf = variable_init();
|
||||
}
|
||||
global $conf;
|
||||
if (!isset($conf)) {
|
||||
$conf = variable_init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,16 +87,16 @@ function variable_init_maybe() {
|
|||
* A cache of the configuration.
|
||||
*/
|
||||
function variable_get($name, $default = null, $createit_comment = null) {
|
||||
global $conf;
|
||||
global $conf;
|
||||
|
||||
variable_init_maybe();
|
||||
variable_init_maybe();
|
||||
|
||||
if (isset($conf[$name])) {
|
||||
return $conf[$name];
|
||||
} elseif (!is_null($createit_comment)) {
|
||||
variable_set($name, $default, $createit_comment);
|
||||
}
|
||||
return $default;
|
||||
if (isset($conf[$name])) {
|
||||
return $conf[$name];
|
||||
} elseif (!is_null($createit_comment)) {
|
||||
variable_set($name, $default, $createit_comment);
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,31 +108,31 @@ 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) {
|
||||
global $conf, $db, $err, $hooks;
|
||||
$err->log('variable', 'variable_set', '+'.serialize($value).'+'.$comment.'+');
|
||||
function variable_set($name, $value, $comment = null) {
|
||||
global $conf, $db, $err, $hooks;
|
||||
$err->log('variable', 'variable_set', '+' . serialize($value) . '+' . $comment . '+');
|
||||
|
||||
variable_init_maybe();
|
||||
variable_init_maybe();
|
||||
|
||||
if (is_object($value) || is_array($value)) {
|
||||
$value2 = serialize($value);
|
||||
}
|
||||
if (array_key_exists($name,$conf)) {
|
||||
$previous=$conf[$name];
|
||||
} else {
|
||||
$previous=null;
|
||||
}
|
||||
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';";
|
||||
} 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';";
|
||||
if (is_object($value) || is_array($value)) {
|
||||
$value2 = serialize($value);
|
||||
}
|
||||
if (array_key_exists($name, $conf)) {
|
||||
$previous = $conf[$name];
|
||||
} else {
|
||||
$previous = null;
|
||||
}
|
||||
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';";
|
||||
} 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';";
|
||||
}
|
||||
$db->query($query);
|
||||
$hooks->invoke("hook_variable_set", array("name" => $name, "old" => $previous, "new" => $value));
|
||||
}
|
||||
$db->query($query);
|
||||
$hooks->invoke("hook_variable_set", array("name" => $name, "old"=> $previous, "new"=>$value ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -142,21 +142,17 @@ function variable_set($name, $value, $comment=null) {
|
|||
* The name of the variable to undefine.
|
||||
*/
|
||||
function variable_del($name) {
|
||||
global $conf, $db;
|
||||
|
||||
$db->query("DELETE FROM `variable` WHERE name = '".$name."'");
|
||||
|
||||
unset($conf[$name]);
|
||||
global $conf, $db;
|
||||
$db->query("DELETE FROM `variable` WHERE name = '" . $name . "'");
|
||||
unset($conf[$name]);
|
||||
}
|
||||
|
||||
function variables_list() {
|
||||
global $db;
|
||||
$t=array();
|
||||
$db->query("SELECT * FROM `variable` WHERE `comment` IS NOT NULL ORDER BY `name`");
|
||||
while ($db->next_record()) {
|
||||
$t[]=$db->Record;
|
||||
}
|
||||
return $t;
|
||||
global $db;
|
||||
$t = array();
|
||||
$db->query("SELECT * FROM `variable` WHERE `comment` IS NOT NULL ORDER BY `name`");
|
||||
while ($db->next_record()) {
|
||||
$t[] = $db->Record;
|
||||
}
|
||||
return $t;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue