diff --git a/gosa-plugins/systems/admin/systems/class_termDNS.inc b/gosa-plugins/systems/admin/systems/class_termDNS.inc
index c31dbeba919b1b916e3233e62d596d71710e544a..e336feb26d3a41f1d1dea274113d832a83b58b72 100644 (file)
$this->IPisMust = $IPisMust;
$this->namingAttr = $namingAttr;
- plugin::plugin ($config, $parent->dn);
+ plugin::plugin ($config, $parent->dn, $this->parent);
+
+ $this->attrs = &$this->parent->attrs;
if(isset($this->attrs[$namingAttr][0])){
$this->OrigCn = preg_replace("/\\\$\$/","",$this->attrs[$namingAttr][0]);
$this->dialog->read_only = !$this->acl_is_writeable("dhcpSetup");
$this->dialog->dhcpHWAddress = "ethernet ".$this->macAddress;
if(!empty($this->ipHostNumber)){
- $this->dialog->statements['fixed-address'] = $this->ipHostNumber;
+ $this->dialog->statements->set('fixed-address', $this->ipHostNumber);
}
}
$this->dialog = FALSE;
}
- if(isset($_POST['save_dhcp']) && $this->acl_is_writeable("dhcpSetup")){
+ if(isset($_POST['save_dhcp']) && $this->acl_is_writeable("dhcpSetup") && is_object($this->dialog)){
$this->dialog->save_object();
$msgs = $this->dialog->check(array());
if(count($msgs)){
foreach($this->Zones as $key => $name){
if($name == $this->dnsEntry['zoneName']){
$net = DNS::FlipIp(str_replace(".in-addr.arpa","",DNS::getNameFromMix($key)));
- $this->ipHostNumber = $this->generateRandomIp($net);
+ $this->ipHostNumber = $this->generateRandomIP($net);
}
}
}
/* Assign smarty all DNS attributes */
foreach($this->DNSattributes as $attr){
- $smarty->assign($attr,$this->dnsEntry[$attr]);
+ $smarty->assign($attr,htmlentities($this->dnsEntry[$attr]));
}
/* Assign all needed vars */
DNS posts
******/
- /* Check if DNS should be enabled / disabled */
- if($this->DNS_is_account && $this->acl_is_writeable("dnsSetup") && !isset($_POST['DNS_is_account'])){
- $this->DNS_is_account = false;
- }elseif(!$this->DNS_is_account && $this->acl_is_writeable("dnsSetup") && isset($_POST['DNS_is_account'])){
- $this->DNS_is_account = true;
+ /* Check if DNS should be enabled / disabled
+ * -skip this, if the dns account is enforced.
+ */
+ if(!$this->hide_dns_check_box){
+ if($this->DNS_is_account && $this->acl_is_writeable("dnsSetup") && !isset($_POST['DNS_is_account'])){
+ $this->DNS_is_account = false;
+ }elseif(!$this->DNS_is_account && $this->acl_is_writeable("dnsSetup") && isset($_POST['DNS_is_account'])){
+ $this->DNS_is_account = true;
+ }
}
/* Get dns attributes */
/* Get all basic DNS attributes (TTL, Clas ..)*/
foreach($this->DNSattributes as $attr){
if(isset($_POST[$attr])){
- $this->dnsEntry[$attr] = $_POST[$attr];
+ $this->dnsEntry[$attr] = get_post($attr);
}
}
}
}
/* Do not add the objectClass ipHost if no ip address is given */
- if(!$this->attrs['ipHostNumber']){
+ if(!isset($this->attrs['ipHostNumber'])){
$this->attrs['objectClass'] = array_remove_entries(array("ipHost"),$this->attrs['objectClass']);
}
$this->dialog->cn = $this->cn;
$this->dialog->dhcpHWAddress = "ethernet ".$this->macAddress;
if(!empty($this->ipHostNumber)){
- $this->dialog->statements['fixed-address'] = $this->ipHostNumber;
+ $this->dialog->statements->set('fixed-address', $this->ipHostNumber);
}
$this->dialog->execute();
$this->dialog->save_object();
$str.=" <tr>".
" <td>".$this->generateRecordListBox($entry['type'],"RecordTypeSelectedFor_".$key)."</td>".
- " <td><input type='text' value='".$entry['value']."' name='RecordValue_".$key."' id='RecordValue_".$key."'></td>".
+ " <td><input type='text' value=\"".htmlentities($entry['value'])."\" name='RecordValue_".$key."' id='RecordValue_".$key."'></td>".
" <td><input type='submit' name='RemoveRecord_".$key."' value='"._("Delete")."' id='RemoveRecord_".$key."'></td>".
"</tr>";
}
" </tr>".
"</table>";
$ret = array("str" => $str, "changeStateForRecords" => $changeStateForRecords);
+
return($ret);
}
{
$str = $net;
$cnt = 4;
- while(substr_count($str,".") < 3 && $cnt > 0){
- $str .= ".".rand(0,255);
- $str = preg_replace("/\.\.*/",".",$str);
- $str = trim($str,". ");
- $cnt --;
+
+ // first gather all IPs
+ $ldap = $this->config->get_ldap_link();
+ $ocs =
+ "(objectClass=goFonHardware)".
+ "(objectClass=goServer)".
+ "(objectClass=GOhard)".
+ "(objectClass=gotoTerminal)".
+ "(objectClass=gotoWorkstation)".
+ "(objectClass=gotoPrinter)".
+ "(objectClass=ipHost)";
+ $list = array();
+ $ldap->search("(&(|{$ocs})(ipHostNumber=*))",array("ipHostNumber"));
+ while($attrs = $ldap->fetch()){
+ if (preg_match("/^$net\./", $attrs['ipHostNumber'][0])) {
+ $list[] = $attrs['ipHostNumber'][0];
+ }
+ }
+
+ // Set starting ip.
+ $ip_data = preg_split("/\./",$net);
+ for($i=0;$i<4;$i++){
+ if(!isset($ip_data[$i])) $ip_data[$i] = 0;
}
- return($str);
+
+ // Search the next free and valid ip.
+ while(in_array(implode(".",$ip_data),$list) || $ip_data[3] <= 1){
+ $ip_data[3] ++ ;
+ if($ip_data[3] > 255){
+ $ip_data[3] = 1 ;
+ $ip_data[2] ++ ;
+ }
+ if($ip_data[2] > 255){
+ $ip_data[2] = 1 ;
+ $ip_data[1] ++ ;
+ }
+ if($ip_data[1] > 255){
+ $ip_data[1] = 1 ;
+ $ip_data[0] ++ ;
+ }
+ if($ip_data[0] > 255) break;
+ }
+
+ return(implode(".",$ip_data));
}