Code

Added Arp New Device handling.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 22 Oct 2007 06:33:21 +0000 (06:33 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 22 Oct 2007 06:33:21 +0000 (06:33 +0000)
Not working

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7610 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/ArpNewDevice.tpl [new file with mode: 0644]
plugins/admin/systems/class_ArpNewDevice.inc [new file with mode: 0644]
plugins/admin/systems/class_divListSystem.inc
plugins/admin/systems/class_servDNS.inc
plugins/admin/systems/class_systemManagement.inc
plugins/admin/systems/class_termDNS.inc
plugins/admin/systems/tabs_arpnewdevice.inc [new file with mode: 0644]

diff --git a/plugins/admin/systems/ArpNewDevice.tpl b/plugins/admin/systems/ArpNewDevice.tpl
new file mode 100644 (file)
index 0000000..8e4bf44
--- /dev/null
@@ -0,0 +1,31 @@
+<h2><img class="center" alt="" align="middle" src="images/rightarrow.png"> {t}Integrating unknown devices{/t}</h2>
+<p>
+ {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}
+</p>
+<table summary="" style="width:100%">
+<tr>
+ <td style>
+  <LABEL for="cn">
+   {t}DNS name{/t}{$must}
+  </LABEL>
+ </td>
+ <td style='width:35%;border-right:1px solid #aaa'>
+  <input name="cn" id="cn" size=18 maxlength=60 value="{$cn}">
+ </td>
+ <td style='width:15%'>
+  <LABEL for="description">
+   {t}Description{/t}
+  </LABEL>
+ </td>
+ <td style='width:35%'>
+  <input name="description" id="description" size=18 maxlength=60 value="{$description}">
+ </td>
+</tr>
+</table>
+<br>
+<p class="seperator"></p>
+{$netconfig}
+
+<input type='hidden' name='ArpNewDevice_posted' value='1'>
+
+<p class="seperator"></p>
diff --git a/plugins/admin/systems/class_ArpNewDevice.inc b/plugins/admin/systems/class_ArpNewDevice.inc
new file mode 100644 (file)
index 0000000..f2d7a75
--- /dev/null
@@ -0,0 +1,74 @@
+<?php 
+class ArpNewDevice extends plugin
+{
+  var $cn= "";
+  var $description = "";
+  var $netConfigDNS = NULL;
+  var $attributes= array("cn","description");
+  var $objectclasses = array("gotoHard");
+  var $ignore_account = TRUE;
+
+  function ArpNewDevice ($config, $dn= NULL, $parent= NULL)
+  {
+    plugin :: plugin($config,$dn);
+    $this->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:
+?>
index 38fe1ddbf46607fdfd5126ef5687bc3eaea0b1a9..ce7c17a28e6081cdcc4f59dedbb4dc35c9af5057 100644 (file)
@@ -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] ++;
 
 
index 4603a4394d269565f395ec3f5c471acca3ebde55..2bc0352779ec0967934863d134a94d544431af68 100644 (file)
@@ -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");
   }
 
 
index aacc86281ec90e1581f858209bb64df3c1bd8be1..08ffae4487ceabc1b9bb563b51d4dd3dbe5b4070 100644 (file)
@@ -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) ||
index 944ebc2bf877b446118b5691a117624472eaf7f0..af07e450b4f42bc5d11126ab7d035f13be396dc9 100644 (file)
@@ -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 (file)
index 0000000..f5d7f68
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+
+class ArpNewDeviceTabs extends tabs
+{
+
+  function save()
+  {
+    tabs::save(TRUE);
+  }
+
+  function execute()
+  {
+    tabs::execute(); 
+    return($this->by_object[$this->current]->execute());
+  }
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>