From e38d145b1b5392e9a88101f7dd5a31173e4cfa90 Mon Sep 17 00:00:00 2001 From: jwarnier Date: Sat, 25 Sep 2010 01:26:50 +0000 Subject: [PATCH] - setup and use $conf['ispconfig_log_dir'], somehow replacing ISPC_LOG_PATH/$conf['logpath'] - replace double-quotes with single-quotes whenever appropriate - fix indentation --- install/dist/lib/fedora.lib.php | 4 +- install/dist/lib/gentoo.lib.php | 10 +- install/dist/lib/opensuse.lib.php | 6 +- install/lib/install.lib.php | 18 +- install/lib/installer_base.lib.php | 24 +- install/tpl/config.inc.php.master | 82 +-- interface/lib/config.inc.php | 4 +- server/cron_daily.php | 4 +- server/lib/classes/db_mysql.inc.php | 30 +- server/lib/classes/getconf.inc.php | 3 +- server/lib/classes/ini_parser.inc.php | 7 +- .../monitor_core_module.inc.php | 514 +++++++++--------- 12 files changed, 367 insertions(+), 339 deletions(-) diff --git a/install/dist/lib/fedora.lib.php b/install/dist/lib/fedora.lib.php index 5cb5b74f6e..8c7710194f 100644 --- a/install/dist/lib/fedora.lib.php +++ b/install/dist/lib/fedora.lib.php @@ -889,8 +889,8 @@ class installer_dist extends installer_base { // exec('chmod a+rx /usr/local/ispconfig/interface/web'); //* Create the ispconfig log directory - if(!is_dir('/var/log/ispconfig')) mkdir('/var/log/ispconfig'); - if(!is_file('/var/log/ispconfig/ispconfig.log')) exec('touch /var/log/ispconfig/ispconfig.log'); + if(!is_dir($conf['ispconfig_log_dir'])) mkdir($conf['ispconfig_log_dir']); + if(!is_file($conf['ispconfig_log_dir'].'/ispconfig.log')) exec('touch '.$conf['ispconfig_log_dir'].'/ispconfig.log'); exec('mv /usr/local/ispconfig/server/scripts/run-getmail.sh /usr/local/bin/run-getmail.sh'); exec('chown getmail /usr/local/bin/run-getmail.sh'); diff --git a/install/dist/lib/gentoo.lib.php b/install/dist/lib/gentoo.lib.php index dce870d895..e6f4a0999b 100644 --- a/install/dist/lib/gentoo.lib.php +++ b/install/dist/lib/gentoo.lib.php @@ -752,11 +752,11 @@ class installer extends installer_base } // Create the ispconfig log directory - if (!is_dir('/var/log/ispconfig')) { - mkdir('/var/log/ispconfig'); + if (!is_dir($conf['ispconfig_log_dir'])) { + mkdir($conf['ispconfig_log_dir']); } - if (!is_file('/var/log/ispconfig/ispconfig.log')) { - exec('touch /var/log/ispconfig/ispconfig.log'); + if (!is_file($conf['ispconfig_log_dir'].'/ispconfig.log')) { + exec('touch '.$conf['ispconfig_log_dir'].'/ispconfig.log'); } exec('mv /usr/local/ispconfig/server/scripts/run-getmail.sh /usr/local/bin/run-getmail.sh'); @@ -765,4 +765,4 @@ class installer extends installer_base } } -?> \ No newline at end of file +?> diff --git a/install/dist/lib/opensuse.lib.php b/install/dist/lib/opensuse.lib.php index 1a7daf0de3..59a07e7d83 100644 --- a/install/dist/lib/opensuse.lib.php +++ b/install/dist/lib/opensuse.lib.php @@ -901,8 +901,8 @@ class installer_dist extends installer_base { exec('chmod a+rx /usr/local/ispconfig/interface/web'); //* Create the ispconfig log directory - if(!is_dir('/var/log/ispconfig')) mkdir('/var/log/ispconfig'); - if(!is_file('/var/log/ispconfig/ispconfig.log')) exec('touch /var/log/ispconfig/ispconfig.log'); + if(!is_dir($conf['ispconfig_log_dir'])) mkdir($conf['ispconfig_log_dir']); + if(!is_file($conf['ispconfig_log_dir'].'/ispconfig.log')) exec('touch '.$conf['ispconfig_log_dir'].'/ispconfig.log'); exec('mv /usr/local/ispconfig/server/scripts/run-getmail.sh /usr/local/bin/run-getmail.sh'); exec('chown getmail /usr/local/bin/run-getmail.sh'); @@ -992,4 +992,4 @@ class installer_dist extends installer_base { } -?> \ No newline at end of file +?> diff --git a/install/lib/install.lib.php b/install/lib/install.lib.php index 7ea2d90579..997f9a1eea 100644 --- a/install/lib/install.lib.php +++ b/install/lib/install.lib.php @@ -97,7 +97,7 @@ function get_distname() { } //** OpenSuSE - elseif(file_exists("/etc/SuSE-release")) { + elseif(file_exists('/etc/SuSE-release')) { if(stristr(file_get_contents('/etc/SuSE-release'),'11.0')) { $distname = 'openSUSE'; $distver = '11.0'; @@ -127,7 +127,7 @@ function get_distname() { //** Redhat - elseif(file_exists("/etc/redhat-release")) { + elseif(file_exists('/etc/redhat-release')) { $content = file_get_contents('/etc/redhat-release'); @@ -171,7 +171,7 @@ function get_distname() { } //** Gentoo - elseif(file_exists("/etc/gentoo-release")) { + elseif(file_exists('/etc/gentoo-release')) { $content = file_get_contents('/etc/gentoo-release'); @@ -183,7 +183,7 @@ function get_distname() { swriteln("Operating System: Gentoo $distver or compatible\n"); } else { - die('unrecognized Linux distribution'); + die('Unrecognized GNU/Linux distribution'); } return array('name' => $distname, 'version' => $distver, 'id' => $distid, 'baseid' => $distbaseid); @@ -203,7 +203,7 @@ function swriteln($text = '') { } function ilog($msg){ - exec("echo `date` \"- [ISPConfig] - \"".$msg." >> ".ISPC_LOG_FILE); + exec("echo `date` \"- [ISPConfig] - \"".$msg.' >> '.ISPC_LOG_FILE); } function error($msg){ @@ -501,8 +501,8 @@ function is_user($user){ $lines = explode("\n", $users); if(is_array($lines)){ foreach($lines as $line){ - if(trim($line) != ""){ - list($f1, $f2, $f3, $f4, $f5, $f6, $f7) = explode(":", $line); + if(trim($line) != ''){ + list($f1, $f2, $f3, $f4, $f5, $f6, $f7) = explode(':', $line); if($f1 == $user) return true; } } @@ -517,8 +517,8 @@ function is_group($group){ $lines = explode("\n", $groups); if(is_array($lines)){ foreach($lines as $line){ - if(trim($line) != ""){ - list($f1, $f2, $f3, $f4) = explode(":", $line); + if(trim($line) != ''){ + list($f1, $f2, $f3, $f4) = explode(':', $line); if($f1 == $group) return true; } } diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php index bd4dbe3688..abc0ff69bf 100644 --- a/install/lib/installer_base.lib.php +++ b/install/lib/installer_base.lib.php @@ -963,7 +963,7 @@ class installer_base { global $conf; //* Create the logging directory for the vhost logfiles - mkdir('/var/log/ispconfig/httpd', 0755, true); + mkdir($conf['ispconfig_log_dir'].'/httpd', 0755, true); if(is_file('/etc/suphp/suphp.conf')) { replaceLine('/etc/suphp/suphp.conf','php=php:/usr/bin','x-httpd-suphp="php:/usr/bin/php-cgi"',0); @@ -1470,10 +1470,10 @@ class installer_base { if(@is_file('/var/log/clamav/clamav.log')) exec('chmod +r /var/log/clamav/clamav.log'); if(@is_file('/var/log/clamav/freshclam.log')) exec('chmod +r /var/log/clamav/freshclam.log'); - //* Create the ispconfig log directory - if(!is_file('/var/log/ispconfig/ispconfig.log')) { - if(!is_dir('/var/log/ispconfig')) mkdir('/var/log/ispconfig', 0755); - touch('/var/log/ispconfig/ispconfig.log'); + //* Create the ispconfig log file and directory + if(!is_file($conf['ispconfig_log_dir'].'/ispconfig.log')) { + if(!is_dir($conf['ispconfig_log_dir'])) mkdir($conf['ispconfig_log_dir'], 0755); + touch($conf['ispconfig_log_dir'].'/ispconfig.log'); } rename($install_dir.'/server/scripts/run-getmail.sh','/usr/local/bin/run-getmail.sh'); @@ -1486,14 +1486,14 @@ class installer_base { /* We rotate these logs in cron_daily.php $fh = fopen('/etc/logrotate.d/logispc3', 'w'); fwrite($fh, - "/var/log/ispconfig/ispconfig.log { \n" . + "$conf['ispconfig_log_dir']/ispconfig.log { \n" . " weekly \n" . " missingok \n" . " rotate 4 \n" . " compress \n" . " delaycompress \n" . "} \n" . - "/var/log/ispconfig/cron.log { \n" . + "$conf['ispconfig_log_dir']/cron.log { \n" . " weekly \n" . " missingok \n" . " rotate 4 \n" . @@ -1544,8 +1544,8 @@ class installer_base { } $root_cron_jobs = array( - "* * * * * $install_dir/server/server.sh > /dev/null 2>> /var/log/ispconfig/cron.log", - "30 00 * * * $install_dir/server/cron_daily.sh > /dev/null 2>> /var/log/ispconfig/cron.log" + "* * * * * $install_dir/server/server.sh > /dev/null 2>> $conf['ispconfig_log_dir']/cron.log", + "30 00 * * * $install_dir/server/cron_daily.sh > /dev/null 2>> $conf['ispconfig_log_dir']/cron.log" ); foreach($root_cron_jobs as $cron_job) { if(!in_array($cron_job."\n", $existing_root_cron_jobs)) { @@ -1563,7 +1563,7 @@ class installer_base { $existing_cron_jobs = file('crontab.txt'); $cron_jobs = array( - '*/5 * * * * /usr/local/bin/run-getmail.sh > /dev/null 2>> /var/log/ispconfig/cron.log' + '*/5 * * * * /usr/local/bin/run-getmail.sh > /dev/null 2>> $conf['ispconfig_log_dir']/cron.log' ); // remove existing ispconfig cronjobs, in case the syntax has changed @@ -1581,8 +1581,8 @@ class installer_base { unlink('crontab.txt'); } - touch('/var/log/ispconfig/cron.log'); - chmod('/var/log/ispconfig/cron.log', 0666); + touch($conf['ispconfig_log_dir'].'/cron.log'); + chmod($conf['ispconfig_log_dir'].'/cron.log', 0666); } diff --git a/install/tpl/config.inc.php.master b/install/tpl/config.inc.php.master index 1bcdcad09b..cddd97b4fb 100644 --- a/install/tpl/config.inc.php.master +++ b/install/tpl/config.inc.php.master @@ -60,27 +60,27 @@ define('ISPC_APP_VERSION', '3.0.3'); //** Database -$conf["db_type"] = 'mysql'; -$conf["db_host"] = '{mysql_server_host}'; -$conf["db_database"] = '{mysql_server_database}'; -$conf["db_user"] = '{mysql_server_ispconfig_user}'; -$conf["db_password"] = '{mysql_server_ispconfig_password}'; -$conf["db_charset"] = 'utf8'; // same charset as html-charset - (HTML --> MYSQL: "utf-8" --> "utf8", "iso-8859-1" --> "latin1") +$conf['db_type'] = 'mysql'; +$conf['db_host'] = '{mysql_server_host}'; +$conf['db_database'] = '{mysql_server_database}'; +$conf['db_user'] = '{mysql_server_ispconfig_user}'; +$conf['db_password'] = '{mysql_server_ispconfig_password}'; +$conf['db_charset'] = 'utf8'; // same charset as html-charset - (HTML --> MYSQL: "utf-8" --> "utf8", "iso-8859-1" --> "latin1") -define("DB_TYPE",$conf["db_type"]); -define("DB_HOST",$conf["db_host"]); -define("DB_DATABASE",$conf["db_database"]); -define("DB_USER",$conf["db_user"]); -define("DB_PASSWORD",$conf["db_password"]); -define("DB_CHARSET",$conf["db_charset"]); +define('DB_TYPE',$conf['db_type']); +define('DB_HOST',$conf['db_host']); +define('DB_DATABASE',$conf['db_database']); +define('DB_USER',$conf['db_user']); +define('DB_PASSWORD',$conf['db_password']); +define('DB_CHARSET',$conf['db_charset']); //** Database settings for the master DB. This setting is only used in multiserver setups -$conf["dbmaster_type"] = 'mysql'; -$conf["dbmaster_host"] = '{mysql_master_server_host}'; -$conf["dbmaster_database"] = '{mysql_master_server_database}'; -$conf["dbmaster_user"] = '{mysql_master_server_ispconfig_user}'; -$conf["dbmaster_password"] = '{mysql_master_server_ispconfig_password}'; +$conf['dbmaster_type'] = 'mysql'; +$conf['dbmaster_host'] = '{mysql_master_server_host}'; +$conf['dbmaster_database'] = '{mysql_master_server_database}'; +$conf['dbmaster_user'] = '{mysql_master_server_ispconfig_user}'; +$conf['dbmaster_password'] = '{mysql_master_server_ispconfig_password}'; //** Paths @@ -91,19 +91,19 @@ define('ISPC_WEB_PATH', ISPC_ROOT_PATH.'/web'); define('ISPC_THEMES_PATH', ISPC_ROOT_PATH.'/web/themes'); define('ISPC_WEB_TEMP_PATH', ISPC_WEB_PATH.'/temp'); // Path for downloads, accessible via browser define('ISPC_CACHE_PATH', ISPC_ROOT_PATH.'/cache'); -define('ISPC_LOG_PATH', '/var/log/ispconfig'); +define('ISPC_LOG_PATH', $conf['ispconfig_log_dir']); //** Paths (Do not change!) -$conf["rootpath"] = substr(dirname(__FILE__),0,-4); -$conf["fs_div"] = "/"; // File system separator, "\\" on Windows and "/"" on Linux and UNIX -$conf["classpath"] = $conf["rootpath"].$conf["fs_div"]."lib".$conf["fs_div"]."classes"; -$conf["temppath"] = $conf["rootpath"].$conf["fs_div"]."temp"; -$conf["logpath"] = ISPC_LOG_PATH; +$conf['rootpath'] = substr(dirname(__FILE__),0,-4); +$conf['fs_div'] = '/'; // File system separator, "\\" on Windows and "/" on Linux and UNIX +$conf['classpath'] = $conf['rootpath'].$conf['fs_div'].'lib'.$conf['fs_div'].'classes'; +$conf['temppath'] = $conf['rootpath'].$conf['fs_div'].'temp'; +$conf['logpath'] = ISPC_LOG_PATH; // Actually just a copy of $conf['ispconfig_log_dir'], might be removed in a later version -define("FS_DIV",$conf["fs_div"]); -define("SERVER_ROOT",$conf["rootpath"]); -define("INCLUDE_ROOT",SERVER_ROOT.FS_DIV."lib"); -define("CLASSES_ROOT",INCLUDE_ROOT.FS_DIV."classes"); +define('FS_DIV',$conf['fs_div']); +define('SERVER_ROOT',$conf['rootpath']); +define('INCLUDE_ROOT',SERVER_ROOT.FS_DIV.'lib'); +define('CLASSES_ROOT',INCLUDE_ROOT.FS_DIV.'classes'); //** Server @@ -111,7 +111,7 @@ $conf['app_title'] = ISPC_APP_TITLE; $conf['app_version'] = ISPC_APP_VERSION; $conf['app_link'] = 'http://www.ispconfig.org/'; $conf['modules_available'] = 'dashboard,admin,mail,sites,monitor,client,dns,help'; -$conf["server_id"] = "{server_id}"; +$conf['server_id'] = '{server_id}'; //** Interface @@ -128,8 +128,8 @@ $conf['demo_mode'] = false; //** Logging -$conf["log_file"] = $conf["logpath"].$conf["fs_div"]."ispconfig.log"; -$conf["log_priority"] = {ispconfig_log_priority}; // 0 = Debug, 1 = Warning, 2 = Error +$conf['log_file'] = $conf['ispconfig_log_dir'].$conf['fs_div'].'ispconfig.log'; +$conf['log_priority'] = {ispconfig_log_priority}; // 0 = Debug, 1 = Warning, 2 = Error //** Allow software package installations @@ -137,29 +137,29 @@ $conf['software_updates_enabled'] = false; //** Themes -$conf["theme"] = 'default'; -$conf["html_content_encoding"] = 'utf-8'; // example: utf-8, iso-8859-1, ... -$conf["logo"] = 'themes/default/images/ispc_logo.png'; +$conf['theme'] = 'default'; +$conf['html_content_encoding'] = 'utf-8'; // example: utf-8, iso-8859-1, ... +$conf['logo'] = 'themes/default/images/ispc_logo.png'; //** Default Language -$conf["language"] = '{language}'; -$conf["debug_language"] = false; +$conf['language'] = '{language}'; +$conf['debug_language'] = false; //** Misc. -$conf["interface_logout_url"] = ""; // example: http://www.domain.tld/ +$conf['interface_logout_url'] = ''; // example: http://www.domain.tld/ //** Auto Load Modules -$conf["start_db"] = true; -$conf["start_session"] = true; +$conf['start_db'] = true; +$conf['start_session'] = true; //** Constants -define("LOGLEVEL_DEBUG",0); -define("LOGLEVEL_WARN",1); -define("LOGLEVEL_ERROR",2); +define('LOGLEVEL_DEBUG',0); +define('LOGLEVEL_WARN',1); +define('LOGLEVEL_ERROR',2); //** include a local config-file if there is one //** IMPORTANT!!! diff --git a/interface/lib/config.inc.php b/interface/lib/config.inc.php index 2bcba6c736..c92030404a 100644 --- a/interface/lib/config.inc.php +++ b/interface/lib/config.inc.php @@ -82,7 +82,7 @@ define('ISPC_CACHE_PATH', ISPC_ROOT_PATH.'/cache'); //** Paths (Do not change!) $conf['rootpath'] = substr(dirname(__FILE__),0,-4); -$conf['fs_div'] = '/'; // File system separator (divider), "\\" on Windows and "/"" on Linux and UNIX +$conf['fs_div'] = '/'; // File system separator (divider), "\\" on Windows and "/" on Linux and UNIX $conf['classpath'] = $conf['rootpath'].$conf['fs_div'].'lib'.$conf['fs_div'].'classes'; $conf['temppath'] = $conf['rootpath'].$conf['fs_div'].'temp'; @@ -114,7 +114,7 @@ $conf['demo_mode'] = false; //** Logging -$conf['log_file'] = '/var/log/ispconfig/ispconfig.log'; +$conf['log_file'] = $conf['ispconfig_log_dir'].'/ispconfig.log'; $conf['log_priority'] = 0; // 0 = Debug, 1 = Warning, 2 = Error diff --git a/server/cron_daily.php b/server/cron_daily.php index b93e099963..05df3d3e92 100644 --- a/server/cron_daily.php +++ b/server/cron_daily.php @@ -228,14 +228,14 @@ foreach($records as $rec) { ####################################################################################################### // rotate the ispconfig.log when it exceeds a size of 10 MB -$logfile = '/var/log/ispconfig/ispconfig.log'; +$logfile = $conf['ispconfig_log_dir'].'/ispconfig.log'; if(is_file($logfile) && filesize($logfile) > 10000000) { exec("gzip -c $logfile > $logfile.1.gz"); exec("cat /dev/null > $logfile"); } // rotate the cron.log when it exceeds a size of 10 MB -$logfile = '/var/log/ispconfig/cron.log'; +$logfile = $conf['ispconfig_log_dir'].'/cron.log'; if(is_file($logfile) && filesize($logfile) > 10000000) { exec("gzip -c $logfile > $logfile.1.gz"); exec("cat /dev/null > $logfile"); diff --git a/server/lib/classes/db_mysql.inc.php b/server/lib/classes/db_mysql.inc.php index fb4f3079a6..c2a5a350d7 100644 --- a/server/lib/classes/db_mysql.inc.php +++ b/server/lib/classes/db_mysql.inc.php @@ -36,7 +36,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. var $linkId = 0; // last result of mysql_connect() var $queryId = 0; // last result of mysql_query() var $record = array(); // last record fetched - var $autoCommit = 1; // Autocommit Transactions + var $autoCommit = 1; // Autocommit Transactions var $currentRow; // current row number var $errorNumber = 0; // last error number var $errorMessage = ''; // last error message @@ -339,7 +339,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. return true; } - + + public function closeConn() { if($this->linkId) @@ -397,17 +398,16 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. if($col['autoInc'] == true) $sql .= 'auto_increment '; $sql.= ','; // key Definitionen - if($col['option'] == 'primary') $index .= "PRIMARY KEY (".$col['name']."),"; - if($col['option'] == 'index') $index .= "INDEX (".$col['name']."),"; - if($col['option'] == 'unique') $index .= "UNIQUE (".$col['name']."),"; + if($col['option'] == 'primary') $index .= 'PRIMARY KEY ('.$col['name'].'),'; + if($col['option'] == 'index') $index .= 'INDEX ('.$col['name'].'),'; + if($col['option'] == 'unique') $index .= 'UNIQUE ('.$col['name'].'),'; } $sql .= $index; $sql = substr($sql,0,-1); $sql .= ')'; - $this->query($sql); return true; - } + } /* $columns = array(action => add | alter | drop @@ -427,11 +427,11 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. $sql = "ALTER TABLE $table_name "; foreach($columns as $col){ if($col['action'] == 'add') { - $sql .= "ADD ".$col['name'].' '.$this->mapType($col['type'],$col['typeValue']).' '; + $sql .= 'ADD '.$col['name'].' '.$this->mapType($col['type'],$col['typeValue']).' '; } elseif ($col['action'] == 'alter') { - $sql .= "CHANGE ".$col['name']." ".$col['name_new'].' '.$this->mapType($col['type'],$col['typeValue']).' '; + $sql .= 'CHANGE '.$col['name'].' '.$col['name_new'].' '.$this->mapType($col['type'],$col['typeValue']).' '; } elseif ($col['action'] == 'drop') { - $sql .= "DROP ".$col['name'].' '; + $sql .= 'DROP '.$col['name'].' '; } if($col['action'] != 'drop') { if($col['defaultValue'] != '') $sql .= "DEFAULT '".$col['defaultValue']."' "; @@ -442,10 +442,10 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. } if($col['autoInc'] == true) $sql .= 'auto_increment '; $sql.= ','; - // key Definitionen - if($col['option'] == 'primary') $index .= "PRIMARY KEY (".$col['name']."),"; - if($col['option'] == 'index') $index .= "INDEX (".$col['name']."),"; - if($col['option'] == 'unique') $index .= "UNIQUE (".$col['name']."),"; + // Index definitions + if($col['option'] == 'primary') $index .= 'PRIMARY KEY ('.$col['name'].'),'; + if($col['option'] == 'index') $index .= 'INDEX ('.$col['name'].'),'; + if($col['option'] == 'unique') $index .= 'UNIQUE ('.$col['name'].'),'; } } $sql .= $index; @@ -493,7 +493,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. global $go_api,$go_info; // Tabellenfelder einlesen - if($rows = $go_api->db->queryAllRecords("SHOW FIELDS FROM ".$table_name)){ + if($rows = $go_api->db->queryAllRecords('SHOW FIELDS FROM '.$table_name)){ foreach($rows as $row) { $name = $row[0]; $default = $row[4]; diff --git a/server/lib/classes/getconf.inc.php b/server/lib/classes/getconf.inc.php index 2a319781fd..c2207a1ccd 100644 --- a/server/lib/classes/getconf.inc.php +++ b/server/lib/classes/getconf.inc.php @@ -34,7 +34,7 @@ class getconf { function get_server_config($server_id, $section = '') { global $app; - + if(!is_array($this->config[$server_id])) { $app->uses('ini_parser'); $server_id = intval($server_id); @@ -59,7 +59,6 @@ class getconf { } return ($section == '') ? $this->config['global'] : $this->config['global'][$section]; } - } ?> diff --git a/server/lib/classes/ini_parser.inc.php b/server/lib/classes/ini_parser.inc.php index d98146a0d9..003d04caf2 100644 --- a/server/lib/classes/ini_parser.inc.php +++ b/server/lib/classes/ini_parser.inc.php @@ -28,7 +28,7 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -class ini_parser { +class ini_parser{ var $config; @@ -37,9 +37,8 @@ class ini_parser { $lines = explode("\n",$ini); foreach($lines as $line) { - + $line = trim($line); if($line != '') { - $line = trim($line); if(preg_match("/^\[([\w\d_]+)\]$/", $line, $matches)) { $section = strtolower($matches[1]); } elseif(preg_match("/^([\w\d_]+)=(.*)$/", $line, $matches) && $section != null) { @@ -70,4 +69,4 @@ class ini_parser { } -?> \ No newline at end of file +?> diff --git a/server/mods-available/monitor_core_module.inc.php b/server/mods-available/monitor_core_module.inc.php index 12f7385a3a..dcdeac7128 100644 --- a/server/mods-available/monitor_core_module.inc.php +++ b/server/mods-available/monitor_core_module.inc.php @@ -95,7 +95,7 @@ class monitor_core_module { } elseif(strstr(trim(file_get_contents('/etc/debian_version')),'6.0') || trim(file_get_contents('/etc/debian_version')) == 'squeeze/sid') { $distname = 'Debian'; $distver = 'Squeeze/Sid'; - $distid = 'debian40'; + $distid = 'debian60'; $distbaseid = 'debian'; } else { $distname = 'Debian'; @@ -106,7 +106,7 @@ class monitor_core_module { } //** OpenSuSE - elseif(file_exists("/etc/SuSE-release")) { + elseif(file_exists('/etc/SuSE-release')) { if(stristr(file_get_contents('/etc/SuSE-release'),'11.0')) { $distname = 'openSUSE'; $distver = '11.0'; @@ -132,7 +132,7 @@ class monitor_core_module { //** Redhat - elseif(file_exists("/etc/redhat-release")) { + elseif(file_exists('/etc/redhat-release')) { $content = file_get_contents('/etc/redhat-release'); @@ -170,7 +170,7 @@ class monitor_core_module { } //** Gentoo - elseif(file_exists("/etc/gentoo-release")) { + elseif(file_exists('/etc/gentoo-release')) { $content = file_get_contents('/etc/gentoo-release'); @@ -181,7 +181,7 @@ class monitor_core_module { $distbaseid = 'gentoo'; } else { - die('unrecognized Linux distribution'); + die('Unrecognized GNU/Linux distribution'); } return array('name' => $distname, 'version' => $distver, 'id' => $distid, 'baseid' => $distbaseid); @@ -229,7 +229,7 @@ class monitor_core_module { $data = array(); /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'harddisk_quota'; @@ -238,7 +238,7 @@ class monitor_core_module { $state = 'ok'; /** Fetch the data for all users*/ - $dfData = shell_exec("repquota -asu"); + $dfData = shell_exec('repquota -asu'); // split into array $df = explode("\n", $dfData); @@ -251,7 +251,7 @@ class monitor_core_module { /* * Make a array of the data */ - $s = preg_split ("/[\s]+/", $df[$i]); + $s = preg_split ('/[\s]+/', $df[$i]); $username = $s[0]; $data['user'][$username]['used'] = $s[2]; $data['user'][$username]['soft'] = $s[3]; @@ -260,7 +260,7 @@ class monitor_core_module { } /** Fetch the data for all users*/ - $dfData = shell_exec("repquota -asg"); + $dfData = shell_exec('repquota -asg'); // split into array $df = explode("\n", $dfData); @@ -273,7 +273,7 @@ class monitor_core_module { /* * Make a array of the data */ - $s = preg_split ("/[\s]+/", $df[$i]); + $s = preg_split ('/[\s]+/', $df[$i]); $groupname = $s[0]; $data['group'][$groupname]['used'] = $s[1]; $data['group'][$groupname]['soft'] = $s[2]; @@ -284,14 +284,14 @@ class monitor_core_module { /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -303,7 +303,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'server_load'; @@ -316,15 +316,15 @@ class monitor_core_module { $data['up_hours'] = floor(($procUptime-$data['up_days']*86400)/3600); $data['up_minutes'] = floor(($procUptime-$data['up_days']*86400-$data['up_hours']*3600)/60); - $data['uptime'] = shell_exec("uptime"); + $data['uptime'] = shell_exec('uptime'); - $tmp = explode(",", $data['uptime'], 4); - $tmpUser = explode(" ", trim($tmp[2])); + $tmp = explode(',', $data['uptime'], 4); + $tmpUser = explode(' ', trim($tmp[2])); $data['user_online'] = intval($tmpUser[0]); //* New Load Average code to fix "always zero" bug in non-english distros. NEEDS TESTING $loadTmp = shell_exec("cat /proc/loadavg | cut -f1-3 -d' '"); - $load = explode(" ", $loadTmp); + $load = explode(' ', $loadTmp); $data['load_1'] = floatval(str_replace(',', '.', $load[0])); $data['load_5'] = floatval(str_replace(',', '.', $load[1])); $data['load_15'] = floatval(str_replace(',', '.', $load[2])); @@ -339,14 +339,14 @@ class monitor_core_module { /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -358,7 +358,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'os_info'; @@ -377,14 +377,14 @@ class monitor_core_module { /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -397,7 +397,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'ispc_info'; @@ -414,14 +414,14 @@ class monitor_core_module { /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -433,7 +433,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'disk_usage'; @@ -442,7 +442,7 @@ class monitor_core_module { $state = 'ok'; /** Fetch the data of ALL devices into a array (needed for monitoring!)*/ - $dfData = shell_exec("df -hT"); + $dfData = shell_exec('df -hT'); // split into array $df = explode("\n", $dfData); @@ -453,9 +453,9 @@ class monitor_core_module { for($i=1; $i <= sizeof($df); $i++) { if ($df[$i] != '') { /* - * Make a array of the data + * Make an array of the data */ - $s = preg_split ("/[\s]+/", $df[$i]); + $s = preg_split ('/[\s]+/', $df[$i]); $data[$i]['fs'] = $s[0]; $data[$i]['type'] = $s[1]; $data[$i]['size'] = $s[2]; @@ -468,12 +468,21 @@ class monitor_core_module { */ $usePercent = floatval($data[$i]['percent']); - //* We dont want to check the cdrom drive as a cd / dvd is always 100% full - if($data[$i]['type'] != 'iso9660' && $data[$i]['type'] != 'cramfs' && $data[$i]['type'] != 'udf' && $data[$i]['type'] != 'tmpfs' && $data[$i]['type'] != 'devtmpfs') { - if ($usePercent > 75) $state = $this->_setState($state, 'info'); - if ($usePercent > 80) $state = $this->_setState($state, 'warning'); - if ($usePercent > 90) $state = $this->_setState($state, 'critical'); - if ($usePercent > 95) $state = $this->_setState($state, 'error'); + //* We don't want to check some filesystem which have no sensible filling levels + switch($data[$i]['type']) { + case 'iso9660': + case 'cramfs': + case 'udf': + case 'tmpfs': + case 'devtmpfs': + case 'udev': + break; + default: + if ($usePercent > 75) $state = $this->_setState($state, 'info'); + if ($usePercent > 80) $state = $this->_setState($state, 'warning'); + if ($usePercent > 90) $state = $this->_setState($state, 'critical'); + if ($usePercent > 95) $state = $this->_setState($state, 'error'); + break; } } } @@ -482,14 +491,14 @@ class monitor_core_module { /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -502,7 +511,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'mem_usage'; @@ -510,14 +519,14 @@ class monitor_core_module { /* Fetch the data into a array */ - $miData = shell_exec("cat /proc/meminfo"); + $miData = shell_exec('cat /proc/meminfo'); $memInfo = explode("\n", $miData); foreach($memInfo as $line) { - $part = preg_split("/:/", $line); + $part = preg_split('/:/', $line); $key = trim($part[0]); - $tmp = explode(" ", trim($part[1])); + $tmp = explode(' ', trim($part[1])); $value = 0; if ($tmp[1] == 'kB') $value = $tmp[0] * 1024; $data[$key] = $value; @@ -532,14 +541,14 @@ class monitor_core_module { /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -552,7 +561,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'cpu_info'; @@ -560,33 +569,48 @@ class monitor_core_module { /* Fetch the data into a array */ - $cpuData = shell_exec("cat /proc/cpuinfo"); - $cpuInfo = explode("\n", $cpuData); - $processor = 0; - - foreach($cpuInfo as $line) { + if(file_exists('/proc/cpuinfo')) { + $cpuData = shell_exec('cat /proc/cpuinfo'); + $cpuInfo = explode("\n", $cpuData); + $processor = 0; + + foreach($cpuInfo as $line) { + + $part = preg_split('/:/', $line); + $key = trim($part[0]); + $value = trim($part[1]); + if($key == 'processor') $processor = intval($value); + if($key != '') $data[$key.' '.$processor] = $value; + } - $part = preg_split("/:/", $line); - $key = trim($part[0]); - $value = trim($part[1]); - if($key == 'processor') $processor = intval($value); - if($key != '') $data[$key.' '.$processor] = $value; + /* the cpu has no state. It is, what it is */ + $state = 'no_state'; + } else { + /* + * It is not Linux, so there is no data and no state + * + * no_state, NOT unknown, because "unknown" is shown as state + * inside the GUI. no_state is hidden. + * + * We have to write NO DATA inside the DB, because the GUI + * could not know, if there is any dat, or not... + */ + $state = 'no_state'; + $data['output']= ''; } - /* the cpu has no state. It is, what it is */ - $state = 'no_state'; /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -599,16 +623,16 @@ class monitor_core_module { global $conf; /** the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** get the "active" Services of the server from the DB */ - $services = $app->dbmaster->queryOneRecord("SELECT * FROM server WHERE server_id = " . $server_id); + $services = $app->dbmaster->queryOneRecord('SELECT * FROM server WHERE server_id = ' . $server_id); /* The type of the Monitor-data */ $type = 'services'; /** the State of the monitoring */ - /* ok, if ALL aktive services are running, + /* ok, if ALL active services are running, * error, if not * There is no other state! */ @@ -680,7 +704,7 @@ class monitor_core_module { } } - /* Monitor MYSQL-Server */ + /* Monitor MySQL Server */ $data['mysqlserver'] = -1; // unknown - not needed if ($services['db_server'] == 1) { if($this->_checkTcp('localhost', 3306)) { @@ -695,14 +719,14 @@ class monitor_core_module { /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -715,7 +739,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'openvz_veinfo'; @@ -733,14 +757,14 @@ class monitor_core_module { /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -752,7 +776,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'openvz_beancounter'; @@ -804,14 +828,14 @@ class monitor_core_module { /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -821,7 +845,7 @@ class monitor_core_module { function monitorSystemUpdate() { /* - * This monitoring is expensive, so do it only once a hour + * This monitoring is expensive, so do it only once an hour */ $min = date('i'); if ($min != 0) return; @@ -833,7 +857,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'system_update'; @@ -868,7 +892,7 @@ class monitor_core_module { */ $data['output'] = shell_exec('apt-get -s -q dist-upgrade'); } - elseif (file_exists("/etc/gentoo-release")) { + elseif (file_exists('/etc/gentoo-release')) { /* * first update the portage tree @@ -929,14 +953,14 @@ class monitor_core_module { /* * Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -948,7 +972,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'mailq'; @@ -975,14 +999,14 @@ class monitor_core_module { /* * Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -995,7 +1019,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'raid_state'; @@ -1084,19 +1108,19 @@ class monitor_core_module { if (strpos($item, ' ONLINE ') !== false) { $this->_setState($state, 'ok'); } - else if (strpos($item, ' OPTIMAL ') !== false) { + elseif (strpos($item, ' OPTIMAL ') !== false) { $this->_setState($state, 'ok'); } - else if (strpos($item, ' INITIAL ') !== false) { + elseif (strpos($item, ' INITIAL ') !== false) { $this->_setState($state, 'info'); } - else if (strpos($item, ' INACTIVE ') !== false) { + elseif (strpos($item, ' INACTIVE ') !== false) { $this->_setState($state, 'critical'); } - else if (strpos($item, ' RESYNC ') !== false) { + elseif (strpos($item, ' RESYNC ') !== false) { $this->_setState($state, 'info'); } - else if (strpos($item, ' DEGRADED ') !== false) { + elseif (strpos($item, ' DEGRADED ') !== false) { $this->_setState($state, 'critical'); } else { @@ -1112,14 +1136,14 @@ class monitor_core_module { /* * Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -1138,7 +1162,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'rkhunter'; @@ -1173,14 +1197,14 @@ class monitor_core_module { /* * Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -1192,7 +1216,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'log_fail2ban'; @@ -1226,14 +1250,14 @@ class monitor_core_module { /* * Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -1245,7 +1269,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'sys_log'; @@ -1254,7 +1278,7 @@ class monitor_core_module { * is there any warning or error for this server? */ $state = 'ok'; - $dbData = $app->dbmaster->queryAllRecords("SELECT loglevel FROM sys_log WHERE server_id = " . $server_id . " AND loglevel > 0"); + $dbData = $app->dbmaster->queryAllRecords('SELECT loglevel FROM sys_log WHERE server_id = ' . $server_id . ' AND loglevel > 0'); if (is_array($dbData)) { foreach($dbData as $item) { if ($item['loglevel'] == 1) $state = $this->_setState($state, 'warning'); @@ -1268,14 +1292,14 @@ class monitor_core_module { /* * Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -1287,7 +1311,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'log_mail'; @@ -1304,14 +1328,14 @@ class monitor_core_module { /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -1323,7 +1347,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'log_mail_warn'; @@ -1340,14 +1364,14 @@ class monitor_core_module { /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -1359,7 +1383,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'log_mail_err'; @@ -1376,14 +1400,14 @@ class monitor_core_module { /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -1396,7 +1420,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'log_messages'; @@ -1413,14 +1437,14 @@ class monitor_core_module { /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -1432,7 +1456,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'log_ispc_cron'; @@ -1449,14 +1473,14 @@ class monitor_core_module { /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -1468,7 +1492,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'log_freshclam'; @@ -1485,16 +1509,16 @@ class monitor_core_module { $tmp = explode("\n", $data); $lastLog = array(); - if ($tmp[sizeof($tmp)-1] == "") { + if ($tmp[sizeof($tmp)-1] == '') { /* the log ends with an empty line remove this */ array_pop($tmp); } - if (strpos($tmp[sizeof($tmp)-1], "-------------") !== false) { + if (strpos($tmp[sizeof($tmp)-1], '-------------') !== false) { /* the log ends with "-----..." remove this */ array_pop($tmp); } for ($i = sizeof($tmp) -1; $i > 0; $i--) { - if (strpos($tmp[$i], "---------") === false) { + if (strpos($tmp[$i], '---------') === false) { /* no delimiter found, so add this to the last-log */ $lastLog[] = $tmp[$i]; } @@ -1509,7 +1533,7 @@ class monitor_core_module { * Check if the outdated-string is found... */ foreach($lastLog as $line) { - if (strpos(strtolower($line), "outdated") !== false) { + if (strpos(strtolower($line), 'outdated') !== false) { /* * Outdatet is only info, because if we set this to warning, the server is * as long in state warning, as there is a new version of ClamAv which takes @@ -1522,14 +1546,14 @@ class monitor_core_module { /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -1541,7 +1565,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'log_clamav'; @@ -1555,14 +1579,14 @@ class monitor_core_module { /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -1574,7 +1598,7 @@ class monitor_core_module { global $conf; /* the id of the server as int */ - $server_id = intval($conf["server_id"]); + $server_id = intval($conf['server_id']); /** The type of the data */ $type = 'log_ispconfig'; @@ -1588,14 +1612,14 @@ class monitor_core_module { /* Insert the data into the database */ - $sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " . - "VALUES (". - $server_id . ", " . + $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES ('. + $server_id . ', ' . "'" . $app->dbmaster->quote($type) . "', " . - time() . ", " . + time() . ', ' . "'" . $app->dbmaster->quote(serialize($data)) . "', " . "'" . $state . "'" . - ")"; + ')'; $app->dbmaster->query($sql); /* The new data is written, now we can delete the old one */ @@ -1604,69 +1628,75 @@ class monitor_core_module { function _getLogData($log) { + global $conf; $dist = ''; $logfile = ''; - if(@is_file('/etc/debian_version')) $dist = 'debian'; - if(@is_file('/etc/redhat-release')) $dist = 'redhat'; - if(@is_file('/etc/SuSE-release')) $dist = 'suse'; - if(@is_file('/etc/gentoo-release')) $dist = 'gentoo'; + if(@is_file('/etc/debian_version')) { + $dist = 'debian'; + } elseif(@is_file('/etc/redhat-release')) { + $dist = 'redhat'; + } elseif(@is_file('/etc/SuSE-release')) { + $dist = 'suse'; + } elseif(@is_file('/etc/gentoo-release')) { + $dist = 'gentoo'; + } switch($log) { case 'log_mail': - if($dist == 'debian') $logfile = '/var/log/mail.log'; - if($dist == 'redhat') $logfile = '/var/log/maillog'; - if($dist == 'suse') $logfile = '/var/log/mail.info'; - if($dist == 'gentoo') $logfile = '/var/log/maillog'; + if($dist == 'debian') { $logfile = '/var/log/mail.log'; } + elseif($dist == 'redhat') { $logfile = '/var/log/maillog'; } + elseif($dist == 'suse') { $logfile = '/var/log/mail.info'; } + elseif($dist == 'gentoo') { $logfile = '/var/log/maillog'; } break; case 'log_mail_warn': - if($dist == 'debian') $logfile = '/var/log/mail.warn'; - if($dist == 'redhat') $logfile = '/var/log/maillog'; - if($dist == 'suse') $logfile = '/var/log/mail.warn'; - if($dist == 'gentoo') $logfile = '/var/log/maillog'; + if($dist == 'debian') { $logfile = '/var/log/mail.warn'; } + elseif($dist == 'redhat') { $logfile = '/var/log/maillog'; } + elseif($dist == 'suse') { $logfile = '/var/log/mail.warn'; } + elseif($dist == 'gentoo') { $logfile = '/var/log/maillog'; } break; case 'log_mail_err': - if($dist == 'debian') $logfile = '/var/log/mail.err'; - if($dist == 'redhat') $logfile = '/var/log/maillog'; - if($dist == 'suse') $logfile = '/var/log/mail.err'; - if($dist == 'gentoo') $logfile = '/var/log/maillog'; + if($dist == 'debian') { $logfile = '/var/log/mail.err'; } + elseif($dist == 'redhat') { $logfile = '/var/log/maillog'; } + elseif($dist == 'suse') { $logfile = '/var/log/mail.err'; } + elseif($dist == 'gentoo') { $logfile = '/var/log/maillog'; } break; case 'log_messages': - if($dist == 'debian') $logfile = '/var/log/messages'; - if($dist == 'redhat') $logfile = '/var/log/messages'; - if($dist == 'suse') $logfile = '/var/log/messages'; - if($dist == 'gentoo') $logfile = '/var/log/messages'; + if($dist == 'debian') { $logfile = '/var/log/messages'; } + elseif($dist == 'redhat') { $logfile = '/var/log/messages'; } + elseif($dist == 'suse') { $logfile = '/var/log/messages'; } + elseif($dist == 'gentoo') { $logfile = '/var/log/messages'; } break; case 'log_ispc_cron': - if($dist == 'debian') $logfile = '/var/log/ispconfig/cron.log'; - if($dist == 'redhat') $logfile = '/var/log/ispconfig/cron.log'; - if($dist == 'suse') $logfile = '/var/log/ispconfig/cron.log'; - if($dist == 'gentoo') $logfile = '/var/log/cron'; + if($dist == 'debian') { $logfile = $conf['ispconfig_log_dir'].'/cron.log'; } + elseif($dist == 'redhat') { $logfile = $conf['ispconfig_log_dir'].'/cron.log'; } + elseif($dist == 'suse') { $logfile = $conf['ispconfig_log_dir'].'/cron.log'; } + elseif($dist == 'gentoo') { $logfile = '/var/log/cron'; } break; case 'log_freshclam': - if($dist == 'debian') $logfile = '/var/log/clamav/freshclam.log'; - if($dist == 'redhat') $logfile = (is_file('/var/log/clamav/freshclam.log') ? '/var/log/clamav/freshclam.log' : '/var/log/freshclam.log'); - if($dist == 'suse') $logfile = ''; - if($dist == 'gentoo') $logfile = '/var/log/clamav/freshclam.log'; + if($dist == 'debian') { $logfile = '/var/log/clamav/freshclam.log'; } + elseif($dist == 'redhat') { $logfile = (is_file('/var/log/clamav/freshclam.log') ? '/var/log/clamav/freshclam.log' : '/var/log/freshclam.log'); } + elseif($dist == 'suse') { $logfile = ''; } + elseif($dist == 'gentoo') { $logfile = '/var/log/clamav/freshclam.log'; } break; case 'log_clamav': - if($dist == 'debian') $logfile = '/var/log/clamav/clamav.log'; - if($dist == 'redhat') $logfile = (is_file('/var/log/clamav/clamd.log') ? '/var/log/clamav/clamd.log' : '/var/log/maillog'); - if($dist == 'suse') $logfile = ''; - if($dist == 'gentoo') $logfile = '/var/log/clamav/clamd.log'; + if($dist == 'debian') { $logfile = '/var/log/clamav/clamav.log'; } + elseif($dist == 'redhat') { $logfile = (is_file('/var/log/clamav/clamd.log') ? '/var/log/clamav/clamd.log' : '/var/log/maillog'); } + elseif($dist == 'suse') { $logfile = ''; } + elseif($dist == 'gentoo') { $logfile = '/var/log/clamav/clamd.log'; } break; case 'log_fail2ban': - if($dist == 'debian') $logfile = '/var/log/fail2ban.log'; - if($dist == 'redhat') $logfile = '/var/log/fail2ban.log'; - if($dist == 'suse') $logfile = '/var/log/fail2ban.log'; - if($dist == 'gentoo') $logfile = '/var/log/fail2ban.log'; + if($dist == 'debian') { $logfile = '/var/log/fail2ban.log'; } + elseif($dist == 'redhat') { $logfile = '/var/log/fail2ban.log'; } + elseif($dist == 'suse') { $logfile = '/var/log/fail2ban.log'; } + elseif($dist == 'gentoo') { $logfile = '/var/log/fail2ban.log'; } break; case 'log_ispconfig': - if($dist == 'debian') $logfile = '/var/log/ispconfig/ispconfig.log'; - if($dist == 'redhat') $logfile = '/var/log/ispconfig/ispconfig.log'; - if($dist == 'suse') $logfile = '/var/log/ispconfig/ispconfig.log'; - if($dist == 'gentoo') $logfile = '/var/log/ispconfig/ispconfig.log'; + if($dist == 'debian') { $logfile = $conf['ispconfig_log_dir'].'/ispconfig.log'; } + elseif($dist == 'redhat') { $logfile = $conf['ispconfig_log_dir'].'/ispconfig.log'; } + elseif($dist == 'suse') { $logfile = $conf['ispconfig_log_dir'].'/ispconfig.log'; } + elseif($dist == 'gentoo') { $logfile = $conf['ispconfig_log_dir'].'/ispconfig.log'; } break; default: $logfile = ''; @@ -1682,7 +1712,7 @@ class monitor_core_module { else { $log = ''; if(is_readable($logfile)) { - if($fd = popen("tail -n 100 $logfile", 'r')) { + if($fd = popen('tail -n 100 '.$logfile, 'r')) { while (!feof($fd)) { $log .= fgets($fd, 4096); $n++; @@ -1743,11 +1773,11 @@ class monitor_core_module { $now = time(); $old = $now - ($min * 60) - ($hour * 60 * 60) - ($days * 24 * 60 * 60); - $sql = "DELETE FROM monitor_data " . - "WHERE " . - "type =" . "'" . $app->dbmaster->quote($type) . "' " . - "AND " . - "created < " . $old; + $sql = 'DELETE FROM monitor_data ' . + 'WHERE ' . + 'type =' . "'" . $app->dbmaster->quote($type) . "' " . + 'AND ' . + 'created < ' . $old; $app->dbmaster->query($sql); } -- GitLab