Code

Revmoced encoding for servers
[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 $allow_mounts = false; //do we allow mount entries?
28   var $create_mount_init = false; //mount entry set for this entry (while editing)?
29   var $create_mount = false; //save mount entry
31   function servnfs ($config, $acl, $allow_mounts, $dn= NULL,$entry = false,$mount = false)
32   {
33     plugin::plugin ($config, $dn);
34     
35     $this->types   = array("CIFS" => "CIFS", "NFS"=>"NFS","samba"=>"samba","netatalk"=>"netatalk","NCP"=>"NCP");
36     if($dn){
37       $this->host = substr($dn, 3, strpos($dn, ',')-3);
38     }
39     
40     $this->acl = $acl;
41         $this->allow_mounts=$allow_mounts;
42         
43     $this->charsets = array();
45     if(!file_exists("/etc/gosa/encodings")){
46       print_red(_("The file '/etc/gosa/encodings' does not exist, can't get supported charsets."));
47     }else{
48       if(!is_readable("/etc/gosa/encodings")){
49         print_red(_("Can't read '/etc/gosa/encodings', please check permissions."));
50       }else{
51         $fp = fopen("/etc/gosa/encodings","r");
52         $i = 100;
53         while(!feof($fp)&&$i){
54           $i -- ;
55           $str = trim(fgets($fp,256));
56       
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         }
66     
67       }
68     }
70     if($entry){
71       list($this->name, $this->description, $this->type, $this->charset,
72            $this->path, $this->option, $this->volume)= split("\|",$entry."|");
73       $this->is_edit          = true;
75     }else{
76       $this->attributes[] = "name";
77     }
79     
80     $this->create_mount_init = $mount;
81   }
83   function execute()
84   {
85     /* Call parent execute */
86     plugin::execute();
88     /* Fill templating stuff */
89     $smarty= get_smarty();
91     $smarty->assign("charsets" ,$this->charsets);
92     $smarty->assign("types"    ,$this->types);
94     /* attrs to smarty*/
95     foreach($this->attributes as $attr){
96       $smarty->assign($attr,$this->$attr);
97     }
99     $smarty->assign("nameACL","");    
100     $smarty->assign("name",$this->name);
102     if($this->is_edit){
103       $smarty->assign("nameACL"," disabled ");
104     }
105     
106     $smarty->assign("allow_mounts", $this->allow_mounts);
107     $smarty->assign("mount_checked", "");
108     
109     
110     $appleMountsACL=chkacl($this->acl,"gotoShareAppleMounts");
111     $appleMountsACLset=strpos($appleMountsACL, "disabled");
112     $smarty->assign("appleMountsACL", $appleMountsACL);
113     $smarty->assign("appleMountsACLset", $appleMountsACLset);
114   
115     if (($this->type == "netatalk") || ($this->type == "NFS")) {
116         if ($this->create_mount_init) {
117           $smarty->assign("mount_checked", "checked");
118         } else {
119         $tmp = split(",", $this->dn);
120         $clip = $tmp[0] . ",ou=servers,ou=systems,";
121         $mountsdn = "cn=mounts," . substr($this->dn, strlen($clip));
122           switch ($this->type) {
123             case "netatalk" : {
124               $mountdn = "cn=".$this->host.":/".$this->name.",".$mountsdn;
125               break;
126             }
127             case "NFS" : {
128               $mountdn = "cn=".$this->host.":".$this->path.",".$mountsdn;
129               break;
130             }
131             default : {
132               continue;
133             }
134           }
135         $ldap = $this->config->get_ldap_link();
136         $ldap->cat($mountdn, array('dn'));
137         $attrs = $ldap->fetch();
138         if (count($attrs) > 0) {
139             $smarty->assign("mount_checked", "checked");
140         }
141         }        
142     }
144     $display= $smarty->fetch(get_template_path('servnfs.tpl', TRUE));
145     return($display);
146   }
148   function remove_from_parent()
149   {
150     /* This cannot be removed... */
151   }
154   /* Save data to object */
155   function save_object()
156   {
157     plugin::save_object(TRUE);
158     if(isset($_POST['path'])){
159       foreach($this->attributes as $attr){
160         $this->$attr = $_POST[$attr];
161       }
162     }
163     
164     if ((isset($_POST['netatalk_mount'])) && (($this->type == "netatalk") || ($this->type == "NFS"))) {
165         $this->create_mount = true;
166     } else {
167         $this->create_mount = false;
168     }
169   }
172   /* Check supplied data */
173   function check()
174   {
175     /* Call common method to give check the hook */
176     $message= plugin::check();
178     // fixme : a check for the path ?  ? 
179     if(empty($this->path)){
180       $message[]=_("Please specify a valid path for your setup.");
181     }
183     // only 0-9a-z
184     if(!$this->is_edit){
185       if(!preg_match("/^[a-z0-9\.\-_]+$/i",$this->name)){
186         $message[]=_("Please specify a valid name for your share.");
187       }
188       if(empty($this->name)){
189         $message[]=_("Please specify a name for your share.");
190       }
191     }
193     if(preg_match("/[^a-z0-9._+ \|-]+/i",$this->description)){
194       $message[]=_("Description contains invalid characters.");
195     }
197     if(preg_match("/[^a-z0-9._+ |-]/i",$this->volume)){
198       $message[]=_("Volume contains invalid characters.");
199     }
200   
201     if(preg_match("/\|/",$this->path)){
202       $message[]=_("Path contains invalid characters.");
203     }
205     if(preg_match("/[^a-z0-9._+ \|-]/i",$this->option)){
206       $message[]=_("Option contains invalid characters.");
207     }
209   /* remove a / at the end of the path, we neither need it there nor
210    * do we want to check for it later.
211    */
212   if(substr($this->path, -1, 1) == '/') {
213     $this->path=substr($this->path, 0, -1);
214   }
215   
216     $ldap= $this->config->get_ldap_link();
217     $ldap->cd($this->config->current['BASE']);
218     $ldap->search("(objectClass=goShareServer)", array("goExportEntry"));
219     while($test = $ldap->fetch()){
220       if($test['dn']==$this->dn)
221         continue;
222       if(isset($test['goExportEntry'])){
223         foreach($test['goExportEntry'] as $entry){
224           $tmp = split("\|",$entry);
225           if($tmp[0] == $this->name){
226             $message[]="Name already in use";
227           }
228         }
229       }
230     }
231     return ($message);
232   }
235   /* Save to LDAP */
236   function save()
237   {
238     /* Everything seems perfect, lets 
239        generate an new export Entry 
240      */
242     $s_return = "";
244     $s_return.= $this->name."|";     
245     $s_return.= $this->description."|";     
246     $s_return.= $this->type."|";     
247     $s_return.= $this->charset."|";     
248     $s_return.= $this->path."|";     
249     $s_return.= $this->option."|";     
250     $s_return.= $this->volume;     
252     return(array($this->name=>$s_return));
253   }
254   
255   function should_create_mount() {
256     return $this->create_mount;
257   }
261 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
262 ?>