Code

Removed CLI
[gosa.git] / gosa-plugins / goto / admin / systems / services / nfs / 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 $create_mount_init = false; //mount entry set for this entry (while editing)?
23   var $create_mount = false; //save mount entry
25   var $parent       = NULL;
26   var $view_logged  = FALSE;
28   function servnfs (&$config, $parent,$entry= false,$mount =false)
29   {
30     $this->parent = $parent;
31     $dn = $parent->dn;
32     plugin::plugin ($config, $dn);
34     $this->types   = array("CIFS" => "CIFS", "NFS"=>"NFS","samba"=>"samba","netatalk"=>"netatalk","NCP"=>"NCP");
35     if($dn){
36       $this->host = substr($dn, 3, strpos($dn, ',')-3);
37     }
39     $this->charsets = array();
41     if(!file_exists(CONFIG_DIR."/encodings")){
42       print_red(sprintf(_("The file '%s/encodings' does not exist, can't get supported charsets."),CONFIG_DIR));
43     }else{
44       if(!is_readable(CONFIG_DIR."/encodings")){
45         print_red(sprintf(_("Can't read '%s/encodings', please check permissions."),CONFIG_DIR));
46       }else{
47         $fp = fopen(CONFIG_DIR."/encodings","r");
48         $i = 100;
49         while(!feof($fp)&&$i){
50           $i -- ;
51           $str = trim(fgets($fp,256));
53           /* Skip comments */
54           if(!preg_match("/^#/",$str)){
55             $arr = split("\=",$str);
56             if(count($arr)==2){
57               $this->charsets[$arr[0]]=$arr[1];
58             }
59           }
60         }
61       }
62     }
64     if($entry){
65       list($this->name, $this->description, $this->type, $this->charset,
66           $this->path, $this->option, $this->volume)= split("\|",$entry."|");
67       $this->is_edit          = true;
69     }else{
70       $this->attributes[] = "name";
71     }
74     $this->create_mount_init = $mount;
75   }
77   function execute()
78   {
79     /* Call parent execute */
80     plugin::execute();
82     if($this->is_account && !$this->view_logged){
83       $this->view_logged = TRUE;
84       new log("view","server/".get_class($this),$this->dn);
85     }
87     /* Fill templating stuff */
88     $smarty= get_smarty();
90     $smarty->assign("charsets" ,$this->charsets);
91     $smarty->assign("types"    ,$this->types);
93     /* attrs to smarty*/
94     foreach($this->attributes as $attr){
95       $smarty->assign($attr,$this->$attr);
96     }
98     $tmp = $this->parent->plInfo();
99     foreach($tmp['plProvidedAcls'] as $name => $translation){
100       $smarty->assign($name."ACL",$this->parent->getacl($name));
101     }
103     $smarty->assign("name",$this->name);
104     if($this->is_edit){
105       $smarty->assign("nameACL", preg_replace("/w/","",$this->parent->getacl("name")));
106     } 
107     $smarty->assign("allow_mounts", $this->parent->allow_mounts);
108     $smarty->assign("mount_checked", "");
110     $smarty->assign("appleMountsACL",    $this->getacl("appleMounts"));
112     if (($this->type == "netatalk") || ($this->type == "NFS")) {
113       if ($this->create_mount_init) {
114         $smarty->assign("mount_checked", "checked");
115       } else {
116         $tmp = split(",", $this->dn);
117         $clip = $tmp[0] . ",".get_ou('serverou');
118         $mountsdn = "cn=mounts," . substr($this->dn, strlen($clip));
119         switch ($this->type) {
120           case "netatalk" : {
121             $mountdn = "cn=".$this->host.":/".$this->name.",".$mountsdn;
122             break;
123           }
124           case "NFS" : {
125             $mountdn = "cn=".$this->host.":".$this->path.",".$mountsdn;
126             break;
127           }
128           default : {
129                       continue;
130                     }
131         }
132         $ldap = $this->config->get_ldap_link();
133         $ldap->cat($mountdn, array('dn'));
134         $attrs = $ldap->fetch();
135         if (count($attrs) > 0) {
136           $smarty->assign("mount_checked", "checked");
137         }
138       }        
139     }
141     $display= $smarty->fetch(get_template_path('servnfs.tpl', TRUE));
142     return($display);
143   }
145   function remove_from_parent()
146   {
147     /* This cannot be removed... */
148   }
151   /* Save data to object */
152   function save_object()
153   {
154     if(isset($_POST['servnfs_posted'])){
156       foreach($this->attributes as $name){
157         if($this->parent->acl_is_writeable($name) && isset($_POST[$name])){
158           $this->$name = $_POST[$name];
159         }
160       }
162       if ((isset($_POST['netatalk_mount'])) && (($this->type == "netatalk") || ($this->type == "NFS"))) {
163         $this->create_mount = true;
164       } else {
165         $this->create_mount = false;
166       }
167     }
168   }
171   /* Check supplied data */
172   function check()
173   {
174     /* Call common method to give check the hook */
175     $message= plugin::check();
177     // fixme : a check for the path ?  ? 
178     if(empty($this->path)){
179       $message[]=_("Please specify a valid path for your setup.");
180     }
182     // only 0-9a-z
183     if(!$this->is_edit){
184       if(!preg_match("/^[a-z0-9\._äüö]*$/ui",$this->name)){
185         $message[]=_("Please specify a valid name for your share.");
186       }
187       if(empty($this->name)){
188         $message[]=_("Please specify a name for your share.");
189       }
190     }
192     if(!empty($this->description) && preg_match("/^[^a-z0-9\._äüö\+ -]*$/ui",$this->description)){
193       $message[]=_("Description contains invalid characters.");
194     }
196     if(!empty($this->volume) && preg_match("/^[^a-z0-9\._äüö\+ -]*$/ui",$this->volume)){
197       $message[]=_("Volume contains invalid characters.");
198     }
200     if(preg_match("/\|/",$this->path)){
201       $message[]=_("Path contains invalid characters.");
202     }
204     if(!empty($this->option) && preg_match("/^[^a-z0-9\._äüö,=\+ -]*$/ui",$this->option)){
205       $message[]=_("Option contains invalid characters.");
206     }
208     /* remove a / at the end of the path, we neither need it there nor
209      * do we want to check for it later.
210      */
211     if(substr($this->path, -1, 1) == '/') {
212       $this->path=substr($this->path, 0, -1);
213     }
215     $ldap= $this->config->get_ldap_link();
216     $ldap->cd($this->config->current['BASE']);
217     $ldap->search("(objectClass=goShareServer)", array("goExportEntry"));
218     while($test = $ldap->fetch()){
219       if($test['dn']==$this->dn)
220         continue;
221       if(isset($test['goExportEntry'])){
222         foreach($test['goExportEntry'] as $entry){
223           $tmp = split("\|",$entry);
224           if($tmp[0] == $this->name){
225             $message[]="Name already in use";
226           }
227         }
228       }
229     }
230     return ($message);
231   }
234   /* Save to LDAP */
235   function save()
236   {
237     /* Everything seems perfect, lets 
238        generate an new export Entry 
239      */
241     $s_return = "";
243     $s_return.= $this->name."|";     
244     $s_return.= $this->description."|";     
245     $s_return.= $this->type."|";     
246     $s_return.= $this->charset."|";     
247     $s_return.= $this->path."|";     
248     $s_return.= $this->option."|";     
249     $s_return.= $this->volume;     
251     return(array($this->name=>$s_return));
252   }
254   function should_create_mount() {
255     return $this->create_mount;
256   }
261 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
262 ?>