make cronjobs also classes and began to refactor the whole cronjob stuff

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-12-19 08:55:23 +01:00
parent a25150babf
commit 903b775f79
52 changed files with 460 additions and 523 deletions

View File

@@ -157,14 +157,14 @@ abstract class ApiCommand extends ApiParameter
// include every english language file we can get // include every english language file we can get
foreach ($langs['English'] as $value) { foreach ($langs['English'] as $value) {
include_once \Froxlor\FileDir::makeSecurePath(FROXLOR_INSTALL_DIR . '/' . $value['file']); include_once \Froxlor\FileDir::makeSecurePath(\Froxlor\Froxlor::getInstallDir() . '/' . $value['file']);
} }
// now include the selected language if its not english // now include the selected language if its not english
if ($language != 'English') { if ($language != 'English') {
if (isset($langs[$language])) { if (isset($langs[$language])) {
foreach ($langs[$language] as $value) { foreach ($langs[$language] as $value) {
include_once \Froxlor\FileDir::makeSecurePath(FROXLOR_INSTALL_DIR . '/' . $value['file']); include_once \Froxlor\FileDir::makeSecurePath(\Froxlor\Froxlor::getInstallDir() . '/' . $value['file']);
} }
} else { } else {
if ($this->debug) { if ($this->debug) {
@@ -174,7 +174,7 @@ abstract class ApiCommand extends ApiParameter
} }
// last but not least include language references file // last but not least include language references file
include_once makeSecurePath(FROXLOR_INSTALL_DIR . '/lng/lng_references.php'); include_once makeSecurePath(\Froxlor\Froxlor::getInstallDir() . '/lng/lng_references.php');
// set array for ApiCommand // set array for ApiCommand
$this->lng = $lng; $this->lng = $lng;

View File

@@ -664,7 +664,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
$srv_hostname = Settings::Get('system.hostname'); $srv_hostname = Settings::Get('system.hostname');
if (Settings::Get('system.froxlordirectlyviahostname') == '0') { if (Settings::Get('system.froxlordirectlyviahostname') == '0') {
$srv_hostname .= '/' . basename(FROXLOR_INSTALL_DIR); $srv_hostname .= '/' . basename(\Froxlor\Froxlor::getInstallDir());
} }
$srv_ip_stmt = Database::prepare(" $srv_ip_stmt = Database::prepare("

View File

@@ -1,50 +0,0 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package API
* @since 0.10.0
*
*/
if (! defined('FROXLOR_INSTALL_DIR')) {
define('FROXLOR_INSTALL_DIR', dirname(dirname(dirname(__DIR__))));
// ensure that default timezone is set
if (function_exists("date_default_timezone_set") && function_exists("date_default_timezone_get")) {
@date_default_timezone_set(@date_default_timezone_get());
}
$installed = true;
// check whether the userdata file exists
if (! @file_exists(FROXLOR_INSTALL_DIR . '/lib/userdata.inc.php')) {
$installed = false;
}
// check whether we can read the userdata file
if ($installed && ! @is_readable(FROXLOR_INSTALL_DIR . '/lib/userdata.inc.php')) {
$installed = false;
}
if ($installed) {
// include userdata for content-check
require FROXLOR_INSTALL_DIR . '/lib/userdata.inc.php';
if (! isset($sql) || ! is_array($sql)) {
$installed = false;
}
}
// do not try to do anything if we have no installed/configured froxlor
if (! $installed) {
header("Status: 404 Not found", 404);
header($_SERVER["SERVER_PROTOCOL"] . " 404 Not found", 404);
exit();
}
require_once FROXLOR_INSTALL_DIR . '/lib/tables.inc.php';
require_once FROXLOR_INSTALL_DIR . '/lib/functions.php';
}
$lng = array();

View File

@@ -0,0 +1,134 @@
<?php
namespace Froxlor\Cron;
use Froxlor\Database;
use Froxlor\Settings;
class CronConfig
{
/**
* 1st: check for task of generation
* 2nd: if task found, generate cron.d-file
* 3rd: maybe restart cron?
*/
public static function checkCrondConfigurationFile()
{
// check for task
Database::query("
SELECT * FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = '99'
");
$num_results = Database::num_rows();
// is there a task for re-generating the cron.d-file?
if ($num_results > 0) {
// get all crons and their intervals
if (isFreeBSD()) {
// FreeBSD does not need a header as we are writing directly to the crontab
$cronfile = "\n";
} else {
$cronfile = "# automatically generated cron-configuration by froxlor\n";
$cronfile .= "# do not manually edit this file as it will be re-generated periodically.\n";
$cronfile .= "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n#\n";
}
// get all the crons
$result_stmt = Database::query("
SELECT * FROM `" . TABLE_PANEL_CRONRUNS . "` WHERE `isactive` = '1'
");
$hour_delay = 0;
$day_delay = 5;
$month_delay = 7;
while ($row_cronentry = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
// create cron.d-entry
if (preg_match("/(\d+) (MINUTE|HOUR|DAY|WEEK|MONTH)/", $row_cronentry['interval'], $matches)) {
if ($matches[1] == 1) {
$minvalue = "*";
} else {
$minvalue = "*/" . $matches[1];
}
switch ($matches[2]) {
case "MINUTE":
$cronfile .= $minvalue . " * * * * ";
break;
case "HOUR":
$cronfile .= $hour_delay . " " . $minvalue . " * * * ";
$hour_delay += 3;
break;
case "DAY":
if ($row_cronentry['cronfile'] == 'traffic') {
// traffic at exactly 0:00 o'clock
$cronfile .= "0 0 " . $minvalue . " * * ";
} else {
$cronfile .= $day_delay . " 0 " . $minvalue . " * * ";
$day_delay += 5;
}
break;
case "MONTH":
$cronfile .= $month_delay . " 0 1 " . $minvalue . " * ";
$month_delay += 7;
break;
case "WEEK":
$cronfile .= $day_delay . " 0 " . ($matches[1] * 7) . " * * ";
$day_delay += 5;
break;
}
// create entry-line
$binpath = Settings::Get("system.croncmdline");
// fallback as it is important
if ($binpath === null) {
$binpath = "/usr/bin/nice -n 5 /usr/bin/php5 -q";
}
$cronfile .= "root " . $binpath . " " . \Froxlor\Froxlor::getInstallDir() . "/scripts/froxlor_master_cronjob.php --" . $row_cronentry['cronfile'] . " 1> /dev/null\n";
}
}
if (isFreeBSD()) {
// FreeBSD handles the cron-stuff in another way. We need to directly
// write to the crontab file as there is not cron.d/froxlor file
// (settings for system.cronconfig should be set correctly of course)
$crontab = file_get_contents(Settings::Get("system.cronconfig"));
if ($crontab === false) {
die("Oh snap, we cannot read the crontab file. This should not happen.\nPlease check the path and permissions, the cron will keep trying if you don't stop the cron-service.\n\n");
}
// now parse out / replace our entries
$crontablines = explode("\n", $crontab);
$newcrontab = "";
foreach ($crontablines as $ctl) {
$ctl = trim($ctl);
if (! empty($ctl) && ! preg_match("/(.*)froxlor_master_cronjob\.php(.*)/", $ctl)) {
$newcrontab .= $ctl . "\n";
}
}
// re-assemble old-content + new froxlor-content
$newcrontab .= $cronfile;
// now continue with writing the file
$cronfile = $newcrontab;
}
// write the file
if (file_put_contents(Settings::Get("system.cronconfig"), $cronfile) === false) {
// oh snap cannot create new crond-file
die("Oh snap, we cannot create the cron-file. This should not happen.\nPlease check the path and permissions, the cron will keep trying if you don't stop the cron-service.\n\n");
}
// correct permissions
chmod(Settings::Get("system.cronconfig"), 0640);
// remove all re-generation tasks
Database::query("DELETE FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = '99'");
// run reload command
\Froxlor\FileDir::safe_exec(escapeshellcmd(Settings::Get('system.crondreload')));
}
return true;
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Froxlor\Cron;
abstract class FroxlorCron
{
abstract public static function run();
private static $lockfile = null;
public static function getLockfile()
{
return static::$lockfile;
}
public static function setLockfile($lockfile = null)
{
static::$lockfile = $lockfile;
}
}

View File

@@ -109,7 +109,7 @@ if (Settings::Get('system.le_froxlor_enabled') == '1') {
'loginname' => 'froxlor.panel', 'loginname' => 'froxlor.panel',
'domain' => Settings::Get('system.hostname'), 'domain' => Settings::Get('system.hostname'),
'domainid' => 0, 'domainid' => 0,
'documentroot' => FROXLOR_INSTALL_DIR, 'documentroot' => \Froxlor\Froxlor::getInstallDir(),
'leprivatekey' => Settings::Get('system.leprivatekey'), 'leprivatekey' => Settings::Get('system.leprivatekey'),
'lepublickey' => Settings::Get('system.lepublickey'), 'lepublickey' => Settings::Get('system.lepublickey'),
'leregistered' => Settings::Get('system.leregistered'), 'leregistered' => Settings::Get('system.leregistered'),

View File

@@ -106,7 +106,7 @@ if (Settings::Get('system.le_froxlor_enabled') == '1') {
'loginname' => 'froxlor.panel', 'loginname' => 'froxlor.panel',
'domain' => Settings::Get('system.hostname'), 'domain' => Settings::Get('system.hostname'),
'domainid' => 0, 'domainid' => 0,
'documentroot' => FROXLOR_INSTALL_DIR, 'documentroot' => \Froxlor\Froxlor::getInstallDir(),
'leprivatekey' => Settings::Get('system.leprivatekey'), 'leprivatekey' => Settings::Get('system.leprivatekey'),
'lepublickey' => Settings::Get('system.lepublickey'), 'lepublickey' => Settings::Get('system.lepublickey'),
'leregistered' => Settings::Get('system.leregistered'), 'leregistered' => Settings::Get('system.leregistered'),

View File

@@ -0,0 +1,114 @@
<?php
namespace Froxlor\Cron\System;
use \Froxlor\Database;
use \Froxlor\Settings;
use \Froxlor\FroxlorLogger;
/**
* This file is part of the Froxlor project.
* Copyright (c) 2016 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Michael Kaufmann <mkaufmann@nutime.de>
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Cron
*
* @since 0.9.35.1
*
*/
class BackupCron extends \Froxlor\Cron\FroxlorCron
{
public static function run()
{
// Check Traffic-Lock
if (function_exists('pcntl_fork')) {
$BackupLock = makeCorrectFile(dirname(self::getLockfile()) . "/froxlor_cron_backup.lock");
if (file_exists($BackupLock) && is_numeric($BackupPid = file_get_contents($BackupLock))) {
if (function_exists('posix_kill')) {
$BackupPidStatus = @posix_kill($BackupPid, 0);
} else {
system("kill -CHLD " . $BackupPid . " 1> /dev/null 2> /dev/null", $BackupPidStatus);
$BackupPidStatus = $BackupPidStatus ? false : true;
}
if ($BackupPidStatus) {
FroxlorLogger::getInstanceOf()->logAction(CRON_ACTION, LOG_INFO, 'Backup run already in progress');
return 1;
}
}
// Create Backup Log and Fork
// We close the database - connection before we fork, so we don't share resources with the child
Database::needRoot(false); // this forces the connection to be set to null
$BackupPid = pcntl_fork();
// Parent
if ($BackupPid) {
file_put_contents($BackupLock, $BackupPid);
// unnecessary to recreate database connection here
return 0;
} // Child
elseif ($BackupPid == 0) {
posix_setsid();
// re-create db
Database::needRoot(false);
} // Fork failed
else {
return 1;
}
} else {
if (extension_loaded('pcntl')) {
$msg = "PHP compiled with pcntl but pcntl_fork function is not available.";
} else {
$msg = "PHP compiled without pcntl.";
}
FroxlorLogger::getInstanceOf()->logAction(CRON_ACTION, LOG_WARNING, $msg . " Not forking backup-cron, this may take a long time!");
}
FroxlorLogger::getInstanceOf()->logAction(CRON_ACTION, LOG_INFO, 'BackupCron: started - creating customer backup');
$result_tasks_stmt = Database::query("
SELECT * FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = '20' ORDER BY `id` ASC
");
$del_stmt = Database::prepare("DELETE FROM `" . TABLE_PANEL_TASKS . "` WHERE `id` = :id");
$all_jobs = $result_tasks_stmt->fetchAll();
foreach ($all_jobs as $row) {
if ($row['data'] != '') {
$row['data'] = json_decode($row['data'], true);
}
if (is_array($row['data'])) {
if (isset($row['data']['customerid']) && isset($row['data']['loginname']) && isset($row['data']['destdir'])) {
$row['data']['destdir'] = makeCorrectDir($row['data']['destdir']);
$customerdocroot = makeCorrectDir(Settings::Get('system.documentroot_prefix') . '/' . $row['data']['loginname'] . '/');
// create folder if not exists
if (! file_exists($row['data']['destdir']) && $row['data']['destdir'] != '/' && $row['data']['destdir'] != Settings::Get('system.documentroot_prefix') && $row['data']['destdir'] != $customerdocroot) {
FroxlorLogger::getInstanceOf()->logAction(CRON_ACTION, LOG_NOTICE, 'Creating backup-destination path for customer: ' . escapeshellarg($row['data']['destdir']));
\Froxlor\FileDir::safe_exec('mkdir -p ' . escapeshellarg($row['data']['destdir']));
}
createCustomerBackup($row['data'], $customerdocroot, FroxlorLogger::getInstanceOf());
}
}
// remove entry
Database::pexecute($del_stmt, array(
'id' => $row['id']
));
}
if (function_exists('pcntl_fork')) {
@unlink($BackupLock);
die();
}
}
}

View File

@@ -1,4 +1,7 @@
<?php <?php
namespace Froxlor\Cron\System;
use Froxlor\Database;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -8,11 +11,11 @@
* file that was distributed with this source code. You can also view the * file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt * COPYING file online at http://files.froxlor.org/misc/COPYING.txt
* *
* @copyright (c) the authors * @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2017-) * @author Froxlor team <team@froxlor.org> (2017-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Cron * @package Cron
* *
*/ */
class Extrausers class Extrausers
{ {
@@ -55,7 +58,7 @@ class Extrausers
$data_sel_stmt = Database::query($query); $data_sel_stmt = Database::query($query);
$data_content = ""; $data_content = "";
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Writing ' . $data_sel_stmt->rowCount() . ' entries to ' . $type . ' file'); $cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Writing ' . $data_sel_stmt->rowCount() . ' entries to ' . $type . ' file');
while ($u = $data_sel_stmt->fetch(PDO::FETCH_ASSOC)) { while ($u = $data_sel_stmt->fetch(\PDO::FETCH_ASSOC)) {
switch ($type) { switch ($type) {
case 'passwd': case 'passwd':
if ($u['login_enabled'] != 'Y') { if ($u['login_enabled'] != 'Y') {

View File

@@ -0,0 +1,70 @@
<?php
namespace Froxlor\Cron\System;
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Michael Kaufmann <mkaufmann@nutime.de>
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Cron
*
* @since 0.9.29.1
*
*/
class MailboxSizeCron extends \Froxlor\Cron\FroxlorCron
{
public static function run()
{
\Froxlor\FroxlorLogger::getInstanceOf()->logAction(CRON_ACTION, LOG_NOTICE, 'calculating mailspace usage');
$maildirs_stmt = \Froxlor\Database\Database::query("
SELECT `id`, CONCAT(`homedir`, `maildir`) AS `maildirpath` FROM `" . TABLE_MAIL_USERS . "` ORDER BY `id`
");
$upd_stmt = \Froxlor\Database\Database::prepare("
UPDATE `" . TABLE_MAIL_USERS . "` SET `mboxsize` = :size WHERE `id` = :id
");
while ($maildir = $maildirs_stmt->fetch(\PDO::FETCH_ASSOC)) {
$_maildir = makeCorrectDir($maildir['maildirpath']);
if (file_exists($_maildir) && is_dir($_maildir)) {
// mail-address allows many special characters, see http://en.wikipedia.org/wiki/Email_address#Local_part
$return = false;
$back = safe_exec('du -sk ' . escapeshellarg($_maildir), $return, array(
'|',
'&',
'`',
'$',
'~',
'?'
));
foreach ($back as $backrow) {
$emailusage = explode(' ', $backrow);
}
$emailusage = floatval($emailusage['0']);
// as freebsd does not have the -b flag for 'du' which gives
// the size in bytes, we use "-sk" for all and calculate from KiB
$emailusage *= 1024;
unset($back);
\Froxlor\Database\Database::pexecute($upd_stmt, array(
'size' => $emailusage,
'id' => $maildir['id']
));
} else {
\Froxlor\FroxlorLogger::getInstanceOf()->logAction(CRON_ACTION, LOG_WARNING, 'maildir ' . $_maildir . ' does not exist');
}
}
}
}

View File

@@ -171,7 +171,7 @@ while ($row = $result_tasks_stmt->fetch(PDO::FETCH_ASSOC)) {
if (Settings::Get('system.nssextrausers') == 1) if (Settings::Get('system.nssextrausers') == 1)
{ {
// explicitly create files after user has been created to avoid unknown user issues for apache/php-fpm when task#1 runs after this // explicitly create files after user has been created to avoid unknown user issues for apache/php-fpm when task#1 runs after this
include_once makeCorrectFile(FROXLOR_INSTALL_DIR.'/scripts/classes/class.Extrausers.php'); include_once makeCorrectFile(\Froxlor\Froxlor::getInstallDir().'/scripts/classes/class.Extrausers.php');
Extrausers::generateFiles($cronlog); Extrausers::generateFiles($cronlog);
} }

View File

@@ -124,9 +124,9 @@ function awstatsGenerateIndex($domain, $outputdir) {
); );
// File names // File names
$index_file = FROXLOR_INSTALL_DIR.'/templates/misc/awstats/index.html'; $index_file = \Froxlor\Froxlor::getInstallDir().'/templates/misc/awstats/index.html';
$index_file = makeCorrectFile($index_file); $index_file = makeCorrectFile($index_file);
$nav_file = FROXLOR_INSTALL_DIR.'/templates/misc/awstats/nav.html'; $nav_file = \Froxlor\Froxlor::getInstallDir().'/templates/misc/awstats/nav.html';
$nav_file = makeCorrectFile($nav_file); $nav_file = makeCorrectFile($nav_file);
// Write the index file // Write the index file

View File

@@ -68,9 +68,9 @@ if ((int)Settings::Get('system.report_webmax') > 0)
} }
// include english language file (fallback) // include english language file (fallback)
include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/lng/english.lng.php'); include_once makeCorrectFile(\Froxlor\Froxlor::getInstallDir() . '/lng/english.lng.php');
// include admin/customer language file // include admin/customer language file
include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/' . $langfile); include_once makeCorrectFile(\Froxlor\Froxlor::getInstallDir() . '/' . $langfile);
// Get mail templates from database; the ones from 'admin' are fetched for fallback // Get mail templates from database; the ones from 'admin' are fetched for fallback
$result2_stmt = Database::prepare(" $result2_stmt = Database::prepare("
@@ -158,9 +158,9 @@ if ((int)Settings::Get('system.report_webmax') > 0)
} }
// include english language file (fallback) // include english language file (fallback)
include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/lng/english.lng.php'); include_once makeCorrectFile(\Froxlor\Froxlor::getInstallDir() . '/lng/english.lng.php');
// include admin/customer language file // include admin/customer language file
include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/' . $langfile); include_once makeCorrectFile(\Froxlor\Froxlor::getInstallDir() . '/' . $langfile);
// Get mail templates from database; the ones from 'admin' are fetched for fallback // Get mail templates from database; the ones from 'admin' are fetched for fallback
$result2_stmt = Database::prepare(" $result2_stmt = Database::prepare("

View File

@@ -108,9 +108,9 @@ if ((int)Settings::Get('system.report_trafficmax') > 0)
} }
// include english language file (fallback) // include english language file (fallback)
include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/lng/english.lng.php'); include_once makeCorrectFile(\Froxlor\Froxlor::getInstallDir() . '/lng/english.lng.php');
// include admin/customer language file // include admin/customer language file
include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/' . $langfile); include_once makeCorrectFile(\Froxlor\Froxlor::getInstallDir() . '/' . $langfile);
// Get mail templates from database; the ones from 'admin' are fetched for fallback // Get mail templates from database; the ones from 'admin' are fetched for fallback
$result2_stmt = Database::prepare(" $result2_stmt = Database::prepare("
@@ -206,9 +206,9 @@ if ((int)Settings::Get('system.report_trafficmax') > 0)
} }
// include english language file (fallback) // include english language file (fallback)
include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/lng/english.lng.php'); include_once makeCorrectFile(\Froxlor\Froxlor::getInstallDir() . '/lng/english.lng.php');
// include admin/customer language file // include admin/customer language file
include_once makeCorrectFile(FROXLOR_INSTALL_DIR . '/' . $langfile); include_once makeCorrectFile(\Froxlor\Froxlor::getInstallDir() . '/' . $langfile);
// Get mail templates from database; the ones from 'admin' are fetched for fallback // Get mail templates from database; the ones from 'admin' are fetched for fallback
$result2_stmt = Database::prepare(" $result2_stmt = Database::prepare("

View File

@@ -239,7 +239,7 @@ class Database
} }
// include userdata.inc.php // include userdata.inc.php
require FROXLOR_INSTALL_DIR . "/lib/userdata.inc.php"; require \Froxlor\Froxlor::getInstallDir() . "/lib/userdata.inc.php";
// le format // le format
if (self::$_needroot == true && isset($sql['root_user']) && isset($sql['root_password']) && (! isset($sql_root) || ! is_array($sql_root))) { if (self::$_needroot == true && isset($sql['root_user']) && isset($sql['root_password']) && (! isset($sql_root) || ! is_array($sql_root))) {
@@ -353,7 +353,7 @@ class Database
global $userinfo, $theme, $linker; global $userinfo, $theme, $linker;
// include userdata.inc.php // include userdata.inc.php
require FROXLOR_INSTALL_DIR . "/lib/userdata.inc.php"; require \Froxlor\Froxlor::getInstallDir() . "/lib/userdata.inc.php";
// le format // le format
if (isset($sql['root_user']) && isset($sql['root_password']) && (! isset($sql_root) || ! is_array($sql_root))) { if (isset($sql['root_user']) && isset($sql['root_password']) && (! isset($sql_root) || ! is_array($sql_root))) {
@@ -390,7 +390,7 @@ class Database
* log to a file, so we can actually ask people for the error * log to a file, so we can actually ask people for the error
* (no one seems to find the stuff in the syslog) * (no one seems to find the stuff in the syslog)
*/ */
$sl_dir = makeCorrectDir(FROXLOR_INSTALL_DIR . "/logs/"); $sl_dir = makeCorrectDir(\Froxlor\Froxlor::getInstallDir() . "/logs/");
if (! file_exists($sl_dir)) { if (! file_exists($sl_dir)) {
@mkdir($sl_dir, 0755); @mkdir($sl_dir, 0755);
} }

View File

@@ -182,9 +182,9 @@ class FileDir
} else { } else {
$destination = self::makeCorrectDir($destination); $destination = self::makeCorrectDir($destination);
if ($logger !== null) { if ($logger !== null) {
$logger->logAction(CRON_ACTION, LOG_NOTICE, 'Running: cp -a ' . FROXLOR_INSTALL_DIR . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination)); $logger->logAction(CRON_ACTION, LOG_NOTICE, 'Running: cp -a ' . \Froxlor\Froxlor::getInstallDir() . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination));
} }
self::safe_exec('cp -a ' . FROXLOR_INSTALL_DIR . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination)); self::safe_exec('cp -a ' . \Froxlor\Froxlor::getInstallDir() . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination));
} }
} }
return; return;

View File

@@ -53,4 +53,46 @@ final class Froxlor
{ {
return self::getFullVersion() . ' (' . self::DBVERSION . ')'; return self::getFullVersion() . ' (' . self::DBVERSION . ')';
} }
/**
* Function hasUpdates
*
* checks if a given version is not equal the current one
*
* @param string $to_check
* version to check, if empty current version is used
*
* @return bool true if version to check does not match, else false
*/
public static function hasUpdates($to_check = null)
{
if (empty($to_check)) {
$to_check = self::VERSION;
}
if (Settings::Get('panel.version') == null || Settings::Get('panel.version') != $to_check) {
return true;
}
return false;
}
/**
* Function hasUpdates
*
* checks if a given database-version is not equal the current one
*
* @param int $to_check
* version to check, if empty current dbversion is used
*
* @return bool true if version to check does not match, else false
*/
public static function hasDbUpdates($to_check = null)
{
if (empty($to_check)) {
$to_check = self::DBVERSION;
}
if (Settings::Get('panel.db_version') == null || Settings::Get('panel.db_version') != $to_check) {
return true;
}
return false;
}
} }

View File

@@ -360,8 +360,8 @@ class ConfigDaemon {
} elseif (preg_match('/^sql\.(.*)$/', $matches[1], $match)) { } elseif (preg_match('/^sql\.(.*)$/', $matches[1], $match)) {
if (is_null($this->_sqldata_cache)) { if (is_null($this->_sqldata_cache)) {
// read in sql-data (if exists) // read in sql-data (if exists)
if (file_exists(FROXLOR_INSTALL_DIR."/lib/userdata.inc.php")) { if (file_exists(\Froxlor\Froxlor::getInstallDir()."/lib/userdata.inc.php")) {
require FROXLOR_INSTALL_DIR."/lib/userdata.inc.php"; require \Froxlor\Froxlor::getInstallDir()."/lib/userdata.inc.php";
unset($sql_root); unset($sql_root);
$this->_sqldata_cache = $sql; $this->_sqldata_cache = $sql;
} }

View File

@@ -60,7 +60,7 @@ class ConfigIO
private function _cleanErrLogs() private function _cleanErrLogs()
{ {
$err_dir = makeCorrectDir(FROXLOR_INSTALL_DIR . "/logs/"); $err_dir = makeCorrectDir(\Froxlor\Froxlor::getInstallDir() . "/logs/");
if (@is_dir($err_dir)) { if (@is_dir($err_dir)) {
// now get rid of old stuff // now get rid of old stuff
// (but append /*.log so we don't delete the directory) // (but append /*.log so we don't delete the directory)

View File

@@ -3860,7 +3860,7 @@ aliases: files
</commands> </commands>
<!-- instead of just restarting apache, we let the cronjob do all the <!-- instead of just restarting apache, we let the cronjob do all the
dirty work --> dirty work -->
<command><![CDATA[php {{const.FROXLOR_INSTALL_DIR}}/scripts/froxlor_master_cronjob.php --force]]></command> <command><![CDATA[php {{const.\Froxlor\Froxlor::getInstallDir()}}/scripts/froxlor_master_cronjob.php --force]]></command>
</daemon> </daemon>
<!-- PHP-FPM --> <!-- PHP-FPM -->
<daemon name="php-fpm" title="PHP-FPM (alternative to mod_php)"> <daemon name="php-fpm" title="PHP-FPM (alternative to mod_php)">
@@ -3898,7 +3898,7 @@ aliases: files
</commands> </commands>
<!-- instead of just restarting apache, we let the cronjob do all the <!-- instead of just restarting apache, we let the cronjob do all the
dirty work --> dirty work -->
<command><![CDATA[php {{const.FROXLOR_INSTALL_DIR}}/scripts/froxlor_master_cronjob.php --force]]></command> <command><![CDATA[php {{const.\Froxlor\Froxlor::getInstallDir()}}/scripts/froxlor_master_cronjob.php --force]]></command>
</daemon> </daemon>
</service> </service>
</services> </services>

View File

@@ -4724,7 +4724,7 @@ aliases: files
</commands> </commands>
<!-- instead of just restarting apache, we let the cronjob do all the <!-- instead of just restarting apache, we let the cronjob do all the
dirty work --> dirty work -->
<command><![CDATA[php {{const.FROXLOR_INSTALL_DIR}}/scripts/froxlor_master_cronjob.php --force]]></command> <command><![CDATA[php {{const.\Froxlor\Froxlor::getInstallDir()}}/scripts/froxlor_master_cronjob.php --force]]></command>
</daemon> </daemon>
<!-- PHP-FPM --> <!-- PHP-FPM -->
<daemon name="php-fpm" title="PHP-FPM (alternative to mod_php)"> <daemon name="php-fpm" title="PHP-FPM (alternative to mod_php)">
@@ -4767,7 +4767,7 @@ aliases: files
</commands> </commands>
<!-- instead of just restarting apache, we let the cronjob do all the <!-- instead of just restarting apache, we let the cronjob do all the
dirty work --> dirty work -->
<command><![CDATA[php {{const.FROXLOR_INSTALL_DIR}}/scripts/froxlor_master_cronjob.php --force]]></command> <command><![CDATA[php {{const.\Froxlor\Froxlor::getInstallDir()}}/scripts/froxlor_master_cronjob.php --force]]></command>
</daemon> </daemon>
</service> </service>
</services> </services>

View File

@@ -1723,7 +1723,7 @@ aliases: files
</commands> </commands>
<!-- instead of just restarting apache, we let the cronjob do all the <!-- instead of just restarting apache, we let the cronjob do all the
dirty work --> dirty work -->
<command><![CDATA[php {{const.FROXLOR_INSTALL_DIR}}/scripts/froxlor_master_cronjob.php --force]]></command> <command><![CDATA[php {{const.\Froxlor\Froxlor::getInstallDir()}}/scripts/froxlor_master_cronjob.php --force]]></command>
</daemon> </daemon>
<!-- PHP-FPM --> <!-- PHP-FPM -->
<daemon name="php-fpm" title="PHP-FPM (alternative to mod_php)"> <daemon name="php-fpm" title="PHP-FPM (alternative to mod_php)">
@@ -1766,7 +1766,7 @@ aliases: files
</commands> </commands>
<!-- instead of just restarting apache, we let the cronjob do all the <!-- instead of just restarting apache, we let the cronjob do all the
dirty work --> dirty work -->
<command><![CDATA[php {{const.FROXLOR_INSTALL_DIR}}/scripts/froxlor_master_cronjob.php --force]]></command> <command><![CDATA[php {{const.\Froxlor\Froxlor::getInstallDir()}}/scripts/froxlor_master_cronjob.php --force]]></command>
</daemon> </daemon>
</service> </service>
</services> </services>

View File

@@ -4624,7 +4624,7 @@ aliases: files
</commands> </commands>
<!-- instead of just restarting apache, we let the cronjob do all the <!-- instead of just restarting apache, we let the cronjob do all the
dirty work --> dirty work -->
<command><![CDATA[php {{const.FROXLOR_INSTALL_DIR}}/scripts/froxlor_master_cronjob.php --force]]></command> <command><![CDATA[php {{const.\Froxlor\Froxlor::getInstallDir()}}/scripts/froxlor_master_cronjob.php --force]]></command>
</daemon> </daemon>
<!-- PHP-FPM --> <!-- PHP-FPM -->
<daemon name="php-fpm" title="PHP-FPM (alternative to mod_php)"> <daemon name="php-fpm" title="PHP-FPM (alternative to mod_php)">
@@ -4661,7 +4661,7 @@ aliases: files
</commands> </commands>
<!-- instead of just restarting apache, we let the cronjob do all the <!-- instead of just restarting apache, we let the cronjob do all the
dirty work --> dirty work -->
<command><![CDATA[php {{const.FROXLOR_INSTALL_DIR}}/scripts/froxlor_master_cronjob.php --force]]></command> <command><![CDATA[php {{const.\Froxlor\Froxlor::getInstallDir()}}/scripts/froxlor_master_cronjob.php --force]]></command>
</daemon> </daemon>
</service> </service>
</services> </services>

View File

@@ -1737,7 +1737,7 @@ aliases: files
</commands> </commands>
<!-- instead of just restarting apache, we let the cronjob do all the <!-- instead of just restarting apache, we let the cronjob do all the
dirty work --> dirty work -->
<command><![CDATA[php {{const.FROXLOR_INSTALL_DIR}}/scripts/froxlor_master_cronjob.php --force]]></command> <command><![CDATA[php {{const.\Froxlor\Froxlor::getInstallDir()}}/scripts/froxlor_master_cronjob.php --force]]></command>
</daemon> </daemon>
<!-- PHP-FPM --> <!-- PHP-FPM -->
<daemon name="php-fpm" title="PHP-FPM (alternative to mod_php)"> <daemon name="php-fpm" title="PHP-FPM (alternative to mod_php)">
@@ -1780,7 +1780,7 @@ aliases: files
</commands> </commands>
<!-- instead of just restarting apache, we let the cronjob do all the <!-- instead of just restarting apache, we let the cronjob do all the
dirty work --> dirty work -->
<command><![CDATA[php {{const.FROXLOR_INSTALL_DIR}}/scripts/froxlor_master_cronjob.php --force]]></command> <command><![CDATA[php {{const.\Froxlor\Froxlor::getInstallDir()}}/scripts/froxlor_master_cronjob.php --force]]></command>
</daemon> </daemon>
</service> </service>
</services> </services>

View File

@@ -4635,7 +4635,7 @@ aliases: files
</commands> </commands>
<!-- instead of just restarting apache, we let the cronjob do all the <!-- instead of just restarting apache, we let the cronjob do all the
dirty work --> dirty work -->
<command><![CDATA[php {{const.FROXLOR_INSTALL_DIR}}/scripts/froxlor_master_cronjob.php --force]]></command> <command><![CDATA[php {{const.\Froxlor\Froxlor::getInstallDir()}}/scripts/froxlor_master_cronjob.php --force]]></command>
</daemon> </daemon>
<!-- PHP-FPM --> <!-- PHP-FPM -->
<daemon name="php-fpm" title="PHP-FPM (alternative to mod_php)"> <daemon name="php-fpm" title="PHP-FPM (alternative to mod_php)">
@@ -4672,7 +4672,7 @@ aliases: files
</commands> </commands>
<!-- instead of just restarting apache, we let the cronjob do all the <!-- instead of just restarting apache, we let the cronjob do all the
dirty work --> dirty work -->
<command><![CDATA[php {{const.FROXLOR_INSTALL_DIR}}/scripts/froxlor_master_cronjob.php --force]]></command> <command><![CDATA[php {{const.\Froxlor\Froxlor::getInstallDir()}}/scripts/froxlor_master_cronjob.php --force]]></command>
</daemon> </daemon>
</service> </service>
</services> </services>

View File

@@ -47,23 +47,18 @@ $lockFilename = 'froxlor_' . $basename . '.lock-';
$lockfName = $lockFilename . getmypid(); $lockfName = $lockFilename . getmypid();
$lockfile = $lockdir . $lockfName; $lockfile = $lockdir . $lockfName;
// guess the froxlor installation path
// normally you should not need to modify this script anymore, if your
// froxlor installation isn't in /var/www/froxlor
define('FROXLOR_INSTALL_DIR', dirname(dirname(__FILE__)));
// create and open the lockfile! // create and open the lockfile!
$keepLockFile = false; $keepLockFile = false;
$debugHandler = fopen($lockfile, 'w'); $debugHandler = fopen($lockfile, 'w');
fwrite($debugHandler, 'Setting Lockfile to ' . $lockfile . "\n"); fwrite($debugHandler, 'Setting Lockfile to ' . $lockfile . "\n");
fwrite($debugHandler, 'Setting Froxlor installation path to ' . FROXLOR_INSTALL_DIR . "\n"); fwrite($debugHandler, 'Setting Froxlor installation path to ' . \Froxlor\Froxlor::getInstallDir() . "\n");
if (! file_exists(FROXLOR_INSTALL_DIR . '/lib/userdata.inc.php')) { if (! file_exists(\Froxlor\Froxlor::getInstallDir() . '/lib/userdata.inc.php')) {
die("Froxlor does not seem to be installed yet - skipping cronjob"); die("Froxlor does not seem to be installed yet - skipping cronjob");
} }
// Includes the Usersettings eg. MySQL-Username/Passwort etc. // Includes the Usersettings eg. MySQL-Username/Passwort etc.
require FROXLOR_INSTALL_DIR . '/lib/userdata.inc.php'; require \Froxlor\Froxlor::getInstallDir() . '/lib/userdata.inc.php';
fwrite($debugHandler, 'Userdatas included' . "\n"); fwrite($debugHandler, 'Userdatas included' . "\n");
// Legacy sql-root-information // Legacy sql-root-information
@@ -81,10 +76,10 @@ if (isset($sql['root_user']) && isset($sql['root_password']) && (! isset($sql_ro
} }
// Includes the Functions // Includes the Functions
require FROXLOR_INSTALL_DIR . '/lib/functions.php'; require \Froxlor\Froxlor::getInstallDir() . '/lib/functions.php';
// Includes the MySQL-Tabledefinitions etc. // Includes the MySQL-Tabledefinitions etc.
require FROXLOR_INSTALL_DIR . '/lib/tables.inc.php'; require \Froxlor\Froxlor::getInstallDir() . '/lib/tables.inc.php';
fwrite($debugHandler, 'Table definitions included' . "\n"); fwrite($debugHandler, 'Table definitions included' . "\n");
// try database connection, it will throw // try database connection, it will throw
@@ -149,7 +144,7 @@ while ($fName = readdir($lockDirHandle)) {
* whether the permission of the files are still correct * whether the permission of the files are still correct
*/ */
fwrite($debugHandler, 'Checking froxlor file permissions' . "\n"); fwrite($debugHandler, 'Checking froxlor file permissions' . "\n");
$_mypath = makeCorrectDir(FROXLOR_INSTALL_DIR); $_mypath = makeCorrectDir(\Froxlor\Froxlor::getInstallDir());
if (((int) \Froxlor\Settings::Get('system.mod_fcgid') == 1 && (int) \Froxlor\Settings::Get('system.mod_fcgid_ownvhost') == 1) || ((int) \Froxlor\Settings::Get('phpfpm.enabled') == 1 && (int) \Froxlor\Settings::Get('phpfpm.enabled_ownvhost') == 1)) { if (((int) \Froxlor\Settings::Get('system.mod_fcgid') == 1 && (int) \Froxlor\Settings::Get('system.mod_fcgid_ownvhost') == 1) || ((int) \Froxlor\Settings::Get('phpfpm.enabled') == 1 && (int) \Froxlor\Settings::Get('phpfpm.enabled_ownvhost') == 1)) {
$user = \Froxlor\Settings::Get('system.mod_fcgid_httpuser'); $user = \Froxlor\Settings::Get('system.mod_fcgid_httpuser');
@@ -175,7 +170,7 @@ $cronlog = \Froxlor\FroxlorLogger::getInstanceOf(array(
)); ));
fwrite($debugHandler, 'Logger has been included' . "\n"); fwrite($debugHandler, 'Logger has been included' . "\n");
if (hasUpdates($version) || hasDbUpdates($dbversion)) { if (\Froxlor\Froxlor::hasUpdates() || \Froxlor\Froxlor::hasDbUpdates()) {
if (\Froxlor\Settings::Get('system.cron_allowautoupdate') == null || \Froxlor\Settings::Get('system.cron_allowautoupdate') == 0) { if (\Froxlor\Settings::Get('system.cron_allowautoupdate') == null || \Froxlor\Settings::Get('system.cron_allowautoupdate') == 0) {
/** /**
* Do not proceed further if the Database version is not the same as the script version * Do not proceed further if the Database version is not the same as the script version
@@ -184,7 +179,7 @@ if (hasUpdates($version) || hasDbUpdates($dbversion)) {
unlink($lockfile); unlink($lockfile);
$errormessage = "Version of file doesn't match version of database. Exiting...\n\n"; $errormessage = "Version of file doesn't match version of database. Exiting...\n\n";
$errormessage .= "Possible reason: Froxlor update\n"; $errormessage .= "Possible reason: Froxlor update\n";
$errormessage .= "Information: Current version in database: " . \Froxlor\Settings::Get('panel.version') . " (DB: " . \Froxlor\Settings::Get('panel.db_version') . ") - version of Froxlor files: " . $version . " (DB: " . $dbversion . ")\n"; $errormessage .= "Information: Current version in database: " . \Froxlor\Settings::Get('panel.version') . "-" . \Froxlor\Froxlor::BRANDING . " (DB: " . \Froxlor\Settings::Get('panel.db_version') . ") - version of Froxlor files: " . \Froxlor\Froxlor::getVersionString() . ")\n";
$errormessage .= "Solution: Please visit your Foxlor admin interface for further information.\n"; $errormessage .= "Solution: Please visit your Foxlor admin interface for further information.\n";
dieWithMail($errormessage); dieWithMail($errormessage);
} }
@@ -201,7 +196,7 @@ if (hasUpdates($version) || hasDbUpdates($dbversion)) {
fwrite($debugHandler, "*** WARNING *** - If you don't want this to happen in the future consider removing the --allow-autoupdate flag from the cronjob\n"); fwrite($debugHandler, "*** WARNING *** - If you don't want this to happen in the future consider removing the --allow-autoupdate flag from the cronjob\n");
// including update procedures // including update procedures
define('_CRON_UPDATE', 1); define('_CRON_UPDATE', 1);
include_once FROXLOR_INSTALL_DIR . '/install/updatesql.php'; include_once \Froxlor\Froxlor::getInstallDir() . '/install/updatesql.php';
// pew - everything went better than expected // pew - everything went better than expected
$cronlog->logAction(CRON_ACTION, LOG_WARNING, 'Automatic update done - you should check your settings to be sure everything is fine'); $cronlog->logAction(CRON_ACTION, LOG_WARNING, 'Automatic update done - you should check your settings to be sure everything is fine');
fwrite($debugHandler, '*** WARNING *** - Automatic update done - you should check your settings to be sure everything is fine' . "\n"); fwrite($debugHandler, '*** WARNING *** - Automatic update done - you should check your settings to be sure everything is fine' . "\n");

View File

@@ -18,10 +18,10 @@
*/ */
// check for cron.d-generation task and create it if necessary // check for cron.d-generation task and create it if necessary
checkCrondConfigurationFile(); \Froxlor\Cron\CronConfig::checkCrondConfigurationFile();
if (\Froxlor\Settings::Get('logger.log_cron') == '1') { if (\Froxlor\Settings::Get('logger.log_cron') == '1') {
$cronlog->setCronLog(0); \Froxlor\FroxlorLogger::getInstanceOf()->setCronLog(0);
fwrite($debugHandler, 'Logging for cron has been shutdown' . "\n"); fwrite($debugHandler, 'Logging for cron has been shutdown' . "\n");
} }

View File

@@ -63,9 +63,9 @@ function storeDefaultIndex($loginname = null, $destination = null, $logger = nul
} else { } else {
$destination = makeCorrectDir($destination); $destination = makeCorrectDir($destination);
if ($logger !== null) { if ($logger !== null) {
$logger->logAction(CRON_ACTION, LOG_NOTICE, 'Running: cp -a ' . FROXLOR_INSTALL_DIR . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination)); $logger->logAction(CRON_ACTION, LOG_NOTICE, 'Running: cp -a ' . \Froxlor\Froxlor::getInstallDir() . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination));
} }
safe_exec('cp -a ' . FROXLOR_INSTALL_DIR . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination)); safe_exec('cp -a ' . \Froxlor\Froxlor::getInstallDir() . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination));
} }
} }
return; return;

View File

@@ -1,140 +0,0 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2014 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
/**
* 1st: check for task of generation
* 2nd: if task found, generate cron.d-file
* 3rd: maybe restart cron?
*/
function checkCrondConfigurationFile() {
// check for task
$result_tasks_stmt = Database::query("
SELECT * FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = '99'
");
$num_results = Database::num_rows();
// is there a task for re-generating the cron.d-file?
if ($num_results > 0) {
// get all crons and their intervals
if (isFreeBSD()) {
// FreeBSD does not need a header as we are writing directly to the crontab
$cronfile = "\n";
} else {
$cronfile = "# automatically generated cron-configuration by froxlor\n";
$cronfile.= "# do not manually edit this file as it will be re-generated periodically.\n";
$cronfile.= "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n#\n";
}
// get all the crons
$result_stmt = Database::query("
SELECT * FROM `" . TABLE_PANEL_CRONRUNS . "` WHERE `isactive` = '1'
");
$hour_delay = 0;
$day_delay = 5;
$month_delay = 7;
while ($row_cronentry = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
// create cron.d-entry
if (preg_match("/(\d+) (MINUTE|HOUR|DAY|WEEK|MONTH)/", $row_cronentry['interval'], $matches)) {
if ($matches[1] == 1) {
$minvalue = "*";
} else {
$minvalue = "*/".$matches[1];
}
switch($matches[2]) {
case "MINUTE":
$cronfile .= $minvalue . " * * * * ";
break;
case "HOUR":
$cronfile .= $hour_delay." " . $minvalue . " * * * ";
$hour_delay += 3;
break;
case "DAY":
if ($row_cronentry['cronfile'] == 'traffic') {
// traffic at exactly 0:00 o'clock
$cronfile .= "0 0 " . $minvalue . " * * ";
} else {
$cronfile .= $day_delay." 0 " . $minvalue . " * * ";
$day_delay += 5;
}
break;
case "MONTH":
$cronfile .= $month_delay." 0 1 " . $minvalue . " * ";
$month_delay += 7;
break;
case "WEEK":
$cronfile .= $day_delay." 0 " . ($matches[1] * 7) . " * * ";
$day_delay += 5;
break;
}
// create entry-line
$binpath = Settings::Get("system.croncmdline");
// fallback as it is important
if ($binpath === null) {
$binpath = "/usr/bin/nice -n 5 /usr/bin/php5 -q";
}
$cronfile .= "root " . $binpath." " . FROXLOR_INSTALL_DIR . "/scripts/froxlor_master_cronjob.php --" . $row_cronentry['cronfile'] . " 1> /dev/null\n";
}
}
if (isFreeBSD()) {
// FreeBSD handles the cron-stuff in another way. We need to directly
// write to the crontab file as there is not cron.d/froxlor file
// (settings for system.cronconfig should be set correctly of course)
$crontab = file_get_contents(Settings::Get("system.cronconfig"));
if ($crontab === false) {
die("Oh snap, we cannot read the crontab file. This should not happen.\nPlease check the path and permissions, the cron will keep trying if you don't stop the cron-service.\n\n");
}
// now parse out / replace our entries
$crontablines = explode("\n", $crontab);
$newcrontab = "";
foreach ($crontablines as $ctl) {
$ctl = trim($ctl);
if (!empty($ctl) && !preg_match("/(.*)froxlor_master_cronjob\.php(.*)/", $ctl)) {
$newcrontab .= $ctl."\n";
}
}
// re-assemble old-content + new froxlor-content
$newcrontab .= $cronfile;
// now continue with writing the file
$cronfile = $newcrontab;
}
// write the file
if (file_put_contents(Settings::Get("system.cronconfig"), $cronfile) === false) {
// oh snap cannot create new crond-file
die("Oh snap, we cannot create the cron-file. This should not happen.\nPlease check the path and permissions, the cron will keep trying if you don't stop the cron-service.\n\n");
}
// correct permissions
chmod(Settings::Get("system.cronconfig"), 0640);
// remove all re-generation tasks
Database::query("DELETE FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = '99'");
// run reload command
safe_exec(escapeshellcmd(Settings::Get('system.crondreload')));
}
return true;
}

View File

@@ -62,7 +62,7 @@ function createAWStatsConf($logFile, $siteDomain, $hostAliases, $customerDocroot
// File names // File names
$domain_file = makeCorrectFile(Settings::Get('system.awstats_conf').'/awstats.' . $siteDomain . '.conf'); $domain_file = makeCorrectFile(Settings::Get('system.awstats_conf').'/awstats.' . $siteDomain . '.conf');
$model_file = FROXLOR_INSTALL_DIR.'/templates/misc/awstats/awstats.froxlor.model.conf'; $model_file = \Froxlor\Froxlor::getInstallDir().'/templates/misc/awstats/awstats.froxlor.model.conf';
$model_file = makeCorrectFile($model_file); $model_file = makeCorrectFile($model_file);
// Test if the file exists // Test if the file exists

View File

@@ -22,7 +22,7 @@
*/ */
function getThemes() { function getThemes() {
$themespath = makeCorrectDir(FROXLOR_INSTALL_DIR.'/templates/'); $themespath = makeCorrectDir(\Froxlor\Froxlor::getInstallDir().'/templates/');
$themes_available = array(); $themes_available = array();
if (is_dir($themespath)) { if (is_dir($themespath)) {

View File

@@ -26,9 +26,9 @@ function phpErrHandler($errno, $errstr, $errfile, $errline, $errcontext) {
$theme = "Sparkle"; $theme = "Sparkle";
} }
// prevent possible file-path-disclosure // prevent possible file-path-disclosure
$errfile = str_replace(FROXLOR_INSTALL_DIR, "", $errfile); $errfile = str_replace(\Froxlor\Froxlor::getInstallDir(), "", $errfile);
// if we're not on the shell, output a nicer error-message // if we're not on the shell, output a nicer error-message
$err_hint = file_get_contents(FROXLOR_INSTALL_DIR.'/templates/'.$theme.'/misc/phperrornice.tpl'); $err_hint = file_get_contents(\Froxlor\Froxlor::getInstallDir().'/templates/'.$theme.'/misc/phperrornice.tpl');
// replace values // replace values
$err_hint = str_replace("<TEXT>", '#'.$errno.' '.$errstr, $err_hint); $err_hint = str_replace("<TEXT>", '#'.$errno.' '.$errstr, $err_hint);
$err_hint = str_replace("<DEBUG>", $errfile.':'.$errline, $err_hint); $err_hint = str_replace("<DEBUG>", $errfile.':'.$errline, $err_hint);

View File

@@ -76,24 +76,7 @@ function isFroxlorVersion($to_check = null) {
return false; return false;
} }
/**
* Function hasUpdates
*
* checks if a given version is not equal the current one
*
* @param string $to_check version to check
*
* @return bool true if version to check does not match, else false
*/
function hasUpdates($to_check = null) {
if (Settings::Get('panel.version') == null
|| Settings::Get('panel.version') != $to_check
) {
return true;
}
return false;
}
/** /**
* Function showUpdateStep * Function showUpdateStep
@@ -208,25 +191,6 @@ function isDatabaseVersion($to_check = null) {
return false; return false;
} }
/**
* Function hasUpdates
*
* checks if a given database-version is not equal the current one
*
* @param int $to_check version to check
*
* @return bool true if version to check does not match, else false
*/
function hasDbUpdates($to_check = null) {
if (Settings::Get('panel.db_version') == null
|| Settings::Get('panel.db_version') != $to_check
) {
return true;
}
return false;
}
/** /**
* Function updateToDbVersion * Function updateToDbVersion
* *

View File

@@ -1,44 +0,0 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Michael Kaufmann <mkaufmann@nutime.de>
* @author Daniel Reichelt <hacking@nachtgeist.net> (2016-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
function getLogLevelDesc($type) {
switch($type) {
case LOG_INFO:
$_type = 'information';
break;
case LOG_NOTICE:
$_type = 'notice';
break;
case LOG_WARNING:
$_type = 'warning';
break;
case LOG_ERR:
$_type = 'error';
break;
case LOG_CRIT:
$_type = 'critical';
break;
case LOG_DEBUG:
$_type = 'debug';
break;
default:
$_type = 'unknown';
break;
}
return $_type;
}

View File

@@ -72,27 +72,24 @@ $filename = htmlentities(basename($_SERVER['PHP_SELF']));
// define default theme for configurehint, etc. // define default theme for configurehint, etc.
$_deftheme = 'Sparkle'; $_deftheme = 'Sparkle';
// define installation directory
define('FROXLOR_INSTALL_DIR', dirname(dirname(__FILE__)));
// check whether the userdata file exists // check whether the userdata file exists
if (!file_exists(FROXLOR_INSTALL_DIR.'/lib/userdata.inc.php')) { if (!file_exists(\Froxlor\Froxlor::getInstallDir().'/lib/userdata.inc.php')) {
$config_hint = file_get_contents(FROXLOR_INSTALL_DIR.'/templates/'.$_deftheme.'/misc/configurehint.tpl'); $config_hint = file_get_contents(\Froxlor\Froxlor::getInstallDir().'/templates/'.$_deftheme.'/misc/configurehint.tpl');
$config_hint = str_replace("<CURRENT_YEAR>", date('Y', time()), $config_hint); $config_hint = str_replace("<CURRENT_YEAR>", date('Y', time()), $config_hint);
die($config_hint); die($config_hint);
} }
// check whether we can read the userdata file // check whether we can read the userdata file
if (!is_readable(FROXLOR_INSTALL_DIR.'/lib/userdata.inc.php')) { if (!is_readable(\Froxlor\Froxlor::getInstallDir().'/lib/userdata.inc.php')) {
// get possible owner // get possible owner
$posixusername = posix_getpwuid(posix_getuid()); $posixusername = posix_getpwuid(posix_getuid());
$posixgroup = posix_getgrgid(posix_getgid()); $posixgroup = posix_getgrgid(posix_getgid());
// get hint-template // get hint-template
$owner_hint = file_get_contents(FROXLOR_INSTALL_DIR.'/templates/'.$_deftheme.'/misc/ownershiphint.tpl'); $owner_hint = file_get_contents(\Froxlor\Froxlor::getInstallDir().'/templates/'.$_deftheme.'/misc/ownershiphint.tpl');
// replace values // replace values
$owner_hint = str_replace("<USER>", $posixusername['name'], $owner_hint); $owner_hint = str_replace("<USER>", $posixusername['name'], $owner_hint);
$owner_hint = str_replace("<GROUP>", $posixgroup['name'], $owner_hint); $owner_hint = str_replace("<GROUP>", $posixgroup['name'], $owner_hint);
$owner_hint = str_replace("<FROXLOR_INSTALL_DIR>", FROXLOR_INSTALL_DIR, $owner_hint); $owner_hint = str_replace("<\Froxlor\Froxlor::getInstallDir()>", \Froxlor\Froxlor::getInstallDir(), $owner_hint);
$owner_hint = str_replace("<CURRENT_YEAR>", date('Y', time()), $owner_hint); $owner_hint = str_replace("<CURRENT_YEAR>", date('Y', time()), $owner_hint);
// show // show
die($owner_hint); die($owner_hint);
@@ -101,12 +98,12 @@ if (!is_readable(FROXLOR_INSTALL_DIR.'/lib/userdata.inc.php')) {
/** /**
* Includes the Usersettings eg. MySQL-Username/Passwort etc. * Includes the Usersettings eg. MySQL-Username/Passwort etc.
*/ */
require FROXLOR_INSTALL_DIR.'/lib/userdata.inc.php'; require \Froxlor\Froxlor::getInstallDir().'/lib/userdata.inc.php';
if (!isset($sql) if (!isset($sql)
|| !is_array($sql) || !is_array($sql)
) { ) {
$config_hint = file_get_contents(FROXLOR_INSTALL_DIR.'/templates/'.$_deftheme.'/misc/configurehint.tpl'); $config_hint = file_get_contents(\Froxlor\Froxlor::getInstallDir().'/templates/'.$_deftheme.'/misc/configurehint.tpl');
$config_hint = str_replace("<CURRENT_YEAR>", date('Y', time()), $config_hint); $config_hint = str_replace("<CURRENT_YEAR>", date('Y', time()), $config_hint);
die($config_hint); die($config_hint);
} }
@@ -114,13 +111,13 @@ if (!isset($sql)
/** /**
* Includes the Functions * Includes the Functions
*/ */
require FROXLOR_INSTALL_DIR.'/lib/functions.php'; require \Froxlor\Froxlor::getInstallDir().'/lib/functions.php';
@set_error_handler('phpErrHandler'); @set_error_handler('phpErrHandler');
/** /**
* Includes the MySQL-Tabledefinitions etc. * Includes the MySQL-Tabledefinitions etc.
*/ */
require FROXLOR_INSTALL_DIR.'/lib/tables.inc.php'; require \Froxlor\Froxlor::getInstallDir().'/lib/tables.inc.php';
/** /**
* Create a new idna converter * Create a new idna converter

View File

@@ -74,7 +74,7 @@ for ($x = 1; $x < count($argv); $x++) {
$cronlog->setCronDebugFlag(defined('CRON_DEBUG_FLAG')); $cronlog->setCronDebugFlag(defined('CRON_DEBUG_FLAG'));
$tasks_cnt_stmt = Database::query("SELECT COUNT(*) as jobcnt FROM `panel_tasks`"); $tasks_cnt_stmt = \Froxlor\Database\Database::query("SELECT COUNT(*) as jobcnt FROM `panel_tasks`");
$tasks_cnt = $tasks_cnt_stmt->fetch(PDO::FETCH_ASSOC); $tasks_cnt = $tasks_cnt_stmt->fetch(PDO::FETCH_ASSOC);
// do we have anything to include? // do we have anything to include?
@@ -88,14 +88,13 @@ if (count($jobs_to_run) > 0) {
if ($tasks_cnt['jobcnt'] > 0) if ($tasks_cnt['jobcnt'] > 0)
{ {
if (Settings::Get('system.nssextrausers') == 1) if (\Froxlor\Settings::Get('system.nssextrausers') == 1)
{ {
include_once makeCorrectFile(FROXLOR_INSTALL_DIR.'/scripts/classes/class.Extrausers.php'); \Froxlor\Cron\System\Extrausers::generateFiles($cronlog);
Extrausers::generateFiles($cronlog);
} }
// clear NSCD cache if using fcgid or fpm, #1570 // clear NSCD cache if using fcgid or fpm, #1570
if (Settings::Get('system.mod_fcgid') == 1 || (int)Settings::Get('phpfpm.enabled') == 1) { if (\Froxlor\Settings::Get('system.mod_fcgid') == 1 || (int)\Froxlor\Settings::Get('phpfpm.enabled') == 1) {
$false_val = false; $false_val = false;
safe_exec('nscd -i passwd 1> /dev/null', $false_val, array('>')); safe_exec('nscd -i passwd 1> /dev/null', $false_val, array('>'));
safe_exec('nscd -i group 1> /dev/null', $false_val, array('>')); safe_exec('nscd -i group 1> /dev/null', $false_val, array('>'));

View File

@@ -1,115 +0,0 @@
<?php if (!defined('MASTER_CRONJOB')) die('You cannot access this file directly!');
/**
* This file is part of the Froxlor project.
* Copyright (c) 2016 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Michael Kaufmann <mkaufmann@nutime.de>
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Cron
*
* @since 0.9.35.1
*
*/
// Check Traffic-Lock
if (function_exists('pcntl_fork')) {
$BackupLock = makeCorrectFile(dirname($lockfile)."/froxlor_cron_backup.lock");
if (file_exists($BackupLock)
&& is_numeric($BackupPid=file_get_contents($BackupLock))
) {
if (function_exists('posix_kill')) {
$BackupPidStatus = @posix_kill($BackupPid,0);
} else {
system("kill -CHLD " . $BackupPid . " 1> /dev/null 2> /dev/null", $BackupPidStatus);
$BackupPidStatus = $BackupPidStatus ? false : true;
}
if ($BackupPidStatus) {
$cronlog->logAction(CRON_ACTION, LOG_INFO, 'Backup run already in progress');
return 1;
}
}
// Create Backup Log and Fork
// We close the database - connection before we fork, so we don't share resources with the child
Database::needRoot(false); // this forces the connection to be set to null
$BackupPid = pcntl_fork();
// Parent
if ($BackupPid) {
file_put_contents($BackupLock, $BackupPid);
// unnecessary to recreate database connection here
return 0;
}
//Child
elseif ($BackupPid == 0) {
posix_setsid();
fclose($debugHandler);
// re-create db
Database::needRoot(false);
}
//Fork failed
else {
return 1;
}
} else {
if (extension_loaded('pcntl')) {
$msg = "PHP compiled with pcntl but pcntl_fork function is not available.";
} else {
$msg = "PHP compiled without pcntl.";
}
$cronlog->logAction(CRON_ACTION, LOG_WARNING, $msg." Not forking backup-cron, this may take a long time!");
}
$cronlog->logAction(CRON_ACTION, LOG_INFO, 'cron_backup: started - creating customer backup');
$result_tasks_stmt = Database::query("
SELECT * FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = '20' ORDER BY `id` ASC
");
$del_stmt = Database::prepare("DELETE FROM `" . TABLE_PANEL_TASKS . "` WHERE `id` = :id");
$all_jobs = $result_tasks_stmt->fetchAll();
foreach ($all_jobs as $row) {
if ($row['data'] != '') {
$row['data'] = json_decode($row['data'], true);
}
if (is_array($row['data'])) {
if (isset($row['data']['customerid'])
&& isset($row['data']['loginname'])
&& isset($row['data']['destdir'])
) {
$row['data']['destdir'] = makeCorrectDir($row['data']['destdir']);
$customerdocroot = makeCorrectDir(Settings::Get('system.documentroot_prefix').'/'.$row['data']['loginname'].'/');
// create folder if not exists
if (!file_exists($row['data']['destdir'])
&& $row['data']['destdir'] != '/'
&& $row['data']['destdir'] != Settings::Get('system.documentroot_prefix')
&& $row['data']['destdir'] != $customerdocroot
) {
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Creating backup-destination path for customer: ' . escapeshellarg($row['data']['destdir']));
safe_exec('mkdir -p '.escapeshellarg($row['data']['destdir']));
}
createCustomerBackup($row['data'], $customerdocroot, $cronlog);
}
}
// remove entry
Database::pexecute($del_stmt, array('id' => $row['id']));
}
if (function_exists('pcntl_fork')) {
@unlink($BackupLock);
die();
}

View File

@@ -1,55 +0,0 @@
<?php if (!defined('MASTER_CRONJOB')) die('You cannot access this file directly!');
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Michael Kaufmann <mkaufmann@nutime.de>
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Cron
*
* @since 0.9.29.1
*
*/
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'calculating mailspace usage');
$maildirs_stmt = Database::query("
SELECT `id`, CONCAT(`homedir`, `maildir`) AS `maildirpath` FROM `".TABLE_MAIL_USERS."` ORDER BY `id`
");
$upd_stmt = Database::prepare("
UPDATE `".TABLE_MAIL_USERS."` SET `mboxsize` = :size WHERE `id` = :id
");
while ($maildir = $maildirs_stmt->fetch(PDO::FETCH_ASSOC)) {
$_maildir = makeCorrectDir($maildir['maildirpath']);
if (file_exists($_maildir)
&& is_dir($_maildir)
) {
// mail-address allows many special characters, see http://en.wikipedia.org/wiki/Email_address#Local_part
$return = false;
$back = safe_exec('du -sk ' . escapeshellarg($_maildir), $return, array('|', '&', '`', '$', '~', '?'));
foreach ($back as $backrow) {
$emailusage = explode(' ', $backrow);
}
$emailusage = floatval($emailusage['0']);
// as freebsd does not have the -b flag for 'du' which gives
// the size in bytes, we use "-sk" for all and calculate from KiB
$emailusage *= 1024;
unset($back);
Database::pexecute($upd_stmt, array('size' => $emailusage, 'id' => $maildir['id']));
} else {
$cronlog->logAction(CRON_ACTION, LOG_WARNING, 'maildir ' . $_maildir . ' does not exist');
}
}

View File

@@ -31,7 +31,10 @@ if (file_exists($userdata)) {
file_put_contents($userdata, $userdata_content); file_put_contents($userdata, $userdata_content);
// include autoloader / api / etc // include autoloader / api / etc
require dirname(__DIR__) . '/lib/classes/api/api_includes.inc.php'; require dirname(__DIR__) . '/vendor/autoload.php';
use \Froxlor\Database;
use \Froxlor\Settings;
Database::needRoot(true); Database::needRoot(true);
Database::query("DROP DATABASE IF EXISTS `test1sql1`;"); Database::query("DROP DATABASE IF EXISTS `test1sql1`;");