diff --git a/gosa-plugins/systems/admin/systems/class_termDNS.inc b/gosa-plugins/systems/admin/systems/class_termDNS.inc
index 58d9a23a2d59eb13417237478e2f3fb96a574d1f..c3806820105ab012dc51e1928edf2d20c0de74eb 100644 (file)
var $dnsEntry = array();
var $DNSenabled = false;
var $hide_dns_check_box = FALSE;
+ var $namingAttr = "cn";
/* Terminal dns
*/
- function termDNS (&$config, $parent,$objectClasses,$IPisMust = false)
+ function termDNS (&$config, $parent,$objectClasses,$IPisMust = false,$namingAttr = "cn")
{
/* We need to know which objectClasses are used, to store the ip/mac
* Because of different type of devices
$this->parent = $parent;
$this->objectclasses = $objectClasses;
$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['cn'][0])){
- $this->OrigCn = preg_replace("/\\\$\$/","",$this->attrs['cn'][0]);
- $this->cn = preg_replace("/\\\$\$/","",$this->attrs['cn'][0]);
+ if(isset($this->attrs[$namingAttr][0])){
+ $this->OrigCn = preg_replace("/\\\$\$/","",$this->attrs[$namingAttr][0]);
+ $this->cn = preg_replace("/\\\$\$/","",$this->attrs[$namingAttr][0]);
}
/* Create list of additional ipHostNumber.
************/
/* Hide all dhcp specific code, if dhcp plugin is not present in config */
- $dhcpEnabled = FALSE;
+ $this->dhcpEnabled = FALSE;
if($this->config->search("servdhcp","class",array("tabs"))){
$this->dhcpEnabled = TRUE;
}
*/
$this->dnsEntry = DNS::getDNSHostEntries($config,$this->OrigCn);
+ $ptr = DNS::FlipIp($this->get_pTRRecord());
+
/* Remove A record which equals $this->ipHostNumber
*/
- $ptr = $this->get_pTRRecord();
foreach($this->dnsEntry['RECORDS'] as $key => $rec){
if(($rec['type'] == "aRecord") && ($rec['value'] == $this->ipHostNumber)){
unset($this->dnsEntry['RECORDS'][$key]);
function netmaskIsCoherent($idZone)
{
- $netmask = DNS::FlipIp(str_replace(".in-addr.arpa","",DNS::getNameFromMix($idZone)));
+ $netmask = DNS::FlipIp(str_replace(".in-addr.arpa.","",DNS::getNameFromMix($idZone)));
if(!strstr($this->ipHostNumber, $netmask)){
return false;
}else{
{
/* Call parent execute */
$smarty= get_smarty();
+ $smarty->assign("autonetACL",$this->acl_is_writeable("macAddress") && $this->acl_is_writeable("ipHostNumber")?"rw":"");
$tmp = $this->plInfo();
foreach($tmp['plProvidedAcls'] as $name => $translation){
$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)){
if(isset($_POST['propose_ip']) && $this->acl_is_writeable("ipHostNumber")){
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);
+ $net = DNS::FlipIp(str_replace(".in-addr.arpa.","",DNS::getNameFromMix($key)));
+ $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 */
$smarty->assign("changeStateForRecords",$changeStateForRecords);
$smarty->assign("staticAddress","<font class=\"must\">*</font>");
- $smarty->assign("autonetACL",$this->acl_is_writeable("macAddress").$this->acl_is_writeable("ipHostNumber"));
+ $smarty->assign("autonetACL",$this->acl_is_writeable("macAddress") && $this->acl_is_writeable("ipHostNumber")?"rw":"");
$display.= $smarty->fetch(get_template_path('network.tpl', TRUE));
}
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 */
}
/* Check if value has changed */
if(isset($_POST['RecordValue_'.$key])){
- $this->dnsEntry['RECORDS'][$key]['value'] = $_POST['RecordValue_'.$key];
+ $this->dnsEntry['RECORDS'][$key]['value'] = get_post('RecordValue_'.$key);
}
}
}
/* 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);
}
}
}
$this->attrs['ipHostNumber'][] = $value;
}
+ /* Do not add the objectClass ipHost if no ip address is given */
+ if(!isset($this->attrs['ipHostNumber'])){
+ $this->attrs['objectClass'] = array_remove_entries(array("ipHost"),$this->attrs['objectClass']);
+ }
+
/* Write back to ldap */
$ldap->cd($this->dn);
$this->cleanup();
$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();
if(count($this->dhcpHostEntry['dhcpOption']) == 0){
$this->dhcpHostEntry['dhcpOption']= array("host-name ".$this->cn);
}
+ }else{
+
+ // Updated Host-Name entry
+ foreach($this->dhcpHostEntry['dhcpOption'] as $key => $entry){
+ if(preg_match("/^host-name/", $entry)){
+ $this->dhcpHostEntry['dhcpOption'][$key] = "host-name ".$this->cn;
+ break;
+ }
+ }
}
/* Write mac address to dhcp settings */
}
/* Updated IP host number */
- if($this->dhcp_is_Account){
+ if($this->dhcp_is_Account && $this->dhcpHostEntry['dhcpStatements']){
foreach($this->dhcpHostEntry['dhcpStatements'] as $id => $value){
if(preg_match("/^fixed-address/",$value)){
$this->dhcpHostEntry['dhcpStatements'][$id] = "fixed-address ".$this->ipHostNumber;
if(($this->initial_dhcpParentNode != $this->dhcpParentNode) ||
($this->cn != $this->OrigCn)){
$attrs = $this->dhcpHostEntry;
- $attrs['cn'] = $this->cn;
+ $attrs[$this->namingAttr] = $this->cn;
unset($attrs['dn']);
unset($attrs['MODIFIED']);
$ldap->cd("cn=".$this->cn.",".$this->dhcpParentNode);
$this->dnsEntry['exists'] = $this->DNS_is_account;
$tmp = DNS::getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn);
}
+
+ /* Update SOA record if needed
+ */
+ $this->updateSOARecord();
/* move follwoing entries
*/
$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);
}
{
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
- $ldap->search ("(&(objectClass=dhcpHost)(cn=".$this->cn."))",array("cn","dn"));
+ $ldap->search ("(&(objectClass=dhcpHost)(cn=".$this->cn."))",array("uid","cn","dn"));
if($ldap->count()){
$attr = $ldap->fetch();
function get_dhcp_parent_node()
{
- return(preg_replace("/^cn=".normalizePreg($this->cn).",/","",$this->get_dhcp_host_entry_dn()));
+ return(preg_replace("/^cn=".preg_quote($this->cn, '/').",/","",$this->get_dhcp_host_entry_dn()));
}
$attrs = $ldap->fetch();
$tmp = array_flip($this->Zones);
$tmp = preg_replace("/^[^\/]*+\//","",$tmp[$this->dnsEntry['zoneName']]);
- $tmp = trim(preg_replace("/\.in-addr.arpa$/","",$tmp));
- $ptr = preg_replace("/^".normalizePreg(DNS::FlipIp($tmp))."\./","",$this->ipHostNumber);
+ $tmp = trim(preg_replace("/\.in-addr.arpa\.$/","",$tmp));
+ $ptr = preg_replace("/^".preg_quote(DNS::FlipIp($tmp), '/')."\./","",$this->ipHostNumber);
return($ptr);
}else{
return(FALSE);
{
$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;
+ }
+
+ // 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($str);
+
+ return(implode(".",$ip_data));
}
$ret = array();
foreach($arr as $r => $name){
$base_part = str_replace($base,"",$r);
- if(preg_match("/^[a-z]*=".normalizePreg($name)."(|,)$/i",$base_part)){
+ if(preg_match("/^[a-z]*=".preg_quote($name, '/')."(|,)$/i",$base_part)){
$ret[$r] = $current.$name;
$tmp = $this->create_tree($arr,$r,$current.". ");
foreach($tmp as $sub_key => $sub_name){
}
}
}
+
+ function updateSOARecord()
+ {
+ $oldEntries = DNS::getDNSHostEntries($this->config,$this->OrigCn);
+ $newEntries = $this->dnsEntry;
+ if(array_differs($newEntries['RECORDS'],$oldEntries['RECORDS'])){
+ DNS::touchDNSZone($this->config,$this->dnsEntry['zoneName']);
+ }
+ }
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: