Skip to content
storage = "sql"
sql = {
driver = "MySQL";
database = "{tmpl_var db_name}";
host = "{tmpl_var db_host}";
port = {tmpl_var db_port};
username = "{tmpl_var db_username}";
password = "{tmpl_var db_password}";
}
\ No newline at end of file
......@@ -98,7 +98,7 @@ if(is_dir('/root/ispconfig') || is_dir('/home/admispconfig')) {
die('This software cannot be installed on a server wich runs ISPConfig 2.x.');
}
// Patch is required to reapir latest amavis versions
// Patch is required to repair latest amavis versions
if(is_installed('amavisd-new') && !is_installed('patch')) die('The patch command is missing. Install patch command and start update again.');
//** Get distribution identifier
......@@ -109,6 +109,7 @@ $conf_old = $conf;
unset($conf);
if($dist['id'] == '') die('Linux distribution or version not recognized.');
if(!$dist['supported']) die('This distribution is not supported.');
//** Include the autoinstaller configuration (for non-interactive setups)
error_reporting(E_ALL ^ E_NOTICE);
......@@ -141,11 +142,18 @@ if(isset($cmd_opt['autoinstall']) && is_file($cmd_opt['autoinstall'])) {
define('AUTOINSTALL', false);
}
//** Include the distribution-specific installer class library and configuration
if(is_file('dist/lib/'.$dist['baseid'].'.lib.php')) include_once 'dist/lib/'.$dist['baseid'].'.lib.php';
include_once 'dist/lib/'.$dist['id'].'.lib.php';
include_once 'dist/conf/'.$dist['confid'].'.conf.php';
$inst = new installer();
if (!$inst->get_php_version()) die('ISPConfig requieres PHP '.$inst->min_php."\n");
$inst->is_update = true;
$inst->raiseEvent('set_dist_config', $dist);
//** tRNG dependencies
$conf['tRNG']='';
......@@ -186,10 +194,6 @@ if(!$conf['mysql']['ip'] = gethostbyname($conf['mysql']['host'])) die('Unable to
$conf['server_id'] = intval($conf_old["server_id"]);
$conf['ispconfig_log_priority'] = $conf_old["log_priority"];
$inst = new installer();
if (!$inst->get_php_version()) die('ISPConfig requieres PHP '.$inst->min_php."\n");
$inst->is_update = true;
echo "This application will update ISPConfig 3 on your server.\n\n";
//* Make a backup before we start the update
......@@ -298,7 +302,9 @@ checkDbHealth();
/*
* dump the new Database and reconfigure the server.ini
*/
$inst->raiseEvent('updateDbAndIni::before');
updateDbAndIni();
$inst->raiseEvent('updateDbAndIni::after');
//** read server config from db into $conf['server_config']
$tmp = $inst->db->queryOneRecord("SELECT config FROM ?? WHERE server_id = ?", $conf["mysql"]["database"] . '.server', $conf['server_id']);
......@@ -320,22 +326,24 @@ if($reconfigure_master_database_rights_answer == 'yes') {
//}
//** Detect the installed applications
$inst->raiseEvent('find_installed_apps::before');
$inst->find_installed_apps();
$inst->raiseEvent('find_installed_apps::after');
//** Check for current service config state and compare to our results
if ($conf['mysql']['master_slave_setup'] == 'y') $current_svc_config = $inst->dbmaster->queryOneRecord("SELECT mail_server,web_server,dns_server,xmpp_server,firewall_server,vserver_server,db_server FROM ?? WHERE server_id=?", $conf['mysql']['master_database'] . '.server', $conf['server_id']);
else $current_svc_config = $inst->db->queryOneRecord("SELECT mail_server,web_server,dns_server,xmpp_server,firewall_server,vserver_server,db_server FROM ?? WHERE server_id=?", $conf["mysql"]["database"] . '.server', $conf['server_id']);
$inst->raiseEvent('check_service_config_state::before');
if ($conf['mysql']['master_slave_setup'] == 'y') $current_svc_config = $inst->dbmaster->queryOneRecord("SELECT mail_server,web_server,dns_server,firewall_server,db_server FROM ?? WHERE server_id=?", $conf['mysql']['master_database'] . '.server', $conf['server_id']);
else $current_svc_config = $inst->db->queryOneRecord("SELECT mail_server,web_server,dns_server,firewall_server,db_server FROM ?? WHERE server_id=?", $conf["mysql"]["database"] . '.server', $conf['server_id']);
$conf['services']['mail'] = check_service_config_state('mail_server', $conf['postfix']['installed']);
$conf['services']['dns'] = check_service_config_state('dns_server', ($conf['powerdns']['installed'] || $conf['bind']['installed'] || $conf['mydns']['installed']));
$conf['services']['web'] = check_service_config_state('web_server', ($conf['apache']['installed'] || $conf['nginx']['installed']));
$conf['services']['xmpp'] = check_service_config_state('xmpp_server', $conf['metronome']['installed']);
$conf['services']['firewall'] = check_service_config_state('firewall_server', ($conf['ufw']['installed'] || $conf['firewall']['installed']));
$conf['services']['vserver'] = check_service_config_state('vserver_server', $conf['services']['vserver']);
$conf['services']['db'] = check_service_config_state('db_server', true); /* Will always offer as MySQL is of course installed on this host as it's a requirement for ISPC to work... */
unset($current_svc_config);
$inst->raiseEvent('check_service_config_state::after');
//** Write new decisions into DB
$sql = "UPDATE ?? SET mail_server = '{$conf['services']['mail']}', web_server = '{$conf['services']['web']}', dns_server = '{$conf['services']['dns']}', file_server = '{$conf['services']['file']}', db_server = '{$conf['services']['db']}', vserver_server = '{$conf['services']['vserver']}', proxy_server = '{$conf['services']['proxy']}', firewall_server = '$firewall_server_enabled', xmpp_server = '$xmpp_server_enabled' WHERE server_id = ?";
$sql = "UPDATE ?? SET mail_server = '{$conf['services']['mail']}', web_server = '{$conf['services']['web']}', dns_server = '{$conf['services']['dns']}', file_server = '{$conf['services']['file']}', db_server = '{$conf['services']['db']}', proxy_server = '{$conf['services']['proxy']}', firewall_server = '$firewall_server_enabled' WHERE server_id = ?";
$inst->db->query($sql, $conf['mysql']['database'].'.server', $conf['server_id']);
if($conf['mysql']['master_slave_setup'] == 'y') {
$inst->dbmaster->query($sql, $conf['mysql']['master_database'].'.server', $conf['server_id']);
......@@ -365,34 +373,10 @@ if($reconfigure_services_answer == 'yes' || $reconfigure_services_answer == 'sel
//* Configure dovecot
swriteln('Configuring Dovecot');
$inst->configure_dovecot();
} elseif ($conf['courier']['installed'] == true) {
//** Configure saslauthd
swriteln('Configuring SASL');
$inst->configure_saslauthd();
//** Configure PAM
swriteln('Configuring PAM');
$inst->configure_pam();
//* Configure courier
swriteln('Configuring Courier');
$inst->configure_courier();
}
}
//** Configure mailman
if($conf['mailman']['installed'] == true && $inst->reconfigure_app('Mailman', $reconfigure_services_answer)) {
swriteln('Configuring Mailman');
$inst->configure_mailman('update');
}
//* Configure mlmmj
if($conf['mlmmj']['installed'] == true && $inst->reconfigure_app('Mlmmj', $reconfigure_services_answer)) {
swriteln('Configuring Mlmmj');
$inst->configure_mlmmj(/*update*/);
}
//** Configure Spamasassin
if($inst->reconfigure_app('Spamassassin', $reconfigure_services_answer)) {
swriteln('Configuring Spamassassin');
......@@ -405,6 +389,12 @@ if($reconfigure_services_answer == 'yes' || $reconfigure_services_answer == 'sel
$inst->configure_amavis();
}
//** Configure Rspamd
if($conf['rspamd']['installed'] == true && $inst->reconfigure_app('Rspamd', $reconfigure_services_answer)) {
swriteln('Configuring Rspamd');
$inst->configure_rspamd();
}
//** Configure Getmail
if ($inst->reconfigure_app('Getmail', $reconfigure_services_answer)) {
swriteln('Configuring Getmail');
......@@ -465,17 +455,6 @@ if($reconfigure_services_answer == 'yes' || $reconfigure_services_answer == 'sel
}
if($conf['services']['xmpp'] && $inst->reconfigure_app('XMPP', $reconfigure_services_answer)) {
//** Configure Metronome XMPP
if($conf['prosody']['installed'] == true) {
swriteln('Configuring Prosody XMPP');
$inst->configure_prosody('dont-create-certs');
} elseif ($conf['metronome']['installed'] == true) {
swriteln('Configuring Metronome XMPP');
$inst->configure_metronome('dont-create-certs');
}
}
if($conf['services']['firewall'] && $inst->reconfigure_app('Firewall', $reconfigure_services_answer)) {
if($conf['ufw']['installed'] == true) {
//* Configure Ubuntu Firewall
......@@ -524,7 +503,16 @@ if ($inst->install_ispconfig_interface) {
}
}
// Create SSL certs for non-webserver(s)?
if(!file_exists('/usr/local/ispconfig/interface/ssl/ispserver.crt')) {
if(strtolower($inst->simple_query('Do you want to create SSL certs for your server?', array('y', 'n'), 'y')) == 'y') {
$inst->make_ispconfig_ssl_cert();
}
}
$inst->raiseEvent('install_ispconfig::before');
$inst->install_ispconfig();
$inst->raiseEvent('install_ispconfig::after');
// Cleanup
$inst->cleanup_ispconfig();
......@@ -542,18 +530,10 @@ if($reconfigure_services_answer == 'yes') {
if($conf['mysql']['installed'] == true && $conf['mysql']['init_script'] != '') system($inst->getinitcommand($conf['mysql']['init_script'], 'restart').' >/dev/null 2>&1');
if($conf['services']['mail']) {
if($conf['postfix']['installed'] == true && $conf['postfix']['init_script'] != '') system($inst->getinitcommand($conf['postfix']['init_script'], 'restart'));
if($conf['saslauthd']['installed'] == true && $conf['saslauthd']['init_script'] != '') system($inst->getinitcommand($conf['saslauthd']['init_script'], 'restart'));
if($conf['amavis']['installed'] == true && $conf['amavis']['init_script'] != '') system($inst->getinitcommand($conf['amavis']['init_script'], 'restart'));
if($conf['rspamd']['installed'] == true && $conf['rspamd']['init_script'] != '') system($inst->getinitcommand($conf['rspamd']['init_script'], 'restart'));
if($conf['clamav']['installed'] == true && $conf['clamav']['init_script'] != '') system($inst->getinitcommand($conf['clamav']['init_script'], 'restart'));
if($conf['courier']['installed'] == true){
if($conf['courier']['courier-authdaemon'] != '') system($inst->getinitcommand($conf['courier']['courier-authdaemon'], 'restart'));
if($conf['courier']['courier-imap'] != '') system($inst->getinitcommand($conf['courier']['courier-imap'], 'restart'));
if($conf['courier']['courier-imap-ssl'] != '') system($inst->getinitcommand($conf['courier']['courier-imap-ssl'], 'restart'));
if($conf['courier']['courier-pop'] != '') system($inst->getinitcommand($conf['courier']['courier-pop'], 'restart'));
if($conf['courier']['courier-pop-ssl'] != '') system($inst->getinitcommand($conf['courier']['courier-pop-ssl'], 'restart'));
}
if($conf['dovecot']['installed'] == true && $conf['dovecot']['init_script'] != '') system($inst->getinitcommand($conf['dovecot']['init_script'], 'restart'));
if($conf['mailman']['installed'] == true && $conf['mailman']['init_script'] != '') system('nohup '.$inst->getinitcommand($conf['mailman']['init_script'], 'restart').' >/dev/null 2>&1 &');
}
if($conf['services']['web'] || $inst->install_ispconfig_interface) {
if($conf['webserver']['server_type'] == 'apache' && $conf['apache']['init_script'] != '') system($inst->getinitcommand($conf['apache']['init_script'], 'restart'));
......@@ -570,11 +550,7 @@ if($reconfigure_services_answer == 'yes') {
if($conf['bind']['installed'] == true && $conf['bind']['init_script'] != '') system($inst->getinitcommand($conf['bind']['init_script'], 'restart').' &> /dev/null');
}
if($conf['services']['xmpp']) {
if($conf['metronome']['installed'] == true && $conf['metronome']['init_script'] != '') system($inst->getinitcommand($conf['metronome']['init_script'], 'restart').' &> /dev/null');
}
if($conf['services']['proxy']) {
if($conf['services']['proxy']) {
// if($conf['squid']['installed'] == true && $conf['squid']['init_script'] != '' && is_executable($conf['init_scripts'].'/'.$conf['squid']['init_script'])) system($conf['init_scripts'].'/'.$conf['squid']['init_script'].' restart &> /dev/null');
if($conf['nginx']['installed'] == true && $conf['nginx']['init_script'] != '') system($inst->getinitcommand($conf['nginx']['init_script'], 'restart').' &> /dev/null');
}
......
......@@ -62,7 +62,11 @@ class app {
$this->_conf = $conf;
if($this->_conf['start_db'] == true) {
$this->load('db_'.$this->_conf['db_type']);
$this->db = new db;
try {
$this->db = new db;
} catch (Exception $e) {
$this->db = false;
}
}
//* Start the session
......@@ -191,14 +195,14 @@ class app {
/*
if (is_writable($this->_conf['log_file'])) {
if (!$fp = fopen ($this->_conf['log_file'], 'a')) {
$this->error('Unable to open logfile.');
$this->error('Unable to open logfile: ' . $this->_conf['log_file']);
}
if (!fwrite($fp, date('d.m.Y-H:i').' - '. $msg."\r\n")) {
$this->error('Unable to write to logfile.');
$this->error('Unable to write to logfile: ' . $this->_conf['log_file']);
}
fclose($fp);
} else {
$this->error('Unable to write to logfile.');
$this->error('Unable to write to logfile: ' . $this->_conf['log_file']);
}
*/
}
......
......@@ -188,6 +188,36 @@ class auth {
}
/**
* Get the minimum password length.
*/
public function get_min_password_length() {
global $app;
$server_config_array = $app->getconf->get_global_config();
$min_password_length = 8;
if(isset($server_config_array['misc']['min_password_length'])) $min_password_length = $server_config_array['misc']['min_password_length'];
return $min_password_length;
}
/**
* Get the minimum password strength.
*/
public function get_min_password_strength() {
global $app;
$server_config_array = $app->getconf->get_global_config();
$min_password_strength = 0;
if(isset($server_config_array['misc']['min_password_strength'])) $min_password_strength = $server_config_array['misc']['min_password_strength'];;
return $min_password_strength;
}
/**
* Generate a ranmdom password.
*
* @param int $minLength
* Minimum number of characters.
* @param boolean $special
* Include special characters, like # and !
*/
public function get_random_password($minLength = 8, $special = false) {
if($minLength < 8) $minLength = 8;
$maxLength = $minLength + 5;
......
......@@ -136,12 +136,6 @@ class custom_datasource {
case 'default_dbserver':
$field = 'db_server';
break;
case 'default_xmppserver':
$field = 'xmpp_server';
break;
case 'default_vserverserver':
$field = 'vserver_server';
break;
case 'mail_servers':
$field = 'mail_server';
break;
......@@ -154,9 +148,6 @@ class custom_datasource {
case 'db_servers':
$field = 'db_server';
break;
case 'xmpp_servers':
$field = 'xmpp_server';
break;
default:
$field = 'web_server';
break;
......
<?php
/*
* db_mysql.inc.php: ISPConfig mysql db interface
*
* Note! When making changes to this file, put a copy in both locations:
* interface/lib/classes/db_mysql.inc.php
* server/lib/classes/db_mysql.inc.php
*/
/*
Copyright (c) 2005, Till Brehm, projektfarm Gmbh
All rights reserved.
......@@ -27,7 +35,8 @@
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class db {
class db
{
/**#@+
* @access private
*/
......@@ -40,12 +49,10 @@ class db {
private $dbUser = ''; // database authorized user
private $dbPass = ''; // user's password
private $dbCharset = 'utf8';// Database charset
private $dbNewLink = false; // Return a new linkID when connect is called again
private $dbClientFlags = 0; // MySQL Client falgs
/**#@-*/
public $show_error_messages = false; // false in server, true in interface
public $show_error_messages = false; // false in server, interface sets true when generating templates
/* old things - unused now ////
private $linkId = 0; // last result of mysqli_connect()
......@@ -53,8 +60,8 @@ class db {
private $record = array(); // last record fetched
private $autoCommit = 1; // Autocommit Transactions
private $currentRow; // current row number
private $errorNumber = 0; // last error number
*/
public $errorNumber = 0; // last error number
public $errorMessage = ''; // last error message
/*
private $errorLocation = '';// last error location
......@@ -63,34 +70,38 @@ class db {
*/
// constructor
public function __construct($prefix = '') {
global $conf;
if($prefix != '') $prefix .= '_';
$this->dbHost = $conf[$prefix.'db_host'];
$this->dbPort = $conf[$prefix.'db_port'];
$this->dbName = $conf[$prefix.'db_database'];
$this->dbUser = $conf[$prefix.'db_user'];
$this->dbPass = $conf[$prefix.'db_password'];
$this->dbCharset = $conf[$prefix.'db_charset'];
$this->dbNewLink = $conf[$prefix.'db_new_link'];
$this->dbClientFlags = $conf[$prefix.'db_client_flags'];
public function __construct($host = NULL , $user = NULL, $pass = NULL, $database = NULL, $port = NULL, $flags = NULL) {
global $app, $conf;
$this->dbHost = $host ? $host : $conf['db_host'];
$this->dbPort = $port ? $port : $conf['db_port'];
$this->dbName = $database ? $database : $conf['db_database'];
$this->dbUser = $user ? $user : $conf['db_user'];
$this->dbPass = $pass ? $pass : $conf['db_password'];
$this->dbCharset = $conf['db_charset'];
$this->dbClientFlags = ($flags !== NULL) ? $flags : $conf['db_client_flags'];
$this->_iConnId = mysqli_init();
mysqli_real_connect($this->_iConnId, $this->dbHost, $this->dbUser, $this->dbPass, '', (int)$this->dbPort, NULL, $this->dbClientFlags);
for($try=0;(!is_object($this->_iConnId) || mysqli_connect_error()) && $try < 5;++$try) {
for($try=0;(!is_object($this->_iConnId) || mysqli_connect_errno()) && $try < 5;++$try) {
sleep($try);
mysqli_real_connect($this->_iConnId, $this->dbHost, $this->dbUser, $this->dbPass, '', (int)$this->dbPort, NULL, $this->dbClientFlags);
if(!is_object($this->_iConnId)) {
$this->_iConnId = mysqli_init();
}
if(!mysqli_real_connect($this->_iConnId, $this->dbHost, $this->dbUser, $this->dbPass, '', (int)$this->dbPort, NULL, $this->dbClientFlags)) {
$this->_sqlerror('Database connection failed');
}
}
if(!is_object($this->_iConnId) || mysqli_connect_error()) {
if(!is_object($this->_iConnId) || mysqli_connect_errno()) {
$this->_iConnId = null;
$this->_sqlerror('Zugriff auf Datenbankserver fehlgeschlagen! / Database server not accessible!');
return false;
$this->_sqlerror('Zugriff auf Datenbankserver fehlgeschlagen! / Database server not accessible!', '', true); // sets errorMessage
throw new Exception($this->errorMessage);
}
if(!((bool)mysqli_query( $this->_iConnId, 'USE `' . $this->dbName . '`'))) {
$this->close();
$this->_sqlerror('Datenbank nicht gefunden / Database not found');
return false;
$this->_sqlerror('Datenbank nicht gefunden / Database not found', '', true); // sets errorMessage
throw new Exception($this->errorMessage);
}
$this->_setCharset();
......@@ -105,6 +116,23 @@ class db {
$this->_iConnId = null;
}
/*
* Test mysql connection.
*
* @return boolean returns true if db connection is good.
*/
public function testConnection() {
if(mysqli_connect_errno()) {
return false;
}
return (boolean)(is_object($this->_iConnId) && mysqli_ping($this->_iConnId));
}
/* This allows our private variables to be "read" out side of the class */
public function __get($var) {
return isset($this->$var) ? $this->$var : NULL;
}
public function _build_query_string($sQuery = '') {
$iArgs = func_num_args();
if($iArgs > 1) {
......@@ -127,7 +155,7 @@ class db {
if($iPos2 !== false && ($iPos === false || $iPos2 <= $iPos)) {
$sTxt = $this->escape($sValue);
$sTxt = str_replace('`', '', $sTxt);
if(strpos($sTxt, '.') !== false) {
$sTxt = preg_replace('/^(.+)\.(.+)$/', '`$1`.`$2`', $sTxt);
......@@ -169,33 +197,33 @@ class db {
/**#@+
* @access private
*/
* @access private
*/
private function _setCharset() {
mysqli_query($this->_iConnId, 'SET NAMES '.$this->dbCharset);
mysqli_query($this->_iConnId, "SET character_set_results = '".$this->dbCharset."', character_set_client = '".$this->dbCharset."', character_set_connection = '".$this->dbCharset."', character_set_database = '".$this->dbCharset."', character_set_server = '".$this->dbCharset."'");
$this->query('SET NAMES '.$this->dbCharset);
$this->query("SET character_set_results = '".$this->dbCharset."', character_set_client = '".$this->dbCharset."', character_set_connection = '".$this->dbCharset."', character_set_database = '".$this->dbCharset."', character_set_server = '".$this->dbCharset."'");
}
private function securityScan($string) {
global $app, $conf;
// get security config
if(isset($app)) {
$app->uses('getconf');
$ids_config = $app->getconf->get_security_config('ids');
if($ids_config['sql_scan_enabled'] == 'yes') {
// Remove whitespace
$string = trim($string);
if(substr($string,-1) == ';') $string = substr($string,0,-1);
// Save original string
$string_orig = $string;
//echo $string;
$chars = array(';', '#', '/*', '*/', '--', '\\\'', '\\"');
$string = str_replace('\\\\', '', $string);
$string = preg_replace('/(^|[^\\\])([\'"])\\2/is', '$1', $string);
$string = preg_replace('/(^|[^\\\])([\'"])(.*?[^\\\])\\2/is', '$1', $string);
......@@ -239,14 +267,28 @@ class db {
$try = 0;
do {
$try++;
$ok = mysqli_ping($this->_iConnId);
$ok = (is_object($this->_iConnId)) ? mysqli_ping($this->_iConnId) : false;
if(!$ok) {
if(!mysqli_real_connect(mysqli_init(), $this->dbHost, $this->dbUser, $this->dbPass, $this->dbName, (int)$this->dbPort, NULL, $this->dbClientFlags)) {
if($try > 4) {
$this->_sqlerror('DB::query -> reconnect');
if(!is_object($this->_iConnId)) {
$this->_iConnId = mysqli_init();
}
if(!mysqli_real_connect($this->_isConnId, $this->dbHost, $this->dbUser, $this->dbPass, $this->dbName, (int)$this->dbPort, NULL, $this->dbClientFlags)) {
if(mysqli_connect_errno() == '111') {
// server is not available
if($try > 9) {
if(isset($app) && isset($app->forceErrorExit)) {
$app->forceErrorExit('Database connection failure!');
}
// if we reach this, the app object is missing or has no exit method, so we continue as normal
}
sleep(30); // additional seconds, please!
}
if($try > 9) {
$this->_sqlerror('db::_query -> reconnect', '', true);
return false;
} else {
sleep(1);
sleep(($try > 7 ? 5 : 1));
}
} else {
$this->_setCharset();
......@@ -258,7 +300,7 @@ class db {
$aArgs = func_get_args();
$sQuery = call_user_func_array(array(&$this, '_build_query_string'), $aArgs);
$this->securityScan($sQuery);
$this->_iQueryId = @mysqli_query($this->_iConnId, $sQuery);
$this->_iQueryId = mysqli_query($this->_iConnId, $sQuery);
if (!$this->_iQueryId) {
$this->_sqlerror('Falsche Anfrage / Wrong Query', 'SQL-Query = ' . $sQuery);
return false;
......@@ -390,7 +432,7 @@ class db {
}
public function query_all_array($sQuery = '') {
return $this->queryAllArray($sQuery);
return call_user_func_array(array(&$this, 'queryAllArray'), func_get_args());
}
......@@ -404,13 +446,14 @@ class db {
* @return int id of last inserted row or 0 if none
*/
public function insert_id() {
$iRes = mysqli_query($this->_iConnId, 'SELECT LAST_INSERT_ID() as `newid`');
if(!is_object($iRes)) return false;
$aReturn = mysqli_fetch_assoc($iRes);
mysqli_free_result($iRes);
return $aReturn['newid'];
$oResult = $this->query('SELECT LAST_INSERT_ID() as `newid`');
if(!$oResult) {
$this->_sqlerror('Unable to select last_insert_id()');
return false;
}
$aReturn = $oResult->get();
$oResult->free();
return isset($aReturn['newid']) ? $aReturn['newid'] : 0;
}
......@@ -431,6 +474,7 @@ class db {
}
/**
* check if a utf8 string is valid
*
......@@ -470,7 +514,7 @@ class db {
public function escape($sString) {
global $app;
if(!is_string($sString) && !is_numeric($sString)) {
$app->log('NON-String given in escape function! (' . gettype($sString) . ')', LOGLEVEL_DEBUG);
$app->log('NON-String given in escape function! (' . gettype($sString) . ')', LOGLEVEL_INFO);
//$sAddMsg = getDebugBacktrace();
$app->log($sAddMsg, LOGLEVEL_DEBUG);
$sString = '';
......@@ -479,7 +523,7 @@ class db {
$cur_encoding = mb_detect_encoding($sString);
if($cur_encoding != "UTF-8") {
if($cur_encoding != 'ASCII') {
if(is_object($app) && method_exists($app, 'log')) $app->log('String ' . substr($sString, 0, 25) . '... is ' . $cur_encoding . '.', LOGLEVEL_DEBUG);
if(is_object($app) && method_exists($app, 'log')) $app->log('String ' . substr($sString, 0, 25) . '... is ' . $cur_encoding . '.', LOGLEVEL_INFO);
if($cur_encoding) $sString = mb_convert_encoding($sString, 'UTF-8', $cur_encoding);
else $sString = mb_convert_encoding($sString, 'UTF-8');
}
......@@ -496,20 +540,27 @@ class db {
*
* @access private
*/
private function _sqlerror($sErrormsg = 'Unbekannter Fehler', $sAddMsg = '') {
private function _sqlerror($sErrormsg = 'Unbekannter Fehler', $sAddMsg = '', $bNoLog = false) {
global $app, $conf;
$mysql_error = (is_object($this->_iConnId) ? mysqli_error($this->_iConnId) : mysqli_connect_error());
$mysql_errno = (is_object($this->_iConnId) ? mysqli_errno($this->_iConnId) : mysqli_connect_errno());
$mysql_errno = mysqli_connect_errno();
$mysql_error = mysqli_connect_error();
if ($mysql_errno === 0 && is_object($this->_iConnId)) {
$mysql_errno = mysqli_errno($this->_iConnId);
$mysql_error = mysqli_error($this->_iConnId);
}
$this->errorNumber = $mysql_error;
$this->errorMessage = $mysql_error;
//$sAddMsg .= getDebugBacktrace();
if($this->show_error_messages && $conf['demo_mode'] === false) {
echo $sErrormsg . $sAddMsg;
} else if(is_object($app) && method_exists($app, 'log')) {
$app->log($sErrormsg . $sAddMsg . ' -> ' . $mysql_errno . ' (' . $mysql_error . ')', LOGLEVEL_WARN);
}
} elseif(is_object($app) && method_exists($app, 'log') && $bNoLog == false) {
$app->log($sErrormsg . $sAddMsg . ' -> ' . $mysql_errno . ' (' . $mysql_error . ')', LOGLEVEL_WARN, false);
} elseif(php_sapi_name() == 'cli') {
echo $sErrormsg . $sAddMsg;
}
}
public function affectedRows() {
......@@ -541,27 +592,27 @@ class db {
}
return $out;
}
public function insertFromArray($tablename, $data) {
if(!is_array($data)) return false;
$k_query = '';
$v_query = '';
$params = array($tablename);
$v_params = array();
foreach($data as $key => $value) {
$k_query .= ($k_query != '' ? ', ' : '') . '??';
$v_query .= ($v_query != '' ? ', ' : '') . '?';
$params[] = $key;
$v_params[] = $value;
}
$query = 'INSERT INTO ?? (' . $k_query . ') VALUES (' . $v_query . ')';
return $this->query($query, true, array_merge($params, $v_params));
}
public function diffrec($record_old, $record_new) {
$diffrec_full = array();
$diff_num = 0;
......@@ -597,15 +648,47 @@ class db {
}
/**
* Function to get the database-size
* @param string $database_name
* @return int - database-size in bytes
*/
public function getDatabaseSize($database_name) {
global $app, $conf;
static $db=null;
if ( ! $db ) {
$clientdb_host = ($conf['db_host']) ? $conf['db_host'] : NULL;
$clientdb_user = ($conf['db_user']) ? $conf['db_user'] : NULL;
$clientdb_password = ($conf['db_password']) ? $conf['db_password'] : NULL;
$clientdb_port = ((int)$conf['db_port']) ? (int)$conf['db_port'] : NULL;
$clientdb_flags = ($conf['db_flags'] !== NULL) ? $conf['db_flags'] : NULL;
require_once 'lib/mysql_clientdb.conf';
$db = new db($clientdb_host, $clientdb_user, $clientdb_password, NULL, $clientdb_port, $clientdb_flags);
}
$result = $db->_query("SELECT SUM(data_length+index_length) FROM information_schema.TABLES WHERE table_schema='".$db->escape($database_name)."'");
if(!$result) {
$db->_sqlerror('Unable to determine the size of database ' . $database_name);
return;
}
$database_size = $result->getAsRow();
$result->free();
return $database_size[0] ? $database_size[0] : 0;
}
//** Function to fill the datalog with a full differential record.
public function datalogSave($db_table, $action, $primary_field, $primary_id, $record_old, $record_new, $force_update = false) {
global $app, $conf;
global $app;
// Check fields
if(!preg_match('/^[a-zA-Z0-9\-\_\.]{1,64}$/',$db_table)) $app->error('Invalid table name '.$db_table);
if(!preg_match('/^[a-zA-Z0-9\-\_]{1,64}$/',$primary_field)) $app->error('Invalid primary field '.$primary_field.' in table '.$db_table);
$primary_id = intval($primary_id);
// Insert backticks only for incomplete table names.
if(stristr($db_table, '.')) {
$escape = '';
} else {
$escape = '`';
}
if($force_update == true) {
//* We force a update even if no record has changed
......@@ -625,18 +708,19 @@ class db {
if($diff_num > 0) {
//print_r($diff_num);
//print_r($diffrec_full);
$diffstr = serialize($diffrec_full);
$username = $_SESSION['s']['user']['username'];
if(isset($_SESSION)) {
$username = $_SESSION['s']['user']['username'];
} else {
$username = 'admin';
}
$dbidx = $primary_field.':'.$primary_id;
if(trim($username) == '') $username = 'none';
if($action == 'INSERT') $action = 'i';
if($action == 'UPDATE') $action = 'u';
if($action == 'DELETE') $action = 'd';
$sql = "INSERT INTO sys_datalog (dbtable,dbidx,server_id,action,tstamp,user,data) VALUES (?, ?, ?, ?, ?, ?, ?)";
$app->db->query($sql, $db_table, $dbidx, $server_id, $action, time(), $username, $diffstr);
$sql = "INSERT INTO sys_datalog (dbtable,dbidx,server_id,action,tstamp,user,data,session_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
$app->db->query($sql, $db_table, $dbidx, $server_id, $action, time(), $username, $diffstr, session_id());
}
return true;
......@@ -645,11 +729,11 @@ class db {
//** Inserts a record and saves the changes into the datalog
public function datalogInsert($tablename, $insert_data, $index_field) {
global $app;
// Check fields
if(!preg_match('/^[a-zA-Z0-9\-\_\.]{1,64}$/',$tablename)) $app->error('Invalid table name '.$tablename);
if(!preg_match('/^[a-zA-Z0-9\-\_]{1,64}$/',$index_field)) $app->error('Invalid index field '.$index_field.' in table '.$tablename);
if(is_array($insert_data)) {
$key_str = '';
$val_str = '';
......@@ -675,6 +759,9 @@ class db {
$old_rec = array();
$index_value = $this->insertID();
if(!$index_value && isset($insert_data[$index_field])) {
$index_value = $insert_data[$index_field];
}
$new_rec = $this->queryOneRecord("SELECT * FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value);
$this->datalogSave($tablename, 'INSERT', $index_field, $index_value, $old_rec, $new_rec);
......@@ -688,7 +775,7 @@ class db {
// Check fields
if(!preg_match('/^[a-zA-Z0-9\-\_\.]{1,64}$/',$tablename)) $app->error('Invalid table name '.$tablename);
if(!preg_match('/^[a-zA-Z0-9\-\_]{1,64}$/',$index_field)) $app->error('Invalid index field '.$index_field.' in table '.$tablename);
$old_rec = $this->queryOneRecord("SELECT * FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value);
if(is_array($update_data)) {
......@@ -723,7 +810,7 @@ class db {
// Check fields
if(!preg_match('/^[a-zA-Z0-9\-\_\.]{1,64}$/',$tablename)) $app->error('Invalid table name '.$tablename);
if(!preg_match('/^[a-zA-Z0-9\-\_]{1,64}$/',$index_field)) $app->error('Invalid index field '.$index_field.' in table '.$tablename);
$old_rec = $this->queryOneRecord("SELECT * FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value);
$this->query("DELETE FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value);
$new_rec = array();
......@@ -732,13 +819,20 @@ class db {
return true;
}
//** Deletes a record and saves the changes into the datalog
public function datalogError($errormsg) {
global $app;
if(isset($app->modules->current_datalog_id) && $app->modules->current_datalog_id > 0) $this->query("UPDATE sys_datalog set error = ? WHERE datalog_id = ?", $errormsg, $app->modules->current_datalog_id);
return true;
}
//* get the current datalog status for the specified login (or currently logged in user)
public function datalogStatus($login = '') {
global $app;
$return = array('count' => 0, 'entries' => array());
//if($_SESSION['s']['user']['typ'] == 'admin') return $return; // these information should not be displayed to admin users
// removed in favor of new non intrusive datalogstatus notification header
if($login == '' && isset($_SESSION['s']['user'])) {
$login = $_SESSION['s']['user']['username'];
......@@ -747,14 +841,24 @@ class db {
$result = $this->queryAllRecords("SELECT COUNT( * ) AS cnt, sys_datalog.action, sys_datalog.dbtable FROM sys_datalog, server WHERE server.server_id = sys_datalog.server_id AND sys_datalog.user = ? AND sys_datalog.datalog_id > server.updated GROUP BY sys_datalog.dbtable, sys_datalog.action", $login);
foreach($result as $row) {
if(!$row['dbtable'] || in_array($row['dbtable'], array('aps_instances', 'aps_instances_settings', 'mail_access', 'mail_content_filter'))) continue; // ignore some entries, maybe more to come
$return['entries'][] = array('table' => $row['dbtable'], 'action' => $row['action'], 'count' => $row['cnt'], 'text' => $app->lng('datalog_status_' . $row['action'] . '_' . $row['dbtable']));
$return['count'] += $row['cnt'];
$return['entries'][] = array('table' => $row['dbtable'], 'action' => $row['action'], 'count' => $row['cnt'], 'text' => $app->lng('datalog_status_' . $row['action'] . '_' . $row['dbtable'])); $return['count'] += $row['cnt'];
}
unset($result);
return $return;
}
public function freeResult($query)
{
if(is_object($query) && (get_class($query) == "mysqli_result")) {
$query->free();
return true;
} else {
return false;
}
}
/*
$columns = array(action => add | alter | drop
name => Spaltenname
......@@ -879,15 +983,6 @@ class db {
if($rows = $app->db->queryAllRecords('SHOW FIELDS FROM ??', $table_name)){
foreach($rows as $row) {
/*
$name = $row[0];
$default = $row[4];
$key = $row[3];
$extra = $row[5];
$isnull = $row[2];
$type = $row[1];
*/
$name = $row['Field'];
$default = $row['Default'];
$key = $row['Key'];
......@@ -988,7 +1083,7 @@ class db {
return 'char';
break;
case 'varchar':
if($typeValue < 1) die('Database failure: Lenght required for these data types.');
if($typeValue < 1) die('Database failure: Length required for these data types.');
return 'varchar('.$typeValue.')';
break;
case 'text':
......
<?php
/**
* FINE granularity DIFF
*
* Computes a set of instructions to convert the content of
* one string into another.
*
* Copyright (c) 2011 Raymond Hill (http://raymondhill.net/blog/?p=441)
*
* Licensed under The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @copyright Copyright 2011 (c) Raymond Hill (http://raymondhill.net/blog/?p=441)
* @link http://www.raymondhill.net/finediff/
* @version 0.6
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Usage (simplest):
*
* include 'finediff.php';
*
* // for the stock stack, granularity values are:
* // FineDiff::$paragraphGranularity = paragraph/line level
* // FineDiff::$sentenceGranularity = sentence level
* // FineDiff::$wordGranularity = word level
* // FineDiff::$characterGranularity = character level [default]
*
* $opcodes = FineDiff::getDiffOpcodes($from_text, $to_text [, $granularityStack = null] );
* // store opcodes for later use...
*
* ...
*
* // restore $to_text from $from_text + $opcodes
* include 'finediff.php';
* $to_text = FineDiff::renderToTextFromOpcodes($from_text, $opcodes);
*
* ...
*/
/**
* Persisted opcodes (string) are a sequence of atomic opcode.
* A single opcode can be one of the following:
* c | c{n} | d | d{n} | i:{c} | i{length}:{s}
* 'c' = copy one character from source
* 'c{n}' = copy n characters from source
* 'd' = skip one character from source
* 'd{n}' = skip n characters from source
* 'i:{c} = insert character 'c'
* 'i{n}:{s}' = insert string s, which is of length n
*
* Do not exist as of now, under consideration:
* 'm{n}:{o} = move n characters from source o characters ahead.
* It would be essentially a shortcut for a delete->copy->insert
* command (swap) for when the inserted segment is exactly the same
* as the deleted one, and with only a copy operation in between.
* TODO: How often this case occurs? Is it worth it? Can only
* be done as a postprocessing method (->optimize()?)
*/
abstract class FineDiffOp {
abstract public function getFromLen();
abstract public function getToLen();
abstract public function getOpcode();
}
class FineDiffDeleteOp extends FineDiffOp {
public function __construct($len) {
$this->fromLen = $len;
}
public function getFromLen() {
return $this->fromLen;
}
public function getToLen() {
return 0;
}
public function getOpcode() {
if ( $this->fromLen === 1 ) {
return 'd';
}
return "d{$this->fromLen}";
}
}
class FineDiffInsertOp extends FineDiffOp {
public function __construct($text) {
$this->text = $text;
}
public function getFromLen() {
return 0;
}
public function getToLen() {
return strlen($this->text);
}
public function getText() {
return $this->text;
}
public function getOpcode() {
$to_len = strlen($this->text);
if ( $to_len === 1 ) {
return "i:{$this->text}";
}
return "i{$to_len}:{$this->text}";
}
}
class FineDiffReplaceOp extends FineDiffOp {
public function __construct($fromLen, $text) {
$this->fromLen = $fromLen;
$this->text = $text;
}
public function getFromLen() {
return $this->fromLen;
}
public function getToLen() {
return strlen($this->text);
}
public function getText() {
return $this->text;
}
public function getOpcode() {
if ( $this->fromLen === 1 ) {
$del_opcode = 'd';
}
else {
$del_opcode = "d{$this->fromLen}";
}
$to_len = strlen($this->text);
if ( $to_len === 1 ) {
return "{$del_opcode}i:{$this->text}";
}
return "{$del_opcode}i{$to_len}:{$this->text}";
}
}
class FineDiffCopyOp extends FineDiffOp {
public function __construct($len) {
$this->len = $len;
}
public function getFromLen() {
return $this->len;
}
public function getToLen() {
return $this->len;
}
public function getOpcode() {
if ( $this->len === 1 ) {
return 'c';
}
return "c{$this->len}";
}
public function increase($size) {
return $this->len += $size;
}
}
/**
* FineDiff ops
*
* Collection of ops
*/
class FineDiffOps {
public function appendOpcode($opcode, $from, $from_offset, $from_len) {
if ( $opcode === 'c' ) {
$edits[] = new FineDiffCopyOp($from_len);
}
else if ( $opcode === 'd' ) {
$edits[] = new FineDiffDeleteOp($from_len);
}
else /* if ( $opcode === 'i' ) */ {
$edits[] = new FineDiffInsertOp(substr($from, $from_offset, $from_len));
}
}
public $edits = array();
}
/**
* FineDiff class
*
* TODO: Document
*
*/
class FineDiff {
/**------------------------------------------------------------------------
*
* Public section
*
*/
/**
* Constructor
* ...
* The $granularityStack allows FineDiff to be configurable so that
* a particular stack tailored to the specific content of a document can
* be passed.
*/
public function __construct($from_text = '', $to_text = '', $granularityStack = null) {
// setup stack for generic text documents by default
$this->granularityStack = $granularityStack ? $granularityStack : FineDiff::$characterGranularity;
$this->edits = array();
$this->from_text = $from_text;
$this->doDiff($from_text, $to_text);
}
public function getOps() {
return $this->edits;
}
public function getOpcodes() {
$opcodes = array();
foreach ( $this->edits as $edit ) {
$opcodes[] = $edit->getOpcode();
}
return implode('', $opcodes);
}
public function renderDiffToHTML() {
$in_offset = 0;
ob_start();
foreach ( $this->edits as $edit ) {
$n = $edit->getFromLen();
if ( $edit instanceof FineDiffCopyOp ) {
FineDiff::renderDiffToHTMLFromOpcode('c', $this->from_text, $in_offset, $n);
}
else if ( $edit instanceof FineDiffDeleteOp ) {
FineDiff::renderDiffToHTMLFromOpcode('d', $this->from_text, $in_offset, $n);
}
else if ( $edit instanceof FineDiffInsertOp ) {
FineDiff::renderDiffToHTMLFromOpcode('i', $edit->getText(), 0, $edit->getToLen());
}
else /* if ( $edit instanceof FineDiffReplaceOp ) */ {
FineDiff::renderDiffToHTMLFromOpcode('d', $this->from_text, $in_offset, $n);
FineDiff::renderDiffToHTMLFromOpcode('i', $edit->getText(), 0, $edit->getToLen());
}
$in_offset += $n;
}
return ob_get_clean();
}
/**------------------------------------------------------------------------
* Return an opcodes string describing the diff between a "From" and a
* "To" string
*/
public static function getDiffOpcodes($from, $to, $granularities = null) {
$diff = new FineDiff($from, $to, $granularities);
return $diff->getOpcodes();
}
/**------------------------------------------------------------------------
* Return an iterable collection of diff ops from an opcodes string
*/
public static function getDiffOpsFromOpcodes($opcodes) {
$diffops = new FineDiffOps();
FineDiff::renderFromOpcodes(null, $opcodes, array($diffops,'appendOpcode'));
return $diffops->edits;
}
/**------------------------------------------------------------------------
* Re-create the "To" string from the "From" string and an "Opcodes" string
*/
public static function renderToTextFromOpcodes($from, $opcodes) {
ob_start();
FineDiff::renderFromOpcodes($from, $opcodes, array('FineDiff','renderToTextFromOpcode'));
return ob_get_clean();
}
/**------------------------------------------------------------------------
* Render the diff to an HTML string -- UTF8 unsafe
*/
public static function renderDiffToHTMLFromOpcodes($from, $opcodes) {
ob_start();
FineDiff::renderFromOpcodes($from, $opcodes, array('FineDiff','renderDiffToHTMLFromOpcode'));
return ob_get_clean();
}
/**------------------------------------------------------------------------
* Render the diff to an HTML string -- UTF8 safe
*/
public static function renderUTF8DiffToHTMLFromOpcodes($from, $opcodes) {
ob_start();
FineDiff::renderUTF8FromOpcode($from, $opcodes, array('FineDiff','renderDiffToHTMLFromOpcode'));
return ob_get_clean();
}
/**------------------------------------------------------------------------
* Generic opcodes parser, user must supply callback for handling
* single opcode
*/
public static function renderFromOpcodes($from, $opcodes, $callback) {
if ( !is_callable($callback) ) {
return;
}
$opcodes_len = strlen($opcodes);
$from_offset = $opcodes_offset = 0;
while ( $opcodes_offset < $opcodes_len ) {
$opcode = substr($opcodes, $opcodes_offset, 1);
$opcodes_offset++;
$n = intval(substr($opcodes, $opcodes_offset));
if ( $n ) {
$opcodes_offset += strlen(strval($n));
}
else {
$n = 1;
}
if ( $opcode === 'c' ) { // copy n characters from source
call_user_func($callback, 'c', $from, $from_offset, $n, '');
$from_offset += $n;
}
else if ( $opcode === 'd' ) { // delete n characters from source
call_user_func($callback, 'd', $from, $from_offset, $n, '');
$from_offset += $n;
}
else /* if ( $opcode === 'i' ) */ { // insert n characters from opcodes
call_user_func($callback, 'i', $opcodes, $opcodes_offset + 1, $n);
$opcodes_offset += 1 + $n;
}
}
}
/**------------------------------------------------------------------------
* Generic opcodes parser, user must supply callback for handling
* single opcode
*/
private static function renderUTF8FromOpcode($from, $opcodes, $callback) {
if ( !is_callable($callback) ) {
return;
}
$from_len = strlen($from);
$opcodes_len = strlen($opcodes);
$from_offset = $opcodes_offset = 0;
$last_to_chars = '';
while ( $opcodes_offset < $opcodes_len ) {
$opcode = substr($opcodes, $opcodes_offset, 1);
$opcodes_offset++;
$n = intval(substr($opcodes, $opcodes_offset));
if ( $n ) {
$opcodes_offset += strlen(strval($n));
}
else {
$n = 1;
}
if ( $opcode === 'c' || $opcode === 'd' ) {
$beg = $from_offset;
$end = $from_offset + $n;
while ( $beg > 0 && (ord($from[$beg]) & 0xC0) === 0x80 ) { $beg--; }
while ( $end < $from_len && (ord($from[$end]) & 0xC0) === 0x80 ) { $end++; }
if ( $opcode === 'c' ) { // copy n characters from source
call_user_func($callback, 'c', $from, $beg, $end - $beg, '');
$last_to_chars = substr($from, $beg, $end - $beg);
}
else /* if ( $opcode === 'd' ) */ { // delete n characters from source
call_user_func($callback, 'd', $from, $beg, $end - $beg, '');
}
$from_offset += $n;
}
else /* if ( $opcode === 'i' ) */ { // insert n characters from opcodes
$opcodes_offset += 1;
if ( strlen($last_to_chars) > 0 && (ord($opcodes[$opcodes_offset]) & 0xC0) === 0x80 ) {
$beg = strlen($last_to_chars) - 1;
while ( $beg > 0 && (ord($last_to_chars[$beg]) & 0xC0) === 0x80 ) { $beg--; }
$prefix = substr($last_to_chars, $beg);
} else {
$prefix = '';
}
$end = $from_offset;
while ( $end < $from_len && (ord($from[$end]) & 0xC0) === 0x80 ) { $end++; }
$toInsert = $prefix . substr($opcodes, $opcodes_offset, $n) . substr($from, $end, $end - $from_offset);
call_user_func($callback, 'i', $toInsert, 0, strlen($toInsert));
$opcodes_offset += $n;
$last_to_chars = $toInsert;
}
}
}
/**
* Stock granularity stacks and delimiters
*/
const paragraphDelimiters = "\n\r";
public static $paragraphGranularity = array(
FineDiff::paragraphDelimiters
);
const sentenceDelimiters = ".\n\r";
public static $sentenceGranularity = array(
FineDiff::paragraphDelimiters,
FineDiff::sentenceDelimiters
);
const wordDelimiters = " \t.\n\r";
public static $wordGranularity = array(
FineDiff::paragraphDelimiters,
FineDiff::sentenceDelimiters,
FineDiff::wordDelimiters
);
const characterDelimiters = "";
public static $characterGranularity = array(
FineDiff::paragraphDelimiters,
FineDiff::sentenceDelimiters,
FineDiff::wordDelimiters,
FineDiff::characterDelimiters
);
public static $textStack = array(
".",
" \t.\n\r",
""
);
/**------------------------------------------------------------------------
*
* Private section
*
*/
/**
* Entry point to compute the diff.
*/
private function doDiff($from_text, $to_text) {
$this->last_edit = false;
$this->stackpointer = 0;
$this->from_text = $from_text;
$this->from_offset = 0;
// can't diff without at least one granularity specifier
if ( empty($this->granularityStack) ) {
return;
}
$this->_processGranularity($from_text, $to_text);
}
/**
* This is the recursive function which is responsible for
* handling/increasing granularity.
*
* Incrementally increasing the granularity is key to compute the
* overall diff in a very efficient way.
*/
private function _processGranularity($from_segment, $to_segment) {
$delimiters = $this->granularityStack[$this->stackpointer++];
$has_next_stage = $this->stackpointer < count($this->granularityStack);
foreach ( FineDiff::doFragmentDiff($from_segment, $to_segment, $delimiters) as $fragment_edit ) {
// increase granularity
if ( $fragment_edit instanceof FineDiffReplaceOp && $has_next_stage ) {
$this->_processGranularity(
substr($this->from_text, $this->from_offset, $fragment_edit->getFromLen()),
$fragment_edit->getText()
);
}
// fuse copy ops whenever possible
else if ( $fragment_edit instanceof FineDiffCopyOp && $this->last_edit instanceof FineDiffCopyOp ) {
$this->edits[count($this->edits)-1]->increase($fragment_edit->getFromLen());
$this->from_offset += $fragment_edit->getFromLen();
}
else {
/* $fragment_edit instanceof FineDiffCopyOp */
/* $fragment_edit instanceof FineDiffDeleteOp */
/* $fragment_edit instanceof FineDiffInsertOp */
$this->edits[] = $this->last_edit = $fragment_edit;
$this->from_offset += $fragment_edit->getFromLen();
}
}
$this->stackpointer--;
}
/**
* This is the core algorithm which actually perform the diff itself,
* fragmenting the strings as per specified delimiters.
*
* This function is naturally recursive, however for performance purpose
* a local job queue is used instead of outright recursivity.
*/
private static function doFragmentDiff($from_text, $to_text, $delimiters) {
// Empty delimiter means character-level diffing.
// In such case, use code path optimized for character-level
// diffing.
if ( empty($delimiters) ) {
return FineDiff::doCharDiff($from_text, $to_text);
}
$result = array();
// fragment-level diffing
$from_text_len = strlen($from_text);
$to_text_len = strlen($to_text);
$from_fragments = FineDiff::extractFragments($from_text, $delimiters);
$to_fragments = FineDiff::extractFragments($to_text, $delimiters);
$jobs = array(array(0, $from_text_len, 0, $to_text_len));
$cached_array_keys = array();
while ( $job = array_pop($jobs) ) {
// get the segments which must be diff'ed
list($from_segment_start, $from_segment_end, $to_segment_start, $to_segment_end) = $job;
// catch easy cases first
$from_segment_length = $from_segment_end - $from_segment_start;
$to_segment_length = $to_segment_end - $to_segment_start;
if ( !$from_segment_length || !$to_segment_length ) {
if ( $from_segment_length ) {
$result[$from_segment_start * 4] = new FineDiffDeleteOp($from_segment_length);
}
else if ( $to_segment_length ) {
$result[$from_segment_start * 4 + 1] = new FineDiffInsertOp(substr($to_text, $to_segment_start, $to_segment_length));
}
continue;
}
// find longest copy operation for the current segments
$best_copy_length = 0;
$from_base_fragment_index = $from_segment_start;
$cached_array_keys_for_current_segment = array();
while ( $from_base_fragment_index < $from_segment_end ) {
$from_base_fragment = $from_fragments[$from_base_fragment_index];
$from_base_fragment_length = strlen($from_base_fragment);
// performance boost: cache array keys
if ( !isset($cached_array_keys_for_current_segment[$from_base_fragment]) ) {
if ( !isset($cached_array_keys[$from_base_fragment]) ) {
$to_all_fragment_indices = $cached_array_keys[$from_base_fragment] = array_keys($to_fragments, $from_base_fragment, true);
}
else {
$to_all_fragment_indices = $cached_array_keys[$from_base_fragment];
}
// get only indices which falls within current segment
if ( $to_segment_start > 0 || $to_segment_end < $to_text_len ) {
$to_fragment_indices = array();
foreach ( $to_all_fragment_indices as $to_fragment_index ) {
if ( $to_fragment_index < $to_segment_start ) { continue; }
if ( $to_fragment_index >= $to_segment_end ) { break; }
$to_fragment_indices[] = $to_fragment_index;
}
$cached_array_keys_for_current_segment[$from_base_fragment] = $to_fragment_indices;
}
else {
$to_fragment_indices = $to_all_fragment_indices;
}
}
else {
$to_fragment_indices = $cached_array_keys_for_current_segment[$from_base_fragment];
}
// iterate through collected indices
foreach ( $to_fragment_indices as $to_base_fragment_index ) {
$fragment_index_offset = $from_base_fragment_length;
// iterate until no more match
for (;;) {
$fragment_from_index = $from_base_fragment_index + $fragment_index_offset;
if ( $fragment_from_index >= $from_segment_end ) {
break;
}
$fragment_to_index = $to_base_fragment_index + $fragment_index_offset;
if ( $fragment_to_index >= $to_segment_end ) {
break;
}
if ( $from_fragments[$fragment_from_index] !== $to_fragments[$fragment_to_index] ) {
break;
}
$fragment_length = strlen($from_fragments[$fragment_from_index]);
$fragment_index_offset += $fragment_length;
}
if ( $fragment_index_offset > $best_copy_length ) {
$best_copy_length = $fragment_index_offset;
$best_from_start = $from_base_fragment_index;
$best_to_start = $to_base_fragment_index;
}
}
$from_base_fragment_index += strlen($from_base_fragment);
// If match is larger than half segment size, no point trying to find better
// TODO: Really?
if ( $best_copy_length >= $from_segment_length / 2) {
break;
}
// no point to keep looking if what is left is less than
// current best match
if ( $from_base_fragment_index + $best_copy_length >= $from_segment_end ) {
break;
}
}
if ( $best_copy_length ) {
$jobs[] = array($from_segment_start, $best_from_start, $to_segment_start, $best_to_start);
$result[$best_from_start * 4 + 2] = new FineDiffCopyOp($best_copy_length);
$jobs[] = array($best_from_start + $best_copy_length, $from_segment_end, $best_to_start + $best_copy_length, $to_segment_end);
}
else {
$result[$from_segment_start * 4 ] = new FineDiffReplaceOp($from_segment_length, substr($to_text, $to_segment_start, $to_segment_length));
}
}
ksort($result, SORT_NUMERIC);
return array_values($result);
}
/**
* Perform a character-level diff.
*
* The algorithm is quite similar to doFragmentDiff(), except that
* the code path is optimized for character-level diff -- strpos() is
* used to find out the longest common subequence of characters.
*
* We try to find a match using the longest possible subsequence, which
* is at most the length of the shortest of the two strings, then incrementally
* reduce the size until a match is found.
*
* I still need to study more the performance of this function. It
* appears that for long strings, the generic doFragmentDiff() is more
* performant. For word-sized strings, doCharDiff() is somewhat more
* performant.
*/
private static function doCharDiff($from_text, $to_text) {
$result = array();
$jobs = array(array(0, strlen($from_text), 0, strlen($to_text)));
while ( $job = array_pop($jobs) ) {
// get the segments which must be diff'ed
list($from_segment_start, $from_segment_end, $to_segment_start, $to_segment_end) = $job;
$from_segment_len = $from_segment_end - $from_segment_start;
$to_segment_len = $to_segment_end - $to_segment_start;
// catch easy cases first
if ( !$from_segment_len || !$to_segment_len ) {
if ( $from_segment_len ) {
$result[$from_segment_start * 4 + 0] = new FineDiffDeleteOp($from_segment_len);
}
else if ( $to_segment_len ) {
$result[$from_segment_start * 4 + 1] = new FineDiffInsertOp(substr($to_text, $to_segment_start, $to_segment_len));
}
continue;
}
if ( $from_segment_len >= $to_segment_len ) {
$copy_len = $to_segment_len;
while ( $copy_len ) {
$to_copy_start = $to_segment_start;
$to_copy_start_max = $to_segment_end - $copy_len;
while ( $to_copy_start <= $to_copy_start_max ) {
$from_copy_start = strpos(substr($from_text, $from_segment_start, $from_segment_len), substr($to_text, $to_copy_start, $copy_len));
if ( $from_copy_start !== false ) {
$from_copy_start += $from_segment_start;
break 2;
}
$to_copy_start++;
}
$copy_len--;
}
}
else {
$copy_len = $from_segment_len;
while ( $copy_len ) {
$from_copy_start = $from_segment_start;
$from_copy_start_max = $from_segment_end - $copy_len;
while ( $from_copy_start <= $from_copy_start_max ) {
$to_copy_start = strpos(substr($to_text, $to_segment_start, $to_segment_len), substr($from_text, $from_copy_start, $copy_len));
if ( $to_copy_start !== false ) {
$to_copy_start += $to_segment_start;
break 2;
}
$from_copy_start++;
}
$copy_len--;
}
}
// match found
if ( $copy_len ) {
$jobs[] = array($from_segment_start, $from_copy_start, $to_segment_start, $to_copy_start);
$result[$from_copy_start * 4 + 2] = new FineDiffCopyOp($copy_len);
$jobs[] = array($from_copy_start + $copy_len, $from_segment_end, $to_copy_start + $copy_len, $to_segment_end);
}
// no match, so delete all, insert all
else {
$result[$from_segment_start * 4] = new FineDiffReplaceOp($from_segment_len, substr($to_text, $to_segment_start, $to_segment_len));
}
}
ksort($result, SORT_NUMERIC);
return array_values($result);
}
/**
* Efficiently fragment the text into an array according to
* specified delimiters.
* No delimiters means fragment into single character.
* The array indices are the offset of the fragments into
* the input string.
* A sentinel empty fragment is always added at the end.
* Careful: No check is performed as to the validity of the
* delimiters.
*/
private static function extractFragments($text, $delimiters) {
// special case: split into characters
if ( empty($delimiters) ) {
$chars = str_split($text, 1);
$chars[strlen($text)] = '';
return $chars;
}
$fragments = array();
$start = $end = 0;
for (;;) {
$end += strcspn($text, $delimiters, $end);
$end += strspn($text, $delimiters, $end);
if ( $end === $start ) {
break;
}
$fragments[$start] = substr($text, $start, $end - $start);
$start = $end;
}
$fragments[$start] = '';
return $fragments;
}
/**
* Stock opcode renderers
*/
private static function renderToTextFromOpcode($opcode, $from, $from_offset, $from_len) {
if ( $opcode === 'c' || $opcode === 'i' ) {
echo substr($from, $from_offset, $from_len);
}
}
private static function renderDiffToHTMLFromOpcode($opcode, $from, $from_offset, $from_len) {
if ( $opcode === 'c' ) {
echo htmlspecialchars(substr($from, $from_offset, $from_len));
}
else if ( $opcode === 'd' ) {
$deletion = substr($from, $from_offset, $from_len);
if ( strcspn($deletion, " \n\r") === 0 ) {
$deletion = str_replace(array("\n","\r"), array('\n','\r'), $deletion);
}
echo '<del>', htmlspecialchars($deletion), '</del>';
}
else /* if ( $opcode === 'i' ) */ {
echo '<ins>', htmlspecialchars(substr($from, $from_offset, $from_len)), '</ins>';
}
}
}
......@@ -232,12 +232,6 @@ class functions {
}
}
$results = $app->db->queryAllRecords("SELECT ip_address AS ip FROM openvz_ip");
if(!empty($results) && is_array($results)){
foreach($results as $result){
if(preg_match($regex, $result['ip'])) $ips[] = $result['ip'];
}
}
$results = $groupid != 1 ? $app->db->queryAllRecords("SELECT rr.data AS server_ip, rr.name as server_name, soa.origin as domain FROM dns_rr as rr, dns_soa as soa WHERE (rr.type = 'A' OR rr.type = 'AAAA') AND soa.id = rr.zone AND rr.sys_groupid = ?", $groupid) : $results = $app->db->queryAllRecords("SELECT rr.data AS server_ip, rr.name as server_name, soa.origin as domain FROM dns_rr as rr, dns_soa as soa WHERE (rr.type = 'A' OR rr.type = 'AAAA') AND soa.id = rr.zone");
if(!empty($results) && is_array($results)){
......@@ -259,6 +253,12 @@ class functions {
}
}
}
$tmp_ips = $app->plugin->raiseEvent('get_server_ips', 0, true);
if(is_array($tmp_ips) && !empty($tmp_ips)) {
$ips = array_merge($ips, $tmp_ips);
}
$results = $groupid != 1 ? $app->db->queryAllRecords("SELECT database_name as name,remote_ips as ip FROM web_database WHERE remote_ips != '' AND sys_groupid = ?", $groupid) : $results = $app->db->queryAllRecords("SELECT database_name as name,remote_ips as ip FROM web_database WHERE remote_ips != ''");
......@@ -513,6 +513,29 @@ class functions {
return $out;
}
// Function to check paths before we use it as include. Use with absolute paths only.
public function check_include_path($path) {
if(strpos($path,'//') !== false) die('Include path seems to be an URL: '.$this->htmlentities($path));
if(strpos($path,'..') !== false) die('Two dots are not allowed in include path: '.$this->htmlentities($path));
if(!preg_match("/^[a-zA-Z0-9_\/\.\-]+$/", $path)) die('Wrong chars in include path: '.$this->htmlentities($path));
$path = realpath($path);
if($path == '') die('Include path does not exist.');
if(substr($path,0,strlen(ISPC_ROOT_PATH)) != ISPC_ROOT_PATH) die('Path '.$this->htmlentities($path).' is outside of ISPConfig installation directory.');
return $path;
}
// Function to check language strings
public function check_language($language) {
global $app;
if(preg_match('/^[a-z]{2}$/',$language)) {
return $language;
} else {
$app->log('Wrong language string: '.$this->htmlentities($language),1);
return 'en';
}
}
}
?>
......@@ -430,6 +430,9 @@ class ispcmail {
if($text == true && $html == false && $attach == false) {
// only text
$content_type = 'text/plain; charset="' . strtolower($this->mail_charset) . '"';
if($this->mail_charset == 'UTF-8') {
$this->headers['Content-Transfer-Encoding'] = '8bit';
}
$textonly = true;
} elseif($text == true && $html == false && $attach == true) {
// text and attachment
......@@ -440,6 +443,9 @@ class ispcmail {
} elseif($html == true && $text == false && $attach == false) {
// html only (or text too)
$content_type = 'text/html; charset="' . strtolower($this->mail_charset) . '"';
if($this->mail_charset == 'UTF-8') {
$this->headers['Content-Transfer-Encoding'] = '8bit';
}
$htmlonly = true;
} elseif($html == true && $attach == true) {
// html and attachments
......@@ -564,17 +570,14 @@ class ispcmail {
* @access private
*/
private function _encodeSubject($input, $charset = 'ISO-8859-1') {
/*
if($charset == 'UTF-8' && function_exists('imap_8bit')) {
$input = "=?utf-8?Q?" . imap_8bit($input) . "?=";
} else {
preg_match_all('/(\s?\w*[\x80-\xFF]+\w*\s?)/', $input, $matches);
foreach ($matches[1] as $value) {
$replacement = preg_replace('/([\x20\x80-\xFF])/e', '"=" . strtoupper(dechex(ord("\1")))', $value);
$input = str_replace($value, '=?' . $charset . '?Q?' . $replacement . '?=', $input);
if(preg_match('/(?:[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})/s', $input)) {
// needs encoding
if(function_exists('imap_8bit')) {
$input = "=?utf-8?Q?" . str_replace("?","=3F", imap_8bit($input)) . "?=";
} else {
$input = '=?utf-8?B?' . base64_encode($input) . '?=';
}
}*/
$input='=?UTF-8?B?'.base64_encode($input).'?=';
}
return $input;
}
......@@ -744,32 +747,22 @@ class ispcmail {
}
if($this->use_smtp == true) {
if(!$this->_logged_in || !$this->_smtp_conn) {
$result = $this->_smtp_login();
if(!$result) return false;
}
$bcc_cc_sent = false;
foreach($recipients as $recipname => $recip) {
if($this->_sent_mails >= $this->smtp_max_mails) {
// close connection to smtp and reconnect
$this->_sent_mails = 0;
$this->_smtp_close();
$result = $this->_smtp_login();
if(!$result) return false;
}
$this->_sent_mails += 1;
// Build mail headers, content etc.
$m_recipients = array();
$m_mail_content = '';
$recipname = trim(str_replace('"', '', $recipname));
$recip = $this->_encodeHeader($recip, $this->mail_charset);
$recipname = $this->_encodeHeader($recipname, $this->mail_charset);
//Email From
fputs($this->_smtp_conn, 'MAIL FROM: <' . $this->_mail_sender . '>' . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
$m_from = $this->_mail_sender;
//Email To
fputs($this->_smtp_conn, 'RCPT TO: <' . $recip . '>' . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
$m_recipients[] = $recip;
if($bcc_cc_sent == false) {
$add_recips = array();
......@@ -777,17 +770,12 @@ class ispcmail {
if($this->getHeader('Bcc') != '') $add_recips = array_merge($add_recips, $this->_extract_names($this->getHeader('Bcc')));
foreach($add_recips as $add_recip) {
if(!$add_recip['mail']) continue;
fputs($this->_smtp_conn, 'RCPT TO: <' . $this->_encodeHeader($add_recip['mail'], $this->mail_charset) . '>' . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
$m_recipients[] = $this->_encodeHeader($add_recip['mail'], $this->mail_charset);
}
unset($add_recips);
$bcc_cc_sent = true;
}
//The Email
fputs($this->_smtp_conn, 'DATA' . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
//Construct Headers
if($recipname && !is_numeric($recipname)) $this->setHeader('To', $recipname . ' <' . $recip . '>');
else $this->setHeader('To', $recip);
......@@ -797,10 +785,32 @@ class ispcmail {
if($this->getHeader('Cc') != '') $mail_content .= 'Cc: ' . $this->_encodeHeader($this->getHeader('Cc'), $this->mail_charset) . $this->_crlf;
$mail_content .= implode($this->_crlf, $headers) . $this->_crlf . ($this->_is_signed == false ? $this->_crlf : '') . $this->body;
fputs($this->_smtp_conn, $mail_content . $this->_crlf . '.' . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
$m_mail_content = $mail_content;
// Attempt SMTP login:
if(!$this->_logged_in || !$this->_smtp_conn) {
$result = $this->_smtp_login();
}
if($this->_sent_mails >= $this->smtp_max_mails) {
// close connection to smtp and reconnect
$this->_sent_mails = 0;
$this->_smtp_close();
$result = $this->_smtp_login();
}
$this->_sent_mails += 1;
// Send mail or queue it
if ($result) {
$this->send_smtp($m_from, $m_recipients, $m_mail_content);
} else {
$this->add_to_queue($m_from, $m_recipients, $m_mail_content);
}
// hopefully message was correctly sent or queued now
// hopefully message was correctly sent now
$result = true;
}
} else {
......@@ -828,7 +838,87 @@ class ispcmail {
return $result;
}
/**
* Send all mails in queue (usually called from cron)
*/
public function send_queue() {
global $app;
$mails = $app->db->queryAllRecords('SELECT * FROM sys_mailqueue');
if (is_array($mails)) {
foreach ($mails as $mail) {
// Open SMTP connections if not open:
if(!$this->_logged_in || !$this->_smtp_conn) {
$result = $this->_smtp_login();
}
if($this->_sent_mails >= $this->smtp_max_mails) {
// close connection to smtp and reconnect
$this->_sent_mails = 0;
$this->_smtp_close();
$result = $this->_smtp_login();
}
$this->_sent_mails += 1;
if (!$result) {
return false;
}
// Send mail:
$id = $mail['id'];
$from = $mail['from_address'];
$recipients = explode("\n", $mail['recipients']);
$mail_content = $mail['mail_content'];
$this->send_smtp($from, $recipients, $mail_content);
// Delete from queue:
$app->db->query('DELETE FROM sys_mailqueue WHERE id = ?', $id);
}
}
}
/**
* Send mail via SMTP
*/
private function send_smtp($from, $recipients, $mail_content) {
// from:
fputs($this->_smtp_conn, 'MAIL FROM: <' . $from . '>' . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
// recipients (To, Cc or Bcc):
foreach ($recipients as $recipient) {
fputs($this->_smtp_conn, 'RCPT TO: <' . $recipient . '>' . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
}
// mail content:
fputs($this->_smtp_conn, 'DATA' . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
fputs($this->_smtp_conn, $mail_content . $this->_crlf . '.' . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
// hopefully message was correctly sent now
$result = true;
return $result;
}
/**
* Add mail to queue for sending later
*/
private function add_to_queue($from, $recipients, $mail_content) {
global $app;
$app->db->query('INSERT INTO `sys_mailqueue` (`from_address`, `recipients`, `mail_content`) VALUES (?,?,?)', $from, implode("\n", $recipients), $mail_content);
}
/**
* Close mail connections
......
......@@ -115,11 +115,17 @@ class ISPConfigJSONHandler {
try {
$this->_return_json('ok', '', call_user_func_array(array($this->classes[$class_name], $method), $params));
} catch(SoapFault $e) {
} catch(ISPConfigRemoteException $e) {
$this->_return_json('remote_fault', $e->getMessage());
}
}
}
?>
if(!class_exists('ISPConfigRemoteException')) {
class ISPConfigRemoteException extends Exception {
public function __construct($code = '', $message = '') {
parent::__construct($message . ' (' . $code . ')', 0);
}
}
}
\ No newline at end of file
......@@ -60,12 +60,76 @@ class listform {
}
//* Set local Language File
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_'.$this->listDef['name'].'_list.lng';
$lng_file = 'lib/lang/'.$app->functions->check_language($_SESSION['s']['language']).'_'.$this->listDef['name'].'_list.lng';
if(!file_exists($lng_file)) $lng_file = 'lib/lang/en_'.$this->listDef['name'].'_list.lng';
include $lng_file;
$this->wordbook = $wb;
$module = (isset($_SESSION['s']['module']['name']) ? $_SESSION['s']['module']['name'] : '');
// load wordbook/lang files from addons
if($module == '') {
$lng_path = 'lib/lang.d';
} else {
$lng_path = '../' . $module . '/lib/lang.d';
}
if(($dir = opendir($lng_path))) {
$fallback_files = array();
$use_files = array();
while(false !== ($cur = readdir($dir))) {
$lng_file = $lng_path . '/' . $cur;
if(is_file($lng_file) && substr($cur, -strlen('.'.$app->listform->listDef["name"].".lng")) === '.'.$app->listform->listDef["name"].".lng") {
if(substr($cur, 0, 3) === 'en_') {
$fallback_files[] = $cur;
} elseif(substr($cur, 0, 3) === $app->functions->check_language($_SESSION["s"]["language"]) . '_') {
$use_files[] = $cur;
}
}
}
closedir($dir);
foreach($fallback_files as $cur) {
$cur_lng = $app->functions->check_language($_SESSION["s"]["language"]) . '_' . substr($cur, 3);
if(in_array($cur_lng, $use_files, true) == false) {
$use_files[] = $cur;
}
}
unset($fallback_files);
reset($use_files);
foreach($use_files as $cur) {
$lng_file = $lng_path . '/' . $cur;
include $lng_file;
if(isset($wb) && is_array($wb)) {
$this->wordbook = $app->functions->array_merge($this->wordbook, $wb);
}
}
unset($use_files);
}
if($module) {
// load list files from addons
$listform_path = '../' . $module . '/lib/form.d';
if(($dir = opendir($listform_path))) {
$items = null;
while(false !== ($cur = readdir($dir))) {
$listform_file = $listform_path . '/' . $cur;
if(is_file($listform_file) && substr($cur, -strlen('.'.$app->listform->listDef["name"].".list.php")) === '.'.$app->listform->listDef["name"].".list.php") {
unset($items); // just in case someone does not create a new array in the list file
include($listform_file);
if(isset($items) && is_array($items) && !empty($items)) {
$this->listDef['item'] = array_merge($this->listDef['item'], $items);
}
}
}
closedir($dir);
}
}
return true;
}
......
......@@ -249,7 +249,7 @@ class listform_actions {
global $app;
//* Set global Language File
$lng_file = ISPC_LIB_PATH.'/lang/'.$_SESSION['s']['language'].'.lng';
$lng_file = ISPC_LIB_PATH.'/lang/'.$app->functions->check_language($_SESSION['s']['language']).'.lng';
if(!file_exists($lng_file))
$lng_file = ISPC_LIB_PATH.'/lang/en.lng';
include $lng_file;
......
......@@ -153,10 +153,10 @@ class listform_tpl_generator {
}
function lng_add($lang, $listDef, $module = '') {
global $go_api, $go_info, $conf;
global $app, $conf;
if($module == '') {
$lng_file = "lib/lang/".$conf["language"]."_".$listDef['name']."_list.lng";
$lng_file = "lib/lang/".$app->functions->check_language($conf["language"])."_".$listDef['name']."_list.lng";
} else {
$lng_file = '../'.$module."/lib/lang/en_".$listDef['name']."_list.lng";
}
......
......@@ -124,17 +124,35 @@ class plugin {
$tmp_event = $sub_events[2];
if($this->debug) $app->log("Called Event '$tmp_event'", LOGLEVEL_DEBUG);
$tmpresult = $this->callPluginEvent($tmp_event, $data, $return_data);
if($return_data == true && $tmpresult) $result .= $tmpresult;
if($return_data == true && $tmpresult) {
if(is_array($tmpresult) && (!$result || is_array($result))) {
$result = array_merge($result, $tmpresult);
} elseif(!is_array($tmpresult)) {
$result .= $tmpresult;
}
}
$tmp_event = $sub_events[0].':'.$sub_events[2];
if($this->debug) $app->log("Called Event '$tmp_event'", LOGLEVEL_DEBUG);
$tmpresult = $this->callPluginEvent($tmp_event, $data, $return_data);
if($return_data == true && $tmpresult) $result .= $tmpresult;
if($return_data == true && $tmpresult) {
if(is_array($tmpresult) && (!$result || is_array($result))) {
$result = array_merge($result, $tmpresult);
} elseif(!is_array($tmpresult)) {
$result .= $tmpresult;
}
}
$tmp_event = $sub_events[0].':'.$sub_events[1].':'.$sub_events[2];
if($this->debug) $app->log("Called Event '$tmp_event'", LOGLEVEL_DEBUG);
$tmpresult = $this->callPluginEvent($tmp_event, $data, $return_data);
if($return_data == true && $tmpresult) $result .= $tmpresult;
if($return_data == true && $tmpresult) {
if(is_array($tmpresult) && (!$result || is_array($result))) {
$result = array_merge($result, $tmpresult);
} elseif(!is_array($tmpresult)) {
$result .= $tmpresult;
}
}
/*$sub_events = array_reverse($sub_events);
$tmp_event = '';
......@@ -147,7 +165,13 @@ class plugin {
} else {
if($this->debug) $app->log("Called Event '$sub_events[0]'", LOGLEVEL_DEBUG);
$tmpresult = $this->callPluginEvent($sub_events[0], $data, $return_data);
if($return_data == true && $tmpresult) $result .= $tmpresult;
if($return_data == true && $tmpresult) {
if(is_array($tmpresult) && (!$result || is_array($result))) {
$result = array_merge($result, $tmpresult);
} elseif(!is_array($tmpresult)) {
$result .= $tmpresult;
}
}
}
}
......@@ -187,7 +211,13 @@ class plugin {
// call_user_method($function_name,$app->loaded_plugins[$plugin_name],$event_name,$data);
$tmpresult = call_user_func(array($app->loaded_plugins[$plugin_name], $function_name), $event_name, $data);
if($return_data == true && $tmpresult) $result .= $tmpresult;
if($return_data == true && $tmpresult) {
if(is_array($tmpresult) && (!$result || is_array($result))) {
$result = array_merge($result, $tmpresult);
} elseif(!is_array($tmpresult)) {
$result .= $tmpresult;
}
}
}
}
......
......@@ -45,7 +45,7 @@ class plugin_backuplist extends plugin_base {
$listTpl->newTemplate('templates/web_backup_list.htm');
//* Loading language file
$lng_file = "lib/lang/".$_SESSION["s"]["language"]."_web_backup_list.lng";
$lng_file = "lib/lang/".$app->functions->check_language($_SESSION["s"]["language"])."_web_backup_list.lng";
include $lng_file;
$listTpl->setVar($wb);
......
......@@ -46,7 +46,7 @@ class plugin_backuplist_mail extends plugin_base {
$listTpl->newTemplate('templates/mail_user_backup_list.htm');
//* Loading language file
$lng_file = "lib/lang/".$_SESSION["s"]["language"]."_mail_backup_list.lng";
$lng_file = "lib/lang/".$app->functions->check_language($_SESSION["s"]["language"])."_mail_backup_list.lng";
include($lng_file);
$listTpl->setVar($wb);
......
......@@ -18,7 +18,7 @@ class plugin_directive_snippets extends plugin_base
$listTpl->newTemplate('templates/web_directive_snippets.htm');
//* Loading language file
$lng_file = "lib/lang/".$_SESSION["s"]["language"]."_web_directive_snippets.lng";
$lng_file = "lib/lang/".$app->functions->check_language($_SESSION["s"]["language"])."_web_directive_snippets.lng";
include $lng_file;
$listTpl->setVar($wb);
......
......@@ -120,7 +120,7 @@ class plugin_listview extends plugin_base {
}
// Loading language field
$lng_file = "lib/lang/".$_SESSION["s"]["language"]."_".$app->listform->listDef['name']."_list.lng";
$lng_file = "lib/lang/".$app->functions->check_language($_SESSION["s"]["language"])."_".$app->listform->listDef['name']."_list.lng";
include $lng_file;
$listTpl->setVar($wb);
......
......@@ -43,11 +43,11 @@ class plugin_system_config_dns_ca extends plugin_base {
$pluginTpl = new tpl;
$pluginTpl->newTemplate('templates/system_config_dns_ca_edit.htm');
include 'lib/lang/'.$_SESSION['s']['language'].'_system_config.lng';
include 'lib/lang/'.$app->functions->check_language($_SESSION['s']['language']).'_system_config.lng';
$pluginTpl->setVar($wb);
if(isset($_GET['action']) && ($_GET['action'] == 'edit') && $_GET['id'] > 0) {
$ca_id = $app->functions->intval($_GET['id']);
if(isset($_GET['action']) && ($_GET['action'] == 'edit') && $ca_id > 0) {
$pluginTpl->setVar('edit_record', 1);
$ca_id = intval($_GET['id']);
$rec = $app->db->queryOneRecord("SELECT * FROM dns_ssl_ca WHERE id = ?", $ca_id);
$pluginTpl->setVar('id', $rec['id']);
$pluginTpl->setVar('ca_name', $rec['ca_name']);
......@@ -56,16 +56,15 @@ class plugin_system_config_dns_ca extends plugin_base {
$pluginTpl->setVar('ca_critical', $rec['ca_critical']);
$pluginTpl->setVar('ca_iodef', $rec['ca_iodef']);
$pluginTpl->setVar('active', $rec['active']);
} elseif(isset($_GET['action']) && ($_GET['action'] == 'save') && $_GET['id'] > 0) {
} elseif(isset($_GET['action']) && ($_GET['action'] == 'save') && $ca_id > 0) {
$pluginTpl->setVar('edit_record', 0);
$ca_id = intval($_GET['id']);
$pluginTpl->setVar('id', $ca_id);
$pluginTpl->setVar('ca_name', $_POST['ca_name']);
$pluginTpl->setVar('ca_issue', $_POST['ca_issue']);
$pluginTpl->setVar('ca_wildcard', $_POST['ca_wildcard']);
$pluginTpl->setVar('ca_critical', $_POST['ca_critical']);
$pluginTpl->setVar('ca_iodef', $_POST['ca_iodef']);
$pluginTpl->setVar('active', $_POST['active']);
$pluginTpl->setVar('ca_name', $app->functions->htmlentities($_POST['ca_name']));
$pluginTpl->setVar('ca_issue', $app->functions->htmlentities($_POST['ca_issue']));
$pluginTpl->setVar('ca_wildcard', $app->functions->htmlentities($_POST['ca_wildcard']));
$pluginTpl->setVar('ca_critical', $app->functions->htmlentities($_POST['ca_critical']));
$pluginTpl->setVar('ca_iodef', $app->functions->htmlentities($_POST['ca_iodef']));
$pluginTpl->setVar('active', $app->functions->htmlentities($_POST['active']));
} else {
$pluginTpl->setVar('edit_record', 0);
}
......@@ -77,10 +76,10 @@ class plugin_system_config_dns_ca extends plugin_base {
function onUpdate() {
global $app;
$id = intval($_GET['id']);
$ca_id = $app->functions->intval($_GET['id']);
if(isset($_GET['action']) && $_GET['action'] == 'save') {
if($id > 0) {
$app->db->query("UPDATE dns_ssl_ca SET ca_name = ?, ca_issue = ?, ca_wildcard = ?, ca_iodef = ?, active = ? WHERE id = ?", $_POST['ca_name'], $_POST['ca_issue'], $_POST['ca_wildcard'], $_POST['ca_iodef'], $_POST['active'], $_GET['id']);
if($ca_id > 0) {
$app->db->query("UPDATE dns_ssl_ca SET ca_name = ?, ca_issue = ?, ca_wildcard = ?, ca_iodef = ?, active = ? WHERE id = ?", $_POST['ca_name'], $_POST['ca_issue'], $_POST['ca_wildcard'], $_POST['ca_iodef'], $_POST['active'], $ca_id);
} else {
$app->db->query("INSERT INTO (sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, ca_name, ca_issue, ca_wildcard, ca_iodef, active) VALUES(1, 1, 'riud', 'riud', '', ?, ?, ?, ?, ?", $_POST['ca_name'], $_POST['ca_issue'], $_POST['ca_wildcard'], $_POST['ca_iodef'], $_POST['active']);
}
......
......@@ -44,7 +44,7 @@ class plugin_system_config_dns_ca_list extends plugin_base {
$listTpl->newTemplate('templates/system_config_dns_ca_list.htm');
//* Loading language file
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_system_config.lng';
$lng_file = 'lib/lang/'.$app->functions->check_language($_SESSION['s']['language']).'_system_config.lng';
include $lng_file;
$listTpl->setVar($wb);
if($_SESSION['s']['user']['typ'] == 'admin') {
......