Minor enhancements and starting to comply with checkstyle

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-12-24 09:35:05 +01:00
parent 04e87cce98
commit c3d44b4558
25 changed files with 217 additions and 205 deletions

View File

@@ -172,21 +172,16 @@ if ($page == 'overview') {
$log->logAction(USR_ACTION, LOG_NOTICE, 'changed main ftp password'); $log->logAction(USR_ACTION, LOG_NOTICE, 'changed main ftp password');
} }
// Update webalizer password // Update statistics password
if (isset($_POST['change_webalizer']) && $_POST['change_webalizer'] == 'true') { if (isset($_POST['change_stats']) && $_POST['change_stats'] == 'true') {
if (CRYPT_STD_DES == 1) { $new_stats_password = \Froxlor\System\Crypt::makeCryptPassword($new_password, true);
$saltfordescrypt = substr(md5(uniqid(microtime(), 1)), 4, 2);
$new_webalizer_password = crypt($new_password, $saltfordescrypt);
} else {
$new_webalizer_password = crypt($new_password);
}
$stmt = Database::prepare("UPDATE `" . TABLE_PANEL_HTPASSWDS . "` $stmt = Database::prepare("UPDATE `" . TABLE_PANEL_HTPASSWDS . "`
SET `password` = :password SET `password` = :password
WHERE `customerid` = :customerid WHERE `customerid` = :customerid
AND `username` = :username"); AND `username` = :username");
$params = array( $params = array(
"password" => $new_webalizer_password, "password" => $new_stats_password,
"customerid" => $userinfo['customerid'], "customerid" => $userinfo['customerid'],
"username" => $userinfo['loginname'] "username" => $userinfo['loginname']
); );

View File

@@ -1,7 +1,6 @@
<?php <?php
namespace Froxlor\Api; namespace Froxlor\Api;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors). * Copyright (c) 2010 the Froxlor Team (see authors).

View File

@@ -234,8 +234,8 @@ class Admins extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
if (strtolower($loginname_check['loginname']) == strtolower($loginname) || strtolower($loginname_check_admin['loginname']) == strtolower($loginname)) { if (strtolower($loginname_check['loginname']) == strtolower($loginname) || strtolower($loginname_check_admin['loginname']) == strtolower($loginname)) {
\Froxlor\UI\Response::standard_error('loginnameexists', $loginname, true); \Froxlor\UI\Response::standard_error('loginnameexists', $loginname, true);
} // Accounts which match systemaccounts are not allowed, filtering them } elseif (preg_match('/^' . preg_quote(Settings::Get('customer.accountprefix'), '/') . '([0-9]+)/', $loginname)) {
elseif (preg_match('/^' . preg_quote(Settings::Get('customer.accountprefix'), '/') . '([0-9]+)/', $loginname)) { // Accounts which match systemaccounts are not allowed, filtering them
\Froxlor\UI\Response::standard_error('loginnameissystemaccount', Settings::Get('customer.accountprefix'), true); \Froxlor\UI\Response::standard_error('loginnameissystemaccount', Settings::Get('customer.accountprefix'), true);
} elseif (! \Froxlor\Validate\Validate::validateUsername($loginname)) { } elseif (! \Froxlor\Validate\Validate::validateUsername($loginname)) {
\Froxlor\UI\Response::standard_error('loginnameiswrong', $loginname, true); \Froxlor\UI\Response::standard_error('loginnameiswrong', $loginname, true);

View File

@@ -523,12 +523,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
\Froxlor\System\Cronjob::inserttask('10'); \Froxlor\System\Cronjob::inserttask('10');
// Add htpasswd for the stats-pages // Add htpasswd for the stats-pages
if (CRYPT_STD_DES == 1) { $htpasswdPassword = \Froxlor\System\Crypt::makeCryptPassword($password, true);
$saltfordescrypt = substr(md5(uniqid(microtime(), 1)), 4, 2);
$htpasswdPassword = crypt($password, $saltfordescrypt);
} else {
$htpasswdPassword = crypt($password);
}
$ins_stmt = Database::prepare(" $ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_PANEL_HTPASSWDS . "` SET INSERT INTO `" . TABLE_PANEL_HTPASSWDS . "` SET

View File

@@ -419,5 +419,4 @@ class DirOptions extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
} }
return $errdoc; return $errdoc;
} }
} }

View File

@@ -78,13 +78,7 @@ class DirProtections extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Res
); );
$username_path_check = Database::pexecute_first($username_path_check_stmt, $params, true, true); $username_path_check = Database::pexecute_first($username_path_check_stmt, $params, true, true);
// check whether we can used salted passwords $password_enc = \Froxlor\System\Crypt::makeCryptPassword($password, true);
if (CRYPT_STD_DES == 1) {
$saltfordescrypt = substr(md5(uniqid(microtime(), 1)), 4, 2);
$password_enc = crypt($password, $saltfordescrypt);
} else {
$password_enc = crypt($password);
}
// duplicate check // duplicate check
if ($username_path_check['username'] == $username && $username_path_check['path'] == $path) { if ($username_path_check['username'] == $username && $username_path_check['path'] == $path) {
@@ -238,12 +232,8 @@ class DirProtections extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Res
if ($password == $result['username']) { if ($password == $result['username']) {
\Froxlor\UI\Response::standard_error('passwordshouldnotbeusername', '', true); \Froxlor\UI\Response::standard_error('passwordshouldnotbeusername', '', true);
} }
if (CRYPT_STD_DES == 1) { $password_enc = \Froxlor\System\Crypt::makeCryptPassword($password, true);
$saltfordescrypt = substr(md5(uniqid(microtime(), 1)), 4, 2);
$password_enc = crypt($password, $saltfordescrypt);
} else {
$password_enc = crypt($password);
}
$upd_query .= "`password`= :password_enc"; $upd_query .= "`password`= :password_enc";
$upd_params['password_enc'] = $password_enc; $upd_params['password_enc'] = $password_enc;
} }

View File

@@ -33,21 +33,21 @@ abstract class BulkAction
* *
* @var string * @var string
*/ */
private $_impFile = null; private $impFile = null;
/** /**
* customer id of the user the entity is being added to * customer id of the user the entity is being added to
* *
* @var int * @var int
*/ */
private $_custId = null; private $custId = null;
/** /**
* array of customer data read from the database * array of customer data read from the database
* *
* @var array * @var array
*/ */
private $_custData = null; private $custData = null;
/** /**
* api-function to call for addingg entity * api-function to call for addingg entity
@@ -81,9 +81,9 @@ abstract class BulkAction
protected function __construct($import_file = null, $customer_id = 0) protected function __construct($import_file = null, $customer_id = 0)
{ {
if (! empty($import_file)) { if (! empty($import_file)) {
$this->_impFile = \Froxlor\FileDir::makeCorrectFile($import_file); $this->impFile = \Froxlor\FileDir::makeCorrectFile($import_file);
} }
$this->_custId = $customer_id; $this->custId = $customer_id;
} }
/** /**
@@ -106,7 +106,7 @@ abstract class BulkAction
*/ */
public function setImportFile($import_file = null) public function setImportFile($import_file = null)
{ {
$this->_impFile = \Froxlor\FileDir::makeCorrectFile($import_file); $this->impFile = \Froxlor\FileDir::makeCorrectFile($import_file);
} }
/** /**
@@ -118,7 +118,7 @@ abstract class BulkAction
*/ */
public function setCustomer($customer_id = 0) public function setCustomer($customer_id = 0)
{ {
$this->_custId = $customer_id; $this->custId = $customer_id;
} }
/** /**
@@ -177,21 +177,21 @@ abstract class BulkAction
*/ */
protected function _parseImportFile($separator = ";") protected function _parseImportFile($separator = ";")
{ {
if (empty($this->_impFile)) { if (empty($this->impFile)) {
throw new \Exception("No file was given for import"); throw new \Exception("No file was given for import");
} }
if (! file_exists($this->_impFile)) { if (! file_exists($this->impFile)) {
throw new \Exception("The file '" . $this->_impFile . "' could not be found"); throw new \Exception("The file '" . $this->impFile . "' could not be found");
} }
if (! is_readable($this->_impFile)) { if (! is_readable($this->impFile)) {
throw new \Exception("Unable to read file '" . $this->_impFile . "'"); throw new \Exception("Unable to read file '" . $this->impFile . "'");
} }
$file_data = array(); $file_data = array();
$is_params_line = true; $is_params_line = true;
$fh = @fopen($this->_impFile, "r"); $fh = @fopen($this->impFile, "r");
if ($fh) { if ($fh) {
while (($line = fgets($fh)) !== false) { while (($line = fgets($fh)) !== false) {
$tmp_arr = explode($separator, $line); $tmp_arr = explode($separator, $line);
@@ -211,7 +211,7 @@ abstract class BulkAction
} }
$this->api_params = array_map("trim", $this->api_params); $this->api_params = array_map("trim", $this->api_params);
} else { } else {
throw new \Exception("Unable to open file '" . $this->_impFile . "'"); throw new \Exception("Unable to open file '" . $this->impFile . "'");
} }
fclose($fh); fclose($fh);
@@ -225,11 +225,11 @@ abstract class BulkAction
{ {
$this->_readCustomerData(); $this->_readCustomerData();
if ($this->_custId <= 0) { if ($this->custId <= 0) {
throw new \Exception("Invalid customer selected"); throw new \Exception("Invalid customer selected");
} }
if (is_null($this->_custData)) { if (is_null($this->custData)) {
throw new \Exception("Failed to read customer data"); throw new \Exception("Failed to read customer data");
} }
} }
@@ -242,13 +242,13 @@ abstract class BulkAction
protected function _readCustomerData() protected function _readCustomerData()
{ {
$cust_stmt = \Froxlor\Database\Database::prepare("SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `customerid` = :cid"); $cust_stmt = \Froxlor\Database\Database::prepare("SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `customerid` = :cid");
$this->_custData = \Froxlor\Database\Database::pexecute_first($cust_stmt, array( $this->custData = \Froxlor\Database\Database::pexecute_first($cust_stmt, array(
'cid' => $this->_custId 'cid' => $this->custId
)); ));
if (is_array($this->_custData) && isset($this->_custData['customerid']) && $this->_custData['customerid'] == $this->_custId) { if (is_array($this->custData) && isset($this->custData['customerid']) && $this->custData['customerid'] == $this->custId) {
return true; return true;
} }
$this->_custData = null; $this->custData = null;
return false; return false;
} }
} }

View File

@@ -16,7 +16,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
public function run() public function run()
{ {
$this->_validate(); $this->validate();
} }
/** /**
@@ -24,27 +24,27 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
* *
* @throws \Exception * @throws \Exception
*/ */
private function _validate() private function validate()
{ {
$this->_checkConfigParam(true); $this->checkConfigParam(true);
$this->_parseConfig(); $this->parseConfig();
require FROXLOR_INSTALL_DIR . '/lib/tables.inc.php'; require FROXLOR_INSTALL_DIR . '/lib/tables.inc.php';
if (array_key_exists("import-settings", $this->_args)) { if (array_key_exists("import-settings", $this->_args)) {
$this->_importSettings(); $this->importSettings();
} }
if (array_key_exists("create", $this->_args)) { if (array_key_exists("create", $this->_args)) {
$this->_createConfig(); $this->createConfig();
} elseif (array_key_exists("apply", $this->_args)) { } elseif (array_key_exists("apply", $this->_args)) {
$this->_applyConfig(); $this->applyConfig();
} elseif (array_key_exists("list-daemons", $this->_args) || array_key_exists("daemon", $this->_args)) { } elseif (array_key_exists("list-daemons", $this->_args) || array_key_exists("daemon", $this->_args)) {
ConfigServicesCmd::printwarn("--list-daemons and --daemon only work together with --apply"); ConfigServicesCmd::printwarn("--list-daemons and --daemon only work together with --apply");
} }
} }
private function _importSettings() private function importSettings()
{ {
if (strtoupper(substr($this->_args["import-settings"], 0, 4)) == 'HTTP') { if (strtoupper(substr($this->_args["import-settings"], 0, 4)) == 'HTTP') {
echo "Settings file seems to be an URL, trying to download" . PHP_EOL; echo "Settings file seems to be an URL, trying to download" . PHP_EOL;
@@ -67,7 +67,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
ConfigServicesCmd::printsucc("Successfully imported settings from '" . $this->_args["import-settings"] . "'"); ConfigServicesCmd::printsucc("Successfully imported settings from '" . $this->_args["import-settings"] . "'");
} }
private function _createConfig() private function createConfig()
{ {
$_daemons_config = array( $_daemons_config = array(
'distro' => "" 'distro' => ""
@@ -185,7 +185,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
return $dist_display; return $dist_display;
} }
private function _applyConfig() private function applyConfig()
{ {
if (strtoupper(substr($this->_args["apply"], 0, 4)) == 'HTTP') { if (strtoupper(substr($this->_args["apply"], 0, 4)) == 'HTTP') {
echo "Config file seems to be an URL, trying to download" . PHP_EOL; echo "Config file seems to be an URL, trying to download" . PHP_EOL;
@@ -238,7 +238,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
$config_dir = FROXLOR_INSTALL_DIR . '/lib/configfiles/'; $config_dir = FROXLOR_INSTALL_DIR . '/lib/configfiles/';
$configfiles = new \Froxlor\Config\ConfigParser($config_dir . '/' . $decoded_config['distro'] . ".xml"); $configfiles = new \Froxlor\Config\ConfigParser($config_dir . '/' . $decoded_config['distro'] . ".xml");
$services = $configfiles->getServices(); $services = $configfiles->getServices();
$replace_arr = $this->_getReplacerArray(); $replace_arr = $this->getReplacerArray();
foreach ($services as $si => $service) { foreach ($services as $si => $service) {
echo PHP_EOL . "--- Configuring: " . strtoupper($si) . " ---" . PHP_EOL . PHP_EOL; echo PHP_EOL . "--- Configuring: " . strtoupper($si) . " ---" . PHP_EOL . PHP_EOL;
@@ -305,7 +305,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
} }
} }
private function _getReplacerArray() private function getReplacerArray()
{ {
$customer_tmpdir = '/tmp/'; $customer_tmpdir = '/tmp/';
if (Settings::Get('system.mod_fcgid') == '1' && Settings::Get('system.mod_fcgid_tmpdir') != '') { if (Settings::Get('system.mod_fcgid') == '1' && Settings::Get('system.mod_fcgid_tmpdir') != '') {
@@ -356,7 +356,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
return $replace_arr; return $replace_arr;
} }
private function _parseConfig() private function parseConfig()
{ {
define('FROXLOR_INSTALL_DIR', $this->_args['froxlor-dir']); define('FROXLOR_INSTALL_DIR', $this->_args['froxlor-dir']);
if (! class_exists('\\Froxlor\\Database\\Database')) { if (! class_exists('\\Froxlor\\Database\\Database')) {
@@ -367,7 +367,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
} }
} }
private function _checkConfigParam($needed = false) private function checkConfigParam($needed = false)
{ {
if ($needed) { if ($needed) {
if (! isset($this->_args["froxlor-dir"])) { if (! isset($this->_args["froxlor-dir"])) {

View File

@@ -14,7 +14,7 @@ class SwitchServerIpAction extends \Froxlor\Cli\Action
public function run() public function run()
{ {
$this->_validate(); $this->validate();
} }
/** /**
@@ -22,26 +22,26 @@ class SwitchServerIpAction extends \Froxlor\Cli\Action
* *
* @throws \Exception * @throws \Exception
*/ */
private function _validate() private function validate()
{ {
$need_config = false; $need_config = false;
if (array_key_exists("list", $this->_args) || array_key_exists("switch", $this->_args)) { if (array_key_exists("list", $this->_args) || array_key_exists("switch", $this->_args)) {
$need_config = true; $need_config = true;
} }
$this->_checkConfigParam($need_config); $this->checkConfigParam($need_config);
$this->_parseConfig(); $this->parseConfig();
if (array_key_exists("list", $this->_args)) { if (array_key_exists("list", $this->_args)) {
$this->_listIPs(); $this->listIPs();
} }
if (array_key_exists("switch", $this->_args)) { if (array_key_exists("switch", $this->_args)) {
$this->_switchIPs(); $this->switchIPs();
} }
} }
private function _listIPs() private function listIPs()
{ {
$sel_stmt = Database::prepare("SELECT * FROM panel_ipsandports ORDER BY ip ASC, port ASC"); $sel_stmt = Database::prepare("SELECT * FROM panel_ipsandports ORDER BY ip ASC, port ASC");
Database::pexecute($sel_stmt); Database::pexecute($sel_stmt);
@@ -57,7 +57,7 @@ class SwitchServerIpAction extends \Froxlor\Cli\Action
echo PHP_EOL . PHP_EOL; echo PHP_EOL . PHP_EOL;
} }
private function _switchIPs() private function switchIPs()
{ {
$ip_list = $this->_args['switch']; $ip_list = $this->_args['switch'];
@@ -158,7 +158,7 @@ class SwitchServerIpAction extends \Froxlor\Cli\Action
SwitchServerIpCmd::printsucc("IP addresses updated"); SwitchServerIpCmd::printsucc("IP addresses updated");
} }
private function _parseConfig() private function parseConfig()
{ {
define('FROXLOR_INSTALL_DIR', $this->_args['froxlor-dir']); define('FROXLOR_INSTALL_DIR', $this->_args['froxlor-dir']);
if (! class_exists('\\Froxlor\\Database\\Database')) { if (! class_exists('\\Froxlor\\Database\\Database')) {
@@ -169,7 +169,7 @@ class SwitchServerIpAction extends \Froxlor\Cli\Action
} }
} }
private function _checkConfigParam($needed = false) private function checkConfigParam($needed = false)
{ {
if ($needed) { if ($needed) {
if (! isset($this->_args["froxlor-dir"])) { if (! isset($this->_args["froxlor-dir"])) {

View File

@@ -59,8 +59,8 @@ abstract class CmdLineHandler
*/ */
private function __construct($argc, $argv) private function __construct($argc, $argv)
{ {
self::$args = $this->_parseArgs($argv); self::$args = $this->parseArgs($argv);
$this->_action = $this->_createAction(); $this->_action = $this->createAction();
$this->_action->run(); $this->_action->run();
} }
@@ -83,7 +83,7 @@ abstract class CmdLineHandler
* *
* @return array * @return array
*/ */
private function _parseArgs($argv) private function parseArgs($argv)
{ {
array_shift($argv); array_shift($argv);
$o = array(); $o = array();
@@ -121,7 +121,7 @@ abstract class CmdLineHandler
* @return \Froxlor\Cli\Action * @return \Froxlor\Cli\Action
* @throws \Exception * @throws \Exception
*/ */
private function _createAction() private function createAction()
{ {
// Test for help-switch // Test for help-switch
@@ -194,23 +194,23 @@ abstract class CmdLineHandler
print $msg . PHP_EOL; print $msg . PHP_EOL;
} }
private static function _printcolor($msg = "", $color = "0") private static function printcolor($msg = "", $color = "0")
{ {
print "\033[" . $color . "m" . $msg . "\033[0m" . PHP_EOL; print "\033[" . $color . "m" . $msg . "\033[0m" . PHP_EOL;
} }
public static function printerr($msg = "") public static function printerr($msg = "")
{ {
self::_printcolor($msg, "31"); self::printcolor($msg, "31");
} }
public static function printsucc($msg = "") public static function printsucc($msg = "")
{ {
self::_printcolor($msg, "32"); self::printcolor($msg, "32");
} }
public static function printwarn($msg = "") public static function printwarn($msg = "")
{ {
self::_printcolor($msg, "33"); self::printcolor($msg, "33");
} }
} }

View File

@@ -94,7 +94,7 @@ class ConfigDaemon
$this->daemon = $this->fullxml->xpath($this->xpath); $this->daemon = $this->fullxml->xpath($this->xpath);
$attributes = $this->daemon[0]->attributes(); $attributes = $this->daemon[0]->attributes();
if ($attributes['title'] != '') { if ($attributes['title'] != '') {
$this->title = $this->_parseContent((string) $attributes['title']); $this->title = $this->parseContent((string) $attributes['title']);
} }
if (isset($attributes['default'])) { if (isset($attributes['default'])) {
$this->default = ($attributes['default'] == true); $this->default = ($attributes['default'] == true);
@@ -106,7 +106,7 @@ class ConfigDaemon
* *
* @return bool * @return bool
*/ */
private function _parse() private function parse()
{ {
// We only want to parse the stuff one time // We only want to parse the stuff one time
if ($this->isparsed == true) { if ($this->isparsed == true) {
@@ -143,7 +143,7 @@ class ConfigDaemon
foreach ($order->children() as $child) { foreach ($order->children() as $child) {
switch ((string) $child->getName()) { switch ((string) $child->getName()) {
case "visibility": case "visibility":
$visibility += $this->_checkVisibility($child); $visibility += $this->checkVisibility($child);
break; break;
case "install": case "install":
case "file": case "file":
@@ -171,7 +171,7 @@ class ConfigDaemon
// Go through every preparsed order and evaluate what should happen to it // Go through every preparsed order and evaluate what should happen to it
foreach ($preparsed as $order) { foreach ($preparsed as $order) {
$parsedorder = $this->_parseOrder($order); $parsedorder = $this->parseOrder($order);
// We got an array (= valid order) and the array already has a type -> add to stack // We got an array (= valid order) and the array already has a type -> add to stack
if (is_array($parsedorder) && array_key_exists('type', $parsedorder)) { if (is_array($parsedorder) && array_key_exists('type', $parsedorder)) {
$this->orders[] = $parsedorder; $this->orders[] = $parsedorder;
@@ -200,7 +200,7 @@ class ConfigDaemon
*/ */
public function getConfig() public function getConfig()
{ {
$this->_parse(); $this->parse();
return $this->orders; return $this->orders;
} }
@@ -211,7 +211,7 @@ class ConfigDaemon
* SimpleXMLElement object holding a single order from the distribution - XML * SimpleXMLElement object holding a single order from the distribution - XML
* @return array|string * @return array|string
*/ */
private function _parseOrder($order) private function parseOrder($order)
{ {
$attributes = array(); $attributes = array();
foreach ($order->attributes() as $key => $value) { foreach ($order->attributes() as $key => $value) {
@@ -221,13 +221,13 @@ class ConfigDaemon
$parsedorder = ''; $parsedorder = '';
switch ((string) $order->getName()) { switch ((string) $order->getName()) {
case "file": case "file":
$parsedorder = $this->_parseFile($order, $attributes); $parsedorder = $this->parseFile($order, $attributes);
break; break;
case "command": case "command":
$parsedorder = $this->_parseCommand($order, $attributes); $parsedorder = $this->parseCommand($order, $attributes);
break; break;
case "install": case "install":
$parsedorder = $this->_parseInstall($order, $attributes); $parsedorder = $this->parseInstall($order, $attributes);
break; break;
default: default:
throw new \Exception('Invalid order: ' . (string) $order->getName()); throw new \Exception('Invalid order: ' . (string) $order->getName());
@@ -243,13 +243,13 @@ class ConfigDaemon
* SimpleXMLElement object holding a single install from the distribution - XML * SimpleXMLElement object holding a single install from the distribution - XML
* @return array|string * @return array|string
*/ */
private function _parseInstall($order, $attributes) private function parseInstall($order, $attributes)
{ {
// No sub - elements, so the content can be returned directly // No sub - elements, so the content can be returned directly
if ($order->count() == 0) { if ($order->count() == 0) {
return array( return array(
'type' => 'install', 'type' => 'install',
'content' => $this->_parseContent(trim((string) $order)) 'content' => $this->parseContent(trim((string) $order))
); );
} }
@@ -259,7 +259,7 @@ class ConfigDaemon
foreach ($order->children() as $child) { foreach ($order->children() as $child) {
switch ((string) $child->getName()) { switch ((string) $child->getName()) {
case "visibility": case "visibility":
$visibility += $this->_checkVisibility($child); $visibility += $this->checkVisibility($child);
break; break;
case "content": case "content":
$content = trim((string) $child); $content = trim((string) $child);
@@ -270,7 +270,7 @@ class ConfigDaemon
if ($visibility > 0) { if ($visibility > 0) {
return array( return array(
'type' => 'install', 'type' => 'install',
'content' => $this->_parseContent($content) 'content' => $this->parseContent($content)
); );
} else { } else {
return ''; return '';
@@ -284,13 +284,13 @@ class ConfigDaemon
* SimpleXMLElement object holding a single command from the distribution - XML * SimpleXMLElement object holding a single command from the distribution - XML
* @return array|string * @return array|string
*/ */
private function _parseCommand($order, $attributes) private function parseCommand($order, $attributes)
{ {
// No sub - elements, so the content can be returned directly // No sub - elements, so the content can be returned directly
if ($order->count() == 0) { if ($order->count() == 0) {
return array( return array(
'type' => 'command', 'type' => 'command',
'content' => $this->_parseContent(trim((string) $order)) 'content' => $this->parseContent(trim((string) $order))
); );
} }
@@ -300,7 +300,7 @@ class ConfigDaemon
foreach ($order->children() as $child) { foreach ($order->children() as $child) {
switch ((string) $child->getName()) { switch ((string) $child->getName()) {
case "visibility": case "visibility":
$visibility += $this->_checkVisibility($child); $visibility += $this->checkVisibility($child);
break; break;
case "content": case "content":
$content = trim((string) $child); $content = trim((string) $child);
@@ -311,7 +311,7 @@ class ConfigDaemon
if ($visibility > 0) { if ($visibility > 0) {
return array( return array(
'type' => 'command', 'type' => 'command',
'content' => $this->_parseContent($content) 'content' => $this->parseContent($content)
); );
} else { } else {
return ''; return '';
@@ -325,7 +325,7 @@ class ConfigDaemon
* SimpleXMLElement object holding a single file from the distribution - XML * SimpleXMLElement object holding a single file from the distribution - XML
* @return array|string * @return array|string
*/ */
private function _parseFile($order, $attributes) private function parseFile($order, $attributes)
{ {
$visibility = 1; $visibility = 1;
// No sub - elements, so the content can be returned directly // No sub - elements, so the content can be returned directly
@@ -336,7 +336,7 @@ class ConfigDaemon
foreach ($order->children() as $child) { foreach ($order->children() as $child) {
switch ((string) $child->getName()) { switch ((string) $child->getName()) {
case "visibility": case "visibility":
$visibility += $this->_checkVisibility($child); $visibility += $this->checkVisibility($child);
break; break;
case "content": case "content":
$content = (string) $child; $content = (string) $child;
@@ -357,7 +357,7 @@ class ConfigDaemon
} }
$return[] = array( $return[] = array(
'type' => 'command', 'type' => 'command',
'content' => $cmd . ' "' . $this->_parseContent($attributes['name']) . '" "' . $this->_parseContent($attributes['name']) . '.frx.bak"', 'content' => $cmd . ' "' . $this->parseContent($attributes['name']) . '" "' . $this->parseContent($attributes['name']) . '.frx.bak"',
'execute' => "pre" 'execute' => "pre"
); );
} }
@@ -366,15 +366,15 @@ class ConfigDaemon
if (isset($attributes['mode'])) { if (isset($attributes['mode'])) {
$return[] = array( $return[] = array(
'type' => 'file', 'type' => 'file',
'content' => $this->_parseContent($content), 'content' => $this->parseContent($content),
'name' => $this->_parseContent($attributes['name']), 'name' => $this->parseContent($attributes['name']),
'mode' => $this->_parseContent($attributes['mode']) 'mode' => $this->parseContent($attributes['mode'])
); );
} else { } else {
$return[] = array( $return[] = array(
'type' => 'file', 'type' => 'file',
'content' => $this->_parseContent($content), 'content' => $this->parseContent($content),
'name' => $this->_parseContent($attributes['name']) 'name' => $this->parseContent($attributes['name'])
); );
} }
@@ -382,7 +382,7 @@ class ConfigDaemon
if (array_key_exists('chmod', $attributes)) { if (array_key_exists('chmod', $attributes)) {
$return[] = array( $return[] = array(
'type' => 'command', 'type' => 'command',
'content' => 'chmod ' . $attributes['chmod'] . ' "' . $this->_parseContent($attributes['name']) . '"', 'content' => 'chmod ' . $attributes['chmod'] . ' "' . $this->parseContent($attributes['name']) . '"',
'execute' => "post" 'execute' => "post"
); );
} }
@@ -391,7 +391,7 @@ class ConfigDaemon
if (array_key_exists('chown', $attributes)) { if (array_key_exists('chown', $attributes)) {
$return[] = array( $return[] = array(
'type' => 'command', 'type' => 'command',
'content' => 'chown ' . $attributes['chown'] . ' "' . $this->_parseContent($attributes['name']) . '"', 'content' => 'chown ' . $attributes['chown'] . ' "' . $this->parseContent($attributes['name']) . '"',
'execute' => "post" 'execute' => "post"
); );
} }
@@ -401,7 +401,7 @@ class ConfigDaemon
$return = array( $return = array(
'type' => 'file', 'type' => 'file',
'subcommands' => $return, 'subcommands' => $return,
'name' => $this->_parseContent($attributes['name']) 'name' => $this->parseContent($attributes['name'])
); );
} }
@@ -418,9 +418,10 @@ class ConfigDaemon
* @param string $content * @param string $content
* @return string $content w/o placeholder * @return string $content w/o placeholder
*/ */
private function _parseContent($content) private function parseContent($content)
{ {
$content = preg_replace_callback('/\{\{(.*)\}\}/Ui', function ($matches) { $content = preg_replace_callback('/\{\{(.*)\}\}/Ui', function ($matches) {
$match = null;
if (preg_match('/^settings\.(.*)$/', $matches[1], $match)) { if (preg_match('/^settings\.(.*)$/', $matches[1], $match)) {
return \Froxlor\Settings::Get($match[1]); return \Froxlor\Settings::Get($match[1]);
} elseif (preg_match('/^lng\.(.*)(?:\.(.*)(?:\.(.*)))$/U', $matches[1], $match)) { } elseif (preg_match('/^lng\.(.*)(?:\.(.*)(?:\.(.*)))$/U', $matches[1], $match)) {
@@ -460,14 +461,14 @@ class ConfigDaemon
* @param \SimpleXMLElement $order * @param \SimpleXMLElement $order
* @return int 0|-1 * @return int 0|-1
*/ */
private function _checkVisibility($order) private function checkVisibility($order)
{ {
$attributes = array(); $attributes = array();
foreach ($order->attributes() as $key => $value) { foreach ($order->attributes() as $key => $value) {
$attributes[(string) $key] = $this->_parseContent(trim((string) $value)); $attributes[(string) $key] = $this->parseContent(trim((string) $value));
} }
$order = $this->_parseContent(trim((string) $order)); $order = $this->parseContent(trim((string) $order));
if (! array_key_exists('mode', $attributes)) { if (! array_key_exists('mode', $attributes)) {
throw new \Exception('"<visibility>' . $order . '</visibility>" is missing mode'); throw new \Exception('"<visibility>' . $order . '</visibility>" is missing mode');
} }

View File

@@ -1,6 +1,23 @@
<?php <?php
namespace Froxlor\Cron; namespace Froxlor\Cron;
/**
* 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.10.0
*
*/
use Froxlor\Database\Database; use Froxlor\Database\Database;
use Froxlor\Settings; use Froxlor\Settings;

View File

@@ -20,30 +20,30 @@ use Froxlor\Settings;
class Bind extends DnsBase class Bind extends DnsBase
{ {
private $_bindconf_file = ""; private $bindconf_file = "";
public function writeConfigs() public function writeConfigs()
{ {
// tell the world what we are doing // tell the world what we are doing
$this->_logger->logAction(CRON_ACTION, LOG_INFO, 'Task4 started - Rebuilding froxlor_bind.conf'); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'Task4 started - Rebuilding froxlor_bind.conf');
// clean up // clean up
$this->_cleanZonefiles(); $this->cleanZonefiles();
// check for subfolder in bind-config-directory // check for subfolder in bind-config-directory
if (! file_exists(\Froxlor\FileDir::makeCorrectDir(Settings::Get('system.bindconf_directory') . '/domains/'))) { if (! file_exists(\Froxlor\FileDir::makeCorrectDir(Settings::Get('system.bindconf_directory') . '/domains/'))) {
$this->_logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir ' . escapeshellarg(\Froxlor\FileDir::makeCorrectDir(Settings::Get('system.bindconf_directory') . '/domains/'))); $this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir ' . escapeshellarg(\Froxlor\FileDir::makeCorrectDir(Settings::Get('system.bindconf_directory') . '/domains/')));
\Froxlor\FileDir::safe_exec('mkdir -p ' . escapeshellarg(\Froxlor\FileDir::makeCorrectDir(Settings::Get('system.bindconf_directory') . '/domains/'))); \Froxlor\FileDir::safe_exec('mkdir -p ' . escapeshellarg(\Froxlor\FileDir::makeCorrectDir(Settings::Get('system.bindconf_directory') . '/domains/')));
} }
$domains = $this->getDomainList(); $domains = $this->getDomainList();
if (empty($domains)) { if (empty($domains)) {
$this->_logger->logAction(CRON_ACTION, LOG_INFO, 'No domains found for nameserver-config, skipping...'); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'No domains found for nameserver-config, skipping...');
return; return;
} }
$this->_bindconf_file = '# ' . Settings::Get('system.bindconf_directory') . 'froxlor_bind.conf' . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n\n"; $this->bindconf_file = '# ' . Settings::Get('system.bindconf_directory') . 'froxlor_bind.conf' . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n\n";
foreach ($domains as $domain) { foreach ($domains as $domain) {
if ($domain['ismainbutsubto'] > 0) { if ($domain['ismainbutsubto'] > 0) {
@@ -54,11 +54,11 @@ class Bind extends DnsBase
} }
$bindconf_file_handler = fopen(\Froxlor\FileDir::makeCorrectFile(Settings::Get('system.bindconf_directory') . '/froxlor_bind.conf'), 'w'); $bindconf_file_handler = fopen(\Froxlor\FileDir::makeCorrectFile(Settings::Get('system.bindconf_directory') . '/froxlor_bind.conf'), 'w');
fwrite($bindconf_file_handler, $this->_bindconf_file); fwrite($bindconf_file_handler, $this->bindconf_file);
fclose($bindconf_file_handler); fclose($bindconf_file_handler);
$this->_logger->logAction(CRON_ACTION, LOG_INFO, 'froxlor_bind.conf written'); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'froxlor_bind.conf written');
$this->reloadDaemon(); $this->reloadDaemon();
$this->_logger->logAction(CRON_ACTION, LOG_INFO, 'Task4 finished'); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'Task4 finished');
} }
private function walkDomainList($domain, $domains) private function walkDomainList($domain, $domains)
@@ -84,20 +84,20 @@ class Bind extends DnsBase
$zonefile_handler = fopen($zonefile_name, 'w'); $zonefile_handler = fopen($zonefile_name, 'w');
fwrite($zonefile_handler, $zoneContent . $subzones); fwrite($zonefile_handler, $zoneContent . $subzones);
fclose($zonefile_handler); fclose($zonefile_handler);
$this->_logger->logAction(CRON_ACTION, LOG_INFO, '`' . $zonefile_name . '` written'); $this->logger->logAction(CRON_ACTION, LOG_INFO, '`' . $zonefile_name . '` written');
$this->_bindconf_file .= $this->_generateDomainConfig($domain); $this->bindconf_file .= $this->generateDomainConfig($domain);
} else { } else {
return (string) \Froxlor\Dns\Dns::createDomainZone(($domain['id'] == 'none') ? $domain : $domain['id'], $isFroxlorHostname, true); return (string) \Froxlor\Dns\Dns::createDomainZone(($domain['id'] == 'none') ? $domain : $domain['id'], $isFroxlorHostname, true);
} }
} else { } else {
$this->_logger->logAction(CRON_ACTION, LOG_INFO, 'Added zonefile ' . $domain['zonefile'] . ' for domain ' . $domain['domain'] . ' - Note that you will also have to handle ALL records for ALL subdomains.'); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'Added zonefile ' . $domain['zonefile'] . ' for domain ' . $domain['domain'] . ' - Note that you will also have to handle ALL records for ALL subdomains.');
$this->_bindconf_file .= $this->_generateDomainConfig($domain); $this->bindconf_file .= $this->generateDomainConfig($domain);
} }
} }
private function _generateDomainConfig($domain = array()) private function generateDomainConfig($domain = array())
{ {
$this->_logger->logAction(CRON_ACTION, LOG_DEBUG, 'Generating dns config for ' . $domain['domain']); $this->logger->logAction(CRON_ACTION, LOG_DEBUG, 'Generating dns config for ' . $domain['domain']);
$bindconf_file = '# Domain ID: ' . $domain['id'] . ' - CustomerID: ' . $domain['customerid'] . ' - CustomerLogin: ' . $domain['loginname'] . "\n"; $bindconf_file = '# Domain ID: ' . $domain['id'] . ' - CustomerID: ' . $domain['customerid'] . ' - CustomerLogin: ' . $domain['loginname'] . "\n";
$bindconf_file .= 'zone "' . $domain['domain'] . '" in {' . "\n"; $bindconf_file .= 'zone "' . $domain['domain'] . '" in {' . "\n";
@@ -105,20 +105,20 @@ class Bind extends DnsBase
$bindconf_file .= ' file "' . \Froxlor\FileDir::makeCorrectFile(Settings::Get('system.bindconf_directory') . '/' . $domain['zonefile']) . '";' . "\n"; $bindconf_file .= ' file "' . \Froxlor\FileDir::makeCorrectFile(Settings::Get('system.bindconf_directory') . '/' . $domain['zonefile']) . '";' . "\n";
$bindconf_file .= ' allow-query { any; };' . "\n"; $bindconf_file .= ' allow-query { any; };' . "\n";
if (count($this->_ns) > 0 || count($this->_axfr) > 0) { if (count($this->ns) > 0 || count($this->axfr) > 0) {
// open allow-transfer // open allow-transfer
$bindconf_file .= ' allow-transfer {' . "\n"; $bindconf_file .= ' allow-transfer {' . "\n";
// put nameservers in allow-transfer // put nameservers in allow-transfer
if (count($this->_ns) > 0) { if (count($this->ns) > 0) {
foreach ($this->_ns as $ns) { foreach ($this->ns as $ns) {
foreach ($ns["ips"] as $ip) { foreach ($ns["ips"] as $ip) {
$bindconf_file .= ' ' . $ip . ";\n"; $bindconf_file .= ' ' . $ip . ";\n";
} }
} }
} }
// AXFR server #100 // AXFR server #100
if (count($this->_axfr) > 0) { if (count($this->axfr) > 0) {
foreach ($this->_axfr as $axfrserver) { foreach ($this->axfr as $axfrserver) {
$bindconf_file .= ' ' . $axfrserver . ';' . "\n"; $bindconf_file .= ' ' . $axfrserver . ';' . "\n";
} }
} }
@@ -132,11 +132,11 @@ class Bind extends DnsBase
return $bindconf_file; return $bindconf_file;
} }
private function _cleanZonefiles() private function cleanZonefiles()
{ {
$config_dir = \Froxlor\FileDir::makeCorrectFile(Settings::Get('system.bindconf_directory') . '/domains/'); $config_dir = \Froxlor\FileDir::makeCorrectFile(Settings::Get('system.bindconf_directory') . '/domains/');
$this->_logger->logAction(CRON_ACTION, LOG_INFO, 'Cleaning dns zone files from ' . $config_dir); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'Cleaning dns zone files from ' . $config_dir);
// check directory // check directory
if (@is_dir($config_dir)) { if (@is_dir($config_dir)) {

View File

@@ -27,19 +27,19 @@ use Froxlor\Settings;
abstract class DnsBase abstract class DnsBase
{ {
protected $_logger = false; protected $logger = false;
protected $_ns = array(); protected $ns = array();
protected $_mx = array(); protected $mx = array();
protected $_axfr = array(); protected $axfr = array();
abstract public function writeConfigs(); abstract public function writeConfigs();
public function __construct($logger) public function __construct($logger)
{ {
$this->_logger = $logger; $this->logger = $logger;
if (Settings::Get('system.nameservers') != '') { if (Settings::Get('system.nameservers') != '') {
$nameservers = explode(',', Settings::Get('system.nameservers')); $nameservers = explode(',', Settings::Get('system.nameservers'));
@@ -59,7 +59,7 @@ abstract class DnsBase
$nameserver $nameserver
); );
} }
$this->_ns[] = array( $this->ns[] = array(
'hostname' => $nameserver, 'hostname' => $nameserver,
'ips' => $nameserver_ips 'ips' => $nameserver_ips
); );
@@ -72,7 +72,7 @@ abstract class DnsBase
if (substr($mxserver, - 1, 1) != '.') { if (substr($mxserver, - 1, 1) != '.') {
$mxserver .= '.'; $mxserver .= '.';
} }
$this->_mx[] = $mxserver; $this->mx[] = $mxserver;
} }
} }
@@ -80,7 +80,7 @@ abstract class DnsBase
if (Settings::Get('system.axfrservers') != '') { if (Settings::Get('system.axfrservers') != '') {
$axfrservers = explode(',', Settings::Get('system.axfrservers')); $axfrservers = explode(',', Settings::Get('system.axfrservers'));
foreach ($axfrservers as $axfrserver) { foreach ($axfrservers as $axfrserver) {
$this->_axfr[] = trim($axfrserver); $this->axfr[] = trim($axfrserver);
} }
} }
} }
@@ -151,15 +151,15 @@ abstract class DnsBase
if (isset($domains[$domains[$key]['ismainbutsubto']])) { if (isset($domains[$domains[$key]['ismainbutsubto']])) {
$domains[$domains[$key]['ismainbutsubto']]['children'][] = $domains[$key]['id']; $domains[$domains[$key]['ismainbutsubto']]['children'][] = $domains[$key]['id'];
} else { } else {
$this->_logger->logAction(CRON_ACTION, LOG_ERR, 'Database inconsistency: domain ' . $domain['domain'] . ' (ID #' . $key . ') is set to to be subdomain to non-existent domain ID #' . $domains[$key]['ismainbutsubto'] . '. No DNS record(s) will be created for this domain.'); $this->logger->logAction(CRON_ACTION, LOG_ERR, 'Database inconsistency: domain ' . $domain['domain'] . ' (ID #' . $key . ') is set to to be subdomain to non-existent domain ID #' . $domains[$key]['ismainbutsubto'] . '. No DNS record(s) will be created for this domain.');
} }
} }
} }
$this->_logger->logAction(CRON_ACTION, LOG_DEBUG, str_pad('domId', 9, ' ') . str_pad('domain', 40, ' ') . 'ismainbutsubto ' . str_pad('parent domain', 40, ' ') . "list of child domain ids"); $this->logger->logAction(CRON_ACTION, LOG_DEBUG, str_pad('domId', 9, ' ') . str_pad('domain', 40, ' ') . 'ismainbutsubto ' . str_pad('parent domain', 40, ' ') . "list of child domain ids");
foreach ($domains as $domain) { foreach ($domains as $domain) {
$logLine = str_pad($domain['id'], 9, ' ') . str_pad($domain['domain'], 40, ' ') . str_pad($domain['ismainbutsubto'], 15, ' ') . str_pad(((isset($domains[$domain['ismainbutsubto']])) ? $domains[$domain['ismainbutsubto']]['domain'] : '-'), 40, ' ') . join(', ', $domain['children']); $logLine = str_pad($domain['id'], 9, ' ') . str_pad($domain['domain'], 40, ' ') . str_pad($domain['ismainbutsubto'], 15, ' ') . str_pad(((isset($domains[$domain['ismainbutsubto']])) ? $domains[$domain['ismainbutsubto']]['domain'] : '-'), 40, ' ') . join(', ', $domain['children']);
$this->_logger->logAction(CRON_ACTION, LOG_DEBUG, $logLine); $this->logger->logAction(CRON_ACTION, LOG_DEBUG, $logLine);
} }
return $domains; return $domains;
@@ -172,9 +172,9 @@ abstract class DnsBase
$cmdStatus = 1; $cmdStatus = 1;
\Froxlor\FileDir::safe_exec(escapeshellcmd($cmd), $cmdStatus); \Froxlor\FileDir::safe_exec(escapeshellcmd($cmd), $cmdStatus);
if ($cmdStatus === 0) { if ($cmdStatus === 0) {
$this->_logger->logAction(CRON_ACTION, LOG_INFO, Settings::Get('system.dns_server') . ' daemon reloaded'); $this->logger->logAction(CRON_ACTION, LOG_INFO, Settings::Get('system.dns_server') . ' daemon reloaded');
} else { } else {
$this->_logger->logAction(CRON_ACTION, LOG_ERR, 'Error while running `' . $cmd . '`: exit code (' . $cmdStatus . ') - please check your system logs'); $this->logger->logAction(CRON_ACTION, LOG_ERR, 'Error while running `' . $cmd . '`: exit code (' . $cmdStatus . ') - please check your system logs');
} }
} }
@@ -182,7 +182,7 @@ abstract class DnsBase
{ {
if (Settings::Get('dkim.use_dkim') == '1') { if (Settings::Get('dkim.use_dkim') == '1') {
if (! file_exists(\Froxlor\FileDir::makeCorrectDir(Settings::Get('dkim.dkim_prefix')))) { if (! file_exists(\Froxlor\FileDir::makeCorrectDir(Settings::Get('dkim.dkim_prefix')))) {
$this->_logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir -p ' . escapeshellarg(\Froxlor\FileDir::makeCorrectDir(Settings::Get('dkim.dkim_prefix')))); $this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir -p ' . escapeshellarg(\Froxlor\FileDir::makeCorrectDir(Settings::Get('dkim.dkim_prefix'))));
\Froxlor\FileDir::safe_exec('mkdir -p ' . escapeshellarg(\Froxlor\FileDir::makeCorrectDir(Settings::Get('dkim.dkim_prefix')))); \Froxlor\FileDir::safe_exec('mkdir -p ' . escapeshellarg(\Froxlor\FileDir::makeCorrectDir(Settings::Get('dkim.dkim_prefix'))));
} }
@@ -254,7 +254,7 @@ abstract class DnsBase
fclose($dkimkeys_file_handler); fclose($dkimkeys_file_handler);
\Froxlor\FileDir::safe_exec(escapeshellcmd(Settings::Get('dkim.dkimrestart_command'))); \Froxlor\FileDir::safe_exec(escapeshellcmd(Settings::Get('dkim.dkimrestart_command')));
$this->_logger->logAction(CRON_ACTION, LOG_INFO, 'Dkim-milter reloaded'); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'Dkim-milter reloaded');
} }
} }
} }

View File

@@ -21,15 +21,15 @@ class PowerDNS extends DnsBase
public function writeConfigs() public function writeConfigs()
{ {
// tell the world what we are doing // tell the world what we are doing
$this->_logger->logAction(CRON_ACTION, LOG_INFO, 'Task4 started - Refreshing DNS database'); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'Task4 started - Refreshing DNS database');
$domains = $this->getDomainList(); $domains = $this->getDomainList();
// clean up // clean up
$this->_clearZoneTables($domains); $this->clearZoneTables($domains);
if (empty($domains)) { if (empty($domains)) {
$this->_logger->logAction(CRON_ACTION, LOG_INFO, 'No domains found for nameserver-config, skipping...'); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'No domains found for nameserver-config, skipping...');
return; return;
} }
@@ -41,9 +41,9 @@ class PowerDNS extends DnsBase
$this->walkDomainList($domain, $domains); $this->walkDomainList($domain, $domains);
} }
$this->_logger->logAction(CRON_ACTION, LOG_INFO, 'PowerDNS database updated'); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'PowerDNS database updated');
$this->reloadDaemon(); $this->reloadDaemon();
$this->_logger->logAction(CRON_ACTION, LOG_INFO, 'Task4 finished'); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'Task4 finished');
} }
private function walkDomainList($domain, $domains) private function walkDomainList($domain, $domains)
@@ -69,21 +69,21 @@ class PowerDNS extends DnsBase
$zoneContent->records[] = $subzone; $zoneContent->records[] = $subzone;
} }
} }
$pdnsDomId = $this->_insertZone($zoneContent->origin, $zoneContent->serial); $pdnsDomId = $this->insertZone($zoneContent->origin, $zoneContent->serial);
$this->_insertRecords($pdnsDomId, $zoneContent->records, $zoneContent->origin); $this->insertRecords($pdnsDomId, $zoneContent->records, $zoneContent->origin);
$this->_insertAllowedTransfers($pdnsDomId); $this->insertAllowedTransfers($pdnsDomId);
$this->_logger->logAction(CRON_ACTION, LOG_INFO, 'DB entries stored for zone `' . $domain['domain'] . '`'); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'DB entries stored for zone `' . $domain['domain'] . '`');
} else { } else {
return \Froxlor\Dns\Dns::createDomainZone(($domain['id'] == 'none') ? $domain : $domain['id'], $isFroxlorHostname, true); return \Froxlor\Dns\Dns::createDomainZone(($domain['id'] == 'none') ? $domain : $domain['id'], $isFroxlorHostname, true);
} }
} else { } else {
$this->_logger->logAction(CRON_ACTION, LOG_ERROR, 'Custom zonefiles are NOT supported when PowerDNS is selected as DNS daemon (triggered by: ' . $domain['domain'] . ')'); $this->logger->logAction(CRON_ACTION, LOG_ERROR, 'Custom zonefiles are NOT supported when PowerDNS is selected as DNS daemon (triggered by: ' . $domain['domain'] . ')');
} }
} }
private function _clearZoneTables($domains = null) private function clearZoneTables($domains = null)
{ {
$this->_logger->logAction(CRON_ACTION, LOG_INFO, 'Cleaning dns zone entries from database'); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'Cleaning dns zone entries from database');
$pdns_domains_stmt = \Froxlor\Dns\PowerDNS::getDB()->prepare("SELECT `id`, `name` FROM `domains` WHERE `name` = :domain"); $pdns_domains_stmt = \Froxlor\Dns\PowerDNS::getDB()->prepare("SELECT `id`, `name` FROM `domains` WHERE `name` = :domain");
@@ -109,7 +109,7 @@ class PowerDNS extends DnsBase
} }
} }
private function _insertZone($domainname, $serial = 0) private function insertZone($domainname, $serial = 0)
{ {
$ins_stmt = PowerDNS::getDB()->prepare(" $ins_stmt = PowerDNS::getDB()->prepare("
INSERT INTO domains set `name` = :domainname, `notified_serial` = :serial, `type` = 'NATIVE' INSERT INTO domains set `name` = :domainname, `notified_serial` = :serial, `type` = 'NATIVE'
@@ -122,7 +122,7 @@ class PowerDNS extends DnsBase
return $lastid; return $lastid;
} }
private function _insertRecords($domainid = 0, $records, $origin) private function insertRecords($domainid = 0, $records, $origin)
{ {
$changedate = date('Ymds', time()); $changedate = date('Ymds', time());
@@ -140,7 +140,7 @@ class PowerDNS extends DnsBase
foreach ($records as $record) { foreach ($records as $record) {
if ($record instanceof \Froxlor\Dns\DnsZone) { if ($record instanceof \Froxlor\Dns\DnsZone) {
$this->_insertRecords($domainid, $record->records, $record->origin); $this->insertRecords($domainid, $record->records, $record->origin);
continue; continue;
} }
@@ -163,7 +163,7 @@ class PowerDNS extends DnsBase
} }
} }
private function _insertAllowedTransfers($domainid) private function insertAllowedTransfers($domainid)
{ {
$ins_stmt = PowerDNS::getDB()->prepare(" $ins_stmt = PowerDNS::getDB()->prepare("
INSERT INTO domainmetadata set `domain_id` = :did, `kind` = 'ALLOW-AXFR-FROM', `content` = :value INSERT INTO domainmetadata set `domain_id` = :did, `kind` = 'ALLOW-AXFR-FROM', `content` = :value
@@ -173,10 +173,10 @@ class PowerDNS extends DnsBase
'did' => $domainid 'did' => $domainid
); );
if (count($this->_ns) > 0 || count($this->_axfr) > 0) { if (count($this->ns) > 0 || count($this->axfr) > 0) {
// put nameservers in allow-transfer // put nameservers in allow-transfer
if (count($this->_ns) > 0) { if (count($this->ns) > 0) {
foreach ($this->_ns as $ns) { foreach ($this->ns as $ns) {
foreach ($ns["ips"] as $ip) { foreach ($ns["ips"] as $ip) {
$ins_data['value'] = $ip; $ins_data['value'] = $ip;
$ins_stmt->execute($ins_data); $ins_stmt->execute($ins_data);
@@ -184,8 +184,8 @@ class PowerDNS extends DnsBase
} }
} }
// AXFR server #100 // AXFR server #100
if (count($this->_axfr) > 0) { if (count($this->axfr) > 0) {
foreach ($this->_axfr as $axfrserver) { foreach ($this->axfr as $axfrserver) {
$ins_data['value'] = $axfrserver; $ins_data['value'] = $axfrserver;
$ins_stmt->execute($ins_data); $ins_stmt->execute($ins_data);
} }

View File

@@ -1,6 +1,23 @@
<?php <?php
namespace Froxlor\Cron; namespace Froxlor\Cron;
/**
* 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.10.0
*
*/
abstract class FroxlorCron abstract class FroxlorCron
{ {

View File

@@ -67,34 +67,33 @@ class Crypt
* *
* 0 - default crypt (depenend on system configuration) * 0 - default crypt (depenend on system configuration)
* 1 - MD5 $1$ * 1 - MD5 $1$
* 2 - BLOWFISH $2a$ | $2y$07$ (on php 5.3.7+) * 2 - BLOWFISH $2y$07$
* 3 - SHA-256 $5$ (default) * 3 - SHA-256 $5$ (default)
* 4 - SHA-512 $6$ * 4 - SHA-512 $6$
* *
* @param string $password * @param string $password
* Password to be crypted * Password to be crypted
* @param bool $htpasswd
* optional whether to generate a SHA1 password for directory protection
* *
* @return string encrypted password * @return string encrypted password
*/ */
public static function makeCryptPassword($password) public static function makeCryptPassword($password, $htpasswd = false)
{ {
if ($htpasswd) {
return '{SHA}' . base64_encode(sha1($password, true));
}
$type = Settings::Get('system.passwordcryptfunc') !== null ? (int) Settings::Get('system.passwordcryptfunc') : 3; $type = Settings::Get('system.passwordcryptfunc') !== null ? (int) Settings::Get('system.passwordcryptfunc') : 3;
switch ($type) { switch ($type) {
case 0:
$cryptPassword = crypt($password);
break;
case 1: case 1:
$cryptPassword = crypt($password, '$1$' . self::generatePassword(true) . self::generatePassword(true)); $cryptPassword = crypt($password, '$1$' . self::generatePassword(true) . self::generatePassword(true));
break; break;
case 2: case 2:
if (\Froxlor\Froxlor::version_compare(phpversion(), '5.3.7', '<')) {
$cryptPassword = crypt($password, '$2a$' . self::generatePassword(true) . self::generatePassword(true));
} else {
// Blowfish hashing with a salt as follows: "$2a$", "$2x$" or "$2y$", // Blowfish hashing with a salt as follows: "$2a$", "$2x$" or "$2y$",
// a two digit cost parameter, "$", and 22 characters from the alphabet "./0-9A-Za-z" // a two digit cost parameter, "$", and 22 characters from the alphabet "./0-9A-Za-z"
$cryptPassword = crypt($password, '$2y$07$' . substr(self::generatePassword(true) . self::generatePassword(true) . self::generatePassword(true), 0, 22)); $cryptPassword = crypt($password, '$2y$07$' . substr(self::generatePassword(true) . self::generatePassword(true) . self::generatePassword(true), 0, 22));
}
break; break;
case 3: case 3:
$cryptPassword = crypt($password, '$5$' . self::generatePassword(true) . self::generatePassword(true)); $cryptPassword = crypt($password, '$5$' . self::generatePassword(true) . self::generatePassword(true));
@@ -103,7 +102,7 @@ class Crypt
$cryptPassword = crypt($password, '$6$' . self::generatePassword(true) . self::generatePassword(true)); $cryptPassword = crypt($password, '$6$' . self::generatePassword(true) . self::generatePassword(true));
break; break;
default: default:
$cryptPassword = crypt($password); $cryptPassword = crypt($password, self::generatePassword(true) . self::generatePassword(true));
break; break;
} }
return $cryptPassword; return $cryptPassword;

View File

@@ -454,7 +454,7 @@ $lng['admin']['subcanemaildomain']['never'] = 'Nooit';
$lng['admin']['subcanemaildomain']['choosableno'] = 'Kiesbaar, standaard nee'; $lng['admin']['subcanemaildomain']['choosableno'] = 'Kiesbaar, standaard nee';
$lng['admin']['subcanemaildomain']['choosableyes'] = 'Kiesbaar, standaard ja'; $lng['admin']['subcanemaildomain']['choosableyes'] = 'Kiesbaar, standaard ja';
$lng['admin']['subcanemaildomain']['always'] = 'Altijd'; $lng['admin']['subcanemaildomain']['always'] = 'Altijd';
$lng['changepassword']['also_change_webalizer'] = ' wijzig ook het wachtwoord van de webalizer-statistieken'; $lng['changepassword']['also_change_stats'] = ' wijzig ook het wachtwoord van de statistieken';
// ADDED IN 1.2.16-svn8 // ADDED IN 1.2.16-svn8

View File

@@ -511,7 +511,7 @@ $lng['admin']['subcanemaildomain']['never'] = 'Never';
$lng['admin']['subcanemaildomain']['choosableno'] = 'Choosable, default no'; $lng['admin']['subcanemaildomain']['choosableno'] = 'Choosable, default no';
$lng['admin']['subcanemaildomain']['choosableyes'] = 'Choosable, default yes'; $lng['admin']['subcanemaildomain']['choosableyes'] = 'Choosable, default yes';
$lng['admin']['subcanemaildomain']['always'] = 'Always'; $lng['admin']['subcanemaildomain']['always'] = 'Always';
$lng['changepassword']['also_change_webalizer'] = ' also change password for the statistics page'; $lng['changepassword']['also_change_stats'] = ' also change password for the statistics page';
// ADDED IN 1.2.16-svn8 // ADDED IN 1.2.16-svn8

View File

@@ -506,7 +506,7 @@ $lng['admin']['subcanemaildomain']['never'] = 'Nie';
$lng['admin']['subcanemaildomain']['choosableno'] = 'Wählbar, Standardwert: Nein'; $lng['admin']['subcanemaildomain']['choosableno'] = 'Wählbar, Standardwert: Nein';
$lng['admin']['subcanemaildomain']['choosableyes'] = 'Wählbar, Standardwert: Ja'; $lng['admin']['subcanemaildomain']['choosableyes'] = 'Wählbar, Standardwert: Ja';
$lng['admin']['subcanemaildomain']['always'] = 'Immer'; $lng['admin']['subcanemaildomain']['always'] = 'Immer';
$lng['changepassword']['also_change_webalizer'] = ' Auch Passwort der Statistikseite ändern'; $lng['changepassword']['also_change_stats'] = ' Auch Passwort der Statistikseite ändern';
// ADDED IN 1.2.16-svn8 // ADDED IN 1.2.16-svn8

View File

@@ -482,7 +482,7 @@ $lng['admin']['subcanemaildomain']['never'] = 'Mai';
$lng['admin']['subcanemaildomain']['choosableno'] = 'Selezionabile, predefinito no'; $lng['admin']['subcanemaildomain']['choosableno'] = 'Selezionabile, predefinito no';
$lng['admin']['subcanemaildomain']['choosableyes'] = 'Selezionabile, predefinito si'; $lng['admin']['subcanemaildomain']['choosableyes'] = 'Selezionabile, predefinito si';
$lng['admin']['subcanemaildomain']['always'] = 'Sempre'; $lng['admin']['subcanemaildomain']['always'] = 'Sempre';
$lng['changepassword']['also_change_webalizer'] = ' modificare anche la password di webalizer'; $lng['changepassword']['also_change_stats'] = ' modificare anche la password di statistic';
// ADDED IN 1.2.16-svn8 // ADDED IN 1.2.16-svn8

View File

@@ -454,7 +454,7 @@ $lng['admin']['subcanemaildomain']['never'] = 'Nunca';
$lng['admin']['subcanemaildomain']['choosableno'] = 'Escolhe, default não'; $lng['admin']['subcanemaildomain']['choosableno'] = 'Escolhe, default não';
$lng['admin']['subcanemaildomain']['choosableyes'] = 'Escolher, default sim'; $lng['admin']['subcanemaildomain']['choosableyes'] = 'Escolher, default sim';
$lng['admin']['subcanemaildomain']['always'] = 'Sempre'; $lng['admin']['subcanemaildomain']['always'] = 'Sempre';
$lng['changepassword']['also_change_webalizer'] = 'Troca a senha das estatísticas do webalizer'; $lng['changepassword']['also_change_stats'] = 'Troca a senha das estatísticas';
$lng['serversettings']['mailpwcleartext']['title'] = 'Salva as senhas de usuários sempre criptografia no banco de dados'; $lng['serversettings']['mailpwcleartext']['title'] = 'Salva as senhas de usuários sempre criptografia no banco de dados';
$lng['serversettings']['mailpwcleartext']['description'] = 'Se você selecionar sim, todas as senhas serão guardadas descriptografadas (Poderá ser lido por todos com acesso ao banco de dados ) na tabela mail_users-table. Somente ative essa opção se você realmente precise!'; $lng['serversettings']['mailpwcleartext']['description'] = 'Se você selecionar sim, todas as senhas serão guardadas descriptografadas (Poderá ser lido por todos com acesso ao banco de dados ) na tabela mail_users-table. Somente ative essa opção se você realmente precise!';
$lng['serversettings']['mailpwcleartext']['removelink'] = 'Clique aqui para limpar todas as senhas não criptografadas da tabela<br />Você realmente deseja limpar todas as senhas não encriptadas a partir da tabela mail_users? Isto não pode ser revertido!'; $lng['serversettings']['mailpwcleartext']['removelink'] = 'Clique aqui para limpar todas as senhas não criptografadas da tabela<br />Você realmente deseja limpar todas as senhas não encriptadas a partir da tabela mail_users? Isto não pode ser revertido!';

View File

@@ -474,7 +474,7 @@ $lng['admin']['subcanemaildomain']['never'] = 'Aldrig';
$lng['admin']['subcanemaildomain']['choosableno'] = 'Valbar, standardvärdet är Nej'; $lng['admin']['subcanemaildomain']['choosableno'] = 'Valbar, standardvärdet är Nej';
$lng['admin']['subcanemaildomain']['choosableyes'] = 'Valbar, standardvärdet är Ja'; $lng['admin']['subcanemaildomain']['choosableyes'] = 'Valbar, standardvärdet är Ja';
$lng['admin']['subcanemaildomain']['always'] = 'Alltid'; $lng['admin']['subcanemaildomain']['always'] = 'Alltid';
$lng['changepassword']['also_change_webalizer'] = ' Ändra även lösenord för webalizer statistik'; $lng['changepassword']['also_change_stats'] = ' Ändra även lösenord för statistik';
// ADDED IN 1.2.16-svn8 // ADDED IN 1.2.16-svn8

View File

@@ -36,8 +36,8 @@ $header
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td> <td>
<input type="checkbox" name="change_webalizer" id="change_webalizer" value="true" /> <input type="checkbox" name="change_stats" id="change_stats" value="true" />
<label for="change_webalizer">{$lng['changepassword']['also_change_webalizer']}</label> <label for="change_stats">{$lng['changepassword']['also_change_stats']}</label>
</td> </td>
</tr> </tr>
<tfoot> <tfoot>