From 48348bafba5024852a29cddf83d7ab9ec36b9d5c Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 20 Oct 2011 16:43:42 +0000 Subject: [PATCH] client-side validation --- lam/lib/modules/dhcp_settings.inc | 12 ++++++++---- lam/lib/modules/fixed_ip.inc | 14 +++++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lam/lib/modules/dhcp_settings.inc b/lam/lib/modules/dhcp_settings.inc index a477d1b1..c656644b 100644 --- a/lam/lib/modules/dhcp_settings.inc +++ b/lam/lib/modules/dhcp_settings.inc @@ -4,7 +4,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) Copyright (C) 2008 Thomas Manninger - 2008 - 2010 Roland Gruber + 2008 - 2011 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 @@ -346,7 +346,7 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I elseif (!check_ip($_POST['cn'],true)) { $errors[] = $this->messages['cn'][2]; } - elseif (array_pop(explode(".", $_POST['cn']))!=0) { + elseif (strrpos($_POST['cn'], '.0') != (strlen($_POST['cn']) - 2)) { $errors[] = $this->messages['cn'][2]; } else { @@ -523,9 +523,13 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I // domain name $return->addElement(new htmlTableExtendedInputField(_('Domain name'), 'domainname', $this->getDHCPOption('domain-name'), 'domainname'), true); // lease Time - $return->addElement(new htmlTableExtendedInputField(_('Lease time'), 'lease_time', $this->getDefaultLeaseTime(), 'leasetime'), true); + $leasetimeInput = new htmlTableExtendedInputField(_('Lease time'), 'lease_time', $this->getDefaultLeaseTime(), 'leasetime'); + $leasetimeInput->setValidationRule(htmlElement::VALIDATE_NUMERIC); + $return->addElement($leasetimeInput, true); // max lease time - $return->addElement(new htmlTableExtendedInputField(_('Maximum lease time'), 'max_lease_time', $this->getMaxLeaseTime(), 'max_leasetime'), true); + $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); // DNS $return->addElement(new htmlTableExtendedInputField(_('DNS'), 'dns', $this->getDHCPOption('domain-name-servers'), 'dns'), true); // gateway diff --git a/lam/lib/modules/fixed_ip.inc b/lam/lib/modules/fixed_ip.inc index 7a02694f..414c093c 100644 --- a/lam/lib/modules/fixed_ip.inc +++ b/lam/lib/modules/fixed_ip.inc @@ -4,7 +4,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) Copyright (C) 2008 Thomas Manninger - 2008 - 2010 Roland Gruber + 2008 - 2011 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 @@ -205,13 +205,17 @@ class fixed_ip extends baseModule { if ($this->getAccountContainer()->dn_orig!=$_SESSION['config']->get_suffix('dhcp')) { $entries = searchLDAP($this->getAccountContainer()->dn_orig, '(objectClass=dhcpHost)', array('cn', 'dhcphwaddress', 'dhcpstatements')); for ($i=0; $i < sizeof($entries); $i++) { + $dhcphwaddress = explode(" ", $entries[$i]['dhcphwaddress'][0]); + $dhcphwaddress = array_pop($dhcphwaddress); + $dhcpstatements = explode(" ", $entries[$i]['dhcpstatements'][0]); + $dhcpstatements = array_pop($dhcpstatements); $this->fixed_ip[$i]['cn'] = $entries[$i]['cn'][0]; - $this->fixed_ip[$i]['mac'] = array_pop(explode(" ", $entries[$i]['dhcphwaddress'][0])); - $this->fixed_ip[$i]['ip'] = array_pop(explode(" ", $entries[$i]['dhcpstatements'][0])); + $this->fixed_ip[$i]['mac'] = $dhcphwaddress; + $this->fixed_ip[$i]['ip'] = $dhcpstatements; $this->orig_ips[$i]['cn'] = $entries[$i]['cn'][0]; - $this->orig_ips[$i]['mac'] = array_pop(explode(" ", $entries[$i]['dhcphwaddress'][0])); - $this->orig_ips[$i]['ip'] = array_pop(explode(" ", $entries[$i]['dhcpstatements'][0])); + $this->orig_ips[$i]['mac'] = $dhcphwaddress; + $this->orig_ips[$i]['ip'] = $dhcpstatements; } } }