more function reducing and fixing
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -123,7 +123,7 @@ abstract class ApiParameter
|
||||
*/
|
||||
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);
|
||||
if ($ul_field_value != '0') {
|
||||
$param_value = - 1;
|
||||
@@ -169,7 +169,7 @@ abstract class ApiParameter
|
||||
// check one level deeper
|
||||
return $this->getModFunctionString(++ $level, $max_level, $trace);
|
||||
}
|
||||
return $class . ':' . $func;
|
||||
return str_replace("Froxlor\\Api\\Commands\\", "", $class) . ':' . $func;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -208,7 +208,7 @@ class Admins extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
// only check if not empty,
|
||||
// cause empty == generate password automatically
|
||||
if ($password != '') {
|
||||
$password = validatePassword($password, true);
|
||||
$password = \Froxlor\System\Crypt::validatePassword($password, true);
|
||||
}
|
||||
|
||||
$diskspace = $diskspace * 1024;
|
||||
@@ -529,7 +529,7 @@ class Admins extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
}
|
||||
|
||||
if ($password != '') {
|
||||
$password = validatePassword($password, true);
|
||||
$password = \Froxlor\System\Crypt::validatePassword($password, true);
|
||||
$password = \Froxlor\System\Crypt::makeCryptPassword($password);
|
||||
} else {
|
||||
$password = $result['password'];
|
||||
|
||||
@@ -227,7 +227,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
|
||||
$fax = $this->getParam('fax', true, '');
|
||||
$customernumber = $this->getParam('customernumber', true, '');
|
||||
$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_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,
|
||||
// cause empty == generate password automatically
|
||||
if ($password != '') {
|
||||
$password = validatePassword($password, true);
|
||||
$password = \Froxlor\System\Crypt::validatePassword($password, true);
|
||||
}
|
||||
|
||||
// gender out of range? [0,2]
|
||||
@@ -846,7 +846,7 @@ class Customers extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resource
|
||||
|
||||
if ($this->isAdmin()) {
|
||||
// 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();
|
||||
$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']);
|
||||
$customernumber = $this->getParam('customernumber', true, $result['customernumber']);
|
||||
$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_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 != '') {
|
||||
$password = validatePassword($password, true);
|
||||
$password = \Froxlor\System\Crypt::validatePassword($password, true);
|
||||
$password = \Froxlor\System\Crypt::makeCryptPassword($password);
|
||||
} else {
|
||||
$password = $result['password'];
|
||||
|
||||
@@ -143,7 +143,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
// remove it for checks
|
||||
$content = substr($content, 0, - 1);
|
||||
}
|
||||
if (! validateDomain($content)) {
|
||||
if (! \Froxlor\Validate\Validate::validateDomain($content)) {
|
||||
$errors[] = $this->lng['error']['dns_mx_needdom'];
|
||||
} else {
|
||||
// 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
|
||||
$content .= '.' . $domain;
|
||||
}
|
||||
if (! validateDomain($content, true)) {
|
||||
if (! \Froxlor\Validate\Validate::validateDomain($content, true)) {
|
||||
$errors[] = $this->lng['error']['dns_cname_invaliddom'];
|
||||
} else {
|
||||
// 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
|
||||
$content = substr($content, 0, - 1);
|
||||
}
|
||||
if (! validateDomain($content)) {
|
||||
if (! \Froxlor\Validate\Validate::validateDomain($content)) {
|
||||
$errors[] = $this->lng['error']['dns_ns_invaliddom'];
|
||||
}
|
||||
// append trailing dot (again)
|
||||
@@ -212,7 +212,7 @@ class DomainZones extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
||||
$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'];
|
||||
} else {
|
||||
// check whether there is a CNAME-record for the same resource
|
||||
|
||||
@@ -85,7 +85,7 @@ class EmailAccounts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Reso
|
||||
$idna_convert = new \Froxlor\Idna\IdnaWrapper();
|
||||
$username = $idna_convert->decode($email_full);
|
||||
$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) {
|
||||
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']) {
|
||||
\Froxlor\UI\Response::standard_error('passwordshouldnotbeusername', '', true);
|
||||
}
|
||||
$password = validatePassword($password, true);
|
||||
$password = \Froxlor\System\Crypt::validatePassword($password, true);
|
||||
$cryptPassword = \Froxlor\System\Crypt::makeCryptPassword($password);
|
||||
$upd_query .= (Settings::Get('system.mailpwcleartext') == '1' ? "`password` = :password, " : '') . "`password_enc`= :password_enc";
|
||||
$upd_params['password_enc'] = $cryptPassword;
|
||||
|
||||
@@ -58,7 +58,7 @@ class Froxlor extends \Froxlor\Api\ApiCommand
|
||||
// check for customized version to not output
|
||||
// "There is a newer version of froxlor" besides the error-message
|
||||
$isnewerversion = - 1;
|
||||
} elseif (version_compare2($this->version, $_version) == - 1) {
|
||||
} elseif (\Froxlor\Froxlor::version_compare2($this->version, $_version) == - 1) {
|
||||
// there is a newer version - yay
|
||||
$isnewerversion = 1;
|
||||
} else {
|
||||
|
||||
@@ -68,7 +68,7 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
|
||||
|
||||
// validation
|
||||
$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);
|
||||
|
||||
if (Settings::Get('system.allow_customer_shell') == '1') {
|
||||
@@ -353,7 +353,7 @@ class Ftps extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntit
|
||||
// password update?
|
||||
if ($password != '') {
|
||||
// validate password
|
||||
$password = validatePassword($password, true);
|
||||
$password = \Froxlor\System\Crypt::validatePassword($password, true);
|
||||
|
||||
if ($password == $result['username']) {
|
||||
\Froxlor\UI\Response::standard_error('passwordshouldnotbeusername', '', true);
|
||||
|
||||
@@ -54,7 +54,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
|
||||
// validation
|
||||
$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);
|
||||
|
||||
// validate whether the dbserver exists
|
||||
@@ -315,7 +315,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
|
||||
if ($password != '') {
|
||||
// validate password
|
||||
$password = validatePassword($password, true);
|
||||
$password = \Froxlor\System\Crypt::validatePassword($password, true);
|
||||
|
||||
if ($password == $result['databasename']) {
|
||||
\Froxlor\UI\Response::standard_error('passwordshouldnotbeusername', '', true);
|
||||
|
||||
@@ -104,7 +104,7 @@ class SubDomains extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc
|
||||
// merge the two parts together
|
||||
$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(
|
||||
'stringiswrong',
|
||||
'mydomain'
|
||||
|
||||
@@ -16,7 +16,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
|
||||
|
||||
public function run()
|
||||
{
|
||||
$this->_\Froxlor\Validate\Validate::validate();
|
||||
$this->_validate();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,7 +24,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function _\Froxlor\Validate\Validate::validate()
|
||||
private function _validate()
|
||||
{
|
||||
$this->_checkConfigParam(true);
|
||||
$this->_parseConfig();
|
||||
|
||||
@@ -14,7 +14,7 @@ class SwitchServerIpAction extends \Froxlor\Cli\Action
|
||||
|
||||
public function run()
|
||||
{
|
||||
$this->_\Froxlor\Validate\Validate::validate();
|
||||
$this->_validate();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -22,7 +22,7 @@ class SwitchServerIpAction extends \Froxlor\Cli\Action
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function _\Froxlor\Validate\Validate::validate()
|
||||
private function _validate()
|
||||
{
|
||||
$need_config = false;
|
||||
if (array_key_exists("list", $this->_args) || array_key_exists("switch", $this->_args)) {
|
||||
|
||||
@@ -201,4 +201,76 @@ final class Froxlor
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ class Crypt
|
||||
$cryptPassword = crypt($password, '$1$' . self::generatePassword(true) . self::generatePassword(true));
|
||||
break;
|
||||
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));
|
||||
} else {
|
||||
// Blowfish hashing with a salt as follows: "$2a$", "$2x$" or "$2y$",
|
||||
@@ -228,7 +228,7 @@ class Crypt
|
||||
if ($pwd_hash == $pwd_check) {
|
||||
|
||||
// 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) {
|
||||
$upd_stmt = \Froxlor\Database\Database::prepare("
|
||||
UPDATE " . $table . " SET `password` = :newpasswd WHERE `" . $uid . "` = :uid
|
||||
@@ -244,4 +244,4 @@ class Crypt
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user