change method signature of \Froxlor\Validate\Validate::validate_ip2
This commit is contained in:
@@ -135,7 +135,7 @@ class IpsAndPorts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
|||||||
{
|
{
|
||||||
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
|
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
|
||||||
|
|
||||||
$ip = \Froxlor\Validate\Validate::validate_ip2($this->getParam('ip'), false, 'invalidip', false, false, false, true);
|
$ip = \Froxlor\Validate\Validate::validate_ip2($this->getParam('ip'), false, 'invalidip', false, false, false, false, true);
|
||||||
$port = \Froxlor\Validate\Validate::validate($this->getParam('port', true, 80), 'port', '/^(([1-9])|([1-9][0-9])|([1-9][0-9][0-9])|([1-9][0-9][0-9][0-9])|([1-5][0-9][0-9][0-9][0-9])|(6[0-4][0-9][0-9][0-9])|(65[0-4][0-9][0-9])|(655[0-2][0-9])|(6553[0-5]))$/Di', array(
|
$port = \Froxlor\Validate\Validate::validate($this->getParam('port', true, 80), 'port', '/^(([1-9])|([1-9][0-9])|([1-9][0-9][0-9])|([1-9][0-9][0-9][0-9])|([1-5][0-9][0-9][0-9][0-9])|(6[0-4][0-9][0-9][0-9])|(65[0-4][0-9][0-9])|(655[0-2][0-9])|(6553[0-5]))$/Di', array(
|
||||||
'stringisempty',
|
'stringisempty',
|
||||||
'myport'
|
'myport'
|
||||||
@@ -332,7 +332,7 @@ class IpsAndPorts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
|||||||
'id' => $id
|
'id' => $id
|
||||||
));
|
));
|
||||||
|
|
||||||
$ip = \Froxlor\Validate\Validate::validate_ip2($this->getParam('ip', true, $result['ip']), false, 'invalidip', false, false, false, true);
|
$ip = \Froxlor\Validate\Validate::validate_ip2($this->getParam('ip', true, $result['ip']), false, 'invalidip', false, false, false, false, true);
|
||||||
$port = \Froxlor\Validate\Validate::validate($this->getParam('port', true, $result['port']), 'port', '/^(([1-9])|([1-9][0-9])|([1-9][0-9][0-9])|([1-9][0-9][0-9][0-9])|([1-5][0-9][0-9][0-9][0-9])|(6[0-4][0-9][0-9][0-9])|(65[0-4][0-9][0-9])|(655[0-2][0-9])|(6553[0-5]))$/Di', array(
|
$port = \Froxlor\Validate\Validate::validate($this->getParam('port', true, $result['port']), 'port', '/^(([1-9])|([1-9][0-9])|([1-9][0-9][0-9])|([1-9][0-9][0-9][0-9])|([1-5][0-9][0-9][0-9][0-9])|(6[0-4][0-9][0-9][0-9])|(65[0-4][0-9][0-9])|(655[0-2][0-9])|(6553[0-5]))$/Di', array(
|
||||||
'stringisempty',
|
'stringisempty',
|
||||||
'myport'
|
'myport'
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ class Check
|
|||||||
$mysql_access_host_array = array_map('trim', explode(',', $newfieldvalue));
|
$mysql_access_host_array = array_map('trim', explode(',', $newfieldvalue));
|
||||||
|
|
||||||
foreach ($mysql_access_host_array as $host_entry) {
|
foreach ($mysql_access_host_array as $host_entry) {
|
||||||
if (Validate::validate_ip2($host_entry, true, 'invalidip', true, true, true, false, true) == false && Validate::validateDomain($host_entry) == false && Validate::validateLocalHostname($host_entry) == false && $host_entry != '%') {
|
if (Validate::validate_ip2($host_entry, true, 'invalidip', true, true, true, true, false) == false && Validate::validateDomain($host_entry) == false && Validate::validateLocalHostname($host_entry) == false && $host_entry != '%') {
|
||||||
return array(
|
return array(
|
||||||
self::FORMFIELDS_PLAUSIBILITY_CHECK_ERROR,
|
self::FORMFIELDS_PLAUSIBILITY_CHECK_ERROR,
|
||||||
'invalidmysqlhost',
|
'invalidmysqlhost',
|
||||||
|
|||||||
@@ -114,9 +114,12 @@ class Validate
|
|||||||
* @param bool $cidr_as_netmask
|
* @param bool $cidr_as_netmask
|
||||||
* whether to format CIDR nodation to netmask notation
|
* whether to format CIDR nodation to netmask notation
|
||||||
*
|
*
|
||||||
|
* @param bool $throw_exception
|
||||||
|
* whether to throw an exception on failure
|
||||||
|
*
|
||||||
* @return string|bool ip address on success, false on failure
|
* @return string|bool ip address on success, false on failure
|
||||||
*/
|
*/
|
||||||
public static function validate_ip2($ip, $return_bool = false, $lng = 'invalidip', $allow_localhost = false, $allow_priv = false, $allow_cidr = false, $throw_exception = false, $cidr_as_netmask = false)
|
public static function validate_ip2($ip, $return_bool = false, $lng = 'invalidip', $allow_localhost = false, $allow_priv = false, $allow_cidr = false, $cidr_as_netmask = false, $throw_exception = false)
|
||||||
{
|
{
|
||||||
$cidr = "";
|
$cidr = "";
|
||||||
if ($allow_cidr) {
|
if ($allow_cidr) {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class ValidateTest extends TestCase
|
|||||||
|
|
||||||
public function testValidateIp()
|
public function testValidateIp()
|
||||||
{
|
{
|
||||||
$result = Validate::validate_ip2("12.34.56.78", false, 'invalidip', false, false, false, true);
|
$result = Validate::validate_ip2("12.34.56.78", false, 'invalidip', false, false, false, false, true);
|
||||||
$this->assertEquals("12.34.56.78", $result);
|
$this->assertEquals("12.34.56.78", $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,12 +58,12 @@ class ValidateTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->expectException("Exception");
|
$this->expectException("Exception");
|
||||||
$this->expectExceptionCode(400);
|
$this->expectExceptionCode(400);
|
||||||
Validate::validate_ip2("10.0.0.1", false, 'invalidip', false, false, false, true);
|
Validate::validate_ip2("10.0.0.1", false, 'invalidip', false, false, false, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testValidateIpPrivNotAllowedBool()
|
public function testValidateIpPrivNotAllowedBool()
|
||||||
{
|
{
|
||||||
$result = Validate::validate_ip2("10.0.0.1", true, 'invalidip', false, false, false, true);
|
$result = Validate::validate_ip2("10.0.0.1", true, 'invalidip', false, false, false, false, true);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,18 +71,18 @@ class ValidateTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->expectException("Exception");
|
$this->expectException("Exception");
|
||||||
$this->expectExceptionCode(400);
|
$this->expectExceptionCode(400);
|
||||||
Validate::validate_ip2("12.34.56.78/24", false, 'invalidip', false, false, false, true);
|
Validate::validate_ip2("12.34.56.78/24", false, 'invalidip', false, false, false, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testValidateIpCidrNotAllowedBool()
|
public function testValidateIpCidrNotAllowedBool()
|
||||||
{
|
{
|
||||||
$result = Validate::validate_ip2("12.34.56.78/24", true, 'invalidip', false, false, false, true);
|
$result = Validate::validate_ip2("12.34.56.78/24", true, 'invalidip', false, false, false, false, true);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testValidateIpCidr()
|
public function testValidateIpCidr()
|
||||||
{
|
{
|
||||||
$result = Validate::validate_ip2("12.34.56.78/24", false, 'invalidip', false, false, true, true);
|
$result = Validate::validate_ip2("12.34.56.78/24", false, 'invalidip', false, false, true, false, true);
|
||||||
$this->assertEquals("12.34.56.78/24", $result);
|
$this->assertEquals("12.34.56.78/24", $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,12 +90,12 @@ class ValidateTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->expectException("Exception");
|
$this->expectException("Exception");
|
||||||
$this->expectExceptionCode(400);
|
$this->expectExceptionCode(400);
|
||||||
Validate::validate_ip2("2620:0:2d0:200::7/32", false, 'invalidip', false, false, true, true);
|
Validate::validate_ip2("2620:0:2d0:200::7/32", false, 'invalidip', false, false, true, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testValidateIpLocalhostAllowed()
|
public function testValidateIpLocalhostAllowed()
|
||||||
{
|
{
|
||||||
$result = Validate::validate_ip2("127.0.0.1/32", false, 'invalidip', true, false, true, true);
|
$result = Validate::validate_ip2("127.0.0.1/32", false, 'invalidip', true, false, true, false, true);
|
||||||
$this->assertEquals("127.0.0.1/32", $result);
|
$this->assertEquals("127.0.0.1/32", $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ class ValidateTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->expectException("Exception");
|
$this->expectException("Exception");
|
||||||
$this->expectExceptionCode(400);
|
$this->expectExceptionCode(400);
|
||||||
Validate::validate_ip2("127.0.0.2", false, 'invalidip', true, false, false, true);
|
Validate::validate_ip2("127.0.0.2", false, 'invalidip', true, false, false, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testValidateUrl()
|
public function testValidateUrl()
|
||||||
|
|||||||
Reference in New Issue
Block a user