From: hickert Date: Mon, 22 Oct 2007 06:33:21 +0000 (+0000) Subject: Added Arp New Device handling. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=86411b920a30cecaf0e189c62c32ca7f0da1807b;p=gosa.git Added Arp New Device handling. Not working git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7610 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/admin/systems/ArpNewDevice.tpl b/plugins/admin/systems/ArpNewDevice.tpl new file mode 100644 index 000000000..8e4bf44ac --- /dev/null +++ b/plugins/admin/systems/ArpNewDevice.tpl @@ -0,0 +1,31 @@ +

{t}Integrating unknown devices{/t}

+

+ {t}The current device has been detected by the ARP monitor used by GOsa. You can integrate this device into your running DHCP/DNS infrastructure by submitting this form. The device entry will disapear from the list of the systems and move to the DNS/DHCP configuration.{/t} +

+ + + + + + + +
+ + + + + + + +
+
+

+{$netconfig} + + + +

diff --git a/plugins/admin/systems/class_ArpNewDevice.inc b/plugins/admin/systems/class_ArpNewDevice.inc new file mode 100644 index 000000000..f2d7a754c --- /dev/null +++ b/plugins/admin/systems/class_ArpNewDevice.inc @@ -0,0 +1,74 @@ +cn =""; + $this->netConfigDNS = new termDNS($this->config,$this->dn,$this->objectclasses); + $this->acl = "#all#"; + $this->netConfigDNS->acl = $this->acl; + $this->netConfigDNS->force_dns(); + } + + function execute() + { + $smarty = get_smarty(); + foreach($this->attributes as $attr){ + $smarty->assign($attr,$this->$attr); + } + $this->netConfigDNS->cn= $this->cn; + $smarty->assign("netconfig", $this->netConfigDNS->execute()); + + /* Display sub dialog from network settings */ + $this->netConfigDNS->acl = $this->acl; + if($this->netConfigDNS->dialog){ + $this->dialog = TRUE; + return($this->netConfigDNS->execute()); + }else{ + $this->dialog = FALSE; + } + + return($smarty->fetch (get_template_path('ArpNewDevice.tpl', TRUE))); + } + + function check() + { + $message= plugin::check(); + $message= array_merge($message, $this->netConfigDNS->check()); + if(empty($this->cn)){ + $message[] = _("Please specify a valid dns name."); + } + return($message); + } + + function save_object() + { + if(isset($_POST['ArpNewDevice_posted'])){ + plugin::save_object(); + $this->netConfigDNS->save_object(); + } + } + + function save() + { + $this->netConfigDNS->acl = $this->acl; + plugin::save(); + $this->netConfigDNS->cn = $this->cn; + $this->netConfigDNS->save($this->dn); + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->rmdir_recursive($this->dn); + show_ldap_error($ldap->get_error(),_("Could not remove arp-alert device after writing dns and dhcp configuration.")); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/admin/systems/class_divListSystem.inc b/plugins/admin/systems/class_divListSystem.inc index 38fe1ddbf..ce7c17a28 100644 --- a/plugins/admin/systems/class_divListSystem.inc +++ b/plugins/admin/systems/class_divListSystem.inc @@ -297,7 +297,7 @@ class divListSystem extends MultiSelectWindow /* Get system type, it is used to fetch the acls for the current object. "winstation" acls are stored as 2winworkstation", so we have to map this here */ - $type = $this->parent->get_system_type($val['objectClass']); + $type = $this->parent->get_system_type($val); if($type == "winstation") { $acl_type = "winworkstation"; }else{ @@ -305,7 +305,7 @@ class divListSystem extends MultiSelectWindow } /* Map NewDevice acls to workstation acls */ - if($type == "NewDevice"){ + if($type == "NewDevice" || $type == "ArpNewDevice"){ $type = "incoming"; $acl_type = "incoming"; } @@ -406,7 +406,10 @@ class divListSystem extends MultiSelectWindow } } - $type = $this->parent->get_system_type($val['objectClass']); + $type = $this->parent->get_system_type($val); + if($type == "ArpNewDevice"){ + $type = "NewDevice"; + } $cnts[$type] ++; diff --git a/plugins/admin/systems/class_servDNS.inc b/plugins/admin/systems/class_servDNS.inc index 4603a4394..2bc035277 100644 --- a/plugins/admin/systems/class_servDNS.inc +++ b/plugins/admin/systems/class_servDNS.inc @@ -467,8 +467,8 @@ class servdns extends goService /* Handle Post events */ if(preg_match("/^zoneName=/",$dn)){ - $this->handle_post_events("remove",array("dn" => $dn,"zoneName" => $for)); - $this->handle_post_events("remove",array("dn" => $dn,"zoneName" => $rev)); +# $this->handle_post_events("remove",array("dn" => $dn,"zoneName" => $for)); +# $this->handle_post_events("remove",array("dn" => $dn,"zoneName" => $rev)); } } @@ -490,7 +490,7 @@ class servdns extends goService /* Handle Post events */ if(preg_match("/^zoneName=/",$dn)){ - $this->handle_post_events("modify",array("dn" => $dn,"zoneName" => $attrs['zoneName'])); +# $this->handle_post_events("modify",array("dn" => $dn,"zoneName" => $attrs['zoneName'])); } }else{ $ldap->cd($dn); @@ -499,10 +499,11 @@ class servdns extends goService /* Handle Post events */ if(preg_match("/^zoneName=/",$dn)){ - $this->handle_post_events("add",array("dn" => $dn,"zoneName" => $attrs['zoneName'])); +# $this->handle_post_events("add",array("dn" => $dn,"zoneName" => $attrs['zoneName'])); } } } + $this->handle_post_events("modify"); } diff --git a/plugins/admin/systems/class_systemManagement.inc b/plugins/admin/systems/class_systemManagement.inc index aacc86281..08ffae448 100644 --- a/plugins/admin/systems/class_systemManagement.inc +++ b/plugins/admin/systems/class_systemManagement.inc @@ -309,9 +309,9 @@ class systems extends plugin /* Find out more about the object type */ $ldap= $this->config->get_ldap_link(); - $ldap->cat($this->dn, array('objectClass')); + $ldap->cat($this->dn, array('objectClass','gotoMode')); $attrs= $ldap->fetch(); - $type= $this->get_system_type($attrs['objectClass']); + $type= $this->get_system_type($attrs); /* Lock the current entry, so everyone will get the above dialog */ @@ -325,7 +325,9 @@ class systems extends plugin "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component")); - if($type == "NewDevice"){ + if($type == "ArpNewDevice"){ + $this->systab = new ArpNewDeviceTabs($this->config,$this->config->data['TABS']['ARPNEWDEVICETABS'],$this->dn); + }elseif($type == "NewDevice"){ $this->systab = new SelectDeviceType($this->config,$this->dn) ; }elseif(isset($tabs[$type])){ @@ -354,7 +356,7 @@ class systems extends plugin "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"), "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation")); - $type = $this->get_system_type($this->terminals[$s_entry]['objectClass']); + $type = $this->get_system_type($this->terminals[$s_entry]); $class = $tabs[$type]["CLASS"]; $tabname = $tabs[$type]["TABNAME"]; $acl_cat = $tabs[$type]["ACL"]; @@ -400,7 +402,7 @@ class systems extends plugin $type = ""; foreach($this->terminals as $terminal){ if($terminal['dn'] == $this->dn){ - $type = $this->get_system_type($terminal['objectClass']); + $type = $this->get_system_type($terminal); break; } } @@ -512,7 +514,7 @@ class systems extends plugin /* Get 'dn' from posted termlinst */ $attrs = $this->terminals[$key]; - $type= $this->get_system_type($attrs['objectClass']); + $type= $this->get_system_type($attrs); /* get object type */ $tabtype = "termtabs"; @@ -577,7 +579,7 @@ class systems extends plugin $this->dn = $this->terminals[$s_entry]['dn']; $attrs = $this->terminals[$s_entry]; - $type= $this->get_system_type($attrs['objectClass']); + $type= $this->get_system_type($attrs); $ui = get_userinfo(); $tabs = array( "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"), @@ -633,7 +635,7 @@ class systems extends plugin $ldap= $this->config->get_ldap_link(); $ldap->cat($this->dn, array('objectClass')); $attrs= $ldap->fetch(); - $type= $this->get_system_type($attrs['objectClass']); + $type= $this->get_system_type($attrs); $ui = get_userinfo(); @@ -958,7 +960,7 @@ class systems extends plugin } /* Attributes to fetch */ - $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName"); + $sys_attrs = array("cn", "description", "macAddress", "objectClass", "sambaDomainName","gotoMode"); $sys_categories = array("terminal", "workstation", "server", "phone" ,"printer"); /* Add FAIstate to attributes if FAI is activated */ @@ -1021,6 +1023,8 @@ class systems extends plugin $add= "- "._("New terminal"); }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){ $add= "- "._("New workstation"); + }elseif (in_array_ics('GOhard', $value['objectClass']) && !isset($value['gotoMode'])){ + $add= "- "._("Unknown device"); }elseif (in_array_ics('GOhard', $value['objectClass'])){ $add= "- "._("New Device"); } @@ -1177,7 +1181,7 @@ class systems extends plugin $this->CopyPasteHandler->cleanup_queue(); $dn = $this->terminals[$s_entry]['dn']; $oc = $this->terminals[$s_entry]['objectClass']; - $type = $this->get_system_type($oc); + $type = $this->get_system_type($this->terminals[$s_entry]); $tab_o = $tabs[$type]['CLASS']; $tab_c = $tabs[$type]['TABCLASS']; @@ -1196,7 +1200,7 @@ class systems extends plugin foreach($this->list_get_selected_items() as $id){ $dn = $this->terminals[$id]['dn']; $oc = $this->terminals[$id]['objectClass']; - $type = $this->get_system_type($oc); + $type = $this->get_system_type($this->terminals[$id]); $tab_o = $tabs[$type]['CLASS']; $tab_c = $tabs[$type]['TABCLASS']; @@ -1240,8 +1244,12 @@ class systems extends plugin } - function get_system_type($classes) + function get_system_type($attrs) { + #$enable_arp_device_handling = preg_match("/ArpNewDevice/i",search_config($this->config->data['TABS'], "ArpNewDevice", "CLASS")); + $enable_arp_device_handling = TRUE; + $classes = $attrs['objectClass']; + $type= ""; if (in_array_ics('ieee802Device', $classes)){ $type= "component"; @@ -1255,6 +1263,8 @@ class systems extends plugin $type= "phone"; }elseif (in_array_ics('goServer', $classes)){ $type= "server"; + }elseif (in_array_ics('GOhard', $classes) && !isset($attrs['gotoMode']) && $enable_arp_device_handling){ + $type= "ArpNewDevice"; }elseif (in_array_ics('GOhard', $classes)){ $type= "NewDevice"; }elseif (in_array_ics('sambaAccount', $classes) || diff --git a/plugins/admin/systems/class_termDNS.inc b/plugins/admin/systems/class_termDNS.inc index 944ebc2bf..af07e450b 100644 --- a/plugins/admin/systems/class_termDNS.inc +++ b/plugins/admin/systems/class_termDNS.inc @@ -461,7 +461,7 @@ class termDNS extends plugin $message= plugin::check(); if($this->dhcpEnabled && $this->dhcp_is_Account && $this->dhcpParentNode != "" && count($this->dhcpHostEntry) == 0){ - $message[] =_("You have not configured your dhcp settings yet."); +# $message[] =_("You have not configured your dhcp settings yet."); } /* Check if mac and ip are already used */ @@ -583,6 +583,21 @@ class termDNS extends plugin /* New entry */ if($this->dhcpEnabled){ + if(count($this->dhcpHostEntry) == 0){ + $this->dialog = new dhcpHost($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->execute(); + $this->dialog->save_object(); + $this->dhcpHostEntry = $this->dialog->save(); + if(count($this->dhcpHostEntry['dhcpOption']) == 0){ + $this->dhcpHostEntry['dhcpOption']= array("host-name ".$this->cn); + } + } + /* Write mac address to dhcp settings */ if($this->dhcp_is_Account){ if(!isset($this->dhcpHostEntry['dhcpHWAddress'][0]) || @@ -603,6 +618,9 @@ class termDNS extends plugin if($this->initial_dhcp_is_Account && !$this->dhcp_is_Account){ $ldap->rmdir_recursive($this->dhcpHostEntry['dn']); show_ldap_error($ldap->get_error(),_("Removing dhcp entry for this object failed.")); + + $tmp = new servdhcp($this->config,$this->dhcpParentNode); + $tmp->handle_post_events("remove"); } /* DHCP Added */ @@ -612,6 +630,10 @@ class termDNS extends plugin unset($attrs['dn']); $ldap->cd("cn=".$this->cn.",".$this->dhcpParentNode); $res = $ldap->add($attrs); + + $tmp = new servdhcp($this->config,$this->dhcpParentNode); + $tmp->handle_post_events("add"); + # print_a($attrs); # print("cn=".$this->cn.",".$this->dhcpParentNode); show_ldap_error($ldap->get_error(),_("Tried to add new dhcp entry failed.")); @@ -629,6 +651,10 @@ class termDNS extends plugin unset($attrs['MODIFIED']); $ldap->cd("cn=".$this->cn.",".$this->dhcpParentNode); $res = $ldap->add($attrs); + + $tmp = new servdhcp($this->config,$this->dhcpParentNode); + $tmp->handle_post_events("modify"); + show_ldap_error($ldap->get_error(),_("Tried to add new dhcp entry failed.")); if($res){ $ldap->rmdir_recursive($this->dhcpHostEntry['dn']); @@ -644,9 +670,17 @@ class termDNS extends plugin unset($attrs['MODIFIED']); $ldap->cd($this->dhcpHostEntry['dn']); $ldap->modify($attrs); + + $tmp = new servdhcp($this->config,$this->dhcpParentNode); + $tmp->handle_post_events("modify"); + show_ldap_error($ldap->get_error(),_("Modifying dhcp entry failed.")); } } + + /* Handle post event */ + $tmp = new servdns($this->config,$this->dn); + $tmp->handle_post_events("modify"); } diff --git a/plugins/admin/systems/tabs_arpnewdevice.inc b/plugins/admin/systems/tabs_arpnewdevice.inc new file mode 100644 index 000000000..f5d7f6830 --- /dev/null +++ b/plugins/admin/systems/tabs_arpnewdevice.inc @@ -0,0 +1,19 @@ +by_object[$this->current]->execute()); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?>