2008-09-24 16:38:27 +00:00
< ? php
/*
2009-10-27 18:47:12 +00:00
This code is part of LDAP Account Manager ( http :// www . ldap - account - manager . org / )
2009-01-03 19:08:00 +00:00
Copyright ( C ) 2008 Thomas Manninger
2018-05-19 06:15:34 +00:00
2008 - 2018 Roland Gruber
2008-09-24 16:38:27 +00:00
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
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
/**
* Manages DHCP entries .
*
* @ package modules
*
* @ author Thomas Manninger
2008-12-29 17:22:06 +00:00
* @ author Roland Gruber
2008-09-24 16:38:27 +00:00
*/
/**
* This function checks if the given IP address ist valid .
*
* @ param string IP to check
* @ param check Subnet
* @ return boolean true or false
**/
if ( ! function_exists ( 'check_ip' )) {
2017-02-19 08:14:11 +00:00
2012-07-15 12:05:47 +00:00
/**
* Checks if the given IP is valid .
2017-02-19 08:14:11 +00:00
*
2012-07-15 12:05:47 +00:00
* @ param String $ip IP address
* @ param boolean $subnet IP must be a subnet
*/
function check_ip ( $ip , $subnet = false ) {
2009-08-14 20:18:08 +00:00
$part = explode ( " . " , $ip );
2018-12-29 08:51:51 +00:00
// IP must contain 4 segments
2008-09-24 16:38:27 +00:00
if ( count ( $part ) != 4 ) {
return false ;
}
else {
// check each segment
for ( $i = 0 ; $i < count ( $part ); $i ++ ) {
// only numbers are allowed
2018-12-29 08:51:51 +00:00
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 ))) {
2015-03-19 17:13:34 +00:00
return false ;
2008-09-24 16:38:27 +00:00
}
}
}
return true ;
}
}
2008-12-29 17:22:06 +00:00
/**
* Manages DHCP entries .
*
* @ package modules
*/
2008-09-24 16:38:27 +00:00
class dhcp_settings extends baseModule {
2009-11-24 18:55:22 +00:00
2012-07-15 12:05:47 +00:00
/** all netbios node types */
2008-09-24 16:38:27 +00:00
private $all_netbios_node_types ;
2013-08-31 09:33:45 +00:00
/** unknown-client options */
private $allowDenyOptions ;
2012-07-15 12:05:47 +00:00
/** LDAP attributes */
2008-09-24 16:38:27 +00:00
public $attributes ;
2017-02-19 08:14:11 +00:00
2008-09-24 16:38:27 +00:00
/**
* Creates a new dhcp_settings object .
*
* @ param string $scope account type
*/
function __construct ( $scope ) {
2009-11-24 18:55:22 +00:00
// list of node types
2008-09-24 16:38:27 +00:00
$this -> all_netbios_node_types = array (
" 1 " => _ ( " B-Node (0x01) " ),
" 2 " => _ ( " P-Node (0x02) " ),
" 4 " => _ ( " M-Node (0x04) " ),
" 8 " => _ ( " H-Node (0x08) " )
);
2013-08-31 09:33:45 +00:00
$this -> allowDenyOptions = array (
'-' => '' ,
'allow' => _ ( " Allow " ),
'deny' => _ ( " Deny " ),
);
2008-09-24 16:38:27 +00:00
// call parent constructor
parent :: __construct ( $scope );
}
2014-04-20 12:59:36 +00:00
/**
* Returns true if this module can manage accounts of the current type , otherwise false .
2017-02-19 08:14:11 +00:00
*
2014-04-20 12:59:36 +00:00
* @ return boolean true if module fits
*/
public function can_manage () {
return in_array ( $this -> get_scope (), array ( 'dhcp' ));
}
2010-06-12 17:17:31 +00:00
/**
* Returns meta data that is interpreted by parent class
*
* @ return array array with meta data
*/
2008-09-24 16:38:27 +00:00
public function get_metaData () {
$return = array ();
// alias name
$return [ " alias " ] = _ ( " DHCP settings " );
// this is a base module
$return [ " is_base " ] = true ;
2010-02-15 16:56:56 +00:00
// icon
$return [ 'icon' ] = 'dhcpBig.png' ;
2008-09-24 16:38:27 +00:00
// RDN attribute
$return [ " RDN " ] = array ( " cn " => " high " );
// LDAP filter
$return [ " ldap_filter " ] = array ();
// module dependencies
$return [ 'dependencies' ] = array ( 'depends' => array (), 'conflicts' => array ());
// managed object classes
2009-11-27 09:56:47 +00:00
$return [ 'objectClasses' ] = array ( 'top' , 'dhcpOptions' , 'dhcpSubnet' );
2008-09-24 16:38:27 +00:00
// managed attributes
2009-11-24 18:55:22 +00:00
$return [ 'attributes' ] = array ( 'cn' , 'dhcpOption' , 'dhcpComments' , 'dhcpNetMask' , 'dhcpStatements' );
2008-09-24 16:38:27 +00:00
// help Entries
$return [ 'help' ] = array (
2012-02-04 15:56:31 +00:00
'domainname' => array (
2008-09-24 16:38:27 +00:00
" Headline " => _ ( " Domain name " ),
" Text " => _ ( " The domain name of the subnet. " )
2012-02-04 15:56:31 +00:00
),
'subnet' => array (
" Headline " => _ ( " Subnet " ), 'attr' => 'cn' ,
2008-09-24 16:38:27 +00:00
" Text " => _ ( " The name of the subnet. Example: 192.168.10.0 " )
2012-02-04 15:56:31 +00:00
),
'leasetime' => array (
2008-09-24 16:38:27 +00:00
" Headline " => _ ( " Lease time " ),
" Text " => _ ( " The lease time specifies after how many seconds the client should request a new IP address. " )
2012-02-04 15:56:31 +00:00
),
'max_leasetime' => array (
2008-09-24 16:38:27 +00:00
" Headline " => _ ( " Maximum lease time " ),
" Text " => _ ( " The maximum lease time specifies after how many seconds the client must request a new IP address. " )
2012-02-04 15:56:31 +00:00
),
'dns' => array (
2008-09-24 16:38:27 +00:00
" Headline " => _ ( " DNS (Domain Name System) " ),
2012-02-08 19:12:00 +00:00
" Text " => _ ( " The IP addresses of the DNS servers. Multiple addresses are separated by \" , \" . Example: 192.168.0.10, 192.168.0.11 " )
2012-02-04 15:56:31 +00:00
),
'gateway' => array (
2008-09-24 16:38:27 +00:00
" Headline " => _ ( " Default gateway " ),
2008-10-13 16:23:43 +00:00
" 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. " )
2012-02-04 15:56:31 +00:00
),
'netbios' => array (
2009-01-04 15:56:13 +00:00
" Headline " => _ ( " Netbios name servers " ),
" Text " => _ ( " The IP addresses of the Netbios name servers (e.g. \" 123.123.123.123, 123.123.123.124 \" ). " )
2012-02-04 15:56:31 +00:00
),
'netbios_type' => array (
2008-09-24 16:38:27 +00:00
" Headline " => _ ( " Netbios node type " ),
2008-09-28 12:18:56 +00:00
" Text " => _ ( " <b>B-Node (0x01): Broadcast.</b><br/>The client tries to find other workstations via broadcasting
2008-09-24 16:38:27 +00:00
( works only inside the same collision domain , viz . the same subnet ) .< br />< br />
< b > P - Node ( 0x02 ) : Point - To - Point </ b >< br />
The client contacts a Netbios name server ( NBNS ) from Microsoft Windows Name Service ( WINS ) for name resolution .< br />< br />
< b > M - Node ( 0x04 ) : Mixed </ b >< br />
The node tries broadcasting first . If that fails then it tries WINS .< br />< br />
< b > H - Node ( 0x08 ) : Hybrid </ b >< br />
The node tries WINS first . If that fails it tries broadcasting .< br />< br />
By default , the nodes are configured as H - Nodes which fits for small networks . In large networks Point - to - Point ( 0x02 ) should be used . " )
2012-02-04 15:56:31 +00:00
),
'subnetmask' => array (
2008-09-24 16:38:27 +00:00
" Headline " => _ ( " Subnet mask " ),
" Text " => _ ( " The subnet mask of the network. " )
2012-02-04 15:56:31 +00:00
),
'netmask' => array (
" Headline " => _ ( " Net mask " ), 'attr' => 'dhcpNetMask' ,
2010-09-16 18:20:09 +00:00
" Text " => _ ( " The net mask is derived from the subnet mask. LAM will calculate it automatically. " )
2012-02-04 15:56:31 +00:00
),
'description' => array (
" Headline " => _ ( " Description " ), 'attr' => 'dhcpComments' ,
2009-05-11 16:33:48 +00:00
" Text " => _ ( " Here you can enter a description for this DHCP entry. " )
2013-08-31 09:33:45 +00:00
),
'unknownClients' => array (
" Headline " => _ ( " Unknown clients " ), 'attr' => 'dhcpStatements' ,
" Text " => _ ( " Specifies if unknown clients are allowed. " )
),
2018-11-25 13:51:03 +00:00
'INFO_domain-search' => array (
'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 (
'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. " )
),
2012-02-04 15:56:31 +00:00
);
2008-12-29 17:22:06 +00:00
// available PDF fields
$return [ 'PDF_fields' ] = array (
2010-04-05 12:38:23 +00:00
'subnet' => _ ( 'Subnet' ),
'domainName' => _ ( 'Domain name' ),
'leaseTime' => _ ( 'Lease time' ),
'maxLeaseTime' => _ ( 'Maximum lease time' ),
'DNSserver' => _ ( 'DNS' ),
'gateway' => _ ( 'Default gateway' ),
'netbiosServer' => _ ( 'Netbios name servers' ),
'netbiosType' => _ ( 'Netbios node type' ),
'subnetMask' => _ ( 'Subnet mask' ),
'netMask' => _ ( 'Net mask' ),
2013-08-31 09:33:45 +00:00
'description' => _ ( 'Description' ),
'unknownClients' => _ ( 'Unknown clients' ),
2018-11-25 13:51:03 +00:00
'domain-search' => _ ( 'Search domains' ),
2008-12-29 17:22:06 +00:00
);
2009-01-04 15:31:28 +00:00
// profile elements
2018-05-19 06:15:34 +00:00
$profileContainer = new htmlResponsiveRow ();
$profileContainer -> add ( new htmlResponsiveInputField ( _ ( 'Subnet' ), 'cn' , null , 'subnet' ), 12 );
$profileContainer -> add ( new htmlResponsiveInputField ( _ ( 'Domain name' ), 'domainname' , null , 'domainname' ), 12 );
$profileContainer -> add ( new htmlResponsiveInputField ( _ ( 'Lease time' ), 'lease_time' , null , 'leasetime' ), 12 );
$profileContainer -> add ( new htmlResponsiveInputField ( _ ( 'Maximum lease time' ), 'max_lease_time' , null , 'max_leasetime' ), 12 );
$profileContainer -> add ( new htmlResponsiveInputField ( _ ( 'DNS' ), 'dns' , null , 'dns' ), 12 );
2018-11-25 13:51:03 +00:00
$profileContainer -> add ( new htmlResponsiveInputField ( _ ( 'Search domains' ), 'domain-search' , null , 'domain-search' ), 12 );
2018-05-19 06:15:34 +00:00
$profileContainer -> add ( new htmlResponsiveInputField ( _ ( 'Default gateway' ), 'routers' , null , 'gateway' ), 12 );
$profileContainer -> add ( new htmlResponsiveInputField ( _ ( 'Netbios name servers' ), 'netbios' , null , 'netbios' ), 12 );
2010-09-16 18:20:09 +00:00
$nodeList = array_flip ( $this -> all_netbios_node_types );
2018-05-19 06:15:34 +00:00
$profileNodeSelect = new htmlResponsiveSelect ( 'netbios_node_type' , $nodeList , null , _ ( 'Netbios node type' ), 'netbios_type' );
2010-09-16 18:20:09 +00:00
$profileNodeSelect -> setHasDescriptiveElements ( true );
2018-05-19 06:15:34 +00:00
$profileContainer -> add ( $profileNodeSelect , 12 );
$profileContainer -> add ( new htmlResponsiveInputField ( _ ( 'Subnet mask' ), 'subnet' , null , 'subnetmask' ), 12 );
2010-09-16 18:20:09 +00:00
$return [ 'profile_options' ] = $profileContainer ;
2009-03-24 19:51:13 +00:00
// upload fields
2013-08-31 09:33:45 +00:00
$uploadAllowDenyOption = $this -> allowDenyOptions ;
unset ( $uploadAllowDenyOption [ '-' ]);
$uploadAllowDenyOption = implode ( ', ' , $uploadAllowDenyOption );
2009-03-24 19:51:13 +00:00
$return [ 'upload_columns' ] = array (
array (
'name' => 'dhcp_settings_subnet' ,
'description' => _ ( 'Subnet' ),
'help' => 'subnet' ,
'example' => '192.168.10.0' ,
'required' => true ,
2017-09-18 17:47:27 +00:00
'unique' => true
2009-03-24 19:51:13 +00:00
),
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' ,
),
2018-11-25 13:51:03 +00:00
array (
'name' => 'dhcp_settings_domain-search' ,
'description' => _ ( 'Search domains' ),
'help' => 'domain-search' ,
'example' => 'example.com' ,
),
2009-03-24 19:51:13 +00:00
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'
),
2013-08-31 09:33:45 +00:00
array (
'name' => 'dhcp_settings_unknownClients' ,
'description' => _ ( 'Unknown clients' ),
'help' => 'unknownClients' ,
'values' => $uploadAllowDenyOption
),
2009-03-24 19:51:13 +00:00
array (
'name' => 'dhcp_settings_subnetMask' ,
'description' => _ ( 'Subnet mask' ),
'help' => 'subnetmask' ,
'required' => true ,
'example' => '255.255.255.0' ,
),
2009-05-11 16:33:48 +00:00
array (
'name' => 'dhcp_settings_description' ,
'description' => _ ( 'Description' ),
'help' => 'description' ,
),
2009-03-24 19:51:13 +00:00
);
2008-09-24 16:38:27 +00:00
return $return ;
}
2017-02-19 08:14:11 +00:00
2008-09-24 16:38:27 +00:00
/**
* 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.' ));
2009-03-24 19:51:13 +00:00
$this -> messages [ 'cn' ][ 3 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' dhcp_settings_subnet' , _ ( 'The subnet is invalid.' ));
2008-09-24 16:38:27 +00:00
$this -> messages [ 'dns' ][ 0 ] = array ( 'ERROR' , _ ( 'You entered one or more invalid DNS servers.' ));
2009-03-24 19:51:13 +00:00
$this -> messages [ 'dns' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' dhcp_settings_DNSserver' , _ ( 'You entered one or more invalid DNS servers.' ));
2008-09-24 16:38:27 +00:00
$this -> messages [ 'lease_time' ][ 0 ] = array ( 'ERROR' , _ ( 'The lease time is invalid.' ));
2009-03-24 19:51:13 +00:00
$this -> messages [ 'lease_time' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' dhcp_settings_leaseTime' , _ ( 'The lease time is invalid.' ));
2008-09-24 16:38:27 +00:00
$this -> messages [ 'routers' ][ 0 ] = array ( 'ERROR' , _ ( 'The default gateway is invalid.' ));
2009-03-24 19:51:13 +00:00
$this -> messages [ 'routers' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' dhcp_settings_gateway' , _ ( 'The default gateway is invalid.' ));
2008-09-24 16:38:27 +00:00
$this -> messages [ 'netbios' ][ 0 ] = array ( 'ERROR' , _ ( 'The Netbios server is invalid.' ));
2009-03-24 19:51:13 +00:00
$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.' ));
2013-08-31 09:33:45 +00:00
$this -> messages [ 'unknownClients' ][ 0 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' dhcp_settings_unknownClients' , _ ( 'Please enter a valid option.' ));
2008-09-24 16:38:27 +00:00
$this -> messages [ 'max_lease_time' ][ 0 ] = array ( 'ERROR' , _ ( 'The maximum lease time is invalid.' ));
2009-03-24 19:51:13 +00:00
$this -> messages [ 'max_lease_time' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' dhcp_settings_maxLeaseTime' , _ ( 'The maximum lease time is invalid.' ));
2008-09-24 16:38:27 +00:00
$this -> messages [ 'subnet' ][ 0 ] = array ( 'ERROR' , _ ( 'The subnet mask is invalid.' ));
2009-03-24 19:51:13 +00:00
$this -> messages [ 'subnet' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' dhcp_settings_subnetMask' , _ ( 'The subnet mask is invalid.' ));
2008-09-24 16:38:27 +00:00
$this -> messages [ 'ranges_reload' ][ 0 ] = array ( 'INFO' , _ ( 'The DHCP ranges were changed to fit for the new subnet.' ));
2018-11-25 13:51:03 +00:00
$this -> messages [ 'ips_reload' ][ 0 ] = array ( 'INFO' , _ ( 'The fixed IP addresses were changed to fit for the new subnet.' ));
2008-09-24 16:38:27 +00:00
$this -> messages [ 'domainname' ][ 2 ] = array ( 'ERROR' , _ ( 'The domain name includes invalid characters. Valid characters are A-Z, a-z, 0-9, ".", "_","-".' ));
2009-03-24 19:51:13 +00:00
$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, ".", "_","-".' ));
2018-11-25 13:51:03 +00:00
$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.' ));
2008-09-24 16:38:27 +00:00
}
2017-02-19 08:14:11 +00:00
2011-02-26 13:14:10 +00:00
/**
* Returns a list of modifications which have to be made to the LDAP account .
*
* @ return array list of modifications
* < br > This function returns an array with 3 entries :
* < br > array ( DN1 ( 'add' => array ( $attr ), 'remove' => array ( $attr ), 'modify' => array ( $attr )), DN2 .... )
* < br > 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 )
* < br > " add " are attributes which have to be added to LDAP entry
* < br > " remove " are attributes which have to be removed from LDAP entry
* < br > " modify " are attributes which have to been modified in LDAP entry
* < br > " info " are values with informational value ( e . g . to be used later by pre / postModify actions )
2008-09-24 16:38:27 +00:00
*/
public function save_attributes () {
2009-11-27 09:56:47 +00:00
// remove dhcpSubnet object class if only the DHCP settings were changed
2017-04-22 09:57:57 +00:00
if ( $this -> isRootNode ()) {
2009-11-27 09:56:47 +00:00
if ( ! 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' ]);
2008-12-07 19:13:50 +00:00
}
2008-09-24 16:38:27 +00:00
}
2009-11-27 09:56:47 +00:00
$return = parent :: save_attributes ();
2008-09-24 16:38:27 +00:00
return $return ;
}
2017-02-19 08:14:11 +00:00
2008-09-24 16:38:27 +00:00
/**
* 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 () {
2009-01-10 17:37:09 +00:00
// check if DHCP main settings and valid DHCP entry
2017-04-22 09:57:57 +00:00
if ( $this -> isRootNode ()) {
2013-02-23 17:10:43 +00:00
if ( ! in_array_ignore_case ( 'dhcpService' , $this -> attributes [ 'objectClass' ]) && ! in_array_ignore_case ( 'dhcpServer' , $this -> attributes [ 'objectClass' ])) {
2009-01-10 17:37:09 +00:00
return array ();
}
}
2008-09-24 16:38:27 +00:00
$errors = array ();
// Check if cn is not empty
2017-04-22 09:57:57 +00:00
if ( ! $this -> isRootNode ()) {
2008-09-24 16:38:27 +00:00
if ( ! empty ( $_POST [ 'cn' ])) $_POST [ 'cn' ] = trim ( $_POST [ 'cn' ]);
2009-11-24 18:55:22 +00:00
$this -> attributes [ 'cn' ][ 0 ] = $_POST [ 'cn' ];
2008-09-24 16:38:27 +00:00
if ( empty ( $_POST [ 'cn' ])) {
$errors [] = $this -> messages [ 'cn' ][ 0 ];
}
// Check, if cn is not already use:
2009-11-26 12:53:37 +00:00
elseif (( sizeof ( searchLDAPByAttribute ( 'cn' , $_POST [ 'cn' ], 'dhcpOptions' , array ( 'cn' ), array ( 'dhcp' ))) > 0 ) && $this -> orig [ 'cn' ][ '0' ] != $_POST [ 'cn' ]) {
2008-09-24 16:38:27 +00:00
$errors [] = $this -> messages [ 'cn' ][ 1 ];
}
elseif ( ! check_ip ( $_POST [ 'cn' ], true )) {
$errors [] = $this -> messages [ 'cn' ][ 2 ];
}
2009-11-24 18:55:22 +00:00
else {
// if the cn was edit, reload the Ranges:
if ( $this -> getAccountContainer () -> getAccountModule ( 'range' ) -> reload_ranges ())
2008-09-24 16:38:27 +00:00
$errors [] = $this -> messages [ 'ranges_reload' ][ 0 ];
// if the cn was edit, reload the ips:
2009-11-24 18:55:22 +00:00
if ( $this -> getAccountContainer () -> getAccountModule ( 'fixed_ip' ) -> reload_ips ())
2008-09-24 16:38:27 +00:00
$errors [] = $this -> messages [ 'ips_reload' ][ 0 ];
}
2013-08-31 09:33:45 +00:00
$this -> setUnknownClients ( $_POST [ 'unknownClients' ]);
2008-09-24 16:38:27 +00:00
}
2017-02-19 08:14:11 +00:00
2008-09-24 16:38:27 +00:00
// Check domainname:
if ( ! empty ( $_POST [ 'domainname' ])) $_POST [ 'domainname' ] = trim ( $_POST [ 'domainname' ]);
if ( ! empty ( $_POST [ 'domainname' ])) {
2013-01-05 15:14:12 +00:00
if ( ! preg_match ( " /^[A-Za-z0-9 \\ ._-]* $ / " , $_POST [ 'domainname' ])) {
2008-09-24 16:38:27 +00:00
$errors [] = $this -> messages [ 'domainname' ][ 2 ];
}
}
2009-11-24 21:50:17 +00:00
$this -> setDHCPOption ( 'domain-name' , '"' . $_POST [ 'domainname' ] . '"' );
2008-09-24 16:38:27 +00:00
// Check DNS
2009-11-24 18:55:22 +00:00
if ( ! empty ( $_POST [ 'dns' ])) {
$_POST [ 'dns' ] = trim ( $_POST [ 'dns' ]);
2008-09-24 16:38:27 +00:00
$ex = explode ( " , " , $_POST [ 'dns' ]);
$dns = " " ;
$is_first = true ;
$invalid = false ;
foreach ( $ex AS $string ) {
if ( $is_first ) {
$dns .= $string ;
$is_first = false ;
}
2009-03-24 19:51:13 +00:00
else {
2008-09-24 16:38:27 +00:00
$dns .= " , $string " ;
}
if ( ! check_ip ( $string )) {
$invalid = true ;
}
}
if ( $invalid ) {
$errors [] = $this -> messages [ 'dns' ][ 0 ];
}
}
2009-11-24 18:55:22 +00:00
$this -> setDHCPOption ( 'domain-name-servers' , $_POST [ 'dns' ]);
2018-11-25 13:51:03 +00:00
// domain search
$this -> processMultiValueInputTextField ( 'INFO_domain-search' , $errors , 'domainname' );
foreach ( $this -> attributes [ 'INFO_domain-search' ] as $key => $domainName ) {
$this -> attributes [ 'INFO_domain-search' ][ $key ] = '"' . $domainName . '"' ;
}
$domainSearch = implode ( ', ' , $this -> attributes [ 'INFO_domain-search' ]);
$this -> setDHCPOption ( 'domain-search' , $domainSearch );
unset ( $this -> attributes [ 'INFO_domain-search' ]);
2017-02-19 08:14:11 +00:00
2008-09-24 16:38:27 +00:00
// Lease Time
2009-01-03 19:05:16 +00:00
if ( ! empty ( $_POST [ 'lease_time' ])) {
$_POST [ 'lease_time' ] = trim ( $_POST [ 'lease_time' ]);
}
$this -> setDefaultLeaseTime ( $_POST [ 'lease_time' ]);
2008-09-24 16:38:27 +00:00
if ( ! is_numeric ( $_POST [ 'lease_time' ]) && ! empty ( $_POST [ 'lease_time' ])) {
$errors [] = $this -> messages [ 'lease_time' ][ 0 ];
}
2017-02-19 08:14:11 +00:00
2008-09-24 16:38:27 +00:00
// Max lease Time
2009-01-03 19:05:16 +00:00
if ( ! empty ( $_POST [ 'max_lease_time' ])) {
$_POST [ 'max_lease_time' ] = trim ( $_POST [ 'max_lease_time' ]);
}
$this -> setMaxLeaseTime ( $_POST [ 'max_lease_time' ]);
2008-09-24 16:38:27 +00:00
if ( ! is_numeric ( $_POST [ 'max_lease_time' ]) && ! empty ( $_POST [ 'max_lease_time' ])) {
$errors [] = $this -> messages [ 'max_lease_time' ][ 0 ];
}
2017-02-19 08:14:11 +00:00
2008-09-24 16:38:27 +00:00
// Default Gateway
2009-11-24 18:55:22 +00:00
if ( ! empty ( $_POST [ 'routers' ])) {
$_POST [ 'routers' ] = trim ( $_POST [ 'routers' ]);
if ( ! check_ip ( $_POST [ 'routers' ])) {
$errors [] = $this -> messages [ 'routers' ][ 0 ];
}
2008-09-24 16:38:27 +00:00
}
2009-11-24 18:55:22 +00:00
$this -> setDHCPOption ( 'routers' , $_POST [ 'routers' ]);
2017-02-19 08:14:11 +00:00
2008-09-24 16:38:27 +00:00
// Netbios
if ( ! empty ( $_POST [ 'netbios' ])) $_POST [ 'netbios' ] = trim ( $_POST [ 'netbios' ]);
2009-01-04 15:56:13 +00:00
$netbiosServers = explode ( ', ' , $_POST [ 'netbios' ]);
$netbiosServersOk = true ;
for ( $i = 0 ; $i < sizeof ( $netbiosServers ); $i ++ ) {
2013-02-24 11:46:11 +00:00
if ( ! check_ip ( $netbiosServers [ $i ]) && ! get_preg ( $netbiosServers [ $i ], 'DNSname' )) {
2009-01-04 15:56:13 +00:00
$netbiosServersOk = false ;
break ;
}
}
if ( ! $netbiosServersOk && ! empty ( $_POST [ 'netbios' ])) {
2008-09-24 16:38:27 +00:00
$errors [] = $this -> messages [ 'netbios' ][ 0 ];
}
2009-11-24 18:55:22 +00:00
$this -> setDHCPOption ( 'netbios-name-servers' , $_POST [ 'netbios' ]);
2017-02-19 08:14:11 +00:00
2009-11-24 18:55:22 +00:00
$this -> setDHCPOption ( 'netbios-node-type' , $_POST [ 'netbios_node_type' ]);
2017-02-19 08:14:11 +00:00
2017-04-22 09:57:57 +00:00
if ( ! $this -> isRootNode ()) {
2008-09-24 16:38:27 +00:00
// Check subnet
$_POST [ 'subnet' ] = trim ( $_POST [ 'subnet' ]);
2010-01-30 14:29:40 +00:00
if ( ! $this -> checkSubnetMask ( $_POST [ 'subnet' ])) {
2008-09-24 16:38:27 +00:00
$errors [] = $this -> messages [ 'subnet' ][ 0 ];
}
2009-11-24 18:55:22 +00:00
$this -> setDHCPOption ( 'subnet-mask' , $_POST [ 'subnet' ]);
2008-09-24 16:38:27 +00:00
2009-03-24 19:51:13 +00:00
// calculate netmask from subnet:
2009-11-25 10:42:25 +00:00
if ( ! empty ( $_POST [ 'subnet' ])) {
$this -> attributes [ 'dhcpNetMask' ][ 0 ] = $this -> calculateNetMask ( $_POST [ 'subnet' ]);
2009-03-24 19:51:13 +00:00
}
2008-09-24 16:38:27 +00:00
}
2009-05-11 16:33:48 +00:00
$this -> attributes [ 'dhcpComments' ][ 0 ] = $_POST [ 'description' ];
2017-02-19 08:14:11 +00:00
2008-09-24 16:38:27 +00:00
return $errors ;
}
2017-02-19 08:14:11 +00:00
2010-01-30 14:29:40 +00:00
/**
* Checks if the subnet mask is valid .
*
* @ param String $mask subnet mask
* @ return boolean correct or incorrect
*/
private function checkSubnetMask ( $mask ) {
// check basic format
if ( ! check_ip ( $mask , true )) {
return false ;
}
// check if bit order is 11...00...
$parts = explode ( '.' , $mask );
$bits = '' ;
for ( $i = 0 ; $i < sizeof ( $parts ); $i ++ ) {
$bits .= decbin ( $parts [ $i ]);
}
return preg_match ( '/^1*0*$/' , $bits );
}
2017-02-19 08:14:11 +00:00
2009-03-24 19:51:13 +00:00
/**
* Calculates the net mask from the subnet .
*
* @ param String $subnet subnet
* @ return integer netmask
*/
private function calculateNetMask ( $subnet ) {
$ex = explode ( " . " , $subnet );
$num = 0 ;
foreach ( $ex AS $mask ) {
$binary = decbin ( $mask );
$num += substr_count ( $binary , 1 );
}
return $num ;
}
2017-02-19 08:14:11 +00:00
2010-06-12 17:17:31 +00:00
/**
* Returns the HTML meta data for the main account page .
2017-02-19 08:14:11 +00:00
*
2010-09-18 11:37:22 +00:00
* @ return htmlElement HTML meta data
2010-06-12 17:17:31 +00:00
*/
2008-09-24 16:38:27 +00:00
public function display_html_attributes () {
2011-11-25 19:06:22 +00:00
$return = new htmlTable ();
2009-01-10 17:37:09 +00:00
// check if DHCP main settings and valid DHCP entry
2017-04-22 09:57:57 +00:00
if ( $this -> isRootNode ()) {
2013-02-23 17:10:43 +00:00
if ( ! in_array_ignore_case ( 'dhcpService' , $this -> attributes [ 'objectClass' ]) && ! in_array_ignore_case ( 'dhcpServer' , $this -> attributes [ 'objectClass' ])) {
$return -> addElement ( new htmlStatusMessage ( 'ERROR' , _ ( 'Please set your LDAP suffix to an LDAP entry with object class "dhcpService" or "dhcpServer".' )));
2010-09-16 18:20:09 +00:00
return $return ;
2009-01-10 17:37:09 +00:00
}
}
2009-11-24 18:55:22 +00:00
// Subnet name
2017-04-22 09:57:57 +00:00
if ( ! $this -> isRootNode ()) {
2010-09-16 18:20:09 +00:00
$cn = '' ;
if ( isset ( $this -> attributes [ 'cn' ][ 0 ])) {
$cn = $this -> attributes [ 'cn' ][ 0 ];
}
$subnetInput = new htmlTableExtendedInputField ( _ ( 'Subnet' ), 'cn' , $cn , 'subnet' );
$subnetInput -> setRequired ( true );
$return -> addElement ( $subnetInput );
$return -> addElement ( new htmlOutputText ( _ ( 'Example' ) . " : 192.168.10.0 " ), true );
2008-09-24 16:38:27 +00:00
}
2010-09-16 18:20:09 +00:00
// domain name
$return -> addElement ( new htmlTableExtendedInputField ( _ ( 'Domain name' ), 'domainname' , $this -> getDHCPOption ( 'domain-name' ), 'domainname' ), true );
// lease Time
2011-10-20 16:43:42 +00:00
$leasetimeInput = new htmlTableExtendedInputField ( _ ( 'Lease time' ), 'lease_time' , $this -> getDefaultLeaseTime (), 'leasetime' );
$leasetimeInput -> setValidationRule ( htmlElement :: VALIDATE_NUMERIC );
$return -> addElement ( $leasetimeInput , true );
2010-09-16 18:20:09 +00:00
// max lease time
2011-10-20 16:43:42 +00:00
$max_leasetimeInput = new htmlTableExtendedInputField ( _ ( 'Maximum lease time' ), 'max_lease_time' , $this -> getMaxLeaseTime (), 'max_leasetime' );
$max_leasetimeInput -> setValidationRule ( htmlElement :: VALIDATE_NUMERIC );
$return -> addElement ( $max_leasetimeInput , true );
2008-09-24 16:38:27 +00:00
// DNS
2010-09-16 18:20:09 +00:00
$return -> addElement ( new htmlTableExtendedInputField ( _ ( 'DNS' ), 'dns' , $this -> getDHCPOption ( 'domain-name-servers' ), 'dns' ), true );
2018-11-25 13:51:03 +00:00
// domain search
$domainSearchEntries = $this -> getDHCPOption ( 'domain-search' );
if ( $domainSearchEntries === null ) {
$domainSearchEntries = '' ;
}
$domainSearchEntries = explode ( ', ' , $domainSearchEntries );
$this -> attributes [ 'INFO_domain-search' ] = $domainSearchEntries ;
$this -> addMultiValueInputTextField ( $return , 'INFO_domain-search' , _ ( 'Search domains' ));
2010-09-16 18:20:09 +00:00
// gateway
$return -> addElement ( new htmlTableExtendedInputField ( _ ( 'Default gateway' ), 'routers' , $this -> getDHCPOption ( 'routers' ), 'gateway' ), true );
// netbios name servers
$return -> addElement ( new htmlTableExtendedInputField ( _ ( 'Netbios name servers' ), 'netbios' , $this -> getDHCPOption ( 'netbios-name-servers' ), 'netbios' ), true );
// netbios node type
2009-11-24 18:55:22 +00:00
$nodeType = $this -> getDHCPOption ( 'netbios-node-type' );
if ( $nodeType == '' ) {
$nodeType = 8 ;
}
$nodeOptions = array ();
foreach ( $this -> all_netbios_node_types as $key => $value ) {
2010-09-16 18:20:09 +00:00
$nodeOptions [ $value ] = $key ;
2009-11-24 18:55:22 +00:00
}
2010-09-16 18:20:09 +00:00
$nodeSelect = new htmlTableExtendedSelect ( 'netbios_node_type' , $nodeOptions , array ( $nodeType ), _ ( 'Netbios node type' ), 'netbios_type' );
$nodeSelect -> setHasDescriptiveElements ( true );
$return -> addElement ( $nodeSelect , true );
2017-02-19 08:14:11 +00:00
2017-04-22 09:57:57 +00:00
if ( ! $this -> isRootNode ()) {
2013-08-31 09:33:45 +00:00
// unknown clients
$unknownClients = $this -> getUnknownClients ();
if ( empty ( $unknownClients )) {
$unknownClients = '-' ;
}
$unknownClientsOptions = array_flip ( $this -> allowDenyOptions );
$unknownClientsSelect = new htmlTableExtendedSelect ( 'unknownClients' , $unknownClientsOptions , array ( $unknownClients ), _ ( 'Unknown clients' ), 'unknownClients' );
$unknownClientsSelect -> setHasDescriptiveElements ( true );
$return -> addElement ( $unknownClientsSelect , true );
2008-09-24 16:38:27 +00:00
// subnetmask
2010-09-16 18:20:09 +00:00
$subnetMaskInput = new htmlTableExtendedInputField ( _ ( 'Subnet mask' ), 'subnet' , $this -> getDHCPOption ( 'subnet-mask' ), 'subnetmask' );
$subnetMaskInput -> setRequired ( true );
$return -> addElement ( $subnetMaskInput , true );
// netmask
$return -> addElement ( new htmlOutputText ( _ ( 'Net mask' )));
$return -> addElement ( new htmlOutputText ( $this -> attributes [ 'dhcpNetMask' ][ 0 ]));
$return -> addElement ( new htmlHelpLink ( 'netmask' ), true );
2008-09-24 16:38:27 +00:00
}
2009-05-11 16:33:48 +00:00
2010-09-16 18:20:09 +00:00
// description
$description = '' ;
if ( isset ( $this -> attributes [ 'dhcpComments' ][ 0 ])) {
$description = $this -> attributes [ 'dhcpComments' ][ 0 ];
}
$return -> addElement ( new htmlTableExtendedInputField ( _ ( 'Description' ), 'description' , $description , 'description' ), true );
2008-09-24 16:38:27 +00:00
return $return ;
}
2017-02-19 08:14:11 +00:00
2008-09-24 16:38:27 +00:00
/**
* 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 );
$this -> attributes [ 'cn' ][ 0 ] = $profile [ 'cn' ][ 0 ];
2017-02-19 08:14:11 +00:00
2009-01-03 19:05:16 +00:00
$this -> setDefaultLeaseTime ( $profile [ 'lease_time' ][ 0 ]);
$this -> setMaxLeaseTime ( $profile [ 'max_lease_time' ][ 0 ]);
2017-02-19 08:14:11 +00:00
2009-11-24 18:55:22 +00:00
$this -> setDHCPOption ( 'domain-name' , $profile [ 'domainname' ][ 0 ]);
$this -> setDHCPOption ( 'domain-name-servers' , $profile [ 'dns' ][ 0 ]);
$this -> setDHCPOption ( 'routers' , $profile [ 'routers' ][ 0 ]);
$this -> setDHCPOption ( 'netbios-name-servers' , $profile [ 'netbios' ][ 0 ]);
$this -> setDHCPOption ( 'netbios-node-type' , $profile [ 'netbios_node_type' ][ 0 ]);
2018-11-25 13:51:03 +00:00
if ( ! empty ( $profile [ 'domain-search' ][ 0 ])) {
$domains = '"' . $profile [ 'domain-search' ][ 0 ] . '"' ;
$domains = str_replace ( ';' , '", "' , $domains );
$this -> setDHCPOption ( 'domain-search' , $domains );
}
2017-02-19 08:14:11 +00:00
2017-04-22 09:57:57 +00:00
if ( ! $this -> isRootNode ()) {
2009-11-24 18:55:22 +00:00
$this -> setDHCPOption ( 'subnet-mask' , $profile [ 'subnet' ][ 0 ]);
2008-09-24 16:38:27 +00:00
// calc the netmask:
2009-11-24 18:55:22 +00:00
$ex = explode ( " . " , $profile [ 'subnet' ][ 0 ]);
2008-09-24 16:38:27 +00:00
$num = 0 ;
foreach ( $ex AS $mask ) {
2009-03-24 19:51:13 +00:00
$binary = decbin ( $mask );
$num += substr_count ( $binary , 1 );
2008-09-24 16:38:27 +00:00
}
$this -> attributes [ 'dhcpNetMask' ][ 0 ] = $num ;
}
}
2017-02-19 08:14:11 +00:00
2008-12-29 17:22:06 +00:00
/**
2017-02-19 08:14:11 +00:00
* { @ inheritDoc }
* @ see baseModule :: get_pdfEntries ()
2015-01-07 17:16:35 +00:00
*/
2017-04-01 07:57:03 +00:00
function get_pdfEntries ( $pdfKeys , $typeId ) {
2009-11-24 18:55:22 +00:00
$nodeType = $this -> getDHCPOption ( 'netbios-node-type' );
$nodeTypeValue = '' ;
if ( isset ( $this -> all_netbios_node_types [ $nodeType ])) {
$nodeTypeValue = $this -> all_netbios_node_types [ $nodeType ];
}
2013-08-31 09:33:45 +00:00
$unknownClients = '' ;
$unknownClientsVal = $this -> getUnknownClients ();
if ( ! empty ( $unknownClientsVal )) {
$unknownClients = $this -> allowDenyOptions [ $unknownClientsVal ];
}
2015-03-08 20:09:18 +00:00
$return = array ();
$this -> addPDFKeyValue ( $return , 'domainName' , _ ( 'Domain name' ), $this -> getDHCPOption ( 'domain-name' ));
$this -> addPDFKeyValue ( $return , 'leaseTime' , _ ( 'Lease time' ), $this -> getDefaultLeaseTime ());
$this -> addPDFKeyValue ( $return , 'maxLeaseTime' , _ ( 'Maximum lease time' ), $this -> getMaxLeaseTime ());
$this -> addPDFKeyValue ( $return , 'DNSserver' , _ ( 'DNS' ), $this -> getDHCPOption ( 'domain-name-servers' ));
2018-11-25 13:51:03 +00:00
$this -> addPDFKeyValue ( $return , 'domain-search' , _ ( 'Search domains' ), $this -> getDHCPOption ( 'domain-search' ));
2015-03-08 20:09:18 +00:00
$this -> addPDFKeyValue ( $return , 'gateway' , _ ( 'Default gateway' ), $this -> getDHCPOption ( 'routers' ));
$this -> addPDFKeyValue ( $return , 'netbiosServer' , _ ( 'Netbios name servers' ), $this -> getDHCPOption ( 'netbios-name-servers' ));
$this -> addPDFKeyValue ( $return , 'netbiosType' , _ ( 'Netbios node type' ), $nodeTypeValue );
$this -> addPDFKeyValue ( $return , 'subnetMask' , _ ( 'Subnet mask' ), $this -> getDHCPOption ( 'subnet-mask' ));
$this -> addPDFKeyValue ( $return , 'unknownClients' , _ ( 'Unknown clients' ), $unknownClients );
2013-05-05 13:50:19 +00:00
$this -> addSimplePDFField ( $return , 'description' , _ ( 'Description' ), 'dhcpComments' );
$this -> addSimplePDFField ( $return , 'subnet' , _ ( 'Subnet' ), 'cn' );
$this -> addSimplePDFField ( $return , 'netMask' , _ ( 'Net mask' ), 'dhcpNetMask' );
return $return ;
2008-12-29 17:22:06 +00:00
}
2017-02-19 08:14:11 +00:00
2009-11-24 18:55:22 +00:00
/**
* Returns a DHCP option .
2017-02-19 08:14:11 +00:00
*
2009-11-24 18:55:22 +00:00
* @ param String $name option name
* @ return String value
*/
2009-11-24 21:50:17 +00:00
public function getDHCPOption ( $name ) {
2009-11-24 18:55:22 +00:00
$return = null ;
if ( is_array ( $this -> attributes [ 'dhcpOption' ])) {
for ( $i = 0 ; $i < sizeof ( $this -> attributes [ 'dhcpOption' ]); $i ++ ) {
2013-08-31 09:33:45 +00:00
$val = $this -> attributes [ 'dhcpOption' ][ $i ];
if ( substr ( $val , 0 , strlen ( $name ) + 1 ) == ( $name . ' ' )) {
$return = substr ( $val , strlen ( $name ) + 1 );
2009-11-24 18:55:22 +00:00
$return = str_replace ( '"' , '' , $return );
break ;
}
}
}
return $return ;
}
2017-02-19 08:14:11 +00:00
2009-11-24 18:55:22 +00:00
/**
* Sets a DHCP option .
2017-02-19 08:14:11 +00:00
*
2009-11-24 18:55:22 +00:00
* @ param String $name option name
* @ param String $value option value
*/
private function setDHCPOption ( $name , $value ) {
2018-11-25 13:51:03 +00:00
if ( empty ( $this -> attributes [ 'dhcpOption' ])) {
2009-11-24 18:55:22 +00:00
$this -> attributes [ 'dhcpOption' ] = array ();
}
for ( $i = 0 ; $i < sizeof ( $this -> attributes [ 'dhcpOption' ]); $i ++ ) {
if ( substr ( $this -> attributes [ 'dhcpOption' ][ $i ], 0 , strlen ( $name ) + 1 ) == ( $name . ' ' )) {
unset ( $this -> attributes [ 'dhcpOption' ][ $i ]);
$this -> attributes [ 'dhcpOption' ] = array_values ( $this -> attributes [ 'dhcpOption' ]);
}
}
if (( $value != null ) && ( $value != '' )) {
$this -> attributes [ 'dhcpOption' ][] = $name . ' ' . $value ;
}
}
2009-01-03 19:05:16 +00:00
/**
* Returns the default lease time .
2017-02-19 08:14:11 +00:00
*
2009-01-03 19:05:16 +00:00
* @ return String time
*/
private function getDefaultLeaseTime () {
$return = null ;
2018-11-11 18:56:15 +00:00
if ( ! empty ( $this -> attributes [ 'dhcpStatements' ])) {
2009-01-03 19:05:16 +00:00
for ( $i = 0 ; $i < sizeof ( $this -> attributes [ 'dhcpStatements' ]); $i ++ ) {
if ( substr ( $this -> attributes [ 'dhcpStatements' ][ $i ], 0 , 19 ) == 'default-lease-time ' ) {
$return = substr ( $this -> attributes [ 'dhcpStatements' ][ $i ], 19 );
break ;
}
}
}
return $return ;
}
2017-02-19 08:14:11 +00:00
2009-01-03 19:05:16 +00:00
/**
* Sets the default lease time .
2017-02-19 08:14:11 +00:00
*
2009-11-24 18:55:22 +00:00
* @ param String $time time
2009-01-03 19:05:16 +00:00
*/
private function setDefaultLeaseTime ( $time ) {
2018-11-25 13:51:03 +00:00
if ( empty ( $this -> attributes [ 'dhcpStatements' ])) {
2009-01-03 19:05:16 +00:00
$this -> attributes [ 'dhcpStatements' ] = array ();
}
for ( $i = 0 ; $i < sizeof ( $this -> attributes [ 'dhcpStatements' ]); $i ++ ) {
if ( substr ( $this -> attributes [ 'dhcpStatements' ][ $i ], 0 , 19 ) == 'default-lease-time ' ) {
unset ( $this -> attributes [ 'dhcpStatements' ][ $i ]);
$this -> attributes [ 'dhcpStatements' ] = array_values ( $this -> attributes [ 'dhcpStatements' ]);
}
}
if (( $time != null ) && ( $time != '' )) {
$this -> attributes [ 'dhcpStatements' ][] = 'default-lease-time ' . $time ;
}
}
2013-08-31 09:33:45 +00:00
/**
* Returns the unknown clients option .
2017-02-19 08:14:11 +00:00
*
2013-08-31 09:33:45 +00:00
* @ return String unknown clients value
*/
private function getUnknownClients () {
$return = null ;
2018-11-11 18:56:15 +00:00
if ( ! empty ( $this -> attributes [ 'dhcpStatements' ])) {
2013-08-31 09:33:45 +00:00
for ( $i = 0 ; $i < sizeof ( $this -> attributes [ 'dhcpStatements' ]); $i ++ ) {
$val = $this -> attributes [ 'dhcpStatements' ][ $i ];
if ( strpos ( $val , 'unknown-clients' ) === ( strlen ( $val ) - strlen ( 'unknown-clients' ))) {
$return = substr ( $val , 0 , ( strlen ( $val ) - strlen ( 'unknown-clients' ) - 1 ));
break ;
}
}
}
return $return ;
}
2017-02-19 08:14:11 +00:00
2013-08-31 09:33:45 +00:00
/**
* Sets the unknown clients option .
2017-02-19 08:14:11 +00:00
*
2013-08-31 09:33:45 +00:00
* @ param String $option allow / deny
*/
private function setUnknownClients ( $option ) {
2018-11-11 18:56:15 +00:00
if ( ! isset ( $this -> attributes [ 'dhcpStatements' ])) {
2013-08-31 09:33:45 +00:00
$this -> attributes [ 'dhcpStatements' ] = array ();
}
for ( $i = 0 ; $i < sizeof ( $this -> attributes [ 'dhcpStatements' ]); $i ++ ) {
$val = $this -> attributes [ 'dhcpStatements' ][ $i ];
if ( strpos ( $val , 'unknown-clients' ) === ( strlen ( $val ) - strlen ( 'unknown-clients' ))) {
unset ( $this -> attributes [ 'dhcpStatements' ][ $i ]);
$this -> attributes [ 'dhcpStatements' ] = array_values ( $this -> attributes [ 'dhcpStatements' ]);
}
}
if ( ! empty ( $option ) && ( $option != '-' )) {
$this -> attributes [ 'dhcpStatements' ][] = $option . ' unknown-clients' ;
}
}
2009-01-03 19:05:16 +00:00
/**
* Returns the maximum lease time .
2017-02-19 08:14:11 +00:00
*
2009-01-03 19:05:16 +00:00
* @ return String time
*/
private function getMaxLeaseTime () {
$return = null ;
2018-11-11 18:56:15 +00:00
if ( ! empty ( $this -> attributes [ 'dhcpStatements' ])) {
2009-01-03 19:05:16 +00:00
for ( $i = 0 ; $i < sizeof ( $this -> attributes [ 'dhcpStatements' ]); $i ++ ) {
if ( substr ( $this -> attributes [ 'dhcpStatements' ][ $i ], 0 , 15 ) == 'max-lease-time ' ) {
$return = substr ( $this -> attributes [ 'dhcpStatements' ][ $i ], 15 );
break ;
}
}
}
return $return ;
}
2017-02-19 08:14:11 +00:00
2009-01-03 19:05:16 +00:00
/**
* Sets the maximum lease time .
2017-02-19 08:14:11 +00:00
*
2009-11-24 18:55:22 +00:00
* @ param String $time time
2009-01-03 19:05:16 +00:00
*/
private function setMaxLeaseTime ( $time ) {
if ( ! is_array ( $this -> attributes [ 'dhcpStatements' ])) {
$this -> attributes [ 'dhcpStatements' ] = array ();
}
for ( $i = 0 ; $i < sizeof ( $this -> attributes [ 'dhcpStatements' ]); $i ++ ) {
if ( substr ( $this -> attributes [ 'dhcpStatements' ][ $i ], 0 , 15 ) == 'max-lease-time ' ) {
unset ( $this -> attributes [ 'dhcpStatements' ][ $i ]);
$this -> attributes [ 'dhcpStatements' ] = array_values ( $this -> attributes [ 'dhcpStatements' ]);
}
}
if (( $time != null ) && ( $time != '' )) {
$this -> attributes [ 'dhcpStatements' ][] = 'max-lease-time ' . $time ;
}
}
2017-02-19 08:14:11 +00:00
2009-03-24 19:51:13 +00:00
/**
2017-05-20 09:46:49 +00:00
* { @ inheritDoc }
* @ see baseModule :: build_uploadAccounts ()
*/
function build_uploadAccounts ( $rawAccounts , $ids , & $partialAccounts , $selectedModules , & $type ) {
2009-03-24 19:51:13 +00:00
$messages = array ();
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 " ;
// subnet
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 , $i );
$messages [] = $error ;
}
// domain name
if ( $rawAccounts [ $i ][ $ids [ 'dhcp_settings_domainName' ]] != " " ) {
2013-01-05 15:14:12 +00:00
if ( preg_match ( " /^[A-Za-z0-9 \\ ._-]* $ / " , $rawAccounts [ $i ][ $ids [ 'dhcp_settings_domainName' ]])) {
2009-03-24 19:51:13 +00:00
$partialAccounts [ $i ][ 'dhcpOption' ][] = " domain-name \" " . $rawAccounts [ $i ][ $ids [ 'dhcp_settings_domainName' ]] . " \" " ;
}
else {
$error = $this -> messages [ 'domainname' ][ 5 ];
array_push ( $error , $i );
$messages [] = $error ;
}
}
// lease time
if ( $rawAccounts [ $i ][ $ids [ 'dhcp_settings_leaseTime' ]] != '' ) {
if ( is_numeric ( $rawAccounts [ $i ][ $ids [ 'dhcp_settings_leaseTime' ]])) {
$partialAccounts [ $i ][ 'dhcpStatements' ][] = 'default-lease-time ' . $rawAccounts [ $i ][ $ids [ 'dhcp_settings_leaseTime' ]];
}
else {
$error = $this -> messages [ 'lease_time' ][ 1 ];
array_push ( $error , $i );
$messages [] = $error ;
}
}
// max lease time
if ( $rawAccounts [ $i ][ $ids [ 'dhcp_settings_maxLeaseTime' ]] != '' ) {
if ( is_numeric ( $rawAccounts [ $i ][ $ids [ 'dhcp_settings_maxLeaseTime' ]])) {
$partialAccounts [ $i ][ 'dhcpStatements' ][] = 'max-lease-time ' . $rawAccounts [ $i ][ $ids [ 'dhcp_settings_maxLeaseTime' ]];
}
else {
$error = $this -> messages [ 'max_lease_time' ][ 1 ];
array_push ( $error , $i );
$messages [] = $error ;
}
}
// DNS
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 ;
}
}
if ( ! $invalid ) {
$partialAccounts [ $i ][ 'dhcpOption' ][] = 'domain-name-servers ' . $rawAccounts [ $i ][ $ids [ 'dhcp_settings_DNSserver' ]];
}
else {
$error = $this -> messages [ 'dns' ][ 1 ];
array_push ( $error , $i );
$messages [] = $error ;
}
}
2018-11-25 13:51:03 +00:00
// search domains
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 . '"' ;
}
}
if ( ! $invalid ) {
$partialAccounts [ $i ][ 'dhcpOption' ][] = 'domain-search ' . implode ( ', ' , $domains );
}
else {
$error = $this -> messages [ 'INFO_domain-search' ][ 1 ];
array_push ( $error , $i );
$messages [] = $error ;
}
}
2009-03-24 19:51:13 +00:00
// gateway
if ( $rawAccounts [ $i ][ $ids [ 'dhcp_settings_gateway' ]] != '' ) {
if ( check_ip ( $rawAccounts [ $i ][ $ids [ 'dhcp_settings_gateway' ]])) {
$partialAccounts [ $i ][ 'dhcpOption' ][] = " routers " . $rawAccounts [ $i ][ $ids [ 'dhcp_settings_gateway' ]];
}
else {
$error = $this -> messages [ 'routers' ][ 1 ];
array_push ( $error , $i );
$messages [] = $error ;
}
}
// netbios name servers
if ( $rawAccounts [ $i ][ $ids [ 'dhcp_settings_netbiosServer' ]] != '' ) {
$ex = explode ( " , " , $rawAccounts [ $i ][ $ids [ 'dhcp_settings_netbiosServer' ]]);
$invalid = false ;
foreach ( $ex AS $string ) {
2013-02-24 11:46:11 +00:00
if ( ! check_ip ( $string ) && ! get_preg ( $string , 'DNSname' )) {
2009-03-24 19:51:13 +00:00
$invalid = true ;
}
}
if ( ! $invalid ) {
$partialAccounts [ $i ][ 'dhcpOption' ][] = " netbios-name-servers " . $rawAccounts [ $i ][ $ids [ 'dhcp_settings_netbiosServer' ]];
}
else {
$error = $this -> messages [ 'netbios' ][ 1 ];
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 ( $rawAccounts [ $i ][ $ids [ 'dhcp_settings_netbiosType' ]] == 'B' ) {
$partialAccounts [ $i ][ 'dhcpOption' ][] = " netbios-node-type 1 " ;
}
elseif ( $rawAccounts [ $i ][ $ids [ 'dhcp_settings_netbiosType' ]] == 'P' ) {
$partialAccounts [ $i ][ 'dhcpOption' ][] = " netbios-node-type 2 " ;
}
elseif ( $rawAccounts [ $i ][ $ids [ 'dhcp_settings_netbiosType' ]] == 'M' ) {
$partialAccounts [ $i ][ 'dhcpOption' ][] = " netbios-node-type 4 " ;
}
elseif ( $rawAccounts [ $i ][ $ids [ 'dhcp_settings_netbiosType' ]] == 'H' ) {
$partialAccounts [ $i ][ 'dhcpOption' ][] = " netbios-node-type 8 " ;
}
}
else {
$error = $this -> messages [ 'netbios_node_type' ][ 1 ];
array_push ( $error , $i );
$messages [] = $error ;
}
}
else {
$partialAccounts [ $i ][ 'dhcpOption' ][] = " netbios-node-type 8 " ; // default H
}
2013-08-31 09:33:45 +00:00
// unknown clients
if ( ! empty ( $rawAccounts [ $i ][ $ids [ 'dhcp_settings_unknownClients' ]])) {
$unknownClients = $rawAccounts [ $i ][ $ids [ 'dhcp_settings_unknownClients' ]];
if ( in_array ( $unknownClients , $this -> allowDenyOptions )) {
$allowDenyOptions = array_flip ( $this -> allowDenyOptions );
$partialAccounts [ $i ][ 'dhcpStatements' ][] = $allowDenyOptions [ $unknownClients ] . ' unknown-clients' ;
}
else {
$error = $this -> messages [ 'unknownClients' ][ 0 ];
array_push ( $error , $i );
$messages [] = $error ;
}
}
2009-03-24 19:51:13 +00:00
// subnet mask
if ( check_ip ( $rawAccounts [ $i ][ $ids [ 'dhcp_settings_subnetMask' ]], true )) {
$partialAccounts [ $i ][ 'dhcpOption' ][] = " subnet-mask " . $rawAccounts [ $i ][ $ids [ 'dhcp_settings_subnetMask' ]];
}
else {
$error = $this -> messages [ 'subnet' ][ 1 ];
array_push ( $error , $i );
$messages [] = $error ;
}
// net mask
$mask = $this -> calculateNetMask ( $rawAccounts [ $i ][ $ids [ 'dhcp_settings_subnetMask' ]]);
$partialAccounts [ $i ][ 'dhcpNetMask' ][ 0 ] = $mask ;
2009-05-11 16:33:48 +00:00
// description
if ( isset ( $rawAccounts [ $i ][ $ids [ 'dhcp_settings_description' ]]) && ( $rawAccounts [ $i ][ $ids [ 'dhcp_settings_description' ]] != '' )) {
$partialAccounts [ $i ][ 'dhcpComments' ][ 0 ] = $rawAccounts [ $i ][ $ids [ 'dhcp_settings_description' ]];
}
2009-03-24 19:51:13 +00:00
}
return $messages ;
}
2017-04-22 09:57:57 +00:00
/**
* Returns if the current DN is the root entry .
*
* @ return bool is root
*/
private function isRootNode () {
$rootSuffix = $this -> getAccountContainer () -> get_type () -> getSuffix ();
return $this -> getAccountContainer () -> dn_orig == $rootSuffix ;
}
2009-01-03 19:05:16 +00:00
2008-09-24 16:38:27 +00:00
}
2009-01-03 19:05:16 +00:00
2008-12-29 17:22:06 +00:00
?>