From a8b52d50af1bb6e8a1c01e8344049820cbac7304 Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Tue, 18 Jan 2011 07:18:28 +0000 Subject: [PATCH] - prework for docroot-settings-extension, refs #533 --- install/froxlor.sql | 27 +++ .../updates/froxlor/0.9/update_0.9.inc.php | 22 ++ lib/classes/domains/class.docrootsettings.php | 198 ++++++++++++++++++ lib/tables.inc.php | 4 +- scripts/jobs/cron_usage.inc.diskspace.php | 46 ++-- 5 files changed, 273 insertions(+), 24 deletions(-) create mode 100644 lib/classes/domains/class.docrootsettings.php diff --git a/install/froxlor.sql b/install/froxlor.sql index 52a84054..7a5e2943 100644 --- a/install/froxlor.sql +++ b/install/froxlor.sql @@ -1105,3 +1105,30 @@ CREATE TABLE IF NOT EXISTS `domain_redirect_codes` ( `did` int(11) unsigned NOT NULL, UNIQUE KEY `rc` (`rid`, `did`) ) ENGINE=MyISAM; + + +# +# Tabellenstruktur fuer Tabelle `ipsandports_docrootsettings` +# + +DROP TABLE IF EXISTS `ipsandports_docrootsettings`; +CREATE TABLE IF NOT EXISTS `ipsandports_docrootsettings` ( + `id` int(5) NOT NULL auto_increment, + `fid` int(11) NOT NULL, + `docrootsettings` text NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM; + + +# +# Tabellenstruktur fuer Tabelle `domain_docrootsettings` +# + +DROP TABLE IF EXISTS `domain_docrootsettings`; +CREATE TABLE IF NOT EXISTS `domain_docrootsettings` ( + `id` int(5) NOT NULL auto_increment, + `fid` int(11) NOT NULL, + `docrootsettings` text NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM; + diff --git a/install/updates/froxlor/0.9/update_0.9.inc.php b/install/updates/froxlor/0.9/update_0.9.inc.php index a2566938..45da31f5 100644 --- a/install/updates/froxlor/0.9/update_0.9.inc.php +++ b/install/updates/froxlor/0.9/update_0.9.inc.php @@ -1389,3 +1389,25 @@ if(isFroxlorVersion('0.9.16')) updateToVersion('0.9.17-svn1'); } + +if(isFroxlorVersion('0.9.17-svn1')) +{ + showUpdateStep("Updating from 0.9.17-svn1 to 0.9.17-svn2", false); + + showUpdateStep("Adding new tables to database"); + $db->query("CREATE TABLE IF NOT EXISTS `ipsandports_docrootsettings` ( + `id` int(5) NOT NULL auto_increment, + `fid` int(11) NOT NULL, + `docrootsettings` text NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM;"); + $db->query("CREATE TABLE IF NOT EXISTS `domain_docrootsettings` ( + `id` int(5) NOT NULL auto_increment, + `fid` int(11) NOT NULL, + `docrootsettings` text NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM;"); + lastStepStatus(0); + + updateToVersion('0.9.17-svn2'); +} diff --git a/lib/classes/domains/class.docrootsettings.php b/lib/classes/domains/class.docrootsettings.php new file mode 100644 index 00000000..e2b90fd0 --- /dev/null +++ b/lib/classes/domains/class.docrootsettings.php @@ -0,0 +1,198 @@ + + * @author Froxlor team (2010-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Classes + * @version $Id$ + * @link http://www.nutime.de/ + * @since 0.9.17-svn2 + * + */ + +class docrootsettings +{ + /** + * Database handler + * @var object + */ + private $_db = false; + + /** + * Settings array + * @var array + */ + private $_settings = array(); + + /** + * main constructor + */ + public function __construct($db, $settings) + { + $this->_db = $db; + $this->_settings = $settings; + } + + /** + * this function lets you add docroot-settings for a given domain (by ID) + * + * @param int $domainid id of the domain to add the settings for + * @param string $ssettings docrootsettings to add for the domain + * + * @return boolean + */ + public function addDomainDocrootsettings($domainid = 0, $ssettings = '') + { + return $this->_addDocrootSetting(TABLE_PANEL_DOMDOCROOTSETTINGS, $domainid, $ssettings); + } + + /** + * this function lets you update docroot-settings for a given domain (by ID) + * + * @param int $domainid id of the domain to update the settings from + * @param string $ssettings docrootsettings to update for the domain + * + * @return boolean + */ + public function updateDomainDocrootsettings($domainid = 0, $ssettings = '') + { + return $this->_updateDocrootSetting(TABLE_PANEL_DOMDOCROOTSETTINGS, $domainid, $ssettings); + } + + /** + * this function lets you add docroot-settings for a given ip/port combo (by ID) + * + * @param int $ipandportid id of the domain to add the settings for + * @param string $ssettings docrootsettings to add for the domain + * + * @return boolean + */ + public function addIpsAndPortsDocrootsettings($ipandportid = 0, $ssettings = '') + { + return $this->_addDocrootSetting(TABLE_PANEL_IPDOCROOTSETTINGS, $ipandportid, $ssettings); + } + + /** + * this function lets you update docroot-settings for a given ip/port combo (by ID) + * + * @param int $ipandportid id of the domain to update the settings from + * @param string $ssettings docrootsettings to update for the domain + * + * @return boolean + */ + public function updateIpsAndPortsDocrootsettings($ipandportid = 0, $ssettings = '') + { + return $this->_updateDocrootSetting(TABLE_PANEL_IPDOCROOTSETTINGS, $ipandportid, $ssettings); + } + + /** + * returns the docroot-setting + * for a given domain (by ID) + * + * @param int $domainid the id of the domain + * + * @return string the settings or empty if not set + */ + public function getDomainDocrootsettings($domainid = 0) + { + return $this->_getDocrootSettingById(TABLE_PANEL_DOMDOCROOTSETTINGS, $domainid); + } + + /** + * returns the docroot-setting + * for a given ip/port combination (by ID) + * + * @param int $ipandportid the id of the ip/port combo + * + * @return string the settings or empty if not set + */ + public function getIpsAndPortsDocrootsettings($ipandportid = 0) + { + return $this->_getDocrootSettingById(TABLE_PANEL_IPDOCROOTSETTINGS, $ipandportid); + } + + /** + * this function is called by addDomainDocrootsettings() and + * addIpsAndPortsDocrootsettings() to add docroot settings for an object + * + * @param string $table table to add the settings to + * @param int $fid foreign id / object id + * @param string $ssettings docroot-settings + * + * @return boolean + */ + private function _addDocrootSetting($table, $fid, $ssettings) + { + $query = "INSERT INTO `".$table."` SET + `fid` = '".(int)$fid."', + `docrootsettings` = '".$db->escape($ssettings)."';"; + $this->_db->query($query); + return true; + } + + /** + * this function is called by updateDomainDocrootsettings() and + * updateIpsAndPortsDocrootsettings() to update docroot settings for an object + * + * if new value is an empty string, entry is being removed + * + * @param string $table table to update the settings from + * @param int $fid foreign id / object id + * @param string $ssettings docroot-settings + * + * @return boolean + */ + private function _updateDocrootSetting($table, $fid, $ssettings) + { + // check if this object has an entry for docrootsettings + if($this->_getDocrootSettingById($table, $fid) != '') + { + if($ssettings != '') + { + // update if new value has been set + $query = "UPDATE `".$table."` SET + `docrootsettings` = '".$db->escape($ssettings)."' + WHERE `fid` = '".(int)$fid."';"; + } + else + { + // remove if new value is empty + $query = "DELETE FROM `".$table."` WHERE `fid` = '".(int)$fid."';"; + } + // run query + $this->_db->query($query); + return true; + } + // this object has no entry for docrootsettings yet + return false; + } + + /** + * read the docrootsetting field of given table + * for given id + * + * @param string $table table where to read from + * @param int $id id of the object + * + * @return string string the settings or empty if not set + */ + private function _getDocrootSettingById($table = null, $id = 0) + { + $query = "SELECT `docrootsettings` FROM `".$table."` WHERE `fid`='".(int)$id."';"; + $result = $this->_db->query_first($query); + if($result !== false && isset($result['docrootsettings'])) + { + return $result['docrootsettings']; + } + return ''; + } +} diff --git a/lib/tables.inc.php b/lib/tables.inc.php index e3bb28ec..bd890c97 100644 --- a/lib/tables.inc.php +++ b/lib/tables.inc.php @@ -52,6 +52,8 @@ define('TABLE_APS_TEMP_SETTINGS', 'aps_temp_settings'); define('TABLE_PANEL_CRONRUNS', 'cronjobs_run'); define('TABLE_PANEL_REDIRECTCODES', 'redirect_codes'); define('TABLE_PANEL_DOMAINREDIRECTS', 'domain_redirect_codes'); +define('TABLE_PANEL_IPDOCROOTSETTINGS', 'ipsandports_docrootsettings'); +define('TABLE_PANEL_DOMDOCROOTSETTINGS', 'domain_docrootsettings'); // APS constants @@ -71,7 +73,7 @@ define('PACKAGE_ENABLED', 2); // VERSION INFO -$version = '0.9.17-svn1'; +$version = '0.9.17-svn2'; $dbversion = '2'; $branding = ''; diff --git a/scripts/jobs/cron_usage.inc.diskspace.php b/scripts/jobs/cron_usage.inc.diskspace.php index c52279f3..f8d183bf 100644 --- a/scripts/jobs/cron_usage.inc.diskspace.php +++ b/scripts/jobs/cron_usage.inc.diskspace.php @@ -18,7 +18,7 @@ /** * report about diskusage for customers */ -$result = $db->query("SELECT +$result = $db->query("SELECT `c`.`customerid`, `c`.`adminid`, `c`.`name`, `c`.`firstname`, `c`.`diskspace`, `c`.`diskspace_used`, `c`.`email`, `c`.`def_language`, `a`.`name` AS `adminname`, `a`.`email` AS `adminmail` @@ -30,11 +30,11 @@ $result = $db->query("SELECT while($row = $db->fetch_array($result)) { if(isset($row['diskspace']) - && $row['diskspace_used'] != NULL - && $row['diskspace_used'] > 0 - && (($row['diskspace_used'] * 100) / $row['diskspace']) >= (int)$settings['system']['report_webmax'] + && $row['diskspace_used'] != NULL + && $row['diskspace_used'] > 0 + && (($row['diskspace_used'] * 100) / $row['diskspace']) >= (int)$settings['system']['report_webmax'] ) { - + $replace_arr = array( 'NAME' => $row['name'], 'DISKAVAILABLE' => ($row['diskspace'] / 1024), /* traffic is stored in KB, template uses MB */ @@ -45,7 +45,7 @@ while($row = $db->fetch_array($result)) $lngfile = $db->query_first("SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "` WHERE `language` ='" . $row['def_language'] . "'"); - + if($lngfile !== NULL) { $langfile = $lngfile['file']; @@ -56,9 +56,9 @@ while($row = $db->fetch_array($result)) WHERE `language` ='" . $settings['panel']['standardlanguage'] . "'"); $langfile = $lngfile['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'] . "' @@ -66,14 +66,14 @@ while($row = $db->fetch_array($result)) AND `templategroup`='mails' AND `varname`='webmaxpercent_subject'"); $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`='webmaxpercent_mailbody'"); $mail_body = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['webmaxpercent']['mailbody']), $replace_arr)); - + $_mailerror = false; try { $mail->SetFrom($row['email'], $row['firstname'] . " " . $row['name']); @@ -89,12 +89,12 @@ while($row = $db->fetch_array($result)) $mailerr_msg = $e->getMessage(); $_mailerror = true; } - + if ($_mailerror) { $cronlog->logAction(CRON_ACTION, LOG_ERR, "Error sending mail: " . $mailerr_msg); standard_error('errorsendingmail', $row["email"]); } - + $mail->ClearAddresses(); $db->query("UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `reportsent`='2' WHERE `customerid`='" . (int)$row['customerid'] . "'"); @@ -109,11 +109,11 @@ $result = $db->query("SELECT `a`.* FROM `" . TABLE_PANEL_ADMINS . "` `a` WHERE ` while($row = $db->fetch_array($result)) { if(isset($row['diskspace']) - && $row['diskspace_used'] != NULL - && $row['diskspace_used'] > 0 - && (($row['diskspace_used'] * 100) / $row['diskspace']) >= (int)$settings['system']['report_webmax'] + && $row['diskspace_used'] != NULL + && $row['diskspace_used'] > 0 + && (($row['diskspace_used'] * 100) / $row['diskspace']) >= (int)$settings['system']['report_webmax'] ) { - + $replace_arr = array( 'NAME' => $row['name'], 'DISKAVAILABLE' => ($row['diskspace'] / 1024), /* traffic is stored in KB, template uses MB */ @@ -124,7 +124,7 @@ while($row = $db->fetch_array($result)) $lngfile = $db->query_first("SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "` WHERE `language` ='" . $row['def_language'] . "'"); - + if($lngfile !== NULL) { $langfile = $lngfile['file']; @@ -135,9 +135,9 @@ while($row = $db->fetch_array($result)) WHERE `language` ='" . $settings['panel']['standardlanguage'] . "'"); $langfile = $lngfile['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'] . "' @@ -145,14 +145,14 @@ while($row = $db->fetch_array($result)) AND `templategroup`='mails' AND `varname`='webmaxpercent_subject'"); $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`='webmaxpercent_mailbody'"); $mail_body = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['webmaxpercent']['mailbody']), $replace_arr)); - + $_mailerror = false; try { $mail->SetFrom($row['email'], $row['name']); @@ -168,12 +168,12 @@ while($row = $db->fetch_array($result)) $mailerr_msg = $e->getMessage(); $_mailerror = true; } - + if ($_mailerror) { $cronlog->logAction(CRON_ACTION, LOG_ERR, "Error sending mail: " . $mailerr_msg); standard_error('errorsendingmail', $row["email"]); } - + $mail->ClearAddresses(); $db->query("UPDATE `" . TABLE_PANEL_ADMINS . "` SET `reportsent`='2' WHERE `adminid`='" . (int)$row['adminid'] . "'");