Code

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