From 03c7e0868d941c286d9ca1e3578f977ce1a56728 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 11 Jun 2024 07:57:16 +0200 Subject: [PATCH] refactoring --- lam/lib/modules/ddns.inc | 185 ++++++------ lam/lib/modules/dhcp_settings.inc | 450 +++++++++++++++--------------- 2 files changed, 324 insertions(+), 311 deletions(-) diff --git a/lam/lib/modules/ddns.inc b/lam/lib/modules/ddns.inc index 3ec619f14..30e587b35 100644 --- a/lam/lib/modules/ddns.inc +++ b/lam/lib/modules/ddns.inc @@ -3,7 +3,7 @@ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) Copyright (C) 2008 Thomas Manninger - 2008 - 2023 Roland Gruber + 2008 - 2024 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,20 +22,19 @@ */ /** -* Manages DDNS entries. -* -* @package modules -* -* @author Thomas Manninger -* @author Roland Gruber -*/ + * Manages DDNS entries. + * + * @package modules + * + * @author Thomas Manninger + * @author Roland Gruber + */ /** -* Manages DDNS entries. -* -* @package modules -*/ - + * Manages DDNS entries. + * + * @package modules + */ class ddns extends baseModule { /** standard DDNS settings */ @@ -43,12 +42,12 @@ class ddns extends baseModule { /** - * Returns true if this module can manage accounts of the current type, otherwise false. - * - * @return boolean true if module fits - */ + * Returns true if this module can manage accounts of the current type, otherwise false. + * + * @return boolean true if module fits + */ public function can_manage() { - return in_array($this->get_scope(), array('dhcp')); + return in_array($this->get_scope(), ['dhcp']); } /** @@ -65,99 +64,99 @@ class ddns extends baseModule { // icon $return['icon'] = 'world-color.svg'; // RDN attribute - $return["RDN"] = array("cn" => "high"); + $return["RDN"] = ["cn" => "high"]; // LDAP filter $return["ldap_filter"] = []; // module dependencies - $return['dependencies'] = array('depends' => array('dhcp_settings'), 'conflicts' => []); + $return['dependencies'] = ['depends' => ['dhcp_settings'], 'conflicts' => []]; // managed object classes $return['objectClasses'] = []; // managed attributes - $return['attributes'] = array('dhcpOption', 'dhcpStatements'); + $return['attributes'] = ['dhcpOption', 'dhcpStatements']; // help Entries - $return['help'] = array( - 'active' => array( + $return['help'] = [ + 'active' => [ "Headline" => _("Activate DynDNS"), "Text" => _("Should DDNS (Dynamic DNS) be activated?") - ), - 'fixed_ips' => array( + ], + 'fixed_ips' => [ "Headline" => _("Fix IP addresses"), "Text" => _("Should fix IP addresses be added to the DNS server?") - ), - 'client_insert' => array( + ], + 'client_insert' => [ "Headline" => _("Disable client updates"), "Text" => _("Disables the client to update DNS entries.") - ), - 'keypath' => array( + ], + 'keypath' => [ "Headline" => _("Path to key for DNS updates"), "Text" => _("The key enables the DHCP server to perform DNS updates." . - " " . "The key is generated with \"genDDNSkey\".") - ), - 'dns' => array( + " " . "The key is generated with \"genDDNSkey\".") + ], + 'dns' => [ "Headline" => _("IP address of the DNS server"), "Text" => _("Please enter the IP address of your DNS server.") - ), - 'zone' => array( + ], + 'zone' => [ "Headline" => _("Zone name"), "Text" => _("Zone name for the DNS server (e.g. company.local).") - ), - 'zone_reverse' => array( + ], + 'zone_reverse' => [ "Headline" => _("Reverse zone name"), "Text" => ("Name of the reverse zone of the DNS server (e.g. 0.168.192.in-addr.arpa).") - ), - ); + ], + ]; // available PDF fields - $return['PDF_fields'] = array( + $return['PDF_fields'] = [ 'DNSserver' => _('IP address of the DNS server'), 'zone' => _('Zone name'), 'reverseZone' => _('Reverse zone name'), - ); + ]; // upload fields if (isLoggedIn() && $this->check_if_ddns_is_enable()) { - $return['upload_columns'] = array( - array( + $return['upload_columns'] = [ + [ 'name' => 'ddns_DNSserver', 'description' => _('IP address of the DNS server'), 'help' => 'dns', 'example' => '123.123.123.123', 'required' => true - ), - array( + ], + [ 'name' => 'ddns_zone', 'description' => _('Zone name'), 'help' => 'zone', 'example' => 'company.local', 'required' => true - ), - array( + ], + [ 'name' => 'ddns_reverseZone', 'description' => _('Reverse zone name'), 'help' => 'zone_reverse', 'example' => '0.168.192.in-addr.arpa', 'required' => true - ), - ); + ], + ]; } return $return; } /** - * This function fills the message array. - */ + * This function fills the message array. + */ public function load_Messages() { - $this->messages['key_path'][0] = array('ERROR', 'Please enter the path to the key.', ''); - $this->messages['key_path'][1] = array('ERROR', 'The key path contains invalid characters.', ''); - $this->messages['ip'][0] = array('ERROR', 'The IP address of the DNS server is invalid.'); - $this->messages['ip'][1] = array('ERROR', _('Account %s:') . ' ddns_DNSserver', 'The IP address of the DNS server is invalid.'); - $this->messages['zone'][0] = array('ERROR', 'Please enter a zone name.'); - $this->messages['zone_reverse'][0] = array('ERROR', 'Please enter the reverse zone.'); + $this->messages['key_path'][0] = ['ERROR', 'Please enter the path to the key.', '']; + $this->messages['key_path'][1] = ['ERROR', 'The key path contains invalid characters.', '']; + $this->messages['ip'][0] = ['ERROR', 'The IP address of the DNS server is invalid.']; + $this->messages['ip'][1] = ['ERROR', _('Account %s:') . ' ddns_DNSserver', 'The IP address of the DNS server is invalid.']; + $this->messages['zone'][0] = ['ERROR', 'Please enter a zone name.']; + $this->messages['zone_reverse'][0] = ['ERROR', 'Please enter the reverse zone.']; } /** - * This functions returns true if all needed settings are done. - * - * @return boolean true if LDAP operation can be done - */ + * This functions returns true if all needed settings are done. + * + * @return boolean true if LDAP operation can be done + */ public function module_complete() { $this->attributes = &$this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes; $this->orig = &$this->getAccountContainer()->getAccountModule('dhcp_settings')->orig; @@ -173,7 +172,9 @@ class ddns extends baseModule { } // Account settings $ip = $this->getDNSServer(); - if (!empty($ip) && !check_ip($ip)) return false; + if (!empty($ip) && !check_ip($ip)) { + return false; + } $zones = $this->getZoneNames(); if (sizeof($zones) < 2) { @@ -195,17 +196,17 @@ class ddns extends baseModule { } /** - * Returns a list of modifications which have to be made to the LDAP account. - * - * @return array list of modifications - *
This function returns an array with 3 entries: - *
array( DN1 ('add' => array($attr), 'remove' => array($attr), 'modify' => array($attr)), DN2 .... ) - *
DN is the DN to change. It may be possible to change several DNs (e.g. create a new user and add him to some groups via attribute memberUid) - *
"add" are attributes which have to be added to LDAP entry - *
"remove" are attributes which have to be removed from LDAP entry - *
"modify" are attributes which have to been modified in LDAP entry - *
"info" are values with informational value (e.g. to be used later by pre/postModify actions) - */ + * Returns a list of modifications which have to be made to the LDAP account. + * + * @return array list of modifications + *
This function returns an array with 3 entries: + *
array( DN1 ('add' => array($attr), 'remove' => array($attr), 'modify' => array($attr)), DN2 .... ) + *
DN is the DN to change. It may be possible to change several DNs (e.g. create a new user and add him to some groups via attribute memberUid) + *
"add" are attributes which have to be added to LDAP entry + *
"remove" are attributes which have to be removed from LDAP entry + *
"modify" are attributes which have to been modified in LDAP entry + *
"info" are values with informational value (e.g. to be used later by pre/postModify actions) + */ public function save_attributes() { // done by dhcp_server object } @@ -223,16 +224,16 @@ class ddns extends baseModule { } $suffix = $type->getSuffix(); - $results = searchLDAP($suffix, "dhcpStatements=ddns-update-style interim", array('dn')); + $results = searchLDAP($suffix, "dhcpStatements=ddns-update-style interim", ['dn']); return (!empty($results)); } /** - * Processes user input of the primary module page. - * It checks if all input values are correct and updates the associated LDAP attributes. - * - * @return array list of info/error messages - */ + * Processes user input of the primary module page. + * It checks if all input values are correct and updates the associated LDAP attributes. + * + * @return array list of info/error messages + */ public function process_attributes() { // Main Settings and Account have to different processes. if ($this->isRootNode()) { @@ -277,7 +278,7 @@ class ddns extends baseModule { $this->setIgnoreClientUpdates(($client_insert == 'on')); $this->setUpdateKey($key_path); - if (!empty($key_path) && (str_replace("\"","",$_POST['key_path']) != $key_path)) { + if (!empty($key_path) && (str_replace("\"", "", $_POST['key_path']) != $key_path)) { $errors[] = $this->messages['key_path'][1]; } @@ -451,8 +452,8 @@ class ddns extends baseModule { if (is_array($this->attributes['dhcpStatements'])) { for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) { if (substr($this->attributes['dhcpStatements'][$i], 0, 5) == 'zone ') { - $parts = explode(" ",substr($this->attributes['dhcpStatements'][$i],5)); - $value = substr(array_shift($parts),0,-1); + $parts = explode(" ", substr($this->attributes['dhcpStatements'][$i], 5)); + $value = substr(array_shift($parts), 0, -1); if (strpos($value, 'in-addr.arpa') === false) { $zone = $value; } @@ -594,7 +595,7 @@ class ddns extends baseModule { if (is_array($this->attributes['dhcpStatements'])) { for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) { if (substr($this->attributes['dhcpStatements'][$i], 0, 8) == 'include ') { - $return = substr($this->attributes['dhcpStatements'][$i],9, strlen($this->attributes['dhcpStatements'][$i]) - 10); + $return = substr($this->attributes['dhcpStatements'][$i], 9, strlen($this->attributes['dhcpStatements'][$i]) - 10); break; } } @@ -623,15 +624,15 @@ class ddns extends baseModule { } /** - * This function loads the LDAP attributes when an account should be loaded. - * - * Calling this method requires the existence of an enclosing {@link accountContainer}.
- *
- * By default this method loads the object classes and accounts which are specified in {@link getManagedObjectClasses()} - * and {@link getManagedAttributes()}. - * - * @param array $attributes array like the array returned by get_ldap_attributes(dn of account) but without count indices - */ + * This function loads the LDAP attributes when an account should be loaded. + * + * Calling this method requires the existence of an enclosing {@link accountContainer}.
+ *
+ * By default this method loads the object classes and accounts which are specified in {@link getManagedObjectClasses()} + * and {@link getManagedAttributes()}. + * + * @param array $attributes array like the array returned by get_ldap_attributes(dn of account) but without count indices + */ public function load_attributes($attributes) { // load nothing, attributes are saved in "dhcp_settings" module } @@ -649,7 +650,7 @@ class ddns extends baseModule { // principal name if (!check_ip($rawAccounts[$i][$ids['ddns_DNSserver']])) { $error = $this->messages['ip'][1]; - array_push($error, array($i)); + array_push($error, [$i]); $messages[] = $error; } else { diff --git a/lam/lib/modules/dhcp_settings.inc b/lam/lib/modules/dhcp_settings.inc index 804f0f645..b1a3040b4 100644 --- a/lam/lib/modules/dhcp_settings.inc +++ b/lam/lib/modules/dhcp_settings.inc @@ -3,7 +3,7 @@ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) Copyright (C) 2008 Thomas Manninger - 2008 - 2022 Roland Gruber + 2008 - 2024 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,13 +22,13 @@ */ /** -* Manages DHCP entries. -* -* @package modules -* -* @author Thomas Manninger -* @author Roland Gruber -*/ + * Manages DHCP entries. + * + * @package modules + * + * @author Thomas Manninger + * @author Roland Gruber + */ /** * This function checks if the given IP address is valid. @@ -59,11 +59,11 @@ if (!function_exists('check_ip')) { for ($i = 0; $i < count($part); $i++) { // only numbers are allowed if (!is_numeric($part[$i]) - || ($part[$i] > 255) - // non-subnet must be > 0 on last digit - || (!$subnet && ($i == 3) && ($part[$i] < 1)) - // subnet must be >= 0 on last digit - || ($subnet && ($i == 3) && ($part[$i] < 0))) { + || ($part[$i] > 255) + // non-subnet must be > 0 on last digit + || (!$subnet && ($i == 3) && ($part[$i] < 1)) + // subnet must be >= 0 on last digit + || ($subnet && ($i == 3) && ($part[$i] < 0))) { return false; } } @@ -73,10 +73,10 @@ if (!function_exists('check_ip')) { } /** -* Manages DHCP entries. -* -* @package modules -*/ + * Manages DHCP entries. + * + * @package modules + */ class dhcp_settings extends baseModule { const UNKNOWN_CLIENTS = 'unknown-clients'; @@ -99,34 +99,34 @@ class dhcp_settings extends baseModule { public $attributes; /** - * Creates a new dhcp_settings object. - * - * @param string $scope account type - */ + * Creates a new dhcp_settings object. + * + * @param string $scope account type + */ function __construct($scope) { // list of node types - $this->all_netbios_node_types = array( + $this->all_netbios_node_types = [ "1" => _("B-Node (0x01)"), "2" => _("P-Node (0x02)"), "4" => _("M-Node (0x04)"), "8" => _("H-Node (0x08)") - ); - $this->allowDenyOptions = array( + ]; + $this->allowDenyOptions = [ '-' => '', 'allow' => _("Allow"), 'deny' => _("Deny"), - ); + ]; // call parent constructor parent::__construct($scope); } /** - * Returns true if this module can manage accounts of the current type, otherwise false. - * - * @return boolean true if module fits - */ + * Returns true if this module can manage accounts of the current type, otherwise false. + * + * @return boolean true if module fits + */ public function can_manage() { - return in_array($this->get_scope(), array('dhcp')); + return in_array($this->get_scope(), ['dhcp']); } /** @@ -143,46 +143,46 @@ class dhcp_settings extends baseModule { // icon $return['icon'] = 'world-color.svg'; // RDN attribute - $return["RDN"] = array("cn" => "high"); + $return["RDN"] = ["cn" => "high"]; // LDAP filter $return["ldap_filter"] = []; // module dependencies - $return['dependencies'] = array('depends' => [], 'conflicts' => []); + $return['dependencies'] = ['depends' => [], 'conflicts' => []]; // managed object classes - $return['objectClasses'] = array('top', 'dhcpOptions', 'dhcpSubnet'); + $return['objectClasses'] = ['top', 'dhcpOptions', 'dhcpSubnet']; // managed attributes - $return['attributes'] = array('cn', 'dhcpOption', 'dhcpComments', 'dhcpNetMask', 'dhcpStatements'); + $return['attributes'] = ['cn', 'dhcpOption', 'dhcpComments', 'dhcpNetMask', 'dhcpStatements']; // help Entries - $return['help'] = array( - 'domainname' => array( + $return['help'] = [ + 'domainname' => [ "Headline" => _("Domain name"), "Text" => _("The domain name of the subnet.") - ), - 'subnet' => array( + ], + 'subnet' => [ "Headline" => _("Subnet"), 'attr' => 'cn', "Text" => _("The name of the subnet. Example: 192.168.10.0") - ), - 'leasetime' => array( + ], + 'leasetime' => [ "Headline" => _("Lease time"), "Text" => _("The lease time specifies after how many seconds the client should request a new IP address.") - ), - 'max_leasetime' => array( + ], + 'max_leasetime' => [ "Headline" => _("Maximum lease time"), "Text" => _("The maximum lease time specifies after how many seconds the client must request a new IP address.") - ), - 'dns' => array( + ], + 'dns' => [ "Headline" => _("DNS (Domain Name System)"), "Text" => _("The IP addresses of the DNS servers. Multiple addresses are separated by \",\". Example: 192.168.0.10, 192.168.0.11") - ), - 'gateway' => array( + ], + 'gateway' => [ "Headline" => _("Default gateway"), "Text" => _("Packets are sent to the default gateway if the receiver does not reside in the same network. The default gateway routes them to the target network.") - ), - 'netbios' => array( + ], + 'netbios' => [ "Headline" => _("Netbios name servers"), "Text" => _("The IP addresses of the Netbios name servers (e.g. \"123.123.123.123, 123.123.123.124\").") - ), - 'netbios_type' => array( + ], + 'netbios_type' => [ "Headline" => _("Netbios node type"), "Text" => _("B-Node (0x01): Broadcast.
The client tries to find other workstations via broadcasting (works only inside the same collision domain, viz. the same subnet).

@@ -197,47 +197,47 @@ The node tries broadcasting first. If that fails then it tries WINS.

The node tries WINS first. If that fails it tries broadcasting.

By default, the nodes are configured as H-Nodes which fits for small networks. In large networks Point-to-Point (0x02) should be used.") - ), - 'subnetmask' => array( + ], + 'subnetmask' => [ "Headline" => _("Subnet mask"), "Text" => _("The subnet mask of the network.") - ), - 'netmask' => array( + ], + 'netmask' => [ "Headline" => _("Net mask"), 'attr' => 'dhcpNetMask', "Text" => _("The net mask is derived from the subnet mask. LAM will calculate it automatically.") - ), - 'description' => array( + ], + 'description' => [ "Headline" => _("Description"), 'attr' => 'dhcpComments', "Text" => _("Here you can enter a description for this DHCP entry.") - ), - 'unknownClients' => array( + ], + 'unknownClients' => [ "Headline" => _("Unknown clients"), 'attr' => 'dhcpStatements', "Text" => _("Specifies if unknown clients are allowed.") - ), - 'INFO_domain-search' => array( + ], + 'INFO_domain-search' => [ 'Headline' => _('Search domains'), 'attr' => 'dhcpOptions', 'Text' => _('This is a list of domain names to be used by the client to locate not-fully-qualified domain names.') - ), - 'domain-search' => array( + ], + 'domain-search' => [ 'Headline' => _('Search domains'), 'attr' => 'dhcpOptions', 'Text' => _('This is a list of domain names to be used by the client to locate not-fully-qualified domain names.') . ' ' . _("Multiple values are separated by semicolon.") - ), - 'authoritative' => array( + ], + 'authoritative' => [ 'Headline' => _('Authoritative'), 'attr' => 'dhcpStatements', 'Text' => _('Authoritative servers reject requests for invalid IP addresses.') - ), - 'extraStatements' => array( + ], + 'extraStatements' => [ 'Headline' => _('Extra statements'), 'attr' => 'dhcpStatements', 'Text' => _('Please enter any additional DHCP statements.') - ), - 'extraOptions' => array( + ], + 'extraOptions' => [ 'Headline' => _('Extra statements'), 'attr' => 'dhcpOptions', 'Text' => _('Please enter any additional DHCP options.') - ), - ); + ], + ]; // available PDF fields - $return['PDF_fields'] = array( + $return['PDF_fields'] = [ 'subnet' => _('Subnet'), 'domainName' => _('Domain name'), 'leaseTime' => _('Lease time'), @@ -252,7 +252,7 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I 'unknownClients' => _('Unknown clients'), self::DOMAIN_SEARCH => _('Search domains'), self::AUTHORITATIVE => _('Authoritative') - ); + ]; // profile elements $profileContainer = new htmlResponsiveRow(); $profileContainer->add(new htmlResponsiveInputField(_('Subnet'), 'cn', null, 'subnet')); @@ -274,153 +274,153 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I $uploadAllowDenyOption = $this->allowDenyOptions; unset($uploadAllowDenyOption['-']); $uploadAllowDenyOption = implode(', ', $uploadAllowDenyOption); - $return['upload_columns'] = array( - array( + $return['upload_columns'] = [ + [ 'name' => 'dhcp_settings_subnet', 'description' => _('Subnet'), 'help' => 'subnet', 'example' => '192.168.10.0', 'required' => true, 'unique' => true - ), - array( + ], + [ 'name' => 'dhcp_settings_domainName', 'description' => _('Domain name'), 'help' => 'domainname', 'example' => 'mydomain.com', - ), - array( + ], + [ 'name' => 'dhcp_settings_leaseTime', 'description' => _('Lease time'), 'help' => 'leasetime', 'example' => '86400', - ), - array( + ], + [ 'name' => 'dhcp_settings_maxLeaseTime', 'description' => _('Maximum lease time'), 'help' => 'max_leasetime', 'example' => '172800', - ), - array( + ], + [ 'name' => 'dhcp_settings_DNSserver', 'description' => _('DNS'), 'help' => 'dns', 'example' => '192.168.10.250', - ), - array( + ], + [ 'name' => 'dhcp_settings_domain-search', 'description' => _('Search domains'), 'help' => 'domain-search', 'example' => 'example.com', - ), - array( + ], + [ 'name' => 'dhcp_settings_gateway', 'description' => _('Default gateway'), 'help' => 'gateway', 'example' => '192.168.10.251', - ), - array( + ], + [ 'name' => 'dhcp_settings_netbiosServer', 'description' => _('Netbios name servers'), 'help' => 'netbios', 'example' => '192.168.10.252, 192.168.10.253', - ), - array( + ], + [ 'name' => 'dhcp_settings_netbiosType', 'description' => _('Netbios node type'), 'help' => 'netbios_type', 'example' => 'M', 'default' => 'H', 'values' => 'B, H, M, P' - ), - array( + ], + [ 'name' => 'dhcp_settings_unknownClients', 'description' => _('Unknown clients'), 'help' => 'unknownClients', 'values' => $uploadAllowDenyOption - ), - array( + ], + [ 'name' => 'dhcp_settings_subnetMask', 'description' => _('Subnet mask'), 'help' => 'subnetmask', 'required' => true, 'example' => '255.255.255.0', - ), - array( + ], + [ 'name' => 'dhcp_settings_authoritative', 'description' => _('Authoritative'), 'help' => 'authoritative', 'values' => 'true, false', 'default' => 'false' - ), - array( + ], + [ 'name' => 'dhcp_settings_description', 'description' => _('Description'), 'help' => 'description', - ), - ); + ], + ]; return $return; } /** - * This function fills the message array. - */ + * This function fills the message array. + */ public function load_Messages() { - $this->messages['cn'][0] = array('ERROR', _('No subnet entered.')); - $this->messages['cn'][1] = array('ERROR', _('The subnet is already in use.')); - $this->messages['cn'][2] = array('ERROR', _('The subnet is invalid.')); - $this->messages['cn'][3] = array('ERROR', _('Account %s:') . ' dhcp_settings_subnet', _('The subnet is invalid.')); - $this->messages['dns'][0] = array('ERROR', _('You entered one or more invalid DNS servers.')); - $this->messages['dns'][1] = array('ERROR', _('Account %s:') . ' dhcp_settings_DNSserver', _('You entered one or more invalid DNS servers.')); - $this->messages['lease_time'][0] = array('ERROR', _('The lease time is invalid.')); - $this->messages['lease_time'][1] = array('ERROR', _('Account %s:') . ' dhcp_settings_leaseTime', _('The lease time is invalid.')); - $this->messages['routers'][0] = array('ERROR', _('The default gateway is invalid.')); - $this->messages['routers'][1] = array('ERROR', _('Account %s:') . ' dhcp_settings_gateway', _('The default gateway is invalid.')); - $this->messages['netbios'][0] = array('ERROR', _('The Netbios server is invalid.')); - $this->messages['netbios'][1] = array('ERROR', _('Account %s:') . ' dhcp_settings_netbiosServer', _('The Netbios server is invalid.')); - $this->messages['netbios_node_type'][1] = array('ERROR', _('Account %s:') . ' dhcp_settings_netbiosType', _('The entered Netbios node type does not exist.')); - $this->messages['unknownClients'][0] = array('ERROR', _('Account %s:') . ' dhcp_settings_unknownClients', _('Please enter a valid option.')); - $this->messages['max_lease_time'][0] = array('ERROR', _('The maximum lease time is invalid.')); - $this->messages['max_lease_time'][1] = array('ERROR', _('Account %s:') . ' dhcp_settings_maxLeaseTime', _('The maximum lease time is invalid.')); - $this->messages['subnet'][0] = array('ERROR', _('The subnet mask is invalid.')); - $this->messages['subnet'][1] = array('ERROR', _('Account %s:') . ' dhcp_settings_subnetMask', _('The subnet mask is invalid.')); - $this->messages['ranges_reload'][0] = array('INFO', _('The DHCP ranges were changed to fit for the new subnet.')); - $this->messages['ips_reload'][0] = array('INFO', _('The fixed IP addresses were changed to fit for the new subnet.')); - $this->messages['domainname'][2] = array('ERROR', _('The domain name includes invalid characters. Valid characters are A-Z, a-z, 0-9, ".", "_","-".')); - $this->messages['domainname'][5] = array('ERROR', _('Account %s:') . ' dhcp_settings_domainName', _('The domain name includes invalid characters. Valid characters are A-Z, a-z, 0-9, ".", "_","-".')); - $this->messages['INFO_domain-search'][0] = array('ERROR', _('Please enter valid domain names for search domains.')); - $this->messages['INFO_domain-search'][1] = array('ERROR', _('Account %s:') . ' dhcp_settings_domain-search', _('Please enter valid domain names for search domains.')); - $this->messages['authoritative'][0] = array('ERROR', _('Account %s:') . ' dhcp_settings_authoritative', _('This value can only be "true" or "false".')); + $this->messages['cn'][0] = ['ERROR', _('No subnet entered.')]; + $this->messages['cn'][1] = ['ERROR', _('The subnet is already in use.')]; + $this->messages['cn'][2] = ['ERROR', _('The subnet is invalid.')]; + $this->messages['cn'][3] = ['ERROR', _('Account %s:') . ' dhcp_settings_subnet', _('The subnet is invalid.')]; + $this->messages['dns'][0] = ['ERROR', _('You entered one or more invalid DNS servers.')]; + $this->messages['dns'][1] = ['ERROR', _('Account %s:') . ' dhcp_settings_DNSserver', _('You entered one or more invalid DNS servers.')]; + $this->messages['lease_time'][0] = ['ERROR', _('The lease time is invalid.')]; + $this->messages['lease_time'][1] = ['ERROR', _('Account %s:') . ' dhcp_settings_leaseTime', _('The lease time is invalid.')]; + $this->messages['routers'][0] = ['ERROR', _('The default gateway is invalid.')]; + $this->messages['routers'][1] = ['ERROR', _('Account %s:') . ' dhcp_settings_gateway', _('The default gateway is invalid.')]; + $this->messages['netbios'][0] = ['ERROR', _('The Netbios server is invalid.')]; + $this->messages['netbios'][1] = ['ERROR', _('Account %s:') . ' dhcp_settings_netbiosServer', _('The Netbios server is invalid.')]; + $this->messages['netbios_node_type'][1] = ['ERROR', _('Account %s:') . ' dhcp_settings_netbiosType', _('The entered Netbios node type does not exist.')]; + $this->messages['unknownClients'][0] = ['ERROR', _('Account %s:') . ' dhcp_settings_unknownClients', _('Please enter a valid option.')]; + $this->messages['max_lease_time'][0] = ['ERROR', _('The maximum lease time is invalid.')]; + $this->messages['max_lease_time'][1] = ['ERROR', _('Account %s:') . ' dhcp_settings_maxLeaseTime', _('The maximum lease time is invalid.')]; + $this->messages['subnet'][0] = ['ERROR', _('The subnet mask is invalid.')]; + $this->messages['subnet'][1] = ['ERROR', _('Account %s:') . ' dhcp_settings_subnetMask', _('The subnet mask is invalid.')]; + $this->messages['ranges_reload'][0] = ['INFO', _('The DHCP ranges were changed to fit for the new subnet.')]; + $this->messages['ips_reload'][0] = ['INFO', _('The fixed IP addresses were changed to fit for the new subnet.')]; + $this->messages['domainname'][2] = ['ERROR', _('The domain name includes invalid characters. Valid characters are A-Z, a-z, 0-9, ".", "_","-".')]; + $this->messages['domainname'][5] = ['ERROR', _('Account %s:') . ' dhcp_settings_domainName', _('The domain name includes invalid characters. Valid characters are A-Z, a-z, 0-9, ".", "_","-".')]; + $this->messages['INFO_domain-search'][0] = ['ERROR', _('Please enter valid domain names for search domains.')]; + $this->messages['INFO_domain-search'][1] = ['ERROR', _('Account %s:') . ' dhcp_settings_domain-search', _('Please enter valid domain names for search domains.')]; + $this->messages['authoritative'][0] = ['ERROR', _('Account %s:') . ' dhcp_settings_authoritative', _('This value can only be "true" or "false".')]; } /** - * Returns a list of modifications which have to be made to the LDAP account. - * - * @return array list of modifications - *
This function returns an array with 3 entries: - *
array( DN1 ('add' => array($attr), 'remove' => array($attr), 'modify' => array($attr)), DN2 .... ) - *
DN is the DN to change. It may be possible to change several DNs (e.g. create a new user and add him to some groups via attribute memberUid) - *
"add" are attributes which have to be added to LDAP entry - *
"remove" are attributes which have to be removed from LDAP entry - *
"modify" are attributes which have to been modified in LDAP entry - *
"info" are values with informational value (e.g. to be used later by pre/postModify actions) - */ + * Returns a list of modifications which have to be made to the LDAP account. + * + * @return array list of modifications + *
This function returns an array with 3 entries: + *
array( DN1 ('add' => array($attr), 'remove' => array($attr), 'modify' => array($attr)), DN2 .... ) + *
DN is the DN to change. It may be possible to change several DNs (e.g. create a new user and add him to some groups via attribute memberUid) + *
"add" are attributes which have to be added to LDAP entry + *
"remove" are attributes which have to be removed from LDAP entry + *
"modify" are attributes which have to been modified in LDAP entry + *
"info" are values with informational value (e.g. to be used later by pre/postModify actions) + */ public function save_attributes() { // remove dhcpSubnet object class if only the DHCP settings were changed if ($this->isRootNode() && !in_array_ignore_case("dhcpSubnet", $this->orig['objectClass']) && in_array_ignore_case("dhcpSubnet", $this->attributes['objectClass'])) { - $this->attributes['objectClass'] = array_delete(array("dhcpSubnet"), $this->attributes['objectClass']); + $this->attributes['objectClass'] = array_delete(["dhcpSubnet"], $this->attributes['objectClass']); } return parent::save_attributes(); } /** - * Processes user input of the primary module page. - * It checks if all input values are correct and updates the associated LDAP attributes. - * - * @return array list of info/error messages - */ + * Processes user input of the primary module page. + * It checks if all input values are correct and updates the associated LDAP attributes. + * + * @return array list of info/error messages + */ public function process_attributes() { // check if DHCP main settings and valid DHCP entry if ($this->isRootNode() @@ -432,25 +432,29 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I // Check if cn is not empty if (!$this->isRootNode()) { - if (!empty($_POST['cn'])) $_POST['cn'] = trim($_POST['cn']); + if (!empty($_POST['cn'])) { + $_POST['cn'] = trim($_POST['cn']); + } $this->attributes['cn'][0] = $_POST['cn']; if (empty($_POST['cn'])) { - $errors[] = $this->messages['cn'][0]; + $errors[] = $this->messages['cn'][0]; } // Check, if cn is not already use: - elseif ((sizeof(searchLDAPByAttribute('cn', $_POST['cn'], 'dhcpOptions', array('cn'), array('dhcp'))) > 0) && $this->orig['cn']['0']!=$_POST['cn']) { - $errors[] = $this->messages['cn'][1]; - } - elseif (!check_ip($_POST['cn'],true)) { + elseif ((sizeof(searchLDAPByAttribute('cn', $_POST['cn'], 'dhcpOptions', ['cn'], ['dhcp'])) > 0) && $this->orig['cn']['0'] != $_POST['cn']) { + $errors[] = $this->messages['cn'][1]; + } + elseif (!check_ip($_POST['cn'], true)) { $errors[] = $this->messages['cn'][2]; } else { // if the cn was edit, reload the Ranges: - if ($this->getAccountContainer()->getAccountModule('range')->reload_ranges()) - $errors[] = $this->messages['ranges_reload'][0]; - // if the cn was edit, reload the ips: - if ($this->getAccountContainer()->getAccountModule('fixed_ip')->reload_ips()) - $errors[] = $this->messages['ips_reload'][0]; + if ($this->getAccountContainer()->getAccountModule('range')->reload_ranges()) { + $errors[] = $this->messages['ranges_reload'][0]; + } + // if the cn was edit, reload the ips: + if ($this->getAccountContainer()->getAccountModule('fixed_ip')->reload_ips()) { + $errors[] = $this->messages['ips_reload'][0]; + } } $this->setUnknownClients($_POST['unknownClients']); } @@ -458,9 +462,11 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I $this->setAuthoritative(isset($_POST['authoritative']) && ($_POST['authoritative'] === 'on')); // Check domainname: - if (!empty($_POST['domainname'])) $_POST['domainname'] = trim($_POST['domainname']); + if (!empty($_POST['domainname'])) { + $_POST['domainname'] = trim($_POST['domainname']); + } if (!empty($_POST['domainname']) && !preg_match("/^[A-Za-z0-9\\._-]*$/", $_POST['domainname'])) { - $errors[] = $this->messages['domainname'][2]; + $errors[] = $this->messages['domainname'][2]; } $this->setDHCPOption(self::DOMAIN_NAME, '"' . $_POST['domainname'] . '"'); @@ -468,19 +474,19 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I if (!empty($_POST['dns'])) { $_POST['dns'] = trim($_POST['dns']); $ex = explode(",", $_POST['dns']); - $is_first=true; + $is_first = true; $invalid = false; - foreach($ex AS $string) { + foreach ($ex as $string) { if ($is_first) { - $is_first=false; - } + $is_first = false; + } - if (!check_ip($string)) { - $invalid = true; - } + if (!check_ip($string)) { + $invalid = true; + } } if ($invalid) { - $errors[] = $this->messages['dns'][0]; + $errors[] = $this->messages['dns'][0]; } } $this->setDHCPOption(self::DOMAIN_NAME_SERVERS, $_POST['dns']); @@ -521,7 +527,9 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I $this->setDHCPOption(self::ROUTERS, $_POST['routers']); // Netbios - if (!empty($_POST['netbios'])) $_POST['netbios'] = trim($_POST['netbios']); + if (!empty($_POST['netbios'])) { + $_POST['netbios'] = trim($_POST['netbios']); + } $netbiosServers = explode(', ', $_POST['netbios']); $netbiosServersOk = true; for ($i = 0; $i < sizeof($netbiosServers); $i++) { @@ -541,7 +549,7 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I // Check subnet $_POST['subnet'] = trim($_POST['subnet']); if (!$this->checkSubnetMask($_POST['subnet'])) { - $errors[] = $this->messages['subnet'][0]; + $errors[] = $this->messages['subnet'][0]; } $this->setDHCPOption(self::SUBNET_MASK, $_POST['subnet']); @@ -594,9 +602,9 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I private function calculateNetMask($subnet) { $ex = explode(".", $subnet); $num = 0; - foreach($ex AS $mask) { - $binary = decbin($mask); - $num += substr_count($binary, 1); + foreach ($ex as $mask) { + $binary = decbin($mask); + $num += substr_count($binary, 1); } return $num; } @@ -664,7 +672,7 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I foreach ($this->all_netbios_node_types as $key => $value) { $nodeOptions[$value] = $key; } - $nodeSelect = new htmlResponsiveSelect('netbios_node_type', $nodeOptions, array($nodeType), _('Netbios node type'), 'netbios_type'); + $nodeSelect = new htmlResponsiveSelect('netbios_node_type', $nodeOptions, [$nodeType], _('Netbios node type'), 'netbios_type'); $nodeSelect->setHasDescriptiveElements(true); $return->add($nodeSelect); @@ -675,7 +683,7 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I $unknownClients = '-'; } $unknownClientsOptions = array_flip($this->allowDenyOptions); - $unknownClientsSelect = new htmlResponsiveSelect('unknownClients', $unknownClientsOptions, array($unknownClients), _('Unknown clients'), 'unknownClients'); + $unknownClientsSelect = new htmlResponsiveSelect('unknownClients', $unknownClientsOptions, [$unknownClients], _('Unknown clients'), 'unknownClients'); $unknownClientsSelect->setHasDescriptiveElements(true); $return->add($unknownClientsSelect); // subnetmask @@ -698,10 +706,10 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I } /** - * Loads the values of an account profile into internal variables. - * - * @param array $profile hash array with profile values (identifier => value) - */ + * Loads the values of an account profile into internal variables. + * + * @param array $profile hash array with profile values (identifier => value) + */ function load_profile($profile) { // profile mappings in meta data parent::load_profile($profile); @@ -725,12 +733,12 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I if (!$this->isRootNode()) { $this->setDHCPOption(self::SUBNET_MASK, $profile['subnet'][0]); - // calc the netmask: - $ex=explode(".", $profile['subnet'][0]); + // calc the netmask: + $ex = explode(".", $profile['subnet'][0]); $num = 0; - foreach($ex AS $mask) { - $binary = decbin($mask); - $num += substr_count($binary, 1); + foreach ($ex as $mask) { + $binary = decbin($mask); + $num += substr_count($binary, 1); } $this->attributes['dhcpNetMask'][0] = $num; } @@ -822,7 +830,7 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I if (!empty($this->attributes['dhcpStatements'])) { for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) { if (substr($this->attributes['dhcpStatements'][$i], 0, 19) == (self::DEFAULT_LEASE_TIME . ' ')) { - $return = substr($this->attributes['dhcpStatements'][$i],19); + $return = substr($this->attributes['dhcpStatements'][$i], 19); break; } } @@ -861,7 +869,7 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) { $val = $this->attributes['dhcpStatements'][$i]; if (strpos($val, self::UNKNOWN_CLIENTS) === (strlen($val) - strlen(self::UNKNOWN_CLIENTS))) { - $return = substr($val,0, (strlen($val) - strlen(self::UNKNOWN_CLIENTS) - 1)); + $return = substr($val, 0, (strlen($val) - strlen(self::UNKNOWN_CLIENTS) - 1)); break; } } @@ -900,7 +908,7 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I if (!empty($this->attributes['dhcpStatements'])) { for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) { if (substr($this->attributes['dhcpStatements'][$i], 0, 15) == (self::MAX_LEASE_TIME . ' ')) { - $return = substr($this->attributes['dhcpStatements'][$i],15); + $return = substr($this->attributes['dhcpStatements'][$i], 15); break; } } @@ -1065,15 +1073,19 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I $messages = []; for ($i = 0; $i < sizeof($rawAccounts); $i++) { // add object class - if (!in_array("dhcpOptions", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "dhcpOptions"; - if (!in_array("dhcpSubnet", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "dhcpSubnet"; + if (!in_array("dhcpOptions", $partialAccounts[$i]['objectClass'])) { + $partialAccounts[$i]['objectClass'][] = "dhcpOptions"; + } + if (!in_array("dhcpSubnet", $partialAccounts[$i]['objectClass'])) { + $partialAccounts[$i]['objectClass'][] = "dhcpSubnet"; + } // subnet - if (check_ip($rawAccounts[$i][$ids['dhcp_settings_subnet']],true)) { + if (check_ip($rawAccounts[$i][$ids['dhcp_settings_subnet']], true)) { $partialAccounts[$i]['cn'] = $rawAccounts[$i][$ids['dhcp_settings_subnet']]; } else { $error = $this->messages['cn'][3]; - array_push($error, array($i)); + array_push($error, [$i]); $messages[] = $error; } // domain name @@ -1083,7 +1095,7 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I } else { $error = $this->messages['domainname'][5]; - array_push($error, array($i)); + array_push($error, [$i]); $messages[] = $error; } } @@ -1094,7 +1106,7 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I } else { $error = $this->messages['lease_time'][1]; - array_push($error, array($i)); + array_push($error, [$i]); $messages[] = $error; } } @@ -1105,7 +1117,7 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I } else { $error = $this->messages['max_lease_time'][1]; - array_push($error, array($i)); + array_push($error, [$i]); $messages[] = $error; } } @@ -1113,17 +1125,17 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I if ($rawAccounts[$i][$ids['dhcp_settings_DNSserver']] != '') { $ex = explode(",", $rawAccounts[$i][$ids['dhcp_settings_DNSserver']]); $invalid = false; - foreach($ex AS $string) { - if (!check_ip($string)) { - $invalid = true; - } + foreach ($ex as $string) { + if (!check_ip($string)) { + $invalid = true; + } } if (!$invalid) { $partialAccounts[$i]['dhcpOption'][] = self::DOMAIN_NAME_SERVERS . ' ' . $rawAccounts[$i][$ids['dhcp_settings_DNSserver']]; } else { $error = $this->messages['dns'][1]; - array_push($error, array($i)); + array_push($error, [$i]); $messages[] = $error; } } @@ -1131,20 +1143,20 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I if ($rawAccounts[$i][$ids['dhcp_settings_domain-search']] != '') { $domains = preg_split('/;[ ]*/', $rawAccounts[$i][$ids['dhcp_settings_domain-search']]); $invalid = false; - foreach($domains AS $key => $name) { - if (!get_preg($name, 'domainname')) { - $invalid = true; - } - else { - $domains[$key] = '"' . $name . '"'; - } + foreach ($domains as $key => $name) { + if (!get_preg($name, 'domainname')) { + $invalid = true; + } + else { + $domains[$key] = '"' . $name . '"'; + } } if (!$invalid) { $partialAccounts[$i]['dhcpOption'][] = self::DOMAIN_SEARCH . ' ' . implode(', ', $domains); } else { $error = $this->messages['INFO_domain-search'][1]; - array_push($error, array($i)); + array_push($error, [$i]); $messages[] = $error; } } @@ -1155,7 +1167,7 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I } else { $error = $this->messages['routers'][1]; - array_push($error, array($i)); + array_push($error, [$i]); $messages[] = $error; } } @@ -1163,23 +1175,23 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I if ($rawAccounts[$i][$ids['dhcp_settings_netbiosServer']] != '') { $ex = explode(",", $rawAccounts[$i][$ids['dhcp_settings_netbiosServer']]); $invalid = false; - foreach($ex AS $string) { - if (!check_ip($string) && !get_preg($string, 'DNSname')) { - $invalid = true; - } + foreach ($ex as $string) { + if (!check_ip($string) && !get_preg($string, 'DNSname')) { + $invalid = true; + } } if (!$invalid) { $partialAccounts[$i]['dhcpOption'][] = self::NETBIOS_NAME_SERVERS . ' ' . $rawAccounts[$i][$ids['dhcp_settings_netbiosServer']]; } else { $error = $this->messages['netbios'][1]; - array_push($error, array($i)); + array_push($error, [$i]); $messages[] = $error; } } // node type if ($rawAccounts[$i][$ids['dhcp_settings_netbiosType']] != '') { - if (in_array($rawAccounts[$i][$ids['dhcp_settings_netbiosType']], array('B', 'P', 'M', 'H'))) { + if (in_array($rawAccounts[$i][$ids['dhcp_settings_netbiosType']], ['B', 'P', 'M', 'H'])) { if ($rawAccounts[$i][$ids['dhcp_settings_netbiosType']] == 'B') { $partialAccounts[$i]['dhcpOption'][] = self::NETBIOS_NODE_TYPE . ' 1'; } @@ -1195,7 +1207,7 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I } else { $error = $this->messages['netbios_node_type'][1]; - array_push($error, array($i)); + array_push($error, [$i]); $messages[] = $error; } } @@ -1211,30 +1223,30 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I } else { $error = $this->messages['unknownClients'][0]; - array_push($error, array($i)); + array_push($error, [$i]); $messages[] = $error; } } // node type if ($rawAccounts[$i][$ids['dhcp_settings_authoritative']] !== '') { - if (in_array($rawAccounts[$i][$ids['dhcp_settings_authoritative']], array('true', 'false'))) { + if (in_array($rawAccounts[$i][$ids['dhcp_settings_authoritative']], ['true', 'false'])) { if ($rawAccounts[$i][$ids['dhcp_settings_authoritative']] === 'true') { $partialAccounts[$i]['dhcpStatements'][] = self::AUTHORITATIVE; } } else { $error = $this->messages['authoritative'][0]; - array_push($error, array($i)); + array_push($error, [$i]); $messages[] = $error; } } // subnet mask - if (check_ip($rawAccounts[$i][$ids['dhcp_settings_subnetMask']],true)) { + if (check_ip($rawAccounts[$i][$ids['dhcp_settings_subnetMask']], true)) { $partialAccounts[$i]['dhcpOption'][] = self::SUBNET_MASK . ' ' . $rawAccounts[$i][$ids['dhcp_settings_subnetMask']]; } else { $error = $this->messages['subnet'][1]; - array_push($error, array($i)); + array_push($error, [$i]); $messages[] = $error; } // net mask @@ -1262,10 +1274,10 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I * @inheritDoc */ public function getListAttributeDescriptions(ConfiguredType $type): array { - return array( + return [ "cn" => _("Subnet"), 'dhcpcomments' => _('Description'), - ); + ]; } }