Code

Updated workstation - Startup
[gosa.git] / plugins / admin / systems / class_servGeneric.inc
index 691853b4b2f3628ed3ee0b9bc09bbb9462d77cc4..b46e85b29ceb61d2f4b63dd497a77d7c9dbf97de 100644 (file)
@@ -38,11 +38,13 @@ class servgeneric extends plugin
                             "sysinfo"         => "sysinfo");
 
   var $fai_activated  =FALSE;
+  var $view_logged = FALSE;
 
-  function servgeneric ($config, $dn= NULL, $parent= NULL)
+  function servgeneric (&$config, $dn= NULL, $parent= NULL)
   {
     /* Check if FAI is activated */
-    $tmp = search_config($config->data,"faiManagement","CLASS");
+    $tmp = $config->search("faiManagement", "CLASS",array('menu','tabs'));
+    
     if(!empty($tmp)){
       $this->fai_activated = TRUE;
     }
@@ -61,13 +63,9 @@ class servgeneric extends plugin
     } else {
       $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
     }
-    $this->netConfigDNS = new termDNS($this->config,$this->dn,$this->objectclasses);
+    $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses);
     $this->netConfigDNS->set_acl_category("server");
     $this->netConfigDNS->set_acl_base($this->base);
-    if($this->is_account){
-      @log::log("view","server/".get_class($this),$this->dn);
-    }
        
     /* Save dn for later references */
     $this->orig_dn= $this->dn;
@@ -93,8 +91,13 @@ class servgeneric extends plugin
     /* Call parent execute */
     plugin::execute();
 
+    if($this->is_account && !$this->view_logged){
+      $this->view_logged = TRUE;
+      new log("view","server/".get_class($this),$this->dn);
+    }
+
     /* Do we represent a valid server? */
-    if (!$this->is_account && $this->parent == NULL){
+    if (!$this->is_account && $this->parent === NULL){
       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
         _("This 'dn' has no server features.")."</b>";
       return($display);
@@ -102,7 +105,7 @@ class servgeneric extends plugin
 
     /* Check for action */
     if (isset($_POST['action']) && $this->acl_is_writeable("FAIstate")){
-      $cmd= search_config($this->config->data['TABS'], "workgeneric", "ACTIONCMD");
+      $cmd = $this->config->search("workgeneric", "ACTIONCMD",array('tabs'));
       if ($cmd == ""){
         print_red(_("No ACTIONCMD definition found in your gosa.conf"));
       } else {
@@ -221,7 +224,12 @@ class servgeneric extends plugin
 
     /* Show main page */
     $smarty->assign("fai_activated",$this->fai_activated);
-    $smarty->assign("netconfig", $this->netConfigDNS->execute());
+
+    $str = $this->netConfigDNS->execute();
+    if(is_object($this->netConfigDNS->dialog)){
+      return($str);
+    }
+    $smarty->assign("netconfig", $str);
     $smarty->assign("modes", $this->modes);
 
     return($smarty->fetch (get_template_path('server.tpl', TRUE)));
@@ -238,7 +246,7 @@ class servgeneric extends plugin
     $ldap= $this->config->get_ldap_link();
     $ldap->rmdir($this->dn);
 
-    @log::log("remove","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+    new log("remove","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
 
     show_ldap_error($ldap->get_error(), sprintf(_("Removing of system server/generic with dn '%s' failed."),$this->dn)); 
 
@@ -250,7 +258,7 @@ class servgeneric extends plugin
       unset($og->member[$this->dn]);
       $og->save ();
     }
-    $this->handle_post_events("remove", array("macAddress" => $this->netConfigDNS->macAddress));
+    $this->handle_post_events("remove",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
   }
 
 
@@ -288,6 +296,11 @@ class servgeneric extends plugin
       $message[]= _("The required field 'Server name' is not set.");
     }
     
+    /* Check if given name is a valid host/dns name */
+    if(!is_dns_name($this->cn)){
+      $message[] = _("Please specify a valid name for this object.");
+    }
+
     if ($this->orig_dn != $this->dn){
       $ldap= $this->config->get_ldap_link();
       $ldap->cd ($this->base);
@@ -295,7 +308,7 @@ class servgeneric extends plugin
       if ($ldap->count() != 0){
         while ($attrs= $ldap->fetch()){
           if ($attrs['dn'] != $this->orig_dn){
-            if(!preg_match("/,ou=incoming,/",$attrs['dn'])){
+            if(!preg_match("/cn=dhcp,/",$attrs['dn']) && !preg_match("/,ou=incoming,/",$attrs['dn']) && preg_match("/,ou=servers,ou=systems,/",$attrs['dn'])){
               $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
               break;
             }
@@ -332,19 +345,19 @@ class servgeneric extends plugin
       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
       $ldap->cd($this->dn);
       $ldap->add($this->attrs);
-      @log::log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+      new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
       $mode= "add";
     } else {
    
       /* cn is not case sensitive for ldap, but for php it is!! */ 
       if($this->config->current['DNMODE'] == "cn"){
         if (strtolower($this->orig_dn) != (strtolower($this->dn))){
-          $this->move($this->orig_dn, $this->dn);
+          $this->recursive_move($this->orig_dn, $this->dn);
           plugin::save();
         }
       }else{
         if ($this->orig_dn != $this->dn){
-          $this->move($this->orig_dn, $this->dn);
+          $this->recursive_move($this->orig_dn, $this->dn);
           plugin::save();
         }
       }
@@ -352,21 +365,59 @@ class servgeneric extends plugin
       $ldap->cd($this->dn);
       $this->cleanup();
       $ldap->modify ($this->attrs); 
-      @log::log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+      new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
 
       $mode= "modify";
     }
     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system server/generic with dn '%s' failed."),$this->dn)); 
     $this->netConfigDNS->cn = $this->cn;
-    $this->netConfigDNS->save($this->dn);
+    $this->netConfigDNS->save();
 
     /* Optionally execute a command after we're done */
     if(!$this->didAction){
-      $this->handle_post_events($mode);
+      $this->handle_post_events($mode,array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
     }
   }
 
 
+  /* Display generic part for server copy & paste */
+  function getCopyDialog()
+  {
+    $vars = array("cn");
+
+    $smarty = get_smarty();
+    $smarty->assign("cn" ,$this->cn);
+    $smarty->assign("object","server");
+    $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
+    $ret = array();
+    $ret['string'] = $str;
+    $ret['status'] = "";
+    return($ret);
+  }
+
+
+  function saveCopyDialog()
+  {
+    if(isset($_POST['cn'])){
+      $this->cn = $_POST['cn'];
+    }
+  }
+
+  
+  function PrepareForCopyPaste($source)  
+  {
+    plugin::PrepareForCopyPaste($source);
+    if(isset($source['macAddress'][0])){
+      $this->netConfigDNS->macAddress = $source['macAddress'][0];
+    }
+    if(isset($source['ipHostNumber'][0])){
+      $this->netConfigDNS->ipHostNumber = $source['ipHostNumber'][0];
+    }
+
+  }
+  
+
+
   /* Return plugin informations for acl handling */ 
   function plInfo()
   {
@@ -378,7 +429,7 @@ class servgeneric extends plugin
           "plPriority"    => 1,
           "plSection"     => array("administration"),           
           "plCategory"    => array("server" => array("description"  => _("Server"),
-                                                     "objectClass"  => "gotoWorkstation")),
+                                                     "objectClass"  => "goServer")),
           "plProvidedAcls"=> array(
             "cn"           => _("Name"),
             "description"  => _("Description"),