diff --git a/gosa-plugins/systems/admin/systems/class_termDNS.inc b/gosa-plugins/systems/admin/systems/class_termDNS.inc
index 06cb3ada7f8cd9242a017dd163edbc679aca2787..e336feb26d3a41f1d1dea274113d832a83b58b72 100644 (file)
/* DNS attributes
*/
- var $DNSattributes = array("dNSClass","zoneName","dNSTTL");
+ var $DNSattributes = array("zoneName","dNSTTL");
var $DNS_is_account = false;
var $initially_was_account = false;
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;
}
+
+ if(!class_available("dhcpHost")){
+ $this->dhcpEnabled = FALSE;
+ }
+
if($this->dhcpEnabled){
$this->dhcpParentNodes = $this->get_dhcp_parent_nodes();
$this->dhcpParentNode = $this->get_dhcp_parent_node();
$this->DNSenabled = true;
}
}
+
+ if(!class_available("DNS")){
+ $this->DNSenabled = FALSE;
+ }
+
if(!$this->DNSenabled){
$this->DNS_is_account = false;
return;
over the whole ldap server was 10 to 20 times slower.
*/
$deps = array();
- $ou = preg_replace("/,.*$/","",get_ou("systemsou"));
- $a_ous = array(get_ou("serverou"),
- get_ou("terminalou"),
- get_ou("workstationou"),
- get_ou("printerou"),
- get_ou("phoneou"),
- get_ou("componentou"));
+ $ou = preg_replace("/,.*$/","",get_ou("systemRDN"));
+ $a_ous = array(get_ou("serverRDN"),
+ get_ou("terminalRDN"),
+ get_ou("workstationRDN"),
+ get_ou("printerRDN"),
+ get_ou("phoneRDN"),
+ get_ou("componentRDN"));
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
{
/* Call parent execute */
$smarty= get_smarty();
+ $smarty->assign("autonetACL",$this->acl_is_writeable("macAddress").$this->acl_is_writeable("ipHostNumber"));
$tmp = $this->plInfo();
foreach($tmp['plProvidedAcls'] as $name => $translation){
**********/
/* Add a new one */
- foreach($_POST as $name => $value){
- if(preg_match("/^additionalHostNumbers_add/",$name)){
- $this->additionalHostNumbers[] = "";
- break;
- }
-
- /* Delete given entry */
- if(preg_match("/^additionalHostNumbers_del_/",$name)){
- $id = preg_replace("/^^additionalHostNumbers_del_([0-9]*)_.*/","\\1",$name);
- if(isset($this->additionalHostNumbers[$id])){
- unset($this->additionalHostNumbers[$id]);
- $this->additionalHostNumbers = array_values($this->additionalHostNumbers);
+ if($this->acl_is_writeable("ipHostNumber")){
+ foreach($_POST as $name => $value){
+ if(preg_match("/^additionalHostNumbers_add/",$name)){
+ $this->additionalHostNumbers[] = "";
+ break;
}
- break;
- }
+
+ /* Delete given entry */
+ if(preg_match("/^additionalHostNumbers_del_/",$name)){
+ $id = preg_replace("/^^additionalHostNumbers_del_([0-9]*)_.*/","\\1",$name);
+ if(isset($this->additionalHostNumbers[$id])){
+ unset($this->additionalHostNumbers[$id]);
+ $this->additionalHostNumbers = array_values($this->additionalHostNumbers);
+ }
+ break;
+ }
+ }
}
$smarty->assign("additionalHostNumbers",$this->additionalHostNumbers);
**********/
/* Check for autonet button */
- if (isset($_POST['autonet'])){
+ if (isset($_POST['autonet']) && ($this->acl_is_writeable("ipHostNumber") || $this->acl_is_writeable("macAddress"))){
$d= new gosaSupportDaemon(TRUE, 0.5);
- $res= $d->_send("<xml><header>gosa_network_completition</header><source>GOSA</source><target>GOSA</target><hostname>".$this->cn."</hostname></xml>", TRUE);
- if (isset($res['XML']['IP'])){
+ $res= $d->_send("<xml><header>gosa_network_completition</header>".
+ "<source>GOSA</source><target>GOSA</target><hostname>".$this->cn."</hostname></xml>", TRUE);
+ if (isset($res['XML']['IP']) && $this->acl_is_writeable("ipHostNumber")){
$this->ipHostNumber= $res['XML']['IP'];
}
- if (isset($res['XML']['MAC'])){
+ if (isset($res['XML']['MAC']) && $this->acl_is_writeable("macAddress")){
$this->macAddress= $res['XML']['MAC'];
}
}
* DHCP Handling
**********/
- if(isset($_POST['dhcpEditOptions'])){
-
+ if(isset($_POST['dhcpEditOptions']) && $this->acl_is_readable("dhcpSetup")){
if(count($this->dhcpHostEntry) == 0){
- $this->dialog = new dhcpHost($this->dhcpParentNode,TRUE);
+ $this->dialog = new dhcpHost($this->parent,$this->dhcpParentNode,TRUE);
}else{
- $this->dialog = new dhcpHost($this->dhcpHostEntry,TRUE);
+ $this->dialog = new dhcpHost($this->parent,$this->dhcpHostEntry,TRUE);
}
- $this->dialog->cn = $this->cn;
+ $this->dialog->cn = $this->cn;
+ $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'])){
+ 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($msgs as $msg){
return($this->dialog->execute());
}
- $smarty->assign("dhcpEnabled", $this->dhcpEnabled);
+ $smarty->assign("dhcpEnabled", $this->dhcpEnabled && $this->acl_is_readable("dhcpSetup"));
$smarty->assign("dhcp_is_Account",$this->dhcp_is_Account);
$smarty->assign("dhcpParentNode", $this->dhcpParentNode);
$smarty->assign("dhcpParentNodes",$this->dhcpParentNodes);
$smarty->assign("dhcpParentNodeCnt",count($this->dhcpParentNodes));
-
/**********
* DNS Handling
**********/
/* There is no dns available
*/
$smarty->assign("DNS_is_account",$this->DNS_is_account);
- $smarty->assign("DNSenabled",$this->DNSenabled);
+ $smarty->assign("DNSenabled",$this->DNSenabled && $this->acl_is_readable("dnsSetup"));
+
if($this->DNSenabled == false){
/* Is IP address must ? */
# $smarty->assign("DNS_is_account",true);
/* Add new empty array to our record list */
- if(isset($_POST['AddNewRecord'])){
+ if(isset($_POST['AddNewRecord']) && $this->acl_is_writeable("dnsSetup")){
$this->dnsEntry['RECORDS'][] =array("type"=>"aRecord","value"=>"");
}
/* propose_ip */
- if(isset($_POST['propose_ip'])){
+ 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);
+ $this->ipHostNumber = $this->generateRandomIP($net);
}
}
}
/* Handle all posts */
$only_once =true;
- foreach($_POST as $name => $value){
+ if($this->acl_is_writeable("dnsSetup")){
+ foreach($_POST as $name => $value){
- /* Check if we have to delete a record entry */
- if((preg_match("/RemoveRecord_/",$name))&&($only_once)) {
+ /* Check if we have to delete a record entry */
+ if((preg_match("/RemoveRecord_/",$name))&&($only_once)) {
- /* Avoid performing this once again */
- $only_once = false;
+ /* Avoid performing this once again */
+ $only_once = false;
- /* Extract id for specified entry */
- $id = preg_replace("/RemoveRecord_/","",$name);
- $id = preg_replace("/_.*$/","",$id);
+ /* Extract id for specified entry */
+ $id = preg_replace("/RemoveRecord_/","",$name);
+ $id = preg_replace("/_.*$/","",$id);
- /* Delete this record, mark edited entries to be able to delete them */
- if(isset($this->dnsEntry['RECORDS'][$id])){
- unset($this->dnsEntry['RECORDS'][$id]);
+ /* Delete this record, mark edited entries to be able to delete them */
+ if(isset($this->dnsEntry['RECORDS'][$id])){
+ unset($this->dnsEntry['RECORDS'][$id]);
+ }
}
}
}
/* 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"));
+
$display.= $smarty->fetch(get_template_path('network.tpl', TRUE));
}
function remove_from_parent()
{
- if($this->initially_was_account){
+ if($this->DNS_is_account){
$ldap = $this->config->get_ldap_link();
/******
Additional IP Host Numbers
******/
-
+
/* Get posts for all additionally added ipHostNumbers */
- foreach($this->additionalHostNumbers as $id => $value){
- if(isset($_POST['additionalHostNumbers_'.$id])){
- $this->additionalHostNumbers[$id] = get_post('additionalHostNumbers_'.$id);
- }
+ if($this->acl_is_writeable("ipHostNumber")){
+ foreach($this->additionalHostNumbers as $id => $value){
+ if(isset($_POST['additionalHostNumbers_'.$id])){
+ $this->additionalHostNumbers[$id] = get_post('additionalHostNumbers_'.$id);
+ }
+ }
}
DHCP posts
******/
- if($this->dhcpEnabled && isset($_POST['network_tpl_posted'])){
+ if($this->acl_is_writeable("dhcpSetup") && $this->dhcpEnabled && isset($_POST['network_tpl_posted'])){
foreach($this->dhcpAttributes as $attr){
if(isset($_POST[$attr])){
$this->$attr = $_POST[$attr];
DNS posts
******/
- /* Check if DNS should be enabled / disabled */
- if($this->DNS_is_account && $this->acl_is_removeable() && !isset($_POST['DNS_is_account'])){
- $this->DNS_is_account = false;
- }elseif(!$this->DNS_is_account && $this->acl_is_createable() && 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 */
- if(($this->DNSenabled) && (isset($_POST['network_tpl_posted']))){
+ if(($this->DNSenabled) && (isset($_POST['network_tpl_posted'])) && $this->acl_is_writeable("dnsSetup")){
/* Check for posted record changes */
- if(is_array($this->dnsEntry['RECORDS']) && $this->acl_is_writeable("Records")){
+ if(is_array($this->dnsEntry['RECORDS'])){
foreach($this->dnsEntry['RECORDS'] as $key => $value){
/* Check if type has changed */
}
/* 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->acl_is_writeable($attr)){
- $this->dnsEntry[$attr] = $_POST[$attr];
+ if(isset($_POST[$attr])){
+ $this->dnsEntry[$attr] = get_post($attr);
}
}
-
-
}
if($this->hide_dns_check_box){
$this->DNS_is_account = true;
foreach($this->additionalHostNumbers as $id => $value){
if(!tests::is_ip($value)){
- $message[]= msgPool::invalid(sprintf(_("IP address #%s"),($id +2)), "", "", "192.168.1.10");
+ $message[]= msgPool::invalid(sprintf(_("IP address %s"),($id +2)), "", "", "192.168.1.10");
}
}
if(($this->IPisMust)||($this->DNS_is_account)){
if (empty($this->ipHostNumber)){
$message[]= msgPool::required(_("IP address"));
- }
-
- if (!tests::is_ip($this->ipHostNumber)){
+ }elseif (!tests::is_ip($this->ipHostNumber)){
$message[]= msgPool::invalid(_("IP address"), "", "", "192.168.1.10");
}
}
/* Check if mac is empty
*/
- if ($this->macAddress == "" ){
- $message[]= msgPool::required(_("IP address"));
- }
- if(!tests::is_mac($this->macAddress)){
- $message[]= msgPool::invalid(_("MAC address"), "", "", "00:0C:7F:31:33:F1");
+ if($this->MACisMust || $this->dhcp_is_Account){
+ if ($this->macAddress == "" ){
+ $message[]= msgPool::required(_("MAC address"));
+ }elseif(!tests::is_mac($this->macAddress)){
+ $message[]= msgPool::invalid(_("MAC address"), "", "", "00:0C:7F:31:33:F1");
+ }
}
/* only perfrom this checks if this is a valid DNS account */
/* Add all additional ipHostNumbers now
*/
- $this->attrs['ipHostNumber'] = array($this->ipHostNumber);
+ if(!empty($this->ipHostNumber)){
+ $this->attrs['ipHostNumber'] = array($this->ipHostNumber);
+ }
foreach($this->additionalHostNumbers as $value){
$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();
/****************/
/* New entry */
- if($this->dhcpEnabled){
+ if($this->dhcpEnabled && $this->acl_is_writeable("dhcpSetup")) {
if(count($this->dhcpHostEntry) == 0){
- $this->dialog = new dhcpHost($this->dhcpParentNode,TRUE);
+ $this->dialog = new dhcpHost($this->parent,$this->dhcpParentNode,TRUE);
$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();
}
/* 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);
*/
if((!$this->DNSenabled) || ((!$this->DNS_is_account)&&(!$this->initially_was_account))){
return;
- }else{
+ }elseif($this->acl_is_writeable("dnsSetup")){
/* Add ipHostNumber to aRecords
*/
$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);
}
"macAddress" => _("MAC address"))
);
- /* Hide all dns specific code, if dns is not available
+ /* Hide all dns/dhcp configurations if not available
*/
- $config = session::get('config');
- foreach($config->data['TABS']['SERVERSERVICE'] as $tab){
- if(preg_match("/^servdns$/",$tab['CLASS'])){
- $tmp['plProvidedAcls']["Records"] = _("DNS records");
- $tmp['plProvidedAcls']["zoneName"] = _("Zone name");
- $tmp['plProvidedAcls']["dNSTTL"] = _("TTL");
- break;
- }
+ if(class_available("servdns")){
+ $tmp['plProvidedAcls']["dnsSetup"] = _("DNS configuration");
+ }
+ if(class_available("servdhcp")){
+ $tmp['plProvidedAcls']["dhcpSetup"] = _("DHCP configuration");
}
return($tmp);
}
{
$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()));
}
$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);
+ $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];
+ }
}
- return($str);
+
+ // 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(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){