combined all cronscripts into one master-cronfile (user only needs to add one file to the crontab);
This commit is contained in:
25
scripts/jobs/always/cron_apsinstaller.php
Normal file
25
scripts/jobs/always/cron_apsinstaller.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
openRootDB($debugHandler, $lockfile);
|
||||
$Aps = new ApsInstaller($settings, $db, $db_root);
|
||||
$Aps->InstallHandler();
|
||||
closeRootDB();
|
||||
|
||||
?>
|
||||
230
scripts/jobs/always/cron_autoresponder.php
Normal file
230
scripts/jobs/always/cron_autoresponder.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Remo Fritzsche
|
||||
* @author Manuel Aller
|
||||
* @author Michael Schlechtinger
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id$
|
||||
* @todo skip mail parsing after x bytes for large mails
|
||||
*/
|
||||
|
||||
$mail = new PHPMailer();
|
||||
|
||||
//dont do anything when module is disabled
|
||||
|
||||
if((int)$settings['autoresponder']['autoresponder_active'] == 0)
|
||||
{
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
return;
|
||||
}
|
||||
|
||||
//only send autoresponder to mails which were delivered since last run
|
||||
|
||||
if((int)$settings['autoresponder']['last_autoresponder_run'] == 0)
|
||||
{
|
||||
//mails from last 5 minutes, otherwise all mails will be parsed -> mailbomb prevention
|
||||
|
||||
$cycle = 300;
|
||||
}
|
||||
else
|
||||
{
|
||||
$cycle = time() - (int)$settings['autoresponder']['last_autoresponder_run'];
|
||||
|
||||
//prevent mailbombs when cycle is bigger than two days
|
||||
|
||||
if($cycle > (2 * 60 * 60 * 24))$cycle = (60 * 60 * 24);
|
||||
}
|
||||
|
||||
$db->query("UPDATE `" . TABLE_PANEL_SETTINGS . "` SET `value` = '" . (int)time() . "' WHERE `settinggroup` = 'autoresponder' AND `varname` = 'last_autoresponder_run'");
|
||||
|
||||
/*
|
||||
//can be used for later usage if autoresponders should be only active in a defined period
|
||||
|
||||
//This query has to disable every autoresponder entry which ended in the past
|
||||
$db->query("UPDATE `autoresponder` SET `enabled` = 0 WHERE `to` < CURDATE()");
|
||||
|
||||
//This query has to activate every autoresponder entry which starts today
|
||||
$db->query("UPDATE `autoresponder` SET `enabled` = 1 WHERE `from` = CURDATE()");
|
||||
*/
|
||||
//getting all mailboxes where autoresponders are active and configured
|
||||
|
||||
$result = $db->query("SELECT * FROM `" . TABLE_MAIL_AUTORESPONDER . "` INNER JOIN `" . TABLE_MAIL_USERS . "` ON `" . TABLE_MAIL_AUTORESPONDER . "`.`email` = `" . TABLE_MAIL_USERS . "`.`email` WHERE `enabled` = 1");
|
||||
|
||||
if($db->num_rows($result) > 0)
|
||||
{
|
||||
while($row = $db->fetch_array($result))
|
||||
{
|
||||
/*
|
||||
* check if specific autoresponder should be used
|
||||
*/
|
||||
$ts_now = time();
|
||||
$ts_start = (int)$row['date_from'];
|
||||
$ts_end = (int)$row['date_until'];
|
||||
|
||||
// not yet
|
||||
if($ts_start != -1 && $ts_start > $ts_now) continue;
|
||||
// already ended
|
||||
if($ts_end != -1 && $ts_end < $ts_now) continue;
|
||||
|
||||
$path = $row['homedir'] . $row['maildir'] . "new/";
|
||||
$files = scandir($path);
|
||||
foreach($files as $entry)
|
||||
{
|
||||
if($entry == '.'
|
||||
|| $entry == '..')continue;
|
||||
|
||||
if(time() - filemtime($path . $entry) - $cycle <= 0)
|
||||
{
|
||||
$content = file($path . $entry);
|
||||
|
||||
//error reading mail contents
|
||||
|
||||
if(count($content) == 0)
|
||||
{
|
||||
$cronlog->logAction(LOG_ERROR, LOG_WARNING, "Unable to read mail from maildir: " . $entry);
|
||||
continue;
|
||||
}
|
||||
|
||||
$match = array();
|
||||
$from = '';
|
||||
$to = '';
|
||||
$sender = '';
|
||||
$spam = false;
|
||||
foreach($content as $line)
|
||||
{
|
||||
// header ends on first empty line, skip rest of mail
|
||||
|
||||
if(strlen(rtrim($line)) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//fetching from field
|
||||
|
||||
if(!strlen($from)
|
||||
&& preg_match("/^From:(.+)<(.*)>$/", $line, $match))
|
||||
{
|
||||
$from = $match[2];
|
||||
}
|
||||
elseif(!strlen($from)
|
||||
&& preg_match("/^From:\s+(.*@.*)$/", $line, $match))
|
||||
{
|
||||
$from = $match[1];
|
||||
}
|
||||
|
||||
//fetching to field
|
||||
|
||||
if(!strlen($to)
|
||||
&& preg_match("/^To:(.+)<(.*)>$/", $line, $match))
|
||||
{
|
||||
$to = $match[2];
|
||||
}
|
||||
elseif(!strlen($to)
|
||||
&& preg_match("/To:\s+(.*@.*)$/", $line, $match))
|
||||
{
|
||||
$to = $match[1];
|
||||
}
|
||||
|
||||
//fetching sender field
|
||||
|
||||
if(!strlen($to)
|
||||
&& preg_match("/^Sender:(.+)<(.*)>$/", $line, $match))
|
||||
{
|
||||
$sender = $match[2];
|
||||
}
|
||||
elseif(!strlen($to)
|
||||
&& preg_match("/Sender:\s+(.*@.*)$/", $line, $match))
|
||||
{
|
||||
$sender = $match[1];
|
||||
}
|
||||
|
||||
//check for amavis/spamassassin spam headers
|
||||
|
||||
if(preg_match("/^X-Spam-Status: (Yes|No)(.*)$/", $line, $match))
|
||||
{
|
||||
if($match[1] == 'Yes')$spam = true;
|
||||
}
|
||||
|
||||
//check for precedence header
|
||||
if(preg_match("/^Precedence: (bulk|list|junk)(.*)$/", $line, $match))
|
||||
{
|
||||
// use the spam flag to skip reply
|
||||
$spam = true;
|
||||
}
|
||||
}
|
||||
|
||||
//skip mail when marked as spam
|
||||
|
||||
if($spam == true)continue;
|
||||
|
||||
//error while parsing mail
|
||||
|
||||
if($to == ''
|
||||
|| $from == '')
|
||||
{
|
||||
$cronlog->logAction(LOG_ERROR, LOG_WARNING, "No valid headers found in mail to parse: " . $entry);
|
||||
continue;
|
||||
}
|
||||
|
||||
//important! prevent mailbombs when mail comes from a maildaemon/mailrobot
|
||||
//robot/daemon mails must go to Sender: field in envelope header
|
||||
//refers to "Das Postfix-Buch" / RFC 2822
|
||||
|
||||
if($sender != '')$from = $sender;
|
||||
|
||||
//make message valid to email format
|
||||
|
||||
$message = str_replace("\r\n", "\n", $row['message']);
|
||||
|
||||
//check if mail is already an answer
|
||||
|
||||
$fullcontent = implode("", $content);
|
||||
|
||||
if(strstr($fullcontent, $message))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//send mail with mailer class
|
||||
|
||||
$mail->From = $to;
|
||||
$mail->FromName = $to;
|
||||
$mail->Subject = $row['subject'];
|
||||
$mail->Body = html_entity_decode($message);
|
||||
$mail->AddAddress($from, $from);
|
||||
$mail->AddCustomHeader('Precedence: bulk');
|
||||
|
||||
if(!$mail->Send())
|
||||
{
|
||||
if($mail->ErrorInfo != '')
|
||||
{
|
||||
$mailerr_msg = $mail->ErrorInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mailerr_msg = $from;
|
||||
}
|
||||
|
||||
$cronlog->logAction(LOG_ERROR, LOG_WARNING, "Error sending autoresponder mail: " . $mailerr_msg);
|
||||
}
|
||||
|
||||
$mail->ClearAddresses();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
59
scripts/jobs/always/cron_legacy.php
Normal file
59
scripts/jobs/always/cron_legacy.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
openRootDB($debugHandler, $lockfile);
|
||||
|
||||
/**
|
||||
* Check if table exists, otherwise create it
|
||||
*/
|
||||
|
||||
$tables = getTables($db);
|
||||
|
||||
if(!isset($tables[TABLE_PANEL_CRONSCRIPT])
|
||||
|| !is_array($tables[TABLE_PANEL_CRONSCRIPT]))
|
||||
{
|
||||
$db->query('CREATE TABLE `' . TABLE_PANEL_CRONSCRIPT . '` ( `id` int(11) unsigned NOT NULL auto_increment, `file` varchar(255) NOT NULL default \'\', PRIMARY KEY (`id`) ) TYPE=MyISAM ; ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Backend Wrapper
|
||||
*/
|
||||
|
||||
$query = 'SELECT * FROM `' . TABLE_PANEL_CRONSCRIPT . '` ';
|
||||
$cronFileIncludeResult = $db->query($query);
|
||||
|
||||
while($cronFileIncludeRow = $db->fetch_array($cronFileIncludeResult))
|
||||
{
|
||||
$cronFileIncludeFullPath = makeSecurePath($pathtophpfiles . '/scripts/' . $cronFileIncludeRow['file']);
|
||||
|
||||
if(fileowner($cronFileIncludeFullPath) == fileowner($pathtophpfiles . '/scripts/' . $filename)
|
||||
&& filegroup($cronFileIncludeFullPath) == filegroup($pathtophpfiles . '/scripts/' . $filename))
|
||||
{
|
||||
fwrite($debugHandler, 'Processing ...' . $cronFileIncludeFullPath . "\n");
|
||||
include_once $cronFileIncludeFullPath;
|
||||
fwrite($debugHandler, 'Processing done!' . "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($debugHandler, 'WARNING! uid and/or gid of "' . $cronFileIncludeFullPath . '" and "' . $pathtophpfiles . '/scripts/' . $filename . '" don\'t match! Execution aborted!' . "\n");
|
||||
$keepLockFile = true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
161
scripts/jobs/always/cron_lighttp.htaccess.php
Normal file
161
scripts/jobs/always/cron_lighttp.htaccess.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* LOOK INTO EVERY CUSTOMER DIR TO SEE IF THERE ARE ANY .HTACCESS FILE TO "TRANSLATE"
|
||||
*/
|
||||
|
||||
if($settings['system']['webserver'] == 'lighttpd')
|
||||
{
|
||||
fwrite($debugHandler, ' cron_lighttp.htaccess: Searching for .htaccess files to translate' . "\n");
|
||||
$lpath = makeCorrectDir(strrchr($settings['system']['apacheconf_vhost'], '/'));
|
||||
$htaccessfh = @fopen($lpath . 'syscp-htaccess.conf', 'w');
|
||||
|
||||
if($htaccessfh !== false)
|
||||
{
|
||||
read_directory($settings['system']['documentroot_prefix'], 25, $htaccessfh);
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($debugHandler, ' ERROR: Cannot open file ' . $lpath . 'syscp-htaccess.conf' . "\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($debugHandler, ' cron_lighttp.htaccess: You don\'t use Lighttpd, you do not have to run this cronscript!' . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* FUNCTIONS
|
||||
*/
|
||||
|
||||
function read_directory($dir1 = null, $min_depth = 25, $htaccessfh = null)
|
||||
{
|
||||
global $htaccessfh;
|
||||
|
||||
if(!is_string($dir1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$depth = explode("/", $dir1);
|
||||
$current_depth = sizeof($depth);
|
||||
|
||||
if($current_depth < $min_depth)
|
||||
{
|
||||
$min_depth = $current_depth;
|
||||
}
|
||||
|
||||
$dir = $dir1;
|
||||
$dh = opendir($dir);
|
||||
|
||||
while($file = readdir($dh))
|
||||
{
|
||||
if(($file != ".")
|
||||
&& ($file != ".."))
|
||||
{
|
||||
$file = $dir . "/" . $file;
|
||||
for ($i = 0;$i <= ($current_depth - $min_depth);$i++)
|
||||
|
||||
// $file is sub-directory
|
||||
|
||||
if($ddh = @opendir($file))
|
||||
{
|
||||
read_directory($file);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(strtolower($file) == '.htaccess')
|
||||
{
|
||||
parseHtaccess($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir($dh);
|
||||
return true;
|
||||
}
|
||||
|
||||
function parseHtaccess($file = null)
|
||||
{
|
||||
global $debugHandler, $htaccessfh;
|
||||
$htacc = @file_get_contents($file);
|
||||
|
||||
if($htacc != "")
|
||||
{
|
||||
$htlines = array();
|
||||
$htlines = explode("\n", $htacc);
|
||||
$userhasrewrites = false;
|
||||
$userrewrites = array();
|
||||
$rule = array();
|
||||
foreach($htlines as $htl)
|
||||
{
|
||||
if(preg_match('/^RewriteEngine\ on$/si', $htl) !== null)
|
||||
{
|
||||
$userhasrewrites = true;
|
||||
}
|
||||
elseif(preg_match('/^RewriteRule\ +\^(.*)\$\(.*)$/si', $htl, $rule) !== null)
|
||||
{
|
||||
$regex = isset($rule[0]) ? $rule[0] : '';
|
||||
$relativeuri = isset($rule[1]) ? $rule[1] : '';
|
||||
|
||||
if($regex != ''
|
||||
&& $relativeuri != '')
|
||||
{
|
||||
$userrewrites[]['regex'] = $regex;
|
||||
$userrewrites[]['relativeuri'] = $relativeuri;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($userhasrewrites)
|
||||
{
|
||||
fwrite($htaccessfh, '$PHYSICAL["path"] == "' . dirname($file) . '" {' . "\n");
|
||||
fwrite($htaccessfh, ' url.rewrite-once = (' . "\n");
|
||||
$count = 1;
|
||||
$max = count($userrewrites);
|
||||
foreach($userrewrites as $usrrw)
|
||||
{
|
||||
fwrite($htaccessfh, ' "^' . $usrrw['regex'] . '$" => "' . $usrrw['relativeuri'] . '"');
|
||||
|
||||
if($count < $max)
|
||||
{
|
||||
fwrite($htaccessfh, ',' . "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($htaccessfh, "\n");
|
||||
}
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
fwrite($htaccessfh, ' )' . "\n");
|
||||
fwrite($htaccessfh, '}' . "\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($debugHandler, ' WARNING: file ' . $file . ' seems to be empty or there was an error' . "\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
345
scripts/jobs/always/cron_tasks.inc.dns.10.bind.php
Normal file
345
scripts/jobs/always/cron_tasks.inc.dns.10.bind.php
Normal file
@@ -0,0 +1,345 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* This script creates the php.ini's used by mod_suPHP+php-cgi
|
||||
*/
|
||||
|
||||
if(@php_sapi_name() != 'cli'
|
||||
&& @php_sapi_name() != 'cgi'
|
||||
&& @php_sapi_name() != 'cgi-fcgi')
|
||||
{
|
||||
die('This script only works in the shell.');
|
||||
}
|
||||
|
||||
class bind
|
||||
{
|
||||
public $db = false;
|
||||
public $logger = false;
|
||||
public $debugHandler = false;
|
||||
public $settings = array();
|
||||
public $nameservers = array();
|
||||
public $mxservers = array();
|
||||
|
||||
public function __construct($db, $logger, $debugHandler, $settings)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->logger = $logger;
|
||||
$this->debugHandler = $debugHandler;
|
||||
$this->settings = $settings;
|
||||
|
||||
if($this->settings['system']['nameservers'] != '')
|
||||
{
|
||||
$nameservers = explode(',', $this->settings['system']['nameservers']);
|
||||
foreach($nameservers as $nameserver)
|
||||
{
|
||||
$nameserver_ip = gethostbyname(trim($nameserver));
|
||||
|
||||
if(substr($nameserver, -1, 1) != '.')
|
||||
{
|
||||
$nameserver.= '.';
|
||||
}
|
||||
|
||||
$this->nameservers[] = array(
|
||||
'hostname' => trim($nameserver),
|
||||
'ip' => trim($nameserver_ip)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if($this->settings['system']['mxservers'] != '')
|
||||
{
|
||||
$mxservers = explode(',', $this->settings['system']['mxservers']);
|
||||
foreach($mxservers as $mxserver)
|
||||
{
|
||||
if(substr($mxserver, -1, 1) != '.')
|
||||
{
|
||||
$mxserver.= '.';
|
||||
}
|
||||
|
||||
$this->mxservers[] = $mxserver;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function writeConfigs()
|
||||
{
|
||||
fwrite($this->debugHandler, ' cron_tasks: Task4 started - Rebuilding froxlor_bind.conf' . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'Task4 started - Rebuilding froxlor_bind.conf');
|
||||
|
||||
if(!file_exists(makeCorrectDir($this->settings['system']['bindconf_directory'] . '/domains/')))
|
||||
{
|
||||
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['bindconf_directory'] . '/domains/')));
|
||||
safe_exec('mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['bindconf_directory'] . '/domains/')));
|
||||
}
|
||||
|
||||
$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";
|
||||
$result_domains = $this->db->query("SELECT `d`.`id`, `d`.`domain`, `d`.`iswildcarddomain`, `d`.`customerid`, `d`.`zonefile`, `d`.`bindserial`, `d`.`dkim`, `d`.`dkim_id`, `d`.`dkim_pubkey`, `ip`.`ip`, `c`.`loginname`, `c`.`guid` FROM `" . TABLE_PANEL_DOMAINS . "` `d` LEFT JOIN `" . TABLE_PANEL_CUSTOMERS . "` `c` USING(`customerid`) LEFT JOIN `" . TABLE_PANEL_IPSANDPORTS . "` AS `ip` ON(`d`.`ipandport`=`ip`.`id`) WHERE `d`.`isbinddomain` = '1' ORDER BY `d`.`domain` ASC");
|
||||
|
||||
while($domain = $this->db->fetch_array($result_domains))
|
||||
{
|
||||
fwrite($this->debugHandler, ' cron_tasks: Task4 - Writing ' . $domain['id'] . '::' . $domain['domain'] . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'Writing ' . $domain['id'] . '::' . $domain['domain']);
|
||||
|
||||
if($domain['zonefile'] == '')
|
||||
{
|
||||
$zonefile = $this->generateZone($domain);
|
||||
$domain['zonefile'] = 'domains/' . $domain['domain'] . '.zone';
|
||||
$zonefile_name = makeCorrectFile($this->settings['system']['bindconf_directory'] . '/' . $domain['zonefile']);
|
||||
$known_filenames[] = basename($zonefile_name);
|
||||
$zonefile_handler = fopen($zonefile_name, 'w');
|
||||
fwrite($zonefile_handler, $zonefile);
|
||||
fclose($zonefile_handler);
|
||||
fwrite($this->debugHandler, ' cron_tasks: Task4 - `' . $zonefile_name . '` zone written' . "\n");
|
||||
}
|
||||
|
||||
$bindconf_file.= '# Domain ID: ' . $domain['id'] . ' - CustomerID: ' . $domain['customerid'] . ' - CustomerLogin: ' . $domain['loginname'] . "\n";
|
||||
$bindconf_file.= 'zone "' . $domain['domain'] . '" in {' . "\n";
|
||||
$bindconf_file.= ' type master;' . "\n";
|
||||
$bindconf_file.= ' file "' . makeCorrectFile($this->settings['system']['bindconf_directory'] . '/' . $domain['zonefile']) . '";' . "\n";
|
||||
$bindconf_file.= ' allow-query { any; };' . "\n";
|
||||
|
||||
if(count($this->nameservers) > 0)
|
||||
{
|
||||
$bindconf_file.= ' allow-transfer {' . "\n";
|
||||
for ($i = 0;$i < count($this->nameservers);$i++)
|
||||
{
|
||||
$bindconf_file.= ' ' . $this->nameservers[$i]['ip'] . ';' . "\n";
|
||||
}
|
||||
|
||||
$bindconf_file.= ' };' . "\n";
|
||||
}
|
||||
|
||||
$bindconf_file.= '};' . "\n";
|
||||
$bindconf_file.= "\n";
|
||||
}
|
||||
|
||||
$bindconf_file_handler = fopen(makeCorrectFile($this->settings['system']['bindconf_directory'] . '/froxlor_bind.conf'), 'w');
|
||||
fwrite($bindconf_file_handler, $bindconf_file);
|
||||
fclose($bindconf_file_handler);
|
||||
fwrite($this->debugHandler, ' cron_tasks: Task4 - froxlor_bind.conf written' . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'froxlor_bind.conf written');
|
||||
safe_exec($this->settings['system']['bindreload_command']);
|
||||
fwrite($this->debugHandler, ' cron_tasks: Task4 - Bind9 reloaded' . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'Bind9 reloaded');
|
||||
$domains_dir = makeCorrectDir($this->settings['system']['bindconf_directory'] . '/domains/');
|
||||
|
||||
if(file_exists($domains_dir)
|
||||
&& is_dir($domains_dir))
|
||||
{
|
||||
$domain_file_dirhandle = opendir($domains_dir);
|
||||
|
||||
while(false !== ($domain_filename = readdir($domain_file_dirhandle)))
|
||||
{
|
||||
if($domain_filename != '.'
|
||||
&& $domain_filename != '..'
|
||||
&& !in_array($domain_filename, $known_filenames)
|
||||
&& file_exists(makeCorrectFile($domains_dir . '/' . $domain_filename)))
|
||||
{
|
||||
fwrite($this->debugHandler, ' cron_tasks: Task4 - unlinking ' . $domain_filename . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_WARNING, 'Deleting ' . $domain_filename);
|
||||
unlink(makeCorrectFile($domains_dir . '/' . $domain_filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function generateZone($domain)
|
||||
{
|
||||
if(filter_var($domain['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))
|
||||
{
|
||||
$ip_a_record = 'A ' . $domain['ip'];
|
||||
}
|
||||
elseif(filter_var($domain['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
|
||||
{
|
||||
$ip_a_record = 'AAAA ' . $domain['ip'];
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$date = date('Ymd');
|
||||
$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 1W' . "\n";
|
||||
|
||||
if(count($this->nameservers) == 0)
|
||||
{
|
||||
$zonefile.= '@ IN SOA ns ' . str_replace('@', '.', $this->settings['panel']['adminmail']) . '. (' . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$zonefile.= '@ IN SOA ' . $this->nameservers[0]['hostname'] . ' ' . str_replace('@', '.', $this->settings['panel']['adminmail']) . '. (' . "\n";
|
||||
}
|
||||
|
||||
$zonefile.= ' ' . $bindserial . ' ; serial' . "\n" . ' 8H ; refresh' . "\n" . ' 2H ; retry' . "\n" . ' 1W ; expiry' . "\n" . ' 11h) ; minimum' . "\n";
|
||||
|
||||
if(count($this->nameservers) == 0)
|
||||
{
|
||||
$zonefile.= '@ IN NS ns' . "\n" . 'ns IN ' . $ip_a_record . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($this->nameservers as $nameserver)
|
||||
{
|
||||
$zonefile.= '@ IN NS ' . trim($nameserver['hostname']) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
if(count($this->mxservers) == 0)
|
||||
{
|
||||
$zonefile.= '@ IN MX 10 mail' . "\n" . 'mail IN ' . $ip_a_record . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($this->mxservers as $mxserver)
|
||||
{
|
||||
$zonefile.= '@ IN MX ' . trim($mxserver) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @TODO domain-based spf-settings
|
||||
*/
|
||||
if($this->settings['spf']['use_spf'] == '1'
|
||||
/*&& $domain['spf'] == '1' */)
|
||||
{
|
||||
$zonefile.= $this->settings['spf']['spf_entry'] . "\n";
|
||||
}
|
||||
|
||||
if($this->settings['dkim']['use_dkim'] == '1'
|
||||
&& $domain['dkim'] == '1'
|
||||
&& $domain['dkim_pubkey'] != '')
|
||||
{
|
||||
$zonefile.= 'dkim_' . $domain['dkim_id'] . '._domainkey IN TXT "v=DKIM1; k=rsa; p=' . trim(preg_replace('/-----BEGIN PUBLIC KEY-----(.+)-----END PUBLIC KEY-----/s', '$1', str_replace("\n", '', $domain['dkim_pubkey']))) . '"' . "\n";
|
||||
}
|
||||
|
||||
$nssubdomains = $this->db->query('SELECT `domain` FROM `' . TABLE_PANEL_DOMAINS . '` WHERE `isbinddomain`=\'1\' AND `domain` LIKE \'%.' . $domain['domain'] . '\'');
|
||||
|
||||
while($nssubdomain = $this->db->fetch_array($nssubdomains))
|
||||
{
|
||||
if(preg_match('/^[^\.]+\.' . preg_quote($domain['domain'], '/') . '/', $nssubdomain['domain']))
|
||||
{
|
||||
$nssubdomain = str_replace('.' . $domain['domain'], '', $nssubdomain['domain']);
|
||||
|
||||
if(count($this->nameservers) == 0)
|
||||
{
|
||||
$zonefile.= $nssubdomain . ' IN NS ns.' . $nssubdomain . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($this->nameservers as $nameserver)
|
||||
{
|
||||
$zonefile.= $nssubdomain . ' IN NS ' . trim($nameserver['hostname']) . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$zonefile.= '@ IN ' . $ip_a_record . "\n";
|
||||
$zonefile.= 'www IN ' . $ip_a_record . "\n";
|
||||
|
||||
if($domain['iswildcarddomain'] == '1')
|
||||
{
|
||||
$zonefile.= '* IN ' . $ip_a_record . "\n";
|
||||
}
|
||||
|
||||
$subdomains = $this->db->query('SELECT `d`.`domain`, `ip`.`ip` AS `ip` FROM `' . TABLE_PANEL_DOMAINS . '` `d`, `' . TABLE_PANEL_IPSANDPORTS . '` `ip` WHERE `parentdomainid`=\'' . $domain['id'] . '\' AND `d`.`ipandport`=`ip`.`id`');
|
||||
|
||||
while($subdomain = $this->db->fetch_array($subdomains))
|
||||
{
|
||||
$zonefile.= str_replace('.' . $domain['domain'], '', $subdomain['domain']) . ' IN A ' . $subdomain['ip'] . "\n";
|
||||
}
|
||||
|
||||
return $zonefile;
|
||||
}
|
||||
|
||||
public function writeDKIMconfigs()
|
||||
{
|
||||
if($this->settings['dkim']['use_dkim'] == '1')
|
||||
{
|
||||
if(!file_exists(makeCorrectDir($this->settings['dkim']['dkim_prefix'])))
|
||||
{
|
||||
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir -p ' . escapeshellarg(makeCorrectDir($this->settings['dkim']['dkim_prefix'])));
|
||||
safe_exec('mkdir -p ' . escapeshellarg(makeCorrectDir($this->settings['dkim']['dkim_prefix'])));
|
||||
}
|
||||
|
||||
$dkimdomains = '';
|
||||
$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");
|
||||
|
||||
while($domain = $this->db->fetch_array($result_domains))
|
||||
{
|
||||
$privkey_filename = makeCorrectFile($this->settings['dkim']['dkim_prefix'] . '/dkim_' . $domain['dkim_id'] . '.private');
|
||||
$pubkey_filename = makeCorrectFile($this->settings['dkim']['dkim_prefix'] . '/dkim_' . $domain['dkim_id'] . '.public');
|
||||
|
||||
if($domain['dkim_privkey'] == ''
|
||||
|| $domain['dkim_pubkey'] == '')
|
||||
{
|
||||
$max_dkim_id = $this->db->query_first("SELECT MAX(`dkim_id`) as `max_dkim_id` FROM `" . TABLE_PANEL_DOMAINS . "`");
|
||||
$domain['dkim_id'] = (int)$max_dkim_id['max_dkim_id'] + 1;
|
||||
$privkey_filename = makeCorrectFile($this->settings['dkim']['dkim_prefix'] . '/dkim_' . $domain['dkim_id'] . '.private');
|
||||
safe_exec('openssl genrsa -out ' . escapeshellarg($privkey_filename) . ' 1024');
|
||||
$domain['dkim_privkey'] = file_get_contents($privkey_filename);
|
||||
safe_exec("chmod 0640 " . escapeshellarg($privkey_filename));
|
||||
$pubkey_filename = makeCorrectFile($this->settings['dkim']['dkim_prefix'] . '/dkim_' . $domain['dkim_id'] . '.public');
|
||||
safe_exec('openssl rsa -in ' . escapeshellarg($privkey_filename) . ' -pubout -outform pem -out ' . escapeshellarg($pubkey_filename));
|
||||
$domain['dkim_pubkey'] = file_get_contents($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'] . "'");
|
||||
}
|
||||
|
||||
if(!file_exists($privkey_filename)
|
||||
&& $domain['dkim_privkey'] != '')
|
||||
{
|
||||
$privkey_file_handler = fopen($privkey_filename, "w");
|
||||
fwrite($privkey_file_handler, $domain['dkim_privkey']);
|
||||
fclose($privkey_file_handler);
|
||||
safe_exec("chmod 0640 " . escapeshellarg($privkey_filename));
|
||||
}
|
||||
|
||||
if(!file_exists($pubkey_filename)
|
||||
&& $domain['dkim_pubkey'] != '')
|
||||
{
|
||||
$pubkey_file_handler = fopen($pubkey_filename, "w");
|
||||
fwrite($pubkey_file_handler, $domain['dkim_pubkey']);
|
||||
fclose($pubkey_file_handler);
|
||||
safe_exec("chmod 0664 " . escapeshellarg($pubkey_filename));
|
||||
}
|
||||
|
||||
$dkimdomains.= $domain['domain'] . "\n";
|
||||
$dkimkeys.= "*@" . $domain['domain'] . ":" . $domain['domain'] . ":" . $privkey_filename . "\n";
|
||||
}
|
||||
|
||||
$dkimdomains_filename = makeCorrectFile($this->settings['dkim']['dkim_prefix'] . '/' . $this->settings['dkim']['dkim_domains']);
|
||||
$dkimdomains_file_handler = fopen($dkimdomains_filename, "w");
|
||||
fwrite($dkimdomains_file_handler, $dkimdomains);
|
||||
fclose($dkimdomains_file_handler);
|
||||
$dkimkeys_filename = makeCorrectFile($this->settings['dkim']['dkim_prefix'] . '/' . $this->settings['dkim']['dkim_dkimkeys']);
|
||||
$dkimkeys_file_handler = fopen($dkimkeys_filename, "w");
|
||||
fwrite($dkimkeys_file_handler, $dkimkeys);
|
||||
fclose($dkimkeys_file_handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
967
scripts/jobs/always/cron_tasks.inc.http.10.apache.php
Normal file
967
scripts/jobs/always/cron_tasks.inc.http.10.apache.php
Normal file
@@ -0,0 +1,967 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
if(@php_sapi_name() != 'cli'
|
||||
&& @php_sapi_name() != 'cgi'
|
||||
&& @php_sapi_name() != 'cgi-fcgi')
|
||||
{
|
||||
die('This script only works in the shell.');
|
||||
}
|
||||
|
||||
class apache
|
||||
{
|
||||
private $db = false;
|
||||
private $logger = false;
|
||||
private $debugHandler = false;
|
||||
private $idnaConvert = false;
|
||||
|
||||
// protected
|
||||
|
||||
protected $settings = array();
|
||||
protected $known_vhostfilenames = array();
|
||||
protected $known_diroptionsfilenames = array();
|
||||
protected $known_htpasswdsfilenames = array();
|
||||
protected $virtualhosts_data = array();
|
||||
protected $diroptions_data = array();
|
||||
protected $htpasswds_data = array();
|
||||
|
||||
public function __construct($db, $logger, $debugHandler, $idnaConvert, $settings)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->logger = $logger;
|
||||
$this->debugHandler = $debugHandler;
|
||||
$this->idnaConvert = $idnaConvert;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
protected function getDB()
|
||||
{
|
||||
return $this->db;
|
||||
}
|
||||
|
||||
public function reload()
|
||||
{
|
||||
fwrite($this->debugHandler, ' apache::reload: reloading apache' . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'reloading apache');
|
||||
safe_exec($this->settings['system']['apachereload_command']);
|
||||
}
|
||||
|
||||
public function createIpPort()
|
||||
{
|
||||
$result_ipsandports = $this->db->query("SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` ORDER BY `ip` ASC, `port` ASC");
|
||||
|
||||
while($row_ipsandports = $this->db->fetch_array($result_ipsandports))
|
||||
{
|
||||
if(filter_var($row_ipsandports['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
|
||||
{
|
||||
$ipport = '[' . $row_ipsandports['ip'] . ']:' . $row_ipsandports['port'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$ipport = $row_ipsandports['ip'] . ':' . $row_ipsandports['port'];
|
||||
}
|
||||
|
||||
fwrite($this->debugHandler, ' apache::createIpPort: creating ip/port settings for ' . $ipport . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'creating ip/port settings for ' . $ipport);
|
||||
$vhosts_filename = makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/10_syscp_ipandport_' . trim(str_replace(':', '.', $row_ipsandports['ip']), '.') . '.' . $row_ipsandports['port'] . '.conf');
|
||||
|
||||
if(!isset($this->virtualhosts_data[$vhosts_filename]))
|
||||
{
|
||||
$this->virtualhosts_data[$vhosts_filename] = '';
|
||||
}
|
||||
|
||||
if($row_ipsandports['listen_statement'] == '1')
|
||||
{
|
||||
$this->virtualhosts_data[$vhosts_filename].= 'Listen ' . $ipport . "\n";
|
||||
$this->logger->logAction(CRON_ACTION, LOG_DEBUG, $ipport . ' :: inserted listen-statement');
|
||||
}
|
||||
|
||||
if($row_ipsandports['namevirtualhost_statement'] == '1')
|
||||
{
|
||||
$this->virtualhosts_data[$vhosts_filename].= 'NameVirtualHost ' . $ipport . "\n";
|
||||
$this->logger->logAction(CRON_ACTION, LOG_DEBUG, $ipport . ' :: inserted namevirtualhost-statement');
|
||||
}
|
||||
|
||||
if($row_ipsandports['vhostcontainer'] == '1')
|
||||
{
|
||||
$this->virtualhosts_data[$vhosts_filename].= '<VirtualHost ' . $ipport . '>' . "\n";
|
||||
|
||||
if($row_ipsandports['vhostcontainer_servername_statement'] == '1')
|
||||
{
|
||||
$this->virtualhosts_data[$vhosts_filename].= ' ServerName ' . $this->settings['system']['hostname'] . "\n";
|
||||
}
|
||||
|
||||
if($row_ipsandports['specialsettings'] != '')
|
||||
{
|
||||
$this->virtualhosts_data[$vhosts_filename].= $row_ipsandports['specialsettings'] . "\n";
|
||||
}
|
||||
|
||||
if($row_ipsandports['ssl'] == '1' && $this->settings['system']['use_ssl'] == '1')
|
||||
{
|
||||
if($row_ipsandports['ssl_cert_file'] == '')
|
||||
{
|
||||
$row_ipsandports['ssl_cert_file'] = $this->settings['system']['ssl_cert_file'];
|
||||
}
|
||||
|
||||
if($row_ipsandports['ssl_key_file'] == '')
|
||||
{
|
||||
$row_ipsandports['ssl_key_file'] = $this->settings['system']['ssl_key_file'];
|
||||
}
|
||||
|
||||
if($row_ipsandports['ssl_ca_file'] == '')
|
||||
{
|
||||
$row_ipsandports['ssl_ca_file'] = $this->settings['system']['ssl_ca_file'];
|
||||
}
|
||||
|
||||
if($row_ipsandports['ssl_cert_file'] != '')
|
||||
{
|
||||
$this->virtualhosts_data[$vhosts_filename].= ' SSLEngine On' . "\n";
|
||||
$this->virtualhosts_data[$vhosts_filename].= ' SSLCertificateFile ' . makeCorrectFile($row_ipsandports['ssl_cert_file']) . "\n";
|
||||
|
||||
if($row_ipsandports['ssl_key_file'] != '')
|
||||
{
|
||||
$this->virtualhosts_data[$vhosts_filename].= ' SSLCertificateKeyFile ' . makeCorrectFile($row_ipsandports['ssl_key_file']) . "\n";
|
||||
}
|
||||
|
||||
if($row_ipsandports['ssl_ca_file'] != '')
|
||||
{
|
||||
$this->virtualhosts_data[$vhosts_filename].= ' SSLCACertificateFile ' . makeCorrectFile($row_ipsandports['ssl_ca_file']) . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->virtualhosts_data[$vhosts_filename].= '</VirtualHost>' . "\n";
|
||||
$this->logger->logAction(CRON_ACTION, LOG_DEBUG, $ipport . ' :: inserted vhostcontainer');
|
||||
}
|
||||
|
||||
unset($vhosts_filename);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We put together the needed php options in the virtualhost entries
|
||||
*/
|
||||
|
||||
protected function composePhpOptions($domain)
|
||||
{
|
||||
$php_options_text = '';
|
||||
|
||||
if($domain['phpenabled'] == '1')
|
||||
{
|
||||
// This vHost has PHP enabled and we are using the regular mod_php
|
||||
|
||||
if($domain['openbasedir'] == '1')
|
||||
{
|
||||
if($this->settings['system']['phpappendopenbasedir'] != '')
|
||||
{
|
||||
$_phpappendopenbasedir = ':' . $this->settings['system']['phpappendopenbasedir'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$_phpappendopenbasedir = '';
|
||||
}
|
||||
|
||||
if($domain['openbasedir_path'] == '1')
|
||||
{
|
||||
$php_options_text.= ' php_admin_value open_basedir "' . $domain['customerroot'] . $_phpappendopenbasedir . "\"\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$php_options_text.= ' php_admin_value open_basedir "' . $domain['documentroot'] . $_phpappendopenbasedir . "\"\n";
|
||||
}
|
||||
}
|
||||
|
||||
if($domain['safemode'] == '0')
|
||||
{
|
||||
$php_options_text.= ' php_admin_flag safe_mode Off ' . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$php_options_text.= ' php_admin_flag safe_mode On ' . "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$php_options_text.= ' # PHP is disabled for this vHost' . "\n";
|
||||
$php_options_text.= ' php_flag engine off' . "\n";
|
||||
}
|
||||
|
||||
return $php_options_text;
|
||||
}
|
||||
|
||||
/*
|
||||
* We collect all servernames and Aliases
|
||||
*/
|
||||
|
||||
protected function getServerNames($domain)
|
||||
{
|
||||
$servernames_text = '';
|
||||
$servernames_text.= ' ServerName ' . $domain['domain'] . "\n";
|
||||
|
||||
if($domain['iswildcarddomain'] == '1')
|
||||
{
|
||||
$server_alias = '*.' . $domain['domain'];
|
||||
}
|
||||
else
|
||||
{
|
||||
if($domain['wwwserveralias'] == '1')
|
||||
{
|
||||
$server_alias = 'www.' . $domain['domain'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$server_alias = '';
|
||||
}
|
||||
}
|
||||
|
||||
$alias_domains = $this->db->query('SELECT `domain`, `iswildcarddomain`, `wwwserveralias` FROM `' . TABLE_PANEL_DOMAINS . '` WHERE `aliasdomain`=\'' . $domain['id'] . '\'');
|
||||
|
||||
while(($alias_domain = $this->db->fetch_array($alias_domains)) !== false)
|
||||
{
|
||||
$server_alias.= ' ' . $alias_domain['domain'];
|
||||
|
||||
if($alias_domain['iswildcarddomain'] == '1')
|
||||
{
|
||||
$server_alias.= ' *.' . $alias_domain['domain'];
|
||||
}
|
||||
else
|
||||
{
|
||||
if($alias_domain['wwwserveralias'] == '1')
|
||||
{
|
||||
$server_alias.= ' www.' . $alias_domain['domain'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(trim($server_alias) != '')
|
||||
{
|
||||
$servernames_text.= ' ServerAlias ' . $server_alias . "\n";
|
||||
}
|
||||
|
||||
$servernames_text.= ' ServerAdmin ' . $domain['email'] . "\n";
|
||||
return $servernames_text;
|
||||
}
|
||||
|
||||
/*
|
||||
* Let's get the webroot
|
||||
*/
|
||||
|
||||
protected function getWebroot($domain)
|
||||
{
|
||||
$webroot_text = '';
|
||||
$domain['customerroot'] = makeCorrectDir($domain['customerroot']);
|
||||
$domain['documentroot'] = makeCorrectDir($domain['documentroot']);
|
||||
|
||||
if($domain['deactivated'] == '1'
|
||||
&& $this->settings['system']['deactivateddocroot'] != '')
|
||||
{
|
||||
$webroot_text.= ' # Using docroot for deactivated users...' . "\n";
|
||||
$webroot_text.= ' DocumentRoot "' . $this->settings['system']['deactivateddocroot'] . "\"\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$webroot_text.= ' DocumentRoot "' . $domain['documentroot'] . "\"\n";
|
||||
}
|
||||
|
||||
return $webroot_text;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lets set the text part for the stats software
|
||||
*/
|
||||
|
||||
protected function getStats($domain)
|
||||
{
|
||||
$stats_text = '';
|
||||
|
||||
if($domain['speciallogfile'] == '1'
|
||||
&& $this->settings['system']['mod_log_sql'] != '1')
|
||||
{
|
||||
if($domain['parentdomainid'] == '0')
|
||||
{
|
||||
$stats_text.= ' Alias /webalizer "' . makeCorrectFile($domain['customerroot'] . '/webalizer/' . $domain['domain']) . '"' . "\n";
|
||||
|
||||
if($this->settings['system']['awstats_enabled'] == '1')
|
||||
{
|
||||
$stats_text.= createAWStatsVhost($domain['domain'], $this->settings);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$stats_text.= ' Alias /webalizer "' . makeCorrectFile($domain['customerroot'] . '/webalizer/' . $domain['parentdomain']) . '"' . "\n";
|
||||
|
||||
if($this->settings['system']['awstats_enabled'] == '1')
|
||||
{
|
||||
$stats_text.= createAWStatsVhost($domain['parentdomain'], $this->settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($domain['customerroot'] != $domain['documentroot'])
|
||||
{
|
||||
$stats_text.= ' Alias /webalizer "' . makeCorrectFile($domain['customerroot'] . '/webalizer') . '"' . "\n";
|
||||
}
|
||||
|
||||
if($this->settings['system']['awstats_enabled'] == '1')
|
||||
{
|
||||
$stats_text.= createAWStatsVhost($domain['domain'], $this->settings);
|
||||
}
|
||||
}
|
||||
|
||||
return $stats_text;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lets set the logfiles
|
||||
*/
|
||||
|
||||
protected function getLogfiles($domain)
|
||||
{
|
||||
$logfiles_text = '';
|
||||
|
||||
if($domain['speciallogfile'] == '1'
|
||||
&& $this->settings['system']['mod_log_sql'] != '1')
|
||||
{
|
||||
if($domain['parentdomainid'] == '0')
|
||||
{
|
||||
$speciallogfile = '-' . $domain['domain'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$speciallogfile = '-' . $domain['parentdomain'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$speciallogfile = '';
|
||||
}
|
||||
|
||||
if($this->settings['system']['mod_log_sql'] == '1')
|
||||
{
|
||||
// We are using mod_log_sql (http://www.outoforder.cc/projects/apache/mod_log_sql/)
|
||||
// TODO: See how we are able emulate the error_log
|
||||
|
||||
$logfiles_text.= ' LogSQLTransferLogTable access_log' . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
// The normal access/error - logging is enabled
|
||||
$error_log = makeCorrectFile($this->settings['system']['logfiles_directory'] . $domain['loginname'] . $speciallogfile . '-error.log');
|
||||
chown($error_log, $this->settings['system']['httpuser']);
|
||||
chgrp($error_log, $this->settings['system']['httpgroup']);
|
||||
|
||||
$access_log = makeCorrectFile($this->settings['system']['logfiles_directory'] . $domain['loginname'] . $speciallogfile . '-access.log');
|
||||
chown($access_log, $this->settings['system']['httpuser']);
|
||||
chgrp($access_log, $this->settings['system']['httpgroup']);
|
||||
|
||||
$logfiles_text.= ' ErrorLog "' . $error_log . "\"\n";
|
||||
$logfiles_text.= ' CustomLog "' . $access_log .'" combined' . "\n";
|
||||
|
||||
}
|
||||
|
||||
if($this->settings['system']['awstats_enabled'] == '1')
|
||||
{
|
||||
// prepare the aliases for stats config files
|
||||
|
||||
$server_alias = '';
|
||||
$alias_domains = $this->db->query('SELECT `domain`, `iswildcarddomain`, `wwwserveralias` FROM `' . TABLE_PANEL_DOMAINS . '` WHERE `aliasdomain`=\'' . $domain['id'] . '\'');
|
||||
|
||||
while(($alias_domain = $this->db->fetch_array($alias_domains)) !== false)
|
||||
{
|
||||
$server_alias.= ' ' . $alias_domain['domain'] . ' ';
|
||||
|
||||
if($alias_domain['iswildcarddomain'] == '1')
|
||||
{
|
||||
$server_alias.= '*.' . $domain['domain'];
|
||||
}
|
||||
else
|
||||
{
|
||||
if($alias_domain['wwwserveralias'] == '1')
|
||||
{
|
||||
$server_alias.= 'www.' . $alias_domain['domain'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$server_alias.= '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($domain['iswildcarddomain'] == '1')
|
||||
{
|
||||
$alias = '*.' . $domain['domain'];
|
||||
}
|
||||
else
|
||||
{
|
||||
if($domain['wwwserveralias'] == '1')
|
||||
{
|
||||
$alias = 'www.' . $domain['domain'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$alias = '';
|
||||
}
|
||||
}
|
||||
|
||||
// After inserting the AWStats information, be sure to build the awstats conf file as well
|
||||
|
||||
createAWStatsConf($this->settings['system']['logfiles_directory'] . $domain['loginname'] . $speciallogfile . '-access.log', $domain['domain'], $alias . $server_alias);
|
||||
}
|
||||
|
||||
return $logfiles_text;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the filename for the virtualhost
|
||||
*/
|
||||
|
||||
protected function getVhostFilename($domain, $ssl_vhost = false)
|
||||
{
|
||||
if($ssl_vhost === true)
|
||||
{
|
||||
$vhost_filename = makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/20_syscp_ssl_vhost_' . $domain['domain'] . '.conf');
|
||||
}
|
||||
else
|
||||
{
|
||||
$vhost_filename = makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/20_syscp_normal_vhost_' . $domain['domain'] . '.conf');
|
||||
}
|
||||
|
||||
return $vhost_filename;
|
||||
}
|
||||
|
||||
/*
|
||||
* We compose the virtualhost entry for one domain
|
||||
*/
|
||||
|
||||
protected function getVhostContent($domain, $ssl_vhost = false)
|
||||
{
|
||||
if($ssl_vhost === true
|
||||
&& $domain['ssl'] != '1')
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
if($ssl_vhost === true
|
||||
&& $domain['ssl'] == '1')
|
||||
{
|
||||
$query = "SELECT * FROM " . TABLE_PANEL_IPSANDPORTS . " WHERE `id`='" . $domain['ssl_ipandport'] . "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = "SELECT * FROM " . TABLE_PANEL_IPSANDPORTS . " WHERE `id`='" . $domain['ipandport'] . "'";
|
||||
}
|
||||
|
||||
$ipandport = $this->db->query_first($query);
|
||||
$domain['ip'] = $ipandport['ip'];
|
||||
$domain['port'] = $ipandport['port'];
|
||||
$domain['ssl_cert_file'] = $ipandport['ssl_cert_file'];
|
||||
$domain['ssl_key_file'] = $ipandport['ssl_key_file'];
|
||||
$domain['ssl_ca_file'] = $ipandport['ssl_ca_file'];
|
||||
|
||||
if(filter_var($domain['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
|
||||
{
|
||||
$ipport = '[' . $domain['ip'] . ']:' . $domain['port'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$ipport = $domain['ip'] . ':' . $domain['port'];
|
||||
}
|
||||
|
||||
$vhost_content = '<VirtualHost ' . $ipport . '>' . "\n";
|
||||
$vhost_content.= $this->getServerNames($domain);
|
||||
|
||||
if($ssl_vhost == false
|
||||
&& $domain['ssl'] == '1'
|
||||
&& $domain['ssl_redirect'] == '1')
|
||||
{
|
||||
$domain['documentroot'] = 'https://' . $domain['domain'] . '/';
|
||||
}
|
||||
|
||||
if(preg_match('/^https?\:\/\//', $domain['documentroot']))
|
||||
{
|
||||
$vhost_content.= ' Redirect 301 / ' . $this->idnaConvert->encode($domain['documentroot']) . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if($ssl_vhost === true
|
||||
&& $domain['ssl'] == '1'
|
||||
&& $this->settings['system']['use_ssl'] == '1')
|
||||
{
|
||||
if($domain['ssl_cert_file'] == '')
|
||||
{
|
||||
$domain['ssl_cert_file'] = $this->settings['system']['ssl_cert_file'];
|
||||
}
|
||||
|
||||
if($domain['ssl_key_file'] == '')
|
||||
{
|
||||
$domain['ssl_key_file'] = $this->settings['system']['ssl_key_file'];
|
||||
}
|
||||
|
||||
if($domain['ssl_ca_file'] == '')
|
||||
{
|
||||
$domain['ssl_ca_file'] = $this->settings['system']['ssl_ca_file'];
|
||||
}
|
||||
|
||||
if($domain['ssl_cert_file'] != '')
|
||||
{
|
||||
$vhost_content.= ' SSLEngine On' . "\n";
|
||||
$vhost_content.= ' SSLCertificateFile ' . makeCorrectFile($domain['ssl_cert_file']) . "\n";
|
||||
|
||||
if($domain['ssl_key_file'] != '')
|
||||
{
|
||||
$vhost_content.= ' SSLCertificateKeyFile ' . makeCorrectFile($domain['ssl_key_file']) . "\n";
|
||||
}
|
||||
|
||||
if($domain['ssl_ca_file'] != '')
|
||||
{
|
||||
$vhost_content.= ' SSLCACertificateFile ' . makeCorrectFile($domain['ssl_ca_file']) . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mkDirWithCorrectOwnership($domain['customerroot'], $domain['documentroot'], $domain['guid'], $domain['guid']);
|
||||
$vhost_content.= $this->getWebroot($domain);
|
||||
$vhost_content.= $this->composePhpOptions($domain);
|
||||
$vhost_content.= $this->getStats($domain);
|
||||
$vhost_content.= $this->getLogfiles($domain);
|
||||
}
|
||||
|
||||
if($domain['specialsettings'] != '')
|
||||
{
|
||||
$vhost_content.= $domain['specialsettings'] . "\n";
|
||||
}
|
||||
|
||||
if($ipandport['default_vhostconf_domain'] != '')
|
||||
{
|
||||
$vhost_content.= $ipandport['default_vhostconf_domain'] . "\n";
|
||||
}
|
||||
|
||||
if($this->settings['system']['default_vhostconf'] != '')
|
||||
{
|
||||
$vhost_content.= $this->settings['system']['default_vhostconf'] . "\n";
|
||||
}
|
||||
|
||||
$vhost_content.= '</VirtualHost>' . "\n";
|
||||
return $vhost_content;
|
||||
}
|
||||
|
||||
/*
|
||||
* We compose the virtualhost entries for the domains
|
||||
*/
|
||||
|
||||
public function createVirtualHosts()
|
||||
{
|
||||
$result_domains = $this->db->query("SELECT `d`.`id`, `d`.`domain`, `d`.`customerid`, `d`.`documentroot`, `d`.`ssl`, `d`.`parentdomainid`, `d`.`ipandport`, `d`.`ssl_ipandport`, `d`.`ssl_redirect`, `d`.`isemaildomain`, `d`.`iswildcarddomain`, `d`.`wwwserveralias`, `d`.`openbasedir`, `d`.`openbasedir_path`, `d`.`safemode`, `d`.`speciallogfile`, `d`.`specialsettings`, `pd`.`domain` AS `parentdomain`, `c`.`loginname`, `d`.`phpsettingid`, `c`.`adminid`, `c`.`guid`, `c`.`email`, `c`.`documentroot` AS `customerroot`, `c`.`deactivated`, `c`.`phpenabled` AS `phpenabled`, `d`.`mod_fcgid_starter`, `d`.`mod_fcgid_maxrequests` FROM `" . TABLE_PANEL_DOMAINS . "` `d` LEFT JOIN `" . TABLE_PANEL_CUSTOMERS . "` `c` USING(`customerid`) " . "LEFT JOIN `" . TABLE_PANEL_DOMAINS . "` `pd` ON (`pd`.`id` = `d`.`parentdomainid`) " . "WHERE `d`.`aliasdomain` IS NULL ORDER BY `d`.`iswildcarddomain`, `d`.`domain` ASC");
|
||||
|
||||
while($domain = $this->db->fetch_array($result_domains))
|
||||
{
|
||||
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']);
|
||||
$vhosts_filename = $this->getVhostFilename($domain);
|
||||
|
||||
// Apply header
|
||||
|
||||
$this->virtualhosts_data[$vhosts_filename] = '# Domain ID: ' . $domain['id'] . ' - CustomerID: ' . $domain['customerid'] . ' - CustomerLogin: ' . $domain['loginname'] . "\n";
|
||||
|
||||
if($domain['deactivated'] != '1'
|
||||
|| $this->settings['system']['deactivateddocroot'] != '')
|
||||
{
|
||||
$this->virtualhosts_data[$vhosts_filename].= $this->getVhostContent($domain);
|
||||
|
||||
if($domain['ssl'] == '1')
|
||||
{
|
||||
// Adding ssl stuff if enabled
|
||||
|
||||
$vhosts_filename_ssl = $this->getVhostFilename($domain, true);
|
||||
$this->virtualhosts_data[$vhosts_filename_ssl] = '# Domain ID: ' . $domain['id'] . ' (SSL) - CustomerID: ' . $domain['customerid'] . ' - CustomerLogin: ' . $domain['loginname'] . "\n";
|
||||
$this->virtualhosts_data[$vhosts_filename_ssl].= $this->getVhostContent($domain, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->virtualhosts_data[$vhosts_filename].= '# Customer deactivated and a docroot for deactivated users hasn\'t been set.' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We compose the diroption entries for the paths
|
||||
*/
|
||||
|
||||
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`');
|
||||
$diroptions = array();
|
||||
|
||||
while($row_diroptions = $this->db->fetch_array($result))
|
||||
{
|
||||
if($row_diroptions['customerid'] != 0
|
||||
&& isset($row_diroptions['customerroot'])
|
||||
&& $row_diroptions['customerroot'] != '')
|
||||
{
|
||||
$diroptions[$row_diroptions['path']] = $row_diroptions;
|
||||
$diroptions[$row_diroptions['path']]['htpasswds'] = array();
|
||||
}
|
||||
}
|
||||
|
||||
$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`');
|
||||
|
||||
while($row_htpasswds = $this->db->fetch_array($result))
|
||||
{
|
||||
if($row_htpasswds['customerid'] != 0
|
||||
&& isset($row_htpasswds['customerroot'])
|
||||
&& $row_htpasswds['customerroot'] != '')
|
||||
{
|
||||
if(!isset($diroptions[$row_htpasswds['path']]) || !is_array($diroptions[$row_htpasswds['path']]))
|
||||
{
|
||||
$diroptions[$row_htpasswds['path']] = array();
|
||||
}
|
||||
|
||||
$diroptions[$row_htpasswds['path']]['path'] = $row_htpasswds['path'];
|
||||
$diroptions[$row_htpasswds['path']]['guid'] = $row_htpasswds['guid'];
|
||||
$diroptions[$row_htpasswds['path']]['customerroot'] = $row_htpasswds['customerroot'];
|
||||
$diroptions[$row_htpasswds['path']]['customerid'] = $row_htpasswds['customerid'];
|
||||
$diroptions[$row_htpasswds['path']]['htpasswds'][] = $row_htpasswds;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($diroptions as $row_diroptions)
|
||||
{
|
||||
$row_diroptions['path'] = makeCorrectDir($row_diroptions['path']);
|
||||
mkDirWithCorrectOwnership($row_diroptions['customerroot'], $row_diroptions['path'], $row_diroptions['guid'], $row_diroptions['guid']);
|
||||
$diroptions_filename = makeCorrectFile($this->settings['system']['apacheconf_diroptions'] . '/40_syscp_diroption_' . md5($row_diroptions['path']) . '.conf');
|
||||
|
||||
if(!isset($this->diroptions_data[$diroptions_filename]))
|
||||
{
|
||||
$this->diroptions_data[$diroptions_filename] = '';
|
||||
}
|
||||
|
||||
if(is_dir($row_diroptions['path']))
|
||||
{
|
||||
$this->diroptions_data[$diroptions_filename].= '<Directory "' . $row_diroptions['path'] . '">' . "\n";
|
||||
|
||||
if(isset($row_diroptions['options_indexes'])
|
||||
&& $row_diroptions['options_indexes'] == '1')
|
||||
{
|
||||
$this->diroptions_data[$diroptions_filename].= ' Options +Indexes' . "\n";
|
||||
fwrite($this->debugHandler, ' cron_tasks: Task3 - Setting Options +Indexes' . "\n");
|
||||
}
|
||||
|
||||
if(isset($row_diroptions['options_indexes'])
|
||||
&& $row_diroptions['options_indexes'] == '0')
|
||||
{
|
||||
$this->diroptions_data[$diroptions_filename].= ' Options -Indexes' . "\n";
|
||||
fwrite($this->debugHandler, ' cron_tasks: Task3 - Setting Options -Indexes' . "\n");
|
||||
}
|
||||
|
||||
if(isset($row_diroptions['error404path'])
|
||||
&& $row_diroptions['error404path'] != '')
|
||||
{
|
||||
$this->diroptions_data[$diroptions_filename].= ' ErrorDocument 404 ' . $row_diroptions['error404path'] . "\n";
|
||||
}
|
||||
|
||||
if(isset($row_diroptions['error403path'])
|
||||
&& $row_diroptions['error403path'] != '')
|
||||
{
|
||||
$this->diroptions_data[$diroptions_filename].= ' ErrorDocument 403 ' . $row_diroptions['error403path'] . "\n";
|
||||
}
|
||||
|
||||
if(isset($row_diroptions['error500path'])
|
||||
&& $row_diroptions['error500path'] != '')
|
||||
{
|
||||
$this->diroptions_data[$diroptions_filename].= ' ErrorDocument 500 ' . $row_diroptions['error500path'] . "\n";
|
||||
}
|
||||
|
||||
if(count($row_diroptions['htpasswds']) > 0)
|
||||
{
|
||||
$htpasswd_filename = makeCorrectFile($this->settings['system']['apacheconf_htpasswddir'] . '/' . $row_diroptions['customerid'] . '-' . md5($row_diroptions['path']) . '.htpasswd');
|
||||
|
||||
if(!isset($this->htpasswds_data[$htpasswd_filename]))
|
||||
{
|
||||
$this->htpasswds_data[$htpasswd_filename] = '';
|
||||
}
|
||||
|
||||
foreach($row_diroptions['htpasswds'] as $row_htpasswd)
|
||||
{
|
||||
$this->htpasswds_data[$htpasswd_filename].= $row_htpasswd['username'] . ':' . $row_htpasswd['password'] . "\n";
|
||||
}
|
||||
|
||||
$this->diroptions_data[$diroptions_filename].= ' AuthType Basic' . "\n";
|
||||
$this->diroptions_data[$diroptions_filename].= ' AuthName "Restricted Area"' . "\n";
|
||||
$this->diroptions_data[$diroptions_filename].= ' AuthUserFile ' . $htpasswd_filename . "\n";
|
||||
$this->diroptions_data[$diroptions_filename].= ' require valid-user' . "\n";
|
||||
}
|
||||
|
||||
$this->diroptions_data[$diroptions_filename].= '</Directory>' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We write the configs
|
||||
*/
|
||||
|
||||
public function writeConfigs()
|
||||
{
|
||||
// Write diroptions
|
||||
|
||||
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']);
|
||||
|
||||
if(count($this->diroptions_data) > 0)
|
||||
{
|
||||
if(!isConfigDir($this->settings['system']['apacheconf_diroptions']))
|
||||
{
|
||||
// Save one big file
|
||||
|
||||
$diroptions_file = '';
|
||||
|
||||
foreach($this->diroptions_data as $diroptions_filename => $diroptions_content)
|
||||
{
|
||||
$diroptions_file.= $diroptions_content . "\n\n";
|
||||
}
|
||||
|
||||
$diroptions_filename = $this->settings['system']['apacheconf_diroptions'];
|
||||
|
||||
// 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_handler = fopen($diroptions_filename, 'w');
|
||||
fwrite($diroptions_file_handler, $diroptions_file);
|
||||
fclose($diroptions_file_handler);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!file_exists($this->settings['system']['apacheconf_diroptions']))
|
||||
{
|
||||
fwrite($this->debugHandler, ' apache::writeConfigs: mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_diroptions'])) . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_diroptions'])));
|
||||
safe_exec('mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_diroptions'])));
|
||||
}
|
||||
|
||||
// Write a single file for every diroption
|
||||
|
||||
foreach($this->diroptions_data as $diroptions_filename => $diroptions_file)
|
||||
{
|
||||
$this->known_diroptionsfilenames[] = basename($diroptions_filename);
|
||||
|
||||
// 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_handler = fopen($diroptions_filename, 'w');
|
||||
fwrite($diroptions_file_handler, $diroptions_file);
|
||||
fclose($diroptions_file_handler);
|
||||
}
|
||||
|
||||
$this->wipeOutOldDiroptionConfigs();
|
||||
}
|
||||
}
|
||||
|
||||
// Write htpasswds
|
||||
|
||||
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']);
|
||||
|
||||
if(count($this->htpasswds_data) > 0)
|
||||
{
|
||||
if(!file_exists($this->settings['system']['apacheconf_htpasswddir']))
|
||||
{
|
||||
$umask = umask();
|
||||
umask(0000);
|
||||
mkdir($this->settings['system']['apacheconf_htpasswddir'], 0751);
|
||||
umask($umask);
|
||||
}
|
||||
elseif(!is_dir($this->settings['system']['apacheconf_htpasswddir']))
|
||||
{
|
||||
fwrite($this->debugHandler, ' cron_tasks: WARNING!!! ' . $this->settings['system']['apacheconf_htpasswddir'] . ' is not a directory. htpasswd directory protection is disabled!!!' . "\n");
|
||||
echo 'WARNING!!! ' . $this->settings['system']['apacheconf_htpasswddir'] . ' is not a directory. htpasswd directory protection is disabled!!!';
|
||||
$this->logger->logAction(CRON_ACTION, LOG_WARNING, 'WARNING!!! ' . $this->settings['system']['apacheconf_htpasswddir'] . ' is not a directory. htpasswd directory protection is disabled!!!');
|
||||
}
|
||||
|
||||
if(is_dir($this->settings['system']['apacheconf_htpasswddir']))
|
||||
{
|
||||
foreach($this->htpasswds_data as $htpasswd_filename => $htpasswd_file)
|
||||
{
|
||||
$this->known_htpasswdsfilenames[] = basename($htpasswd_filename);
|
||||
$htpasswd_file_handler = fopen($htpasswd_filename, 'w');
|
||||
fwrite($htpasswd_file_handler, $htpasswd_file);
|
||||
fclose($htpasswd_file_handler);
|
||||
}
|
||||
|
||||
$this->wipeOutOldHtpasswdConfigs();
|
||||
}
|
||||
}
|
||||
|
||||
// Write virtualhosts
|
||||
|
||||
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']);
|
||||
|
||||
if(count($this->virtualhosts_data) > 0)
|
||||
{
|
||||
if(!isConfigDir($this->settings['system']['apacheconf_vhost']))
|
||||
{
|
||||
// Save one big file
|
||||
|
||||
$vhosts_file = '';
|
||||
|
||||
foreach($this->virtualhosts_data as $vhosts_filename => $vhost_content)
|
||||
{
|
||||
$vhosts_file.= $vhost_content . "\n\n";
|
||||
}
|
||||
|
||||
// Include diroptions file in case it exists
|
||||
|
||||
if(file_exists($this->settings['system']['apacheconf_diroptions']))
|
||||
{
|
||||
$vhosts_file.= "\n" . 'Include ' . $this->settings['system']['apacheconf_diroptions'] . "\n\n";
|
||||
}
|
||||
|
||||
$vhosts_filename = $this->settings['system']['apacheconf_vhost'];
|
||||
|
||||
// Apply header
|
||||
|
||||
$vhosts_file = '# ' . basename($vhosts_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" . $vhosts_file;
|
||||
$vhosts_file_handler = fopen($vhosts_filename, 'w');
|
||||
fwrite($vhosts_file_handler, $vhosts_file);
|
||||
fclose($vhosts_file_handler);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!file_exists($this->settings['system']['apacheconf_vhost']))
|
||||
{
|
||||
fwrite($this->debugHandler, ' apache::writeConfigs: mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost'])) . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost'])));
|
||||
safe_exec('mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost'])));
|
||||
}
|
||||
|
||||
// Write a single file for every vhost
|
||||
|
||||
foreach($this->virtualhosts_data as $vhosts_filename => $vhosts_file)
|
||||
{
|
||||
$this->known_vhostfilenames[] = basename($vhosts_filename);
|
||||
|
||||
// Apply header
|
||||
|
||||
$vhosts_file = '# ' . basename($vhosts_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" . $vhosts_file;
|
||||
$vhosts_file_handler = fopen($vhosts_filename, 'w');
|
||||
fwrite($vhosts_file_handler, $vhosts_file);
|
||||
fclose($vhosts_file_handler);
|
||||
}
|
||||
|
||||
$this->wipeOutOldVhostConfigs();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We remove old vhost config files
|
||||
*/
|
||||
|
||||
protected function wipeOutOldVhostConfigs()
|
||||
{
|
||||
fwrite($this->debugHandler, ' apache::wipeOutOldVhostConfigs: cleaning ' . $this->settings['system']['apacheconf_vhost'] . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, "cleaning " . $this->settings['system']['apacheconf_vhost']);
|
||||
|
||||
if(isConfigDir($this->settings['system']['apacheconf_vhost'])
|
||||
&& file_exists($this->settings['system']['apacheconf_vhost'])
|
||||
&& is_dir($this->settings['system']['apacheconf_vhost']))
|
||||
{
|
||||
$vhost_file_dirhandle = opendir($this->settings['system']['apacheconf_vhost']);
|
||||
|
||||
while(false !== ($vhost_filename = readdir($vhost_file_dirhandle)))
|
||||
{
|
||||
if($vhost_filename != '.'
|
||||
&& $vhost_filename != '..'
|
||||
&& !in_array($vhost_filename, $this->known_vhostfilenames)
|
||||
&& preg_match('/^(10|20|30)_syscp_(ipandport|normal_vhost|wildcard_vhost|ssl_vhost)_(.+)\.conf$/', $vhost_filename)
|
||||
&& file_exists(makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/' . $vhost_filename)))
|
||||
{
|
||||
fwrite($this->debugHandler, ' apache::wipeOutOldVhostConfigs: unlinking ' . $vhost_filename . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'unlinking ' . $vhost_filename);
|
||||
unlink(makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/' . $vhost_filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We remove old diroptions config files
|
||||
*/
|
||||
|
||||
protected function wipeOutOldDiroptionConfigs()
|
||||
{
|
||||
fwrite($this->debugHandler, ' apache::wipeOutOldDiroptionConfigs: cleaning ' . $this->settings['system']['apacheconf_diroptions'] . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, "cleaning " . $this->settings['system']['apacheconf_diroptions']);
|
||||
|
||||
if(isConfigDir($this->settings['system']['apacheconf_diroptions'])
|
||||
&& file_exists($this->settings['system']['apacheconf_diroptions'])
|
||||
&& is_dir($this->settings['system']['apacheconf_diroptions']))
|
||||
{
|
||||
$diroptions_file_dirhandle = opendir($this->settings['system']['apacheconf_diroptions']);
|
||||
|
||||
while(false !== ($diroptions_filename = readdir($diroptions_file_dirhandle)))
|
||||
{
|
||||
if($diroptions_filename != '.'
|
||||
&& $diroptions_filename != '..'
|
||||
&& !in_array($diroptions_filename, $this->known_diroptionsfilenames)
|
||||
&& preg_match('/^40_syscp_diroption_(.+)\.conf$/', $diroptions_filename)
|
||||
&& file_exists(makeCorrectFile($this->settings['system']['apacheconf_diroptions'] . '/' . $diroptions_filename)))
|
||||
{
|
||||
fwrite($this->debugHandler, ' apache::wipeOutOldDiroptionConfigs: unlinking ' . $diroptions_filename . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'unlinking ' . $diroptions_filename);
|
||||
unlink(makeCorrectFile($this->settings['system']['apacheconf_diroptions'] . '/' . $diroptions_filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We remove old htpasswd config files
|
||||
*/
|
||||
|
||||
protected function wipeOutOldHtpasswdConfigs()
|
||||
{
|
||||
fwrite($this->debugHandler, ' apache::wipeOutOldHtpasswdConfigs: cleaning ' . $this->settings['system']['apacheconf_htpasswddir'] . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, "cleaning " . $this->settings['system']['apacheconf_htpasswddir']);
|
||||
|
||||
if(isConfigDir($this->settings['system']['apacheconf_htpasswddir'])
|
||||
&& file_exists($this->settings['system']['apacheconf_htpasswddir'])
|
||||
&& is_dir($this->settings['system']['apacheconf_htpasswddir']))
|
||||
{
|
||||
$htpasswds_file_dirhandle = opendir($this->settings['system']['apacheconf_htpasswddir']);
|
||||
|
||||
while(false !== ($htpasswd_filename = readdir($htpasswds_file_dirhandle)))
|
||||
{
|
||||
if($htpasswd_filename != '.'
|
||||
&& $htpasswd_filename != '..'
|
||||
&& !in_array($htpasswd_filename, $this->known_htpasswdsfilenames)
|
||||
&& file_exists(makeCorrectFile($this->settings['system']['apacheconf_htpasswddir'] . '/' . $htpasswd_filename)))
|
||||
{
|
||||
fwrite($this->debugHandler, ' apache::wipeOutOldHtpasswdConfigs: unlinking ' . $htpasswd_filename . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'unlinking ' . $htpasswd_filename);
|
||||
unlink(makeCorrectFile($this->settings['system']['apacheconf_htpasswddir'] . '/' . $htpasswd_filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
262
scripts/jobs/always/cron_tasks.inc.http.15.apache_fcgid.php
Normal file
262
scripts/jobs/always/cron_tasks.inc.http.15.apache_fcgid.php
Normal file
@@ -0,0 +1,262 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
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
|
||||
{
|
||||
private $php_configs_cache = array();
|
||||
private $admin_cache = array();
|
||||
|
||||
/*
|
||||
* We put together the needed php options in the virtualhost entries
|
||||
*/
|
||||
|
||||
protected function composePhpOptions($domain)
|
||||
{
|
||||
$php_options_text = '';
|
||||
|
||||
if($domain['phpenabled'] == '1')
|
||||
{
|
||||
// This vHost has PHP enabled and we are using mod_fcgid
|
||||
//create basic variables for config
|
||||
|
||||
$configdir = makeCorrectDir($this->settings['system']['mod_fcgid_configdir'] . '/' . $domain['loginname'] . '/' . $domain['domain'] . '/');
|
||||
$starter_filename = makeCorrectFile($configdir . '/php-fcgi-starter');
|
||||
$phpini_filename = makeCorrectFile($configdir . '/php.ini');
|
||||
$tmpdir = makeCorrectDir($this->settings['system']['mod_fcgid_tmpdir'] . '/' . $domain['loginname'] . '/');
|
||||
|
||||
// create config dir if necessary
|
||||
|
||||
if(!is_dir($configdir))
|
||||
{
|
||||
safe_exec('mkdir -p ' . escapeshellarg($configdir));
|
||||
safe_exec('chown ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($configdir));
|
||||
}
|
||||
|
||||
// create tmp dir if necessary
|
||||
|
||||
if(!is_dir($tmpdir))
|
||||
{
|
||||
safe_exec('mkdir -p ' . escapeshellarg($tmpdir));
|
||||
safe_exec('chown -R ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($tmpdir));
|
||||
safe_exec('chmod 0750 ' . escapeshellarg($tmpdir));
|
||||
}
|
||||
|
||||
// Load php config
|
||||
|
||||
$phpconfig = $this->getPhpConfig((int)$domain['phpsettingid']);
|
||||
|
||||
if((int)$this->settings['system']['mod_fcgid_wrapper'] == 0)
|
||||
{
|
||||
$php_options_text.= ' SuexecUserGroup "' . $domain['loginname'] . '" "' . $domain['loginname'] . '"' . "\n";
|
||||
$php_options_text.= ' ScriptAlias /php/ ' . $configdir . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$php_options_text.= ' SuexecUserGroup "' . $domain['loginname'] . '" "' . $domain['loginname'] . '"' . "\n";
|
||||
$php_options_text.= ' <Directory "' . $domain['documentroot'] . '">' . "\n";
|
||||
$file_extensions = explode(' ', $phpconfig['file_extensions']);
|
||||
$php_options_text.= ' AddHandler fcgid-script .' . implode(' .', $file_extensions) . "\n";
|
||||
foreach($file_extensions as $file_extension)
|
||||
{
|
||||
$php_options_text.= ' FCGIWrapper ' . $starter_filename . ' .' . $file_extension . "\n";
|
||||
}
|
||||
|
||||
$php_options_text.= ' Options +ExecCGI' . "\n";
|
||||
$php_options_text.= ' Order allow,deny' . "\n";
|
||||
$php_options_text.= ' allow from all' . "\n";
|
||||
$php_options_text.= ' </Directory>' . "\n";
|
||||
}
|
||||
|
||||
// create starter
|
||||
|
||||
$starter_file = "#!/bin/sh\n\n";
|
||||
$starter_file.= "#\n";
|
||||
$starter_file.= "# starter created/changed on " . date("Y.m.d H:i:s") . " for domain '" . $domain['domain'] . "' with id #" . $domain['id'] . " from php template '" . $phpconfig['description'] . "' with id #" . $phpconfig['id'] . "\n";
|
||||
$starter_file.= "# Do not change anything in this file, it will be overwritten by the Froxlor Cronjob!\n";
|
||||
$starter_file.= "#\n\n";
|
||||
$starter_file.= "PHPRC=" . escapeshellarg($configdir) . "\n";
|
||||
$starter_file.= "export PHPRC\n";
|
||||
|
||||
// set number of processes for one domain
|
||||
|
||||
if((int)$domain['mod_fcgid_starter'] != - 1)
|
||||
{
|
||||
$starter_file.= "PHP_FCGI_CHILDREN=" . (int)$domain['mod_fcgid_starter'] . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if((int)$phpconfig['mod_fcgid_starter'] != - 1)
|
||||
{
|
||||
$starter_file.= "PHP_FCGI_CHILDREN=" . (int)$phpconfig['mod_fcgid_starter'] . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$starter_file.= "PHP_FCGI_CHILDREN=" . (int)$this->settings['system']['mod_fcgid_starter'] . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
$starter_file.= "export PHP_FCGI_CHILDREN\n";
|
||||
|
||||
// set number of maximum requests for one domain
|
||||
|
||||
if((int)$domain['mod_fcgid_maxrequests'] != - 1)
|
||||
{
|
||||
$starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$domain['mod_fcgid_maxrequests'] . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if((int)$phpconfig['mod_fcgid_maxrequests'] != - 1)
|
||||
{
|
||||
$starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$phpconfig['mod_fcgid_maxrequests'] . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$this->settings['system']['mod_fcgid_maxrequests'] . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
$starter_file.= "export PHP_FCGI_MAX_REQUESTS\n";
|
||||
|
||||
// Set Binary
|
||||
|
||||
$starter_file.= "exec " . $phpconfig['binary'] . " -c " . escapeshellarg($configdir) . "\n";
|
||||
|
||||
//remove +i attibute, so starter can be overwritten
|
||||
|
||||
if(file_exists($starter_filename))
|
||||
{
|
||||
safe_exec('chattr -i ' . escapeshellarg($starter_filename));
|
||||
}
|
||||
|
||||
$starter_file_handler = fopen($starter_filename, 'w');
|
||||
fwrite($starter_file_handler, $starter_file);
|
||||
fclose($starter_file_handler);
|
||||
safe_exec('chmod 750 ' . escapeshellarg($starter_filename));
|
||||
safe_exec('chown ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($starter_filename));
|
||||
safe_exec('chattr +i ' . escapeshellarg($starter_filename));
|
||||
|
||||
// define the php.ini
|
||||
|
||||
$openbasedir = '';
|
||||
$openbasedirc = ';';
|
||||
|
||||
if($domain['openbasedir'] == '1')
|
||||
{
|
||||
$openbasedirc = '';
|
||||
if($domain['openbasedir_path'] == '0')
|
||||
{
|
||||
$openbasedir = $domain['documentroot'] . ':' . $tmpdir . ':' . $this->settings['system']['mod_fcgid_peardir'] . ':' . $this->settings['system']['phpappendopenbasedir'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$openbasedir = $domain['customerroot'] . ':' . $tmpdir . ':' . $this->settings['system']['mod_fcgid_peardir'] . ':' . $this->settings['system']['phpappendopenbasedir'];
|
||||
}
|
||||
|
||||
$openbasedir = explode(':', $openbasedir);
|
||||
foreach($openbasedir as $number => $path)
|
||||
{
|
||||
$openbasedir[$number] = makeCorrectDir($path);
|
||||
}
|
||||
|
||||
$openbasedir = implode(':', $openbasedir);
|
||||
}
|
||||
else
|
||||
{
|
||||
$openbasedir = 'none';
|
||||
$openbasedirc = ';';
|
||||
}
|
||||
|
||||
$admin = $this->getAdminData($domain['adminid']);
|
||||
$php_ini_variables = array(
|
||||
'SAFE_MODE' => ($domain['safemode'] == '0' ? 'Off' : 'On'),
|
||||
'PEAR_DIR' => $this->settings['system']['mod_fcgid_peardir'],
|
||||
'OPEN_BASEDIR' => $openbasedir,
|
||||
'OPEN_BASEDIR_C' => $openbasedirc,
|
||||
'OPEN_BASEDIR_GLOBAL' => $this->settings['system']['phpappendopenbasedir'],
|
||||
'TMP_DIR' => $tmpdir,
|
||||
'CUSTOMER_EMAIL' => $domain['email'],
|
||||
'ADMIN_EMAIL' => $admin['email'],
|
||||
'DOMAIN' => $domain['domain'],
|
||||
'CUSTOMER' => $domain['loginname'],
|
||||
'ADMIN' => $admin['loginname']
|
||||
);
|
||||
|
||||
//insert a small header for the file
|
||||
|
||||
$phpini_file = ";\n";
|
||||
$phpini_file.= "; php.ini created/changed on " . date("Y.m.d H:i:s") . " for domain '" . $domain['domain'] . "' with id #" . $domain['id'] . " from php template '" . $phpconfig['description'] . "' with id #" . $phpconfig['id'] . "\n";
|
||||
$phpini_file.= "; Do not change anything in this file, it will be overwritten by the Froxlor Cronjob!\n";
|
||||
$phpini_file.= ";\n\n";
|
||||
$phpini_file.= replace_variables($phpconfig['phpsettings'], $php_ini_variables);
|
||||
$phpini_file = str_replace('"none"', 'none', $phpini_file);
|
||||
$phpini_file = preg_replace('/\"+/', '"', $phpini_file);
|
||||
$phpini_file_handler = fopen($phpini_filename, 'w');
|
||||
fwrite($phpini_file_handler, $phpini_file);
|
||||
fclose($phpini_file_handler);
|
||||
safe_exec('chown root:0 ' . escapeshellarg($phpini_filename));
|
||||
safe_exec('chmod 0644 ' . escapeshellarg($phpini_filename));
|
||||
}
|
||||
else
|
||||
{
|
||||
$php_options_text.= ' # PHP is disabled for this vHost' . "\n";
|
||||
}
|
||||
|
||||
return $php_options_text;
|
||||
}
|
||||
|
||||
private function getPhpConfig($php_config_id)
|
||||
{
|
||||
$php_config_id = intval($php_config_id);
|
||||
|
||||
// If domain has no config, we will use the default one.
|
||||
|
||||
if($php_config_id == 0)
|
||||
{
|
||||
$php_config_id = 1;
|
||||
}
|
||||
|
||||
if(!isset($this->php_configs_cache[$php_config_id]))
|
||||
{
|
||||
$this->php_configs_cache[$php_config_id] = $this->getDB()->query_first("SELECT * FROM `" . TABLE_PANEL_PHPCONFIGS . "` WHERE `id` = " . (int)$php_config_id);
|
||||
}
|
||||
|
||||
return $this->php_configs_cache[$php_config_id];
|
||||
}
|
||||
|
||||
private function getAdminData($adminid)
|
||||
{
|
||||
$adminid = intval($adminid);
|
||||
|
||||
if(!isset($this->admin_cache[$adminid]))
|
||||
{
|
||||
$this->admin_cache[$adminid] = $this->getDB()->query_first("SELECT `email`, `loginname` FROM `" . TABLE_PANEL_ADMINS . "` WHERE `adminid` = " . (int)$adminid);
|
||||
}
|
||||
|
||||
return $this->admin_cache[$adminid];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
620
scripts/jobs/always/cron_tasks.inc.http.20.lighttpd.php
Normal file
620
scripts/jobs/always/cron_tasks.inc.http.20.lighttpd.php
Normal file
@@ -0,0 +1,620 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* This script creates the php.ini's used by mod_suPHP+php-cgi
|
||||
*/
|
||||
|
||||
if(@php_sapi_name() != 'cli'
|
||||
&& @php_sapi_name() != 'cgi'
|
||||
&& @php_sapi_name() != 'cgi-fcgi')
|
||||
{
|
||||
die('This script only works in the shell.');
|
||||
}
|
||||
|
||||
class lighttpd
|
||||
{
|
||||
private $db = false;
|
||||
private $logger = false;
|
||||
private $debugHandler = false;
|
||||
private $idnaConvert = false;
|
||||
|
||||
// protected
|
||||
|
||||
protected $settings = array();
|
||||
protected $lighttpd_data = array();
|
||||
protected $needed_htpasswds = array();
|
||||
protected $auth_backend_loaded = false;
|
||||
protected $htpasswd_files = array();
|
||||
protected $mod_accesslog_loaded = "0";
|
||||
|
||||
|
||||
public function __construct($db, $logger, $debugHandler, $idnaConvert, $settings)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->logger = $logger;
|
||||
$this->debugHandler = $debugHandler;
|
||||
$this->idnaConvert = $idnaConvert;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
protected function getDB()
|
||||
{
|
||||
return $this->db;
|
||||
}
|
||||
|
||||
public function reload()
|
||||
{
|
||||
fwrite($this->debugHandler, ' lighttpd::reload: reloading lighttpd' . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'reloading apache');
|
||||
safe_exec($this->settings['system']['apachereload_command']);
|
||||
}
|
||||
|
||||
public function createIpPort()
|
||||
{
|
||||
$query = "SELECT `id`, `ip`, `port`, `listen_statement`, `namevirtualhost_statement`, `vhostcontainer`, " . " `vhostcontainer_servername_statement`, `specialsettings`, `ssl`, `ssl_cert_file` " . " 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))
|
||||
{
|
||||
if(filter_var($row_ipsandports['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
|
||||
{
|
||||
$ip = '[' . $row_ipsandports['ip'] . ']';
|
||||
$port = $row_ipsandports['port'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$ip = $row_ipsandports['ip'];
|
||||
$port = $row_ipsandports['port'];
|
||||
}
|
||||
|
||||
fwrite($this->debugHandler, ' lighttpd::createIpPort: creating ip/port settings for ' . $ip . ":" . $port . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'creating ip/port settings for ' . $ip . ":" . $port);
|
||||
$vhost_filename = makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/10_froxlor_ipandport_' . trim(str_replace(':', '.', $row_ipsandports['ip']), '.') . '.' . $row_ipsandports['port'] . '.conf');
|
||||
|
||||
if(!isset($this->lighttpd_data[$vhosts_filename]))
|
||||
{
|
||||
$this->lighttpd_data[$vhosts_filename] = '';
|
||||
}
|
||||
|
||||
$this->lighttpd_data[$vhost_filename].= '$SERVER["socket"] == "' . $ip . ':' . $port . '" {' . "\n";
|
||||
|
||||
if($row_ipsandports['listen_statement'] == '1')
|
||||
{
|
||||
$this->lighttpd_data[$vhost_filename].= 'server.port = ' . $port . "\n";
|
||||
$this->lighttpd_data[$vhost_filename].= 'server.bind = "' . $ip . '"' . "\n";
|
||||
}
|
||||
|
||||
if($row_ipsandports['ssl'] == '1')
|
||||
{
|
||||
$this->lighttpd_data[$vhost_filename].= 'ssl.engine = "enable"' . "\n";
|
||||
$this->lighttpd_data[$vhost_filename].= 'ssl.pemfile = "' . $row_ipsandports['ssl_cert_file'] . '"' . "\n";
|
||||
}
|
||||
|
||||
$this->createLighttpdHosts($row_ipsandports['ip'], $row_ipsandports['port'], $row_ipsandports['ssl'], $vhost_filename);
|
||||
$this->lighttpd_data[$vhost_filename].= $this->needed_htpasswds[$row_ipsandports['id']] . "\n";
|
||||
$this->lighttpd_data[$vhost_filename].= '}' . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
protected function create_htaccess($domain)
|
||||
{
|
||||
$needed_htpasswds = array();
|
||||
$htpasswd_query = "SELECT * FROM " . TABLE_PANEL_HTPASSWDS . " WHERE `path` LIKE '" . $domain['documentroot'] . "%'";
|
||||
$result_htpasswds = $this->db->query($htpasswd_query);
|
||||
|
||||
while($row_htpasswds = $this->db->fetch_array($result_htpasswds))
|
||||
{
|
||||
$filename = $row_htpasswds['customerid'] . '-' . md5($row_htpasswds['path']) . '.htpasswd';
|
||||
|
||||
if(!in_array($row_htpasswds['path'], $needed_htpasswds))
|
||||
{
|
||||
if(empty($needed_htpasswds))
|
||||
{
|
||||
$auth_backend_loaded[$domain['ipandport']] = 'yes';
|
||||
|
||||
if(!$this->auth_backend_loaded)
|
||||
{
|
||||
$htaccess_text.= ' auth.backend = "htpasswd"' . "\n";
|
||||
}
|
||||
|
||||
$htaccess_text.= ' auth.backend.htpasswd.userfile = "' . makeCorrectFile($this->settings['system']['apacheconf_htpasswddir'] . '/' . $filename) . '"' . "\n";
|
||||
$htaccess_text.= ' auth.require = ( ' . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$htaccess_text.= ' ,' . "\n";
|
||||
}
|
||||
|
||||
if(!strstr($this->needed_htpasswds[$filename], $row_htpasswds['username'] . ':' . $row_htpasswds['password']))
|
||||
{
|
||||
$this->needed_htpasswds[$filename].= $row_htpasswds['username'] . ':' . $row_htpasswds['password'] . "\n";
|
||||
}
|
||||
|
||||
$needed_htpasswds[] = $row_htpasswds['path'];
|
||||
$htaccess_path = substr($row_htpasswds['path'], strlen($domain['documentroot']) - 1);
|
||||
$htaccess_text.= ' "' . makeCorrectDir($htaccess_path) . '" =>' . "\n";
|
||||
$htaccess_text.= ' (' . "\n";
|
||||
$htaccess_text.= ' "method" => "basic",' . "\n";
|
||||
$htaccess_text.= ' "realm" => "Restricted Area",' . "\n";
|
||||
$htaccess_text.= ' "require" => "user=' . $row_htpasswds[username] . '"' . "\n";
|
||||
$htaccess_text.= ' )' . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
if(strlen(trim($htaccess_text)) > 0)
|
||||
{
|
||||
$htaccess_text.= ' )' . "\n";
|
||||
}
|
||||
|
||||
return $htaccess_text;
|
||||
}
|
||||
|
||||
public function createVirtualHosts()
|
||||
{
|
||||
}
|
||||
|
||||
public function createFileDirOptions()
|
||||
{
|
||||
}
|
||||
|
||||
protected function composePhpOptions($domain)
|
||||
{
|
||||
}
|
||||
|
||||
protected function createLighttpdHosts($ip, $port, $ssl, $vhost_filename)
|
||||
{
|
||||
$query = "SELECT * FROM " . TABLE_PANEL_IPSANDPORTS . " WHERE `ip`='" . $ip . "' AND `port`='" . $port . "'";
|
||||
$ipandport = $this->db->query_first($query);
|
||||
|
||||
if($ssl == '0')
|
||||
{
|
||||
$query2 = "SELECT `d`.`id`, `d`.`domain`, `d`.`customerid`, `d`.`documentroot`, `d`.`ssl`, `d`.`parentdomainid`, `d`.`ipandport`, `d`.`ssl_ipandport`, `d`.`ssl_redirect`, `d`.`isemaildomain`, `d`.`iswildcarddomain`, `d`.`wwwserveralias`, `d`.`openbasedir`, `d`.`openbasedir_path`, `d`.`safemode`, `d`.`speciallogfile`, `d`.`specialsettings`, `pd`.`domain` AS `parentdomain`, `c`.`loginname`, `c`.`guid`, `c`.`email`, `c`.`documentroot` AS `customerroot`, `c`.`deactivated`, `c`.`phpenabled` AS `phpenabled` FROM `" . TABLE_PANEL_DOMAINS . "` `d` LEFT JOIN `" . TABLE_PANEL_CUSTOMERS . "` `c` USING(`customerid`) LEFT JOIN `" . TABLE_PANEL_DOMAINS . "` `pd` ON (`pd`.`id` = `d`.`parentdomainid`) WHERE `d`.`ipandport`='" . $ipandport['id'] . "' ORDER BY `d`.`iswildcarddomain`, `d`.`domain` ASC";
|
||||
}
|
||||
else
|
||||
{
|
||||
$query2 = "SELECT `d`.`id`, `d`.`domain`, `d`.`customerid`, `d`.`documentroot`, `d`.`ssl`, `d`.`parentdomainid`, `d`.`ipandport`, `d`.`ssl_ipandport`, `d`.`ssl_redirect`, `d`.`isemaildomain`, `d`.`iswildcarddomain`, `d`.`wwwserveralias`, `d`.`openbasedir`, `d`.`openbasedir_path`, `d`.`safemode`, `d`.`speciallogfile`, `d`.`specialsettings`, `pd`.`domain` AS `parentdomain`, `c`.`loginname`, `c`.`guid`, `c`.`email`, `c`.`documentroot` AS `customerroot`, `c`.`deactivated`, `c`.`phpenabled` AS `phpenabled` FROM `" . TABLE_PANEL_DOMAINS . "` `d` LEFT JOIN `" . TABLE_PANEL_CUSTOMERS . "` `c` USING(`customerid`) LEFT JOIN `" . TABLE_PANEL_DOMAINS . "` `pd` ON (`pd`.`id` = `d`.`parentdomainid`) WHERE `d`.`ssl_ipandport`='" . $ipandport['id'] . "' ORDER BY `d`.`iswildcarddomain`, `d`.`domain` ASC";
|
||||
}
|
||||
|
||||
$result_domains = $this->db->query($query2);
|
||||
|
||||
while($domain = $this->db->fetch_array($result_domains))
|
||||
{
|
||||
$query = "SELECT * FROM " . TABLE_PANEL_IPSANDPORTS . " WHERE `id`='" . $domain['ipandport'] . "'";
|
||||
$ipandport = $this->db->query_first($query);
|
||||
$domain['ip'] = $ipandport['ip'];
|
||||
$domain['port'] = $ipandport['port'];
|
||||
$domain['ssl_cert_file'] = $ipandport['ssl_cert_file'];
|
||||
|
||||
if(!empty($this->lighttpd_data[$vhost_filename]))
|
||||
{
|
||||
if($ssl == '1')
|
||||
{
|
||||
$ssl_vhost = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ssl_vhost = false;
|
||||
}
|
||||
|
||||
$this->lighttpd_data[$vhost_filename].= $this->getVhostContent($domain, $ssl_vhost);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getVhostContent($domain, $ssl_vhost = false)
|
||||
{
|
||||
if($ssl_vhost === true
|
||||
&& $domain['ssl'] != '1')
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
if($ssl_vhost === true
|
||||
&& $domain['ssl'] == '1')
|
||||
{
|
||||
$query = "SELECT * FROM " . TABLE_PANEL_IPSANDPORTS . " WHERE `id`='" . $domain['ssl_ipandport'] . "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = "SELECT * FROM " . TABLE_PANEL_IPSANDPORTS . " WHERE `id`='" . $domain['ipandport'] . "'";
|
||||
}
|
||||
|
||||
$ipandport = $this->db->query_first($query);
|
||||
$domain['ip'] = $ipandport['ip'];
|
||||
$domain['port'] = $ipandport['port'];
|
||||
$domain['ssl_cert_file'] = $ipandport['ssl_cert_file'];
|
||||
|
||||
if(filter_var($domain['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
|
||||
{
|
||||
$ipport = '[' . $domain['ip'] . ']:' . $domain['port'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$ipport = $domain['ip'] . ':' . $domain['port'];
|
||||
}
|
||||
|
||||
$vhost_content.= $this->getServerNames($domain) . " {\n";
|
||||
$vhost_content.= $this->getWebroot($domain, $ssl_vhost);
|
||||
$vhost_content.= $this->create_htaccess($domain);
|
||||
$vhost_content.= $this->create_pathOptions($domain);
|
||||
$vhost_content.= $this->composePhpOptions($domain);
|
||||
$vhost_content.= $this->getLogFiles($domain);
|
||||
$vhost_content.= '}' . "\n";
|
||||
return $vhost_content;
|
||||
}
|
||||
|
||||
protected function getLogFiles($domain)
|
||||
{
|
||||
$logfiles_text = '';
|
||||
|
||||
if($this->settings['system']['mod_log_sql'] == 1)
|
||||
{
|
||||
// We are using mod_log_sql (http://www.outoforder.cc/projects/apache/mod_log_sql/)
|
||||
// TODO: See how we are able emulate the error_log
|
||||
}
|
||||
else
|
||||
{
|
||||
// The normal access/error - logging is enabled
|
||||
|
||||
$filename = makeCorrectFile($this->settings['system']['logfiles_directory'] . $domain['loginname'] . $speciallogfile . '-error.log');
|
||||
|
||||
if(!is_file($filename))
|
||||
{
|
||||
$ourFileHandle = fopen($filename, 'w') or die("can't open file");
|
||||
fclose($ourFileHandle);
|
||||
}
|
||||
|
||||
chown($filename, $this->settings['system']['httpuser']);
|
||||
chgrp($filename, $this->settings['system']['httpgroup']);
|
||||
|
||||
//access log
|
||||
|
||||
$filename = makeCorrectFile($this->settings['system']['logfiles_directory'] . $domain['loginname'] . $speciallogfile . '-access.log');
|
||||
|
||||
if(!is_file($filename))
|
||||
{
|
||||
$ourFileHandle = fopen($filename, 'w') or die("can't open file");
|
||||
fclose($ourFileHandle);
|
||||
}
|
||||
|
||||
$logfiles_text.= ' accesslog.filename = "' . $filename . '"' . "\n";
|
||||
|
||||
chown($filename, $this->settings['system']['httpuser']);
|
||||
chgrp($filename, $this->settings['system']['httpgroup']);
|
||||
}
|
||||
|
||||
return $logfiles_text;
|
||||
}
|
||||
|
||||
protected function create_pathOptions($domain)
|
||||
{
|
||||
$query = "SELECT * FROM " . TABLE_PANEL_HTACCESS . " WHERE `path` LIKE '" . $domain['documentroot'] . "%'";
|
||||
$result = $this->db->query($query);
|
||||
|
||||
$path_options = '';
|
||||
$error_string = '';
|
||||
|
||||
while($row = $this->db->fetch_array($result))
|
||||
{
|
||||
if(!empty($row['error404path']))
|
||||
{
|
||||
$error_string.= ' server.error-handler-404 = "' . makeCorrectFile($row['documentroot'] . '/' . $row['error404path']) . '"' . "\n";
|
||||
}
|
||||
|
||||
if($row['options_indexes'] != '0')
|
||||
{
|
||||
$path = makeCorrectDir(substr($row['path'], strlen($domain['documentroot']) - 1));
|
||||
|
||||
// We need to remove the last slash, otherwise the regex wouldn't work
|
||||
|
||||
$path = substr($path, 0, -1);
|
||||
$path_options.= '$HTTP["url"] =~ "^' . $path . '($|/)" {' . "\n";
|
||||
$path_options.= "\t" . 'dir-listing.activate = "enable"' . "\n";
|
||||
if(!empty($error_string))
|
||||
{
|
||||
$path_options.= $error_string;
|
||||
// reset $error_string here to prevent duplicate entries
|
||||
$error_string = '';
|
||||
}
|
||||
$path_options.= '}' . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$path_options = $error_string;
|
||||
}
|
||||
}
|
||||
|
||||
return $path_options;
|
||||
}
|
||||
|
||||
protected function getDirOptions($domain)
|
||||
{
|
||||
$query = "SELECT * FROM " . TABLE_PANEL_HTPASSWDS . " WHERE `customerid`='" . $domain[customerid] . "'";
|
||||
$result = $this->db->query($query);
|
||||
|
||||
while($row_htpasswds = $this->db->fetch_array($result))
|
||||
{
|
||||
if($auth_backend_loaded[$domain['ipandport']] != 'yes'
|
||||
&& $auth_backend_loaded[$domain['ssl_ipandport']] != 'yes')
|
||||
{
|
||||
$filename = $domain['customerid'] . '.htpasswd';
|
||||
|
||||
if($this->auth_backend_loaded[$domain['ipandport']] != 'yes')
|
||||
{
|
||||
$auth_backend_loaded[$domain['ipandport']] = 'yes';
|
||||
$diroption_text.= 'auth.backend = "htpasswd"' . "\n";
|
||||
$diroption_text.= 'auth.backend.htpasswd.userfile = "' . makeCorrectFile($this->settings['system']['apacheconf_htpasswddir'] . '/' . $filename) . '"' . "\n";
|
||||
$this->needed_htpasswds[$filename] = $row_htpasswds['username'] . ':' . $row_htpasswds['password'] . "\n";
|
||||
$diroption_text.= 'auth.require = ( ' . "\n";
|
||||
$previous_domain_id = '1';
|
||||
}
|
||||
elseif($this->auth_backend_loaded[$domain['ssl_ipandport']] != 'yes')
|
||||
{
|
||||
$auth_backend_loaded[$domain['ssl_ipandport']] = 'yes';
|
||||
$diroption_text.= 'auth.backend= "htpasswd"' . "\n";
|
||||
$diroption_text.= 'auth.backend.htpasswd.userfile = "' . makeCorrectFile($this->settings['system']['apacheconf_htpasswddir'] . '/' . $filename) . '"' . "\n";
|
||||
$this->needed_htpasswds[$filename] = $row_htpasswds['username'] . ':' . $row_htpasswds['password'] . "\n";
|
||||
$diroption_text.= 'auth.require = ( ' . "\n";
|
||||
$previous_domain_id = '1';
|
||||
}
|
||||
}
|
||||
|
||||
$diroption_text.= '"' . $row_htpasswds['path'] . '" =>' . "\n";
|
||||
$diroption_text.= '(' . "\n";
|
||||
$diroption_text.= ' "method" => "basic",' . "\n";
|
||||
$diroption_text.= ' "realm" => "Restricted Area",' . "\n";
|
||||
$diroption_text.= ' "require" => "user=' . $row_htpasswds['username'] . '"' . "\n";
|
||||
$diroption_text.= ')' . "\n";
|
||||
|
||||
if($this->auth_backend_loaded[$domain['ssl_ipandport']] == 'yes')
|
||||
{
|
||||
$this->needed_htpasswds[$domain['ssl_ipandport']].= $diroption_text;
|
||||
}
|
||||
|
||||
if($this->auth_backend_loaded[$domain['ipandport']] != 'yes')
|
||||
{
|
||||
$this->needed_htpasswds[$domain['ipandport']].= $diroption_text;
|
||||
}
|
||||
}
|
||||
|
||||
return ' auth.backend.htpasswd.userfile = "' . makeCorrectFile($this->settings['system']['apacheconf_htpasswddir'] . '/' . $filename) . '"' . "\n";
|
||||
}
|
||||
|
||||
protected function getServerNames($domain)
|
||||
{
|
||||
$server_string = array();
|
||||
$domain_name = ereg_replace('\.', '\.', $domain['domain']);
|
||||
|
||||
if($domain['iswildcarddomain'] == '1')
|
||||
{
|
||||
$server_string[] = '(^|\.)' . $domain_name . '$';
|
||||
}
|
||||
else
|
||||
{
|
||||
if($domain['wwwserveralias'] == '1')
|
||||
{
|
||||
$server_string[] = '^(www\.|)' . $domain_name . '$';
|
||||
}
|
||||
else
|
||||
{
|
||||
$server_string[] = '^'.$domain_name.'$';
|
||||
}
|
||||
}
|
||||
|
||||
$alias_domains = $this->db->query('SELECT `domain`, `iswildcarddomain`, `wwwserveralias` FROM `' . TABLE_PANEL_DOMAINS . '` WHERE `aliasdomain`=\'' . $domain['id'] . '\'');
|
||||
|
||||
while(($alias_domain = $this->db->fetch_array($alias_domains)) !== false)
|
||||
{
|
||||
$alias_domain_name = ereg_replace('\.', '\.', $alias_domain['domain']);
|
||||
|
||||
if($alias_domain['iswildcarddomain'] == '1')
|
||||
{
|
||||
$server_string[] = '(^|\.)' . $alias_domain_name . '$';
|
||||
}
|
||||
else
|
||||
{
|
||||
if($alias_domain['wwwserveralias'] == '1')
|
||||
{
|
||||
$server_string[] = '^(www\.|)' . $alias_domain_name . '$';
|
||||
}
|
||||
else
|
||||
{
|
||||
$server_string[] = '^'.$alias_domain_name . '$';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0;$i < sizeof($server_string);$i++)
|
||||
{
|
||||
$data = $server_string[$i];
|
||||
|
||||
if(sizeof($server_string) > 1)
|
||||
{
|
||||
if($i == 0)
|
||||
{
|
||||
$servernames_text = '(' . $data . '|';
|
||||
}
|
||||
elseif(sizeof($server_string) - 1 == $i)
|
||||
{
|
||||
$servernames_text.= $data . ')';
|
||||
}
|
||||
else
|
||||
{
|
||||
$servernames_text.= $data . '|';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$servernames_text = $data;
|
||||
}
|
||||
}
|
||||
|
||||
unset($data);
|
||||
|
||||
if($servernames_text != '') {
|
||||
$servernames_text = '$HTTP["host"] =~ "' . $servernames_text . '"';
|
||||
} else {
|
||||
$servernames_text = '$HTTP["host"] == "' . $domain['domain'] . '"';
|
||||
}
|
||||
|
||||
return $servernames_text;
|
||||
}
|
||||
|
||||
protected function getWebroot($domain, $ssl)
|
||||
{
|
||||
$webroot_text = '';
|
||||
|
||||
if($domain['deactivated'] == '1'
|
||||
&& $this->settings['system']['deactivateddocroot'] != '')
|
||||
{
|
||||
$webroot_text.= ' # Using docroot for deactivated users...' . "\n";
|
||||
$webroot_text.= ' server.document-root = "' . $this->settings['system']['deactivateddocroot'] . "\"\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if($ssl === false
|
||||
&& $domain['ssl_redirect'] == '1')
|
||||
{
|
||||
$redirect_domain = $this->idnaConvert->encode('https://' . $domain['domain']);
|
||||
$webroot_text.= ' url.redirect = ('."\n";
|
||||
$webroot_text.= "\t" . '"^/(.*)" => "' . $redirect_domain . '/$1",' . "\n";
|
||||
$webroot_text.= "\t" . '"" => "' . $redirect_domain . '",' . "\n";
|
||||
$webroot_text.= "\t" . '"/" => "' . $redirect_domain . '"' . "\n";
|
||||
$webroot_text.= ' )'."\n";
|
||||
}
|
||||
elseif(preg_match("#^https?://#i", $domain['documentroot']))
|
||||
{
|
||||
$redirect_domain = $this->idnaConvert->encode($domain['documentroot']);
|
||||
$webroot_text.= ' url.redirect = ('."\n";
|
||||
$webroot_text.= "\t" . '"^/(.*)" => "' . $redirect_domain . '/$1",' . "\n";
|
||||
$webroot_text.= "\t" . '"" => "' . $redirect_domain . '",' . "\n";
|
||||
$webroot_text.= "\t" . '"/" => "' . $redirect_domain . '"' . "\n";
|
||||
$webroot_text.= ' )'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$webroot_text.= ' server.document-root = "' . makeCorrectDir($domain['documentroot']) . "\"\n";
|
||||
}
|
||||
}
|
||||
|
||||
return $webroot_text;
|
||||
}
|
||||
|
||||
public function writeConfigs()
|
||||
{
|
||||
fwrite($this->debugHandler, ' lighttpd::writeConfigs: rebuilding ' . $this->settings['system']['apacheconf_vhost'] . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . $this->settings['system']['apacheconf_vhost']);
|
||||
|
||||
if(!isConfigDir($this->settings['system']['apacheconf_vhost']))
|
||||
{
|
||||
// Save one big file
|
||||
|
||||
foreach($this->lighttpd_data as $vhosts_filename => $vhost_content)
|
||||
{
|
||||
$vhosts_file.= $vhost_content . "\n\n";
|
||||
}
|
||||
|
||||
$vhosts_filename = $this->settings['system']['apacheconf_vhost'];
|
||||
|
||||
// Apply header
|
||||
|
||||
$vhosts_file = '# ' . basename($vhosts_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" . $vhosts_file;
|
||||
$vhosts_file_handler = fopen($vhosts_filename, 'w');
|
||||
fwrite($vhosts_file_handler, $vhosts_file);
|
||||
fclose($vhosts_file_handler);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!file_exists($this->settings['system']['apacheconf_vhost']))
|
||||
{
|
||||
fwrite($this->debugHandler, ' lighttpd::writeConfigs: mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost'])) . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost'])));
|
||||
safe_exec('mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost'])));
|
||||
}
|
||||
|
||||
// Write a single file for every vhost
|
||||
|
||||
foreach($this->lighttpd_data as $vhosts_filename => $vhosts_file)
|
||||
{
|
||||
$this->known_filenames[] = basename($vhosts_filename);
|
||||
|
||||
// Apply header
|
||||
|
||||
$vhosts_file = '# ' . basename($vhosts_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" . $vhosts_file;
|
||||
|
||||
if(!empty($vhosts_filename))
|
||||
{
|
||||
$vhosts_file_handler = fopen($vhosts_filename, 'w');
|
||||
fwrite($vhosts_file_handler, $vhosts_file);
|
||||
fclose($vhosts_file_handler);
|
||||
}
|
||||
}
|
||||
|
||||
$this->wipeOutOldConfigs();
|
||||
}
|
||||
|
||||
// Write the diroptions
|
||||
|
||||
if(isConfigDir($this->settings['system']['apacheconf_htpasswddir']))
|
||||
{
|
||||
foreach($this->needed_htpasswds as $key => $data)
|
||||
{
|
||||
if(!is_dir($this->settings['system']['apacheconf_htpasswddir']))
|
||||
{
|
||||
mkdir($this->settings['system']['apacheconf_htpasswddir']);
|
||||
}
|
||||
|
||||
$filename = $this->settings['system']['apacheconf_htpasswddir'] . '/' . $key;
|
||||
$htpasswd_handler = fopen($filename, 'w');
|
||||
fwrite($htpasswd_handler, $data);
|
||||
fclose($htpasswd_handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function wipeOutOldConfigs()
|
||||
{
|
||||
fwrite($this->debugHandler, ' lighttpd::wipeOutOldConfigs: cleaning ' . $this->settings['system']['apacheconf_vhost'] . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, "cleaning " . $this->settings['system']['apacheconf_vhost']);
|
||||
|
||||
if(isConfigDir($this->settings['system']['apacheconf_vhost'])
|
||||
&& file_exists($this->settings['system']['apacheconf_vhost'])
|
||||
&& is_dir($this->settings['system']['apacheconf_vhost']))
|
||||
{
|
||||
$vhost_file_dirhandle = opendir($this->settings['system']['apacheconf_vhost']);
|
||||
|
||||
while(false !== ($vhost_filename = readdir($vhost_file_dirhandle)))
|
||||
{
|
||||
if($vhost_filename != '.'
|
||||
&& $vhost_filename != '..'
|
||||
&& !in_array($vhost_filename, $this->known_filenames)
|
||||
&& preg_match('/^(10|20|30)_froxlor_ipandport_(.+)\.conf$/', $vhost_filename)
|
||||
&& file_exists(makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/' . $vhost_filename)))
|
||||
{
|
||||
fwrite($this->debugHandler, ' lighttpd::wipeOutOldConfigs: unlinking ' . $vhost_filename . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'unlinking ' . $vhost_filename);
|
||||
unlink(makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/' . $vhost_filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
286
scripts/jobs/always/cron_tasks.inc.http.25.lighttpd_fcgid.php
Normal file
286
scripts/jobs/always/cron_tasks.inc.http.25.lighttpd_fcgid.php
Normal file
@@ -0,0 +1,286 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* This script creates the php.ini's used by mod_suPHP+php-cgi
|
||||
*/
|
||||
|
||||
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
|
||||
{
|
||||
private $php_configs_cache = array();
|
||||
private $admin_cache = array();
|
||||
|
||||
protected function composePhpOptions($domain)
|
||||
{
|
||||
$php_options_text = '';
|
||||
|
||||
if($domain['phpenabled'] == '1')
|
||||
{
|
||||
// This vHost has PHP enabled and we are using mod_fcgid
|
||||
//create basic variables for config
|
||||
|
||||
$configdir = makeCorrectDir($this->settings['system']['mod_fcgid_configdir'] . '/' . $domain['loginname'] . '/' . $domain['domain'] . '/');
|
||||
$starter_filename = makeCorrectFile($configdir . '/php-fcgi-starter');
|
||||
$phpini_filename = makeCorrectFile($configdir . '/php.ini');
|
||||
$tmpdir = makeCorrectDir($this->settings['system']['mod_fcgid_tmpdir'] . '/' . $domain['loginname'] . '/');
|
||||
|
||||
// create config dir if necessary
|
||||
|
||||
if(!is_dir($configdir))
|
||||
{
|
||||
safe_exec('mkdir -p ' . escapeshellarg($configdir));
|
||||
safe_exec('chown ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($configdir));
|
||||
}
|
||||
|
||||
// create tmp dir if necessary
|
||||
|
||||
if(!is_dir($tmpdir))
|
||||
{
|
||||
safe_exec('mkdir -p ' . escapeshellarg($tmpdir));
|
||||
safe_exec('chown -R ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($tmpdir));
|
||||
safe_exec('chmod 0750 ' . escapeshellarg($tmpdir));
|
||||
}
|
||||
|
||||
// Load php config
|
||||
|
||||
$phpconfig = $this->getPhpConfig((int)$domain['phpsettingid']);
|
||||
|
||||
$php_options_text = 'fastcgi.server = ( '."\n";
|
||||
$file_extensions = explode(' ', $phpconfig['file_extensions']);
|
||||
foreach($file_extensions as $f_extension)
|
||||
{
|
||||
$php_options_text.= "\t".'".'.$f_extension.'" => ('."\n";
|
||||
$php_options_text.= "\t\t".'"localhost" => ('."\n";
|
||||
$php_options_text.= "\t\t".'"socket" => "/var/run/lighttpd/'.$domain['loginname'].'-'.$domain['domain'].'-php.socket",'."\n";
|
||||
$php_options_text.= "\t\t".'"bin-path" => "'.$phpconfig['binary'].' -c '.$phpini_filename.'",'."\n";
|
||||
$php_options_text.= "\t\t".'"bin-environment" => ('."\n";
|
||||
if((int)$domain['mod_fcgid_starter'] != - 1)
|
||||
{
|
||||
$php_options_text.= "\t\t\t".'"PHP_FCGI_CHILDREN" => "' . (int)$domain['mod_fcgid_starter'] . '",'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if((int)$phpconfig['mod_fcgid_starter'] != - 1)
|
||||
{
|
||||
$php_options_text.= "\t\t\t".'"PHP_FCGI_CHILDREN" => "' . (int)$phpconfig['mod_fcgid_starter'] . '",'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$php_options_text.= "\t\t\t".'"PHP_FCGI_CHILDREN" => "' . (int)$this->settings['system']['mod_fcgid_starter'] . '",'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
if((int)$domain['mod_fcgid_maxrequests'] != - 1)
|
||||
{
|
||||
$php_options_text.= "\t\t\t".'"PHP_FCGI_MAX_REQUESTS" => "' . (int)$domain['mod_fcgid_maxrequests'] . '"'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if((int)$phpconfig['mod_fcgid_maxrequests'] != - 1)
|
||||
{
|
||||
$php_options_text.= "\t\t\t".'"PHP_FCGI_MAX_REQUESTS" => "' . (int)$phpconfig['mod_fcgid_maxrequests'] . '"'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$php_options_text.= "\t\t\t".'"PHP_FCGI_MAX_REQUESTS" => "' . (int)$this->settings['system']['mod_fcgid_maxrequests'] . '"'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
$php_options_text.= "\t\t".')'."\n";
|
||||
$php_options_text.= "\t".')'."\n";
|
||||
$php_options_text.= "".')'."\n";
|
||||
|
||||
} // foreach extension
|
||||
$php_options_text.= "".')'."\n";
|
||||
|
||||
// create starter
|
||||
|
||||
$starter_file = "#!/bin/sh\n\n";
|
||||
$starter_file.= "#\n";
|
||||
$starter_file.= "# starter created/changed on " . date("Y.m.d H:i:s") . " for domain '" . $domain['domain'] . "' with id #" . $domain['id'] . " from php template '" . $phpconfig['description'] . "' with id #" . $phpconfig['id'] . "\n";
|
||||
$starter_file.= "# Do not change anything in this file, it will be overwritten by the Froxlor Cronjob!\n";
|
||||
$starter_file.= "#\n\n";
|
||||
$starter_file.= "PHPRC=" . escapeshellarg($configdir) . "\n";
|
||||
$starter_file.= "export PHPRC\n";
|
||||
|
||||
// set number of processes for one domain
|
||||
|
||||
if((int)$domain['mod_fcgid_starter'] != - 1)
|
||||
{
|
||||
$starter_file.= "PHP_FCGI_CHILDREN=" . (int)$domain['mod_fcgid_starter'] . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if((int)$phpconfig['mod_fcgid_starter'] != - 1)
|
||||
{
|
||||
$starter_file.= "PHP_FCGI_CHILDREN=" . (int)$phpconfig['mod_fcgid_starter'] . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$starter_file.= "PHP_FCGI_CHILDREN=" . (int)$this->settings['system']['mod_fcgid_starter'] . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
$starter_file.= "export PHP_FCGI_CHILDREN\n";
|
||||
|
||||
// set number of maximum requests for one domain
|
||||
|
||||
if((int)$domain['mod_fcgid_maxrequests'] != - 1)
|
||||
{
|
||||
$starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$domain['mod_fcgid_maxrequests'] . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if((int)$phpconfig['mod_fcgid_maxrequests'] != - 1)
|
||||
{
|
||||
$starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$phpconfig['mod_fcgid_maxrequests'] . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$this->settings['system']['mod_fcgid_maxrequests'] . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
$starter_file.= "export PHP_FCGI_MAX_REQUESTS\n";
|
||||
|
||||
// Set Binary
|
||||
|
||||
$starter_file.= "exec " . $phpconfig['binary'] . " -c " . escapeshellarg($configdir) . "\n";
|
||||
|
||||
//remove +i attibute, so starter can be overwritten
|
||||
|
||||
if(file_exists($starter_filename))
|
||||
{
|
||||
safe_exec('chattr -i ' . escapeshellarg($starter_filename));
|
||||
}
|
||||
|
||||
$starter_file_handler = fopen($starter_filename, 'w');
|
||||
fwrite($starter_file_handler, $starter_file);
|
||||
fclose($starter_file_handler);
|
||||
safe_exec('chmod 750 ' . escapeshellarg($starter_filename));
|
||||
safe_exec('chown ' . $domain['guid'] . ':' . $domain['guid'] . ' ' . escapeshellarg($starter_filename));
|
||||
safe_exec('chattr +i ' . escapeshellarg($starter_filename));
|
||||
|
||||
// define the php.ini
|
||||
|
||||
$openbasedir = '';
|
||||
$openbasedirc = ';';
|
||||
|
||||
if($domain['openbasedir'] == '1')
|
||||
{
|
||||
$openbasedirc = '';
|
||||
if($domain['openbasedir_path'] == '0')
|
||||
{
|
||||
$openbasedir = $domain['documentroot'] . ':' . $tmpdir . ':' . $this->settings['system']['mod_fcgid_peardir'] . ':' . $this->settings['system']['phpappendopenbasedir'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$openbasedir = $domain['customerroot'] . ':' . $tmpdir . ':' . $this->settings['system']['mod_fcgid_peardir'] . ':' . $this->settings['system']['phpappendopenbasedir'];
|
||||
}
|
||||
|
||||
$openbasedir = explode(':', $openbasedir);
|
||||
foreach($openbasedir as $number => $path)
|
||||
{
|
||||
$openbasedir[$number] = makeCorrectDir($path);
|
||||
}
|
||||
|
||||
$openbasedir = implode(':', $openbasedir);
|
||||
}
|
||||
else
|
||||
{
|
||||
$openbasedir = 'none';
|
||||
$openbasedirc = ';';
|
||||
}
|
||||
|
||||
$admin = $this->getAdminData($domain['adminid']);
|
||||
$php_ini_variables = array(
|
||||
'SAFE_MODE' => ($domain['safemode'] == '0' ? 'Off' : 'On'),
|
||||
'PEAR_DIR' => $this->settings['system']['mod_fcgid_peardir'],
|
||||
'OPEN_BASEDIR' => $openbasedir,
|
||||
'OPEN_BASEDIR_C' => $openbasedirc,
|
||||
'OPEN_BASEDIR_GLOBAL' => $this->settings['system']['phpappendopenbasedir'],
|
||||
'TMP_DIR' => $tmpdir,
|
||||
'CUSTOMER_EMAIL' => $domain['email'],
|
||||
'ADMIN_EMAIL' => $admin['email'],
|
||||
'DOMAIN' => $domain['domain'],
|
||||
'CUSTOMER' => $domain['loginname'],
|
||||
'ADMIN' => $admin['loginname']
|
||||
);
|
||||
|
||||
//insert a small header for the file
|
||||
|
||||
$phpini_file = ";\n";
|
||||
$phpini_file.= "; php.ini created/changed on " . date("Y.m.d H:i:s") . " for domain '" . $domain['domain'] . "' with id #" . $domain['id'] . " from php template '" . $phpconfig['description'] . "' with id #" . $phpconfig['id'] . "\n";
|
||||
$phpini_file.= "; Do not change anything in this file, it will be overwritten by the Froxlor Cronjob!\n";
|
||||
$phpini_file.= ";\n\n";
|
||||
$phpini_file.= replace_variables($phpconfig['phpsettings'], $php_ini_variables);
|
||||
$phpini_file = str_replace('"none"', 'none', $phpini_file);
|
||||
$phpini_file = preg_replace('/\"+/', '"', $phpini_file);
|
||||
$phpini_file_handler = fopen($phpini_filename, 'w');
|
||||
fwrite($phpini_file_handler, $phpini_file);
|
||||
fclose($phpini_file_handler);
|
||||
safe_exec('chown root:0 ' . escapeshellarg($phpini_filename));
|
||||
safe_exec('chmod 0644 ' . escapeshellarg($phpini_filename));
|
||||
}
|
||||
else
|
||||
{
|
||||
$php_options_text.= ' # PHP is disabled for this vHost' . "\n";
|
||||
}
|
||||
|
||||
return $php_options_text;
|
||||
}
|
||||
|
||||
private function getPhpConfig($php_config_id)
|
||||
{
|
||||
$php_config_id = intval($php_config_id);
|
||||
|
||||
// If domain has no config, we will use the default one.
|
||||
|
||||
if($php_config_id == 0)
|
||||
{
|
||||
$php_config_id = 1;
|
||||
}
|
||||
|
||||
if(!isset($this->php_configs_cache[$php_config_id]))
|
||||
{
|
||||
$this->php_configs_cache[$php_config_id] = $this->getDB()->query_first("SELECT * FROM `" . TABLE_PANEL_PHPCONFIGS . "` WHERE `id` = " . (int)$php_config_id);
|
||||
}
|
||||
|
||||
return $this->php_configs_cache[$php_config_id];
|
||||
}
|
||||
|
||||
private function getAdminData($adminid)
|
||||
{
|
||||
$adminid = intval($adminid);
|
||||
|
||||
if(!isset($this->admin_cache[$adminid]))
|
||||
{
|
||||
$this->admin_cache[$adminid] = $this->getDB()->query_first("SELECT `email`, `loginname` FROM `" . TABLE_PANEL_ADMINS . "` WHERE `adminid` = " . (int)$adminid);
|
||||
}
|
||||
|
||||
return $this->admin_cache[$adminid];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
249
scripts/jobs/always/cron_tasks.php
Normal file
249
scripts/jobs/always/cron_tasks.php
Normal file
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* LOOK INTO TASKS TABLE TO SEE IF THERE ARE ANY UNDONE JOBS
|
||||
*/
|
||||
|
||||
fwrite($debugHandler, ' cron_tasks: Searching for tasks to do' . "\n");
|
||||
$cronlog->logAction(CRON_ACTION, LOG_INFO, "Searching for tasks to do");
|
||||
$result_tasks = $db->query("SELECT `id`, `type`, `data` FROM `" . TABLE_PANEL_TASKS . "` ORDER BY `id` ASC");
|
||||
$resultIDs = array();
|
||||
|
||||
while($row = $db->fetch_array($result_tasks))
|
||||
{
|
||||
$resultIDs[] = $row['id'];
|
||||
|
||||
if($row['data'] != '')
|
||||
{
|
||||
$row['data'] = unserialize($row['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* TYPE=1 MEANS TO REBUILD APACHE VHOSTS.CONF
|
||||
*/
|
||||
|
||||
if($row['type'] == '1')
|
||||
{
|
||||
//dhr: cleanout froxlor-generated awstats configs prior to re-creation
|
||||
if ($settings['system']['awstats_enabled'] == '1')
|
||||
{
|
||||
$awstatsclean['header'] = "## GENERATED BY FROXLOR\n";
|
||||
$awstatsclean['path'] = '/etc/awstats';
|
||||
$awstatsclean['dir'] = dir($awstatsclean['path']);
|
||||
while($awstatsclean['entry'] = $awstatsclean['dir']->read()) {
|
||||
$awstatsclean['fullentry'] = $awstatsclean['path'].'/'.$awstatsclean['entry'];
|
||||
$awstatsclean['fh'] = fopen($awstatsclean['fullentry'], 'r');
|
||||
$awstatsclean['headerRead'] = fgets($awstatsclean['fh'], strlen($awstatsclean['header'])+1);
|
||||
fclose($awstatsclean['fh']);
|
||||
if($awstatsclean['headerRead'] == $awstatsclean['header']) {
|
||||
@unlink($awstatsclean['fullentry']);
|
||||
}
|
||||
}
|
||||
unset($awstatsclean);
|
||||
}
|
||||
//end dhr
|
||||
|
||||
if(!isset($webserver))
|
||||
{
|
||||
if($settings['system']['webserver'] == "apache2")
|
||||
{
|
||||
if($settings['system']['mod_fcgid'] == 1)
|
||||
{
|
||||
$webserver = new apache_fcgid($db, $cronlog, $debugHandler, $idna_convert, $settings);
|
||||
}
|
||||
else
|
||||
{
|
||||
$webserver = new apache($db, $cronlog, $debugHandler, $idna_convert, $settings);
|
||||
}
|
||||
}
|
||||
elseif($settings['system']['webserver'] == "lighttpd")
|
||||
{
|
||||
if($settings['system']['mod_fcgid'] == 1)
|
||||
{
|
||||
$webserver = new lighttpd_fcgid($db, $cronlog, $debugHandler, $idna_convert, $settings);
|
||||
}
|
||||
else
|
||||
{
|
||||
$webserver = new lighttpd($db, $cronlog, $debugHandler, $idna_convert, $settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($webserver))
|
||||
{
|
||||
$webserver->createIpPort();
|
||||
$webserver->createVirtualHosts();
|
||||
$webserver->createFileDirOptions();
|
||||
$webserver->writeConfigs();
|
||||
$webserver->reload();
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Please check you Webserver settings\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TYPE=2 MEANS TO CREATE A NEW HOME AND CHOWN
|
||||
*/
|
||||
elseif ($row['type'] == '2')
|
||||
{
|
||||
fwrite($debugHandler, ' cron_tasks: Task2 started - create new home' . "\n");
|
||||
$cronlog->logAction(CRON_ACTION, LOG_INFO, 'Task2 started - create new home');
|
||||
|
||||
if(is_array($row['data']))
|
||||
{
|
||||
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: mkdir -p ' . escapeshellarg($settings['system']['documentroot_prefix'] . $row['data']['loginname'] . '/webalizer'));
|
||||
safe_exec('mkdir -p ' . escapeshellarg($settings['system']['documentroot_prefix'] . $row['data']['loginname'] . '/webalizer'));
|
||||
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: mkdir -p ' . escapeshellarg($settings['system']['vmail_homedir'] . $row['data']['loginname']));
|
||||
safe_exec('mkdir -p ' . escapeshellarg($settings['system']['vmail_homedir'] . $row['data']['loginname']));
|
||||
|
||||
//check if admin of customer has added template for new customer directories
|
||||
|
||||
$result = $db->query("SELECT `t`.`value`, `c`.`email` AS `customer_email`, `a`.`email` AS `admin_email`, `c`.`loginname` AS `customer_login`, `a`.`loginname` AS `admin_login` FROM `" . TABLE_PANEL_CUSTOMERS . "` AS `c` INNER JOIN `" . TABLE_PANEL_ADMINS . "` AS `a` ON `c`.`adminid` = `a`.`adminid` INNER JOIN `" . TABLE_PANEL_TEMPLATES . "` AS `t` ON `a`.`adminid` = `t`.`adminid` WHERE `varname` = 'index_html' AND `c`.`loginname` = '" . $db->escape($row['data']['loginname']) . "'");
|
||||
|
||||
if($db->num_rows($result) > 0)
|
||||
{
|
||||
$template = $db->fetch_array($result);
|
||||
$replace_arr = array(
|
||||
'SERVERNAME' => $settings['system']['hostname'],
|
||||
'CUSTOMER' => $template['customer_login'],
|
||||
'ADMIN' => $template['admin_login'],
|
||||
'CUSTOMER_EMAIL' => $template['customer_email'],
|
||||
'ADMIN_EMAIL' => $template['admin_email']
|
||||
);
|
||||
$htmlcontent = replace_variables($template['value'], $replace_arr);
|
||||
$indexhtmlpath = $settings['system']['documentroot_prefix'] . $row['data']['loginname'] . '/index.' . $settings['system']['index_file_extension'];
|
||||
$index_html_handler = fopen($indexhtmlpath, 'w');
|
||||
fwrite($index_html_handler, $htmlcontent);
|
||||
fclose($index_html_handler);
|
||||
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Creating \'index.' . $settings['system']['index_file_extension'] . '\' for Customer \'' . $template['customer_login'] . '\' based on template in directory ' . escapeshellarg($indexhtmlpath));
|
||||
}
|
||||
else
|
||||
{
|
||||
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: cp -a ' . $pathtophpfiles . '/templates/misc/standardcustomer/* ' . escapeshellarg($settings['system']['documentroot_prefix'] . $row['data']['loginname'] . '/'));
|
||||
safe_exec('cp -a ' . $pathtophpfiles . '/templates/misc/standardcustomer/* ' . escapeshellarg($settings['system']['documentroot_prefix'] . $row['data']['loginname'] . '/'));
|
||||
}
|
||||
|
||||
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: chown -R ' . (int)$row['data']['uid'] . ':' . (int)$row['data']['gid'] . ' ' . escapeshellarg($settings['system']['documentroot_prefix'] . $row['data']['loginname']));
|
||||
safe_exec('chown -R ' . (int)$row['data']['uid'] . ':' . (int)$row['data']['gid'] . ' ' . escapeshellarg($settings['system']['documentroot_prefix'] . $row['data']['loginname']));
|
||||
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: chown -R ' . (int)$settings['system']['vmail_uid'] . ':' . (int)$settings['system']['vmail_gid'] . ' ' . escapeshellarg($settings['system']['vmail_homedir'] . $row['data']['loginname']));
|
||||
safe_exec('chown -R ' . (int)$settings['system']['vmail_uid'] . ':' . (int)$settings['system']['vmail_gid'] . ' ' . escapeshellarg($settings['system']['vmail_homedir'] . $row['data']['loginname']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TYPE=3 MEANS TO DO NOTHING
|
||||
*/
|
||||
elseif ($row['type'] == '3')
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* TYPE=4 MEANS THAT SOMETHING IN THE BIND CONFIG HAS CHANGED. REBUILD syscp_bind.conf
|
||||
*/
|
||||
elseif ($row['type'] == '4')
|
||||
{
|
||||
if(!isset($nameserver))
|
||||
{
|
||||
$nameserver = new bind($db, $cronlog, $debugHandler, $settings);
|
||||
}
|
||||
|
||||
if($settings['dkim']['use_dkim'] == '1')
|
||||
{
|
||||
$nameserver->writeDKIMconfigs();
|
||||
}
|
||||
|
||||
$nameserver->writeConfigs();
|
||||
}
|
||||
|
||||
/**
|
||||
* TYPE=5 MEANS THAT A NEW FTP-ACCOUNT HAS BEEN CREATED, CREATE THE DIRECTORY
|
||||
*/
|
||||
elseif ($row['type'] == '5')
|
||||
{
|
||||
$cronlog->logAction(CRON_ACTION, LOG_INFO, 'Creating new FTP-home');
|
||||
$result_directories = $db->query('SELECT `f`.`homedir`, `f`.`uid`, `f`.`gid`, `c`.`documentroot` AS `customerroot` FROM `' . TABLE_FTP_USERS . '` `f` LEFT JOIN `' . TABLE_PANEL_CUSTOMERS . '` `c` USING (`customerid`) ');
|
||||
|
||||
while($directory = $db->fetch_array($result_directories))
|
||||
{
|
||||
mkDirWithCorrectOwnership($directory['customerroot'], $directory['homedir'], $directory['uid'], $directory['gid']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TYPE=6 MEANS THAT A CUSTOMER HAS BEEN DELETED AND THAT WE HAVE TO REMOVE ITS FILES
|
||||
*/
|
||||
elseif ($row['type'] == '6')
|
||||
{
|
||||
fwrite($debugHandler, ' cron_tasks: Task6 started - deleting customer data' . "\n");
|
||||
$cronlog->logAction(CRON_ACTION, LOG_INFO, 'Task6 started - deleting customer data');
|
||||
|
||||
if(is_array($row['data']))
|
||||
{
|
||||
if(isset($row['data']['loginname']))
|
||||
{
|
||||
/*
|
||||
* remove homedir
|
||||
*/
|
||||
$homedir = makeCorrectDir($settings['system']['documentroot_prefix'] . $row['data']['loginname']);
|
||||
|
||||
if($homedir != '/'
|
||||
&& $homedir != $settings['system']['documentroot_prefix']
|
||||
&& substr($homedirdir, 0, strlen($settings['system']['documentroot_prefix'])) == $settings['system']['documentroot_prefix'])
|
||||
{
|
||||
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: rm -rf ' . escapeshellarg($homedir));
|
||||
safe_exec('rm -rf '.escapeshellarg($homedir));
|
||||
}
|
||||
|
||||
/*
|
||||
* remove maildir
|
||||
*/
|
||||
$maildir = makeCorrectDir($settings['system']['vmail_homedir'] . $row['data']['loginname']);
|
||||
|
||||
if($maildir != '/'
|
||||
&& $maildir != $settings['system']['vmail_homedir']
|
||||
&& substr($maildir, 0, strlen($settings['system']['vmail_homedir'])) == $settings['system']['vmail_homedir'])
|
||||
{
|
||||
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: rm -rf ' . escapeshellarg($maildir));
|
||||
safe_exec('rm -rf '.escapeshellarg($maildir));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($db->num_rows($result_tasks) != 0)
|
||||
{
|
||||
$where = array();
|
||||
foreach($resultIDs as $id)
|
||||
{
|
||||
$where[] = '`id`=\'' . (int)$id . '\'';
|
||||
}
|
||||
|
||||
$where = implode($where, ' OR ');
|
||||
$db->query('DELETE FROM `' . TABLE_PANEL_TASKS . '` WHERE ' . $where);
|
||||
unset($resultIDs);
|
||||
unset($where);
|
||||
}
|
||||
|
||||
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . '` SET `value` = UNIX_TIMESTAMP() WHERE `settinggroup` = \'system\' AND `varname` = \'last_tasks_run\' ');
|
||||
|
||||
?>
|
||||
232
scripts/jobs/daily/cron_traffic.inc.functions.php
Normal file
232
scripts/jobs/daily/cron_traffic.inc.functions.php
Normal file
@@ -0,0 +1,232 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Function which make webalizer statistics and returns used traffic since last run
|
||||
*
|
||||
* @param string Name of logfile
|
||||
* @param string Place where stats should be build
|
||||
* @param string Caption for webalizer output
|
||||
* @return int Used traffic
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
*/
|
||||
|
||||
function callWebalizerGetTraffic($logfile, $outputdir, $caption, $usersdomainlist)
|
||||
{
|
||||
global $settings;
|
||||
$returnval = 0;
|
||||
|
||||
if(file_exists($settings['system']['logfiles_directory'] . $logfile . '-access.log'))
|
||||
{
|
||||
$domainargs = '';
|
||||
foreach($usersdomainlist as $domainid => $domain)
|
||||
{
|
||||
$domainargs.= ' -r ' . escapeshellarg($domain);
|
||||
}
|
||||
|
||||
$outputdir = makeCorrectDir($outputdir);
|
||||
|
||||
if(!file_exists($outputdir))
|
||||
{
|
||||
safe_exec('mkdir -p ' . escapeshellarg($outputdir));
|
||||
}
|
||||
|
||||
if(file_exists($outputdir . 'webalizer.hist.1'))
|
||||
{
|
||||
unlink($outputdir . 'webalizer.hist.1');
|
||||
}
|
||||
|
||||
if(file_exists($outputdir . 'webalizer.hist')
|
||||
&& !file_exists($outputdir . 'webalizer.hist.1'))
|
||||
{
|
||||
safe_exec('cp ' . escapeshellarg($outputdir . 'webalizer.hist') . ' ' . escapeshellarg($outputdir . 'webalizer.hist.1'));
|
||||
}
|
||||
|
||||
$verbosity = '';
|
||||
|
||||
if($settings['system']['webalizer_quiet'] == '1')
|
||||
{
|
||||
$verbosity = '-q';
|
||||
}
|
||||
elseif($settings['system']['webalizer_quiet'] == '2')
|
||||
{
|
||||
$verbosity = '-Q';
|
||||
}
|
||||
|
||||
safe_exec('webalizer ' . $verbosity . ' -p -o ' . escapeshellarg($outputdir) . ' -n ' . escapeshellarg($caption) . $domainargs . ' ' . escapeshellarg($settings['system']['logfiles_directory'] . $logfile . '-access.log'));
|
||||
|
||||
/**
|
||||
* Format of webalizer.hist-files:
|
||||
* Month: $webalizer_hist_row['0']
|
||||
* Year: $webalizer_hist_row['1']
|
||||
* KB: $webalizer_hist_row['5']
|
||||
*/
|
||||
|
||||
$httptraffic = array();
|
||||
$webalizer_hist = @file_get_contents($outputdir . 'webalizer.hist');
|
||||
$webalizer_hist_rows = explode("\n", $webalizer_hist);
|
||||
foreach($webalizer_hist_rows as $webalizer_hist_row)
|
||||
{
|
||||
if($webalizer_hist_row != '')
|
||||
{
|
||||
$webalizer_hist_row = explode(' ', $webalizer_hist_row);
|
||||
|
||||
if(isset($webalizer_hist_row['0'])
|
||||
&& isset($webalizer_hist_row['1'])
|
||||
&& isset($webalizer_hist_row['5']))
|
||||
{
|
||||
$month = intval($webalizer_hist_row['0']);
|
||||
$year = intval($webalizer_hist_row['1']);
|
||||
$traffic = floatval($webalizer_hist_row['5']);
|
||||
|
||||
if(!isset($httptraffic[$year]))
|
||||
{
|
||||
$httptraffic[$year] = array();
|
||||
}
|
||||
|
||||
$httptraffic[$year][$month] = $traffic;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reset($httptraffic);
|
||||
$httptrafficlast = array();
|
||||
$webalizer_lasthist = @file_get_contents($outputdir . 'webalizer.hist.1');
|
||||
$webalizer_lasthist_rows = explode("\n", $webalizer_lasthist);
|
||||
foreach($webalizer_lasthist_rows as $webalizer_lasthist_row)
|
||||
{
|
||||
if($webalizer_lasthist_row != '')
|
||||
{
|
||||
$webalizer_lasthist_row = explode(' ', $webalizer_lasthist_row);
|
||||
|
||||
if(isset($webalizer_lasthist_row['0'])
|
||||
&& isset($webalizer_lasthist_row['1'])
|
||||
&& isset($webalizer_lasthist_row['5']))
|
||||
{
|
||||
$month = intval($webalizer_lasthist_row['0']);
|
||||
$year = intval($webalizer_lasthist_row['1']);
|
||||
$traffic = floatval($webalizer_lasthist_row['5']);
|
||||
|
||||
if(!isset($httptrafficlast[$year]))
|
||||
{
|
||||
$httptrafficlast[$year] = array();
|
||||
}
|
||||
|
||||
$httptrafficlast[$year][$month] = $traffic;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reset($httptrafficlast);
|
||||
foreach($httptraffic as $year => $months)
|
||||
{
|
||||
foreach($months as $month => $traffic)
|
||||
{
|
||||
if(!isset($httptrafficlast[$year][$month]))
|
||||
{
|
||||
$returnval+= $traffic;
|
||||
}
|
||||
elseif($httptrafficlast[$year][$month] < $httptraffic[$year][$month])
|
||||
{
|
||||
$returnval+= ($httptraffic[$year][$month] - $httptrafficlast[$year][$month]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return floatval($returnval);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function saves the logfile written by mod_log_sql
|
||||
* into a logfile webalizer can parse
|
||||
*
|
||||
* @param string $domain The "speciallogfile" - domain(s)
|
||||
* @param string $loginname The loginname of the customer
|
||||
* @return bool
|
||||
*
|
||||
* @author Florian Aders <eleras@syscp.org>
|
||||
*/
|
||||
|
||||
function safeSQLLogfile($domains, $loginname)
|
||||
{
|
||||
global $db, $settings;
|
||||
$sql = "SELECT * FROM access_log ";
|
||||
$where = "WHERE virtual_host = ";
|
||||
|
||||
if(!is_array($domains))
|
||||
{
|
||||
// If it isn't an array, it's a speciallogfile-domain
|
||||
|
||||
$logname = $settings['system']['logfiles_directory'] . $loginname . '-' . $domains . '-access.log';
|
||||
$where.= "'$domains' OR virtual_host = 'www.$domains'";
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we have an array, these are all domains aggregated into a single logfile
|
||||
|
||||
if(count($domains) == 0)
|
||||
{
|
||||
// If the $omains-array is empty, this customer has only speciallogfile-
|
||||
// domains, so just return, all logfiles are already written to disk
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$logname = $settings['system']['logfiles_directory'] . $loginname . '-access.log';
|
||||
|
||||
// Build the "WHERE" - part of the sql-query
|
||||
|
||||
foreach($domains as $domain)
|
||||
{
|
||||
// A domain may be reached with or without the "www" in front.
|
||||
|
||||
$where.= "'$domain' OR virtual_host = 'www.$domain' OR virtual_host = ";
|
||||
}
|
||||
|
||||
$where = substr($where, 0, -19);
|
||||
}
|
||||
|
||||
// We want clean, ordered logfiles
|
||||
|
||||
$sql.= $where . " ORDER BY time_stamp;";
|
||||
$logs = $db->query($sql);
|
||||
|
||||
// Don't overwrite the logfile - append the new stuff
|
||||
|
||||
file_put_contents($logname, "", FILE_APPEND);
|
||||
|
||||
while($logline = $db->fetch_array($logs))
|
||||
{
|
||||
// Create a "CustomLog" - line
|
||||
|
||||
$writelog = $logline['remote_host'] . " " . $logline['virtual_host'] . " " . $logline['remote_user'] . " ";
|
||||
$writelog.= date("[d/M/Y:H:i:s O]", $logline['time_stamp']);
|
||||
$writelog.= " \"" . $logline['request_method'] . " " . $logline['request_uri'] . " " . $logline['request_protocol'] . "\" ";
|
||||
$writelog.= $logline['status'];
|
||||
$writelog.= " " . $logline['bytes_sent'] . " \"" . $logline['referer'] . "\" \"" . $logline['agent'] . "\"\n";
|
||||
file_put_contents($logname, $writelog, FILE_APPEND);
|
||||
}
|
||||
|
||||
// Remove the just written stuff
|
||||
|
||||
$db->query("DELETE FROM access_log " . $where);
|
||||
return true;
|
||||
}
|
||||
|
||||
380
scripts/jobs/daily/cron_traffic.php
Normal file
380
scripts/jobs/daily/cron_traffic.php
Normal file
@@ -0,0 +1,380 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
openRootDB($debugHandler, $lockfile);
|
||||
|
||||
/**
|
||||
* 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 . "` ;");
|
||||
|
||||
while($row_domainlist = $db->fetch_array($result_domainlist))
|
||||
{
|
||||
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']]))
|
||||
{
|
||||
$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'], '');
|
||||
unset($db_root->password);
|
||||
$last_dbserver = 0;
|
||||
|
||||
$databases_list = array();
|
||||
$databases_list_result = $db_root->query("show databases");
|
||||
while($databases_list_row = $db->fetch_array($databases_list_result))
|
||||
{
|
||||
$databases_list[] = strtolower($databases_list_row['Database']);
|
||||
}
|
||||
|
||||
while($row_database = $db->fetch_array($databases))
|
||||
{
|
||||
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'], '');
|
||||
unset($db_root->password);
|
||||
$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[] = strtolower($databases_list_row['Database']);
|
||||
}
|
||||
}
|
||||
|
||||
if(in_array(strtolower($row_database['databasename']), $databases_list))
|
||||
{
|
||||
$mysql_usage_result = $db_root->query("SHOW TABLE STATUS FROM `" . $db_root->escape($row_database['databasename']) . "`");
|
||||
|
||||
while($mysql_usage_row = $db_root->fetch_array($mysql_usage_result))
|
||||
{
|
||||
if(!isset($mysqlusage_all[$row_database['customerid']]))
|
||||
{
|
||||
$mysqlusage_all[$row_database['customerid']] = 0;
|
||||
}
|
||||
$mysqlusage_all[$row_database['customerid']] += floatval($mysql_usage_row['Data_length'] + $mysql_usage_row['Index_length']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Seems like the database " . $row_database['databasename'] . " had been removed manually.\n";
|
||||
}
|
||||
}
|
||||
|
||||
$db_root->close();
|
||||
|
||||
|
||||
$result = $db->query("SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "` ORDER BY `customerid` ASC");
|
||||
|
||||
while($row = $db->fetch_array($result))
|
||||
{
|
||||
/**
|
||||
* HTTP-Traffic
|
||||
*/
|
||||
|
||||
fwrite($debugHandler, 'http traffic for ' . $row['loginname'] . ' started...' . "\n");
|
||||
$httptraffic = 0;
|
||||
|
||||
if(isset($domainlist[$row['customerid']])
|
||||
&& is_array($domainlist[$row['customerid']])
|
||||
&& count($domainlist[$row['customerid']]) != 0)
|
||||
{
|
||||
// Examining which caption to use for default webalizer stats...
|
||||
|
||||
if($row['standardsubdomain'] != '0')
|
||||
{
|
||||
// ... of course we'd prefer to use the standardsubdomain ...
|
||||
|
||||
$caption = $domainlist[$row['customerid']][$row['standardsubdomain']];
|
||||
}
|
||||
else
|
||||
{
|
||||
// ... but if there is no standardsubdomain, we have to use the loginname ...
|
||||
|
||||
$caption = $row['loginname'];
|
||||
|
||||
// ... which results in non-usable links to files in the stats, so lets have a look if we find a domain which is not speciallogfiledomain
|
||||
|
||||
foreach($domainlist[$row['customerid']] as $domainid => $domain)
|
||||
{
|
||||
if(!isset($speciallogfile_domainlist[$row['customerid']])
|
||||
|| !isset($speciallogfile_domainlist[$row['customerid']][$domainid]))
|
||||
{
|
||||
$caption = $domain;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$httptraffic = 0;
|
||||
reset($domainlist[$row['customerid']]);
|
||||
|
||||
if(isset($speciallogfile_domainlist[$row['customerid']])
|
||||
&& is_array($speciallogfile_domainlist[$row['customerid']])
|
||||
&& count($speciallogfile_domainlist[$row['customerid']]) != 0)
|
||||
{
|
||||
reset($speciallogfile_domainlist[$row['customerid']]);
|
||||
foreach($speciallogfile_domainlist[$row['customerid']] as $domainid => $domain)
|
||||
{
|
||||
if($settings['system']['mod_log_sql'] == 1)
|
||||
{
|
||||
safeSQLLogfile($domain, $row['loginname']);
|
||||
|
||||
// Remove this domain from the domainlist - it's already analysed
|
||||
// and doesn't need to be selected twice
|
||||
|
||||
unset($domainlist[$row['customerid']][$domainid]);
|
||||
}
|
||||
|
||||
$httptraffic+= floatval(callWebalizerGetTraffic($row['loginname'] . '-' . $domain, $row['documentroot'] . '/webalizer/' . $domain . '/', $domain, $domainlist[$row['customerid']]));
|
||||
}
|
||||
}
|
||||
|
||||
reset($domainlist[$row['customerid']]);
|
||||
|
||||
if($settings['system']['mod_log_sql'] == 1)
|
||||
{
|
||||
safeSQLLogfile($domainlist[$row['customerid']], $row['loginname']);
|
||||
}
|
||||
|
||||
$httptraffic+= floatval(callWebalizerGetTraffic($row['loginname'], $row['documentroot'] . '/webalizer/', $caption, $domainlist[$row['customerid']]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Webalizer 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);
|
||||
unset($db->password);
|
||||
$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'] . "'");
|
||||
|
||||
if(!is_array($ftptraffic))
|
||||
{
|
||||
$ftptraffic = array(
|
||||
'up_bytes_sum' => 0,
|
||||
'down_bytes_sum' => 0
|
||||
);
|
||||
}
|
||||
|
||||
$db->query("UPDATE `" . TABLE_FTP_USERS . "` SET `up_bytes`='0', `down_bytes`='0' WHERE `customerid`='" . (int)$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);
|
||||
$current_traffic['ftp_up'] = floatval(($ftptraffic['up_bytes_sum'] / 1024));
|
||||
$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'] . "'");
|
||||
$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']]))
|
||||
{
|
||||
$admin_traffic[$row['adminid']]['http'] = 0;
|
||||
$admin_traffic[$row['adminid']]['ftp_up'] = 0;
|
||||
$admin_traffic[$row['adminid']]['ftp_down'] = 0;
|
||||
$admin_traffic[$row['adminid']]['mail'] = 0;
|
||||
$admin_traffic[$row['adminid']]['all'] = 0;
|
||||
$admin_traffic[$row['adminid']]['sum_month'] = 0;
|
||||
}
|
||||
|
||||
$admin_traffic[$row['adminid']]['http']+= $current_traffic['http'];
|
||||
$admin_traffic[$row['adminid']]['ftp_up']+= $current_traffic['ftp_up'];
|
||||
$admin_traffic[$row['adminid']]['ftp_down']+= $current_traffic['ftp_down'];
|
||||
$admin_traffic[$row['adminid']]['mail']+= $current_traffic['mail'];
|
||||
$admin_traffic[$row['adminid']]['all']+= $current_traffic['all'];
|
||||
$admin_traffic[$row['adminid']]['sum_month']+= $sum_month_traffic['all'];
|
||||
|
||||
/**
|
||||
* WebSpace-Usage
|
||||
*/
|
||||
|
||||
fwrite($debugHandler, 'calculating webspace usage for ' . $row['loginname'] . "\n");
|
||||
$webspaceusage = 0;
|
||||
|
||||
if(file_exists($row['documentroot']) && is_dir($row['documentroot']))
|
||||
{
|
||||
$back = safe_exec('du -s ' . escapeshellarg($row['documentroot']) . '');
|
||||
foreach($back as $backrow)
|
||||
{
|
||||
$webspaceusage = explode(' ', $backrow);
|
||||
}
|
||||
|
||||
$webspaceusage = floatval($webspaceusage['0']);
|
||||
unset($back);
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($debugHandler, 'documentroot ' . $row['documentroot'] . ' does not exist' . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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))
|
||||
{
|
||||
$back = safe_exec('du -s ' . escapeshellarg($maildir) . '');
|
||||
foreach($back as $backrow)
|
||||
{
|
||||
$emailusage = explode(' ', $backrow);
|
||||
}
|
||||
|
||||
$emailusage = floatval($emailusage['0']);
|
||||
unset($back);
|
||||
}
|
||||
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']]))
|
||||
{
|
||||
$mysqlusage = floatval($mysqlusage_all[$row['customerid']] / 1024);
|
||||
}
|
||||
|
||||
$current_diskspace = array();
|
||||
$current_diskspace['webspace'] = floatval($webspaceusage);
|
||||
$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']]))
|
||||
{
|
||||
$admin_diskspace[$row['adminid']] = array();
|
||||
$admin_diskspace[$row['adminid']]['webspace'] = 0;
|
||||
$admin_diskspace[$row['adminid']]['mail'] = 0;
|
||||
$admin_diskspace[$row['adminid']]['mysql'] = 0;
|
||||
$admin_diskspace[$row['adminid']]['all'] = 0;
|
||||
}
|
||||
|
||||
$admin_diskspace[$row['adminid']]['webspace']+= $current_diskspace['webspace'];
|
||||
$admin_diskspace[$row['adminid']]['mail']+= $current_diskspace['mail'];
|
||||
$admin_diskspace[$row['adminid']]['mysql']+= $current_diskspace['mysql'];
|
||||
$admin_diskspace[$row['adminid']]['all']+= $current_diskspace['all'];
|
||||
|
||||
/**
|
||||
* Total Usage
|
||||
*/
|
||||
|
||||
$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'] . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin Usage
|
||||
*/
|
||||
|
||||
$result = $db->query("SELECT `adminid` FROM `" . TABLE_PANEL_ADMINS . "` ORDER BY `adminid` ASC");
|
||||
|
||||
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_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'] . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . '` SET `value` = UNIX_TIMESTAMP() WHERE `settinggroup` = \'system\' AND `varname` = \'last_traffic_run\' ');
|
||||
|
||||
closeRootDB();
|
||||
|
||||
?>
|
||||
37
scripts/jobs/daily/cron_used_tickets_reset.php
Normal file
37
scripts/jobs/daily/cron_used_tickets_reset.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* RESET USED TICKETS COUNTER
|
||||
*/
|
||||
|
||||
fwrite($debugHandler, 'Used tickets reset run started...' . "\n");
|
||||
$now = time();
|
||||
$cycle = $settings['ticket']['reset_cycle'];
|
||||
|
||||
if($cycle == '0'
|
||||
|| ($cycle == '1' && (date("j", $now) == '1' || date("j", $now) == '7' || date("j", $now) == '14' || date("j", $now) == '21'))
|
||||
|| ($cycle == '2' && date("j", $now) == '1')
|
||||
|| ($cycle == '3' && date("dm", $now) == '0101'))
|
||||
{
|
||||
fwrite($debugHandler, 'Resetting customers used ticket counter' . "\n");
|
||||
$db->query("UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `tickets_used` = '0'");
|
||||
}
|
||||
|
||||
?>
|
||||
23
scripts/jobs/hourly/cron_apsupdater.php
Normal file
23
scripts/jobs/hourly/cron_apsupdater.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
$Aps = new ApsUpdater($db);
|
||||
$Aps->UpdateHandler();
|
||||
|
||||
?>
|
||||
51
scripts/jobs/monthly/cron_ticketarchive.php
Normal file
51
scripts/jobs/monthly/cron_ticketarchive.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* ARCHIVING CLOSED TICKETS
|
||||
*/
|
||||
|
||||
fwrite($debugHandler, 'Ticket-archiving run started...' . "\n");
|
||||
$result_tickets = $db->query("SELECT `id`, `lastchange`, `subject` FROM `" . TABLE_PANEL_TICKETS . "`
|
||||
WHERE `status` = '3' AND `answerto` = '0';");
|
||||
$archiving_count = 0;
|
||||
|
||||
while($row_ticket = $db->fetch_array($result_tickets))
|
||||
{
|
||||
$lastchange = $row_ticket['lastchange'];
|
||||
$now = time();
|
||||
$days = (int)(($now - $lastchange) / 86400);
|
||||
|
||||
if($days >= $settings['ticket']['archiving_days'])
|
||||
{
|
||||
fwrite($debugHandler, 'archiving ticket "' . $row_ticket['subject'] . '" (ID #' . $row_ticket['id'] . ')' . "\n");
|
||||
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$row_ticket['id']);
|
||||
$mainticket->Set('lastchange', $now, true, true);
|
||||
$mainticket->Set('lastreplier', '1', true, true);
|
||||
$mainticket->Set('status', '3', true, true);
|
||||
$mainticket->Update();
|
||||
$mainticket->Archive();
|
||||
$archiving_count++;
|
||||
}
|
||||
}
|
||||
|
||||
fwrite($debugHandler, 'Archived ' . $archiving_count . ' tickets' . "\n");
|
||||
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . '` SET `value` = UNIX_TIMESTAMP() WHERE `settinggroup` = \'system\' AND `varname` = \'last_archive_run\' ');
|
||||
|
||||
?>
|
||||
220
scripts/jobs/monthly/cron_traffic_report.php
Normal file
220
scripts/jobs/monthly/cron_traffic_report.php
Normal file
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
fwrite($debugHandler, 'Trafficreport run started...' . "\n");
|
||||
$yesterday = time() - (60 * 60 * 24);
|
||||
|
||||
/**
|
||||
* Initialize the mailingsystem
|
||||
*/
|
||||
|
||||
require (dirname(__FILE__) . '/../lib/class.phpmailer.php');
|
||||
$mail = new PHPMailer();
|
||||
$mail->From = $settings['panel']['adminmail'];
|
||||
|
||||
// Warn the customers at 90% traffic-usage
|
||||
|
||||
$result = $db->query("SELECT `c`.`customerid`, `c`.`adminid`, `c`.`name`, `c`.`firstname`, `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` = '0'");
|
||||
|
||||
while($row = $db->fetch_array($result))
|
||||
{
|
||||
if(isset($row['traffic'])
|
||||
&& $row['traffic'] > 0
|
||||
&& $row['traffic_used'] != NULL
|
||||
&& (($row['traffic_used'] * 100) / $row['traffic']) >= 90)
|
||||
{
|
||||
$replace_arr = array(
|
||||
'NAME' => $row['name'],
|
||||
'TRAFFIC' => $row['traffic'],
|
||||
'TRAFFICUSED' => $row['traffic_used']
|
||||
);
|
||||
$lngfile = $db->query_first("SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "`
|
||||
WHERE `language` ='" . $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'] . "'");
|
||||
$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'] . "'
|
||||
AND `language`='" . $db->escape($row['def_language']) . "'
|
||||
AND `templategroup`='mails'
|
||||
AND `varname`='trafficninetypercent_subject'");
|
||||
$mail_subject = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['trafficninetypercent']['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`='trafficninetypercent_mailbody'");
|
||||
$mail_body = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['trafficninetypercent']['mailbody']), $replace_arr));
|
||||
$mail->From = $row['adminmail'];
|
||||
$mail->FromName = $row['adminname'];
|
||||
$mail->Subject = $mail_subject;
|
||||
$mail->Body = $mail_body;
|
||||
$mail->AddAddress($row['email'], $row['firstname'] . ' ' . $row['name']);
|
||||
|
||||
if(!$mail->Send())
|
||||
{
|
||||
$cronlog->logAction(CRON_ACTION, LOG_ERR, "Error sending mail: " . $mail->ErrorInfo);
|
||||
standard_error('errorsendingmail', $row["email"]);
|
||||
}
|
||||
|
||||
$mail->ClearAddresses();
|
||||
$db->query('UPDATE `' . TABLE_PANEL_CUSTOMERS . '` SET `reportsent`=\'1\'
|
||||
WHERE `customerid`=\'' . (int)$row['customerid'] . '\'');
|
||||
}
|
||||
}
|
||||
|
||||
// Warn the admins at 90% traffic-usage
|
||||
|
||||
$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'");
|
||||
|
||||
while($row = $db->fetch_array($result))
|
||||
{
|
||||
if(isset($row['traffic'])
|
||||
&& $row['traffic'] > 0
|
||||
&& (($row['traffic_used_total'] * 100) / $row['traffic']) >= 90)
|
||||
{
|
||||
$replace_arr = array(
|
||||
'NAME' => $row['name'],
|
||||
'TRAFFIC' => $row['traffic'],
|
||||
'TRAFFICUSED' => $row['traffic_used_total']
|
||||
);
|
||||
$lngfile = $db->query_first("SELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "`
|
||||
WHERE `language` ='" . $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'] . "'");
|
||||
$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'] . "'
|
||||
AND `language`='" . $db->escape($row['def_language']) . "'
|
||||
AND `templategroup`='mails'
|
||||
AND `varname`='trafficninetypercent_subject'");
|
||||
$mail_subject = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['trafficninetypercent']['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`='trafficninetypercent_mailbody'");
|
||||
$mail_body = html_entity_decode(replace_variables((($result2['value'] != '') ? $result2['value'] : $lng['mails']['trafficninetypercent']['mailbody']), $replace_arr));
|
||||
$mail->From = $row['email'];
|
||||
$mail->FromName = $row['firstname'] . " " . $row['name'];
|
||||
$mail->Subject = $mail_subject;
|
||||
$mail->Body = $mail_body;
|
||||
$mail->AddAddress($row['email'], $row['name']);
|
||||
|
||||
if(!$mail->Send())
|
||||
{
|
||||
$cronlog->logAction(CRON_ACTION, LOG_ERR, "Error sending mail: " . $mail->ErrorInfo);
|
||||
standard_error('errorsendingmail', $row["email"]);
|
||||
}
|
||||
|
||||
$mail->ClearAddresses();
|
||||
$db->query("UPDATE `" . TABLE_PANEL_ADMINS . "` SET `reportsent`='1'
|
||||
WHERE `customerid`='" . (int)$row['adminid'] . "'");
|
||||
}
|
||||
|
||||
// Another month, let's build our report
|
||||
|
||||
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'] . "'");
|
||||
|
||||
while($customer = $db->fetch_array($customers))
|
||||
{
|
||||
$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";
|
||||
}
|
||||
|
||||
$mail_body.= '---------------------------------------------' . "\n";
|
||||
$mail_body.= sprintf('%-15s', $row['loginname']) . ' ' . sprintf('%-12d', $row['traffic_used_total']) . ' (' . sprintf('%00.3f%%', (($row['traffic_used_total'] * 100) / $row['traffic'])) . ') ' . $row['traffic'] . "\n";
|
||||
$mail->From = $row['email'];
|
||||
$mail->FromName = $row['name'];
|
||||
$mail->Subject = $mail_subject;
|
||||
$mail->Body = $mail_body;
|
||||
$mail->AddAddress($row['email'], $row['name']);
|
||||
|
||||
if(!$mail->Send())
|
||||
{
|
||||
$cronlog->logAction(CRON_ACTION, LOG_ERR, "Error sending mail: " . $mail->ErrorInfo);
|
||||
standard_error('errorsendingmail', $row["email"]);
|
||||
}
|
||||
|
||||
$mail->ClearAddresses();
|
||||
}
|
||||
}
|
||||
|
||||
// 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\';');
|
||||
}
|
||||
|
||||
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . '` SET `value` = UNIX_TIMESTAMP()
|
||||
WHERE `settinggroup` = \'system\' AND `varname` = \'last_traffic_report_run\' ');
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user