Setting eol-style for php and tpl - files
This commit is contained in:
@@ -1,27 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implementation of the Application Packaging Standard from SwSoft/Parallels
|
||||
* http://apsstandard.com
|
||||
*
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Sven Skrabal <info@nexpa.de>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id: cron_apsinstaller.php 2724 2009-06-07 14:18:02Z flo $
|
||||
* @todo
|
||||
*/
|
||||
|
||||
$needrootdb = true;
|
||||
require (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
$Aps = new ApsInstaller($settings, $db, $db_root);
|
||||
$Aps->InstallHandler();
|
||||
require (dirname(__FILE__) . '/../lib/cron_shutdown.php');
|
||||
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implementation of the Application Packaging Standard from SwSoft/Parallels
|
||||
* http://apsstandard.com
|
||||
*
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Sven Skrabal <info@nexpa.de>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id: cron_apsinstaller.php 2724 2009-06-07 14:18:02Z flo $
|
||||
* @todo
|
||||
*/
|
||||
|
||||
$needrootdb = true;
|
||||
require (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
$Aps = new ApsInstaller($settings, $db, $db_root);
|
||||
$Aps->InstallHandler();
|
||||
require (dirname(__FILE__) . '/../lib/cron_shutdown.php');
|
||||
|
||||
?>
|
||||
@@ -1,27 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implementation of the Application Packaging Standard from SwSoft/Parallels
|
||||
* http://apsstandard.com
|
||||
*
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Sven Skrabal <info@nexpa.de>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id: cron_apsupdater.php 2724 2009-06-07 14:18:02Z flo $
|
||||
* @todo
|
||||
*/
|
||||
|
||||
$needrootdb = false;
|
||||
require (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
$Aps = new ApsUpdater($db);
|
||||
$Aps->UpdateHandler();
|
||||
require (dirname(__FILE__) . '/../lib/cron_shutdown.php');
|
||||
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implementation of the Application Packaging Standard from SwSoft/Parallels
|
||||
* http://apsstandard.com
|
||||
*
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Sven Skrabal <info@nexpa.de>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
* @version $Id: cron_apsupdater.php 2724 2009-06-07 14:18:02Z flo $
|
||||
* @todo
|
||||
*/
|
||||
|
||||
$needrootdb = false;
|
||||
require (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
$Aps = new ApsUpdater($db);
|
||||
$Aps->UpdateHandler();
|
||||
require (dirname(__FILE__) . '/../lib/cron_shutdown.php');
|
||||
|
||||
?>
|
||||
@@ -1,229 +1,229 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Remo Fritzsche
|
||||
* @author Manuel Aller
|
||||
* @author Michael Schlechtinger
|
||||
* @author Sven Skrabal <info@nexpa.de>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_autoresponder.php 2724 2009-06-07 14:18:02Z flo $
|
||||
* @todo skip mail parsing after x bytes for large mails
|
||||
* implement start and end date for autoresponder mails
|
||||
*/
|
||||
|
||||
$needrootdb = false;
|
||||
require (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
$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))
|
||||
{
|
||||
$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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
?>
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Remo Fritzsche
|
||||
* @author Manuel Aller
|
||||
* @author Michael Schlechtinger
|
||||
* @author Sven Skrabal <info@nexpa.de>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_autoresponder.php 2724 2009-06-07 14:18:02Z flo $
|
||||
* @todo skip mail parsing after x bytes for large mails
|
||||
* implement start and end date for autoresponder mails
|
||||
*/
|
||||
|
||||
$needrootdb = false;
|
||||
require (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
$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))
|
||||
{
|
||||
$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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,81 +1,81 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @author Martin Burchert <eremit@syscp.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_legacy.php 2692 2009-03-27 18:04:47Z flo $
|
||||
*/
|
||||
|
||||
/**
|
||||
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
|
||||
* When using this "header" you have to change $lockFilename for your needs.
|
||||
* Don't forget to also copy the footer which closes database connections
|
||||
* and the lockfile! (Note: This "header" also establishes a mysql-root-
|
||||
* connection, if you don't need it, see for the header in cron_tasks.php)
|
||||
*/
|
||||
|
||||
$needrootdb = true;
|
||||
include (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
|
||||
/**
|
||||
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @author Martin Burchert <eremit@syscp.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_legacy.php 2692 2009-03-27 18:04:47Z flo $
|
||||
*/
|
||||
|
||||
/**
|
||||
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
|
||||
* When using this "header" you have to change $lockFilename for your needs.
|
||||
* Don't forget to also copy the footer which closes database connections
|
||||
* and the lockfile! (Note: This "header" also establishes a mysql-root-
|
||||
* connection, if you don't need it, see for the header in cron_tasks.php)
|
||||
*/
|
||||
|
||||
$needrootdb = true;
|
||||
include (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
|
||||
/**
|
||||
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
?>
|
||||
@@ -1,182 +1,182 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Michael Kaufmann <mk@syscp-help.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_lighttp.htaccess.php 2692 2009-03-27 18:04:47Z flo $
|
||||
*/
|
||||
|
||||
/**
|
||||
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
|
||||
* When using this "header" you have to change $lockFilename for your needs.
|
||||
* Don't forget to also copy the footer which closes database connections
|
||||
* and the lockfile!
|
||||
*/
|
||||
|
||||
include (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
|
||||
/**
|
||||
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Michael Kaufmann <mk@syscp-help.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_lighttp.htaccess.php 2692 2009-03-27 18:04:47Z flo $
|
||||
*/
|
||||
|
||||
/**
|
||||
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
|
||||
* When using this "header" you have to change $lockFilename for your needs.
|
||||
* Don't forget to also copy the footer which closes database connections
|
||||
* and the lockfile!
|
||||
*/
|
||||
|
||||
include (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
|
||||
/**
|
||||
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,337 +1,337 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @author Martin Burchert <eremit@syscp.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_tasks.inc.dns.10.bind.php 2692 2009-03-27 18:04:47Z flo $
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 syscp_bind.conf' . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'Task4 started - Rebuilding syscp_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'] . 'syscp_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'] . '/syscp_bind.conf'), 'w');
|
||||
fwrite($bindconf_file_handler, $bindconf_file);
|
||||
fclose($bindconf_file_handler);
|
||||
fwrite($this->debugHandler, ' cron_tasks: Task4 - syscp_bind.conf written' . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'syscp_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";
|
||||
}
|
||||
}
|
||||
|
||||
$zonefile.= '@ IN TXT "v=spf1 a mx -all"' . "\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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @author Martin Burchert <eremit@syscp.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_tasks.inc.dns.10.bind.php 2692 2009-03-27 18:04:47Z flo $
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 syscp_bind.conf' . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'Task4 started - Rebuilding syscp_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'] . 'syscp_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'] . '/syscp_bind.conf'), 'w');
|
||||
fwrite($bindconf_file_handler, $bindconf_file);
|
||||
fclose($bindconf_file_handler);
|
||||
fwrite($this->debugHandler, ' cron_tasks: Task4 - syscp_bind.conf written' . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'syscp_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";
|
||||
}
|
||||
}
|
||||
|
||||
$zonefile.= '@ IN TXT "v=spf1 a mx -all"' . "\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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,264 +1,264 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Aders <eleras@syscp.org>
|
||||
* @author Luca Longinotti <chtekk@syscp.org>
|
||||
* @author Michael Kaufmann <mk@syscp-help.org>
|
||||
* @author Sven Skrabal <info@nexpa.de>
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_tasks.inc.http.15.apache_fcgid.php 2714 2009-04-17 10:02:03Z flo $
|
||||
*/
|
||||
|
||||
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 SysCP 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 SysCP 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->db->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->db->query_first("SELECT `email`, `loginname` FROM `" . TABLE_PANEL_ADMINS . "` WHERE `adminid` = " . (int)$adminid);
|
||||
}
|
||||
|
||||
return $this->admin_cache[$adminid];
|
||||
}
|
||||
}
|
||||
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Aders <eleras@syscp.org>
|
||||
* @author Luca Longinotti <chtekk@syscp.org>
|
||||
* @author Michael Kaufmann <mk@syscp-help.org>
|
||||
* @author Sven Skrabal <info@nexpa.de>
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_tasks.inc.http.15.apache_fcgid.php 2714 2009-04-17 10:02:03Z flo $
|
||||
*/
|
||||
|
||||
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 SysCP 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 SysCP 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->db->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->db->query_first("SELECT `email`, `loginname` FROM `" . TABLE_PANEL_ADMINS . "` WHERE `adminid` = " . (int)$adminid);
|
||||
}
|
||||
|
||||
return $this->admin_cache[$adminid];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,211 +1,211 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @author Martin Burchert <eremit@syscp.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_tasks.php 2692 2009-03-27 18:04:47Z flo $
|
||||
*/
|
||||
|
||||
/**
|
||||
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
|
||||
* When using this "header" you have to change $lockFilename for your needs.
|
||||
* Don't forget to also copy the footer which closes database connections
|
||||
* and the lockfile!
|
||||
*/
|
||||
|
||||
include (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
|
||||
/**
|
||||
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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')
|
||||
{
|
||||
if(!isset($webserver))
|
||||
{
|
||||
if($settings['system']['webserver'] == "apache2")
|
||||
{
|
||||
if($settings['system']['mod_fcgid'] == 1)
|
||||
{
|
||||
$webserver = new apache_fcgid($db, $cronlog, $debugHandler, $settings);
|
||||
}
|
||||
else
|
||||
{
|
||||
$webserver = new apache($db, $cronlog, $debugHandler, $settings);
|
||||
}
|
||||
}
|
||||
elseif($settings['system']['webserver'] == "lighttpd")
|
||||
{
|
||||
if($settings['system']['mod_fcgid'] == 1)
|
||||
{
|
||||
$webserver = new lighttpd_fcgid($db, $cronlog, $debugHandler, $settings);
|
||||
}
|
||||
else
|
||||
{
|
||||
$webserver = new lighttpd($db, $cronlog, $debugHandler, $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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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\' ');
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
?>
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @author Martin Burchert <eremit@syscp.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_tasks.php 2692 2009-03-27 18:04:47Z flo $
|
||||
*/
|
||||
|
||||
/**
|
||||
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
|
||||
* When using this "header" you have to change $lockFilename for your needs.
|
||||
* Don't forget to also copy the footer which closes database connections
|
||||
* and the lockfile!
|
||||
*/
|
||||
|
||||
include (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
|
||||
/**
|
||||
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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')
|
||||
{
|
||||
if(!isset($webserver))
|
||||
{
|
||||
if($settings['system']['webserver'] == "apache2")
|
||||
{
|
||||
if($settings['system']['mod_fcgid'] == 1)
|
||||
{
|
||||
$webserver = new apache_fcgid($db, $cronlog, $debugHandler, $settings);
|
||||
}
|
||||
else
|
||||
{
|
||||
$webserver = new apache($db, $cronlog, $debugHandler, $settings);
|
||||
}
|
||||
}
|
||||
elseif($settings['system']['webserver'] == "lighttpd")
|
||||
{
|
||||
if($settings['system']['mod_fcgid'] == 1)
|
||||
{
|
||||
$webserver = new lighttpd_fcgid($db, $cronlog, $debugHandler, $settings);
|
||||
}
|
||||
else
|
||||
{
|
||||
$webserver = new lighttpd($db, $cronlog, $debugHandler, $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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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\' ');
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,80 +1,80 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Support-Tickets - Cronfile
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version. This program is distributed in the
|
||||
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
|
||||
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Michael Kaufmann <mkaufmann@nutime.de>
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
* @package Panel
|
||||
* @version CVS: $Id: cron_ticketarchive.php 2724 2009-06-07 14:18:02Z flo $
|
||||
* @link http://www.nutime.de/
|
||||
* @since File available since Release 1.2.18
|
||||
*/
|
||||
|
||||
/**
|
||||
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
|
||||
* When using this "header" you have to change $lockFilename for your needs.
|
||||
* Don't forget to also copy the footer which closes database connections
|
||||
* and the lockfile! (Note: This "header" also establishes a mysql-root-
|
||||
* connection, if you don't need it, see for the header in cron_tasks.php)
|
||||
*/
|
||||
|
||||
$needrootdb = false;
|
||||
include (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
|
||||
/**
|
||||
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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\' ');
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Support-Tickets - Cronfile
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version. This program is distributed in the
|
||||
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
|
||||
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Michael Kaufmann <mkaufmann@nutime.de>
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
* @package Panel
|
||||
* @version CVS: $Id: cron_ticketarchive.php 2724 2009-06-07 14:18:02Z flo $
|
||||
* @link http://www.nutime.de/
|
||||
* @since File available since Release 1.2.18
|
||||
*/
|
||||
|
||||
/**
|
||||
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
|
||||
* When using this "header" you have to change $lockFilename for your needs.
|
||||
* Don't forget to also copy the footer which closes database connections
|
||||
* and the lockfile! (Note: This "header" also establishes a mysql-root-
|
||||
* connection, if you don't need it, see for the header in cron_tasks.php)
|
||||
*/
|
||||
|
||||
$needrootdb = false;
|
||||
include (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
|
||||
/**
|
||||
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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\' ');
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
?>
|
||||
@@ -1,231 +1,231 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @author Florian Aders <eleras@syscp.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_traffic.inc.functions.php 2692 2009-03-27 18:04:47Z flo $
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @author Florian Aders <eleras@syscp.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_traffic.inc.functions.php 2692 2009-03-27 18:04:47Z flo $
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,400 +1,400 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @author Martin Burchert <eremit@syscp.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_traffic.php 2739 2009-11-06 14:46:30Z flo $
|
||||
*/
|
||||
|
||||
/**
|
||||
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
|
||||
* When using this "header" you have to change $lockFilename for your needs.
|
||||
* Don't forget to also copy the footer which closes database connections
|
||||
* and the lockfile! (Note: This "header" also establishes a mysql-root-
|
||||
* connection, if you don't need it, see for the header in cron_tasks.php)
|
||||
*/
|
||||
|
||||
$needrootdb = true;
|
||||
include (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
|
||||
/**
|
||||
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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('SysCP 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\' ');
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
?>
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @author Martin Burchert <eremit@syscp.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_traffic.php 2739 2009-11-06 14:46:30Z flo $
|
||||
*/
|
||||
|
||||
/**
|
||||
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
|
||||
* When using this "header" you have to change $lockFilename for your needs.
|
||||
* Don't forget to also copy the footer which closes database connections
|
||||
* and the lockfile! (Note: This "header" also establishes a mysql-root-
|
||||
* connection, if you don't need it, see for the header in cron_tasks.php)
|
||||
*/
|
||||
|
||||
$needrootdb = true;
|
||||
include (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
|
||||
/**
|
||||
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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('SysCP 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\' ');
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,240 +1,240 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Aders <eleras@syscp.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_traffic_report.php 2692 2009-03-27 18:04:47Z flo $
|
||||
*/
|
||||
|
||||
/**
|
||||
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
|
||||
* When using this "header" you have to change $lockFilename for your needs.
|
||||
* Don't forget to also copy the footer which closes database connections
|
||||
* and the lockfile!
|
||||
*/
|
||||
|
||||
include (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
|
||||
/**
|
||||
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
|
||||
*/
|
||||
|
||||
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\' ');
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
?>
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Aders <eleras@syscp.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: cron_traffic_report.php 2692 2009-03-27 18:04:47Z flo $
|
||||
*/
|
||||
|
||||
/**
|
||||
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
|
||||
* When using this "header" you have to change $lockFilename for your needs.
|
||||
* Don't forget to also copy the footer which closes database connections
|
||||
* and the lockfile!
|
||||
*/
|
||||
|
||||
include (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
|
||||
/**
|
||||
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
|
||||
*/
|
||||
|
||||
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\' ');
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,66 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Support-Tickets - Reset used tickets - Cronfile
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version. This program is distributed in the
|
||||
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
|
||||
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Michael Kaufmann <mkaufmann@nutime.de>
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
* @package Panel
|
||||
* @version CVS: $Id: cron_used_tickets_reset.php 2244 2008-10-06 11:01:18Z EleRas $
|
||||
* @link http://www.nutime.de/
|
||||
* @since File available since Release 1.2.20
|
||||
*/
|
||||
|
||||
/**
|
||||
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
|
||||
* When using this "header" you have to change $lockFilename for your needs.
|
||||
* Don't forget to also copy the footer which closes database connections
|
||||
* and the lockfile! (Note: This "header" also establishes a mysql-root-
|
||||
* connection, if you don't need it, see for the header in cron_tasks.php)
|
||||
*/
|
||||
|
||||
$needrootdb = false;
|
||||
include (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
|
||||
/**
|
||||
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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'");
|
||||
}
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Support-Tickets - Reset used tickets - Cronfile
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version. This program is distributed in the
|
||||
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
|
||||
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Michael Kaufmann <mkaufmann@nutime.de>
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
* @package Panel
|
||||
* @version CVS: $Id: cron_used_tickets_reset.php 2244 2008-10-06 11:01:18Z EleRas $
|
||||
* @link http://www.nutime.de/
|
||||
* @since File available since Release 1.2.20
|
||||
*/
|
||||
|
||||
/**
|
||||
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
|
||||
* When using this "header" you have to change $lockFilename for your needs.
|
||||
* Don't forget to also copy the footer which closes database connections
|
||||
* and the lockfile! (Note: This "header" also establishes a mysql-root-
|
||||
* connection, if you don't need it, see for the header in cron_tasks.php)
|
||||
*/
|
||||
|
||||
$needrootdb = false;
|
||||
include (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
|
||||
/**
|
||||
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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'");
|
||||
}
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
?>
|
||||
@@ -1,140 +1,140 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: install_configs.php 2698 2009-04-13 20:25:59Z flo $
|
||||
*/
|
||||
|
||||
/**
|
||||
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
|
||||
* When using this "header" you have to change $lockFilename for your needs.
|
||||
* Don't forget to also copy the footer which closes database connections
|
||||
* and the lockfile!
|
||||
*/
|
||||
|
||||
include (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
|
||||
/**
|
||||
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
|
||||
*/
|
||||
|
||||
require ($pathtophpfiles . '/lib/configfiles_index.inc.php');
|
||||
require ($pathtophpfiles . '/lib/userdata.inc.php');
|
||||
|
||||
$replace_arr = Array(
|
||||
'<SQL_UNPRIVILEGED_USER>' => $sql['user'],
|
||||
'<SQL_UNPRIVILEGED_PASSWORD>' => $sql['password'],
|
||||
'<SQL_DB>' => $sql['db'],
|
||||
'<SQL_HOST>' => $sql['host'],
|
||||
'<SERVERNAME>' => $settings['system']['hostname'],
|
||||
'<SERVERIP>' => $settings['system']['ipaddress'],
|
||||
'<NAMESERVERS>' => $settings['system']['nameservers'],
|
||||
'<VIRTUAL_MAILBOX_BASE>' => $settings['system']['vmail_homedir'],
|
||||
'<VIRTUAL_UID_MAPS>' => $settings['system']['vmail_uid'],
|
||||
'<VIRTUAL_GID_MAPS>' => $settings['system']['vmail_gid'],
|
||||
'<AWSTATS_PATH>' => $settings['system']['awstats_path'],
|
||||
'<SSLPROTOCOLS>' => ($settings['system']['use_ssl'] == '1') ? 'imaps pop3s' : ''
|
||||
);
|
||||
|
||||
$cli_params = $_SERVER['argv'];
|
||||
unset($cli_params[0]);
|
||||
|
||||
if(isset($cli_params[1]) && $cli_params[1] != '' && isset($configfiles[$cli_params[1]]))
|
||||
{
|
||||
$distribution = $cli_params[1];
|
||||
unset($cli_params[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo 'No valid distribution specified!' . "\n";
|
||||
}
|
||||
|
||||
foreach($cli_params as $cli_param)
|
||||
{
|
||||
list($service, $daemon) = explode('=', $cli_param);
|
||||
echo $service . ' ' . $daemon;
|
||||
if(isset($configfiles[$distribution]['services'][$service]) && isset($configfiles[$distribution]['services'][$service]['daemons'][$daemon]))
|
||||
{
|
||||
foreach($configfiles[$distribution]['services'][$service]['daemons'][$daemon] as $action => $value)
|
||||
{
|
||||
if(substr($action, 0, 8) == 'commands')
|
||||
{
|
||||
if(is_array($value))
|
||||
{
|
||||
echo '=== COMMANDS BEGIN ===' . "\n";
|
||||
foreach($value as $command)
|
||||
{
|
||||
echo '-- running ' . $command . "\n";
|
||||
if(in_array('reallydoit', $cli_params))
|
||||
{
|
||||
passthru($command);
|
||||
}
|
||||
}
|
||||
echo '==== COMMANDS END ====' . "\n";
|
||||
}
|
||||
}
|
||||
elseif(substr($action, 0, 5) == 'files')
|
||||
{
|
||||
if(is_array($value))
|
||||
{
|
||||
echo '=== FILES BEGIN ===' . "\n";
|
||||
while(list($filename, $realname) = each($value))
|
||||
{
|
||||
$file_content = file_get_contents('./templates/misc/configfiles/' . $distribution . '/' . $daemon . '/' . $filename);
|
||||
$file_content = strtr($file_content, $replace_arr);
|
||||
echo '-- filename: ' . $realname . "\n";
|
||||
echo '-- filecontent:' . "\n" . '---' . "\n";
|
||||
echo $file_content;
|
||||
echo '---' . "\n";
|
||||
if(in_array('reallydoit', $cli_params))
|
||||
{
|
||||
if(file_exists($realname))
|
||||
{
|
||||
exec('mv ' . escapeshellarg($realname) . ' ' . escapeshellarg($realname) . '.orig');
|
||||
}
|
||||
file_put_contents($realname, $file_content);
|
||||
}
|
||||
}
|
||||
echo '==== FILES END ====' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($configfiles[$distribution]['services'][$service]['daemons'][$daemon]['restart'])
|
||||
&& is_array($configfiles[$distribution]['services'][$service]['daemons'][$daemon]['restart']))
|
||||
{
|
||||
echo '=== RESTART BEGIN ===' . "\n";
|
||||
foreach($configfiles[$distribution]['services'][$service]['daemons'][$daemon]['restart'] as $command)
|
||||
{
|
||||
echo '-- running ' . $command . "\n";
|
||||
if(in_array('reallydoit', $cli_params))
|
||||
{
|
||||
passthru($command);
|
||||
}
|
||||
}
|
||||
echo '==== RESTART END ====' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the SysCP project.
|
||||
* Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
|
||||
* @package System
|
||||
* @version $Id: install_configs.php 2698 2009-04-13 20:25:59Z flo $
|
||||
*/
|
||||
|
||||
/**
|
||||
* STARTING REDUNDANT CODE, WHICH IS SOME KINDA HEADER FOR EVERY CRON SCRIPT.
|
||||
* When using this "header" you have to change $lockFilename for your needs.
|
||||
* Don't forget to also copy the footer which closes database connections
|
||||
* and the lockfile!
|
||||
*/
|
||||
|
||||
include (dirname(__FILE__) . '/../lib/cron_init.php');
|
||||
|
||||
/**
|
||||
* END REDUNDANT CODE (CRONSCRIPT "HEADER")
|
||||
*/
|
||||
|
||||
require ($pathtophpfiles . '/lib/configfiles_index.inc.php');
|
||||
require ($pathtophpfiles . '/lib/userdata.inc.php');
|
||||
|
||||
$replace_arr = Array(
|
||||
'<SQL_UNPRIVILEGED_USER>' => $sql['user'],
|
||||
'<SQL_UNPRIVILEGED_PASSWORD>' => $sql['password'],
|
||||
'<SQL_DB>' => $sql['db'],
|
||||
'<SQL_HOST>' => $sql['host'],
|
||||
'<SERVERNAME>' => $settings['system']['hostname'],
|
||||
'<SERVERIP>' => $settings['system']['ipaddress'],
|
||||
'<NAMESERVERS>' => $settings['system']['nameservers'],
|
||||
'<VIRTUAL_MAILBOX_BASE>' => $settings['system']['vmail_homedir'],
|
||||
'<VIRTUAL_UID_MAPS>' => $settings['system']['vmail_uid'],
|
||||
'<VIRTUAL_GID_MAPS>' => $settings['system']['vmail_gid'],
|
||||
'<AWSTATS_PATH>' => $settings['system']['awstats_path'],
|
||||
'<SSLPROTOCOLS>' => ($settings['system']['use_ssl'] == '1') ? 'imaps pop3s' : ''
|
||||
);
|
||||
|
||||
$cli_params = $_SERVER['argv'];
|
||||
unset($cli_params[0]);
|
||||
|
||||
if(isset($cli_params[1]) && $cli_params[1] != '' && isset($configfiles[$cli_params[1]]))
|
||||
{
|
||||
$distribution = $cli_params[1];
|
||||
unset($cli_params[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo 'No valid distribution specified!' . "\n";
|
||||
}
|
||||
|
||||
foreach($cli_params as $cli_param)
|
||||
{
|
||||
list($service, $daemon) = explode('=', $cli_param);
|
||||
echo $service . ' ' . $daemon;
|
||||
if(isset($configfiles[$distribution]['services'][$service]) && isset($configfiles[$distribution]['services'][$service]['daemons'][$daemon]))
|
||||
{
|
||||
foreach($configfiles[$distribution]['services'][$service]['daemons'][$daemon] as $action => $value)
|
||||
{
|
||||
if(substr($action, 0, 8) == 'commands')
|
||||
{
|
||||
if(is_array($value))
|
||||
{
|
||||
echo '=== COMMANDS BEGIN ===' . "\n";
|
||||
foreach($value as $command)
|
||||
{
|
||||
echo '-- running ' . $command . "\n";
|
||||
if(in_array('reallydoit', $cli_params))
|
||||
{
|
||||
passthru($command);
|
||||
}
|
||||
}
|
||||
echo '==== COMMANDS END ====' . "\n";
|
||||
}
|
||||
}
|
||||
elseif(substr($action, 0, 5) == 'files')
|
||||
{
|
||||
if(is_array($value))
|
||||
{
|
||||
echo '=== FILES BEGIN ===' . "\n";
|
||||
while(list($filename, $realname) = each($value))
|
||||
{
|
||||
$file_content = file_get_contents('./templates/misc/configfiles/' . $distribution . '/' . $daemon . '/' . $filename);
|
||||
$file_content = strtr($file_content, $replace_arr);
|
||||
echo '-- filename: ' . $realname . "\n";
|
||||
echo '-- filecontent:' . "\n" . '---' . "\n";
|
||||
echo $file_content;
|
||||
echo '---' . "\n";
|
||||
if(in_array('reallydoit', $cli_params))
|
||||
{
|
||||
if(file_exists($realname))
|
||||
{
|
||||
exec('mv ' . escapeshellarg($realname) . ' ' . escapeshellarg($realname) . '.orig');
|
||||
}
|
||||
file_put_contents($realname, $file_content);
|
||||
}
|
||||
}
|
||||
echo '==== FILES END ====' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($configfiles[$distribution]['services'][$service]['daemons'][$daemon]['restart'])
|
||||
&& is_array($configfiles[$distribution]['services'][$service]['daemons'][$daemon]['restart']))
|
||||
{
|
||||
echo '=== RESTART BEGIN ===' . "\n";
|
||||
foreach($configfiles[$distribution]['services'][$service]['daemons'][$daemon]['restart'] as $command)
|
||||
{
|
||||
echo '-- running ' . $command . "\n";
|
||||
if(in_array('reallydoit', $cli_params))
|
||||
{
|
||||
passthru($command);
|
||||
}
|
||||
}
|
||||
echo '==== RESTART END ====' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* STARTING CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
include ($pathtophpfiles . '/lib/cron_shutdown.php');
|
||||
|
||||
/**
|
||||
* END CRONSCRIPT FOOTER
|
||||
*/
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user