diff --git a/admin_admins.php b/admin_admins.php index fc7de9e1..f8219a54 100644 --- a/admin_admins.php +++ b/admin_admins.php @@ -18,7 +18,7 @@ */ define('AREA', 'admin'); -require ("./lib/init.php"); +require './lib/init.php'; if (isset($_POST['id'])) { $id = intval($_POST['id']); diff --git a/admin_aps.php b/admin_aps.php index 5f89cc7e..7f85d13d 100644 --- a/admin_aps.php +++ b/admin_aps.php @@ -20,7 +20,7 @@ // Required code define('AREA', 'admin'); -require ("./lib/init.php"); +require './lib/init.php'; $Id = 0; if(isset($_GET['id']))$Id = (int)$_GET['id']; diff --git a/admin_configfiles.php b/admin_configfiles.php index 3da7f611..48bb87f1 100644 --- a/admin_configfiles.php +++ b/admin_configfiles.php @@ -18,14 +18,10 @@ */ define('AREA', 'admin'); - -/** - * Include our init.php, which manages Sessions, Language etc. - */ - $need_db_sql_data = true; -require ("./lib/init.php"); -require ("./lib/configfiles_index.inc.php"); +require './lib/init.php'; +require './lib/configfiles_index.inc.php'; + $distribution = ''; $distributions_select = ''; $service = ''; diff --git a/admin_cronjobs.php b/admin_cronjobs.php index 9eac5100..4ccf0d78 100644 --- a/admin_cronjobs.php +++ b/admin_cronjobs.php @@ -16,7 +16,7 @@ */ define('AREA', 'admin'); -require_once('./lib/init.php'); +require './lib/init.php'; if (isset($_POST['id'])) { $id = intval($_POST['id']); diff --git a/admin_customers.php b/admin_customers.php index 65e59254..23a06d81 100644 --- a/admin_customers.php +++ b/admin_customers.php @@ -18,7 +18,7 @@ */ define('AREA', 'admin'); -require ("./lib/init.php"); +require './lib/init.php'; if (isset($_POST['id'])) { $id = intval($_POST['id']); diff --git a/admin_domains.php b/admin_domains.php index dccff90b..13b60ead 100644 --- a/admin_domains.php +++ b/admin_domains.php @@ -18,7 +18,7 @@ */ define('AREA', 'admin'); -require ("./lib/init.php"); +require './lib/init.php'; if (isset($_POST['id'])) { $id = intval($_POST['id']); diff --git a/admin_index.php b/admin_index.php index 1a0c539d..39925f54 100644 --- a/admin_index.php +++ b/admin_index.php @@ -18,7 +18,7 @@ */ define('AREA', 'admin'); -require ("./lib/init.php"); +require './lib/init.php'; if ($action == 'logout') { diff --git a/admin_ipsandports.php b/admin_ipsandports.php index 518df119..0908e4ef 100644 --- a/admin_ipsandports.php +++ b/admin_ipsandports.php @@ -18,7 +18,7 @@ */ define('AREA', 'admin'); -require ("./lib/init.php"); +require './lib/init.php'; if (isset($_POST['id'])) { $id = intval($_POST['id']); diff --git a/admin_logger.php b/admin_logger.php index d64f80da..256e444f 100644 --- a/admin_logger.php +++ b/admin_logger.php @@ -18,8 +18,7 @@ */ define('AREA', 'admin'); - -require('./lib/init.php'); +require './lib/init.php'; if ($page == 'log' && $userinfo['change_serversettings'] == '1' diff --git a/admin_message.php b/admin_message.php index 2cb63419..bd7213cf 100644 --- a/admin_message.php +++ b/admin_message.php @@ -18,7 +18,7 @@ */ define('AREA', 'admin'); -require('./lib/init.php'); +require './lib/init.php'; if (isset($_POST['id'])) { $id = intval($_POST['id']); diff --git a/admin_phpsettings.php b/admin_phpsettings.php index a3f1949f..01a52451 100644 --- a/admin_phpsettings.php +++ b/admin_phpsettings.php @@ -18,7 +18,7 @@ */ define('AREA', 'admin'); -require ("./lib/init.php"); +require './lib/init.php'; if (isset($_POST['id'])) { $id = intval($_POST['id']); diff --git a/admin_settings.php b/admin_settings.php index 092fc29a..8339b3e7 100644 --- a/admin_settings.php +++ b/admin_settings.php @@ -18,10 +18,9 @@ */ define('AREA', 'admin'); - $need_db_sql_data = true; $need_root_db_sql_data = true; -require ("./lib/init.php"); +require './lib/init.php'; if (($page == 'settings' || $page == 'overview') && $userinfo['change_serversettings'] == '1' diff --git a/admin_templates.php b/admin_templates.php index 73520a29..1ce0f26c 100644 --- a/admin_templates.php +++ b/admin_templates.php @@ -18,7 +18,7 @@ */ define('AREA', 'admin'); -require ("./lib/init.php"); +require './lib/init.php'; if (isset($_POST['subjectid'])) { $subjectid = intval($_POST['subjectid']); diff --git a/admin_tickets.php b/admin_tickets.php index ca48070b..4dd410b6 100644 --- a/admin_tickets.php +++ b/admin_tickets.php @@ -18,7 +18,7 @@ */ define('AREA', 'admin'); -require ("./lib/init.php"); +require './lib/init.php'; if (isset($_POST['id'])) { $id = intval($_POST['id']); diff --git a/admin_traffic.php b/admin_traffic.php index 3469a598..d6f6f7b8 100644 --- a/admin_traffic.php +++ b/admin_traffic.php @@ -17,8 +17,7 @@ */ define('AREA', 'admin'); - -require ("./lib/init.php"); +require './lib/init.php'; if ($action == 'logout') { $logout_stmt = Database::prepare(" diff --git a/admin_updates.php b/admin_updates.php index f4211613..153cfe0b 100644 --- a/admin_updates.php +++ b/admin_updates.php @@ -16,7 +16,7 @@ */ define('AREA', 'admin'); -require('./lib/init.php'); +require './lib/init.php'; if ($page == 'overview') { $log->logAction(ADM_ACTION, LOG_NOTICE, "viewed admin_updates"); diff --git a/customer_aps.php b/customer_aps.php index 4958de67..6b6c18eb 100644 --- a/customer_aps.php +++ b/customer_aps.php @@ -18,7 +18,7 @@ */ define('AREA', 'customer'); -require ('./lib/init.php'); +require './lib/init.php'; $Id = 0; if (isset($_GET['id'])) { diff --git a/customer_autoresponder.php b/customer_autoresponder.php index 1b3bee3f..2e6f460a 100644 --- a/customer_autoresponder.php +++ b/customer_autoresponder.php @@ -18,7 +18,7 @@ */ define('AREA', 'customer'); -require('./lib/init.php'); +require './lib/init.php'; if ($action == 'add') { // Create new autoresponder diff --git a/customer_domains.php b/customer_domains.php index 8269d77b..9659a2ff 100644 --- a/customer_domains.php +++ b/customer_domains.php @@ -18,7 +18,7 @@ */ define('AREA', 'customer'); -require ("./lib/init.php"); +require './lib/init.php'; if(isset($_POST['id'])) { $id = intval($_POST['id']); diff --git a/customer_email.php b/customer_email.php index 1451178a..282888f1 100644 --- a/customer_email.php +++ b/customer_email.php @@ -18,12 +18,7 @@ */ define('AREA', 'customer'); - -/** - * Include our init.php, which manages Sessions, Language etc. - */ - -require ("./lib/init.php"); +require './lib/init.php'; if (isset($_POST['id'])) { $id = intval($_POST['id']); diff --git a/customer_extras.php b/customer_extras.php index 0d747842..235a2e72 100644 --- a/customer_extras.php +++ b/customer_extras.php @@ -18,12 +18,7 @@ */ define('AREA', 'customer'); - -/** - * Include our init.php, which manages Sessions, Language etc. - */ - -require ("./lib/init.php"); +require './lib/init.php'; if(isset($_POST['id'])) { $id = intval($_POST['id']); diff --git a/customer_ftp.php b/customer_ftp.php index ef094894..3dbda933 100644 --- a/customer_ftp.php +++ b/customer_ftp.php @@ -18,11 +18,7 @@ */ define('AREA', 'customer'); - -/** - * Include our init.php, which manages Sessions, Language etc. - */ -require('./lib/init.php'); +require './lib/init.php'; $id = 0; if (isset($_POST['id'])) { diff --git a/customer_index.php b/customer_index.php index c4871568..b7e9ec89 100644 --- a/customer_index.php +++ b/customer_index.php @@ -18,11 +18,7 @@ */ define('AREA', 'customer'); - -/** - * Include our init.php, which manages Sessions, Language etc. - */ -require('./lib/init.php'); +require './lib/init.php'; if ($action == 'logout') { $log->logAction(USR_ACTION, LOG_NOTICE, 'logged out'); diff --git a/customer_mysql.php b/customer_mysql.php index 4cbc77f3..314cf74f 100644 --- a/customer_mysql.php +++ b/customer_mysql.php @@ -21,7 +21,7 @@ define('AREA', 'customer'); $need_db_sql_data = true; $need_root_db_sql_data = true; -require('./lib/init.php'); +require './lib/init.php'; if (isset($_POST['id'])) { $id = intval($_POST['id']); diff --git a/customer_tickets.php b/customer_tickets.php index f3211a0c..b02dee04 100644 --- a/customer_tickets.php +++ b/customer_tickets.php @@ -18,7 +18,7 @@ */ define('AREA', 'customer'); -require ("./lib/init.php"); +require './lib/init.php'; if (isset($_POST['id'])) { diff --git a/customer_traffic.php b/customer_traffic.php index 4836100d..3bb3e853 100644 --- a/customer_traffic.php +++ b/customer_traffic.php @@ -18,12 +18,8 @@ */ define('AREA', 'customer'); - -/** - * Include our init.php, which manages Sessions, Language etc. - */ $intrafficpage = 1; -require('./lib/init.php'); +require './lib/init.php'; $traffic = ''; $month = null; $year = null; diff --git a/index.php b/index.php index 9e7d7142..3532d639 100644 --- a/index.php +++ b/index.php @@ -18,11 +18,7 @@ */ define('AREA', 'login'); - -/** - * Include our init.php, which manages Sessions, Language etc. - */ -require ('./lib/init.php'); +require './lib/init.php'; if ($action == '') { $action = 'login'; @@ -32,13 +28,13 @@ if ($action == 'login') { if (isset($_POST['send']) && $_POST['send'] == 'send') { $loginname = validate($_POST['loginname'], 'loginname'); $password = validate($_POST['password'], 'password'); - + $stmt = Database::prepare("SELECT `loginname` AS `customer` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `loginname`= :loginname" ); Database::pexecute($stmt, array("loginname" => $loginname)); $row = $stmt->fetch(PDO::FETCH_ASSOC); - + if ($row['customer'] == $loginname) { $table = "`" . TABLE_PANEL_CUSTOMERS . "`"; $uid = 'customerid'; @@ -53,7 +49,7 @@ if ($action == 'login') { ); Database::pexecute($stmt, array("domain" => $domainname)); $row2 = $stmt->fetch(PDO::FETCH_ASSOC); - + if (isset($row2['customerid']) && $row2['customerid'] > 0) { $loginname = getCustomerDetail($row2['customerid'], 'loginname'); if ($loginname !== false) { @@ -177,7 +173,7 @@ if ($action == 'login') { $has_theme = true; } } - + $params = array( "hash" => $s, "userid" => $userinfo['userid'], @@ -187,7 +183,7 @@ if ($action == 'login') { "language" => $language, "adminsession" => $userinfo['adminsession'] ); - + if ($has_theme) { $params["theme"] = $theme; $stmt = Database::prepare("INSERT INTO `" . TABLE_PANEL_SESSIONS . "` @@ -274,7 +270,7 @@ if ($action == 'forgotpwd') { AND `email`= :email" ); Database::pexecute($result_stmt, array("loginname" => $loginname, "email" => $email)); - + if (Database::num_rows() > 0) { $adminchecked = true; } else { @@ -284,7 +280,7 @@ if ($action == 'forgotpwd') { if ($result_stmt !== null) { $user = $result_stmt->fetch(PDO::FETCH_ASSOC); - + /* Check whether user is banned */ if ($user['deactivated']) { $message = $lng['pwdreminder']['notallowed']; @@ -327,13 +323,13 @@ if ($action == 'forgotpwd') { $result_stmt = Database::prepare('SELECT `value` FROM `' . TABLE_PANEL_TEMPLATES . '` WHERE `adminid`= :adminid AND `language`= :lang - AND `templategroup`=\'mails\' + AND `templategroup`=\'mails\' AND `varname`=\'password_reset_subject\'' ); Database::pexecute($result_stmt, array("adminid" => $user['adminid'], "lang" => $def_language)); $result = $result_stmt->fetch(PDO::FETCH_ASSOC); $mail_subject = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $lng['pwdreminder']['subject']), $replace_arr)); - + $result_stmt = Database::prepare('SELECT `value` FROM `' . TABLE_PANEL_TEMPLATES . '` WHERE `adminid`= :adminid AND `language`= :lang @@ -343,7 +339,7 @@ if ($action == 'forgotpwd') { Database::pexecute($result_stmt, array("adminid" => $user['adminid'], "lang" => $def_language)); $result = $result_stmt->fetch(PDO::FETCH_ASSOC); $mail_body = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $body), $replace_arr)); - + $_mailerror = false; try { $mail->Subject = $mail_subject; diff --git a/scripts/froxlor_master_cronjob.php b/scripts/froxlor_master_cronjob.php index b5000846..141f20db 100644 --- a/scripts/froxlor_master_cronjob.php +++ b/scripts/froxlor_master_cronjob.php @@ -32,7 +32,7 @@ if (isset($argv[1]) && strtolower($argv[1]) == '--help') { } /** - * check for --force to include cron_tasks + * check for --force to include cron_tasks * even if it's not its turn */ for ($x = 1; $x < count($argv); $x++) { @@ -56,7 +56,7 @@ for ($x = 1; $x < count($argv); $x++) { } foreach ($jobs_to_run as $cron) { - require_once($cron); + require_once $cron; } fwrite($debugHandler, 'Cronfiles have been included' . "\n"); diff --git a/scripts/jobs/cron_tasks.php b/scripts/jobs/cron_tasks.php index e69cc329..b9589ad1 100644 --- a/scripts/jobs/cron_tasks.php +++ b/scripts/jobs/cron_tasks.php @@ -20,13 +20,13 @@ /* * necessary includes */ -require_once(makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.dns.10.bind.php')); -require_once(makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.http.10.apache.php')); -require_once(makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.http.15.apache_fcgid.php')); -require_once(makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.http.20.lighttpd.php')); -require_once(makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.http.25.lighttpd_fcgid.php')); -require_once(makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.http.30.nginx.php')); -require_once(makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.http.35.nginx_phpfpm.php')); +require_once makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.dns.10.bind.php'); +require_once makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.http.10.apache.php'); +require_once makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.http.15.apache_fcgid.php'); +require_once makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.http.20.lighttpd.php'); +require_once makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.http.25.lighttpd_fcgid.php'); +require_once makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.http.30.nginx.php'); +require_once makeCorrectFile(dirname(__FILE__) . '/cron_tasks.inc.http.35.nginx_phpfpm.php'); /** * LOOK INTO TASKS TABLE TO SEE IF THERE ARE ANY UNDONE JOBS diff --git a/scripts/jobs/cron_traffic.php b/scripts/jobs/cron_traffic.php index b93aa66a..63f07532 100644 --- a/scripts/jobs/cron_traffic.php +++ b/scripts/jobs/cron_traffic.php @@ -17,128 +17,118 @@ * */ -//Check Traffic-Lock -if(function_exists('pcntl_fork')) { - $TrafficLock = dirname($lockfile)."/froxlor_cron_traffic.lock"; - if(file_exists($TrafficLock) && is_numeric($TrafficPid=file_get_contents($TrafficLock))) { - if(function_exists('posix_kill')) { +// Check Traffic-Lock +if (function_exists('pcntl_fork')) { + $TrafficLock = makeCorrectFile(dirname($lockfile)."/froxlor_cron_traffic.lock"); + if (file_exists($TrafficLock) + && is_numeric($TrafficPid=file_get_contents($TrafficLock)) + ) { + if (function_exists('posix_kill')) { $TrafficPidStatus = @posix_kill($TrafficPid,0); - } - else { + } else { system("kill -CHLD " . $TrafficPid . " 1> /dev/null 2> /dev/null", $TrafficPidStatus); $TrafficPidStatus = $TrafficPidStatus ? false : true; } - if($TrafficPidStatus) { + if ($TrafficPidStatus) { fwrite($debugHandler,"Traffic Run already in progress\n"); return 1; } } - //Create Traffic Log and Fork + // Create Traffic Log and Fork // We close the database - connection before we fork, so we don't share resources with the child - $db->close(); - unset($db); + Database::needRoot(false); // this forces the connection to be set to null $TrafficPid = pcntl_fork(); - if($TrafficPid) { //Parent - file_put_contents($TrafficLock,$TrafficPid); - // Recreate the database - connection - require ($pathtophpfiles . '/lib/userdata.inc.php'); - if(isset($sql['root_user']) && isset($sql['root_password']) && (!isset($sql_root) || !is_array($sql_root))) { - $sql_root = array(0 => array('caption' => 'Default', 'host' => $sql['host'], 'user' => $sql['root_user'], 'password' => $sql['root_password'])); - unset($sql['root_user']); - unset($sql['root_password']); - } - $db = new db($sql['host'], $sql['user'], $sql['password'], $sql['db']); + // Parent + if ($TrafficPid) { + file_put_contents($TrafficLock, $TrafficPid); + // unnecessary to recreate database connection here return 0; + } - elseif($TrafficPid == 0) { //Child + //Child + elseif ($TrafficPid == 0) { posix_setsid(); fclose($debugHandler); - $debugHandler = fopen("/tmp/froxlor_traffic.log","w"); - require ($pathtophpfiles . '/lib/userdata.inc.php'); //There is no bloody reason not to have sql values in the backend ready! - if(isset($sql['root_user']) && isset($sql['root_password']) && (!isset($sql_root) || !is_array($sql_root))) { - $sql_root = array(0 => array('caption' => 'Default', 'host' => $sql['host'], 'user' => $sql['root_user'], 'password' => $sql['root_password'])); - unset($sql['root_user']); - unset($sql['root_password']); - } - $db = new db($sql['host'], $sql['user'], $sql['password'], $sql['db']); //database handler renewal after fork() + $debugHandler = fopen("/tmp/froxlor_traffic.log", "w"); + // re-create db + Database::needRoot(false); } - else { //Fork failed + //Fork failed + else { return 1; } -} -else { + +} else { fwrite($debugHandler,"PHP compiled without pcntl. Not forking traffic-cron, this may take a long time!"); } -openRootDB($debugHandler, $lockfile); -require_once(makeCorrectFile(dirname(__FILE__) . '/cron_traffic.inc.functions.php')); + +require_once makeCorrectFile(dirname(__FILE__) . '/cron_traffic.inc.functions.php'); /** * TRAFFIC AND DISKUSAGE MESSURE */ - fwrite($debugHandler, 'Traffic run started...' . "\n"); $admin_traffic = array(); $domainlist = array(); $speciallogfile_domainlist = array(); -$result_domainlist = $db->query("SELECT `id`, `domain`, `customerid`, `parentdomainid`, `speciallogfile` FROM `" . TABLE_PANEL_DOMAINS . "` WHERE `aliasdomain` IS NULL AND `email_only` <> '1' ;"); +$result_domainlist_stmt = Database::query(" + SELECT `id`, `domain`, `customerid`, `parentdomainid`, `speciallogfile` + FROM `" . TABLE_PANEL_DOMAINS . "` WHERE `aliasdomain` IS NULL AND `email_only` <> '1'; +"); -while($row_domainlist = $db->fetch_array($result_domainlist)) -{ - if(!isset($domainlist[$row_domainlist['customerid']])) - { +while ($row_domainlist = $result_domainlist_stmt->fetch(PDO::FETCH_ASSOC)) { + + if (!isset($domainlist[$row_domainlist['customerid']])) { $domainlist[$row_domainlist['customerid']] = array(); } $domainlist[$row_domainlist['customerid']][$row_domainlist['id']] = $row_domainlist['domain']; - if($row_domainlist['parentdomainid'] == '0' - && $row_domainlist['speciallogfile'] == '1') - { - if(!isset($speciallogfile_domainlist[$row_domainlist['customerid']])) - { + if ($row_domainlist['parentdomainid'] == '0' + && $row_domainlist['speciallogfile'] == '1' + ) { + if (!isset($speciallogfile_domainlist[$row_domainlist['customerid']])) { $speciallogfile_domainlist[$row_domainlist['customerid']] = array(); } - $speciallogfile_domainlist[$row_domainlist['customerid']][$row_domainlist['id']] = $row_domainlist['domain']; } } $mysqlusage_all = array(); -$databases = $db->query("SELECT * FROM " . TABLE_PANEL_DATABASES . " ORDER BY `dbserver`"); -$db_root = new db($sql_root[0]['host'], $sql_root[0]['user'], $sql_root[0]['password'], ''); +$databases_stmt = Database::query("SELECT * FROM " . TABLE_PANEL_DATABASES . " ORDER BY `dbserver`"); $last_dbserver = 0; $databases_list = array(); -$databases_list_result = $db_root->query("show databases"); -while ($databases_list_row = $db->fetch_array($databases_list_result)) { +Database::needRoot(true); +$databases_list_result_stmt = Database::query("SHOW DATABASES"); +while ($databases_list_row = $databases_list_result_stmt->fetch(PDO::FETCH_ASSOC)) { $databases_list[] = strtolower($databases_list_row['Database']); } -while ($row_database = $db->fetch_array($databases)) { +while ($row_database = $databases_stmt->fetch(PDO::FETCH_ASSOC)) { if ($last_dbserver != $row_database['dbserver']) { - $db_root->close(); - $db_root = new db($sql_root[$row_database['dbserver']]['host'], $sql_root[$row_database['dbserver']]['user'], $sql_root[$row_database['dbserver']]['password'], ''); + Database::needRoot(true, $row_database['dbserver']); $last_dbserver = $row_database['dbserver']; $database_list = array(); - $databases_list_result = $db_root->query("show databases"); - while ($databases_list_row = $db->fetch_array($databases_list_result)) { + $databases_list_result_stmt = Database::query("SHOW DATABASES"); + while ($databases_list_row = $databases_list_result_stmt->fetch(PDO::FETCH_ASSOC)) { $databases_list[] = strtolower($databases_list_row['Database']); } } if (in_array(strtolower($row_database['databasename']), $databases_list)) { // sum up data_length and index_length - $mysql_usage_result = $db_root->query(" + $mysql_usage_result_stmt = Database::prepare(" SELECT SUM(data_length + index_length) AS customerusage FROM information_schema.TABLES - WHERE table_schema = '" . $db_root->escape($row_database['databasename']) . "' + WHERE table_schema = :database GROUP BY table_schema; "); // get the result - $mysql_usage_row = $db_root->fetch_array($mysql_usage_result); + $mysql_usage_row = Database::pexecute_first($mysql_usage_result_stmt, array('database' => $row_database['databasename'])); // initialize counter for customer if (!isset($mysqlusage_all[$row_database['customerid']])) { $mysqlusage_all[$row_database['customerid']] = 0; @@ -150,20 +140,19 @@ while ($row_database = $db->fetch_array($databases)) { } } -$db_root->close(); +Database::needRoot(false); // We are using the file-system quota, this will speed up the diskusage - collection if ($settings['system']['diskquota_enabled']) { $usedquota = getFilesystemQuota(); } -$result = $db->query("SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "` ORDER BY `customerid` ASC"); +$result_stmt = Database::query("SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "` ORDER BY `customerid` ASC"); -while ($row = $db->fetch_array($result)) { +while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { /** * HTTP-Traffic */ - fwrite($debugHandler, 'http traffic for ' . $row['loginname'] . ' started...' . "\n"); $httptraffic = 0; @@ -220,40 +209,17 @@ while ($row = $db->fetch_array($result)) { // make the stuff readable for the customer, #258 makeChownWithNewStats($row); - - /** - * Webalizer/AWStats might run for some time, so we'd better check if our database is still present - */ - if (empty($db->link_id) - || $db->link_id === false - ) { - fwrite($debugHandler, 'Database-connection seems to be down, trying to reconnect' . "\n"); - - // just in case - $db->close(); - require_once ($pathtophpfiles . '/lib/userdata.inc.php'); - $db = new db($sql['host'], $sql['user'], $sql['password'], $sql['db']); - - if ($db->link_id == 0) { - fclose($debugHandler); - unlink($lockfile); - $cronlog->logAction(CRON_ACTION, LOG_ERR, 'Database-connection crashed during traffic-cronjob, could not reconnect!'); - die('Froxlor can\'t connect to mysqlserver. Exiting...'); - } - - fwrite($debugHandler, 'Database-connection re-established' . "\n"); - unset($sql); - $cronlog->logAction(CRON_ACTION, LOG_WARNING, 'Database-connection crashed during traffic-cronjob, reconnected!'); - } - } /** * FTP-Traffic */ - fwrite($debugHandler, 'ftp traffic for ' . $row['loginname'] . ' started...' . "\n"); - $ftptraffic = $db->query_first("SELECT SUM(`up_bytes`) AS `up_bytes_sum`, SUM(`down_bytes`) AS `down_bytes_sum` FROM `" . TABLE_FTP_USERS . "` WHERE `customerid`='" . (int)$row['customerid'] . "'"); + $ftptraffic_stmt = Database::prepare(" + SELECT SUM(`up_bytes`) AS `up_bytes_sum`, SUM(`down_bytes`) AS `down_bytes_sum` + FROM `" . TABLE_FTP_USERS . "` WHERE `customerid` = :customerid + "); + $ftptraffic = Database::pexecute_first($ftptraffic_stmt, array('customerid' => $row['customerid'])); if (!is_array($ftptraffic)) { $ftptraffic = array( @@ -262,18 +228,19 @@ while ($row = $db->fetch_array($result)) { ); } - $db->query("UPDATE `" . TABLE_FTP_USERS . "` SET `up_bytes`='0', `down_bytes`='0' WHERE `customerid`='" . (int)$row['customerid'] . "'"); + $upd_stmt = Database::prepare(" + UPDATE `" . TABLE_FTP_USERS . "` SET `up_bytes` = '0', `down_bytes` = '0' WHERE `customerid` = :customerid + "); + Database::pexecute($upd_stmt, array('customerid' => $row['customerid'])); /** * Mail-Traffic */ - $mailtraffic = 0; /** * Total Traffic */ - fwrite($debugHandler, 'total traffic for ' . $row['loginname'] . ' started' . "\n"); $current_traffic = array(); $current_traffic['http'] = floatval($httptraffic); @@ -281,13 +248,42 @@ while ($row = $db->fetch_array($result)) { $current_traffic['ftp_down'] = floatval(($ftptraffic['down_bytes_sum'] / 1024)); $current_traffic['mail'] = floatval($mailtraffic); $current_traffic['all'] = $current_traffic['http'] + $current_traffic['ftp_up'] + $current_traffic['ftp_down'] + $current_traffic['mail']; - $db->query("INSERT INTO `" . TABLE_PANEL_TRAFFIC . "` (`customerid`, `year`, `month`, `day`, `stamp`, `http`, `ftp_up`, `ftp_down`, `mail`) VALUES('" . (int)$row['customerid'] . "', '" . date('Y') . "', '" . date('m') . "', '" . date('d') . "', '" . time() . "', '" . (float)$current_traffic['http'] . "', '" . (float)$current_traffic['ftp_up'] . "', '" . (float)$current_traffic['ftp_down'] . "', '" . (float)$current_traffic['mail'] . "')"); - $sum_month_traffic = $db->query_first("SELECT SUM(`http`) AS `http`, SUM(`ftp_up`) AS `ftp_up`, SUM(`ftp_down`) AS `ftp_down`, SUM(`mail`) AS `mail` FROM `" . TABLE_PANEL_TRAFFIC . "` WHERE `year`='" . date('Y') . "' AND `month`='" . date('m') . "' AND `customerid`='" . (int)$row['customerid'] . "'"); + + $ins_data = array( + 'customerid' => $row['customerid'], + 'year' => date('Y', time()), + 'month' => date('m', time()), + 'day' => date('d', time()), + 'stamp' => $time(), + 'http' => $current_traffic['http'], + 'ftp_up' => $current_traffic['ftp_up'], + 'ftp_down' => $current_traffic['ftp_down'], + 'mail' => $current_traffic['mail'] + ); + $ins_stmt = Database::prepare(" + INSERT INTO `" . TABLE_PANEL_TRAFFIC . "` SET + `customerid` = :customerid, + `year` = :year, + `month` = :month, + `day` = :day, + `stamp` = :stamp, + `http` = :http, + `ftp_up` = :ftp_up, + `ftp_down` = :ftp_down, + `mail` = :mail + "); + Database::pexecute($ins_stmt, $ins_data); + + $sum_month_traffic_stmt = Database::prepare(" + SELECT SUM(`http`) AS `http`, SUM(`ftp_up`) AS `ftp_up`, SUM(`ftp_down`) AS `ftp_down`, SUM(`mail`) AS `mail` + FROM `" . TABLE_PANEL_TRAFFIC . "` WHERE `year` = :year AND `month` = :month AND `customerid` = :customerid + "); + $sum_month_traffic = Database::pexecute_first($sum_month_traffic_stmt, array('year' => date('Y', time()), 'month' => date('m', time()), 'customerid' => $row['customerid'])); $sum_month_traffic['all'] = $sum_month_traffic['http'] + $sum_month_traffic['ftp_up'] + $sum_month_traffic['ftp_down'] + $sum_month_traffic['mail']; - if(!isset($admin_traffic[$row['adminid']]) - || !is_array($admin_traffic[$row['adminid']])) - { + if (!isset($admin_traffic[$row['adminid']]) + || !is_array($admin_traffic[$row['adminid']]) + ) { $admin_traffic[$row['adminid']]['http'] = 0; $admin_traffic[$row['adminid']]['ftp_up'] = 0; $admin_traffic[$row['adminid']]['ftp_down'] = 0; @@ -306,32 +302,32 @@ while ($row = $db->fetch_array($result)) { /** * WebSpace-Usage */ - fwrite($debugHandler, 'calculating webspace usage for ' . $row['loginname'] . "\n"); $webspaceusage = 0; - # Using repquota, it's faster using this tool than using du traversing the complete directory - if ($settings['system']['diskquota_enabled'] && isset($usedquota[$row['guid']]['block']['used']) && $usedquota[$row['guid']]['block']['used'] >= 1) - { - # We may use the array we created earlier, the used diskspace is stored in [][block][used] + // Using repquota, it's faster using this tool than using du traversing the complete directory + if ($settings['system']['diskquota_enabled'] + && isset($usedquota[$row['guid']]['block']['used']) + && $usedquota[$row['guid']]['block']['used'] >= 1 + ) { + // We may use the array we created earlier, the used diskspace is stored in [][block][used] $webspaceusage = floatval($usedquota[$row['guid']]['block']['used']); - } - else - { - # Use the old fashioned way with "du" - if(file_exists($row['documentroot']) && is_dir($row['documentroot'])) - { + + } else { + + // Use the old fashioned way with "du" + if (file_exists($row['documentroot']) + && is_dir($row['documentroot']) + ) { $back = safe_exec('du -sk ' . escapeshellarg($row['documentroot']) . ''); - foreach($back as $backrow) - { + foreach ($back as $backrow) { $webspaceusage = explode(' ', $backrow); } $webspaceusage = floatval($webspaceusage['0']); unset($back); - } - else - { + + } else { fwrite($debugHandler, 'documentroot ' . $row['documentroot'] . ' does not exist' . "\n"); } } @@ -339,36 +335,30 @@ while ($row = $db->fetch_array($result)) { /** * MailSpace-Usage */ - fwrite($debugHandler, 'calculating mailspace usage for ' . $row['loginname'] . "\n"); $emailusage = 0; $maildir = makeCorrectDir($settings['system']['vmail_homedir'] . $row['loginname']); - if(file_exists($maildir) && is_dir($maildir)) - { + if (file_exists($maildir) && is_dir($maildir)) { $back = safe_exec('du -sk ' . escapeshellarg($maildir) . ''); - foreach($back as $backrow) - { + foreach ($back as $backrow) { $emailusage = explode(' ', $backrow); } $emailusage = floatval($emailusage['0']); unset($back); - } - else - { + + } else { fwrite($debugHandler, 'maildir ' . $maildir . ' does not exist' . "\n"); } /** * MySQLSpace-Usage */ - fwrite($debugHandler, 'calculating mysqlspace usage for ' . $row['loginname'] . "\n"); $mysqlusage = 0; - if(isset($mysqlusage_all[$row['customerid']])) - { + if (isset($mysqlusage_all[$row['customerid']])) { $mysqlusage = floatval($mysqlusage_all[$row['customerid']] / 1024); } @@ -377,11 +367,33 @@ while ($row = $db->fetch_array($result)) { $current_diskspace['mail'] = floatval($emailusage); $current_diskspace['mysql'] = floatval($mysqlusage); $current_diskspace['all'] = $current_diskspace['webspace'] + $current_diskspace['mail'] + $current_diskspace['mysql']; - $db->query("INSERT INTO `" . TABLE_PANEL_DISKSPACE . "` (`customerid`, `year`, `month`, `day`, `stamp`, `webspace`, `mail`, `mysql`) VALUES('" . (int)$row['customerid'] . "', '" . date('Y') . "', '" . date('m') . "', '" . date('d') . "', '" . time() . "', '" . (float)$current_diskspace['webspace'] . "', '" . (float)$current_diskspace['mail'] . "', '" . (float)$current_diskspace['mysql'] . "')"); - if(!isset($admin_diskspace[$row['adminid']]) - || !is_array($admin_diskspace[$row['adminid']])) - { + $ins_data = array( + 'customerid' => $row['customerid'], + 'year' => date('Y', time()), + 'month' => date('m', time()), + 'day' => date('d', time()), + 'stamp' => time(), + 'webspace' => $current_diskspace['webspace'], + 'mail' => $current_diskspace['mail'], + 'mysql' => $current_diskspace['mysql'] + ); + $ins_stmt = Database::preapre(" + INSERT INTO `" . TABLE_PANEL_DISKSPACE . "` SET + `customerid` = :customerid, + `year` = :year, + `month` = :month, + `day` = :day, + `stamp` = :stamp, + `webspace` = :webspace, + `mail` = :mail, + `mysql` = :mysql + "); + Database::pexecute($ins_stmt, $ins_data); + + if (!isset($admin_diskspace[$row['adminid']]) + || !is_array($admin_diskspace[$row['adminid']]) + ) { $admin_diskspace[$row['adminid']] = array(); $admin_diskspace[$row['adminid']]['webspace'] = 0; $admin_diskspace[$row['adminid']]['mail'] = 0; @@ -397,45 +409,64 @@ while ($row = $db->fetch_array($result)) { /** * Total Usage */ - - if($settings['system']['backup_count'] == 0 && file_exists($settings['system']['backup_dir'] . $row['loginname'])){ + if ($settings['system']['backup_count'] == 0 + && file_exists($settings['system']['backup_dir'] . $row['loginname']) + ) { $backupsize = exec('du -s ' . escapeshellarg($settings['system']['backup_dir']) . $row['loginname'] . ''); - $diskusage = floatval($webspaceusage + $emailusage + $mysqlusage - $backupsize); - } - else{ + $diskusage = floatval($webspaceusage + $emailusage + $mysqlusage - $backupsize); + } else { $diskusage = floatval($webspaceusage + $emailusage + $mysqlusage); - } + } - $db->query("UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `diskspace_used`='" . (float)$current_diskspace['all'] . "', `traffic_used`='" . (float)$sum_month_traffic['all'] . "' WHERE `customerid`='" . (int)$row['customerid'] . "'"); + $upd_data = array( + 'diskspace' => $current_diskspace['all'], + 'traffic' => $sum_month_traffic['all'], + 'customerid' => $row['customerid'] + ); + $upd_stmt = Database::prepare(" + UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET + `diskspace_used` = :diskspace, + `traffic_used` = :traffic + WHERE `customerid` = :customerid + "); + Database::pexecute($upd_stmt, $upd_data); /** * Proftpd Quota */ - - $db->query("UPDATE `" . TABLE_FTP_QUOTATALLIES . "` SET `bytes_in_used`='" . (float)$current_diskspace['all'] . "'*1024 WHERE `name` = '" . $row['loginname'] . "' OR `name` LIKE '" . $row['loginname'] . $settings['customer']['ftpprefix'] . "%'"); + $upd_data = array( + 'biu' => ($current_diskspace['all'] * 1024), + 'loginname' => $row['loginname'], + 'loginnamelike' => $row['loginname'] . $settings['customer']['ftpprefix'] . "%" + ); + $upd_stmt = Database::prepare(" + UPDATE `" . TABLE_FTP_QUOTATALLIES . "` SET + `bytes_in_used` = :biu WHERE `name` = :loginname OR `name` LIKE :loginnamelike + "); + Database::pexecute($upd_stmt, $upd_data); /** * Pureftpd Quota */ + if ($settings['system']['ftpserver'] == "pureftpd") { - if($settings['system']['ftpserver'] == "pureftpd") - { - $result_quota = $db->query("SELECT homedir FROM `" . TABLE_FTP_USERS . "` WHERE customerid = '" . $row['customerid'] . "'"); + $result_quota_stmt = Database::prepare(" + SELECT homedir FROM `" . TABLE_FTP_USERS . "` WHERE customerid = :customerid + "); + Database::pexecute($result_quota_stmt, array('customerid' => $row['customerid'])); - // get correct user - if($settings['system']['mod_fcgid'] == 1 && $row['deactivated'] == '0') - { - $user = $row['loginname']; - $group = $row['loginname']; - } - else - { - $user = $row['guid']; - $group = $row['guid']; - } + // get correct user + if ($settings['system']['mod_fcgid'] == 1 + && $row['deactivated'] == '0' + ) { + $user = $row['loginname']; + $group = $row['loginname']; + } else { + $user = $row['guid']; + $group = $row['guid']; + } - while($row_quota = $db->fetch_array($result_quota)) - { + while ($row_quota = $result_quota_stmt->fetch(PDO::FETCH_ASSOC)) { $quotafile = "" . $row_quota['homedir'] . ".ftpquota"; $fh = fopen($quotafile, 'w'); $stringdata = "0 " . $current_diskspace['all']*1024 . ""; @@ -449,27 +480,88 @@ while ($row = $db->fetch_array($result)) { /** * Admin Usage */ +$result_stmt = Database::query("SELECT `adminid` FROM `" . TABLE_PANEL_ADMINS . "` ORDER BY `adminid` ASC"); -$result = $db->query("SELECT `adminid` FROM `" . TABLE_PANEL_ADMINS . "` ORDER BY `adminid` ASC"); +while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { -while($row = $db->fetch_array($result)) -{ - if(isset($admin_traffic[$row['adminid']])) - { - $db->query("INSERT INTO `" . TABLE_PANEL_TRAFFIC_ADMINS . "` (`adminid`, `year`, `month`, `day`, `stamp`, `http`, `ftp_up`, `ftp_down`, `mail`) VALUES('" . (int)$row['adminid'] . "', '" . date('Y') . "', '" . date('m') . "', '" . date('d') . "', '" . time() . "', '" . (float)$admin_traffic[$row['adminid']]['http'] . "', '" . (float)$admin_traffic[$row['adminid']]['ftp_up'] . "', '" . (float)$admin_traffic[$row['adminid']]['ftp_down'] . "', '" . (float)$admin_traffic[$row['adminid']]['mail'] . "')"); - $db->query("UPDATE `" . TABLE_PANEL_ADMINS . "` SET `traffic_used`='" . (float)$admin_traffic[$row['adminid']]['sum_month'] . "' WHERE `adminid`='" . (float)$row['adminid'] . "'"); + if (isset($admin_traffic[$row['adminid']])) { + + $ins_data = array( + 'adminid' => $row['adminid'], + 'year' => date('Y', time()), + 'month' => date('m', time()), + 'day' => date('d', time()), + 'stamp' => $time(), + 'http' => $admin_traffic[$row['adminid']]['http'], + 'ftp_up' => $admin_traffic[$row['adminid']]['ftp_up'], + 'ftp_down' => $admin_traffic[$row['adminid']]['ftp_down'], + 'mail' => $admin_traffic[$row['adminid']]['mail'] + ); + $ins_stmt = Database::prepare(" + INSERT INTO `" . TABLE_PANEL_TRAFFIC_ADMINS . "` SET + `adminid` = :adminid, + `year` = :year, + `month` = :month, + `day` = :day, + `stamp` = :stamp, + `http` = :http, + `ftp_up` = :ftp_up, + `ftp_down` = :ftp_down, + `mail` = :mail + "); + Database::pexecute($ins_stmt, $ins_data); + + $upd_data = array( + 'traffic' => $admin_traffic[$row['adminid']]['sum_month'], + 'adminid' => $row['adminid'] + ); + $upd_stmt = Database::prepare(" + UPDATE `" . TABLE_PANEL_ADMINS . "` SET + `traffic_used` = :traffic + WHERE `adminid` = :adminid + "); + Database::pexecute($upd_stmt, $upd_data); } - if(isset($admin_diskspace[$row['adminid']])) - { - $db->query("INSERT INTO `" . TABLE_PANEL_DISKSPACE_ADMINS . "` (`adminid`, `year`, `month`, `day`, `stamp`, `webspace`, `mail`, `mysql`) VALUES('" . (int)$row['adminid'] . "', '" . date('Y') . "', '" . date('m') . "', '" . date('d') . "', '" . time() . "', '" . (float)$admin_diskspace[$row['adminid']]['webspace'] . "', '" . (float)$admin_diskspace[$row['adminid']]['mail'] . "', '" . (float)$admin_diskspace[$row['adminid']]['mysql'] . "')"); - $db->query("UPDATE `" . TABLE_PANEL_ADMINS . "` SET `diskspace_used`='" . (float)$admin_diskspace[$row['adminid']]['all'] . "' WHERE `adminid`='" . (float)$row['adminid'] . "'"); + if (isset($admin_diskspace[$row['adminid']])) { + + $ins_data = array( + 'adminid' => $row['adminid'], + 'year' => date('Y', time()), + 'month' => date('m', time()), + 'day' => date('d', time()), + 'stamp' => time(), + 'webspace' => $admin_diskspace[$row['adminid']]['webspace'], + 'mail' => $admin_diskspace[$row['adminid']]['mail'], + 'mysql' => $admin_diskspace[$row['adminid']]['mysql'] + ); + $ins_stmt = Database::preapre(" + INSERT INTO `" . TABLE_PANEL_DISKSPACE_ADMINS . "` SET + `adminid` = :adminid, + `year` = :year, + `month` = :month, + `day` = :day, + `stamp` = :stamp, + `webspace` = :webspace, + `mail` = :mail, + `mysql` = :mysql + "); + + $upd_data = array( + 'diskspace' => $admin_diskspace[$row['adminid']]['all'], + 'adminid' => $row['adminid'] + ); + $upd_stmt = Database::prepare(" + UPDATE `" . TABLE_PANEL_ADMINS . "` SET + `diskspace_used` = :diskspace + WHERE `adminid` = :adminid + "); + Database::pexecute($upd_stmt, $upd_data); + } } -$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . '` SET `value` = UNIX_TIMESTAMP() WHERE `settinggroup` = \'system\' AND `varname` = \'last_traffic_run\' '); - -closeRootDB(); +Database::query("UPDATE `" . TABLE_PANEL_SETTINGS . "` SET `value` = UNIX_TIMESTAMP() WHERE `settinggroup` = 'system' AND `varname` = 'last_traffic_run'"); if (function_exists('pcntl_fork')) { @unlink($TrafficLock); diff --git a/scripts/jobs/cron_usage.inc.diskspace.php b/scripts/jobs/cron_usage.inc.diskspace.php index 3ed11638..611654e4 100644 --- a/scripts/jobs/cron_usage.inc.diskspace.php +++ b/scripts/jobs/cron_usage.inc.diskspace.php @@ -18,19 +18,20 @@ /** * report about diskusage for customers */ -$result = $db->query("SELECT - `c`.`customerid`, `c`.`adminid`, `c`.`name`, `c`.`firstname`, `c`.`company`, `c`.`diskspace`, - `c`.`diskspace_used`, `c`.`email`, `c`.`def_language`, +$result_stmt = Database::query(" + SELECT `c`.`customerid`, `c`.`adminid`, `c`.`name`, `c`.`firstname`, + `c`.`company`, `c`.`diskspace`, `c`.`diskspace_used`, `c`.`email`, `c`.`def_language`, `a`.`name` AS `adminname`, `a`.`email` AS `adminmail` FROM `" . TABLE_PANEL_CUSTOMERS . "` AS `c` - LEFT JOIN `" . TABLE_PANEL_ADMINS . "` AS `a` + LEFT JOIN `" . TABLE_PANEL_ADMINS . "` AS `a` ON `a`.`adminid` = `c`.`adminid` - WHERE `c`.`diskspace` > '0' AND `c`.`reportsent` <> '2'"); + WHERE `c`.`diskspace` > '0' AND `c`.`reportsent` <> '2' +"); -while($row = $db->fetch_array($result)) -{ - if(isset($row['diskspace']) - && $row['diskspace_used'] != NULL +while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { + + if (isset($row['diskspace']) + && $row['diskspace_used'] != null && $row['diskspace_used'] > 0 && (($row['diskspace_used'] * 100) / $row['diskspace']) >= (int)$settings['system']['report_webmax'] ) { @@ -49,18 +50,16 @@ while($row = $db->fetch_array($result)) 'MAX_PERCENT' => $settings['system']['report_webmax'] ); - $lngfile = $db->query_first(" + $lngfile_stmt = Database::prepare(" SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "` - WHERE `language` ='" . $row['def_language'] . "' + WHERE `language` = :deflang "); + $lngfile = Database::pexecute_first($lngfile_stmt, array('deflang' => $row['def_language'])); if ($lngfile !== null) { $langfile = $lngfile['file']; } else { - $lngfile = $db->query_first(" - SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "` - WHERE `language` ='" . $settings['panel']['standardlanguage'] . "' - "); + $lngfile = Database::pexecute_first($lngfile_stmt, array('deflang' => $settings['panel']['standardlanguage'])); $langfile = $lngfile['file']; } @@ -70,18 +69,22 @@ while($row = $db->fetch_array($result)) include_once makeCorrectFile($pathtophpfiles . '/' . $langfile); // Get mail templates from database; the ones from 'admin' are fetched for fallback - $result2 = $db->query_first("SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "` - WHERE `adminid`='" . (int)$row['adminid'] . "' - AND `language`='" . $db->escape($row['def_language']) . "' - AND `templategroup`='mails' - AND `varname`='diskmaxpercent_subject'"); + $result2_stmt = Database::prepare(" + SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "` + WHERE `adminid` = :adminid + AND `language` = :lang + AND `templategroup` = 'mails' AND `varname` = :varname + "); + $resul2_data = array( + 'adminid' => $row['adminid'], + 'lang' => $row['def_language'], + 'varname' => 'diskmaxpercent_subject' + ); + $result2 = Database::pexecute_first($result2_stmt, $result2_data); $mail_subject = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['webmaxpercent']['subject']), $replace_arr)); - $result2 = $db->query_first("SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "` - WHERE `adminid`='" . (int)$row['adminid'] . "' - AND `language`='" . $db->escape($row['def_language']) . "' - AND `templategroup`='mails' - AND `varname`='diskmaxpercent_mailbody'"); + $resul2_data['varname'] = 'diskmaxpercent_mailbody'; + $result2 = Database::pexecute_first($result2_stmt, $result2_data); $mail_body = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['webmaxpercent']['mailbody']), $replace_arr)); $_mailerror = false; @@ -106,20 +109,25 @@ while($row = $db->fetch_array($result)) } $mail->ClearAddresses(); - $db->query("UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `reportsent`='2' - WHERE `customerid`='" . (int)$row['customerid'] . "'"); + $upd_stmt = Database::prepare(" + UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `reportsent` = '2' + WHERE `customerid` = :customerid + "); + Database::pexecute($upd_stmt, array('customerid' => $row['customerid'])); } } /** * report about diskusage for admins/reseller */ -$result = $db->query("SELECT `a`.* FROM `" . TABLE_PANEL_ADMINS . "` `a` WHERE `a`.`reportsent` <> '2'"); +$result_stmt = Database::query(" + SELECT `a`.* FROM `" . TABLE_PANEL_ADMINS . "` `a` WHERE `a`.`reportsent` <> '2' +"); -while($row = $db->fetch_array($result)) -{ - if(isset($row['diskspace']) - && $row['diskspace_used'] != NULL +while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { + + if (isset($row['diskspace']) + && $row['diskspace_used'] != null && $row['diskspace_used'] > 0 && (($row['diskspace_used'] * 100) / $row['diskspace']) >= (int)$settings['system']['report_webmax'] ) { @@ -132,35 +140,41 @@ while($row = $db->fetch_array($result)) 'MAX_PERCENT' => $settings['system']['report_webmax'] ); - $lngfile = $db->query_first("SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "` - WHERE `language` ='" . $row['def_language'] . "'"); + $lngfile_stmt = Database::prepare(" + SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "` + WHERE `language` = :deflang + "); + $lngfile = Database::pexecute_first($lngfile_stmt, array('deflang' => $row['def_language'])); - if($lngfile !== NULL) - { + if ($lngfile !== null) { $langfile = $lngfile['file']; - } - else - { - $lngfile = $db->query_first("SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "` - WHERE `language` ='" . $settings['panel']['standardlanguage'] . "'"); + } else { + $lngfile = Database::pexecute_first($lngfile_stmt, array('deflang' => $settings['panel']['standardlanguage'])); $langfile = $lngfile['file']; } + // include english language file (fallback) + include_once makeCorrectFile($pathtophpfiles . '/lng/english.lng.php'); + // include admin/customer language file include_once makeCorrectFile($pathtophpfiles . '/' . $langfile); // Get mail templates from database; the ones from 'admin' are fetched for fallback - $result2 = $db->query_first("SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "` - WHERE `adminid`='" . (int)$row['adminid'] . "' - AND `language`='" . $db->escape($row['def_language']) . "' - AND `templategroup`='mails' - AND `varname`='diskmaxpercent_subject'"); + $result2_stmt = Database::prepare(" + SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "` + WHERE `adminid` = :adminid + AND `language` = :lang + AND `templategroup` = 'mails' AND `varname` = :varname + "); + $resul2_data = array( + 'adminid' => $row['adminid'], + 'lang' => $row['def_language'], + 'varname' => 'diskmaxpercent_subject' + ); + $result2 = Database::pexecute_first($result2_stmt, $result2_data); $mail_subject = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['webmaxpercent']['subject']), $replace_arr)); - $result2 = $db->query_first("SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "` - WHERE `adminid`='" . (int)$row['adminid'] . "' - AND `language`='" . $db->escape($row['def_language']) . "' - AND `templategroup`='mails' - AND `varname`='diskmaxpercent_mailbody'"); + $resul2_data['varname'] = 'diskmaxpercent_mailbody'; + $result2 = Database::pexecute_first($result2_stmt, $result2_data); $mail_body = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['webmaxpercent']['mailbody']), $replace_arr)); $_mailerror = false; @@ -185,7 +199,10 @@ while($row = $db->fetch_array($result)) } $mail->ClearAddresses(); - $db->query("UPDATE `" . TABLE_PANEL_ADMINS . "` SET `reportsent`='2' - WHERE `adminid`='" . (int)$row['adminid'] . "'"); + $upd_stmt = Database::prepare(" + UPDATE `" . TABLE_PANEL_ADMINS . "` SET `reportsent` = '2' + WHERE `adminid` = :adminid + "); + Database::pexecute($upd_stmt, array('adminid' => $row['adminid'])); } } diff --git a/scripts/jobs/cron_usage_report.php b/scripts/jobs/cron_usage_report.php index 41952c77..d362f241 100644 --- a/scripts/jobs/cron_usage_report.php +++ b/scripts/jobs/cron_usage_report.php @@ -30,23 +30,32 @@ $mail->SetFrom($settings['panel']['adminmail'], 'Froxlor Administrator'); // Warn the customers at xx% traffic-usage -$result = $db->query("SELECT `c`.`customerid`, `c`.`adminid`, `c`.`name`, `c`.`firstname`, `c`.`company`, `c`.`traffic`, - `c`.`email`, `c`.`def_language`, `a`.`name` AS `adminname`, `a`.`email` AS `adminmail`, - (SELECT SUM(`t`.`http` + `t`.`ftp_up` + `t`.`ftp_down` + `t`.`mail`) - FROM `" . TABLE_PANEL_TRAFFIC . "` `t` - WHERE `t`.`customerid` = `c`.`customerid` AND `t`.`year` = '" . (int)date("Y", $yesterday) . "' - AND `t`.`month` = '" . date("m", $yesterday) . "') as `traffic_used` - FROM `" . TABLE_PANEL_CUSTOMERS . "` AS `c` - LEFT JOIN `" . TABLE_PANEL_ADMINS . "` AS `a` ON `a`.`adminid` = `c`.`adminid` - WHERE `c`.`reportsent` <> '1'"); +$result_stmt = Database::prepare(" + SELECT `c`.`customerid`, `c`.`adminid`, `c`.`name`, `c`.`firstname`, + `c`.`company`, `c`.`traffic`, `c`.`email`, `c`.`def_language`, + `a`.`name` AS `adminname`, `a`.`email` AS `adminmail`, + (SELECT SUM(`t`.`http` + `t`.`ftp_up` + `t`.`ftp_down` + `t`.`mail`) + FROM `" . TABLE_PANEL_TRAFFIC . "` `t` + WHERE `t`.`customerid` = `c`.`customerid` AND `t`.`year` = :year AND `t`.`month` = :month + ) as `traffic_used` + FROM `" . TABLE_PANEL_CUSTOMERS . "` AS `c` + LEFT JOIN `" . TABLE_PANEL_ADMINS . "` AS `a` + ON `a`.`adminid` = `c`.`adminid` WHERE `c`.`reportsent` <> '1' +"); -while($row = $db->fetch_array($result)) -{ - if(isset($row['traffic']) - && $row['traffic'] > 0 - && $row['traffic_used'] != NULL - && (($row['traffic_used'] * 100) / $row['traffic']) >= (int)$settings['system']['report_trafficmax']) - { +$result_data = array( + 'year' => date("Y", $yesterday), + 'month' => date("m", $yesterday) +); +Database::pexecute($result_stmt, $result_data); + +while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { + + if (isset($row['traffic']) + && $row['traffic'] > 0 + && $row['traffic_used'] != null + && (($row['traffic_used'] * 100) / $row['traffic']) >= (int)$settings['system']['report_trafficmax'] + ) { $rep_userinfo = array( 'name' => $row['name'], 'firstname' => $row['firstname'], @@ -60,35 +69,42 @@ while($row = $db->fetch_array($result)) 'USAGE_PERCENT' => round(($row['traffic_used'] * 100) / $row['traffic'], 2), 'MAX_PERCENT' => $settings['system']['report_trafficmax'] ); - $lngfile = $db->query_first("SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "` - WHERE `language` ='" . $row['def_language'] . "'"); - if($lngfile !== NULL) - { + $lngfile_stmt = Database::prepare(" + SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "` + WHERE `language` = :deflang + "); + $lngfile = Database::pexecute_first($lngfile_stmt, array('deflang' => $row['def_language'])); + + if ($lngfile !== null) { $langfile = $lngfile['file']; - } - else - { - $lngfile = $db->query_first("SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "` - WHERE `language` ='" . $settings['panel']['standardlanguage'] . "'"); + } else { + $lngfile = Database::pexecute_first($lngfile_stmt, array('deflang' => $settings['panel']['standardlanguage'])); $langfile = $lngfile['file']; } + // include english language file (fallback) + include_once makeCorrectFile($pathtophpfiles . '/lng/english.lng.php'); + // include admin/customer language file include_once makeCorrectFile($pathtophpfiles . '/' . $langfile); // Get mail templates from database; the ones from 'admin' are fetched for fallback - - $result2 = $db->query_first("SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "` - WHERE `adminid`='" . (int)$row['adminid'] . "' - AND `language`='" . $db->escape($row['def_language']) . "' - AND `templategroup`='mails' - AND `varname`='trafficmaxpercent_subject'"); + $result2_stmt = Database::prepare(" + SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "` + WHERE `adminid` = :adminid + AND `language` = :lang + AND `templategroup` = 'mails' AND `varname` = :varname + "); + $resul2_data = array( + 'adminid' => $row['adminid'], + 'lang' => $row['def_language'], + 'varname' => 'trafficmaxpercent_subject' + ); + $result2 = Database::pexecute_first($result2_stmt, $result2_data); $mail_subject = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['trafficmaxpercent']['subject']), $replace_arr)); - $result2 = $db->query_first("SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "` - WHERE `adminid`='" . (int)$row['adminid'] . "' - AND `language`='" . $db->escape($row['def_language']) . "' - AND `templategroup`='mails' - AND `varname`='trafficmaxpercent_mailbody'"); + + $resul2_data['varname'] = 'trafficmaxpercent_mailbody'; + $result2 = Database::pexecute_first($result2_stmt, $result2_data); $mail_body = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['trafficmaxpercent']['mailbody']), $replace_arr)); $_mailerror = false; @@ -107,33 +123,43 @@ while($row = $db->fetch_array($result)) $_mailerror = true; } - if($_mailerror) - { + if ($_mailerror) { $cronlog->logAction(CRON_ACTION, LOG_ERR, 'Error sending mail: ' . $mailerr_msg); echo 'Error sending mail: ' . $mailerr_msg . "\n"; } $mail->ClearAddresses(); - $db->query('UPDATE `' . TABLE_PANEL_CUSTOMERS . '` SET `reportsent`=\'1\' - WHERE `customerid`=\'' . (int)$row['customerid'] . '\''); + $upd_stmt = Database::prepare(" + UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `reportsent` = '1' + WHERE `customerid` = :customerid + "); + Database::pexecute($upd_stmt, array('customerid' => $row['customerid'])); } } // Warn the admins at xx% traffic-usage +$result_stmt = Database::prepare(" + SELECT `a`.*, + (SELECT SUM(`t`.`http` + `t`.`ftp_up` + `t`.`ftp_down` + `t`.`mail`) + FROM `" . TABLE_PANEL_TRAFFIC_ADMINS . "` `t` + WHERE `t`.`adminid` = `a`.`adminid` AND `t`.`year` = :year AND `t`.`month` = :month + ) as `traffic_used_total` + FROM `" . TABLE_PANEL_ADMINS . "` `a` WHERE `a`.`reportsent` = '0' +"); -$result = $db->query("SELECT `a`.*, - (SELECT SUM(`t`.`http` + `t`.`ftp_up` + `t`.`ftp_down` + `t`.`mail`) - FROM `" . TABLE_PANEL_TRAFFIC_ADMINS . "` `t` - WHERE `t`.`adminid` = `a`.`adminid` AND `t`.`year` = '" . (int)date("Y", $yesterday) . "' - AND `t`.`month` = '" . date("m", $yesterday) . "') as `traffic_used_total` - FROM `" . TABLE_PANEL_ADMINS . "` `a` WHERE `a`.`reportsent` = '0'"); +$result_data = array( + 'year' => date("Y", $yesterday), + 'month' => date("m", $yesterday) +); +Database::pexecute($result_stmt, $result_data); + +while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { + + if (isset($row['traffic']) + && $row['traffic'] > 0 + && (($row['traffic_used_total'] * 100) / $row['traffic']) >= (int)$settings['system']['report_trafficmax'] + ) { -while($row = $db->fetch_array($result)) -{ - if(isset($row['traffic']) - && $row['traffic'] > 0 - && (($row['traffic_used_total'] * 100) / $row['traffic']) >= (int)$settings['system']['report_trafficmax']) - { $replace_arr = array( 'NAME' => $row['name'], 'TRAFFIC' => round(($row['traffic'] / 1024), 2), /* traffic is stored in KB, template uses MB */ @@ -141,37 +167,44 @@ while($row = $db->fetch_array($result)) 'USAGE_PERCENT' => round(($row['traffic_used_total'] * 100) / $row['traffic'], 2), 'MAX_PERCENT' => $settings['system']['report_trafficmax'] ); - $lngfile = $db->query_first("SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "` - WHERE `language` ='" . $row['def_language'] . "'"); - if($lngfile !== NULL) - { + $lngfile_stmt = Database::prepare(" + SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "` + WHERE `language` = :deflang + "); + $lngfile = Database::pexecute_first($lngfile_stmt, array('deflang' => $row['def_language'])); + + if ($lngfile !== null) { $langfile = $lngfile['file']; - } - else - { - $lngfile = $db->query_first("SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "` - WHERE `language` ='" . $settings['panel']['standardlanguage'] . "'"); + } else { + $lngfile = Database::pexecute_first($lngfile_stmt, array('deflang' => $settings['panel']['standardlanguage'])); $langfile = $lngfile['file']; } + // include english language file (fallback) + include_once makeCorrectFile($pathtophpfiles . '/lng/english.lng.php'); + // include admin/customer language file include_once makeCorrectFile($pathtophpfiles . '/' . $langfile); // Get mail templates from database; the ones from 'admin' are fetched for fallback - - $result2 = $db->query_first("SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "` - WHERE `adminid`='" . (int)$row['adminid'] . "' - AND `language`='" . $db->escape($row['def_language']) . "' - AND `templategroup`='mails' - AND `varname`='trafficmaxpercent_subject'"); + $result2_stmt = Database::prepare(" + SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "` + WHERE `adminid` = :adminid + AND `language` = :lang + AND `templategroup` = 'mails' AND `varname` = :varname + "); + $resul2_data = array( + 'adminid' => $row['adminid'], + 'lang' => $row['def_language'], + 'varname' => 'trafficmaxpercent_subject' + ); + $result2 = Database::pexecute_first($result2_stmt, $result2_data); $mail_subject = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['trafficmaxpercent']['subject']), $replace_arr)); - $result2 = $db->query_first("SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "` - WHERE `adminid`='" . (int)$row['adminid'] . "' - AND `language`='" . $db->escape($row['def_language']) . "' - AND `templategroup`='mails' - AND `varname`='trafficmaxpercent_mailbody'"); + + $resul2_data['varname'] = 'trafficmaxpercent_mailbody'; + $result2 = Database::pexecute_first($result2_stmt, $result2_data); $mail_body = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['trafficmaxpercent']['mailbody']), $replace_arr)); - + $_mailerror = false; try { $mail->SetFrom($row['email'], $row['name']); @@ -194,27 +227,36 @@ while($row = $db->fetch_array($result)) } $mail->ClearAddresses(); - $db->query("UPDATE `" . TABLE_PANEL_ADMINS . "` SET `reportsent`='1' - WHERE `adminid`='" . (int)$row['adminid'] . "'"); + $upd_stmt = Database::prepare(" + UPDATE `" . TABLE_PANEL_ADMINS . "` SET `reportsent` = '1' + WHERE `adminid` = :adminid + "); + Database::pexecute($upd_stmt, array('adminid' => $row['adminid'])); } // Another month, let's build our report + if (date('d') == '01') { - if(date('d') == '01') - { $mail_subject = 'Trafficreport ' . date("m/y", $yesterday) . ' for ' . $row['name']; $mail_body = 'Trafficreport ' . date("m/y", $yesterday) . ' for ' . $row['name'] . "\n"; $mail_body.= '---------------------------------------------' . "\n"; $mail_body.= 'Loginname Traffic used (Percent) | Traffic available' . "\n"; - $customers = $db->query("SELECT `c`.*, - (SELECT SUM(`t`.`http` + `t`.`ftp_up` + `t`.`ftp_down` + `t`.`mail`) - FROM `" . TABLE_PANEL_TRAFFIC . "` `t` - WHERE `t`.`customerid` = `c`.`customerid` AND `t`.`year` = '" . (int)date("Y", $yesterday) . "' - AND `t`.`month` = '" . date("m", $yesterday) . "') as `traffic_used_total` - FROM `" . TABLE_PANEL_CUSTOMERS . "` `c` WHERE `c`.`adminid` = '" . $row['adminid'] . "'"); + $customers_stmt = Database::prepare(" + SELECT `c`.*, + (SELECT SUM(`t`.`http` + `t`.`ftp_up` + `t`.`ftp_down` + `t`.`mail`) + FROM `" . TABLE_PANEL_TRAFFIC . "` `t` + WHERE `t`.`customerid` = `c`.`customerid` AND `t`.`year` = :year AND `t`.`month` = :month + ) as `traffic_used_total` + FROM `" . TABLE_PANEL_CUSTOMERS . "` `c` WHERE `c`.`adminid` = :adminid + "); + $customers_data = array( + 'year' => date("Y", $yesterday), + 'month' => date("m", $yesterday), + 'adminid' => $row['adminid'] + ); + Database::pexecute($customers_stmt, $customers_data); - while($customer = $db->fetch_array($customers)) - { + while ($customer = $customers_stmt->fetch(PDO::FETCH_ASSOC)) { if ($customer['traffic'] > 0) { $mail_body.= sprintf('%-15s', $customer['loginname']) . ' ' . sprintf('%-12d', $customer['traffic_used_total']) . ' (' . sprintf('%00.3f%%', (($customer['traffic_used_total'] * 100) / $customer['traffic'])) . ') ' . $customer['traffic'] . "\n"; } else { @@ -253,9 +295,7 @@ while($row = $db->fetch_array($result)) include dirname(__FILE__).'/cron_usage.inc.diskspace.php'; // Another month, reset the reportstatus - -if(date('d') == '01') -{ - $db->query('UPDATE `' . TABLE_PANEL_CUSTOMERS . '` SET `reportsent` = \'0\';'); - $db->query('UPDATE `' . TABLE_PANEL_ADMINS . '` SET `reportsent` = \'0\';'); +if (date('d') == '01') { + Database::query("UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `reportsent` = '0';"); + Database::query("UPDATE `" . TABLE_PANEL_ADMINS . "` SET `reportsent` = '0';"); }