migrate ALL the crons to new PDO database class, refs #1287

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2013-11-28 12:35:20 +01:00
parent 990e39cadb
commit 4426ab52d3
15 changed files with 274 additions and 300 deletions

View File

@@ -420,7 +420,7 @@ return Array(
'a2enmod suexec fcgid', 'a2enmod suexec fcgid',
($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'groupadd -f '.$settings['system']['mod_fcgid_httpgroup'] : null, ($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'groupadd -f '.$settings['system']['mod_fcgid_httpgroup'] : null,
($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'useradd -s /bin/false -g '.$settings['system']['mod_fcgid_httpgroup'].' '.$settings['system']['mod_fcgid_httpuser'] : null, ($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'useradd -s /bin/false -g '.$settings['system']['mod_fcgid_httpgroup'].' '.$settings['system']['mod_fcgid_httpuser'] : null,
($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'chown -R '.$settings['system']['mod_fcgid_httpuser'].':'.$settings['system']['mod_fcgid_httpgroup'].' '.$pathtophpfiles : null, ($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'chown -R '.$settings['system']['mod_fcgid_httpuser'].':'.$settings['system']['mod_fcgid_httpgroup'].' '.FROXLOR_INSTALL_DIR : null,
($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'mkdir -p '.makeCorrectDir($settings['system']['mod_fcgid_configdir']) : null, ($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'mkdir -p '.makeCorrectDir($settings['system']['mod_fcgid_configdir']) : null,
($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'mkdir -p '.makeCorrectDir($settings['system']['mod_fcgid_tmpdir']) : null, ($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'mkdir -p '.makeCorrectDir($settings['system']['mod_fcgid_tmpdir']) : null,
($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'a2dismod php5' : null ($settings['system']['mod_fcgid_ownvhost'] == '1') ? 'a2dismod php5' : null
@@ -439,7 +439,7 @@ return Array(
'a2enmod suexec fastcgi actions', 'a2enmod suexec fastcgi actions',
($settings['phpfpm']['enabled_ownvhost'] == '1') ? 'groupadd -f '.$settings['phpfpm']['vhost_httpgroup'] : null, ($settings['phpfpm']['enabled_ownvhost'] == '1') ? 'groupadd -f '.$settings['phpfpm']['vhost_httpgroup'] : null,
($settings['phpfpm']['enabled_ownvhost'] == '1') ? 'useradd -s /bin/false -g '.$settings['phpfpm']['vhost_httpgroup'].' '.$settings['phpfpm']['vhost_httpuser'] : null, ($settings['phpfpm']['enabled_ownvhost'] == '1') ? 'useradd -s /bin/false -g '.$settings['phpfpm']['vhost_httpgroup'].' '.$settings['phpfpm']['vhost_httpuser'] : null,
($settings['phpfpm']['enabled_ownvhost'] == '1') ? 'chown -R '.$settings['phpfpm']['vhost_httpuser'].':'.$settings['phpfpm']['vhost_httpgroup'].' '.$pathtophpfiles : null, ($settings['phpfpm']['enabled_ownvhost'] == '1') ? 'chown -R '.$settings['phpfpm']['vhost_httpuser'].':'.$settings['phpfpm']['vhost_httpgroup'].' '.FROXLOR_INSTALL_DIR : null,
($settings['phpfpm']['enabled_ownvhost'] == '1') ? 'a2dismod php5' : null ($settings['phpfpm']['enabled_ownvhost'] == '1') ? 'a2dismod php5' : null
) )
) )

View File

@@ -16,10 +16,11 @@
* @package Cron * @package Cron
* *
*/ */
if(@php_sapi_name() != 'cli'
&& @php_sapi_name() != 'cgi' if (@php_sapi_name() != 'cli'
&& @php_sapi_name() != 'cgi-fcgi') && @php_sapi_name() != 'cgi'
{ && @php_sapi_name() != 'cgi-fcgi'
) {
die('This script will only work in the shell.'); die('This script will only work in the shell.');
} }
@@ -39,17 +40,12 @@ $lockfile = $lockdir . $lockfName;
// normally you should not need to modify this script anymore, if your // normally you should not need to modify this script anymore, if your
// froxlor installation isn't in /var/www/froxlor // froxlor installation isn't in /var/www/froxlor
define('FROXLOR_INSTALL_DIR', dirname(dirname(__FILE__))); define('FROXLOR_INSTALL_DIR', dirname(dirname(__FILE__)));
// TODO remove when not needed anymore
$pathtophpfiles = dirname(dirname(__FILE__));
// should the froxlor installation guessing not work correctly,
// uncomment the following line, and put your path in there!
//$pathtophpfiles = '/var/www/froxlor/';
// create and open the lockfile! // create and open the lockfile!
$keepLockFile = false; $keepLockFile = false;
$debugHandler = fopen($lockfile, 'w'); $debugHandler = fopen($lockfile, 'w');
fwrite($debugHandler, 'Setting Lockfile to ' . $lockfile . "\n"); fwrite($debugHandler, 'Setting Lockfile to ' . $lockfile . "\n");
fwrite($debugHandler, 'Setting Froxlor installation path to ' . $pathtophpfiles . "\n"); fwrite($debugHandler, 'Setting Froxlor installation path to ' . FROXLOR_INSTALL_DIR . "\n");
// open the lockfile directory and scan for existing lockfiles // open the lockfile directory and scan for existing lockfiles
$lockDirHandle = opendir($lockdir); $lockDirHandle = opendir($lockdir);
@@ -119,27 +115,28 @@ require FROXLOR_INSTALL_DIR . '/lib/functions.php';
require FROXLOR_INSTALL_DIR . '/lib/tables.inc.php'; require FROXLOR_INSTALL_DIR . '/lib/tables.inc.php';
fwrite($debugHandler, 'Table definitions included' . "\n"); fwrite($debugHandler, 'Table definitions included' . "\n");
//Includes the MySQL-Connection-Class // try database connection, it will throw
fwrite($debugHandler, 'Database Class has been loaded' . "\n"); // and exception itself if failed
$db = new db($sql['host'], $sql['user'], $sql['password'], $sql['db']); try {
Database::query("SELECT 1");
if ($db->link_id == 0) { } catch (Exception $e) {
// Do not proceed further if no database connection could be established // Do not proceed further if no database connection could be established
fclose($debugHandler); fclose($debugHandler);
unlink($lockfile); unlink($lockfile);
die('Froxlor can\'t connect to mysqlserver. Please check userdata.inc.php! Exiting...'); die($e->getMessage());
} }
fwrite($debugHandler, 'Database-connection established' . "\n"); fwrite($debugHandler, 'Database-connection established' . "\n");
unset($sql); $result_stmt = Database::query("
$result = $db->query("SELECT `settingid`, `settinggroup`, `varname`, `value` FROM `" . TABLE_PANEL_SETTINGS . "`"); SELECT `settingid`, `settinggroup`, `varname`, `value`
FROM `" . TABLE_PANEL_SETTINGS . "`
");
while ($row = $db->fetch_array($result)) { while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
$settings[$row['settinggroup']][$row['varname']] = $row['value']; $settings[$row['settinggroup']][$row['varname']] = $row['value'];
} }
unset($row); unset($row);
unset($result);
fwrite($debugHandler, 'Froxlor settings have been loaded from the database' . "\n"); fwrite($debugHandler, 'Froxlor settings have been loaded from the database' . "\n");
/** /**
@@ -150,7 +147,7 @@ if ((int)$settings['system']['mod_fcgid'] == 1
&& (int)$settings['system']['mod_fcgid_ownvhost'] == 1 && (int)$settings['system']['mod_fcgid_ownvhost'] == 1
) { ) {
fwrite($debugHandler, 'Checking froxlor file permissions'); fwrite($debugHandler, 'Checking froxlor file permissions');
$mypath = makeCorrectDir(dirname(dirname(__FILE__))); // /var/www/froxlor, needed for chown $mypath = makeCorrectDir(FROXLOR_INSTALL_DIR);
$user = $settings['system']['mod_fcgid_httpuser']; $user = $settings['system']['mod_fcgid_httpuser'];
$group = $settings['system']['mod_fcgid_httpgroup']; $group = $settings['system']['mod_fcgid_httpgroup'];
// all the files and folders have to belong to the local user // all the files and folders have to belong to the local user
@@ -161,7 +158,6 @@ if ((int)$settings['system']['mod_fcgid'] == 1
// be sure HTMLPurifier's cache folder is writable // be sure HTMLPurifier's cache folder is writable
safe_exec('chmod -R 0755 '.escapeshellarg(dirname(__FILE__).'/classes/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer')); safe_exec('chmod -R 0755 '.escapeshellarg(dirname(__FILE__).'/classes/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer'));
if (!isset($settings['panel']['version']) if (!isset($settings['panel']['version'])
|| $settings['panel']['version'] != $version || $settings['panel']['version'] != $version
) { ) {

View File

@@ -22,15 +22,6 @@ if ($settings['logger']['log_cron'] == '1') {
fwrite($debugHandler, 'Logging for cron has been shutdown' . "\n"); fwrite($debugHandler, 'Logging for cron has been shutdown' . "\n");
} }
// TODO remove when completely migrated to PDO
$db->close();
fwrite($debugHandler, 'Closing database connection' . "\n");
if (isset($db_root)) {
$db_root->close();
fwrite($debugHandler, 'Closing database rootconnection' . "\n");
}
if ($keepLockFile === true) { if ($keepLockFile === true) {
fwrite($debugHandler, '=== Keep lockfile because of exception ==='); fwrite($debugHandler, '=== Keep lockfile because of exception ===');
} }

View File

@@ -63,12 +63,10 @@ unset($key);
$filename = basename($_SERVER['PHP_SELF']); $filename = basename($_SERVER['PHP_SELF']);
// keep this for compatibility reasons
$pathtophpfiles = dirname(dirname(__FILE__));
// define default theme for configurehint, etc. // define default theme for configurehint, etc.
$_deftheme = 'Sparkle'; $_deftheme = 'Sparkle';
// define installation directory
define('FROXLOR_INSTALL_DIR', dirname(dirname(__FILE__))); define('FROXLOR_INSTALL_DIR', dirname(dirname(__FILE__)));
// check whether the userdata file exists // check whether the userdata file exists

View File

@@ -17,7 +17,7 @@
define('MASTER_CRONJOB', 1); define('MASTER_CRONJOB', 1);
include_once(dirname(dirname(__FILE__)) . '/lib/cron_init.php'); include_once dirname(dirname(__FILE__)) . '/lib/cron_init.php';
$jobs_to_run = includeCronjobs($debugHandler); $jobs_to_run = includeCronjobs($debugHandler);
@@ -37,7 +37,7 @@ if (isset($argv[1]) && strtolower($argv[1]) == '--help') {
*/ */
for ($x = 1; $x < count($argv); $x++) { for ($x = 1; $x < count($argv); $x++) {
if (isset($argv[$x]) && strtolower($argv[$x]) == '--force') { if (isset($argv[$x]) && strtolower($argv[$x]) == '--force') {
$crontasks = makeCorrectFile($pathtophpfiles.'/scripts/jobs/cron_tasks.php'); $crontasks = makeCorrectFile(FROXLOR_INSTALL_DIR.'/scripts/jobs/cron_tasks.php');
// really force re-generating of config-files by // really force re-generating of config-files by
// inserting task 1 // inserting task 1
inserttask('1'); inserttask('1');
@@ -46,7 +46,7 @@ for ($x = 1; $x < count($argv); $x++) {
} }
} }
elseif (isset($argv[$x]) && substr(strtolower($argv[$x]), 0, 8) == '--force-') { elseif (isset($argv[$x]) && substr(strtolower($argv[$x]), 0, 8) == '--force-') {
$crontasks = makeCorrectFile($pathtophpfiles.'/scripts/jobs/cron_'.substr(strtolower($argv[$x]), 8).'.php'); $crontasks = makeCorrectFile(FROXLOR_INSTALL_DIR.'/scripts/jobs/cron_'.substr(strtolower($argv[$x]), 8).'.php');
if (file_exists($crontasks)) { if (file_exists($crontasks)) {
if (!in_array($crontasks, $jobs_to_run)) { if (!in_array($crontasks, $jobs_to_run)) {
array_unshift($jobs_to_run, $crontasks); array_unshift($jobs_to_run, $crontasks);
@@ -69,7 +69,5 @@ fwrite($debugHandler, 'Cronfiles have been included' . "\n");
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Checking system\'s last guid'); $cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Checking system\'s last guid');
checkLastGuid(); checkLastGuid();
/* // shutdown cron
* shutdown cron include_once FROXLOR_INSTALL_DIR . '/lib/cron_shutdown.php';
*/
include_once($pathtophpfiles . '/lib/cron_shutdown.php');

View File

@@ -17,17 +17,8 @@
* *
*/ */
if(@php_sapi_name() != 'cli'
&& @php_sapi_name() != 'cgi'
&& @php_sapi_name() != 'cgi-fcgi')
{
die('This script only works in the shell.');
}
class bind class bind
{ {
public $db = false;
public $logger = false; public $logger = false;
public $debugHandler = false; public $debugHandler = false;
public $settings = array(); public $settings = array();
@@ -35,9 +26,8 @@ class bind
public $mxservers = array(); public $mxservers = array();
public $axfrservers = array(); public $axfrservers = array();
public function __construct($db, $logger, $debugHandler, $settings) { public function __construct($logger, $debugHandler, $settings) {
$this->db = $db;
$this->logger = $logger; $this->logger = $logger;
$this->debugHandler = $debugHandler; $this->debugHandler = $debugHandler;
$this->settings = $settings; $this->settings = $settings;
@@ -89,10 +79,14 @@ class bind
$known_filenames = array(); $known_filenames = array();
$bindconf_file = '# ' . $this->settings['system']['bindconf_directory'] . 'froxlor_bind.conf' . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n"; $bindconf_file = '# ' . $this->settings['system']['bindconf_directory'] . 'froxlor_bind.conf' . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n";
$result_domains = $this->db->query("SELECT `d`.`id`, `d`.`domain`, `d`.`iswildcarddomain`, `d`.`wwwserveralias`, `d`.`customerid`, `d`.`zonefile`, `d`.`bindserial`, `d`.`dkim`, `d`.`dkim_id`, `d`.`dkim_pubkey`, `c`.`loginname`, `c`.`guid` FROM `" . TABLE_PANEL_DOMAINS . "` `d` LEFT JOIN `" . TABLE_PANEL_CUSTOMERS . "` `c` USING(`customerid`) WHERE `d`.`isbinddomain` = '1' ORDER BY `d`.`domain` ASC"); $result_domains_stmt = Database::query("
SELECT `d`.`id`, `d`.`domain`, `d`.`iswildcarddomain`, `d`.`wwwserveralias`, `d`.`customerid`, `d`.`zonefile`, `d`.`bindserial`, `d`.`dkim`, `d`.`dkim_id`, `d`.`dkim_pubkey`, `c`.`loginname`, `c`.`guid`
FROM `" . TABLE_PANEL_DOMAINS . "` `d` LEFT JOIN `" . TABLE_PANEL_CUSTOMERS . "` `c` USING(`customerid`)
WHERE `d`.`isbinddomain` = '1' ORDER BY `d`.`domain` ASC
");
while ($domain = $result_domains_stmt->fetch(PDO::FETCH_ASSOC)) {
while($domain = $this->db->fetch_array($result_domains))
{
fwrite($this->debugHandler, ' cron_tasks: Task4 - Writing ' . $domain['id'] . '::' . $domain['domain'] . "\n"); fwrite($this->debugHandler, ' cron_tasks: Task4 - Writing ' . $domain['id'] . '::' . $domain['domain'] . "\n");
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'Writing ' . $domain['id'] . '::' . $domain['domain']); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'Writing ' . $domain['id'] . '::' . $domain['domain']);
@@ -181,9 +175,15 @@ class bind
// Array to save DNS records // Array to save DNS records
$records = array(); $records = array();
$result_ip = $this->db->query("SELECT `p`.`ip` AS `ip` FROM `".TABLE_PANEL_IPSANDPORTS."` `p`, `".TABLE_DOMAINTOIP."` `di` WHERE `di`.`id_domain` = '$domain[id]' AND `p`.`id` = `di`.`id_ipandports` GROUP BY `p`.`ip`;"); $result_ip_stmt = Database::prepare("
SELECT `p`.`ip` AS `ip`
FROM `".TABLE_PANEL_IPSANDPORTS."` `p`, `".TABLE_DOMAINTOIP."` `di`
WHERE `di`.`id_domain` = :domainid AND `p`.`id` = `di`.`id_ipandports`
GROUP BY `p`.`ip`;
");
Database::pexecute($result_ip_stmt, array('domainid' => $domain['id']));
while ($ip = $this->db->fetch_array($result_ip)) { while ($ip = $result_ip_stmt->fetch(PDO::FETCH_ASSOC)) {
if (filter_var($ip['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { if (filter_var($ip['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$ip_a_records[] = "A\t\t" . $ip['ip']; $ip_a_records[] = "A\t\t" . $ip['ip'];
@@ -198,15 +198,18 @@ class bind
$date = date('Ymd'); $date = date('Ymd');
$bindserial = (preg_match('/^' . $date . '/', $domain['bindserial']) ? $domain['bindserial'] + 1 : $date . '00'); $bindserial = (preg_match('/^' . $date . '/', $domain['bindserial']) ? $domain['bindserial'] + 1 : $date . '00');
$this->db->query("UPDATE `" . TABLE_PANEL_DOMAINS . "` SET `bindserial`='" . $bindserial . "' WHERE `id`='" . $domain['id'] . "'");
$zonefile = '$TTL ' . (int)$this->settings['system']['defaultttl'] . "\n";
if(count($this->nameservers) == 0) $upd_stmt = Database::prepare("
{ UPDATE `" . TABLE_PANEL_DOMAINS . "` SET
`bindserial` = :serial
WHERE `id` = :id
");
Database::pexecute($upd_stmt, array('serial' => $bindserial, 'id' => $domain['id']));
$zonefile = '$TTL ' . (int)$this->settings['system']['defaultttl'] . "\n";
if (count($this->nameservers) == 0) {
$zonefile.= '@ IN SOA ns ' . str_replace('@', '.', $this->settings['panel']['adminmail']) . '. (' . "\n"; $zonefile.= '@ IN SOA ns ' . str_replace('@', '.', $this->settings['panel']['adminmail']) . '. (' . "\n";
} } else {
else
{
$zonefile.= '@ IN SOA ' . $this->nameservers[0]['hostname'] . ' ' . str_replace('@', '.', $this->settings['panel']['adminmail']) . '. (' . "\n"; $zonefile.= '@ IN SOA ' . $this->nameservers[0]['hostname'] . ' ' . str_replace('@', '.', $this->settings['panel']['adminmail']) . '. (' . "\n";
} }
@@ -261,22 +264,22 @@ class bind
*/ */
$zonefile.= $this->generateDkim($domain); $zonefile.= $this->generateDkim($domain);
$nssubdomains = $this->db->query('SELECT `domain` FROM `' . TABLE_PANEL_DOMAINS . '` WHERE `isbinddomain`=\'1\' AND `domain` LIKE \'%.' . $domain['domain'] . '\''); $nssubdomains_stmt = Database::prepare("
SELECT `domain` FROM `" . TABLE_PANEL_DOMAINS . "`
WHERE `isbinddomain` = '1' AND `domain` LIKE :domain
");
Database::pexecute($nssubdomains_stmt, array('domain' => '%.' . $domain['domain']));
while ($nssubdomain = $nssubdomains_stmt->fetch(PDO::FETCH_ASSOC)) {
if (preg_match('/^[^\.]+\.' . preg_quote($domain['domain'], '/') . '/', $nssubdomain['domain'])) {
while($nssubdomain = $this->db->fetch_array($nssubdomains))
{
if(preg_match('/^[^\.]+\.' . preg_quote($domain['domain'], '/') . '/', $nssubdomain['domain']))
{
$nssubdomain = str_replace('.' . $domain['domain'], '', $nssubdomain['domain']); $nssubdomain = str_replace('.' . $domain['domain'], '', $nssubdomain['domain']);
if(count($this->nameservers) == 0) if (count($this->nameservers) == 0) {
{
$zonefile.= $nssubdomain . ' IN NS ns.' . $nssubdomain . "\n"; $zonefile.= $nssubdomain . ' IN NS ns.' . $nssubdomain . "\n";
} } else {
else foreach ($this->nameservers as $nameserver) {
{
foreach($this->nameservers as $nameserver)
{
$zonefile.= $nssubdomain . ' IN NS ' . trim($nameserver['hostname']) . "\n"; $zonefile.= $nssubdomain . ' IN NS ' . trim($nameserver['hostname']) . "\n";
} }
} }
@@ -286,16 +289,17 @@ class bind
$records[] = '@'; $records[] = '@';
$records[] = 'www'; $records[] = 'www';
if ($domain['iswildcarddomain'] == '1') {
if($domain['iswildcarddomain'] == '1')
{
$records[] = '*'; $records[] = '*';
} }
$subdomains = $this->db->query("SELECT `domain` FROM `".TABLE_PANEL_DOMAINS."` WHERE `parentdomainid` = '$domain[id]';"); $subdomains_stmt = Database::prepare("
SELECT `domain` FROM `".TABLE_PANEL_DOMAINS."`
WHERE `parentdomainid` = :domainid
");
Database::pexecute($subdomains_stmt, array('domainid' => $domain['id']));
while($subdomain = $this->db->fetch_array($subdomains)) while ($subdomain = $subdomains_stmt->fetch(PDO::FETCH_ASSOC)) {
{
// Listing domains is enough as there currently is no support for choosing // Listing domains is enough as there currently is no support for choosing
// different ips for a subdomain => use same IPs as toplevel // different ips for a subdomain => use same IPs as toplevel
$records[] = str_replace('.' . $domain['domain'], '', $subdomain['domain']); $records[] = str_replace('.' . $domain['domain'], '', $subdomain['domain']);
@@ -331,26 +335,21 @@ class bind
// algorithm // algorithm
$algorithm = explode(',', $this->settings['dkim']['dkim_algorithm']); $algorithm = explode(',', $this->settings['dkim']['dkim_algorithm']);
$alg = ''; $alg = '';
foreach($algorithm as $a) foreach ($algorithm as $a) {
{ if ($a == 'all') {
if($a == 'all')
{
break; break;
} } else {
else
{
$alg.=$a.':'; $alg.=$a.':';
} }
} }
if($alg != '')
{ if ($alg != '') {
$alg = substr($alg, 0, -1); $alg = substr($alg, 0, -1);
$dkim_txt.= 'h='.$alg.';'; $dkim_txt.= 'h='.$alg.';';
} }
// notes // notes
if(trim($this->settings['dkim']['dkim_notes'] != '')) if (trim($this->settings['dkim']['dkim_notes'] != '')) {
{
$dkim_txt.= 'n='.trim($this->settings['dkim']['dkim_notes']).';'; $dkim_txt.= 'n='.trim($this->settings['dkim']['dkim_notes']).';';
} }
@@ -358,8 +357,7 @@ class bind
$dkim_txt.= 'k=rsa;p='.trim(preg_replace('/-----BEGIN PUBLIC KEY-----(.+)-----END PUBLIC KEY-----/s', '$1', str_replace("\n", '', $domain['dkim_pubkey']))).';'; $dkim_txt.= 'k=rsa;p='.trim(preg_replace('/-----BEGIN PUBLIC KEY-----(.+)-----END PUBLIC KEY-----/s', '$1', str_replace("\n", '', $domain['dkim_pubkey']))).';';
// service-type // service-type
if($this->settings['dkim']['dkim_servicetype'] == '1') if ($this->settings['dkim']['dkim_servicetype'] == '1') {
{
$dkim_txt.= 's=email;'; $dkim_txt.= 's=email;';
} }
@@ -369,8 +367,7 @@ class bind
// split if necessary // split if necessary
$txt_record_split=''; $txt_record_split='';
$lbr=50; $lbr=50;
for($pos=0; $pos<=strlen($dkim_txt)-1; $pos+=$lbr) for ($pos=0; $pos<=strlen($dkim_txt)-1; $pos+=$lbr) {
{
$txt_record_split.= (($pos==0) ? '("' : "\t\t\t\t\t \"") . substr($dkim_txt, $pos, $lbr) . (($pos>=strlen($dkim_txt)-$lbr) ? '")' : '"' ) ."\n"; $txt_record_split.= (($pos==0) ? '("' : "\t\t\t\t\t \"") . substr($dkim_txt, $pos, $lbr) . (($pos>=strlen($dkim_txt)-$lbr) ? '")' : '"' ) ."\n";
} }
@@ -378,8 +375,8 @@ class bind
$zone_dkim .= 'dkim_' . $domain['dkim_id'] . '._domainkey IN TXT ' . $txt_record_split; $zone_dkim .= 'dkim_' . $domain['dkim_id'] . '._domainkey IN TXT ' . $txt_record_split;
// adsp-entry // adsp-entry
if($this->settings['dkim']['dkim_add_adsp'] == "1") if ($this->settings['dkim']['dkim_add_adsp'] == "1") {
{
$zone_dkim .= '_adsp._domainkey IN TXT "dkim='; $zone_dkim .= '_adsp._domainkey IN TXT "dkim=';
switch((int)$this->settings['dkim']['dkim_add_adsppolicy']) switch((int)$this->settings['dkim']['dkim_add_adsppolicy'])
{ {
@@ -411,17 +408,21 @@ class bind
$dkimdomains = ''; $dkimdomains = '';
$dkimkeys = ''; $dkimkeys = '';
$result_domains = $this->db->query("SELECT `id`, `domain`, `dkim`, `dkim_id`, `dkim_pubkey`, `dkim_privkey` FROM `" . TABLE_PANEL_DOMAINS . "` WHERE `dkim` = '1' ORDER BY `id` ASC"); $result_domains_stmt = Database::query("
SELECT `id`, `domain`, `dkim`, `dkim_id`, `dkim_pubkey`, `dkim_privkey`
FROM `" . TABLE_PANEL_DOMAINS . "` WHERE `dkim` = '1' ORDER BY `id` ASC
");
while ($domain = $result_domains_stmt->fetch(PDO::FETCH_ASSOC)) {
while($domain = $this->db->fetch_array($result_domains))
{
$privkey_filename = makeCorrectFile($this->settings['dkim']['dkim_prefix'] . '/dkim_' . $domain['dkim_id']); $privkey_filename = makeCorrectFile($this->settings['dkim']['dkim_prefix'] . '/dkim_' . $domain['dkim_id']);
$pubkey_filename = makeCorrectFile($this->settings['dkim']['dkim_prefix'] . '/dkim_' . $domain['dkim_id'] . '.public'); $pubkey_filename = makeCorrectFile($this->settings['dkim']['dkim_prefix'] . '/dkim_' . $domain['dkim_id'] . '.public');
if($domain['dkim_privkey'] == '' if($domain['dkim_privkey'] == ''
|| $domain['dkim_pubkey'] == '') || $domain['dkim_pubkey'] == '')
{ {
$max_dkim_id = $this->db->query_first("SELECT MAX(`dkim_id`) as `max_dkim_id` FROM `" . TABLE_PANEL_DOMAINS . "`"); $max_dkim_id_stmt = Database::query("SELECT MAX(`dkim_id`) as `max_dkim_id` FROM `" . TABLE_PANEL_DOMAINS . "`");
$max_dkim_id = $max_dkim_id_stmt->fetch(PDO::FETCH_ASSOC);
$domain['dkim_id'] = (int)$max_dkim_id['max_dkim_id'] + 1; $domain['dkim_id'] = (int)$max_dkim_id['max_dkim_id'] + 1;
$privkey_filename = makeCorrectFile($this->settings['dkim']['dkim_prefix'] . '/dkim_' . $domain['dkim_id']); $privkey_filename = makeCorrectFile($this->settings['dkim']['dkim_prefix'] . '/dkim_' . $domain['dkim_id']);
safe_exec('openssl genrsa -out ' . escapeshellarg($privkey_filename) . ' ' . $this->settings['dkim']['dkim_keylength']); safe_exec('openssl genrsa -out ' . escapeshellarg($privkey_filename) . ' ' . $this->settings['dkim']['dkim_keylength']);
@@ -431,7 +432,20 @@ class bind
safe_exec('openssl rsa -in ' . escapeshellarg($privkey_filename) . ' -pubout -outform pem -out ' . escapeshellarg($pubkey_filename)); safe_exec('openssl rsa -in ' . escapeshellarg($privkey_filename) . ' -pubout -outform pem -out ' . escapeshellarg($pubkey_filename));
$domain['dkim_pubkey'] = file_get_contents($pubkey_filename); $domain['dkim_pubkey'] = file_get_contents($pubkey_filename);
safe_exec("chmod 0664 " . escapeshellarg($pubkey_filename)); safe_exec("chmod 0664 " . escapeshellarg($pubkey_filename));
$this->db->query("UPDATE `" . TABLE_PANEL_DOMAINS . "` SET `dkim_id` = '" . $domain['dkim_id'] . "', `dkim_privkey` = '" . $domain['dkim_privkey'] . "', `dkim_pubkey` = '" . $domain['dkim_pubkey'] . "' WHERE `id` = '" . $domain['id'] . "'"); $upd_stmt = Database::prepare("
UPDATE `" . TABLE_PANEL_DOMAINS . "` SET
`dkim_id` = :dkimid,
`dkim_privkey` = :privkey,
`dkim_pubkey` = :pubkey
WHERE `id` = :id
");
$upd_data = array(
'dkimid' => $domain['dkim_id'],
'privkey' => $domain['dkim_privkey'],
'pubkey' => $domain['dkim_pubkey'],
'id' => $domain['id']
);
Database::pexecute($upd_stmt, $upd_data);
} }
if(!file_exists($privkey_filename) if(!file_exists($privkey_filename)
@@ -471,5 +485,3 @@ class bind
} }
} }
} }
?>

View File

@@ -17,22 +17,13 @@
* *
*/ */
if(@php_sapi_name() != 'cli'
&& @php_sapi_name() != 'cgi'
&& @php_sapi_name() != 'cgi-fcgi')
{
die('This script only works in the shell.');
}
class apache class apache
{ {
private $db = false;
private $logger = false; private $logger = false;
private $debugHandler = false; private $debugHandler = false;
private $idnaConvert = false; private $idnaConvert = false;
// protected // protected
protected $settings = array(); protected $settings = array();
protected $known_vhostfilenames = array(); protected $known_vhostfilenames = array();
protected $known_diroptionsfilenames = array(); protected $known_diroptionsfilenames = array();
@@ -49,9 +40,8 @@ class apache
*/ */
private $_deactivated = false; private $_deactivated = false;
public function __construct($db, $logger, $debugHandler, $idnaConvert, $settings) public function __construct($logger, $debugHandler, $idnaConvert, $settings)
{ {
$this->db = $db;
$this->logger = $logger; $this->logger = $logger;
$this->debugHandler = $debugHandler; $this->debugHandler = $debugHandler;
$this->idnaConvert = $idnaConvert; $this->idnaConvert = $idnaConvert;
@@ -59,11 +49,6 @@ class apache
} }
protected function getDB()
{
return $this->db;
}
public function reload() public function reload()
{ {
if((int)$this->settings['phpfpm']['enabled'] == 1) if((int)$this->settings['phpfpm']['enabled'] == 1)
@@ -157,9 +142,9 @@ class apache
public function createIpPort() public function createIpPort()
{ {
$result_ipsandports = $this->db->query("SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` ORDER BY `ip` ASC, `port` ASC"); $result_ipsandports_stmt = Database::query("SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` ORDER BY `ip` ASC, `port` ASC");
while ($row_ipsandports = $this->db->fetch_array($result_ipsandports)) { while ($row_ipsandports = $result_ipsandports_stmt->fetch(PDO::FETCH_ASSOC)) {
if (filter_var($row_ipsandports['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { if (filter_var($row_ipsandports['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$ipport = '[' . $row_ipsandports['ip'] . ']:' . $row_ipsandports['port']; $ipport = '[' . $row_ipsandports['ip'] . ']:' . $row_ipsandports['port'];
} else { } else {
@@ -375,10 +360,14 @@ class apache
$this->_createStandardErrorHandler(); $this->_createStandardErrorHandler();
} }
/* /**
* We put together the needed php options in the virtualhost entries * We put together the needed php options in the virtualhost entries
*/ *
* @param array $domain
* @param bool $ssl_vhost
*
* @return string
*/
protected function composePhpOptions($domain, $ssl_vhost = false) protected function composePhpOptions($domain, $ssl_vhost = false)
{ {
$php_options_text = ''; $php_options_text = '';
@@ -404,12 +393,10 @@ class apache
return $php_options_text; return $php_options_text;
} }
public function createOwnVhostStarter() public function createOwnVhostStarter() {}
{
}
/* /**
* We collect all servernames and Aliases * We collect all servernames and Aliases
*/ */
protected function getServerNames($domain) protected function getServerNames($domain)
{ {
@@ -426,9 +413,14 @@ class apache
$servernames_text .= ' ServerAlias ' . $server_alias . "\n"; $servernames_text .= ' ServerAlias ' . $server_alias . "\n";
} }
$alias_domains = $this->db->query('SELECT `domain`, `iswildcarddomain`, `wwwserveralias` FROM `' . TABLE_PANEL_DOMAINS . '` WHERE `aliasdomain`=\'' . $domain['id'] . '\''); $alias_domains_stmt = Database::prepare("
SELECT `domain`, `iswildcarddomain`, `wwwserveralias`
FROM `" . TABLE_PANEL_DOMAINS . "`
WHERE `aliasdomain`= :domainid
");
Database::pexecute($alias_domains_stmt, array('domainid' => $domain['id']));
while (($alias_domain = $this->db->fetch_array($alias_domains)) !== false) { while (($alias_domain = $alias_domains_stmt->fetch(PDO::FETCH_ASSOC)) !== false) {
$server_alias = ' ServerAlias ' . $alias_domain['domain']; $server_alias = ' ServerAlias ' . $alias_domain['domain'];
if ($alias_domain['iswildcarddomain'] == '1') { if ($alias_domain['iswildcarddomain'] == '1') {
@@ -446,7 +438,7 @@ class apache
return $servernames_text; return $servernames_text;
} }
/* /**
* Let's get the webroot * Let's get the webroot
*/ */
protected function getWebroot($domain) protected function getWebroot($domain)
@@ -469,7 +461,7 @@ class apache
return $webroot_text; return $webroot_text;
} }
/* /**
* Lets set the text part for the stats software * Lets set the text part for the stats software
*/ */
protected function getStats($domain) protected function getStats($domain)
@@ -506,9 +498,9 @@ class apache
return $stats_text; return $stats_text;
} }
/* /**
* Lets set the logfiles * Lets set the logfiles
*/ */
protected function getLogfiles($domain) { protected function getLogfiles($domain) {
$logfiles_text = ''; $logfiles_text = '';
@@ -543,11 +535,14 @@ class apache
if ((int)$domain['parentdomainid'] == 0) { if ((int)$domain['parentdomainid'] == 0) {
// prepare the aliases and subdomains for stats config files // prepare the aliases and subdomains for stats config files
$server_alias = ''; $server_alias = '';
$alias_domains = $this->db->query('SELECT `domain`, `iswildcarddomain`, `wwwserveralias` FROM `' . TABLE_PANEL_DOMAINS . '` $alias_domains_stmt = Database::prepare("
WHERE `aliasdomain`=\'' . $domain['id'] . '\' SELECT `domain`, `iswildcarddomain`, `wwwserveralias`
OR `parentdomainid` =\''. $domain['id']. '\''); FROM `" . TABLE_PANEL_DOMAINS . "`
WHERE `aliasdomain` = :domainid OR `parentdomainid` = :domainid
");
Database::pexecute($alias_domains_stmt, array('domainid' => $domain['id']));
while (($alias_domain = $this->db->fetch_array($alias_domains)) !== false) { while (($alias_domain = $alias_domains_stmt->fetch(PDO::FETCH_ASSOC)) !== false) {
$server_alias .= ' ' . $alias_domain['domain'] . ' '; $server_alias .= ' ' . $alias_domain['domain'] . ' ';
@@ -576,7 +571,7 @@ class apache
return $logfiles_text; return $logfiles_text;
} }
/* /**
* Get the filename for the virtualhost * Get the filename for the virtualhost
*/ */
protected function getVhostFilename($domain, $ssl_vhost = false) protected function getVhostFilename($domain, $ssl_vhost = false)
@@ -605,7 +600,7 @@ class apache
return $vhost_filename; return $vhost_filename;
} }
/* /**
* We compose the virtualhost entry for one domain * We compose the virtualhost entry for one domain
*/ */
protected function getVhostContent($domain, $ssl_vhost = false) protected function getVhostContent($domain, $ssl_vhost = false)
@@ -618,7 +613,7 @@ class apache
} }
$query = "SELECT * FROM `".TABLE_PANEL_IPSANDPORTS."` `i`, `".TABLE_DOMAINTOIP."` `dip` $query = "SELECT * FROM `".TABLE_PANEL_IPSANDPORTS."` `i`, `".TABLE_DOMAINTOIP."` `dip`
WHERE dip.id_domain = '".(int)$domain['id']."' AND i.id = dip.id_ipandports "; WHERE dip.id_domain = :domainid AND i.id = dip.id_ipandports ";
if ($ssl_vhost === true if ($ssl_vhost === true
&& ($domain['ssl'] == '1' || $domain['ssl_redirect'] == '1') && ($domain['ssl'] == '1' || $domain['ssl_redirect'] == '1')
@@ -630,11 +625,12 @@ class apache
} }
$vhost_content = ''; $vhost_content = '';
$result = $this->db->query($query); $result_stmt = Database::prepare($query);
Database::pexecute($result_stmt, array('domainid' => $domain['id']));
$ipportlist = ''; $ipportlist = '';
$_vhost_content = ''; $_vhost_content = '';
while ($ipandport = $this->db->fetch_array($result)) { while ($ipandport = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
$ipport = ''; $ipport = '';
$domain['ip'] = $ipandport['ip']; $domain['ip'] = $ipandport['ip'];
@@ -677,13 +673,14 @@ class apache
// This returns the first port that is != 443 with ssl enabled, if any // This returns the first port that is != 443 with ssl enabled, if any
// ordered by ssl-certificate (if any) so that the ip/port combo // ordered by ssl-certificate (if any) so that the ip/port combo
// with certificate is used // with certificate is used
$ssldestport = $this->db->query_first( $ssldestport_stmt = Database::prepare("
"SELECT `ip`.`port` FROM ".TABLE_PANEL_IPSANDPORTS." `ip` SELECT `ip`.`port` FROM ".TABLE_PANEL_IPSANDPORTS." `ip`
LEFT JOIN `".TABLE_DOMAINTOIP."` `dip` ON (`ip`.`id` = `dip`.`id_ipandports`) LEFT JOIN `".TABLE_DOMAINTOIP."` `dip` ON (`ip`.`id` = `dip`.`id_ipandports`)
WHERE `dip`.`id_domain` = '".(int)$domain['id']."' WHERE `dip`.`id_domain` = :domainid
AND `ip`.`ssl` = '1' AND `ip`.`port` != 443 AND `ip`.`ssl` = '1' AND `ip`.`port` != 443
ORDER BY `ip`.`ssl_cert_file` DESC, `ip`.`port` LIMIT 1;" ORDER BY `ip`.`ssl_cert_file` DESC, `ip`.`port` LIMIT 1;
); ");
$ssldestport = Database::pexecute_first($ssldestport_stmt, array('domainid' => $domain['id']));
if ($ssldestport['port'] != '') { if ($ssldestport['port'] != '') {
$_sslport = ":".$ssldestport['port']; $_sslport = ":".$ssldestport['port'];
@@ -737,7 +734,7 @@ class apache
if (preg_match('/^https?\:\/\//', $domain['documentroot'])) { if (preg_match('/^https?\:\/\//', $domain['documentroot'])) {
$corrected_docroot = $this->idnaConvert->encode($domain['documentroot']); $corrected_docroot = $this->idnaConvert->encode($domain['documentroot']);
/* Get domain's redirect code */ // Get domain's redirect code
$code = getDomainRedirectCode($domain['id']); $code = getDomainRedirectCode($domain['id']);
$modrew_red = ''; $modrew_red = '';
if ($code != '') { if ($code != '') {
@@ -782,7 +779,7 @@ class apache
return $vhost_content; return $vhost_content;
} }
/* /**
* We compose the virtualhost entries for the domains * We compose the virtualhost entries for the domains
*/ */
public function createVirtualHosts() public function createVirtualHosts()
@@ -811,8 +808,8 @@ class apache
WHERE `d`.`aliasdomain` IS NULL AND `d`.`email_only` <> '1' WHERE `d`.`aliasdomain` IS NULL AND `d`.`email_only` <> '1'
ORDER BY `d`.`parentdomainid` DESC, `d`.`iswildcarddomain`, `d`.`domain` ASC;"; ORDER BY `d`.`parentdomainid` DESC, `d`.`iswildcarddomain`, `d`.`domain` ASC;";
$result_domains = $this->db->query($query); $result_domains_stmt = Database::query($query);
while ($domain = $this->db->fetch_array($result_domains)) { while ($domain = $result_domains_stmt->fetch(PDO::FETCH_ASSOC)) {
fwrite($this->debugHandler, ' apache::createVirtualHosts: creating vhost container for domain ' . $domain['id'] . ', customer ' . $domain['loginname'] . "\n"); fwrite($this->debugHandler, ' apache::createVirtualHosts: creating vhost container for domain ' . $domain['id'] . ', customer ' . $domain['loginname'] . "\n");
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'creating vhost container for domain ' . $domain['id'] . ', customer ' . $domain['loginname']); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'creating vhost container for domain ' . $domain['id'] . ', customer ' . $domain['loginname']);
$vhosts_filename = $this->getVhostFilename($domain); $vhosts_filename = $this->getVhostFilename($domain);
@@ -838,15 +835,20 @@ class apache
} }
} }
/* /**
* We compose the diroption entries for the paths * We compose the diroption entries for the paths
*/ */
public function createFileDirOptions() public function createFileDirOptions()
{ {
$result = $this->db->query('SELECT `htac`.*, `c`.`guid`, `c`.`documentroot` AS `customerroot` FROM `' . TABLE_PANEL_HTACCESS . '` `htac` LEFT JOIN `' . TABLE_PANEL_CUSTOMERS . '` `c` USING (`customerid`) ORDER BY `htac`.`path`'); $result_stmt = Database::query("
SELECT `htac`.*, `c`.`guid`, `c`.`documentroot` AS `customerroot`
FROM `" . TABLE_PANEL_HTACCESS . "` `htac`
LEFT JOIN `" . TABLE_PANEL_CUSTOMERS . "` `c` USING (`customerid`)
ORDER BY `htac`.`path`
");
$diroptions = array(); $diroptions = array();
while ($row_diroptions = $this->db->fetch_array($result)) { while ($row_diroptions = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
if ($row_diroptions['customerid'] != 0 if ($row_diroptions['customerid'] != 0
&& isset($row_diroptions['customerroot']) && isset($row_diroptions['customerroot'])
&& $row_diroptions['customerroot'] != '' && $row_diroptions['customerroot'] != ''
@@ -856,9 +858,14 @@ class apache
} }
} }
$result = $this->db->query('SELECT `htpw`.*, `c`.`guid`, `c`.`documentroot` AS `customerroot` FROM `' . TABLE_PANEL_HTPASSWDS . '` `htpw` LEFT JOIN `' . TABLE_PANEL_CUSTOMERS . '` `c` USING (`customerid`) ORDER BY `htpw`.`path`, `htpw`.`username`'); $result_stmt = Database::query("
SELECT `htpw`.*, `c`.`guid`, `c`.`documentroot` AS `customerroot`
FROM `" . TABLE_PANEL_HTPASSWDS . "` `htpw`
LEFT JOIN `" . TABLE_PANEL_CUSTOMERS . "` `c` USING (`customerid`)
ORDER BY `htpw`.`path`, `htpw`.`username`
");
while ($row_htpasswds = $this->db->fetch_array($result)) { while ($row_htpasswds = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
if ($row_htpasswds['customerid'] != 0 if ($row_htpasswds['customerid'] != 0
&& isset($row_htpasswds['customerroot']) && isset($row_htpasswds['customerroot'])
&& $row_htpasswds['customerroot'] != '' && $row_htpasswds['customerroot'] != ''
@@ -1013,20 +1020,18 @@ class apache
} }
} }
/* /**
* We write the configs * We write the configs
*/ */
public function writeConfigs() public function writeConfigs()
{ {
// Write diroptions // Write diroptions
fwrite($this->debugHandler, ' apache::writeConfigs: rebuilding ' . $this->settings['system']['apacheconf_diroptions'] . "\n"); fwrite($this->debugHandler, ' apache::writeConfigs: rebuilding ' . $this->settings['system']['apacheconf_diroptions'] . "\n");
$this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . $this->settings['system']['apacheconf_diroptions']); $this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . $this->settings['system']['apacheconf_diroptions']);
if (count($this->diroptions_data) > 0) { if (count($this->diroptions_data) > 0) {
if (!isConfigDir($this->settings['system']['apacheconf_diroptions'])) { if (!isConfigDir($this->settings['system']['apacheconf_diroptions'])) {
// Save one big file // Save one big file
$diroptions_file = ''; $diroptions_file = '';
foreach ($this->diroptions_data as $diroptions_filename => $diroptions_content) { foreach ($this->diroptions_data as $diroptions_filename => $diroptions_content) {
@@ -1036,7 +1041,6 @@ class apache
$diroptions_filename = $this->settings['system']['apacheconf_diroptions']; $diroptions_filename = $this->settings['system']['apacheconf_diroptions'];
// Apply header // Apply header
$diroptions_file = '# ' . basename($diroptions_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $diroptions_file; $diroptions_file = '# ' . basename($diroptions_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $diroptions_file;
$diroptions_file_handler = fopen($diroptions_filename, 'w'); $diroptions_file_handler = fopen($diroptions_filename, 'w');
fwrite($diroptions_file_handler, $diroptions_file); fwrite($diroptions_file_handler, $diroptions_file);
@@ -1049,7 +1053,6 @@ class apache
} }
// Write a single file for every diroption // Write a single file for every diroption
foreach ($this->diroptions_data as $diroptions_filename => $diroptions_file) { foreach ($this->diroptions_data as $diroptions_filename => $diroptions_file) {
$this->known_diroptionsfilenames[] = basename($diroptions_filename); $this->known_diroptionsfilenames[] = basename($diroptions_filename);
@@ -1063,7 +1066,6 @@ class apache
} }
// Write htpasswds // Write htpasswds
fwrite($this->debugHandler, ' apache::writeConfigs: rebuilding ' . $this->settings['system']['apacheconf_htpasswddir'] . "\n"); fwrite($this->debugHandler, ' apache::writeConfigs: rebuilding ' . $this->settings['system']['apacheconf_htpasswddir'] . "\n");
$this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . $this->settings['system']['apacheconf_htpasswddir']); $this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . $this->settings['system']['apacheconf_htpasswddir']);
@@ -1090,7 +1092,6 @@ class apache
} }
// Write virtualhosts // Write virtualhosts
fwrite($this->debugHandler, ' apache::writeConfigs: rebuilding ' . $this->settings['system']['apacheconf_vhost'] . "\n"); fwrite($this->debugHandler, ' apache::writeConfigs: rebuilding ' . $this->settings['system']['apacheconf_vhost'] . "\n");
$this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . $this->settings['system']['apacheconf_vhost']); $this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . $this->settings['system']['apacheconf_vhost']);
@@ -1111,7 +1112,6 @@ class apache
} }
// Include diroptions file in case it exists // Include diroptions file in case it exists
if (file_exists($this->settings['system']['apacheconf_diroptions'])) { if (file_exists($this->settings['system']['apacheconf_diroptions'])) {
$vhosts_file.= "\n" . 'Include ' . $this->settings['system']['apacheconf_diroptions'] . "\n\n"; $vhosts_file.= "\n" . 'Include ' . $this->settings['system']['apacheconf_diroptions'] . "\n\n";
} }

View File

@@ -17,13 +17,6 @@
* *
*/ */
if(@php_sapi_name() != 'cli'
&& @php_sapi_name() != 'cgi'
&& @php_sapi_name() != 'cgi-fcgi')
{
die('This script only works in the shell.');
}
class apache_fcgid extends apache class apache_fcgid extends apache
{ {
protected function composePhpOptions($domain, $ssl_vhost = false) protected function composePhpOptions($domain, $ssl_vhost = false)

View File

@@ -18,22 +18,13 @@
* @TODO ssl-redirect to non-standard port * @TODO ssl-redirect to non-standard port
*/ */
if(@php_sapi_name() != 'cli'
&& @php_sapi_name() != 'cgi'
&& @php_sapi_name() != 'cgi-fcgi'
) {
die('This script only works in the shell.');
}
class lighttpd class lighttpd
{ {
private $db = false;
private $logger = false; private $logger = false;
private $debugHandler = false; private $debugHandler = false;
private $idnaConvert = false; private $idnaConvert = false;
// protected // protected
protected $settings = array(); protected $settings = array();
protected $lighttpd_data = array(); protected $lighttpd_data = array();
protected $needed_htpasswds = array(); protected $needed_htpasswds = array();
@@ -49,20 +40,14 @@ class lighttpd
*/ */
private $_deactivated = false; private $_deactivated = false;
public function __construct($db, $logger, $debugHandler, $idnaConvert, $settings) public function __construct($logger, $debugHandler, $idnaConvert, $settings)
{ {
$this->db = $db;
$this->logger = $logger; $this->logger = $logger;
$this->debugHandler = $debugHandler; $this->debugHandler = $debugHandler;
$this->idnaConvert = $idnaConvert; $this->idnaConvert = $idnaConvert;
$this->settings = $settings; $this->settings = $settings;
} }
protected function getDB()
{
return $this->db;
}
public function reload() public function reload()
{ {
if ((int)$this->settings['phpfpm']['enabled'] == 1) { if ((int)$this->settings['phpfpm']['enabled'] == 1) {
@@ -77,10 +62,9 @@ class lighttpd
public function createIpPort() public function createIpPort()
{ {
$query = "SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` ORDER BY `ip` ASC, `port` ASC"; $result_ipsandports_stmt = Database::query("SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` ORDER BY `ip` ASC, `port` ASC");
$result_ipsandports = $this->db->query($query);
while ($row_ipsandports = $this->db->fetch_array($result_ipsandports)) { while ($row_ipsandports = $result_ipsandports_stmt->fetch(PDO::FETCH_ASSOC)) {
if (filter_var($row_ipsandports['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { if (filter_var($row_ipsandports['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$ip = '[' . $row_ipsandports['ip'] . ']'; $ip = '[' . $row_ipsandports['ip'] . ']';
$port = $row_ipsandports['port']; $port = $row_ipsandports['port'];
@@ -242,11 +226,14 @@ class lighttpd
protected function create_htaccess($domain) protected function create_htaccess($domain)
{ {
$needed_htpasswds = array(); $needed_htpasswds = array();
$htpasswd_query = "SELECT * FROM " . TABLE_PANEL_HTPASSWDS . " WHERE `path` LIKE '" . $domain['documentroot'] . "%'"; $result_htpasswds_stmt = Database::prepare("
$result_htpasswds = $this->db->query($htpasswd_query); SELECT * FROM " . TABLE_PANEL_HTPASSWDS . "
WHERE `path` LIKE :docroot
");
Database::pexecute($result_htpasswds_stmt, array('docroot' => $domain['documentroot'] . '%'));
$htaccess_text = ''; $htaccess_text = '';
while ($row_htpasswds = $this->db->fetch_array($result_htpasswds)) { while ($row_htpasswds = $result_htpasswds_stmt->fetch(PDO::FETCH_ASSOC)) {
$row_htpasswds['path'] = makeCorrectDir($row_htpasswds['path']); $row_htpasswds['path'] = makeCorrectDir($row_htpasswds['path']);
mkDirWithCorrectOwnership($domain['documentroot'], $row_htpasswds['path'], $domain['guid'], $domain['guid']); mkDirWithCorrectOwnership($domain['documentroot'], $row_htpasswds['path'], $domain['guid'], $domain['guid']);
@@ -328,8 +315,8 @@ class lighttpd
ORDER BY `d`.`parentdomainid` DESC, `d`.`iswildcarddomain`, `d`.`domain` ASC;"; ORDER BY `d`.`parentdomainid` DESC, `d`.`iswildcarddomain`, `d`.`domain` ASC;";
$included_vhosts = array(); $included_vhosts = array();
$result_domains = $this->db->query($query); $result_domains_stmt = Database::query($query);
while ($domain = $this->db->fetch_array($result_domains)) { while ($domain = $result_domains_stmt->fetch(PDO::FETCH_ASSOC)) {
if (is_dir($this->settings['system']['apacheconf_vhost'])) { if (is_dir($this->settings['system']['apacheconf_vhost'])) {
safe_exec('mkdir -p '.escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost'].'/vhosts/'))); safe_exec('mkdir -p '.escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost'].'/vhosts/')));
@@ -418,13 +405,14 @@ class lighttpd
// This returns the first port that is != 443 with ssl enabled, if any // This returns the first port that is != 443 with ssl enabled, if any
// ordered by ssl-certificate (if any) so that the ip/port combo // ordered by ssl-certificate (if any) so that the ip/port combo
// with certificate is used // with certificate is used
$ssldestport = $this->db->query_first( $ssldestport_stmt = Database::prepare(
"SELECT `ip`.`port` FROM ".TABLE_PANEL_IPSANDPORTS." `ip` "SELECT `ip`.`port` FROM ".TABLE_PANEL_IPSANDPORTS." `ip`
LEFT JOIN `".TABLE_DOMAINTOIP."` `dip` ON (`ip`.`id` = `dip`.`id_ipandports`) LEFT JOIN `".TABLE_DOMAINTOIP."` `dip` ON (`ip`.`id` = `dip`.`id_ipandports`)
WHERE `dip`.`id_domain` = '".(int)$domain['id']."' WHERE `dip`.`id_domain` = :domainid
AND `ip`.`ssl` = '1' AND `ip`.`port` != 443 AND `ip`.`ssl` = '1' AND `ip`.`port` != 443
ORDER BY `ip`.`ssl_cert_file` DESC, `ip`.`port` LIMIT 1;" ORDER BY `ip`.`ssl_cert_file` DESC, `ip`.`port` LIMIT 1;"
); );
$ssldestport = Database::pexecute_first($ssldestport_stmt, array('domainid' => $domain['id']));
if ($ssldestport['port'] != '') { if ($ssldestport['port'] != '') {
$_sslport = ":".$ssldestport['port']; $_sslport = ":".$ssldestport['port'];
@@ -457,8 +445,11 @@ class lighttpd
$vhost_content.= $this->composePhpOptions($domain); $vhost_content.= $this->composePhpOptions($domain);
$vhost_content.= $this->getStats($domain); $vhost_content.= $this->getStats($domain);
$query = "SELECT * FROM `".TABLE_PANEL_IPSANDPORTS."` WHERE `id`='".$ipid."';"; $ipandport_stmt = Database::prepare("
$ipandport = $this->db->query_first($query); SELECT * FROM `".TABLE_PANEL_IPSANDPORTS."`
WHERE `id` = :id
");
$ipandport = Database::pexecute_first($ipandport_stmt, array('id' => $ipid));
$domain['ip'] = $ipandport['ip']; $domain['ip'] = $ipandport['ip'];
$domain['port'] = $ipandport['port']; $domain['port'] = $ipandport['port'];
@@ -544,7 +535,6 @@ class lighttpd
// The normal access/error - logging is enabled // The normal access/error - logging is enabled
// error log cannot be set conditionally see // error log cannot be set conditionally see
// https://redmine.lighttpd.net/issues/665 // https://redmine.lighttpd.net/issues/665
$access_log = makeCorrectFile($this->settings['system']['logfiles_directory'] . $domain['loginname'] . $speciallogfile . '-access.log'); $access_log = makeCorrectFile($this->settings['system']['logfiles_directory'] . $domain['loginname'] . $speciallogfile . '-access.log');
// Create the logfile if it does not exist (fixes #46) // Create the logfile if it does not exist (fixes #46)
touch($access_log); touch($access_log);
@@ -558,11 +548,14 @@ class lighttpd
if ((int)$domain['parentdomainid'] == 0) { if ((int)$domain['parentdomainid'] == 0) {
// prepare the aliases and subdomains for stats config files // prepare the aliases and subdomains for stats config files
$server_alias = ''; $server_alias = '';
$alias_domains = $this->db->query('SELECT `domain`, `iswildcarddomain`, `wwwserveralias` FROM `' . TABLE_PANEL_DOMAINS . '` $alias_domains_stmt = Database::prepare("
WHERE `aliasdomain`=\'' . $domain['id'] . '\' SELECT `domain`, `iswildcarddomain`, `wwwserveralias`
OR `parentdomainid` =\''. $domain['id']. '\''); FROM `" . TABLE_PANEL_DOMAINS . "`
WHERE `aliasdomain` = :domainid OR `parentdomainid` = :domainid
");
Database::pexecute($alias_domains_stmt, array('domainid' => $domain['id']));
while (($alias_domain = $this->db->fetch_array($alias_domains)) !== false) { while (($alias_domain = $alias_domains_stmt->fetch(PDO::FETCH_ASSOC)) !== false) {
$server_alias.= ' ' . $alias_domain['domain'] . ' '; $server_alias.= ' ' . $alias_domain['domain'] . ' ';
@@ -600,13 +593,16 @@ class lighttpd
protected function create_pathOptions($domain) protected function create_pathOptions($domain)
{ {
$query = "SELECT * FROM " . TABLE_PANEL_HTACCESS . " WHERE `path` LIKE '" . $domain['documentroot'] . "%'"; $result_stmt = Database::prepare("
$result = $this->db->query($query); SELECT * FROM " . TABLE_PANEL_HTACCESS . "
WHERE `path` LIKE :docroot
");
Database::pexecute($result_stmt, array('docroot' => $domain['documentroot'] . '%'));
$path_options = ''; $path_options = '';
$error_string = ''; $error_string = '';
while ($row = $this->db->fetch_array($result)) { while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
if (!empty($row['error404path'])) { if (!empty($row['error404path'])) {
$defhandler = $row['error404path']; $defhandler = $row['error404path'];
@@ -661,10 +657,13 @@ class lighttpd
protected function getDirOptions($domain) protected function getDirOptions($domain)
{ {
$query = "SELECT * FROM " . TABLE_PANEL_HTPASSWDS . " WHERE `customerid`='" . $domain['customerid'] . "'"; $result_stmt = Database::prepare("
$result = $this->db->query($query); SELECT * FROM " . TABLE_PANEL_HTPASSWDS . "
WHERE `customerid` = :customerid
");
Database::pexecute($result_stmt, array('customerid' => $domain['customerid']));
while ($row_htpasswds = $this->db->fetch_array($result)) { while ($row_htpasswds = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
if ($auth_backend_loaded[$domain['ipandport']] != 'yes' if ($auth_backend_loaded[$domain['ipandport']] != 'yes'
&& $auth_backend_loaded[$domain['ssl_ipandport']] != 'yes' && $auth_backend_loaded[$domain['ssl_ipandport']] != 'yes'
) { ) {
@@ -721,9 +720,14 @@ class lighttpd
} }
} }
$alias_domains = $this->db->query('SELECT `domain`, `iswildcarddomain`, `wwwserveralias` FROM `' . TABLE_PANEL_DOMAINS . '` WHERE `aliasdomain`=\'' . $domain['id'] . '\''); $alias_domains_stmt = Database::prepare("
SELECT `domain`, `iswildcarddomain`, `wwwserveralias`
FROM `" . TABLE_PANEL_DOMAINS . "`
WHERE `aliasdomain` = :domainid
");
Database::pexecute($alias_domains_stmt, array('domainid' => $domain['id']));
while (($alias_domain = $this->db->fetch_array($alias_domains)) !== false) { while (($alias_domain = $alias_domains_stmt->fetch(PDO::FETCH_ASSOC)) !== false) {
$alias_domain_name = ereg_replace('\.', '\.', $alias_domain['domain']); $alias_domain_name = ereg_replace('\.', '\.', $alias_domain['domain']);
if ($alias_domain['iswildcarddomain'] == '1') { if ($alias_domain['iswildcarddomain'] == '1') {
@@ -800,10 +804,9 @@ class lighttpd
return $webroot_text; return $webroot_text;
} }
/* /**
* Lets set the text part for the stats software * Lets set the text part for the stats software
*/ */
protected function getStats($domain) protected function getStats($domain)
{ {
$stats_text = ''; $stats_text = '';
@@ -896,7 +899,6 @@ class lighttpd
} }
// Write the diroptions // Write the diroptions
if (isConfigDir($this->settings['system']['apacheconf_htpasswddir'])) { if (isConfigDir($this->settings['system']['apacheconf_htpasswddir'])) {
foreach ($this->needed_htpasswds as $key => $data) { foreach ($this->needed_htpasswds as $key => $data) {
if (!is_dir($this->settings['system']['apacheconf_htpasswddir'])) { if (!is_dir($this->settings['system']['apacheconf_htpasswddir'])) {

View File

@@ -15,13 +15,6 @@
* *
*/ */
if(@php_sapi_name() != 'cli'
&& @php_sapi_name() != 'cgi'
&& @php_sapi_name() != 'cgi-fcgi')
{
die('This script only works in the shell.');
}
class lighttpd_fcgid extends lighttpd class lighttpd_fcgid extends lighttpd
{ {
protected function composePhpOptions($domain) protected function composePhpOptions($domain)

View File

@@ -15,23 +15,14 @@
* *
*/ */
if(@php_sapi_name() != 'cli'
&& @php_sapi_name() != 'cgi'
&& @php_sapi_name() != 'cgi-fcgi')
{
die('This script only works in the shell.');
}
class nginx class nginx
{ {
private $db = false;
private $logger = false; private $logger = false;
private $debugHandler = false; private $debugHandler = false;
private $idnaConvert = false; private $idnaConvert = false;
private $nginx_server = array(); private $nginx_server = array();
// protected // protected
protected $settings = array(); protected $settings = array();
protected $nginx_data = array(); protected $nginx_data = array();
protected $needed_htpasswds = array(); protected $needed_htpasswds = array();
@@ -49,9 +40,8 @@ class nginx
*/ */
private $_deactivated = false; private $_deactivated = false;
public function __construct($db, $logger, $debugHandler, $idnaConvert, $settings, $nginx_server=array()) public function __construct($logger, $debugHandler, $idnaConvert, $settings, $nginx_server=array())
{ {
$this->db = $db;
$this->logger = $logger; $this->logger = $logger;
$this->debugHandler = $debugHandler; $this->debugHandler = $debugHandler;
$this->idnaConvert = $idnaConvert; $this->idnaConvert = $idnaConvert;
@@ -59,11 +49,6 @@ class nginx
$this->nginx_server = $nginx_server; $this->nginx_server = $nginx_server;
} }
protected function getDB()
{
return $this->db;
}
public function reload() public function reload()
{ {
fwrite($this->debugHandler, ' nginx::reload: reloading nginx' . "\n"); fwrite($this->debugHandler, ' nginx::reload: reloading nginx' . "\n");
@@ -134,10 +119,11 @@ class nginx
public function createIpPort() public function createIpPort()
{ {
$query = "SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` ORDER BY `ip` ASC, `port` ASC"; $result_ipsandports_stmt = Database::query("
$result_ipsandports = $this->db->query($query); SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` ORDER BY `ip` ASC, `port` ASC
");
while ($row_ipsandports = $this->db->fetch_array($result_ipsandports)) { while ($row_ipsandports = $result_ipsandports_stmt->fetch(PDO::FETCH_ASSOC)) {
if (filter_var($row_ipsandports['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { if (filter_var($row_ipsandports['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$ip = '[' . $row_ipsandports['ip'] . ']'; $ip = '[' . $row_ipsandports['ip'] . ']';
} else { } else {
@@ -287,8 +273,8 @@ class nginx
WHERE `d`.`aliasdomain` IS NULL AND `d`.`email_only` <> '1' WHERE `d`.`aliasdomain` IS NULL AND `d`.`email_only` <> '1'
ORDER BY `d`.`parentdomainid` DESC, `d`.`iswildcarddomain`, `d`.`domain` ASC;"; ORDER BY `d`.`parentdomainid` DESC, `d`.`iswildcarddomain`, `d`.`domain` ASC;";
$result_domains = $this->db->query($query); $result_domains_stmt = Database::query($query);
while ($domain = $this->db->fetch_array($result_domains)) { while ($domain = $result_domains_stmt->fetch(PDO::FETCH_ASSOC)) {
if (is_dir($this->settings['system']['apacheconf_vhost'])) { if (is_dir($this->settings['system']['apacheconf_vhost'])) {
safe_exec('mkdir -p '.escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost']))); safe_exec('mkdir -p '.escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost'])));
@@ -356,7 +342,9 @@ class nginx
$vhost_content = ''; $vhost_content = '';
$_vhost_content = ''; $_vhost_content = '';
$query = "SELECT * FROM `".TABLE_PANEL_IPSANDPORTS."` `i`, `".TABLE_DOMAINTOIP."` `dip` WHERE dip.id_domain = '".$domain['id']."' AND i.id = dip.id_ipandports "; $query = "SELECT * FROM `".TABLE_PANEL_IPSANDPORTS."` `i`, `".TABLE_DOMAINTOIP."` `dip`
WHERE dip.id_domain = :domainid AND i.id = dip.id_ipandports ";
if ($ssl_vhost === true if ($ssl_vhost === true
&& ($domain['ssl'] == '1' || $domain['ssl_redirect'] == '1') && ($domain['ssl'] == '1' || $domain['ssl_redirect'] == '1')
) { ) {
@@ -370,8 +358,10 @@ class nginx
// start vhost // start vhost
$vhost_content.= 'server { ' . "\n"; $vhost_content.= 'server { ' . "\n";
$result = $this->db->query($query); $result_stmt = Database::prepare($query);
while ($ipandport = $this->db->fetch_array($result)) { Database::pexecute($result_stmt, array('domainid' => $domain['id']));
while ($ipandport = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
$domain['ip'] = $ipandport['ip']; $domain['ip'] = $ipandport['ip'];
$domain['port'] = $ipandport['port']; $domain['port'] = $ipandport['port'];
@@ -415,13 +405,14 @@ class nginx
// This returns the first port that is != 443 with ssl enabled, if any // This returns the first port that is != 443 with ssl enabled, if any
// ordered by ssl-certificate (if any) so that the ip/port combo // ordered by ssl-certificate (if any) so that the ip/port combo
// with certificate is used // with certificate is used
$ssldestport = $this->db->query_first( $ssldestport_stmt = Database::prepare(
"SELECT `ip`.`port` FROM ".TABLE_PANEL_IPSANDPORTS." `ip` "SELECT `ip`.`port` FROM ".TABLE_PANEL_IPSANDPORTS." `ip`
LEFT JOIN `".TABLE_DOMAINTOIP."` `dip` ON (`ip`.`id` = `dip`.`id_ipandports`) LEFT JOIN `".TABLE_DOMAINTOIP."` `dip` ON (`ip`.`id` = `dip`.`id_ipandports`)
WHERE `dip`.`id_domain` = '".(int)$domain['id']."' WHERE `dip`.`id_domain` = :domainid
AND `ip`.`ssl` = '1' AND `ip`.`port` != 443 AND `ip`.`ssl` = '1' AND `ip`.`port` != 443
ORDER BY `ip`.`ssl_cert_file` DESC, `ip`.`port` LIMIT 1;" ORDER BY `ip`.`ssl_cert_file` DESC, `ip`.`port` LIMIT 1;"
); );
$ssldestport = Database::pexecute_first($ssldestport_stmt, array('domainid' => $domain['id']));
if ($ssldestport['port'] != '') { if ($ssldestport['port'] != '') {
$_sslport = ":".$ssldestport['port']; $_sslport = ":".$ssldestport['port'];
@@ -575,14 +566,17 @@ class nginx
{ {
$has_location = false; $has_location = false;
$query = "SELECT * FROM " . TABLE_PANEL_HTACCESS . " WHERE `path` LIKE '" . $domain['documentroot'] . "%'"; $result_stmt = Database::prepare("
$result = $this->db->query($query); SELECT * FROM " . TABLE_PANEL_HTACCESS . "
WHERE `path` LIKE :docroot
");
Database::pexecute($result_stmt, array('docroot' => $domain['documentroot'] . '%'));
$path_options = ''; $path_options = '';
$htpasswds = $this->getHtpasswds($domain); $htpasswds = $this->getHtpasswds($domain);
// for each entry in the htaccess table // for each entry in the htaccess table
while ($row = $this->db->fetch_array($result)) { while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
if (!empty($row['error404path'])) { if (!empty($row['error404path'])) {
$defhandler = $row['error404path']; $defhandler = $row['error404path'];
if (!validateUrl($defhandler)) { if (!validateUrl($defhandler)) {
@@ -680,9 +674,7 @@ class nginx
} }
/* // now the rest of the htpasswds
* now the rest of the htpasswds
*/
if (count($htpasswds) > 0) { if (count($htpasswds) > 0) {
foreach ($htpasswds as $idx => $single) { foreach ($htpasswds as $idx => $single) {
//if ($single['path'] != '/') { //if ($single['path'] != '/') {
@@ -708,17 +700,17 @@ class nginx
protected function getHtpasswds($domain) { protected function getHtpasswds($domain) {
$query = 'SELECT DISTINCT * $result_stmt = Database::prepare("
FROM ' . TABLE_PANEL_HTPASSWDS . ' AS a SELECT DISTINCT *
JOIN ' . TABLE_PANEL_DOMAINS . ' AS b FROM `" . TABLE_PANEL_HTPASSWDS . "` AS a
USING (`customerid`) JOIN `" . TABLE_PANEL_DOMAINS . "` AS b USING (`customerid`)
WHERE b.customerid=' . $domain['customerid'] . ' AND b.domain="' . $domain['domain'] . '";'; WHERE b.customerid = :customerid AND b.domain = :domain
");
$result = $this->db->query($query); Database::pexecute($result_stmt, array('customerid' => $domain['customerid'], 'domain' => $domain['domain']));
$returnval = array(); $returnval = array();
$x = 0; $x = 0;
while ($row_htpasswds = $this->db->fetch_array($result)) { while ($row_htpasswds = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
if (count($row_htpasswds) > 0) { if (count($row_htpasswds) > 0) {
$htpasswd_filename = makeCorrectFile($this->settings['system']['apacheconf_htpasswddir'] . '/' . $row_htpasswds['customerid'] . '-' . md5($row_htpasswds['path']) . '.htpasswd'); $htpasswd_filename = makeCorrectFile($this->settings['system']['apacheconf_htpasswddir'] . '/' . $row_htpasswds['customerid'] . '-' . md5($row_htpasswds['path']) . '.htpasswd');
@@ -874,11 +866,14 @@ class nginx
if ((int)$domain['parentdomainid'] == 0) { if ((int)$domain['parentdomainid'] == 0) {
// prepare the aliases and subdomains for stats config files // prepare the aliases and subdomains for stats config files
$server_alias = ''; $server_alias = '';
$alias_domains = $this->db->query('SELECT `domain`, `iswildcarddomain`, `wwwserveralias` FROM `' . TABLE_PANEL_DOMAINS . '` $alias_domains_stmt = Database::prepare("
WHERE `aliasdomain`=\'' . $domain['id'] . '\' SELECT `domain`, `iswildcarddomain`, `wwwserveralias`
OR `parentdomainid` =\''. $domain['id']. '\''); FROM `" . TABLE_PANEL_DOMAINS . "`
WHERE `aliasdomain` = :domainid OR `parentdomainid` = :domainid
");
Database::pexecute($alias_domains_stmt, array('domainid' => $domain['id']));
while (($alias_domain = $this->db->fetch_array($alias_domains)) !== false) { while (($alias_domain = $alias_domains_stmt->fetch(PDO::FETCH_ASSOC)) !== false) {
$server_alias .= ' ' . $alias_domain['domain'] . ' '; $server_alias .= ' ' . $alias_domain['domain'] . ' ';
if ($alias_domain['iswildcarddomain'] == '1') { if ($alias_domain['iswildcarddomain'] == '1') {
@@ -924,9 +919,14 @@ class nginx
$server_alias = 'www.' . $domain['domain']; $server_alias = 'www.' . $domain['domain'];
} }
$alias_domains = $this->db->query('SELECT `domain`, `iswildcarddomain`, `wwwserveralias` FROM `' . TABLE_PANEL_DOMAINS . '` WHERE `aliasdomain`=\'' . $domain['id'] . '\''); $alias_domains_stmt = Database::prepare("
SELECT `domain`, `iswildcarddomain`, `wwwserveralias`
FROM `" . TABLE_PANEL_DOMAINS . "`
WHERE `aliasdomain` = :domainid
");
Database::pexecute($alias_domains_stmt, array('domainid' => $domain['id']));
while (($alias_domain = $this->db->fetch_array($alias_domains)) !== false) { while (($alias_domain = $alias_domains_stmt->fetch(PDO::FETCH_ASSOC)) !== false) {
$server_alias .= ' ' . $alias_domain['domain']; $server_alias .= ' ' . $alias_domain['domain'];
if ($alias_domain['iswildcarddomain'] == '1') { if ($alias_domain['iswildcarddomain'] == '1') {
@@ -994,9 +994,7 @@ class nginx
} }
} }
/* // htaccess stuff
* htaccess stuff
*/
if (count($this->htpasswds_data) > 0) { if (count($this->htpasswds_data) > 0) {
if (!file_exists($this->settings['system']['apacheconf_htpasswddir'])) { if (!file_exists($this->settings['system']['apacheconf_htpasswddir'])) {
$umask = umask(); $umask = umask();

View File

@@ -15,13 +15,6 @@
* *
*/ */
if(@php_sapi_name() != 'cli'
&& @php_sapi_name() != 'cgi'
&& @php_sapi_name() != 'cgi-fcgi')
{
die('This script only works in the shell.');
}
class nginx_phpfpm extends nginx class nginx_phpfpm extends nginx
{ {
protected function composePhpOptions($domain, $ssl_vhost = false) protected function composePhpOptions($domain, $ssl_vhost = false)

View File

@@ -73,7 +73,7 @@ while ($row = $result_tasks_stmt->fetch(PDO::FETCH_ASSOC)) {
} }
} }
$webserver = new $websrv($db, $cronlog, $debugHandler, $idna_convert, $settings); $webserver = new $websrv($cronlog, $debugHandler, $idna_convert, $settings);
} }
if (isset($webserver)) { if (isset($webserver)) {
@@ -153,7 +153,7 @@ while ($row = $result_tasks_stmt->fetch(PDO::FETCH_ASSOC)) {
*/ */
elseif ($row['type'] == '4' && (int)$settings['system']['bind_enable'] != 0) { elseif ($row['type'] == '4' && (int)$settings['system']['bind_enable'] != 0) {
if (!isset($nameserver)) { if (!isset($nameserver)) {
$nameserver = new bind($db, $cronlog, $debugHandler, $settings); $nameserver = new bind($cronlog, $debugHandler, $settings);
} }
if ($settings['dkim']['use_dkim'] == '1') { if ($settings['dkim']['use_dkim'] == '1') {

View File

@@ -64,9 +64,9 @@ while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
} }
// include english language file (fallback) // include english language file (fallback)
include_once makeCorrectFile($pathtophpfiles . '/lng/english.lng.php'); include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/lng/english.lng.php');
// include admin/customer language file // include admin/customer language file
include_once makeCorrectFile($pathtophpfiles . '/' . $langfile); include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/' . $langfile);
// Get mail templates from database; the ones from 'admin' are fetched for fallback // Get mail templates from database; the ones from 'admin' are fetched for fallback
$result2_stmt = Database::prepare(" $result2_stmt = Database::prepare("
@@ -154,9 +154,9 @@ while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
} }
// include english language file (fallback) // include english language file (fallback)
include_once makeCorrectFile($pathtophpfiles . '/lng/english.lng.php'); include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/lng/english.lng.php');
// include admin/customer language file // include admin/customer language file
include_once makeCorrectFile($pathtophpfiles . '/' . $langfile); include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/' . $langfile);
// Get mail templates from database; the ones from 'admin' are fetched for fallback // Get mail templates from database; the ones from 'admin' are fetched for fallback
$result2_stmt = Database::prepare(" $result2_stmt = Database::prepare("

View File

@@ -84,9 +84,9 @@ while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
} }
// include english language file (fallback) // include english language file (fallback)
include_once makeCorrectFile($pathtophpfiles . '/lng/english.lng.php'); include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/lng/english.lng.php');
// include admin/customer language file // include admin/customer language file
include_once makeCorrectFile($pathtophpfiles . '/' . $langfile); include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/' . $langfile);
// Get mail templates from database; the ones from 'admin' are fetched for fallback // Get mail templates from database; the ones from 'admin' are fetched for fallback
$result2_stmt = Database::prepare(" $result2_stmt = Database::prepare("
@@ -182,9 +182,9 @@ while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
} }
// include english language file (fallback) // include english language file (fallback)
include_once makeCorrectFile($pathtophpfiles . '/lng/english.lng.php'); include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/lng/english.lng.php');
// include admin/customer language file // include admin/customer language file
include_once makeCorrectFile($pathtophpfiles . '/' . $langfile); include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/' . $langfile);
// Get mail templates from database; the ones from 'admin' are fetched for fallback // Get mail templates from database; the ones from 'admin' are fetched for fallback
$result2_stmt = Database::prepare(" $result2_stmt = Database::prepare("