1 <?php
3 class servnfs extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary = "Manage server objects";
7 var $cli_description = "Some longer text\nfor help";
8 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 /* attribute list for save action */
11 var $ignore_account = TRUE;
12 var $attributes = array("description","type","charset","path","option", "volume");
13 var $objectclasses = array("whatever");
14 var $is_account = true;
16 var $name =""; // Name of
17 var $description =""; // description
18 var $type =""; // Type FS/Samba/NCP
19 var $charset =""; // charset
20 var $host =""; // hostname
21 var $types =array(); // Array Types NFS/Samba/NCP/netatalk
22 var $charsets =array(); // Array with charsets
23 var $path =""; // Path
24 var $volume =""; // Volume
25 var $option =""; // Options
26 var $is_edit =false;
27 var $create_mount_init = false; //mount entry set for this entry (while editing)?
28 var $create_mount = false; //save mount entry
30 var $parent = NULL;
32 function servnfs ($config, $parent,$entry= false,$mount =false)
33 {
34 $this->parent = $parent;
35 $dn = $parent->dn;
36 plugin::plugin ($config, $dn);
38 $this->types = array("CIFS" => "CIFS", "NFS"=>"NFS","samba"=>"samba","netatalk"=>"netatalk","NCP"=>"NCP");
39 if($dn){
40 $this->host = substr($dn, 3, strpos($dn, ',')-3);
41 }
43 $this->charsets = array();
45 if(!file_exists(CONFIG_DIR."/encodings")){
46 print_red(sprintf(_("The file '%s/encodings' does not exist, can't get supported charsets."),CONFIG_DIR));
47 }else{
48 if(!is_readable(CONFIG_DIR."/encodings")){
49 print_red(sprintf(_("Can't read '%s/encodings', please check permissions."),CONFIG_DIR));
50 }else{
51 $fp = fopen(CONFIG_DIR."/encodings","r");
52 $i = 100;
53 while(!feof($fp)&&$i){
54 $i -- ;
55 $str = trim(fgets($fp,256));
57 /* Skip comments */
58 if(!preg_match("/^#/",$str)){
59 $arr = split("\=",$str);
60 if(count($arr)==2){
61 $this->charsets[$arr[0]]=$arr[1];
62 }
63 }
64 }
65 }
66 }
68 if($entry){
69 list($this->name, $this->description, $this->type, $this->charset,
70 $this->path, $this->option, $this->volume)= split("\|",$entry."|");
71 $this->is_edit = true;
73 }else{
74 $this->attributes[] = "name";
75 }
78 $this->create_mount_init = $mount;
79 }
81 function execute()
82 {
83 /* Call parent execute */
84 plugin::execute();
86 /* Fill templating stuff */
87 $smarty= get_smarty();
89 $smarty->assign("charsets" ,$this->charsets);
90 $smarty->assign("types" ,$this->types);
92 /* attrs to smarty*/
93 foreach($this->attributes as $attr){
94 $smarty->assign($attr,$this->$attr);
95 }
97 $tmp = $this->parent->plInfo();
98 foreach($tmp['plProvidedAcls'] as $name => $translation){
99 $smarty->assign($name."ACL",$this->parent->getacl($name));
100 }
102 $smarty->assign("name",$this->name);
103 if($this->is_edit){
104 $smarty->assign("nameACL", preg_replace("/w/","",$this->parent->getacl("name")));
105 }
106 $smarty->assign("allow_mounts", $this->parent->allow_mounts);
107 $smarty->assign("mount_checked", "");
109 $smarty->assign("appleMountsACL", $this->getacl("appleMounts"));
111 if (($this->type == "netatalk") || ($this->type == "NFS")) {
112 if ($this->create_mount_init) {
113 $smarty->assign("mount_checked", "checked");
114 } else {
115 $tmp = split(",", $this->dn);
116 $clip = $tmp[0] . ",ou=servers,ou=systems,";
117 $mountsdn = "cn=mounts," . substr($this->dn, strlen($clip));
118 switch ($this->type) {
119 case "netatalk" : {
120 $mountdn = "cn=".$this->host.":/".$this->name.",".$mountsdn;
121 break;
122 }
123 case "NFS" : {
124 $mountdn = "cn=".$this->host.":".$this->path.",".$mountsdn;
125 break;
126 }
127 default : {
128 continue;
129 }
130 }
131 $ldap = $this->config->get_ldap_link();
132 $ldap->cat($mountdn, array('dn'));
133 $attrs = $ldap->fetch();
134 if (count($attrs) > 0) {
135 $smarty->assign("mount_checked", "checked");
136 }
137 }
138 }
140 $display= $smarty->fetch(get_template_path('servnfs.tpl', TRUE));
141 return($display);
142 }
144 function remove_from_parent()
145 {
146 /* This cannot be removed... */
147 }
150 /* Save data to object */
151 function save_object()
152 {
153 if(isset($_POST['servnfs_posted'])){
155 foreach($this->attributes as $name){
156 if($this->parent->acl_is_writeable($name) && isset($_POST[$name])){
157 $this->$name = $_POST[$name];
158 }
159 }
161 if ((isset($_POST['netatalk_mount'])) && (($this->type == "netatalk") || ($this->type == "NFS"))) {
162 $this->create_mount = true;
163 } else {
164 $this->create_mount = false;
165 }
166 }
167 }
170 /* Check supplied data */
171 function check()
172 {
173 /* Call common method to give check the hook */
174 $message= plugin::check();
176 // fixme : a check for the path ? ?
177 if(empty($this->path)){
178 $message[]=_("Please specify a valid path for your setup.");
179 }
181 // only 0-9a-z
182 if(!$this->is_edit){
183 if(!preg_match("/^[a-z0-9\._]+$/i",$this->name)){
184 $message[]=_("Please specify a valid name for your share.");
185 }
186 if(empty($this->name)){
187 $message[]=_("Please specify a name for your share.");
188 }
189 }
191 if(preg_match("/[^a-z0-9äöü._+ -]+/i",$this->description)){
192 $message[]=_("Description contains invalid characters.");
193 }
195 if(preg_match("/[^a-z0-9._+ -]/i",$this->volume)){
196 $message[]=_("Volume contains invalid characters.");
197 }
199 if(preg_match("/\|/",$this->path)){
200 $message[]=_("Path contains invalid characters.");
201 }
203 if(preg_match("/[^a-z0-9\.,=_+ -]/i",$this->option)){
204 $message[]=_("Option contains invalid characters.");
205 }
207 /* remove a / at the end of the path, we neither need it there nor
208 * do we want to check for it later.
209 */
210 if(substr($this->path, -1, 1) == '/') {
211 $this->path=substr($this->path, 0, -1);
212 }
214 $ldap= $this->config->get_ldap_link();
215 $ldap->cd($this->config->current['BASE']);
216 $ldap->search("(objectClass=goShareServer)", array("goExportEntry"));
217 while($test = $ldap->fetch()){
218 if($test['dn']==$this->dn)
219 continue;
220 if(isset($test['goExportEntry'])){
221 foreach($test['goExportEntry'] as $entry){
222 $tmp = split("\|",$entry);
223 if($tmp[0] == $this->name){
224 $message[]="Name already in use";
225 }
226 }
227 }
228 }
229 return ($message);
230 }
233 /* Save to LDAP */
234 function save()
235 {
236 /* Everything seems perfect, lets
237 generate an new export Entry
238 */
240 $s_return = "";
242 $s_return.= $this->name."|";
243 $s_return.= $this->description."|";
244 $s_return.= $this->type."|";
245 $s_return.= $this->charset."|";
246 $s_return.= $this->path."|";
247 $s_return.= $this->option."|";
248 $s_return.= $this->volume;
250 return(array($this->name=>$s_return));
251 }
253 function should_create_mount() {
254 return $this->create_mount;
255 }
258 }
260 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
261 ?>