Code

Fixed "Undefined index: �z"
[gosa.git] / plugins / admin / systems / class_goShareServer.inc
index 5775aee0aa387a0179cde9912c247152ba7c090c..010c18cadbe3c5e9e2fb408e01c1af4c8b45aabc 100644 (file)
@@ -21,12 +21,14 @@ class goShareServer extends plugin{
   var $goShareServerStatus  = "";
   var $goExportEntry        = array();
   var $allow_mounts         = false;
+  var $mounts_to_remove     = array();
+  var $mounts_to_add        = array();
 
   function goShareServer($config,$dn)
   {
     plugin::plugin($config,$dn);
 
-    $this->DisplayName = _("Shares");
+    $this->DisplayName = _("File service");
 
     $tmp =array();
     if(isset($this->attrs['goExportEntry'])){
@@ -145,7 +147,7 @@ class goShareServer extends plugin{
     $fields['Message']    = _("Shares");
     $fields['AllowStart'] = true;
     $fields['AllowStop']  = true;
-    $fields['AllowReset'] = true;
+    $fields['AllowRestart'] = true;
     $fields['AllowRemove']= true;
     $fields['AllowEdit']  = true;
     return($fields);
@@ -166,6 +168,7 @@ class goShareServer extends plugin{
       $ldap->add($this->attrs);
     }
     show_ldap_error($ldap->get_error());
+    $this->handle_post_events("remove");
   }
 
 
@@ -199,44 +202,35 @@ class goShareServer extends plugin{
       $ldap->add($this->attrs);
     }
     show_ldap_error($ldap->get_error());
+    if($this->initially_was_account){
+      $this->handle_post_events("modify");
+    }else{
+      $this->handle_post_events("add");
+    }
   }
 
 
   /* Directly save new status flag */
   function setStatus($value)
   {
+    if($value == "none") return;
+    if(!$this->initially_was_account) return;
     $ldap = $this->config->get_ldap_link();
     $ldap->cd($this->dn);
     $ldap->cat($this->dn,array("objectClass"));
-
     if($ldap->count()){
-      $attrs =array();
-      foreach(array() as $req) {
-        if(!isset($attrs[$req])){
-          if(empty($this->$req)){
-            print_red(sprintf(_("The required attribute '%s' is not set."),$req));
-          }else{
-            $attrs[$req] = $this->$req;
-          }
-        }else{
-          $attrs[$req] = $attrs[$req][0];
-        }
-      }
 
       $tmp = $ldap->fetch();
       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
         $attrs['objectClass'][] = $tmp['objectClass'][$i];
-      }    
-      if(!in_array("goShareServer",$attrs['objectClass'])){
-        $attrs['objectClass'][] = "goShareServer";
       }
-
       $flag = $this->StatusFlag;
       $attrs[$flag] = $value;
       $this->$flag = $value;
       $ldap->modify($attrs);
       show_ldap_error($ldap->get_error());
-    }    
+      $this->action_hook();
+    }
   }
 
 
@@ -263,6 +257,87 @@ class goShareServer extends plugin{
     unset($this->goExportEntryList[$id]);
   }
 
+   function process_mounts() {
+
+    $clip = "cn=" . $this->cn . ",ou=servers,ou=systems,";
+    $mountsdn = "cn=mounts," . substr($this->dn, strlen($clip));
+
+    $mounts = array(
+      "objectClass" => "container",
+      "cn" => "mounts"
+    );
+
+    # load data from mounts container
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cat($mountsdn, array('dn'));
+    $attrs = $ldap->fetch();
+
+    # mounts container not present yet, so we create it
+    if (count($attrs) == 0) {
+        $ldap->cd($mountsdn);
+        $ldap->add($mounts);
+        show_ldap_error($ldap->get_error(), _("Creating mount container failed"));
+        gosa_log("Mount container '$mountsdn' has been created");
+    }
+
+    # remove deleted mounts from the container
+    foreach ($this->mounts_to_remove as $entry) {
+      $mount=$this->returnMountEntry($entry);
+      $mountdn = "cn=".$mount["cn"].","."$mountsdn";
+
+      $ldap->cat($mountdn, array('dn'));
+      $attrs = $ldap->fetch();
+
+      if (count($attrs) != 0) {
+        $ldap->rmdir($mountdn);
+        show_ldap_error($ldap->get_error(), _("Removing mount container failed"));
+        gosa_log("Mount object '".$mountdn."' has been removed");
+      }
+    }
+
+    # add new mounts to the container
+    foreach ($this->mounts_to_add as $entry) {
+
+      $mount=$this->returnMountEntry($entry);
+      $mountdn = "cn=".$mount["cn"].","."$mountsdn";
+      $ldap->cd($mountdn);
+      $ldap->add($mount);
+      show_ldap_error($ldap->get_error(), _("Saving mount container failed"));
+      gosa_log("Mount object '".$mountdn."' has been added");
+    }
+  }
+
+   function action_hook($add_attrs= array())
+  {
+    /* Find postcreate entries for this class */
+    $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
+    if ($command == "" && isset($this->config->data['TABS'])){
+      $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
+    }
+    if ($command != ""){
+      /* Walk through attribute list */
+      foreach ($this->attributes as $attr){
+        if (!is_array($this->$attr)){
+          $command= preg_replace("/%$attr/", $this->$attr, $command);
+        }
+      }
+      $command= preg_replace("/%dn/", $this->dn, $command);
+      /* Additional attributes */
+      foreach ($add_attrs as $name => $value){
+        $command= preg_replace("/%$name/", $value, $command);
+      }
+      if (check_command($command)){
+        @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
+            $command, "Execute");
+
+        exec($command);
+      } else {
+        $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
+        print_red ($message);
+      }
+    }
+  }
+
 
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: