Code

Updated terminal copy & paste
[gosa.git] / plugins / admin / systems / class_goShareServer.inc
index 6c968e94816781badeabdc027447a38ad1cbe491..6b7f39aa382c514633f11ddc96f9bfc75fe96d00 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 
-class goShareServer extends plugin{
+require_once("class_goService.inc");
+
+class goShareServer extends goService{
 
   var $cli_summary      = "This plugin is used within the ServerService Pluign \nand indicates that this server supports shares.";
   var $cli_description  = "Some longer text\nfor help";
@@ -8,7 +10,7 @@ class goShareServer extends plugin{
 
   /* This plugin only writes its objectClass */
   var $objectclasses    = array("goShareServer");
-  var $attributes       = array("goShareServerStatus","goExportEntry");
+  var $attributes       = array("goExportEntry");
   var $StatusFlag       = "goShareServerStatus";
 
   /* This class can't be assigned twice so it conflicts with itsself */
@@ -16,17 +18,17 @@ class goShareServer extends plugin{
 
   var $DisplayName      = "";
   var $dn               = NULL;
-  var $acl;
   var $cn                   = "";
   var $goShareServerStatus  = "";
   var $goExportEntry        = array();
   var $allow_mounts         = false;
   var $mounts_to_remove     = array();
   var $mounts_to_add        = array();
+  var $view_logged  =FALSE;
 
   function goShareServer($config,$dn)
   {
-    plugin::plugin($config,$dn);
+    goService::goService($config,$dn);
 
     $this->DisplayName = _("File service");
 
@@ -53,8 +55,13 @@ class goShareServer extends plugin{
   { 
     $smarty = get_smarty(); 
 
+    if($this->is_account && !$this->view_logged){
+      $this->view_logged = TRUE;
+      new log("view","server/".get_class($this),$this->dn);
+    }
+
 
-    if((isset($_POST['DelNfsEnt']))&&(isset($_POST['goExportEntryList']))){
+    if((isset($_POST['DelNfsEnt']))&&(isset($_POST['goExportEntryList'])) && ($this->acl_is_writeable("name"))){
       if($this->allow_mounts){
         foreach($_POST['goExportEntryList'] as $entry){
           $this->deleteFromMountList($this->goExportEntryList[$entry]);
@@ -65,9 +72,11 @@ class goShareServer extends plugin{
       }
     }
 
-    if(isset($_POST['NewNfsAdd'])){
+    if(isset($_POST['NewNfsAdd']) && ($this->acl_is_writeable("name"))){
       $this->oldone = NULL;
-      $this->o_subWindow = new servnfs($this->config,$this->acl, $this->allow_mounts, $this->dn);
+      $this->o_subWindow = new servnfs($this->config, $this);
+      $this->o_subWindow->set_acl_category("server");
+      $this->o_subWindow->set_acl_base($this->dn);
       $this->dialog = true;
     }
 
@@ -75,7 +84,9 @@ class goShareServer extends plugin{
       $entry = $this->goExportEntryList[$_POST['goExportEntryList'][0]];
       $add_mount=isset($this->mounts_to_add[$entry]);
       $this->oldone=$entry;
-      $this->o_subWindow = new servnfs($this->config,$this->acl,$this->allow_mounts,$this->dn,$entry,$add_mount);
+      $this->o_subWindow = new servnfs($this->config,$this,$entry,$add_mount);
+      $this->o_subWindow->set_acl_base($this->dn);
+      $this->o_subWindow->set_acl_category("server");
       $this->dialog = true;
     }
     if(isset($this->o_subWindow)){
@@ -91,6 +102,7 @@ class goShareServer extends plugin{
       }else{
         $this->o_subWindow->save_object();
         $newone = $this->o_subWindow->save();
+
         $this->addToList($newone);
         if($this->allow_mounts){
           if($this->oldone) {
@@ -117,14 +129,18 @@ class goShareServer extends plugin{
       return $this->o_subWindow->execute();
     }
 
-
-
-
-
     foreach($this->attributes as $attr){
       $smarty->assign($attr,$this->$attr);
-      $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
     }
+
+    /* Set acls */
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $name => $translated){
+      $smarty->assign($name."ACL",$this->getacl($name));
+    }
+    $smarty->assign("createable",$this->acl_is_createable());
+    $smarty->assign("removeable",$this->acl_is_removeable());
+
     $tellSmarty= array();
     ksort($this->goExportEntryList);
     foreach($this->goExportEntryList as $name=>$values){
@@ -133,45 +149,19 @@ class goShareServer extends plugin{
     }
     $smarty->assign("goExportEntry",array_keys($tellSmarty));
     $smarty->assign("goExportEntryKeys",($tellSmarty));
-    $smarty->assign("goExportEntryACL", chkacl($this->acl, "goExportEntry"));
-
-
     return($smarty->fetch(get_template_path("goShareServer.tpl",TRUE,dirname(__FILE__))));
   }
 
 
   function getListEntry()
   {
-    $flag = $this->StatusFlag;
-    $fields['Status']     = $this->$flag;
-    $fields['Message']    = _("Shares");
-    $fields['AllowStart'] = true;
-    $fields['AllowStop']  = true;
-    $fields['AllowRestart'] = true;
-    $fields['AllowRemove']= true;
+    $fields = goService::getListEntry();
+    $fields['Message']    = _("File service (Shares)");
     $fields['AllowEdit']  = true;
     return($fields);
   }
 
 
-  function remove_from_parent()
-  {
-    plugin::remove_from_parent();
-    /* Check if this is a new entry ... add/modify */
-    $ldap = $this->config->get_ldap_link();
-    $ldap->cat($this->dn,array("objectClass"));
-    if($ldap->count()){
-      $ldap->cd($this->dn);
-      $ldap->modify($this->attrs);
-    }else{
-      $ldap->cd($this->dn);
-      $ldap->add($this->attrs);
-    }
-    show_ldap_error($ldap->get_error());
-    $this->handle_post_events("remove");
-  }
-
-
   function save()
   {
     plugin::save();
@@ -190,7 +180,6 @@ class goShareServer extends plugin{
       $this->process_mounts();
     }
 
-
     /* Check if this is a new entry ... add/modify */
     $ldap = $this->config->get_ldap_link();
     $ldap->cat($this->dn,array("objectClass"));
@@ -201,35 +190,13 @@ class goShareServer extends plugin{
       $ldap->cd($this->dn);
       $ldap->add($this->attrs);
     }
-    show_ldap_error($ldap->get_error());
+    show_ldap_error($ldap->get_error(), sprintf(_("Saving of system server/shares with dn '%s' failed."),$this->dn));
     if($this->initially_was_account){
       $this->handle_post_events("modify");
+      new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
     }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()){
-
-      $tmp = $ldap->fetch();
-      for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
-        $attrs['objectClass'][] = $tmp['objectClass'][$i];
-      }
-      $flag = $this->StatusFlag;
-      $attrs[$flag] = $value;
-      $this->$flag = $value;
-      $ldap->modify($attrs);
-      show_ldap_error($ldap->get_error());
-      $this->action_hook();
+      new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
     }
   }
 
@@ -253,8 +220,26 @@ class goShareServer extends plugin{
     $this->goExportEntryList[$key]=$entry[$key];
   }
 
-  function deleteFromList($id){
-    unset($this->goExportEntryList[$id]);
+  function deleteFromList($id)
+  {
+    /* Check if the share is used by someone */
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->search("(|(gotoProfileServer=*|$id)(gotoShare=*|$id|*))", array("cn"));
+    $cnt= $ldap->count();
+    if ($cnt){
+      $msg= sprintf(_("The share can't be removed since it is still used by %d users:"), $cnt);
+      $msg.= "<br><br><ul>";
+      while ($attrs= $ldap->fetch()){
+        $msg.= "<li>".$attrs["cn"][0]."</li>";
+      }
+      $msg.= "</ul>"._("Please correct the share-/profile settings of these users");
+      print_red($msg);
+
+    } else {
+      /* Finally remove it */
+      unset($this->goExportEntryList[$id]);
+    }
   }
 
    function process_mounts() {
@@ -276,8 +261,8 @@ class goShareServer extends plugin{
     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");
+        show_ldap_error($ldap->get_error(), sprintf(_("Creating system server/shares (mount container) with dn '%s' failed."),$this->dn)); 
+        new log("modify","server/".get_class($this),$mountsdn,array_keys($mounts),$ldap->get_error());
     }
 
     # remove deleted mounts from the container
@@ -290,62 +275,134 @@ class goShareServer extends plugin{
 
       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");
+        show_ldap_error($ldap->get_error(), sprintf(_("Removing system server/shares (mount container) with dn '%s' failed."),$this->dn)); 
+        new log("remove","server/".get_class($this),$mountdn,array_keys($mount),$ldap->get_error());
       }
     }
 
     # 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");
+      show_ldap_error($ldap->get_error(), sprintf(_("Saving system server/shares (mount container) with dn '%s' failed."),$this->dn)); 
+      new log("create","server/".get_class($this),$mountdn,array_keys($mount),$ldap->get_error());
     }
   }
 
-   function action_hook($add_attrs= array())
+  function addToMountList($entry) 
   {
-    /* 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);
-        }
+    if($this->acl_is_writeable("name")){
+      $key =  key($entry);
+      $type = $this->get_share_type($entry[$key]);
+      if (($type == "netatalk") || ($type == "NFS")) {
+        $this->mounts_to_add[$entry[$key]] = $entry[$key];
+        unset($this->mounts_to_remove[$entry[$key]]);
       }
-      $command= preg_replace("/%dn/", $this->dn, $command);
-      /* Additional attributes */
-      foreach ($add_attrs as $name => $value){
-        $command= preg_replace("/%$name/", $value, $command);
+    }
+  }
+
+  function deleteFromMountList($entry) 
+  {
+    if($this->acl_is_writeable("name")){
+      $type = $this->get_share_type($entry);
+      if (($type == "netatalk") || ($type == "NFS")) {
+        $this->mounts_to_remove[$entry] = $entry;
+        unset($this->mounts_to_add[$entry]);
       }
+    }
+  }
 
-      /* If there are still some %.. in our command, try to fill these with some other class vars */
-      if(preg_match("/%/",$command)){
-        $attrs = get_object_vars($this);
-        foreach($attrs as $name => $value){
-          if(!is_string($value)) continue;
-          $command= preg_replace("/%$name/", $value, $command);
-        }
+  function get_share_type($share) 
+  {
+    $tmp = split("\|", $share);
+    return $tmp[2];
+  }
+
+  function returnMountEntry($entry)
+  {
+    $item = split("\|", $entry);
+    $name = $item[0];
+    $description = $item[1];
+    $type = $item[2];
+    $charset = $item[3];
+    $path = $item[4];
+    $options = $item[5];
+
+    switch ($type) {
+      case "netatalk" : {
+        $mount = array(
+            "mountDirectory" => "/Network/Servers/",
+            "mountOption" => array(
+              "net",
+              "url==afp://;AUTH=NO%20USER%20AUTHENT@".$this->cn."/$name/"
+              ),
+            "mountType" => "url",
+            "objectClass" => "mount",
+            "cn" => $this->cn .":/".$name
+            );
+        break;
+      }
+      case "NFS" : {
+        $mount = array(
+            "mountDirectory" => "/Network/Servers/",
+            "mountOption" => "net",
+            "mountType" => "nfs",
+            "objectClass" => "mount",
+            "cn" => $this->cn .":".$path
+            );
+        break;
       }
+      default : {
+                  continue;
+                }
+    }
+    return $mount;
+  }
 
-      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);
+  function PrepareForCopyPaste($source)
+  {
+    plugin::PrepareForCopyPaste($source);
+
+    $tmp =array();
+    if(isset($source['goExportEntry'])){
+      if(isset($source['goExportEntry']['count'])){
+        for($i= 0; $i<$source['goExportEntry']['count']; $i++){
+          $entry= $source['goExportEntry'][$i];
+          $tmp[preg_replace('/\|.*$/', '', $entry)]= $entry;
+        }
       }
     }
+    $this->goExportEntryList = $tmp;
+    $this->goExportEntry = $tmp;
+  }
+
+
+  /* Return plugin informations for acl handling */
+  function plInfo()
+  {
+    return (array(
+          "plShortName"   => _("File service (Shares)"),
+          "plDescription" => _("File service - Shares")." ("._("Services").")",
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 90,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("server"),
+
+          "plProvidedAcls"=> array(
+              "name"        => _("Name"),
+              "netatalkmount" => _("Apple mounts"),
+              "description" => _("Description"),
+              "type"        => _("Type"),
+              "charset"     => _("Charset"),
+              "path"        => _("Path"),
+              "option"      => _("Option"),
+              "volume"      => _("Volume"))
+
+          ));
   }