From: cajus Date: Wed, 26 Apr 2006 14:36:47 +0000 (+0000) Subject: Added netatalk share management X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=723b7899aaf78eebc147043cb1014a5f708a7306;p=gosa.git Added netatalk share management git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3127 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/contrib/gosa.conf b/contrib/gosa.conf index 00a59493a..0ea88fd3b 100644 --- a/contrib/gosa.conf +++ b/contrib/gosa.conf @@ -13,6 +13,8 @@ path="plugins/personal/mail" /> + + diff --git a/include/class_ldap.inc b/include/class_ldap.inc index a098b15f5..677f7f459 100644 --- a/include/class_ldap.inc +++ b/include/class_ldap.inc @@ -1039,6 +1039,35 @@ function gen_xls ($dn, $filter= "(objectClass=*)", $attributes= array('*'), $rec } } + + function get_objectclasses() + { + $objectclasses = array(); + + # Get base to look for schema + $sr = @ldap_read ($this->cid, NULL, "objectClass=*", array("subschemaSubentry")); + $attr = @ldap_get_entries($this->cid,$sr); + if (!isset($attr[0]['subschemasubentry'][0])){ + return array(); + } + + # Get list of objectclasses + $nb= $attr[0]['subschemasubentry'][0]; + $objectclasses= array(); + $sr= ldap_read ($this->cid, $nb, "objectClass=*", array("objectclasses")); + $attrs= ldap_get_entries($this->cid,$sr); + if (!isset($attrs[0])){ + return array(); + } + foreach ($attrs[0]['objectclasses'] as $val){ + $name= preg_replace("/^.* NAME\s+\(*\s*'([^']+)'\s*\)*.*$/", '\\1', $val); + if ($name != $val){ + $objectclasses[$name]= $val; + } + } + + return $objectclasses; + } } diff --git a/include/functions_setup.inc b/include/functions_setup.inc index a55866635..77ca026fb 100644 --- a/include/functions_setup.inc +++ b/include/functions_setup.inc @@ -247,6 +247,16 @@ function schema_check($server, $admin, $password, $aff=0,$CalledByIndexPhP=false $affich['nagioscontact']['status']= true; } + if ((!isset($objectclasses['apple-user'])) || (!isset($objectclasses['mount'])) ){ + $messages['netatalk']['msg']= _("Support for netatalk disabled, no schema seems to be installed"); + $affich['netatalk']['msg']= $messages['netatalk']['msg']."apple.schema"; + $messages['netatalk']['status']= FALSE; + $affich['netatalk']['status']= FALSE; + }else{ + $affich['netatalk']['msg']= _("Support for netatalk enabled")."apple.schema"; + $affich['netatalk']['status']= true; + } + /* Fix for PHP Fehler "Undefined index: ldapconf" * Ablaufverfolgung[1]: Funktion schema_check Datei: /home/hickert/gosa/include/functions_setup.inc (Zeile 230) */ @@ -553,6 +563,8 @@ function parse_contrib_conf() $possible_plugins['pureftp'][] = "'\n.*.*\n'i"; $possible_plugins['webdav'][] = "'\n.*.*\n'i"; $possible_plugins['phpgroupware'][]= "'\n.*.*\n'i"; + $possible_plugins['netatalk'][0] = "'\n.*.*\n'i"; + $possible_plugins['netatalk'][1] = "'\n.*.*\n'i"; /*Header information Needed to send the generated gosa.conf to the browser */ diff --git a/plugins/admin/groups/acl_definition.inc b/plugins/admin/groups/acl_definition.inc index f03560216..103ce8bea 100644 --- a/plugins/admin/groups/acl_definition.inc +++ b/plugins/admin/groups/acl_definition.inc @@ -211,6 +211,10 @@ $ACLD['samba']= ) ; +$ACLD['netatalk']= array( + "netatalkShare", + "netatalkUserHomepath"); + $ACLD['proxyAccount']= array( "proxyAccount", @@ -259,7 +263,8 @@ $ACLD['gotoEnvironment']=array( "gotoLogonScript", "gotoKioskProfile", "gotoProfileQuota", - "gotoHotplugDevice" + "gotoHotplugDevice", + "gotoShareAppleMounts" ); $ACLD['phpgwAccount'] =array("phpgwAccount" ); diff --git a/plugins/admin/systems/class_servNfs.inc b/plugins/admin/systems/class_servNfs.inc index 0b96923ca..4770a78d1 100644 --- a/plugins/admin/systems/class_servNfs.inc +++ b/plugins/admin/systems/class_servNfs.inc @@ -17,18 +17,28 @@ class servnfs extends plugin var $description =""; // description var $type =""; // Type FS/Samba/NCP var $charset =""; // charset - var $types =array(); // Array Types NFS/Samba/NCP + var $host =""; // hostname + var $types =array(); // Array Types NFS/Samba/NCP/netatalk var $charsets =array(); // Array with charsets var $path =""; // Path var $option =""; // Options var $is_edit =false; + var $allow_mounts = false; //do we allow mount entries? + var $create_mount_init = false; //mount entry set for this entry (while editing)? + var $create_mount = false; //save mount entry - - function servnfs ($config, $dn= NULL,$entry = false) + function servnfs ($config, $acl, $allow_mounts, $dn= NULL,$entry = false,$mount = false) { plugin::plugin ($config, $dn); - $this->types = array("NFS"=>"NFS","samba"=>"samba","NCP"=>"NCP"); - + + $this->types = array("NFS"=>"NFS","samba"=>"samba","netatalk"=>"netatalk","NCP"=>"NCP"); + if($dn){ + $this->host = substr($dn, 3, strpos($dn, ',')-3); + } + + $this->acl = $acl; + $this->allow_mounts=$allow_mounts; + $this->charsets = array(); if(!file_exists("/etc/gosa/encodings")){ @@ -60,20 +70,23 @@ class servnfs extends plugin $tmp = split("\|",$entry); $this->name = $tmp[0]; // Name of NFS $this->description = $tmp[1]; // description - $this->type = $tmp[2]; // Type NFS/Samba/NCP + $this->type = $tmp[2]; // Type NFS/Samba/NCP/netatalk $this->charset = $tmp[3]; // charset $this->path = $tmp[4]; // Path $this->option = $tmp[5]; // Options $this->is_edit = true; + }else{ $this->attributes[] = "name"; } + + $this->create_mount_init = $mount; } function execute() { - /* Call parent execute */ - plugin::execute(); + /* Call parent execute */ + plugin::execute(); /* Fill templating stuff */ $smarty= get_smarty(); @@ -92,6 +105,44 @@ class servnfs extends plugin if($this->is_edit){ $smarty->assign("nameACL"," disabled "); } + + $smarty->assign("allow_mounts", $this->allow_mounts); + $smarty->assign("mount_checked", ""); + + + $appleMountsACL=chkacl($this->acl,"gotoShareAppleMounts"); + $appleMountsACLset=strpos($appleMountsACL, "disabled"); + $smarty->assign("appleMountsACL", $appleMountsACL); + $smarty->assign("appleMountsACLset", $appleMountsACLset); + + if (($this->type == "netatalk") || ($this->type == "NFS")) { + if ($this->create_mount_init) { + $smarty->assign("mount_checked", "checked"); + } else { + $tmp = split(",", $this->dn); + $clip = $tmp[0] . ",ou=servers,ou=systems,"; + $mountsdn = "cn=mounts," . substr($this->dn, strlen($clip)); + switch ($this->type) { + case "netatalk" : { + $mountdn = "cn=".$this->host.":/".$this->name.",".$mountsdn; + break; + } + case "NFS" : { + $mountdn = "cn=".$this->host.":".$this->path.",".$mountsdn; + break; + } + default : { + continue; + } + } + $ldap = $this->config->get_ldap_link(); + $ldap->cat($mountdn); + $attrs = $ldap->fetch(); + if (count($attrs) > 0) { + $smarty->assign("mount_checked", "checked"); + } + } + } $display= $smarty->fetch(get_template_path('servnfs.tpl', TRUE)); return($display); @@ -112,6 +163,12 @@ class servnfs extends plugin $this->$attr = $_POST[$attr]; } } + + if ((isset($_POST['netatalk_mount'])) && (($this->type == "netatalk") || ($this->type == "NFS"))) { + $this->create_mount = true; + } else { + $this->create_mount = false; + } } @@ -148,6 +205,13 @@ class servnfs extends plugin $message[]=_("Option contains invalid characters."); } + /* remove a / at the end of the path, we neither need it there nor + * do we want to check for it later. + */ + if(substr($this->path, -1, 1) == '/') { + $this->path=substr($this->path, 0, -1); + } + $ldap= $this->config->get_ldap_link(); $ldap->cd($this->config->current['BASE']); $ldap->search("(objectClass=goShareServer)", array("goExportEntry")); @@ -183,6 +247,10 @@ class servnfs extends plugin return(array($this->name=>$s_return)); } + + function should_create_mount() { + return $this->create_mount; + } } diff --git a/plugins/admin/systems/class_servService.inc b/plugins/admin/systems/class_servService.inc index e4984e3de..8b112da81 100644 --- a/plugins/admin/systems/class_servService.inc +++ b/plugins/admin/systems/class_servService.inc @@ -35,10 +35,22 @@ class servservice extends plugin "goMailServer" => array(), "goCupsServer" => array()); + var $allow_mounts = false; //do we allow mount entries? + var $mounts_to_add = array(); + var $mounts_to_remove = array(); + var $oldone = NULL; //temp dave for old mount entry + function servservice ($config, $dn= NULL) { + plugin::plugin ($config, $dn); + $ldap = $this->config->get_ldap_link(); + $avl_objectclasses = @$ldap->get_objectclasses(); + if (isset($avl_objectclasses["mount"])) { + $this->allow_mounts = true; + } + /* Assemble final object class list */ foreach ($this->additionaloc as $oc => $dummy){ if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){ @@ -90,30 +102,52 @@ class servservice extends plugin function deleteFromList($id){ unset($this->goExportEntry[$id]); } - + + 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 execute() { - /* Call parent execute */ - plugin::execute(); + /* Call parent execute */ + plugin::execute(); /* Fill templating stuff */ $smarty= get_smarty(); $smarty->assign("staticAddress", ""); - + if((isset($_POST['DelNfsEnt']))&&(isset($_POST['goExportEntry']))){ + if($this->allow_mounts){ + $this->deleteFromMountList($this->goExportEntry[$_POST['goExportEntry']]); + } $this->deleteFromList($_POST['goExportEntry']); } if(isset($_POST['NewNfsAdd'])){ - $this->o_subWindow = new servnfs($this->config, $this->dn); + $this->oldone = NULL; + $this->o_subWindow = new servnfs($this->config,$this->acl, $this->allow_mounts, $this->dn); $this->dialog = true; } if((isset($_POST['NewNfsEdit']))&&(isset($_POST['goExportEntry']))){ $entry = $this->goExportEntry[$_POST['goExportEntry']]; - $this->o_subWindow = new servnfs($this->config, $this->dn,$entry); + $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->dialog = true; } @@ -130,7 +164,15 @@ class servservice extends plugin }else{ $this->o_subWindow->save_object(); $newone = $this->o_subWindow->save(); - $this->addToList($newone) ; + $this->addToList($newone); + if($this->allow_mounts){ + if($this->oldone) { + $this->deleteFromMountList($this->oldone); + } + if ($this->o_subWindow->should_create_mount()) { + $this->addToMountList($newone); + } + } unset($this->o_subWindow); $this->dialog = false; } @@ -138,6 +180,7 @@ class servservice extends plugin /* Cancel NFS setup */ if(isset($_POST['NFScancel'])){ + $this->oldone = NULL; unset($this->o_subWindow); $this->dialog = false; } @@ -173,7 +216,7 @@ class servservice extends plugin ksort($this->goExportEntry); foreach($this->goExportEntry as $name=>$values){ $tmp = split("\|",$values); - $tellSmarty[$name] = $tmp[0]." ".$tmp[4]; + $tellSmarty[$name] = $tmp[0]." ".$tmp[4]." (".$tmp[2].")"; } $smarty->assign("goExportEntry",array_keys($tellSmarty)); $smarty->assign("goExportEntryKeys",($tellSmarty)); @@ -309,6 +352,11 @@ class servservice extends plugin $this->attrs[$name][]= $element; } } + + /* Process netatalk mounts */ + if($this->allow_mounts) { + $this->process_mounts(); + } /* Remove illegal attributes */ foreach ($this->additionaloc as $oc => $attrs){ @@ -323,7 +371,7 @@ class servservice extends plugin $ldap= $this->config->get_ldap_link(); $ldap->cd($this->dn); $this->cleanup(); -$ldap->modify ($this->attrs); + $ldap->modify ($this->attrs); show_ldap_error($ldap->get_error()); @@ -336,8 +384,103 @@ $ldap->modify ($this->attrs); $this->handle_post_events("add"); } } + + 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); + $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()); + 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); + $attrs = $ldap->fetch(); + + if (count($attrs) != 0) { + $ldap->rmdir($mountdn); + show_ldap_error($ldap->get_error()); + 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()); + gosa_log("Mount object '".$mountdn."' has been added"); + } + } + + 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; + } + +} // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/plugins/admin/systems/servnfs.tpl b/plugins/admin/systems/servnfs.tpl index 095e159d6..8574dec82 100644 --- a/plugins/admin/systems/servnfs.tpl +++ b/plugins/admin/systems/servnfs.tpl @@ -1,7 +1,7 @@

 {t}Edit share{/t}

-
+ @@ -22,7 +22,7 @@
- {t}Path{/t} + {t}Path{/t} {$must} @@ -35,13 +35,35 @@ - diff --git a/plugins/admin/users/class_userManagement.inc b/plugins/admin/users/class_userManagement.inc index f3e3596cd..43360391a 100644 --- a/plugins/admin/users/class_userManagement.inc +++ b/plugins/admin/users/class_userManagement.inc @@ -774,6 +774,8 @@ class userManagement extends plugin name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>"; $sambaimg = ""; + $netatalkimg = ""; $tplcreateuserimg = ""; @@ -885,6 +887,12 @@ class userManagement extends plugin $samba=$empty; } + if(in_array("apple-user" ,$val['objectClass'])){ + $netatalk = preg_replace("/%KEY%/", "$key", $netatalkimg); + }else{ + $netatalk=$empty; + } + if(in_array("gosaUserTemplate",$val['objectClass'])){ $tpl = preg_replace("/%KEY%/", "$key", $tplimg); $s_img_create_from_template = preg_replace("/%KEY%/", "$key", $tplcreateuserimg); @@ -905,7 +913,7 @@ class userManagement extends plugin /* Create each field */ $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'"); $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port, "attach" => "style='' title='dn: ".@LDAP::fix($val['dn'])."'"); - $field3 = array("string" => $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba, "attach" => "style='width:152px;'"); + $field3 = array("string" => $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba." ".$netatalk, "attach" => "style='width:152px;'"); $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),"attach" => "style='width:102px;border-right:0px;text-align:right;'"); $add = array($field1,$field2,$field3,$field4); diff --git a/plugins/personal/netatalk/class_netatalk.inc b/plugins/personal/netatalk/class_netatalk.inc new file mode 100644 index 000000000..9c65c8c2e --- /dev/null +++ b/plugins/personal/netatalk/class_netatalk.inc @@ -0,0 +1,328 @@ + + Copyright (C) 2006 Bernd Zeimetz + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*! \brief netatalk plugin + \author Gina Haeussge + \author Bernd Zeimetz + \version 0.1 + \date 21.3.2006 + + This class provides the functionality to read and write all attributes + relevant for netatalk from/to the LDAP. It does syntax checking + and displays the formulars required. + */ + +class netatalk extends plugin { + + /* Definitions */ + var $plHeadline = "Netatalk"; + var $plDescription = "Manage netatalk account"; + + /* CLI vars */ + var $cli_summary = "Manage netatalk account"; + var $cli_description = "Manage Account \nfor netatalk"; + var $cli_parameters = array ("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* Plugin specific values */ + var $apple_user_homepath_raw = ""; + var $apple_user_homeurl_raw = ""; + var $apple_user_homeurl_xml = ""; + var $apple_user_homeurl = ""; + var $apple_user_homeDirectory = ""; + var $apple_user_share = ""; + var $shares = array(); + var $shares_settings = array(); + var $selectedshare = ""; + var $mountDirectory = "/Network/Servers"; + + /* Attributes to save to LDAP */ + var $attributes = array ("apple-user-homeurl", "apple-user-homeDirectory"); + + /* Attributes to use in smarty template */ + var $smarty_attributes = array ("apple_user_homepath_raw", "shares", "selectedshare"); + + /* Attributes to save from $_POST */ + var $post_attributes = array ("apple_user_share", "apple_user_homepath_raw"); + + /* Objectclasses */ + var $objectclasses = array ("apple-user"); + + /* Checkboxes */ + var $is_chk_box = array (); + + + /* The constructor just saves a copy of the config. You may add what ever you need. */ + function netatalk($config, $dn = NULL) { + + /* Include config object */ + $this->config = $config; + plugin :: plugin($config, $dn); + + /* Copy needed attributes */ + foreach($this->attributes as $val) { + if (isset($this->attrs["$val"][0])) { + $name = str_replace('-', '_', $val); + $this->$name = $this->attrs["$val"][0]; + } + } + + if (strlen($this->apple_user_homeDirectory) >0) { + $this->apple_user_homepath_raw = substr($this->apple_user_homeDirectory, strrpos($this->apple_user_homeDirectory, '/') + 1 ); + } + + /* Save initial account state */ + $this->initially_was_account = $this->is_account; + } + + /* Execute the plugin, produce the output. */ + function execute() { + plugin :: execute(); + + /* Use the smarty templating engine here... */ + $smarty = get_smarty(); + $display = ""; + + /* Do we need to flip is_account state? */ + if (isset ($_POST['modify_state'])) { + $this->is_account = !$this->is_account; + } + + /* Do we represent a valid account? */ + if (!$this->is_account && $this->parent == NULL) { + $display = "\"\"src=\"images/stop.png\" "._("This account has no netatalk extensions.").""; + + $display .= back_to_main(); + return ($display); + } + + + /* Get netatalk shares */ + $this->shares = array(); + $ldap = $this->config->get_ldap_link(); + + if($this->dn === "new" || $this->dn == NULL) { + $ldap->cd($this->parent->by_object['user']->base); + } else { + $ldap->cd ($this->dn); + $ldap->cd ('..'); $ldap->cd ('..'); + } + $ldap->search ("(&(objectClass=mount)(|(mountType=url)(mountType=nfs))(cn=*))"); + + + /* Show tab dialog headers */ + if ($this->parent != NULL) { + if ($this->is_account) { + $display = $this->show_header(_("Remove netatalk account"), _("This account has netatalk features enabled. You can disable them by clicking below.")); + } else { + $errmsg=""; + $obj = $this->parent->by_object['posixAccount']; + if (!($obj->is_account) ) { + $errmsg.="Posix features are needed for netatalk accounts, enable them first. "; + } + if ($ldap->count() == 0) { + $errmsg.="At least one share with netatalk or NFS mount entry needed."; + } + if($errmsg==""){ + $display = $this->show_header(_("Create netatalk account"), _("This account has netatalk features disabled. You can enable them by clicking below.")); + } else { + $display = $this->show_header(_("Create netatalk account"), _($errmsg), TRUE); + } + return ($display); + } + } + + + while ($attrs = $ldap->fetch()){ + $tmp = split(":", $attrs["cn"][0]); + $host = trim($tmp[0]); + $dir = trim($tmp[1]); + $mountType = trim($attrs["mountType"][0]); + if ($mountType == "url") { + $mountTypeReal = "netatalk"; + } else { + $mountTypeReal = $mountType; + } + $share = $attrs["cn"][0]. " (" . $mountTypeReal . ")"; + $this->shares[$share] = $share; + $this->shares_settings[$share]["mountType"]=$mountType; + $this->shares_settings[$share]["dir"]=$dir; + $this->shares_settings[$share]["host"]=$host; + + $oldShare=substr($this->apple_user_homeDirectory, 0, strrpos($this->apple_user_homeDirectory, '/')); + $newShare=($this->mountDirectory . "/". $host . $dir ); + if (strcmp($oldShare, $newShare)==0) { + $this->selectedshare = $share; + } + } + asort($this->shares); + /* Assign attributes and ACL to smarty */ + + $smarty->assign("netatalkShareACL", chkacl($this->acl, "netatalkShare")); + $smarty->assign("netatalkUserHomepathACL", chkacl($this->acl, "netatalkUserHomepath")); + foreach ($this->smarty_attributes as $val) { + $smarty->assign("$val", $this-> $val); + if (in_array($val, $this->is_chk_box)) { + if ($this-> $val == "checked") { + $smarty->assign($val."CHK", " checked "); + } else { + $smarty->assign($val."CHK", ""); + } + } + } + + /* Let smarty fetch and process the page. */ + $display .= ($smarty->fetch(get_template_path('netatalk.tpl', TRUE, dirname(__FILE__)))); + return ($display); + } + + + /* Check if we have correct data */ + function check() { + $message = array (); + + if (strlen($this->apple_user_share) == 0) { + $message[] = _("You must select a share to use."); + } + + return ($message); + } + + /* Save to LDAP */ + function save() { + /* remove a / at the end of the homepath, we neither need it there nor + * do we want to check for it later. + */ + if(substr($this->apple_user_homepath_raw, -1, 1) === '/') { + $this->apple_user_homepath_raw=substr($this->apple_user_homepath_raw, 0, -1); + } + + $mountType=$this->shares_settings[$this->apple_user_share]["mountType"]; + $dir=$this->shares_settings[$this->apple_user_share]["dir"]; + $host=$this->shares_settings[$this->apple_user_share]["host"]; + + /* Convert raw data to wished format */ + if ($this->is_account) { + if($mountType=="url") { + $this->apple_user_homeurl_xml = 'afp://'.$host.$dir . ''.$this->apple_user_homepath_raw.''; + $this->apple_user_homeurl = base64_encode($this->apple_user_homeurl_xml); + } else { + $this->apple_user_homeurl = ""; + } + $this->apple_user_homeDirectory = $this->mountDirectory . '/' . $host .$dir . '/' . $this->apple_user_homepath_raw; + } else { + $this->apple_user_homeurl = ""; + $this->apple_user_homeDirectory = ""; + } + + $ldap = $this->config->get_ldap_link(); + + /* Call parents save to prepare $this->attrs */ + plugin :: save(); + + /* Do attribute conversion */ + foreach ($this->attributes as $val) { + $name = str_replace('-', '_', $val); + if ($this->$name != "") { + $this->attrs[$val] = $this->$name; + } else { + $this->attrs[$val] = array(); + } + unset ($this->attrs[$name]); + } + + /* Write back to ldap */ + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify($this->attrs); + + show_ldap_error($ldap->get_error()); + + /* Optionally execute a command after we're done */ + if ($this->initially_was_account == $this->is_account) { + if ($this->is_modified) { + $this->handle_post_events("modify"); + } + } else { + $this->handle_post_events("add"); + } + } + + /* Use Save_object for every Post handling */ + function save_object() { + if (isset ($_POST['netatalkTab'])) { + /* Save ldap attributes */ + plugin :: save_object(); + + foreach($this->post_attributes as $val) { + if (isset ($_POST[$val])) { + $this->$val = $_POST[$val]; + } else { + $this->$val = ""; + } + } + + /* Specialhandling for checkboxes */ + foreach ($this->is_chk_box as $val) { + if (isset ($_POST[$val])) { + $this-> $val = "checked"; + } else { + $this-> $val = "unchecked"; + } + } + + $this->apple_user_homeurl_raw = 'afp://' . $this->apple_user_share; + } + } + + function remove_from_parent() { + /* Cancel if there's nothing to do here */ + if (!$this->initially_was_account) { + return; + } + + /* include global link_info */ + $ldap = $this->config->get_ldap_link(); + + /* Remove and write to LDAP */ + plugin :: remove_from_parent(); + + /* Adapt attributes if needed */ + // $method= new $this->method($this->config); + // $method->fixAttributesOnRemove($this); + + @ DEBUG(DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $this->attributes, "Save"); + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify($this->attrs); + + show_ldap_error($ldap->get_error()); + + /* remove the entry from LDAP */ + unset ($this->attrs['uid']); + + /* Optionally execute a command after we're done */ + $this->handle_post_events('remove'); + } + +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/personal/netatalk/main.inc b/plugins/personal/netatalk/main.inc new file mode 100644 index 000000000..b11774eab --- /dev/null +++ b/plugins/personal/netatalk/main.inc @@ -0,0 +1,126 @@ + + Copyright (C) 2006 Bernd Zeimetz + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +if (!$remove_lock) { + /* Reset requested? */ + if (isset ($_POST['edit_cancel']) || (isset ($_GET['reset']) && $_GET['reset'] == 1)) { + del_lock($ui->dn); + sess_del('edit'); + sess_del('netatalk'); + } + + /* Create netatalk object on demand */ + if (!isset ($_SESSION['netatalk']) || (isset ($_GET['reset']) && $_GET['reset'] == 1)) { + $_SESSION['netatalk'] = new netatalk($config, $ui->dn); + } + $netatalk = $_SESSION['netatalk']; + + /* save changes back to object */ + if (isset ($_SESSION['edit'])) { + $netatalk->save_object(); + } + + /* Enter edit mode? */ + if (isset ($_POST['edit'])) { + + /* Check locking */ + if (($username = get_lock($ui->dn)) != "") { + $_SESSION['back_plugin'] = $plug; + gen_locked_message($username, $ui->dn); + exit (); + } + + /* Lock the current entry */ + add_lock($ui->dn, $ui->dn); + $_SESSION['dn'] = $ui->dn; + $_SESSION['edit'] = TRUE; + } + + /* Adjust acl's to mode */ + if (isset ($_SESSION['edit'])) { + $acl = get_permissions($ui->dn, $ui->subtreeACL); + $netatalk->acl = get_module_permission($acl, "netatalk", $ui->dn); + } else { + $acl = get_permissions($ui->dn, $ui->subtreeACL); + $editacl = get_module_permission($acl, "netatalk", $ui->dn); + $netatalk->acl = "#none#"; + } + + /* save changes to LDAP and disable edit mode */ + if (isset ($_POST['edit_finish'])) { + + /* Perform checks */ + $message = $netatalk->check(); + + /* No errors, save object */ + if (count($message) == 0) { + $netatalk->save(); + gosa_log("User/netatalk object'".$ui->dn."' has been saved"); + $netatalk->acl = "#none#"; + del_lock($ui->dn); + sess_del('edit'); + + /* Store object */ + $_SESSION['netatalk'] = $netatalk; + } else { + /* Errors found, show message */ + show_errors($message); + } + } + + /* Execute formular */ + $display = $netatalk->execute(); + + /* Store changes in session */ + if (isset ($_SESSION['edit'])) { + $_SESSION['netatalk'] = $netatalk; + } + + $info = ""; + /* Show page footer depending on the mode */ + if ($netatalk->is_account) { + $display .= "

"; + + /* Are we in edit mode? */ + if (isset ($_SESSION['edit'])) { + $display .= "\n"; + $display .= " "; + $display .= "\n"; + $info = "\"\" ".$ui->dn." "; + } else { + $info = "\"\" ".$ui->dn." "; + if (isset ($editacl) && $editacl != "#none#") { + $info .= "\"\" "._("Click the 'Edit' button below to change informations in this dialog"); + $display .= "\n"; + } + + $display .= "\n"; + } + $display .= "

\n"; + } + + /* Page header*/ + $display = print_header(get_template_path('images/netatalk.png'), _("Netatalk settings"), $info).$display; + +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/personal/netatalk/netatalk.tpl b/plugins/personal/netatalk/netatalk.tpl new file mode 100644 index 000000000..0f5b4a039 --- /dev/null +++ b/plugins/personal/netatalk/netatalk.tpl @@ -0,0 +1,26 @@ +
+ {t}Type{/t} - + + {if $allow_mounts == TRUE} +

+ {if $appleMountsACLset == FALSE} + {literal} + + {/literal} + {/if} +
+
+ {/if}
+ + + + + + + +
+ + + +
+ + + +
+ + + + +