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");
32 $this->charsets = array();
34 if(!file_exists("/etc/gosa/encodings")){
35 print_red(_("The file '/etc/gosa/encodings' does not exist, can't get supported charsets."));
36 }else{
37 if(!is_readable("/etc/gosa/encodings")){
38 print_red(_("Can't read '/etc/gosa/encodings', please check permissions."));
39 }else{
40 $fp = fopen("/etc/gosa/encodings","r");
41 $i = 100;
42 while(!feof($fp)&&$i){
43 $i -- ;
44 $str = trim(fgets($fp,256));
46 /* Skip comments */
47 if(!preg_match("/^#/",$str)){
48 $arr = split("\=",$str);
49 if(count($arr)==2){
50 $this->charsets[$arr[0]]=$arr[1];
51 }
52 }
53 }
56 }
57 }
59 if($entry){
60 $tmp = split("\|",$entry);
61 $this->name = $tmp[0]; // Name of NFS
62 $this->description = $tmp[1]; // description
63 $this->type = $tmp[2]; // Type NFS/Samba/NCP
64 $this->charset = $tmp[3]; // charset
65 $this->path = $tmp[4]; // Path
66 $this->option = $tmp[5]; // Options
67 $this->is_edit = true;
68 }else{
69 $this->attributes[] = "name";
70 }
71 }
73 function execute()
74 {
75 /* Call parent execute */
76 plugin::execute();
78 /* Fill templating stuff */
79 $smarty= get_smarty();
81 $smarty->assign("charsets" ,$this->charsets);
82 $smarty->assign("types" ,$this->types);
84 /* attrs to smarty*/
85 foreach($this->attributes as $attr){
86 $smarty->assign($attr,$this->$attr);
87 }
89 $smarty->assign("nameACL","");
90 $smarty->assign("name",$this->name);
92 if($this->is_edit){
93 $smarty->assign("nameACL"," disabled ");
94 }
96 $display= $smarty->fetch(get_template_path('servnfs.tpl', TRUE));
97 return($display);
98 }
100 function remove_from_parent()
101 {
102 /* This cannot be removed... */
103 }
106 /* Save data to object */
107 function save_object()
108 {
109 plugin::save_object(TRUE);
110 if(isset($_POST['path'])){
111 foreach($this->attributes as $attr){
112 $this->$attr = $_POST[$attr];
113 }
114 }
115 }
118 /* Check supplied data */
119 function check()
120 {
121 $message= array();
123 // fixme : a check for the path ? ?
124 if(empty($this->path)){
125 $message[]=_("Please specify a valid path for your setup.");
126 }
128 // only 0-9a-z
129 if(!$this->is_edit){
130 if(preg_match("/[^a-z0-9]/i",$this->name)){
131 $message[]=_("Please specify a valid name for your setup.");
132 }
133 if(empty($this->name)){
134 $message[]=_("Please specify a name for your setup.");
135 }
136 }
138 if(preg_match("/\|/",$this->description)){
139 $message[]=_("Description contains invalid characters.");
140 }
142 if(preg_match("/\|/",$this->path)){
143 $message[]=_("Path contains invalid characters.");
144 }
146 if(preg_match("/\|/",$this->option)){
147 $message[]=_("Option contains invalid characters.");
148 }
150 $ldap= $this->config->get_ldap_link();
151 $ldap->cd($this->config->current['BASE']);
152 $ldap->search("(objectClass=goShareServer)", array("goExportEntry"));
153 while($test = $ldap->fetch()){
154 if($test['dn']==$this->dn)
155 continue;
156 foreach($test['goExportEntry'] as $entry){
157 $tmp = split("\|",$entry);
158 if($tmp[0] == $this->name){
159 $message[]="Name already in use";
160 }
161 }
162 }
163 return ($message);
164 }
167 /* Save to LDAP */
168 function save()
169 {
170 /* Everything seems perfect, lets
171 generate an new export Entry
172 */
174 $s_return = "";
176 $s_return.= $this->name."|";
177 $s_return.= $this->description."|";
178 $s_return.= $this->type."|";
179 $s_return.= $this->charset."|";
180 $s_return.= $this->path."|";
181 $s_return.= $this->option;
183 return(array($this->name=>$s_return));
184 }
186 }
188 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
189 ?>