new){
$this->dhcpRange= $attrs['dhcpRange'][0];
list($this->range_start, $this->range_stop)= preg_split('/\s+/', $this->dhcpRange);
}
$this->advanced->setAutoOptions(array("host-name"));
$this->advanced->setAutoStatements(array("fixed-address"));
}
function execute()
{
$smarty= get_smarty();
$smarty->assign("cn", $this->cn);
$smarty->assign("range_start", $this->range_start);
$smarty->assign("range_stop", $this->range_stop);
/* Show main page */
$display= $smarty->fetch(get_template_path('dhcp_pool.tpl', TRUE)).$this->network->execute();
/* Merge arrays for advanced view */
$this->fix_options();
foreach (array("options", "statements") as $type){
$this->advanced->$type= $this->$type + $this->network->$type;;
}
$display.= $this->advanced->execute();
/* Merge back for removals */
foreach (array("options", "statements") as $type){
$this->$type= $this->advanced->$type;
$this->network->$type= $this->advanced->$type;
}
/* Add footer */
$display.= "
".
"
";
return ($display);
}
function remove_from_parent()
{
}
/* Save data to object */
function save_object()
{
if (isset($_POST['cn'])){
$this->cn= validate(get_post('cn'));
$this->range_start= validate(get_post('range_start'));
$this->range_stop= validate(get_post('range_stop'));
}
dhcpPlugin::save_object();
/* Move range to internal variable */
$this->dhcpRange= $this->range_start." ".$this->range_stop;
}
/* Check values */
function check($cache)
{
$message= array();
/* All required fields are set? */
if ($this->cn == ""){
$message[]= _("Required field 'Name' is not filled.");
}
/* cn already used? */
if ($this->orig_cn != $this->cn || $this->new){
foreach($cache as $dn => $dummy){
if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){
$message[]= _("The name for this section is already used!");
break;
}
}
}
if ($this->dhcpRange == ""){
$message[]= _("Required field 'Range' is not filled.");
}
if (!is_ip($this->range_start) || !is_ip($this->range_stop)){
$message[]= _("Field 'Range' contains invalid IP addresses.");
}
if(!is_ip_range($this->range_start,$this->range_stop)){
$message[] = _("Field 'Range' contains invalid IP range.");
}
/* Check if range is in the network */
$dn= $this->dn;
while (preg_match('/,/', $dn)){
$type= $this->objectType($cache, $dn);
/* Check for subnet */
if ($type == 'dhcpSubnet'){
$network= $cache[$dn]['cn'][0];
$netmask= normalize_netmask($cache[$dn]['dhcpNetMask'][0]);
if (!is_in_network($network, $netmask, $this->range_start) ||
!is_in_network($network, $netmask, $this->range_stop)){
$message[] = _("'Range' is not inside the configured network.");
}
}
/* Stop if we've examined the service base object */
if ($type == 'dhcpService'){
break;
}
$dn= preg_replace('/^[^,]+,/', '', $dn);
}
/* Check external plugins */
$net= $this->network->check();
$adv= $this->advanced->check();
$message= array_merge($message, $net, $adv);
return $message;
}
/* Save to LDAP */
function save()
{
dhcpPlugin::save();
$this->attrs['dhcpRange']= array($this->dhcpRange);
return ($this->attrs);
}
function objectType($cache, $dn)
{
$type= "";
$types= array("dhcpService", "dhcpClass", "dhcpSubClass", "dhcpHost",
"dhcpGroup", "dhcpPool", "dhcpSubnet", "dhcpSharedNetwork");
foreach ($cache[$dn]['objectClass'] as $oc){
if (in_array($oc, $types)){
$type= $oc;
break;
}
}
return ($type);
}
}
?>