more function reducing and fixing

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-12-21 16:53:04 +01:00
parent 0a28ef2af6
commit a819d81ef2
21 changed files with 125 additions and 179 deletions

View File

@@ -67,7 +67,7 @@ if ($page == 'overview') {
'page' => 'error', 'page' => 'error',
'errno' => 3 'errno' => 3
)); ));
} elseif (version_compare2($version, $_version) == - 1) { } elseif (\Froxlor\Froxlor::version_compare2($version, $_version) == - 1) {
// there is a newer version - yay // there is a newer version - yay
$isnewerversion = 1; $isnewerversion = 1;
} else { } else {

View File

@@ -107,7 +107,7 @@ if ($page == '' || $page == 'overview') {
$value_arr = array(); $value_arr = array();
$value_arr['diskspace'] = intval_ressource($_POST['diskspace']); $value_arr['diskspace'] = (int)($_POST['diskspace']);
if (isset($_POST['diskspace_ul'])) { if (isset($_POST['diskspace_ul'])) {
$value_arr['diskspace'] = - 1; $value_arr['diskspace'] = - 1;
} }
@@ -117,22 +117,22 @@ if ($page == '' || $page == 'overview') {
$value_arr['traffic'] = - 1; $value_arr['traffic'] = - 1;
} }
$value_arr['subdomains'] = intval_ressource($_POST['subdomains']); $value_arr['subdomains'] = (int)($_POST['subdomains']);
if (isset($_POST['subdomains_ul'])) { if (isset($_POST['subdomains_ul'])) {
$value_arr['subdomains'] = - 1; $value_arr['subdomains'] = - 1;
} }
$value_arr['emails'] = intval_ressource($_POST['emails']); $value_arr['emails'] = (int)($_POST['emails']);
if (isset($_POST['emails_ul'])) { if (isset($_POST['emails_ul'])) {
$value_arr['emails'] = - 1; $value_arr['emails'] = - 1;
} }
$value_arr['email_accounts'] = intval_ressource($_POST['email_accounts']); $value_arr['email_accounts'] = (int)($_POST['email_accounts']);
if (isset($_POST['email_accounts_ul'])) { if (isset($_POST['email_accounts_ul'])) {
$value_arr['email_accounts'] = - 1; $value_arr['email_accounts'] = - 1;
} }
$value_arr['email_forwarders'] = intval_ressource($_POST['email_forwarders']); $value_arr['email_forwarders'] = (int)($_POST['email_forwarders']);
if (isset($_POST['email_forwarders_ul'])) { if (isset($_POST['email_forwarders_ul'])) {
$value_arr['email_forwarders'] = - 1; $value_arr['email_forwarders'] = - 1;
} }
@@ -151,20 +151,20 @@ if ($page == '' || $page == 'overview') {
$value_arr['email_imap'] = 0; $value_arr['email_imap'] = 0;
if (isset($_POST['email_imap'])) { if (isset($_POST['email_imap'])) {
$value_arr['email_imap'] = intval_ressource($_POST['email_imap']); $value_arr['email_imap'] = (int)($_POST['email_imap']);
} }
$value_arr['email_pop3'] = 0; $value_arr['email_pop3'] = 0;
if (isset($_POST['email_pop3'])) { if (isset($_POST['email_pop3'])) {
$value_arr['email_pop3'] = intval_ressource($_POST['email_pop3']); $value_arr['email_pop3'] = (int)($_POST['email_pop3']);
} }
$value_arr['ftps'] = intval_ressource($_POST['ftps']); $value_arr['ftps'] = (int)($_POST['ftps']);
if (isset($_POST['ftps_ul'])) { if (isset($_POST['ftps_ul'])) {
$value_arr['ftps'] = - 1; $value_arr['ftps'] = - 1;
} }
$value_arr['mysqls'] = intval_ressource($_POST['mysqls']); $value_arr['mysqls'] = (int)($_POST['mysqls']);
if (isset($_POST['mysqls_ul'])) { if (isset($_POST['mysqls_ul'])) {
$value_arr['mysqls'] = - 1; $value_arr['mysqls'] = - 1;
} }
@@ -285,7 +285,7 @@ if ($page == '' || $page == 'overview') {
$value_arr = array(); $value_arr = array();
$value_arr['diskspace'] = intval_ressource($_POST['diskspace']); $value_arr['diskspace'] = (int)($_POST['diskspace']);
if (isset($_POST['diskspace_ul'])) { if (isset($_POST['diskspace_ul'])) {
$value_arr['diskspace'] = - 1; $value_arr['diskspace'] = - 1;
} }
@@ -295,22 +295,22 @@ if ($page == '' || $page == 'overview') {
$value_arr['traffic'] = - 1; $value_arr['traffic'] = - 1;
} }
$value_arr['subdomains'] = intval_ressource($_POST['subdomains']); $value_arr['subdomains'] = (int)($_POST['subdomains']);
if (isset($_POST['subdomains_ul'])) { if (isset($_POST['subdomains_ul'])) {
$value_arr['subdomains'] = - 1; $value_arr['subdomains'] = - 1;
} }
$value_arr['emails'] = intval_ressource($_POST['emails']); $value_arr['emails'] = (int)($_POST['emails']);
if (isset($_POST['emails_ul'])) { if (isset($_POST['emails_ul'])) {
$value_arr['emails'] = - 1; $value_arr['emails'] = - 1;
} }
$value_arr['email_accounts'] = intval_ressource($_POST['email_accounts']); $value_arr['email_accounts'] = (int)($_POST['email_accounts']);
if (isset($_POST['email_accounts_ul'])) { if (isset($_POST['email_accounts_ul'])) {
$value_arr['email_accounts'] = - 1; $value_arr['email_accounts'] = - 1;
} }
$value_arr['email_forwarders'] = intval_ressource($_POST['email_forwarders']); $value_arr['email_forwarders'] = (int)($_POST['email_forwarders']);
if (isset($_POST['email_forwarders_ul'])) { if (isset($_POST['email_forwarders_ul'])) {
$value_arr['email_forwarders'] = - 1; $value_arr['email_forwarders'] = - 1;
} }
@@ -329,20 +329,20 @@ if ($page == '' || $page == 'overview') {
$value_arr['email_imap'] = 0; $value_arr['email_imap'] = 0;
if (isset($_POST['email_imap'])) { if (isset($_POST['email_imap'])) {
$value_arr['email_imap'] = intval_ressource($_POST['email_imap']); $value_arr['email_imap'] = (int)($_POST['email_imap']);
} }
$value_arr['email_pop3'] = 0; $value_arr['email_pop3'] = 0;
if (isset($_POST['email_pop3'])) { if (isset($_POST['email_pop3'])) {
$value_arr['email_pop3'] = intval_ressource($_POST['email_pop3']); $value_arr['email_pop3'] = (int)($_POST['email_pop3']);
} }
$value_arr['ftps'] = intval_ressource($_POST['ftps']); $value_arr['ftps'] = (int)($_POST['ftps']);
if (isset($_POST['ftps_ul'])) { if (isset($_POST['ftps_ul'])) {
$value_arr['ftps'] = - 1; $value_arr['ftps'] = - 1;
} }
$value_arr['mysqls'] = intval_ressource($_POST['mysqls']); $value_arr['mysqls'] = (int)($_POST['mysqls']);
if (isset($_POST['mysqls_ul'])) { if (isset($_POST['mysqls_ul'])) {
$value_arr['mysqls'] = - 1; $value_arr['mysqls'] = - 1;
} }

View File

@@ -120,11 +120,11 @@ if ($page == 'overview') {
} elseif ($page == 'change_password') { } elseif ($page == 'change_password') {
if (isset($_POST['send']) && $_POST['send'] == 'send') { if (isset($_POST['send']) && $_POST['send'] == 'send') {
$old_password = \Froxlor\Validate\Validate::validate($_POST['old_password'], 'old password'); $old_password = \Froxlor\Validate\Validate::validate($_POST['old_password'], 'old password');
if (! validatePasswordLogin($userinfo, $old_password, TABLE_PANEL_CUSTOMERS, 'customerid')) { if (! \Froxlor\System\Crypt::validatePasswordLogin($userinfo, $old_password, TABLE_PANEL_CUSTOMERS, 'customerid')) {
\Froxlor\UI\Response::standard_error('oldpasswordnotcorrect'); \Froxlor\UI\Response::standard_error('oldpasswordnotcorrect');
} }
$new_password = validatePassword($_POST['new_password'], 'new password'); $new_password = \Froxlor\System\Crypt::validatePassword($_POST['new_password'], 'new password');
$new_password_confirm = validatePassword($_POST['new_password_confirm'], 'new password confirm'); $new_password_confirm = validatePassword($_POST['new_password_confirm'], 'new password confirm');
if ($old_password == '') { if ($old_password == '') {

View File

@@ -602,8 +602,8 @@ if ($action == 'resetpwd') {
$new_password = \Froxlor\Validate\Validate::validate($_POST['new_password'], 'new password'); $new_password = \Froxlor\Validate\Validate::validate($_POST['new_password'], 'new password');
$new_password_confirm = \Froxlor\Validate\Validate::validate($_POST['new_password_confirm'], 'new password confirm'); $new_password_confirm = \Froxlor\Validate\Validate::validate($_POST['new_password_confirm'], 'new password confirm');
} else { } else {
$new_password = validatePassword($_POST['new_password'], 'new password'); $new_password = \Froxlor\System\Crypt::validatePassword($_POST['new_password'], 'new password');
$new_password_confirm = validatePassword($_POST['new_password_confirm'], 'new password confirm'); $new_password_confirm = \Froxlor\System\Crypt::validatePassword($_POST['new_password_confirm'], 'new password confirm');
} }
if ($new_password == '') { if ($new_password == '') {

View File

@@ -1081,7 +1081,7 @@ if (\Froxlor\Froxlor::isFroxlorVersion('0.9.12')) {
lastStepStatus(0); lastStepStatus(0);
if ((int) Settings::Get('autoresponder.autoresponder_active') == 1) { if ((int) Settings::Get('autoresponder.autoresponder_active') == 1) {
$update_autoresponder_default = isset($_POST['update_autoresponder_default']) ? intval_ressource($_POST['update_autoresponder_default']) : 0; $update_autoresponder_default = isset($_POST['update_autoresponder_default']) ? (int)($_POST['update_autoresponder_default']) : 0;
if (isset($_POST['update_autoresponder_default_ul'])) { if (isset($_POST['update_autoresponder_default_ul'])) {
$update_autoresponder_default = - 1; $update_autoresponder_default = - 1;
} }

View File

@@ -51,5 +51,5 @@ function versionInUpdate($current_version, $version_to_check)
return true; return true;
} }
return (version_compare2($current_version, $version_to_check) == - 1 ? true : false); return (\Froxlor\Froxlor::version_compare2($current_version, $version_to_check) == - 1 ? true : false);
} }

View File

@@ -123,7 +123,7 @@ abstract class ApiParameter
*/ */
protected function getUlParam($param = null, $ul_field = null, $optional = false, $default = 0) protected function getUlParam($param = null, $ul_field = null, $optional = false, $default = 0)
{ {
$param_value = intval_ressource($this->getParam($param, $optional, $default)); $param_value = (int)$this->getParam($param, $optional, $default);
$ul_field_value = $this->getBoolParam($ul_field, true, 0); $ul_field_value = $this->getBoolParam($ul_field, true, 0);
if ($ul_field_value != '0') { if ($ul_field_value != '0') {
$param_value = - 1; $param_value = - 1;
@@ -169,7 +169,7 @@ abstract class ApiParameter
// check one level deeper // check one level deeper
return $this->getModFunctionString(++ $level, $max_level, $trace); return $this->getModFunctionString(++ $level, $max_level, $trace);
} }
return $class . ':' . $func; return str_replace("Froxlor\\Api\\Commands\\", "", $class) . ':' . $func;
} }
/** /**

View File

@@ -208,7 +208,7 @@ class Admins extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
// only check if not empty, // only check if not empty,
// cause empty == generate password automatically // cause empty == generate password automatically
if ($password != '') { if ($password != '') {
$password = validatePassword($password, true); $password = \Froxlor\System\Crypt::validatePassword($password, true);
} }
$diskspace = $diskspace * 1024; $diskspace = $diskspace * 1024;
@@ -529,7 +529,7 @@ class Admins extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
} }
if ($password != '') { if ($password != '') {
$password = validatePassword($password, true); $password = \Froxlor\System\Crypt::validatePassword($password, true);
$password = \Froxlor\System\Crypt::makeCryptPassword($password); $password = \Froxlor\System\Crypt::makeCryptPassword($password);
} else { } else {
$password = $result['password']; $password = $result['password'];

View File

@@ -227,7 +227,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
$fax = $this->getParam('fax', true, ''); $fax = $this->getParam('fax', true, '');
$customernumber = $this->getParam('customernumber', true, ''); $customernumber = $this->getParam('customernumber', true, '');
$def_language = $this->getParam('def_language', true, Settings::Get('panel.standardlanguage')); $def_language = $this->getParam('def_language', true, Settings::Get('panel.standardlanguage'));
$gender = intval_ressource($this->getParam('gender', true, 0)); $gender = (int) $this->getParam('gender', true, 0);
$custom_notes = $this->getParam('custom_notes', true, ''); $custom_notes = $this->getParam('custom_notes', true, '');
$custom_notes_show = $this->getBoolParam('custom_notes_show', true, 0); $custom_notes_show = $this->getBoolParam('custom_notes_show', true, 0);
@@ -276,7 +276,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
// only check if not empty, // only check if not empty,
// cause empty == generate password automatically // cause empty == generate password automatically
if ($password != '') { if ($password != '') {
$password = validatePassword($password, true); $password = \Froxlor\System\Crypt::validatePassword($password, true);
} }
// gender out of range? [0,2] // gender out of range? [0,2]
@@ -846,7 +846,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
if ($this->isAdmin()) { if ($this->isAdmin()) {
// parameters // parameters
$move_to_admin = intval_ressource($this->getBoolParam('move_to_admin', true, 0)); $move_to_admin = (int) ($this->getBoolParam('move_to_admin', true, 0));
$idna_convert = new \Froxlor\Idna\IdnaWrapper(); $idna_convert = new \Froxlor\Idna\IdnaWrapper();
$email = $this->getParam('email', true, $idna_convert->decode($result['email'])); $email = $this->getParam('email', true, $idna_convert->decode($result['email']));
@@ -861,7 +861,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
$fax = $this->getParam('fax', true, $result['fax']); $fax = $this->getParam('fax', true, $result['fax']);
$customernumber = $this->getParam('customernumber', true, $result['customernumber']); $customernumber = $this->getParam('customernumber', true, $result['customernumber']);
$def_language = $this->getParam('def_language', true, $result['def_language']); $def_language = $this->getParam('def_language', true, $result['def_language']);
$gender = intval_ressource($this->getParam('gender', true, $result['gender'])); $gender = (int) $this->getParam('gender', true, $result['gender']);
$custom_notes = $this->getParam('custom_notes', true, $result['custom_notes']); $custom_notes = $this->getParam('custom_notes', true, $result['custom_notes']);
$custom_notes_show = $this->getBoolParam('custom_notes_show', true, $result['custom_notes_show']); $custom_notes_show = $this->getBoolParam('custom_notes_show', true, $result['custom_notes_show']);
@@ -940,7 +940,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
} }
if ($password != '') { if ($password != '') {
$password = validatePassword($password, true); $password = \Froxlor\System\Crypt::validatePassword($password, true);
$password = \Froxlor\System\Crypt::makeCryptPassword($password); $password = \Froxlor\System\Crypt::makeCryptPassword($password);
} else { } else {
$password = $result['password']; $password = $result['password'];

View File

@@ -143,7 +143,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
// remove it for checks // remove it for checks
$content = substr($content, 0, - 1); $content = substr($content, 0, - 1);
} }
if (! validateDomain($content)) { if (! \Froxlor\Validate\Validate::validateDomain($content)) {
$errors[] = $this->lng['error']['dns_mx_needdom']; $errors[] = $this->lng['error']['dns_mx_needdom'];
} else { } else {
// check whether there is a CNAME-record for the same resource // check whether there is a CNAME-record for the same resource
@@ -166,7 +166,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
// add domain name // add domain name
$content .= '.' . $domain; $content .= '.' . $domain;
} }
if (! validateDomain($content, true)) { if (! \Froxlor\Validate\Validate::validateDomain($content, true)) {
$errors[] = $this->lng['error']['dns_cname_invaliddom']; $errors[] = $this->lng['error']['dns_cname_invaliddom'];
} else { } else {
// check whether there are RR-records for the same resource // check whether there are RR-records for the same resource
@@ -185,7 +185,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
// remove it for checks // remove it for checks
$content = substr($content, 0, - 1); $content = substr($content, 0, - 1);
} }
if (! validateDomain($content)) { if (! \Froxlor\Validate\Validate::validateDomain($content)) {
$errors[] = $this->lng['error']['dns_ns_invaliddom']; $errors[] = $this->lng['error']['dns_ns_invaliddom'];
} }
// append trailing dot (again) // append trailing dot (again)
@@ -212,7 +212,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
$target = substr($target, 0, - 1); $target = substr($target, 0, - 1);
} }
} }
if ($target != '.' && ! validateDomain($target, true)) { if ($target != '.' && ! \Froxlor\Validate\Validate::validateDomain($target, true)) {
$errors[] = $this->lng['error']['dns_srv_needdom']; $errors[] = $this->lng['error']['dns_srv_needdom'];
} else { } else {
// check whether there is a CNAME-record for the same resource // check whether there is a CNAME-record for the same resource

View File

@@ -85,7 +85,7 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso
$idna_convert = new \Froxlor\Idna\IdnaWrapper(); $idna_convert = new \Froxlor\Idna\IdnaWrapper();
$username = $idna_convert->decode($email_full); $username = $idna_convert->decode($email_full);
$password = \Froxlor\Validate\Validate::validate($email_password, 'password', '', '', array(), true); $password = \Froxlor\Validate\Validate::validate($email_password, 'password', '', '', array(), true);
$password = validatePassword($password, true); $password = \Froxlor\System\Crypt::validatePassword($password, true);
if ($result['popaccountid'] != 0) { if ($result['popaccountid'] != 0) {
throw new \Exception("Email address '" . $email_full . "' has already an account assigned.", 406); throw new \Exception("Email address '" . $email_full . "' has already an account assigned.", 406);
@@ -346,7 +346,7 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso
if ($password == $result['email_full']) { if ($password == $result['email_full']) {
\Froxlor\UI\Response::standard_error('passwordshouldnotbeusername', '', true); \Froxlor\UI\Response::standard_error('passwordshouldnotbeusername', '', true);
} }
$password = validatePassword($password, true); $password = \Froxlor\System\Crypt::validatePassword($password, true);
$cryptPassword = \Froxlor\System\Crypt::makeCryptPassword($password); $cryptPassword = \Froxlor\System\Crypt::makeCryptPassword($password);
$upd_query .= (Settings::Get('system.mailpwcleartext') == '1' ? "`password` = :password, " : '') . "`password_enc`= :password_enc"; $upd_query .= (Settings::Get('system.mailpwcleartext') == '1' ? "`password` = :password, " : '') . "`password_enc`= :password_enc";
$upd_params['password_enc'] = $cryptPassword; $upd_params['password_enc'] = $cryptPassword;

View File

@@ -58,7 +58,7 @@ class Froxlor extends \Froxlor\Api\ApiCommand
// check for customized version to not output // check for customized version to not output
// "There is a newer version of froxlor" besides the error-message // "There is a newer version of froxlor" besides the error-message
$isnewerversion = - 1; $isnewerversion = - 1;
} elseif (version_compare2($this->version, $_version) == - 1) { } elseif (\Froxlor\Froxlor::version_compare2($this->version, $_version) == - 1) {
// there is a newer version - yay // there is a newer version - yay
$isnewerversion = 1; $isnewerversion = 1;
} else { } else {

View File

@@ -68,7 +68,7 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
// validation // validation
$password = \Froxlor\Validate\Validate::validate($password, 'password', '', '', array(), true); $password = \Froxlor\Validate\Validate::validate($password, 'password', '', '', array(), true);
$password = validatePassword($password, true); $password = \Froxlor\System\Crypt::validatePassword($password, true);
$description = \Froxlor\Validate\Validate::validate(trim($description), 'description', '', '', array(), true); $description = \Froxlor\Validate\Validate::validate(trim($description), 'description', '', '', array(), true);
if (Settings::Get('system.allow_customer_shell') == '1') { if (Settings::Get('system.allow_customer_shell') == '1') {
@@ -353,7 +353,7 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
// password update? // password update?
if ($password != '') { if ($password != '') {
// validate password // validate password
$password = validatePassword($password, true); $password = \Froxlor\System\Crypt::validatePassword($password, true);
if ($password == $result['username']) { if ($password == $result['username']) {
\Froxlor\UI\Response::standard_error('passwordshouldnotbeusername', '', true); \Froxlor\UI\Response::standard_error('passwordshouldnotbeusername', '', true);

View File

@@ -54,7 +54,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
// validation // validation
$password = \Froxlor\Validate\Validate::validate($password, 'password', '', '', array(), true); $password = \Froxlor\Validate\Validate::validate($password, 'password', '', '', array(), true);
$password = validatePassword($password, true); $password = \Froxlor\System\Crypt::validatePassword($password, true);
$databasedescription = \Froxlor\Validate\Validate::validate(trim($databasedescription), 'description', '', '', array(), true); $databasedescription = \Froxlor\Validate\Validate::validate(trim($databasedescription), 'description', '', '', array(), true);
// validate whether the dbserver exists // validate whether the dbserver exists
@@ -315,7 +315,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
if ($password != '') { if ($password != '') {
// validate password // validate password
$password = validatePassword($password, true); $password = \Froxlor\System\Crypt::validatePassword($password, true);
if ($password == $result['databasename']) { if ($password == $result['databasename']) {
\Froxlor\UI\Response::standard_error('passwordshouldnotbeusername', '', true); \Froxlor\UI\Response::standard_error('passwordshouldnotbeusername', '', true);

View File

@@ -104,7 +104,7 @@ class SubDomains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
// merge the two parts together // merge the two parts together
$completedomain = $subdomain . '.' . $domain; $completedomain = $subdomain . '.' . $domain;
if (Settings::Get('system.validate_domain') && ! validateDomain($completedomain)) { if (Settings::Get('system.validate_domain') && ! \Froxlor\Validate\Validate::validateDomain($completedomain)) {
\Froxlor\UI\Response::standard_error(array( \Froxlor\UI\Response::standard_error(array(
'stringiswrong', 'stringiswrong',
'mydomain' 'mydomain'

View File

@@ -16,7 +16,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
public function run() public function run()
{ {
$this->_\Froxlor\Validate\Validate::validate(); $this->_validate();
} }
/** /**
@@ -24,7 +24,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
* *
* @throws \Exception * @throws \Exception
*/ */
private function _\Froxlor\Validate\Validate::validate() private function _validate()
{ {
$this->_checkConfigParam(true); $this->_checkConfigParam(true);
$this->_parseConfig(); $this->_parseConfig();

View File

@@ -14,7 +14,7 @@ class SwitchServerIpAction extends \Froxlor\Cli\Action
public function run() public function run()
{ {
$this->_\Froxlor\Validate\Validate::validate(); $this->_validate();
} }
/** /**
@@ -22,7 +22,7 @@ class SwitchServerIpAction extends \Froxlor\Cli\Action
* *
* @throws \Exception * @throws \Exception
*/ */
private function _\Froxlor\Validate\Validate::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)) {

View File

@@ -201,4 +201,76 @@ final class Froxlor
} }
return false; return false;
} }
/**
* compare of froxlor versions
*
* @param string $a
* @param string $b
*
* @return integer 0 if equal, 1 if a>b and -1 if b>a
*/
public static function version_compare2($a, $b)
{
// split version into pieces and remove trailing .0
$a = explode(".", $a);
$b = explode(".", $b);
self::_parseVersionArray($a);
self::_parseVersionArray($b);
while (count($a) != count($b)) {
if (count($a) < count($b)) {
$a[] = '0';
} elseif (count($b) < count($a)) {
$b[] = '0';
}
}
foreach ($a as $depth => $aVal) {
// iterate over each piece of A
if (isset($b[$depth])) {
// if B matches A to this depth, compare the values
if ($aVal > $b[$depth]) {
return 1; // A > B
} else if ($aVal < $b[$depth]) {
return - 1; // B > A
}
// an equal result is inconclusive at this point
} else {
// if B does not match A to this depth, then A comes after B in sort order
return 1; // so A > B
}
}
// at this point, we know that to the depth that A and B extend to, they are equivalent.
// either the loop ended because A is shorter than B, or both are equal.
return (count($a) < count($b)) ? - 1 : 0;
}
private static function _parseVersionArray(&$arr = null)
{
// -svn or -dev or -rc ?
if (stripos($arr[count($arr) - 1], '-') !== false) {
$x = explode("-", $arr[count($arr) - 1]);
$arr[count($arr) - 1] = $x[0];
if (stripos($x[1], 'rc') !== false) {
$arr[] = '-1';
$arr[] = '2'; // rc > dev > svn
// number of rc
$arr[] = substr($x[1], 2);
} else if (stripos($x[1], 'dev') !== false) {
$arr[] = '-1';
$arr[] = '1'; // svn < dev < rc
// number of dev
$arr[] = substr($x[1], 3);
} // -svn version are deprecated
else if (stripos($x[1], 'svn') !== false) {
$arr[] = '-1';
$arr[] = '0'; // svn < dev < rc
// number of svn
$arr[] = substr($x[1], 3);
}
}
}
} }

View File

@@ -88,7 +88,7 @@ class Crypt
$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 (version_compare(phpversion(), '5.3.7', '<')) { if (\Froxlor\Froxlor::version_compare(phpversion(), '5.3.7', '<')) {
$cryptPassword = crypt($password, '$2a$' . self::generatePassword(true) . self::generatePassword(true)); $cryptPassword = crypt($password, '$2a$' . self::generatePassword(true) . self::generatePassword(true));
} else { } else {
// Blowfish hashing with a salt as follows: "$2a$", "$2x$" or "$2y$", // Blowfish hashing with a salt as follows: "$2a$", "$2x$" or "$2y$",
@@ -228,7 +228,7 @@ class Crypt
if ($pwd_hash == $pwd_check) { if ($pwd_hash == $pwd_check) {
// check for update of hash (only if our database is ready to handle the bigger string) // check for update of hash (only if our database is ready to handle the bigger string)
$is_ready = (version_compare2("0.9.33", \Froxlor\Froxlor::getVersion()) <= 0 ? true : false); $is_ready = (\Froxlor\Froxlor::version_compare2("0.9.33", \Froxlor\Froxlor::getVersion()) <= 0 ? true : false);
if ($update_hash && $is_ready) { if ($update_hash && $is_ready) {
$upd_stmt = \Froxlor\Database\Database::prepare(" $upd_stmt = \Froxlor\Database\Database::prepare("
UPDATE " . $table . " SET `password` = :newpasswd WHERE `" . $uid . "` = :uid UPDATE " . $table . " SET `password` = :newpasswd WHERE `" . $uid . "` = :uid
@@ -244,4 +244,4 @@ class Crypt
} }
return false; return false;
} }
} }

View File

@@ -1,88 +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 <d00p@froxlor.org>
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
/**
* compare of froxlor versions
*
* @param string $a
* @param string $b
*
* @return integer 0 if equal, 1 if a>b and -1 if b>a
*/
function version_compare2($a, $b)
{
// split version into pieces and remove trailing .0
$a = explode(".", $a);
$b = explode(".", $b);
_parseVersionArray($a);
_parseVersionArray($b);
while (count($a) != count($b)) {
if (count($a) < count($b)) {
$a[] = '0';
} elseif (count($b) < count($a)) {
$b[] = '0';
}
}
foreach ($a as $depth => $aVal) {
// iterate over each piece of A
if (isset($b[$depth])) {
// if B matches A to this depth, compare the values
if ($aVal > $b[$depth]) {
return 1; // A > B
} else if ($aVal < $b[$depth]) {
return - 1; // B > A
}
// an equal result is inconclusive at this point
} else {
// if B does not match A to this depth, then A comes after B in sort order
return 1; // so A > B
}
}
// at this point, we know that to the depth that A and B extend to, they are equivalent.
// either the loop ended because A is shorter than B, or both are equal.
return (count($a) < count($b)) ? - 1 : 0;
}
function _parseVersionArray(&$arr = null)
{
// -svn or -dev or -rc ?
if (stripos($arr[count($arr) - 1], '-') !== false) {
$x = explode("-", $arr[count($arr) - 1]);
$arr[count($arr) - 1] = $x[0];
if (stripos($x[1], 'rc') !== false) {
$arr[] = '-1';
$arr[] = '2'; // rc > dev > svn
// number of rc
$arr[] = substr($x[1], 2);
} else if (stripos($x[1], 'dev') !== false) {
$arr[] = '-1';
$arr[] = '1'; // svn < dev < rc
// number of dev
$arr[] = substr($x[1], 3);
} // -svn version are deprecated
else if (stripos($x[1], 'svn') !== false) {
$arr[] = '-1';
$arr[] = '0'; // svn < dev < rc
// number of svn
$arr[] = substr($x[1], 3);
}
}
}

View File

@@ -1,38 +0,0 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org> (2003-2009)
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
/**
* Returns an integer of the given value which isn't negative.
* Returns -1 if the given value was -1.
*
* @param
* any The value
* @return int The positive value
* @author Florian Lippert <flo@syscp.org>
*/
function intval_ressource($the_value)
{
$the_value = intval($the_value);
if ($the_value < 0 && $the_value != '-1') {
$the_value *= - 1;
}
return $the_value;
}