X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fsystems%2Fclass_goShareServer.inc;h=99c75c32624facd006789bb49f2e70fedc431f1d;hb=96e561f68b807338f5f8923b665eb96376bd2f11;hp=5775aee0aa387a0179cde9912c247152ba7c090c;hpb=1e93f456bafdd1bb637d688e97df17f9082a5b5a;p=gosa.git diff --git a/plugins/admin/systems/class_goShareServer.inc b/plugins/admin/systems/class_goShareServer.inc index 5775aee0a..99c75c326 100644 --- a/plugins/admin/systems/class_goShareServer.inc +++ b/plugins/admin/systems/class_goShareServer.inc @@ -8,7 +8,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 */ @@ -17,16 +17,18 @@ 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(); function goShareServer($config,$dn) { plugin::plugin($config,$dn); - $this->DisplayName = _("Shares"); + $this->DisplayName = _("File service"); $tmp =array(); if(isset($this->attrs['goExportEntry'])){ @@ -140,12 +142,13 @@ class goShareServer extends plugin{ function getListEntry() { + $this->updateStatusState(); $flag = $this->StatusFlag; $fields['Status'] = $this->$flag; $fields['Message'] = _("Shares"); $fields['AllowStart'] = true; $fields['AllowStop'] = true; - $fields['AllowReset'] = true; + $fields['AllowRestart'] = true; $fields['AllowRemove']= true; $fields['AllowEdit'] = true; return($fields); @@ -155,6 +158,13 @@ class goShareServer extends plugin{ function remove_from_parent() { plugin::remove_from_parent(); + + /* Remove status flag, it is not a memeber of + this->attributes, so ensure that it is deleted too */ + if(!empty($this->StatusFlag)){ + $this->attrs[$this->StatusFlag] = array(); + } + /* Check if this is a new entry ... add/modify */ $ldap = $this->config->get_ldap_link(); $ldap->cat($this->dn,array("objectClass")); @@ -165,7 +175,8 @@ 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(_("Removing of system server/shares with dn '%s' failed."),$this->dn)); + $this->handle_post_events("remove"); } @@ -198,45 +209,36 @@ 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"); + }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()); - } + show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for system server/shares with dn '%s' failed."),$this->dn)); + $this->action_hook(); + } } @@ -263,6 +265,199 @@ 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(), sprintf(_("Creating system server/shares (mount container) with dn '%s' failed."),$this->dn)); + 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(), sprintf(_("Removing system server/shares (mount container) with dn '%s' failed."),$this->dn)); + 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(), sprintf(_("Saving system server/shares (mount container) with dn '%s' failed."),$this->dn)); + 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 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); + } + } + + 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); + } + } + } + + /* Get updates for status flag */ + function updateStatusState() + { + if(empty($this->StatusFlag)) return; + + $attrs = array(); + $flag = $this->StatusFlag; + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->cn); + $ldap->cat($this->dn,array($flag)); + if($ldap->count()){ + $attrs = $ldap->fetch(); + } + if(isset($attrs[$flag][0])){ + $this->$flag = $attrs[$flag][0]; + } + } + + + function addToMountList($entry) + { + $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]]); + } + } + + function deleteFromMountList($entry) + { + $type = $this->get_share_type($entry); + if (($type == "netatalk") || ($type == "NFS")) { + $this->mounts_to_remove[$entry] = $entry; + unset($this->mounts_to_add[$entry]); + } + } + + 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; + } + + + /* Return plugin informations for acl handling */ + function plInfo() + { + return (array( + "plShortName" => _("Shares"), + "plDescription" => _("Share service"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 0, + "plSection" => array("administration"), + "plCategory" => array("server"), + + "plProvidedAcls"=> array( + "goExportEntry" =>_("Share entry")) + )); + } + } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: