Code

Fixed undefined index
[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");
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 $option        ="";  // Options
25   var $is_edit           =false;
26   var $allow_mounts = false; //do we allow mount entries?
27   var $create_mount_init = false; //mount entry set for this entry (while editing)?
28   var $create_mount = false; //save mount entry
30   function servnfs ($config, $acl, $allow_mounts, $dn= NULL,$entry = false,$mount = false)
31   {
32     plugin::plugin ($config, $dn);
33     
34     $this->types   = array("NFS"=>"NFS","samba"=>"samba","netatalk"=>"netatalk","NCP"=>"NCP");
35     if($dn){
36       $this->host = substr($dn, 3, strpos($dn, ',')-3);
37     }
38     
39     $this->acl = $acl;
40         $this->allow_mounts=$allow_mounts;
41         
42     $this->charsets = array();
44     if(!file_exists("/etc/gosa/encodings")){
45       print_red(_("The file '/etc/gosa/encodings' does not exist, can't get supported charsets."));
46     }else{
47       if(!is_readable("/etc/gosa/encodings")){
48         print_red(_("Can't read '/etc/gosa/encodings', please check permissions."));
49       }else{
50         $fp = fopen("/etc/gosa/encodings","r");
51         $i = 100;
52         while(!feof($fp)&&$i){
53           $i -- ;
54           $str = trim(fgets($fp,256));
55       
56           /* Skip comments */
57           if(!preg_match("/^#/",$str)){
58             $arr = split("\=",$str);
59             if(count($arr)==2){
60               $this->charsets[$arr[0]]=$arr[1];
61             }
62           }
63         }
65     
66       }
67     }
69     if($entry){
70       $tmp = split("\|",$entry);
71       $this->name          = $tmp[0];  // Name of NFS
72       $this->description   = $tmp[1];  // description
73       $this->type          = $tmp[2];  // Type NFS/Samba/NCP/netatalk
74       $this->charset       = $tmp[3];  // charset
75       $this->path          = $tmp[4];  // Path
76       $this->option        = $tmp[5];  // Options
77       $this->is_edit          = true;
78       
79     }else{
80       $this->attributes[] = "name";
81     }
82     
83     $this->create_mount_init = $mount;
84   }
86   function execute()
87   {
88     /* Call parent execute */
89     plugin::execute();
91     /* Fill templating stuff */
92     $smarty= get_smarty();
94     $smarty->assign("charsets" ,$this->charsets);
95     $smarty->assign("types"    ,$this->types);
97     /* attrs to smarty*/
98     foreach($this->attributes as $attr){
99       $smarty->assign($attr,$this->$attr);
100     }
102     $smarty->assign("nameACL","");    
103     $smarty->assign("name",$this->name);
105     if($this->is_edit){
106       $smarty->assign("nameACL"," disabled ");
107     }
108     
109     $smarty->assign("allow_mounts", $this->allow_mounts);
110     $smarty->assign("mount_checked", "");
111     
112     
113     $appleMountsACL=chkacl($this->acl,"gotoShareAppleMounts");
114     $appleMountsACLset=strpos($appleMountsACL, "disabled");
115     $smarty->assign("appleMountsACL", $appleMountsACL);
116     $smarty->assign("appleMountsACLset", $appleMountsACLset);
117   
118     if (($this->type == "netatalk") || ($this->type == "NFS")) {
119         if ($this->create_mount_init) {
120           $smarty->assign("mount_checked", "checked");
121         } else {
122         $tmp = split(",", $this->dn);
123         $clip = $tmp[0] . ",ou=servers,ou=systems,";
124         $mountsdn = "cn=mounts," . substr($this->dn, strlen($clip));
125           switch ($this->type) {
126             case "netatalk" : {
127               $mountdn = "cn=".$this->host.":/".$this->name.",".$mountsdn;
128               break;
129             }
130             case "NFS" : {
131               $mountdn = "cn=".$this->host.":".$this->path.",".$mountsdn;
132               break;
133             }
134             default : {
135               continue;
136             }
137           }
138         $ldap = $this->config->get_ldap_link();
139       $ldap->cat($mountdn);
140         $attrs = $ldap->fetch();
141         if (count($attrs) > 0) {
142             $smarty->assign("mount_checked", "checked");
143         }
144         }        
145     }
147     $display= $smarty->fetch(get_template_path('servnfs.tpl', TRUE));
148     return($display);
149   }
151   function remove_from_parent()
152   {
153     /* This cannot be removed... */
154   }
157   /* Save data to object */
158   function save_object()
159   {
160     plugin::save_object(TRUE);
161     if(isset($_POST['path'])){
162       foreach($this->attributes as $attr){
163         $this->$attr = $_POST[$attr];
164       }
165     }
166     
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   }
175   /* Check supplied data */
176   function check()
177   {
178     /* Call common method to give check the hook */
179     $message= plugin::check();
181     // fixme : a check for the path ?  ? 
182     if(empty($this->path)){
183       $message[]=_("Please specify a valid path for your setup.");
184     }
186     // only 0-9a-z
187     if(!$this->is_edit){
188       if(preg_match("/[^a-z0-9\.\-_]/i",$this->name)){
189         $message[]=_("Please specify a valid name for your setup.");
190       }
191       if(empty($this->name)){
192         $message[]=_("Please specify a name for your setup.");
193       }
194     }
196     if(preg_match("/\|/",$this->description)){
197       $message[]=_("Description contains invalid characters.");
198     }
199   
200     if(preg_match("/\|/",$this->path)){
201       $message[]=_("Path contains invalid characters.");
202     }
204     if(preg_match("/\|/",$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   }
214   
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;     
250     return(array($this->name=>$s_return));
251   }
252   
253   function should_create_mount() {
254     return $this->create_mount;
255   }
259 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
260 ?>