Code

allow special chars in device names
[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 $types         =array();  // Array Types NFS/Samba/NCP
21   var $charsets      =array();  // Array with charsets
22   var $path          ="";  // Path
23   var $option        ="";  // Options
24   var $is_edit           =false;
27   function servnfs ($config, $dn= NULL,$entry = false)
28   {
29     plugin::plugin ($config, $dn);
30     $this->types   = array("NFS"=>"NFS","samba"=>"samba","NCP"=>"NCP");
31     $this->charsets = array("UTF-8" => "UTF-8",
32         "ISO8859-1"=>"ISO8859-1 (Latin 1)",
33         "ISO8859-2"=>"ISO8859-2 (Latin 2)",
34         "ISO8859-3"=>"ISO8859-3 (Latin 3)",
35         "ISO8859-4"=>"ISO8859-4 (Latin 4)",
36         "ISO8859-5"=>"ISO8859-5 (Latin 5)",
37         "cp850"=>"CP850 (Europe)");
39     if($entry){
40       $tmp = split("\|",$entry);
41       $this->name          = $tmp[0];  // Name of NFS
42       $this->description   = $tmp[1];  // description
43       $this->type          = $tmp[2];  // Type NFS/Samba/NCP
44       $this->charset       = $tmp[3];  // charset
45       $this->path          = $tmp[4];  // Path
46       $this->option        = $tmp[5];  // Options
47       $this->is_edit          = true;
48     }else{
49       $this->attributes[] = "name";
50     }
51   }
53   function execute()
54   {
55         /* Call parent execute */
56         plugin::execute();
58     /* Fill templating stuff */
59     $smarty= get_smarty();
61     $smarty->assign("charsets" ,$this->charsets);
62     $smarty->assign("types"    ,$this->types);
64     /* attrs to smarty*/
65     foreach($this->attributes as $attr){
66       $smarty->assign($attr,$this->$attr);
67     }
69     $smarty->assign("nameACL","");    
70     $smarty->assign("name",$this->name);
72     if($this->is_edit){
73       $smarty->assign("nameACL"," disabled ");
74     }
76     $display= $smarty->fetch(get_template_path('servnfs.tpl', TRUE));
77     return($display);
78   }
80   function remove_from_parent()
81   {
82     /* This cannot be removed... */
83   }
86   /* Save data to object */
87   function save_object()
88   {
89     plugin::save_object(TRUE);
90     if(isset($_POST['path'])){
91       foreach($this->attributes as $attr){
92         $this->$attr = $_POST[$attr];
93       }
94     }
95   }
98   /* Check supplied data */
99   function check()
100   {
101     $message= array();
103     // fixme : a check for the path ?  ? 
104     if(empty($this->path)){
105       $message[]=_("Please specify a valid path for your setup.");
106     }
108     // only 0-9a-z
109     if(!$this->is_edit){
110       if(preg_match("/[^a-z0-9]/i",$this->name)){
111         $message[]=_("Please specify a valid name for your setup.");
112       }
113       if(empty($this->name)){
114         $message[]=_("Please specify a name for your setup.");
115       }
116     }
118     if(preg_match("/\|/",$this->description)){
119       $message[]=_("Description contains invalid characters.");
120     }
121   
122     if(preg_match("/\|/",$this->path)){
123       $message[]=_("Path contains invalid characters.");
124     }
126     if(preg_match("/\|/",$this->option)){
127       $message[]=_("Option contains invalid characters.");
128     }
130     $ldap= $this->config->get_ldap_link();
131     $ldap->cd($this->config->current['BASE']);
132     $ldap->search("(objectClass=goShareServer)", array("goExportEntry"));
133     while($test = $ldap->fetch()){
134       if($test['dn']==$this->dn)
135         continue;
136       foreach($test['goExportEntry'] as $entry){
137         $tmp = split("\|",$entry);
138         if($tmp[0] == $this->name){
139           $message[]="Name already in use";
140         }
141       }
142     }
143     return ($message);
144   }
147   /* Save to LDAP */
148   function save()
149   {
150     /* Everything seems perfect, lets 
151        generate an new export Entry 
152      */
154     $s_return = "";
156     $s_return.= $this->name."|";     
157     $s_return.= $this->description."|";     
158     $s_return.= $this->type."|";     
159     $s_return.= $this->charset."|";     
160     $s_return.= $this->path."|";     
161     $s_return.= $this->option;     
163     return(array($this->name=>$s_return));
164   }
168 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
169 ?>