Code

Updated workstation - Startup
[gosa.git] / plugins / admin / systems / class_winGeneric.inc
index 844b6795dd3a674f0d4b70220495e38644ba35e9..ef279f3ab20351aa809392b7a04f8e4c51a9bdad 100644 (file)
@@ -44,22 +44,25 @@ class wingeneric extends plugin
                             "sambaNTPassword","sambaPwdLastSet","sambaAcctFlags");
   var $objectclasses= array("posixAccount","person","organizationalPerson","inetOrgPerson","gosaAccount","shadowAccount","sambaSamAccount","top");
 
+  var $view_logged = FALSE;
 
-  function wingeneric ($config, $dn= NULL, $parent= NULL)
+  function wingeneric (&$config, $dn= NULL, $parent= NULL)
   {
     plugin::plugin ($config, $dn, $parent);
-    $this->netConfigDNS = new termDNS($this->config,$this->dn,$this->objectclasses);
+    $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses);
     /* Set base */
     if ($this->dn == "new"){
       $ui= get_userinfo();
       $this->base= dn2base($ui->dn);
       $this->cn= "";
     } else {
-      $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
+      $this->base= preg_replace ("/^[^,]+,".normalizePreg(get_winstations_ou())."/", "", $this->dn);
     }
 
     /* Save dn for later references */
     $this->orig_dn= $this->dn;
+
+    $this->cn= preg_replace("/\\\$\$/","",$this->cn);
   }
 
 
@@ -78,11 +81,17 @@ class wingeneric extends plugin
 
   function execute()
   {
-       /* Call parent execute */
-       plugin::execute();
+    /* Call parent execute */
+    plugin::execute();
+
+    if($this->is_account && !$this->view_logged){
+      $this->view_logged = TRUE;
+      new log("view","winworkstation/".get_class($this),$this->dn);
+    }
+
 
     /* Do we represent a valid phone? */
-    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 network features.")."</b>";
       return($display);
@@ -106,7 +115,13 @@ class wingeneric extends plugin
       if($this->dialog->isClosed()){
         $this->dialog = false;
       }elseif($this->dialog->isSelected()){
-        $this->base = $this->dialog->isSelected();
+
+        /* A new base was selected, check if it is a valid one */
+        $tmp = $this->get_allowed_bases();
+        if(isset($tmp[$this->dialog->isSelected()])){
+          $this->base = $this->dialog->isSelected();
+        }
+
         $this->dialog= false;
       }else{
         return($this->dialog->execute());
@@ -127,7 +142,11 @@ class wingeneric extends plugin
     $smarty->assign("base_select", $this->base);
 
     /* Show main page */
-    $smarty->assign("netconfig", $this->netConfigDNS->execute());
+    $str = $this->netConfigDNS->execute();
+    if(is_object($this->netConfigDNS->dialog)){
+      return($str);
+    }
+    $smarty->assign("netconfig", $str);
     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
   }
 
@@ -136,6 +155,7 @@ class wingeneric extends plugin
     $this->netConfigDNS->remove_from_parent();
     $ldap= $this->config->get_ldap_link();
     $ldap->rmdir($this->dn);
+    new log("remove","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
     show_ldap_error($ldap->get_error(), sprintf(_("Removing of system wingeneric/generic with dn '%s' failed."),$this->dn));
     $this->handle_post_events("remove");
 
@@ -153,11 +173,21 @@ class wingeneric extends plugin
   /* Save data to object */
   function save_object()
   {
+    /* Create a base backup and reset the
+       base directly after calling plugin::save_object();
+       Base will be set seperatly a few lines below */
+    $base_tmp = $this->base;
     plugin::save_object();
+    $this->base = $base_tmp;
+
     $this->netConfigDNS->save_object();
-    /* Save base, since this is no LDAP attribute */
-    if (isset($_POST['base']) && $this->acl_is_moveable()){
-      $this->base= $_POST['base'];
+
+    /* Set new base if allowed */
+    $tmp = $this->get_allowed_bases();
+    if(isset($_POST['base'])){
+      if(isset($tmp[$_POST['base']])){
+        $this->base= $_POST['base'];
+      }
     }
   }
 
@@ -185,6 +215,9 @@ class wingeneric extends plugin
       $ldap->search ("(cn=".$this->cn.")", array("cn"));
       if ($ldap->count() != 0){
         while ($attrs= $ldap->fetch()){
+          if(preg_match("/cn=dhcp,/",$attrs['dn'])){
+            continue;
+          }
           if ($attrs['dn'] != $this->orig_dn){
             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
             break;
@@ -225,6 +258,7 @@ class wingeneric extends plugin
       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
       $ldap->cd($this->dn);
       $ldap->add($this->attrs);
+      new log("create","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
       $this->handle_post_events("add");
     } else {
       if ($this->orig_dn != $this->dn){
@@ -234,13 +268,12 @@ class wingeneric extends plugin
       $ldap->cd($this->dn);
       $this->cleanup();
       $ldap->modify ($this->attrs); 
-
+      new log("modify","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
       $this->handle_post_events("modify");
     }
 
-    # FIXME can't save mac address
-    #$this->netConfigDNS->cn = $this->cn;
-    #$this->netConfigDNS->save($this->dn);
+    $this->netConfigDNS->cn =  preg_replace("/\\\$\$/","",$this->cn);
+    $this->netConfigDNS->save();
     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system wingeneric/generic with dn '%s' failed."),$this->dn));
 
     /* Optionally execute a command after we're done */