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
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$Id: config.php,v 1.12 2005/12/18 09:51:32 benjamin Exp $
|
$Id: config.php,v 1.12 2005/12/18 09:51:32 benjamin Exp $
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
AlternC - Web Hosting System
|
AlternC - Web Hosting System
|
||||||
Copyright (C) 2002 by the AlternC Development Team.
|
Copyright (C) 2002 by the AlternC Development Team.
|
||||||
http://alternc.org/
|
http://alternc.org/
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Based on:
|
Based on:
|
||||||
Valentin Lacambre's web hosting softwares: http://altern.org/
|
Valentin Lacambre's web hosting softwares: http://altern.org/
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
LICENSE
|
LICENSE
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License (GPL)
|
modify it under the terms of the GNU General Public License (GPL)
|
||||||
as published by the Free Software Foundation; either version 2
|
as published by the Free Software Foundation; either version 2
|
||||||
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
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
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Original Author of file: Benjamin Sonntag
|
Original Author of file: Benjamin Sonntag
|
||||||
Purpose of file: General configuration file for AlternC Desktop
|
Purpose of file: General configuration file for AlternC Desktop
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
define('DO_XHPROF_STATS', FALSE);
|
define('DO_XHPROF_STATS', FALSE);
|
||||||
if (DO_XHPROF_STATS) require_once('/usr/share/alternc/panel/admin/xhprof_header.php');
|
if (DO_XHPROF_STATS) {
|
||||||
|
require_once('/usr/share/alternc/panel/admin/xhprof_header.php');
|
||||||
|
}
|
||||||
|
|
||||||
// To enable the display of the alternc debug error, do the following :
|
// To enable the display of the alternc debug error, do the following :
|
||||||
// # touch /etc/alternc/alternc_display_php_error
|
// # touch /etc/alternc/alternc_display_php_error
|
||||||
if (file_exists('/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();
|
session_start();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Si vous voulez mettre le bureau en maintenance, decommentez le code ci-dessous
|
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>
|
echo "Le bureau AlternC est en vacances jusqu'a minuit pour maintenance.<br>
|
||||||
Merci de revenir plus tard.";
|
Merci de revenir plus tard.";
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
/* */
|
/* */
|
||||||
|
|
||||||
if (ini_get("safe_mode")) {
|
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 !!";
|
echo "SAFE MODE IS ENABLED for the web panel ! It's a bug in your php or apache configuration, please fix it !!";
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// For people who want to authenticate with HTTP AUTH
|
// For people who want to authenticate with HTTP AUTH
|
||||||
if (isset($_GET['http_auth'])) $http_auth=strval($_GET['http_auth']);
|
if (isset($_GET['http_auth']))
|
||||||
|
$http_auth = strval($_GET['http_auth']);
|
||||||
if (isset($http_auth)) {
|
if (isset($http_auth)) {
|
||||||
if (empty($_SERVER['PHP_AUTH_USER']) || empty($_SERVER['PHP_AUTH_PW'])) {
|
if (empty($_SERVER['PHP_AUTH_USER']) || empty($_SERVER['PHP_AUTH_PW'])) {
|
||||||
header('WWW-Authenticate: Basic realm="AlternC Authentication"');
|
header('WWW-Authenticate: Basic realm="AlternC Authentication"');
|
||||||
header('HTTP/1.0 401 Unauthorized');
|
header('HTTP/1.0 401 Unauthorized');
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
|
if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
|
||||||
// Gruiiik
|
// Gruiiik
|
||||||
$_REQUEST["username"]=$_SERVER['PHP_AUTH_USER'];
|
$_REQUEST["username"] = $_SERVER['PHP_AUTH_USER'];
|
||||||
$_REQUEST["password"]=$_SERVER['PHP_AUTH_PW'];
|
$_REQUEST["password"] = $_SERVER['PHP_AUTH_PW'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// proper srand (not using time(), which is what PHP does!)
|
// proper srand (not using time(), which is what PHP does!)
|
||||||
list($usec, $sec) = explode(" ", microtime());
|
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 */
|
/* Server Domain Name */
|
||||||
$host=getenv("HTTP_HOST");
|
$host = getenv("HTTP_HOST");
|
||||||
|
|
||||||
/* Global variables (AlternC configuration) */
|
/* 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
|
// Define constants from vars of /etc/alternc/local.sh
|
||||||
// The you can't choose where is the AlternC Panel
|
// The you can't choose where is the AlternC Panel
|
||||||
define("DEFAULT_PASS_SIZE", 8);
|
define("DEFAULT_PASS_SIZE", 8);
|
||||||
define('ALTERNC_MAIL', "$L_ALTERNC_MAIL");
|
define('ALTERNC_MAIL', "$L_ALTERNC_MAIL");
|
||||||
define('ALTERNC_HTML', "$L_ALTERNC_HTML");
|
define('ALTERNC_HTML', "$L_ALTERNC_HTML");
|
||||||
if(isset($L_ALTERNC_LOGS_ARCHIVE))
|
if (isset($L_ALTERNC_LOGS_ARCHIVE)) {
|
||||||
define('ALTERNC_LOGS_ARCHIVE', "$L_ALTERNC_LOGS_ARCHIVE");
|
define('ALTERNC_LOGS_ARCHIVE', "$L_ALTERNC_LOGS_ARCHIVE");
|
||||||
define('ALTERNC_LOGS', "$L_ALTERNC_LOGS");
|
}
|
||||||
define('ALTERNC_PANEL', "/usr/share/alternc/panel");
|
define('ALTERNC_LOGS', "$L_ALTERNC_LOGS");
|
||||||
define('ALTERNC_LOCALES', ALTERNC_PANEL."/locales");
|
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_JOBS', '/var/run/alternc/jobs-lock');
|
||||||
define('ALTERNC_LOCK_PANEL', '/var/lib/alternc/panel/nologin.lock');
|
define('ALTERNC_LOCK_PANEL', '/var/lib/alternc/panel/nologin.lock');
|
||||||
define('ALTERNC_APACHE2_GEN_TMPL_DIR', '/etc/alternc/templates/apache2/');
|
define('ALTERNC_APACHE2_GEN_TMPL_DIR', '/etc/alternc/templates/apache2/');
|
||||||
define('ALTERNC_VHOST_DIR',"/var/lib/alternc/apache-vhost/");
|
define('ALTERNC_VHOST_DIR', "/var/lib/alternc/apache-vhost/");
|
||||||
define('ALTERNC_VHOST_FILE',ALTERNC_VHOST_DIR."vhosts_all.conf");
|
define('ALTERNC_VHOST_FILE', ALTERNC_VHOST_DIR . "vhosts_all.conf");
|
||||||
define('ALTERNC_VHOST_MANUALCONF',ALTERNC_VHOST_DIR."manual/");
|
define('ALTERNC_VHOST_MANUALCONF', ALTERNC_VHOST_DIR . "manual/");
|
||||||
|
|
||||||
|
|
||||||
/* PHPLIB inclusions : */
|
/* PHPLIB inclusions : */
|
||||||
$root=ALTERNC_PANEL."/";
|
$root = ALTERNC_PANEL . "/";
|
||||||
|
|
||||||
require_once($root."/class/db_mysql.php");
|
require_once($root . "/class/db_mysql.php");
|
||||||
require_once($root."/class/functions.php");
|
require_once($root . "/class/functions.php");
|
||||||
require_once($root."/class/variables.php");
|
require_once($root . "/class/variables.php");
|
||||||
|
|
||||||
// Redirection si appel <20> https://(!fqdn)/
|
// 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/");
|
header("Location: https://$L_FQDN/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// child class of the phplib parent DB class
|
||||||
// Classe h<>rit<69>e de la classe db de la phplib.
|
|
||||||
/**
|
/**
|
||||||
* Class for MySQL management in the bureau
|
* Class for MySQL management in the bureau
|
||||||
*
|
*
|
||||||
* This class heriting from the db class of the phplib manages
|
* This class heriting from the db class of the phplib manages
|
||||||
* the connection to the MySQL database.
|
* the connection to the MySQL database.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class DB_system extends DB_Sql {
|
class DB_system extends DB_Sql {
|
||||||
var $Host = null;
|
|
||||||
var $Database = null;
|
|
||||||
var $User = null;
|
|
||||||
var $Password = null;
|
|
||||||
|
|
||||||
/**
|
var $Host = null;
|
||||||
* Creator
|
var $Database = null;
|
||||||
*/
|
var $User = null;
|
||||||
function DB_system() {
|
var $Password = null;
|
||||||
global $L_MYSQL_HOST,$L_MYSQL_DATABASE,$L_MYSQL_LOGIN,$L_MYSQL_PWD;
|
|
||||||
$this->Host = $L_MYSQL_HOST;
|
/**
|
||||||
$this->Database = $L_MYSQL_DATABASE;
|
* Creator
|
||||||
$this->User = $L_MYSQL_LOGIN;
|
*/
|
||||||
$this->Password = $L_MYSQL_PWD;
|
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.
|
// Current User ID = the user whose commands are made on behalf of.
|
||||||
$cuid=0;
|
$cuid = 0;
|
||||||
|
|
||||||
|
|
||||||
$classes=array();
|
$classes = array();
|
||||||
/* CLASSES PHP : automatic include : */
|
/* CLASSES PHP : automatic include : */
|
||||||
foreach ( glob( $root."class/m_*.php") as $di ) {
|
foreach (glob($root . "class/m_*.php") as $di) {
|
||||||
if (preg_match("#${root}class/m_(.*)\\.php$#",$di,$match)) { // $
|
if (preg_match("#${root}class/m_(.*)\\.php$#", $di, $match)) { // $
|
||||||
$classes[]=$match[1];
|
$classes[] = $match[1];
|
||||||
require_once($di);
|
require_once($di);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* THE DEFAULT CLASSES ARE :
|
/* 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.
|
// Load file for the system class.
|
||||||
// Those class will not be build by default.
|
// Those class will not be build by default.
|
||||||
// They may contain forbidden action for the panel, for example: exec, system
|
// They may contain forbidden action for the panel, for example: exec, system
|
||||||
// or files operations
|
// or files operations
|
||||||
// We can imagine load those class only for command-line scripts.
|
// We can imagine load those class only for command-line scripts.
|
||||||
foreach ( glob( $root."class/class_system_*.php") as $fcs ) {
|
foreach (glob($root . "class/class_system_*.php") as $fcs) {
|
||||||
if (is_readable($fcs)) require_once($fcs);
|
if (is_readable($fcs))
|
||||||
|
require_once($fcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Language */
|
/* Language */
|
||||||
include_once("lang_env.php");
|
include_once("lang_env.php");
|
||||||
|
|
||||||
$mem=new m_mem();
|
$mem = new m_mem();
|
||||||
$err=new m_err();
|
$err = new m_err();
|
||||||
$authip=new m_authip();
|
$authip = new m_authip();
|
||||||
$hooks=new m_hooks();
|
$hooks = new m_hooks();
|
||||||
|
|
||||||
/* Check the User identity (if required) */
|
/* Check the User identity (if required) */
|
||||||
if (!defined('NOCHECK')) {
|
if (!defined('NOCHECK')) {
|
||||||
if (!$mem->checkid()) {
|
if (!$mem->checkid()) {
|
||||||
if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
|
if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
|
||||||
header('WWW-Authenticate: Basic realm="AlternC Authentication"');
|
header('WWW-Authenticate: Basic realm="AlternC Authentication"');
|
||||||
header('HTTP/1.0 401 Unauthorized');
|
header('HTTP/1.0 401 Unauthorized');
|
||||||
exit();
|
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']:'');
|
for ($i = 0; $i < count($classes); $i++) {
|
||||||
$isinvited=false;
|
$name2 = $classes[$i];
|
||||||
if ($admin->enabled) $isinvited=true;
|
if (isset($$name2))
|
||||||
|
continue; // for already instancied class like mem, err or authip
|
||||||
if ($oldid && $oldid!=$cuid) {
|
$name1 = "m_" . $name2;
|
||||||
$isinvited=true;
|
$$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
|
// 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
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$Id: config_nochk.php,v 1.2 2004/11/04 06:56:49 anonymous Exp $
|
$Id: config_nochk.php,v 1.2 2004/11/04 06:56:49 anonymous Exp $
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
AlternC - Web Hosting System
|
AlternC - Web Hosting System
|
||||||
Copyright (C) 2002 by the AlternC Development Team.
|
Copyright (C) 2002 by the AlternC Development Team.
|
||||||
http://alternc.org/
|
http://alternc.org/
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Based on:
|
Based on:
|
||||||
Valentin Lacambre's web hosting softwares: http://altern.org/
|
Valentin Lacambre's web hosting softwares: http://altern.org/
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
LICENSE
|
LICENSE
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License (GPL)
|
modify it under the terms of the GNU General Public License (GPL)
|
||||||
as published by the Free Software Foundation; either version 2
|
as published by the Free Software Foundation; either version 2
|
||||||
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
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
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Original Author of file: Benjamin Sonntag
|
Original Author of file: Benjamin Sonntag
|
||||||
Purpose of file: General configuration file for AlternC Desktop
|
Purpose of file: General configuration file for AlternC Desktop
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
define('NOCHECK', 1);
|
define('NOCHECK', 1);
|
||||||
require_once("config.php");
|
require_once("config.php");
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
@ -8,488 +8,441 @@
|
||||||
*
|
*
|
||||||
* $Id: db_mysql.php,v 1.3 2005/03/05 16:27:30 said Exp $
|
* $Id: db_mysql.php,v 1.3 2005/03/05 16:27:30 said Exp $
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class DB_Sql {
|
class DB_Sql {
|
||||||
|
/* public: connection parameters */
|
||||||
/* public: connection parameters */
|
|
||||||
var $Host = "";
|
|
||||||
var $Database = "";
|
|
||||||
var $User = "";
|
|
||||||
var $Password = "";
|
|
||||||
|
|
||||||
/* public: configuration parameters */
|
var $Host = "";
|
||||||
var $Auto_Free = 0; ## Set to 1 for automatic mysql_free_result()
|
var $Database = "";
|
||||||
var $Debug = 0; ## Set to 1 for debugging messages.
|
var $User = "";
|
||||||
var $Halt_On_Error = "no"; ## "yes" (halt with message), "no" (ignore errors quietly), "report" (ignore errror, but spit a warning)
|
var $Password = "";
|
||||||
var $Seq_Table = "db_sequence";
|
|
||||||
|
|
||||||
/* public: result array and current row number */
|
/* public: configuration parameters */
|
||||||
var $Record = array();
|
var $Auto_Free = 0; ## Set to 1 for automatic mysql_free_result()
|
||||||
var $Row;
|
var $Debug = 0; ## Set to 1 for debugging messages.
|
||||||
var $num_rows;
|
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 */
|
/* public: result array and current row number */
|
||||||
var $Errno = 0;
|
var $Record = array();
|
||||||
var $Error = "";
|
var $Row;
|
||||||
|
var $num_rows;
|
||||||
|
|
||||||
/* public: this is an api revision, not a CVS revision. */
|
/* public: current error number and error text */
|
||||||
var $type = "mysql";
|
var $Errno = 0;
|
||||||
var $revision = "1.2";
|
var $Error = "";
|
||||||
|
|
||||||
/* private: link and query handles */
|
/* public: this is an api revision, not a CVS revision. */
|
||||||
var $Link_ID = 0;
|
var $type = "mysql";
|
||||||
var $Query_ID = 0;
|
var $revision = "1.2";
|
||||||
var $Query_String = "";
|
|
||||||
|
|
||||||
|
|
||||||
|
/* private: link and query handles */
|
||||||
|
var $Link_ID = 0;
|
||||||
|
var $Query_ID = 0;
|
||||||
|
var $Query_String = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* 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'])) { ...
|
|
||||||
*/
|
*/
|
||||||
|
function DB_Sql($query = "") {
|
||||||
// if no $table specified, assume that we are working with a query
|
$this->query($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 resource class variable Link_ID
|
||||||
return $res;
|
*/
|
||||||
}
|
function link_id() {
|
||||||
|
return $this->Link_ID;
|
||||||
/********************************************************************************************************/
|
|
||||||
// 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 */
|
* @return integer class variable Query_ID
|
||||||
function halt($msg) {
|
*/
|
||||||
$this->Error = @mysql_error($this->Link_ID);
|
function query_id() {
|
||||||
$this->Errno = @mysql_errno($this->Link_ID);
|
return $this->Query_ID;
|
||||||
if ($this->Halt_On_Error == "no")
|
}
|
||||||
return;
|
|
||||||
|
|
||||||
$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")
|
/* establish connection, select database */
|
||||||
die("Session halted.");
|
if (0 == $this->Link_ID) {
|
||||||
}
|
|
||||||
|
|
||||||
function haltmsg($msg) {
|
$this->Link_ID = mysql_pconnect($Host, $User, $Password);
|
||||||
printf("</td></tr></table><b>Database error:</b> %s<br />\n", $msg);
|
if (!$this->Link_ID) {
|
||||||
printf("<b>MySQL Error</b>: %s (%s)<br />\n",
|
$this->halt("pconnect($Host, $User, \$Password) failed.");
|
||||||
$this->Errno,
|
return 0;
|
||||||
$this->Error);
|
}
|
||||||
}
|
|
||||||
|
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
|
<?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",
|
"fr_FR" => "Français",
|
||||||
"en_US" => "English",
|
"en_US" => "English",
|
||||||
# "es_ES" => "Español",
|
# "es_ES" => "Español",
|
||||||
# "it_IT" => "Italiano",
|
# "it_IT" => "Italiano",
|
||||||
# "de_DE" => "Deutsch",
|
# "de_DE" => "Deutsch",
|
||||||
# "pt_BR" => "Portuguese",
|
# "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
|
$arr_lang_translation = $lang_translation; // not pretty but I don't want side effect right now
|
||||||
|
|
||||||
function update_locale($langpath) {
|
function update_locale($langpath) {
|
||||||
global $arr_lang_translation;
|
global $arr_lang_translation;
|
||||||
$locales=array();
|
$locales = array();
|
||||||
$file=file("/etc/locale.gen", FILE_SKIP_EMPTY_LINES);
|
$file = file("/etc/locale.gen", FILE_SKIP_EMPTY_LINES);
|
||||||
if (! is_array($file) ) return $locales;
|
if (!is_array($file)) {
|
||||||
foreach ($file as $v ) {
|
return $locales;
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
}
|
foreach ($file as $v) {
|
||||||
if (!count($locales)) {
|
if ((preg_match("/^([a-z][a-z]_[A-Z][A-Z])/", trim($v), $mat) && file_exists($langpath . '/' . $mat[1]))) {
|
||||||
$locales=array("en_US"=>"en_US");
|
if (!array_key_exists($mat[1], $arr_lang_translation)) {
|
||||||
}
|
continue;
|
||||||
return $locales;
|
}
|
||||||
|
$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
|
// setlang is on the link at the login page
|
||||||
if (isset($_REQUEST["setlang"])) {
|
if (isset($_REQUEST["setlang"])) {
|
||||||
$lang=$_REQUEST["setlang"];
|
$lang = $_REQUEST["setlang"];
|
||||||
$setlang=$_REQUEST["setlang"];
|
$setlang = $_REQUEST["setlang"];
|
||||||
} elseif (isset($_COOKIE['lang'])) {
|
} elseif (isset($_COOKIE['lang'])) {
|
||||||
$lang=$_COOKIE['lang'];
|
$lang = $_COOKIE['lang'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$langpath = bindtextdomain("alternc", ALTERNC_LOCALES);
|
$langpath = bindtextdomain("alternc", ALTERNC_LOCALES);
|
||||||
|
@ -45,49 +49,50 @@ $locales = update_locale($langpath);
|
||||||
|
|
||||||
// Default to en_US :
|
// Default to en_US :
|
||||||
if (!isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
|
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
|
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.
|
// treat special cases such as en_AU or fr_BF : use the language only, not the country.
|
||||||
$ll=substr($lang,0,2);
|
$ll = substr($lang, 0, 2);
|
||||||
foreach($locales as $l) {
|
foreach ($locales as $l) {
|
||||||
if (substr($l,0,2)==$ll) {
|
if (substr($l, 0, 2) == $ll) {
|
||||||
$lang=$l;
|
$lang = $l;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($locales[$lang])) list($lang)=each($locales);
|
if (!isset($locales[$lang])) {
|
||||||
|
list($lang) = each($locales);
|
||||||
|
}
|
||||||
if (isset($setlang) && isset($lang)) {
|
if (isset($setlang) && isset($lang)) {
|
||||||
setcookie("lang",$lang);
|
setcookie("lang", $lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
// User chose a non existent language, select the first available one
|
// User chose a non existent language, select the first available one
|
||||||
if ($lang == NULL) {
|
if ($lang == NULL) {
|
||||||
$lang = "en_US";
|
$lang = "en_US";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Language ok, set the locale environment */
|
/* Language ok, set the locale environment */
|
||||||
putenv("LC_MESSAGES=".$lang);
|
putenv("LC_MESSAGES=" . $lang);
|
||||||
putenv("LANG=".$lang);
|
putenv("LANG=" . $lang);
|
||||||
putenv("LANGUAGE=".$lang);
|
putenv("LANGUAGE=" . $lang);
|
||||||
// this locale MUST be selected in "dpkg-reconfigure locales"
|
// this locale MUST be selected in "dpkg-reconfigure locales"
|
||||||
setlocale(LC_ALL,$lang);
|
setlocale(LC_ALL, $lang);
|
||||||
textdomain("alternc");
|
textdomain("alternc");
|
||||||
|
|
||||||
$empty="";
|
$empty = "";
|
||||||
if (_($empty) && preg_match("#charset=([A-Za-z0-9\.-]*)#",_($empty),$mat)) {
|
if (_($empty) && preg_match("#charset=([A-Za-z0-9\.-]*)#", _($empty), $mat)) {
|
||||||
$charset=$mat[1];
|
$charset = $mat[1];
|
||||||
}
|
}
|
||||||
if (! isset($charset) || !$charset) $charset="UTF-8";
|
if (!isset($charset) || !$charset) {
|
||||||
bind_textdomain_codeset("alternc","$charset");
|
$charset = "UTF-8";
|
||||||
|
}
|
||||||
?>
|
bind_textdomain_codeset("alternc", "$charset");
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/* Read global variables (AlternC configuration) */
|
/* Read global variables (AlternC configuration) */
|
||||||
$L_VERSION="@@REPLACED_DURING_BUILD@@";
|
$L_VERSION = "@@REPLACED_DURING_BUILD@@";
|
||||||
|
|
||||||
// To be able to have displayer version != help version
|
// To be able to have displayer version != help version
|
||||||
// (usefull during RC, etc...)
|
// (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 */
|
/* To ease the transition, we define a lookup table for old names */
|
||||||
$compat = array('DEFAULT_MX' => 'MX',
|
$compat = array('DEFAULT_MX' => 'MX',
|
||||||
'MYSQL_USER' => 'MYSQL_LOGIN',
|
'MYSQL_USER' => 'MYSQL_LOGIN',
|
||||||
'MYSQL_PASS' => 'MYSQL_PWD',
|
'MYSQL_PASS' => 'MYSQL_PWD',
|
||||||
'NS1_HOSTNAME' => 'NS1',
|
'NS1_HOSTNAME' => 'NS1',
|
||||||
'NS2_HOSTNAME' => 'NS2');
|
'NS2_HOSTNAME' => 'NS2');
|
||||||
|
|
||||||
|
|
||||||
$config_file = fopen('/etc/alternc/local.sh', 'r');
|
$config_file = fopen('/etc/alternc/local.sh', 'r');
|
||||||
while (FALSE !== ($line = fgets($config_file))) {
|
while (FALSE !== ($line = fgets($config_file))) {
|
||||||
if (preg_match('/^([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $regs)) {
|
if (preg_match('/^([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $regs)) {
|
||||||
$GLOBALS['L_'.$regs[1]] = $regs[2];
|
$GLOBALS['L_' . $regs[1]] = $regs[2];
|
||||||
if (isset($compat[$regs[1]])) {
|
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);
|
fclose($config_file);
|
||||||
|
|
||||||
$config_file = fopen('/etc/alternc/my.cnf', 'r');
|
$config_file = fopen('/etc/alternc/my.cnf', 'r');
|
||||||
while (FALSE !== ($line = fgets($config_file))) {
|
while (false!== ($line = fgets($config_file))) {
|
||||||
if (preg_match('/^([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $regs)) {
|
if (preg_match('/^([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $regs)) {
|
||||||
switch ($regs[1]) {
|
switch ($regs[1]) {
|
||||||
case "user":
|
case "user":
|
||||||
$GLOBALS['L_MYSQL_LOGIN'] = $regs[2];
|
$GLOBALS['L_MYSQL_LOGIN'] = $regs[2];
|
||||||
break;
|
break;
|
||||||
case "password":
|
case "password":
|
||||||
$GLOBALS['L_MYSQL_PWD'] = $regs[2];
|
$GLOBALS['L_MYSQL_PWD'] = $regs[2];
|
||||||
break;
|
break;
|
||||||
case "host":
|
case "host":
|
||||||
$GLOBALS['L_MYSQL_HOST'] = $regs[2];
|
$GLOBALS['L_MYSQL_HOST'] = $regs[2];
|
||||||
break;
|
break;
|
||||||
case "database":
|
case "database":
|
||||||
$GLOBALS['L_MYSQL_DATABASE'] = $regs[2];
|
$GLOBALS['L_MYSQL_DATABASE'] = $regs[2];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose($config_file);
|
fclose($config_file);
|
||||||
?>
|
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
class m_action {
|
class m_action {
|
||||||
/* --------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
function m_action() {
|
function m_action() {
|
||||||
|
@ -48,9 +48,9 @@ class m_action {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function do_action() {
|
function do_action() {
|
||||||
global $err, $L_INOTIFY_DO_ACTION;
|
global $err, $L_INOTIFY_DO_ACTION;
|
||||||
$err->log("action", "do_action");
|
$err->log("action", "do_action");
|
||||||
if( ! @touch($L_INOTIFY_DO_ACTION) ){
|
if (!@touch($L_INOTIFY_DO_ACTION)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -77,9 +77,9 @@ class m_action {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function chmod($filename, $perms, $user = "root") {
|
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
|
* 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;";
|
$purge = "select * from actions where TO_DAYS(curdate()) - TO_DAYS(creation) > 2;";
|
||||||
$result = $db->query($purge);
|
$result = $db->query($purge);
|
||||||
if (! $result) {
|
if (!$result) {
|
||||||
$err->raise("action", _("Error selecting old actions"));
|
$err->raise("action", _("Error selecting old actions"));
|
||||||
return false;
|
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;";
|
$purge = "delete from actions where TO_DAYS(curdate()) - TO_DAYS(creation) > 2;";
|
||||||
}
|
}
|
||||||
$result = $db->query($purge);
|
$result = $db->query($purge);
|
||||||
if (! $result) {
|
if (!$result) {
|
||||||
$err->raise("action", _("Error purging old actions"));
|
$err->raise("action", _("Error purging old actions"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return $db->num_rows($result) ;
|
return $db->num_rows($result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -327,7 +326,7 @@ class m_action {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @global m_mysql $db
|
* @global m_mysql $db
|
||||||
|
@ -343,7 +342,7 @@ class m_action {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of actions marked as executable and ready for execution
|
* Returns a list of actions marked as executable and ready for execution
|
||||||
*
|
*
|
||||||
|
@ -352,7 +351,7 @@ class m_action {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function get_job() {
|
function get_job() {
|
||||||
global $db, $err;
|
global $db;
|
||||||
$tab = array();
|
$tab = array();
|
||||||
$db->query("Select * from actions where begin !=0 and end = 0 ;");
|
$db->query("Select * from actions where begin !=0 and end = 0 ;");
|
||||||
if ($db->next_record()) {
|
if ($db->next_record()) {
|
||||||
|
@ -371,7 +370,6 @@ class m_action {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function cancel($id) {
|
function cancel($id) {
|
||||||
global $db;
|
|
||||||
$this->finish($id, 666);
|
$this->finish($id, 666);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,9 +79,9 @@ class m_admin {
|
||||||
*/
|
*/
|
||||||
function hook_menu() {
|
function hook_menu() {
|
||||||
global $mem, $cuid, $debug_alternc, $L_INOTIFY_UPDATE_DOMAIN;
|
global $mem, $cuid, $debug_alternc, $L_INOTIFY_UPDATE_DOMAIN;
|
||||||
if (!$mem->checkRight())
|
if (!$mem->checkRight()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
$obj = array(
|
$obj = array(
|
||||||
'title' => _("Administration"),
|
'title' => _("Administration"),
|
||||||
'ico' => 'images/admin.png',
|
'ico' => 'images/admin.png',
|
||||||
|
@ -343,38 +343,36 @@ class m_admin {
|
||||||
|
|
||||||
$request = 'SELECT compte AS uid FROM domaines WHERE 1';
|
$request = 'SELECT compte AS uid FROM domaines WHERE 1';
|
||||||
|
|
||||||
if ($pattern && preg_match('/[.a-zA-Z0-9]+/', $pattern))
|
if ($pattern && preg_match('/[.a-zA-Z0-9]+/', $pattern)) {
|
||||||
$request .= sprintf(' AND domaine LIKE "%%%s%%"', $pattern);
|
$request .= sprintf(' AND domaine LIKE "%%%s%%"', $pattern);
|
||||||
|
}
|
||||||
if ($creator)
|
if ($creator) {
|
||||||
$request .= sprintf(' AND compte in (select uid from membres where creator = "%s" ) ', $creator);
|
$request .= sprintf(' AND compte in (select uid from membres where creator = "%s" ) ', $creator);
|
||||||
|
}
|
||||||
if ($mem->user['uid'] != 2000 && !$all)
|
if ($mem->user['uid'] != 2000 && !$all) {
|
||||||
$request .= sprintf(' AND compte in (select uid from membres where creator = "%s") ', $cuid);
|
$request .= sprintf(' AND compte in (select uid from membres where creator = "%s") ', $cuid);
|
||||||
|
}
|
||||||
|
|
||||||
$request .= ' GROUP BY uid';
|
$request .= ' GROUP BY uid';
|
||||||
} elseif ($pattern_type === 'login') {
|
} elseif ($pattern_type === 'login') {
|
||||||
|
|
||||||
$request = 'SELECT uid FROM membres WHERE 1';
|
$request = 'SELECT uid FROM membres WHERE 1';
|
||||||
|
|
||||||
if ($pattern && preg_match('/[a-zA-Z0-9]+/', $pattern))
|
if ($pattern && preg_match('/[a-zA-Z0-9]+/', $pattern)) {
|
||||||
$request .= sprintf(' AND login LIKE "%%%s%%"', $pattern);
|
$request .= sprintf(' AND login LIKE "%%%s%%"', $pattern);
|
||||||
|
}
|
||||||
if ($creator)
|
if ($creator) {
|
||||||
$request .= sprintf(' AND creator = "%s"', $creator);
|
$request .= sprintf(' AND creator = "%s"', $creator);
|
||||||
|
}
|
||||||
if ($mem->user['uid'] != 2000 && !$all)
|
if ($mem->user['uid'] != 2000 && !$all) {
|
||||||
$request .= sprintf(' AND creator = "%s"', $cuid);
|
$request .= sprintf(' AND creator = "%s"', $cuid);
|
||||||
|
}
|
||||||
$request .= ' ORDER BY login;';
|
$request .= ' ORDER BY login;';
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$err->raise("admin", _("Invalid pattern type provided. Are you even performing a legitimate action?"));
|
$err->raise("admin", _("Invalid pattern type provided. Are you even performing a legitimate action?"));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if ($creator) {
|
if ($creator) {
|
||||||
// Limit listing to a specific reseller
|
// Limit listing to a specific reseller
|
||||||
$request = "SELECT uid FROM membres WHERE creator='" . $creator . "' ORDER BY login;";
|
$request = "SELECT uid FROM membres WHERE creator='" . $creator . "' ORDER BY login;";
|
||||||
|
@ -411,7 +409,7 @@ class m_admin {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function mailallmembers($subject, $message, $from) {
|
function mailallmembers($subject, $message, $from) {
|
||||||
global $err, $mem, $cuid, $db;
|
global $err, $db;
|
||||||
$err->log("admin", "mailallmembers");
|
$err->log("admin", "mailallmembers");
|
||||||
if (!$this->enabled) {
|
if (!$this->enabled) {
|
||||||
$err->raise("admin", _("-- Only administrators can access this page! --"));
|
$err->raise("admin", _("-- Only administrators can access this page! --"));
|
||||||
|
@ -453,7 +451,7 @@ class m_admin {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function get_creator_list() {
|
function get_creator_list() {
|
||||||
global $err, $mem, $cuid;
|
global $err, $cuid;
|
||||||
|
|
||||||
$creators = array();
|
$creators = array();
|
||||||
|
|
||||||
|
@ -488,7 +486,7 @@ class m_admin {
|
||||||
* @return boolean TRUE if I am the creator of that account. FALSE else.
|
* @return boolean TRUE if I am the creator of that account. FALSE else.
|
||||||
*/
|
*/
|
||||||
function checkcreator($uid) {
|
function checkcreator($uid) {
|
||||||
global $err, $mem, $db, $cuid;
|
global $err, $db, $cuid;
|
||||||
if ($cuid == 2000) {
|
if ($cuid == 2000) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -514,7 +512,7 @@ class m_admin {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function add_shared_domain($u, $domain_name) {
|
function add_shared_domain($u, $domain_name) {
|
||||||
global $db, $err, $dom, $mem, $cuid;
|
global $err, $dom, $mem;
|
||||||
$err->log("admin", "add_shared_domain", $u . "/" . $domain_name);
|
$err->log("admin", "add_shared_domain", $u . "/" . $domain_name);
|
||||||
|
|
||||||
if (!$mem->checkright()) {
|
if (!$mem->checkright()) {
|
||||||
|
@ -575,7 +573,7 @@ class m_admin {
|
||||||
* @return boolean Returns FALSE if an error occurs, TRUE if not.
|
* @return boolean Returns FALSE if an error occurs, TRUE if not.
|
||||||
*/
|
*/
|
||||||
function add_mem($login, $pass, $nom, $prenom, $mail, $canpass = 1, $type = 'default', $duration = 0, $notes = "", $force = 0, $create_dom = '', $db_server_id) {
|
function add_mem($login, $pass, $nom, $prenom, $mail, $canpass = 1, $type = 'default', $duration = 0, $notes = "", $force = 0, $create_dom = '', $db_server_id) {
|
||||||
global $err, $quota, $classes, $cuid, $mem, $L_MYSQL_DATABASE, $L_MYSQL_LOGIN, $hooks, $action;
|
global $err, $cuid, $mem, $L_MYSQL_DATABASE, $L_MYSQL_LOGIN, $hooks, $action;
|
||||||
$err->log("admin", "add_mem", $login . "/" . $mail);
|
$err->log("admin", "add_mem", $login . "/" . $mail);
|
||||||
if (!$this->enabled) {
|
if (!$this->enabled) {
|
||||||
$err->raise("admin", _("-- Only administrators can access this page! --"));
|
$err->raise("admin", _("-- Only administrators can access this page! --"));
|
||||||
|
@ -629,8 +627,9 @@ class m_admin {
|
||||||
$uid = 2000;
|
$uid = 2000;
|
||||||
} else {
|
} else {
|
||||||
$uid = $db->Record["nextid"];
|
$uid = $db->Record["nextid"];
|
||||||
if ($uid <= 2000)
|
if ($uid <= 2000) {
|
||||||
$uid = 2000;
|
$uid = 2000;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$db->query("INSERT INTO membres (uid,login,pass,mail,creator,canpass,type,created,notes,db_server_id) VALUES ('$uid','$login','$pass','$mail','$cuid','$canpass', '$type', NOW(), '$notes', '$db_server_id');");
|
$db->query("INSERT INTO membres (uid,login,pass,mail,creator,canpass,type,created,notes,db_server_id) VALUES ('$uid','$login','$pass','$mail','$cuid','$canpass', '$type', NOW(), '$notes', '$db_server_id');");
|
||||||
$db->query("INSERT INTO local(uid,nom,prenom) VALUES('$uid','$nom','$prenom');");
|
$db->query("INSERT INTO local(uid,nom,prenom) VALUES('$uid','$nom','$prenom');");
|
||||||
|
@ -749,8 +748,7 @@ EOF;
|
||||||
* @return boolean Returns FALSE if an error occurs, TRUE if not
|
* @return boolean Returns FALSE if an error occurs, TRUE if not
|
||||||
*/
|
*/
|
||||||
function update_mem($uid, $mail, $nom, $prenom, $pass, $enabled, $canpass, $type = 'default', $duration = 0, $notes = "", $reset_quotas = false) {
|
function update_mem($uid, $mail, $nom, $prenom, $pass, $enabled, $canpass, $type = 'default', $duration = 0, $notes = "", $reset_quotas = false) {
|
||||||
global $err, $db;
|
global $err, $db, $quota;
|
||||||
global $cuid, $quota;
|
|
||||||
|
|
||||||
$notes = addslashes($notes);
|
$notes = addslashes($notes);
|
||||||
|
|
||||||
|
@ -853,7 +851,7 @@ EOF;
|
||||||
* @return boolean Returns FALSE if an error occurs, TRUE if not.
|
* @return boolean Returns FALSE if an error occurs, TRUE if not.
|
||||||
*/
|
*/
|
||||||
function del_mem($uid) {
|
function del_mem($uid) {
|
||||||
global $err, $quota, $classes, $cuid, $mem, $dom, $hooks, $action;
|
global $err, $mem, $dom, $hooks, $action;
|
||||||
$err->log("admin", "del_mem", $uid);
|
$err->log("admin", "del_mem", $uid);
|
||||||
|
|
||||||
if (!$this->enabled) {
|
if (!$this->enabled) {
|
||||||
|
@ -904,9 +902,9 @@ EOF;
|
||||||
global $err, $db;
|
global $err, $db;
|
||||||
|
|
||||||
$periods = intval($periods);
|
$periods = intval($periods);
|
||||||
if ($periods == 0)
|
if ($periods == 0) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
$query = "UPDATE membres SET renewed = renewed + INTERVAL (duration * $periods) MONTH WHERE uid=${uid};";
|
$query = "UPDATE membres SET renewed = renewed + INTERVAL (duration * $periods) MONTH WHERE uid=${uid};";
|
||||||
if ($db->query($query)) {
|
if ($db->query($query)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -929,12 +927,14 @@ EOF;
|
||||||
global $err, $db;
|
global $err, $db;
|
||||||
|
|
||||||
if ($duration == 0) {
|
if ($duration == 0) {
|
||||||
if ($db->query("UPDATE membres SET duration = NULL, renewed = NULL WHERE uid=$uid;"))
|
if ($db->query("UPDATE membres SET duration = NULL, renewed = NULL WHERE uid=$uid;")) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($db->query("UPDATE membres SET duration = $duration WHERE uid=$uid") &&
|
if ($db->query("UPDATE membres SET duration = $duration WHERE uid=$uid") &&
|
||||||
$db->query("UPDATE membres SET renewed = NOW() WHERE uid=$uid and renewed is null;"))
|
$db->query("UPDATE membres SET renewed = NOW() WHERE uid=$uid and renewed is null;")) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$err->raise("admin", _("Account not found"));
|
$err->raise("admin", _("Account not found"));
|
||||||
|
@ -992,12 +992,13 @@ EOF;
|
||||||
" WHEN m.renewed <= NOW() THEN 2" .
|
" WHEN m.renewed <= NOW() THEN 2" .
|
||||||
" ELSE 1 END 'status' FROM membres m, local l" .
|
" ELSE 1 END 'status' FROM membres m, local l" .
|
||||||
" WHERE m.uid = l.uid" .
|
" WHERE m.uid = l.uid" .
|
||||||
" HAVING status=2 or status=3 ORDER BY status DESC, expiry;"))
|
" HAVING status=2 or status=3 ORDER BY status DESC, expiry;")) {
|
||||||
return false;
|
return false;
|
||||||
else {
|
} else {
|
||||||
$res = array();
|
$res = array();
|
||||||
while ($db->next_record())
|
while ($db->next_record()) {
|
||||||
$res[] = $db->Record;
|
$res[] = $db->Record;
|
||||||
|
}
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1025,7 +1026,6 @@ EOF;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turns a super-admin account into a common account
|
* Turns a super-admin account into a common account
|
||||||
*
|
*
|
||||||
|
@ -1238,8 +1238,9 @@ EOF;
|
||||||
function selecttldmode($current = false) {
|
function selecttldmode($current = false) {
|
||||||
for ($i = 0; $i < count($this->tldmode); $i++) {
|
for ($i = 0; $i < count($this->tldmode); $i++) {
|
||||||
echo "<option value=\"$i\"";
|
echo "<option value=\"$i\"";
|
||||||
if ($current == $i)
|
if ($current == $i) {
|
||||||
echo " selected=\"selected\"";
|
echo " selected=\"selected\"";
|
||||||
|
}
|
||||||
echo ">" . _($this->tldmode[$i]) . "</option>\n";
|
echo ">" . _($this->tldmode[$i]) . "</option>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1294,11 +1295,13 @@ EOF;
|
||||||
$err->raise("admin", _("This TLD already exist"));
|
$err->raise("admin", _("This TLD already exist"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (substr($tld, 0, 1) == ".")
|
if (substr($tld, 0, 1) == ".") {
|
||||||
$tld = substr($tld, 1);
|
$tld = substr($tld, 1);
|
||||||
|
}
|
||||||
$mode = intval($mode);
|
$mode = intval($mode);
|
||||||
if ($mode == 0)
|
if ($mode == 0) {
|
||||||
$mode = "0";
|
$mode = "0";
|
||||||
|
}
|
||||||
$db->query("INSERT INTO tld (tld,mode) VALUES ('$tld','$mode');");
|
$db->query("INSERT INTO tld (tld,mode) VALUES ('$tld','$mode');");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1322,8 +1325,9 @@ EOF;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$mode = intval($mode);
|
$mode = intval($mode);
|
||||||
if ($mode == 0)
|
if ($mode == 0) {
|
||||||
$mode = "0";
|
$mode = "0";
|
||||||
|
}
|
||||||
$db->query("UPDATE tld SET mode='$mode' WHERE tld='$tld';");
|
$db->query("UPDATE tld SET mode='$mode' WHERE tld='$tld';");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1350,7 +1354,7 @@ EOF;
|
||||||
* @return array an indexed array of associative array from the MySQL "policy" table
|
* @return array an indexed array of associative array from the MySQL "policy" table
|
||||||
*/
|
*/
|
||||||
function listPasswordPolicies() {
|
function listPasswordPolicies() {
|
||||||
global $db, $classes, $hooks;
|
global $db, $hooks;
|
||||||
$tmp1 = array();
|
$tmp1 = array();
|
||||||
$tmp2 = array();
|
$tmp2 = array();
|
||||||
$policies = array();
|
$policies = array();
|
||||||
|
@ -1358,16 +1362,6 @@ EOF;
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$tmp1[$db->Record["name"]] = $db->Record;
|
$tmp1[$db->Record["name"]] = $db->Record;
|
||||||
}
|
}
|
||||||
/* * /
|
|
||||||
foreach($classes as $c) {
|
|
||||||
if (method_exists($GLOBALS[$c],"alternc_password_policy")) {
|
|
||||||
$res=$GLOBALS[$c]->alternc_password_policy(); // returns an array
|
|
||||||
foreach($res as $k=>$v) {
|
|
||||||
$tmp2[$k]=$v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* */
|
|
||||||
$tmp3 = $hooks->invoke("alternc_password_policy");
|
$tmp3 = $hooks->invoke("alternc_password_policy");
|
||||||
foreach ($tmp3 as $v) {
|
foreach ($tmp3 as $v) {
|
||||||
foreach ($v as $l => $m) {
|
foreach ($v as $l => $m) {
|
||||||
|
@ -1433,7 +1427,7 @@ EOF;
|
||||||
* @return boolean TRUE if the password if OK for this login and this policy, FALSE if it is not.
|
* @return boolean TRUE if the password if OK for this login and this policy, FALSE if it is not.
|
||||||
*/
|
*/
|
||||||
function checkPolicy($policy, $login, $password) {
|
function checkPolicy($policy, $login, $password) {
|
||||||
global $db, $err;
|
global $err;
|
||||||
|
|
||||||
if (empty($login)) {
|
if (empty($login)) {
|
||||||
$err->raise("admin", _("Please enter a login"));
|
$err->raise("admin", _("Please enter a login"));
|
||||||
|
@ -1468,14 +1462,16 @@ EOF;
|
||||||
$logins = preg_split("/[@_-]/", $login);
|
$logins = preg_split("/[@_-]/", $login);
|
||||||
$logins[] = $login;
|
$logins[] = $login;
|
||||||
foreach ($logins as $l) {
|
foreach ($logins as $l) {
|
||||||
if (!$l) continue;
|
if (!$l) {
|
||||||
if (strpos($password, $l) !== false || strpos($l,$password) !== false) {
|
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"));
|
$err->raise("admin", _("The password policy prevents you to use your login name inside your password or the other way around"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($pol["classcount"] > 0) {
|
if ($pol["classcount"] > 0) {
|
||||||
$cls = array(0, 0, 0, 0, 0);
|
$cls = array(0, 0, 0, 0, 0);
|
||||||
for ($i = 0; $i < strlen($password); $i++) {
|
for ($i = 0; $i < strlen($password); $i++) {
|
||||||
|
|
|
@ -1,178 +1,174 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$Id: mime.php,v 1.3 2004/06/03 14:32:20 anonymous Exp $
|
$Id: mime.php,v 1.3 2004/06/03 14:32:20 anonymous Exp $
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
AlternC - Web Hosting System
|
AlternC - Web Hosting System
|
||||||
Copyright (C) 2002 by the AlternC Development Team.
|
Copyright (C) 2002 by the AlternC Development Team.
|
||||||
http://alternc.org/
|
http://alternc.org/
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Based on:
|
Based on:
|
||||||
Valentin Lacambre's web hosting softwares: http://altern.org/
|
Valentin Lacambre's web hosting softwares: http://altern.org/
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
LICENSE
|
LICENSE
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License (GPL)
|
modify it under the terms of the GNU General Public License (GPL)
|
||||||
as published by the Free Software Foundation; either version 2
|
as published by the Free Software Foundation; either version 2
|
||||||
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
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
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Original Author of file: Benjamin Sonntag 23/12/2001
|
Original Author of file: Benjamin Sonntag 23/12/2001
|
||||||
Purpose of file: Brouteur php3 pour AlternC
|
Purpose of file: Brouteur php3 pour AlternC
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
Brouteur php3 pour AlternC (voir http://www.alternc.org)
|
Brouteur php3 pour AlternC (voir http://www.alternc.org)
|
||||||
|
|
||||||
Version 0.1
|
|
||||||
|
|
||||||
Notes :
|
Version 0.1
|
||||||
Benjamin Sonntag 23/12/2001 Version initiale
|
|
||||||
|
|
||||||
Fichier :
|
|
||||||
mime.php3 : gestion de la liste des types mime des fichiers.
|
|
||||||
|
|
||||||
*/
|
Notes :
|
||||||
|
Benjamin Sonntag 23/12/2001 Version initiale
|
||||||
|
|
||||||
|
Fichier :
|
||||||
|
mime.php3 : gestion de la liste des types mime des fichiers.
|
||||||
|
|
||||||
|
*/
|
||||||
if (!IsSet($MIME_H)) {
|
if (!IsSet($MIME_H)) {
|
||||||
$MIME_H=1;
|
$MIME_H = 1;
|
||||||
|
|
||||||
$bro_mime=
|
$bro_mime = array(
|
||||||
array(
|
"css" => "text/css",
|
||||||
"css" => "text/css",
|
"csv" => "text/comma-separated-values",
|
||||||
"csv" => "text/comma-separated-values",
|
"dia" => "application/x-dia",
|
||||||
"dia" => "application/x-dia",
|
"doc" => "application/msword",
|
||||||
"doc" => "application/msword",
|
"dot" => "application/msword",
|
||||||
"dot" => "application/msword",
|
"epf" => "application/postscript",
|
||||||
"epf" => "application/postscript",
|
"gif" => "image/gif",
|
||||||
"gif" => "image/gif",
|
"hqx" => "application/mac-binhex40",
|
||||||
"hqx" => "application/mac-binhex40",
|
"htm" => "text/html",
|
||||||
"htm" => "text/html",
|
"html" => "text/html",
|
||||||
"html"=> "text/html",
|
"jpeg" => "image/jpeg",
|
||||||
"jpeg" => "image/jpeg",
|
"jpg" => "image/jpeg",
|
||||||
"jpg" => "image/jpeg",
|
"m3u" => "audio/mpegurl",
|
||||||
"m3u" => "audio/mpegurl",
|
"mp3" => "audio/mpeg",
|
||||||
"mp3" => "audio/mpeg",
|
"ogg" => "application/ogg",
|
||||||
"ogg" => "application/ogg",
|
"pdf" => "application/pdf",
|
||||||
"pdf" => "application/pdf",
|
"php" => "text/plain",
|
||||||
"php" => "text/plain",
|
"png" => "image/png",
|
||||||
"png" => "image/png",
|
"pps" => "application/powerpoint",
|
||||||
"pps" => "application/powerpoint",
|
"ppt" => "application/powerpoint",
|
||||||
"ppt" => "application/powerpoint",
|
"ps" => "application/postscript",
|
||||||
"ps" => "application/postscript",
|
"psd" => "image/psd",
|
||||||
"psd" => "image/psd",
|
"ra" => "audio/x-pn-realaudio",
|
||||||
"ra" => "audio/x-pn-realaudio",
|
"ram" => "audio/x-pn-realaudio",
|
||||||
"ram" => "audio/x-pn-realaudio",
|
"rar" => "application/rar",
|
||||||
"rar" => "application/rar",
|
"rm" => "audio/x-pn-realaudio",
|
||||||
"rm" => "audio/x-pn-realaudio",
|
"rtf" => "text/rtf",
|
||||||
"rtf" => "text/rtf",
|
"swf" => "application/x-shockwave-flash",
|
||||||
"swf" => "application/x-shockwave-flash",
|
"sxc" => "application/vnd.sun.xml.calc",
|
||||||
"sxc" => "application/vnd.sun.xml.calc",
|
"sxd" => "application/vnd.sun.xml.draw",
|
||||||
"sxd" => "application/vnd.sun.xml.draw",
|
"sxi" => "application/vnd.sun.xml.impress",
|
||||||
"sxi" => "application/vnd.sun.xml.impress",
|
"sxw" => "application/vnd.sun.xml.writer",
|
||||||
"sxw" => "application/vnd.sun.xml.writer",
|
"tif" => "image/tiff",
|
||||||
"tif" => "image/tiff",
|
"tiff" => "image/tiff",
|
||||||
"tiff" => "image/tiff",
|
"txt" => "text/plain",
|
||||||
"txt" => "text/plain",
|
"vcf" => "text/x-vCard",
|
||||||
"vcf" => "text/x-vCard",
|
"vcs" => "text/x-vCalendar",
|
||||||
"vcs" => "text/x-vCalendar",
|
"xcf" => "image/xcf",
|
||||||
"xcf" => "image/xcf",
|
"xls" => "application/vnd.ms-excel",
|
||||||
"xls" => "application/vnd.ms-excel",
|
"zip" => "application/zip",
|
||||||
"zip" => "application/zip",
|
);
|
||||||
);
|
|
||||||
|
|
||||||
$bro_icon=
|
$bro_icon = array(
|
||||||
array(
|
"css" => "txt",
|
||||||
"css" => "txt",
|
"csv" => "xls",
|
||||||
"csv" => "xls",
|
"dia" => "jpg",
|
||||||
"dia" => "jpg",
|
"doc" => "doc",
|
||||||
"doc" => "doc",
|
"dot" => "doc",
|
||||||
"dot" => "doc",
|
"epf" => "txt",
|
||||||
"epf" => "txt",
|
"gif" => "jpg",
|
||||||
"gif" => "jpg",
|
"hqx" => "exe",
|
||||||
"hqx" => "exe",
|
"htm" => "htm",
|
||||||
"htm" => "htm",
|
"html" => "htm",
|
||||||
"html"=> "htm",
|
"jpeg" => "jpg",
|
||||||
"jpeg" => "jpg",
|
"jpg" => "jpg",
|
||||||
"jpg" => "jpg",
|
"m3u" => "m3u",
|
||||||
"m3u" => "m3u",
|
"mp3" => "wav",
|
||||||
"mp3" => "wav",
|
"ogg" => "wav",
|
||||||
"ogg" => "wav",
|
"pdf" => "pdf",
|
||||||
"pdf" => "pdf",
|
"php" => "php",
|
||||||
"php" => "php",
|
"png" => "jpg",
|
||||||
"png" => "jpg",
|
"pps" => "ppt",
|
||||||
"pps" => "ppt",
|
"ppt" => "ppt",
|
||||||
"ppt" => "ppt",
|
"ps" => "txt",
|
||||||
"ps" => "txt",
|
"psd" => "jpg",
|
||||||
"psd" => "jpg",
|
"ra" => "ra",
|
||||||
"ra" => "ra",
|
"ram" => "ra",
|
||||||
"ram" => "ra",
|
"rar" => "zip",
|
||||||
"rar" => "zip",
|
"rm" => "ra",
|
||||||
"rm" => "ra",
|
"rtf" => "doc",
|
||||||
"rtf" => "doc",
|
"swf" => "swf",
|
||||||
"swf" => "swf",
|
"sxc" => "sxc",
|
||||||
"sxc" => "sxc",
|
"sxd" => "sxd",
|
||||||
"sxd" => "sxd",
|
"sxi" => "sxi",
|
||||||
"sxi" => "sxi",
|
"sxw" => "sxw",
|
||||||
"sxw" => "sxw",
|
"tif" => "jpg",
|
||||||
"tif" => "jpg",
|
"tiff" => "jpg",
|
||||||
"tiff" => "jpg",
|
"txt" => "txt",
|
||||||
"txt" => "txt",
|
"vcf" => "file",
|
||||||
"vcf" => "file",
|
"vcs" => "file",
|
||||||
"vcs" => "file",
|
"xcf" => "jpg",
|
||||||
"xcf" => "jpg",
|
"xls" => "xls",
|
||||||
"xls" => "xls",
|
"zip" => "zip",
|
||||||
"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_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");
|
include("config.php");
|
||||||
|
|
||||||
if (!$admin->enabled) {
|
if (!$admin->enabled) {
|
||||||
__("This page is restricted to authorized staff");
|
__("This page is restricted to authorized staff");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->query("SELECT id,hostname FROM stats;");
|
$db->query("SELECT id,hostname FROM stats;");
|
||||||
$d=array();
|
$d = array();
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$d[]=$db->Record;
|
$d[] = $db->Record;
|
||||||
}
|
}
|
||||||
foreach ($d as $r) {
|
foreach ($d as $r) {
|
||||||
echo "Stats de ".$r[0]." ".$r[1]." <br>\n"; flush();
|
echo "Stats de " . $r[0] . " " . $r[1] . " <br>\n";
|
||||||
$stats->_createconf($r[0],1);
|
flush();
|
||||||
|
$stats->_createconf($r[0], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
@ -2,28 +2,28 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Id: variables.php,v 1.8 2005/04/02 00:26:36 anarcat Exp $
|
* $Id: variables.php,v 1.8 2005/04/02 00:26:36 anarcat Exp $
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
AlternC - Web Hosting System
|
AlternC - Web Hosting System
|
||||||
Copyright (C) 2002 by the AlternC Development Team.
|
Copyright (C) 2002 by the AlternC Development Team.
|
||||||
http://alternc.org/
|
http://alternc.org/
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Based on:
|
Based on:
|
||||||
Valentin Lacambre's web hosting softwares: http://altern.org/
|
Valentin Lacambre's web hosting softwares: http://altern.org/
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
LICENSE
|
LICENSE
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License (GPL)
|
modify it under the terms of the GNU General Public License (GPL)
|
||||||
as published by the Free Software Foundation; either version 2
|
as published by the Free Software Foundation; either version 2
|
||||||
of the License, or (at your option) any later version.
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
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.
|
* file.
|
||||||
*/
|
*/
|
||||||
function variable_init($conf = array()) {
|
function variable_init($conf = array()) {
|
||||||
global $db;
|
global $db;
|
||||||
$result = $db->query('SELECT * FROM `variable`');
|
$result = $db->query('SELECT * FROM `variable`');
|
||||||
while ($db->next_record($result)) {
|
while ($db->next_record($result)) {
|
||||||
/* maybe the data is *not* serialized, in that case, take it verbatim */
|
/* maybe the data is *not* serialized, in that case, take it verbatim */
|
||||||
$variable = $db->Record;
|
$variable = $db->Record;
|
||||||
if (($variables[$variable['name']] = @unserialize($variable['value'])) === FALSE) {
|
if (($variables[$variable['name']] = @unserialize($variable['value'])) === FALSE) {
|
||||||
$variables[$variable['name']] = $variable['value'];
|
$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()
|
* @uses variable_init()
|
||||||
*/
|
*/
|
||||||
function variable_init_maybe() {
|
function variable_init_maybe() {
|
||||||
global $conf;
|
global $conf;
|
||||||
if (!isset($conf)) {
|
if (!isset($conf)) {
|
||||||
$conf = variable_init();
|
$conf = variable_init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,16 +87,16 @@ function variable_init_maybe() {
|
||||||
* A cache of the configuration.
|
* A cache of the configuration.
|
||||||
*/
|
*/
|
||||||
function variable_get($name, $default = null, $createit_comment = null) {
|
function variable_get($name, $default = null, $createit_comment = null) {
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
variable_init_maybe();
|
variable_init_maybe();
|
||||||
|
|
||||||
if (isset($conf[$name])) {
|
if (isset($conf[$name])) {
|
||||||
return $conf[$name];
|
return $conf[$name];
|
||||||
} elseif (!is_null($createit_comment)) {
|
} elseif (!is_null($createit_comment)) {
|
||||||
variable_set($name, $default, $createit_comment);
|
variable_set($name, $default, $createit_comment);
|
||||||
}
|
}
|
||||||
return $default;
|
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
|
* The value to set. This can be any PHP data type; these functions take care
|
||||||
* of serialization as necessary.
|
* of serialization as necessary.
|
||||||
*/
|
*/
|
||||||
function variable_set($name, $value, $comment=null) {
|
function variable_set($name, $value, $comment = null) {
|
||||||
global $conf, $db, $err, $hooks;
|
global $conf, $db, $err, $hooks;
|
||||||
$err->log('variable', 'variable_set', '+'.serialize($value).'+'.$comment.'+');
|
$err->log('variable', 'variable_set', '+' . serialize($value) . '+' . $comment . '+');
|
||||||
|
|
||||||
variable_init_maybe();
|
variable_init_maybe();
|
||||||
|
|
||||||
if (is_object($value) || is_array($value)) {
|
if (is_object($value) || is_array($value)) {
|
||||||
$value2 = serialize($value);
|
$value2 = serialize($value);
|
||||||
}
|
}
|
||||||
if (array_key_exists($name,$conf)) {
|
if (array_key_exists($name, $conf)) {
|
||||||
$previous=$conf[$name];
|
$previous = $conf[$name];
|
||||||
} else {
|
} 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;
|
$conf[$name] = $value;
|
||||||
if ( empty($comment) ) {
|
if (empty($comment)) {
|
||||||
$query = "INSERT INTO variable (name, value) values ('".$name."', '".addslashes($value2)."') on duplicate key update name='$name', value='$value';";
|
$query = "INSERT INTO variable (name, value) values ('" . $name . "', '" . addslashes($value2) . "') on duplicate key update name='$name', value='$value';";
|
||||||
} else {
|
} else {
|
||||||
$comment=mysql_real_escape_string($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';";
|
$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.
|
* The name of the variable to undefine.
|
||||||
*/
|
*/
|
||||||
function variable_del($name) {
|
function variable_del($name) {
|
||||||
global $conf, $db;
|
global $conf, $db;
|
||||||
|
$db->query("DELETE FROM `variable` WHERE name = '" . $name . "'");
|
||||||
$db->query("DELETE FROM `variable` WHERE name = '".$name."'");
|
unset($conf[$name]);
|
||||||
|
|
||||||
unset($conf[$name]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function variables_list() {
|
function variables_list() {
|
||||||
global $db;
|
global $db;
|
||||||
$t=array();
|
$t = array();
|
||||||
$db->query("SELECT * FROM `variable` WHERE `comment` IS NOT NULL ORDER BY `name`");
|
$db->query("SELECT * FROM `variable` WHERE `comment` IS NOT NULL ORDER BY `name`");
|
||||||
while ($db->next_record()) {
|
while ($db->next_record()) {
|
||||||
$t[]=$db->Record;
|
$t[] = $db->Record;
|
||||||
}
|
}
|
||||||
return $t;
|
return $t;
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
Loading…
Reference in New Issue