Code

Fixed error messages in servnfs:
[gosa.git] / plugins / admin / systems / class_servNfs.inc
1 <?php
3 class servnfs extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account   = TRUE;
7   var $attributes       = array("description","type","charset","path","option", "volume");
8   var $objectclasses    = array("whatever");
9   var $is_account       = true;
11   var $name          ="";  // Name of  
12   var $description   ="";  // description
13   var $type          ="";  // Type FS/Samba/NCP
14   var $charset       ="";  // charset
15   var $host       ="";  // hostname
16   var $types         =array();  // Array Types NFS/Samba/NCP/netatalk
17   var $charsets      =array();  // Array with charsets
18   var $path          ="";  // Path
19   var $volume        ="";  // Volume
20   var $option        ="";  // Options
21   var $is_edit           =false;
22   var $allow_mounts = false; //do we allow mount entries?
23   var $create_mount_init = false; //mount entry set for this entry (while editing)?
24   var $create_mount = false; //save mount entry
26   function servnfs ($config, $acl, $allow_mounts, $dn= NULL,$entry = false,$mount = false)
27   {
28     plugin::plugin ($config, $dn);
29     
30     $this->types   = array("CIFS" => "CIFS", "NFS"=>"NFS","samba"=>"samba","netatalk"=>"netatalk","NCP"=>"NCP");
31     if($dn){
32       $this->host = substr($dn, 3, strpos($dn, ',')-3);
33     }
34     
35     $this->acl = $acl;
36         $this->allow_mounts=$allow_mounts;
37         
38     $this->charsets = array();
40     if(!file_exists(CONFIG_DIR."/encodings")){
41       print_red(sprintf(_("The file '%s/encodings' does not exist, can't get supported charsets."),CONFIG_DIR));
42     }else{
43       if(!is_readable(CONFIG_DIR."/encodings")){
44         print_red(sprintf(_("Can't read '%s/encodings', please check permissions."),CONFIG_DIR));
45       }else{
46         $fp = fopen(CONFIG_DIR."/encodings","r");
47         $i = 100;
48         while(!feof($fp)&&$i){
49           $i -- ;
50           $str = trim(fgets($fp,256));
51       
52           /* Skip comments */
53           if(!preg_match("/^#/",$str)){
54             $arr = split("\=",$str);
55             if(count($arr)==2){
56               $this->charsets[$arr[0]]=$arr[1];
57             }
58           }
59         }
61     
62       }
63     }
65     if($entry){
66       list($this->name, $this->description, $this->type, $this->charset,
67            $this->path, $this->option, $this->volume)= split("\|",$entry."|");
68       $this->is_edit          = true;
70     }else{
71       $this->attributes[] = "name";
72     }
74     
75     $this->create_mount_init = $mount;
76   }
78   function execute()
79   {
80     /* Call parent execute */
81     plugin::execute();
83     /* Fill templating stuff */
84     $smarty= get_smarty();
86     $smarty->assign("charsets" ,$this->charsets);
87     $smarty->assign("types"    ,$this->types);
89     /* attrs to smarty*/
90     foreach($this->attributes as $attr){
91       $smarty->assign($attr,$this->$attr);
92     }
94     $smarty->assign("nameACL","");    
95     $smarty->assign("name",$this->name);
97     if($this->is_edit){
98       $smarty->assign("nameACL"," disabled ");
99     }
100     
101     $smarty->assign("allow_mounts", $this->allow_mounts);
102     $smarty->assign("mount_checked", "");
103     
104     
105     $appleMountsACL=chkacl($this->acl,"gotoShareAppleMounts");
106     $appleMountsACLset=strpos($appleMountsACL, "disabled");
107     $smarty->assign("appleMountsACL", $appleMountsACL);
108     $smarty->assign("appleMountsACLset", $appleMountsACLset);
109   
110     if (($this->type == "netatalk") || ($this->type == "NFS")) {
111         if ($this->create_mount_init) {
112           $smarty->assign("mount_checked", "checked");
113         } else {
114         $tmp = split(",", $this->dn);
115         $clip = $tmp[0] . ",ou=servers,ou=systems,";
116         $mountsdn = "cn=mounts," . substr($this->dn, strlen($clip));
117           switch ($this->type) {
118             case "netatalk" : {
119               $mountdn = "cn=".$this->host.":/".$this->name.",".$mountsdn;
120               break;
121             }
122             case "NFS" : {
123               $mountdn = "cn=".$this->host.":".$this->path.",".$mountsdn;
124               break;
125             }
126             default : {
127               continue;
128             }
129           }
130         $ldap = $this->config->get_ldap_link();
131         $ldap->cat($mountdn, array('dn'));
132         $attrs = $ldap->fetch();
133         if (count($attrs) > 0) {
134             $smarty->assign("mount_checked", "checked");
135         }
136         }        
137     }
139     $display= $smarty->fetch(get_template_path('servnfs.tpl', TRUE));
140     return($display);
141   }
143   function remove_from_parent()
144   {
145     /* This cannot be removed... */
146   }
149   /* Save data to object */
150   function save_object()
151   {
152     plugin::save_object(TRUE);
153     if(isset($_POST['path'])){
154       foreach($this->attributes as $attr){
155         $this->$attr = $_POST[$attr];
156       }
157     }
158     
159     if ((isset($_POST['netatalk_mount'])) && (($this->type == "netatalk") || ($this->type == "NFS"))) {
160         $this->create_mount = true;
161     } else {
162         $this->create_mount = false;
163     }
164   }
167   /* Check supplied data */
168   function check()
169   {
170     /* Call common method to give check the hook */
171     $message= plugin::check();
173     // fixme : a check for the path ?  ? 
174     if(empty($this->path)){
175       $message[]=_("Please specify a valid path for your setup.");
176     }
178     // Skip if there are diallowed characters 
179     if(!$this->is_edit){
180       if(!preg_match("/^[a-z0-9\._\-äüö]*$/ui",$this->name)){
181         $message[]=_("Please specify a valid name for your share.");
182       }
183       if(empty($this->name)){
184         $message[]=_("Please specify a name for your share.");
185       }
186     }
188     if(!empty($this->description) && preg_match("/^[^a-z0-9\._äüö\+ -]*$/ui",$this->description)){
189       $message[]=_("Description contains invalid characters.");
190     }
192     if(!empty($this->volume) && preg_match("/^[^a-z0-9\._äüö\+ -]*$/ui",$this->volume)){
193       $message[]=_("Volume contains invalid characters.");
194     }
195   
196     if(preg_match("/\|/",$this->path)){
197       $message[]=_("Path contains invalid characters.");
198     }
200     if(!empty($this->option) && preg_match("/^[^a-z0-9\._äüö,=\+ -]*$/ui",$this->option)){
201       $message[]=_("Option contains invalid characters.");
202     }
204   /* remove a / at the end of the path, we neither need it there nor
205    * do we want to check for it later.
206    */
207   if(substr($this->path, -1, 1) == '/') {
208     $this->path=substr($this->path, 0, -1);
209   }
210   
211     $ldap= $this->config->get_ldap_link();
212     $ldap->cd($this->config->current['BASE']);
213     $ldap->search("(objectClass=goShareServer)", array("goExportEntry"));
214     while($test = $ldap->fetch()){
215       if($test['dn']==$this->dn)
216         continue;
217       if(isset($test['goExportEntry'])){
218         foreach($test['goExportEntry'] as $entry){
219           $tmp = split("\|",$entry);
220           if($tmp[0] == $this->name){
221             $message[]="Name already in use";
222           }
223         }
224       }
225     }
226     return ($message);
227   }
230   /* Save to LDAP */
231   function save()
232   {
233     /* Everything seems perfect, lets 
234        generate an new export Entry 
235      */
237     $s_return = "";
239     $s_return.= $this->name."|";     
240     $s_return.= $this->description."|";     
241     $s_return.= $this->type."|";     
242     $s_return.= $this->charset."|";     
243     $s_return.= $this->path."|";     
244     $s_return.= $this->option."|";     
245     $s_return.= $this->volume;     
247     return(array($this->name=>$s_return));
248   }
249   
250   function should_create_mount() {
251     return $this->create_mount;
252   }
256 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
257 ?>