fix wording add validation for cidr syntax add automatic transform of cidr to netmask for mysql
This commit is contained in:
@@ -290,6 +290,28 @@ class Store
|
||||
|
||||
public static function storeSettingMysqlAccessHost($fieldname, $fielddata, $newfieldvalue)
|
||||
{
|
||||
$ips = $newfieldvalue;
|
||||
//Convert cidr to netmask for mysql, if needed be
|
||||
if(strpos($ips, ',') !== false) {
|
||||
$ips = explode(',', $ips);
|
||||
}
|
||||
if(is_array($ips) && count($ips) > 0) {
|
||||
$newfieldvalue = [];
|
||||
foreach ($ips as $ip) {
|
||||
$org_ip = $ip;
|
||||
$ip_cidr = explode("/", $ip);
|
||||
if (count($ip_cidr) == 2) {
|
||||
$ip = $ip_cidr[0];
|
||||
if(in_array((int)strlen((string)$ip_cidr[1]),array(1,2))) {
|
||||
$ip_cidr[1] = \Froxlor\Validate\Validate::cidr2NetmaskAddr($org_ip);
|
||||
}
|
||||
$newfieldvalue[] = $ip . '/' . $ip_cidr[1];
|
||||
} else {
|
||||
$newfieldvalue[] = $org_ip;
|
||||
}
|
||||
}
|
||||
$newfieldvalue = implode(',', $newfieldvalue);
|
||||
}
|
||||
$returnvalue = self::storeSettingField($fieldname, $fielddata, $newfieldvalue);
|
||||
|
||||
if ($returnvalue !== false && is_array($fielddata) && isset($fielddata['settinggroup']) && $fielddata['settinggroup'] == 'system' && isset($fielddata['varname']) && $fielddata['varname'] == 'mysql_access_host') {
|
||||
|
||||
@@ -64,6 +64,26 @@ class Validate
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts CIDR to a netmask address
|
||||
*
|
||||
* @thx to https://stackoverflow.com/a/5711080/3020926
|
||||
* @param string $cidr
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function cidr2NetmaskAddr ($cidr) {
|
||||
|
||||
$ta = substr ($cidr, strpos ($cidr, '/') + 1) * 1;
|
||||
$netmask = str_split (str_pad (str_pad ('', $ta, '1'), 32, '0'), 8);
|
||||
|
||||
foreach ($netmask as &$element) {
|
||||
$element = bindec ($element);
|
||||
}
|
||||
|
||||
return join ('.', $netmask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether it is a valid ip
|
||||
*
|
||||
@@ -90,6 +110,9 @@ class Validate
|
||||
$ip_cidr = explode("/", $ip);
|
||||
if (count($ip_cidr) == 2) {
|
||||
$ip = $ip_cidr[0];
|
||||
if(in_array((int)strlen((string)$ip_cidr[1]),array(1,2))) {
|
||||
$ip_cidr[1] = self::cidr2NetmaskAddr($org_ip);
|
||||
}
|
||||
$cidr = "/" . $ip_cidr[1];
|
||||
} else {
|
||||
$ip = $org_ip;
|
||||
|
||||
@@ -569,7 +569,7 @@ $lng['serversettings']['apacheconf_htpasswddir']['description'] = 'Where should
|
||||
|
||||
$lng['error']['formtokencompromised'] = 'The request seems to be compromised. For security reasons you were logged out.';
|
||||
$lng['serversettings']['mysql_access_host']['title'] = 'MySQL-Access-Hosts';
|
||||
$lng['serversettings']['mysql_access_host']['description'] = 'A comma separated list of hosts from which users should be allowed to connect to the MySQL-Server. To allow a subnet, long CIDR syntax like 100.127.0.0/255.255.0.0 is valid.';
|
||||
$lng['serversettings']['mysql_access_host']['description'] = 'A comma separated list of hosts from which users should be allowed to connect to the MySQL-Server. To allow a subnet the netmask or cidr syntax is valid.';
|
||||
|
||||
// ADDED IN 1.2.18-svn1
|
||||
|
||||
|
||||
@@ -564,7 +564,7 @@ $lng['serversettings']['apacheconf_htpasswddir']['description'] = 'Wo sollen die
|
||||
|
||||
$lng['error']['formtokencompromised'] = 'Das Formular scheint manipuliert worden zu sein. Aus Sicherheitsgründen wurden Sie ausgelogged.';
|
||||
$lng['serversettings']['mysql_access_host']['title'] = 'MySQL-Access-Hosts';
|
||||
$lng['serversettings']['mysql_access_host']['description'] = 'Eine durch Komma getrennte Liste mit den Hostnamen aller Hostnames/IP-Adressen, von denen sich die Benutzer einloggen dürfen. Um ein Subnetz zu erlauben, die lange CIDR Schreibweise (Beispiel 100.127.0.0/255.255.0.0) ist erlaubt.';
|
||||
$lng['serversettings']['mysql_access_host']['description'] = 'Eine durch Komma getrennte Liste mit den Hostnamen aller Hostnames/IP-Adressen, von denen sich die Benutzer einloggen dürfen. Um ein Subnetz zu erlauben ist die Netzmaske oder CIDR Syntax erlaubt.';
|
||||
|
||||
// ADDED IN 1.2.18-svn1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user