ca8b1f09d73e941fef5457c6279db7bdb79618fb
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);
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 }
40 $this->acl = $acl;
41 $this->allow_mounts=$allow_mounts;
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));
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 }
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 /* Decode if path is base64 */
76 if (!preg_match('%/%', $this->path)){
77 $this->path= base64_decode($this->path);
78 }
80 }else{
81 $this->attributes[] = "name";
82 }
85 $this->create_mount_init = $mount;
86 }
88 function execute()
89 {
90 /* Call parent execute */
91 plugin::execute();
93 /* Fill templating stuff */
94 $smarty= get_smarty();
96 $smarty->assign("charsets" ,$this->charsets);
97 $smarty->assign("types" ,$this->types);
99 /* attrs to smarty*/
100 foreach($this->attributes as $attr){
101 $smarty->assign($attr,$this->$attr);
102 }
104 $smarty->assign("nameACL","");
105 $smarty->assign("name",$this->name);
107 if($this->is_edit){
108 $smarty->assign("nameACL"," disabled ");
109 }
111 $smarty->assign("allow_mounts", $this->allow_mounts);
112 $smarty->assign("mount_checked", "");
115 $appleMountsACL=chkacl($this->acl,"gotoShareAppleMounts");
116 $appleMountsACLset=strpos($appleMountsACL, "disabled");
117 $smarty->assign("appleMountsACL", $appleMountsACL);
118 $smarty->assign("appleMountsACLset", $appleMountsACLset);
120 if (($this->type == "netatalk") || ($this->type == "NFS")) {
121 if ($this->create_mount_init) {
122 $smarty->assign("mount_checked", "checked");
123 } else {
124 $tmp = split(",", $this->dn);
125 $clip = $tmp[0] . ",ou=servers,ou=systems,";
126 $mountsdn = "cn=mounts," . substr($this->dn, strlen($clip));
127 switch ($this->type) {
128 case "netatalk" : {
129 $mountdn = "cn=".$this->host.":/".$this->name.",".$mountsdn;
130 break;
131 }
132 case "NFS" : {
133 $mountdn = "cn=".$this->host.":".$this->path.",".$mountsdn;
134 break;
135 }
136 default : {
137 continue;
138 }
139 }
140 $ldap = $this->config->get_ldap_link();
141 $ldap->cat($mountdn, array('dn'));
142 $attrs = $ldap->fetch();
143 if (count($attrs) > 0) {
144 $smarty->assign("mount_checked", "checked");
145 }
146 }
147 }
149 $display= $smarty->fetch(get_template_path('servnfs.tpl', TRUE));
150 return($display);
151 }
153 function remove_from_parent()
154 {
155 /* This cannot be removed... */
156 }
159 /* Save data to object */
160 function save_object()
161 {
162 plugin::save_object(TRUE);
163 if(isset($_POST['path'])){
164 foreach($this->attributes as $attr){
165 $this->$attr = $_POST[$attr];
166 }
167 }
169 if ((isset($_POST['netatalk_mount'])) && (($this->type == "netatalk") || ($this->type == "NFS"))) {
170 $this->create_mount = true;
171 } else {
172 $this->create_mount = false;
173 }
174 }
177 /* Check supplied data */
178 function check()
179 {
180 /* Call common method to give check the hook */
181 $message= plugin::check();
183 // fixme : a check for the path ? ?
184 if(empty($this->path)){
185 $message[]=_("Please specify a valid path for your setup.");
186 }
188 // only 0-9a-z
189 if(!$this->is_edit){
190 if(!preg_match("/^[a-z0-9\.\-_]+$/i",$this->name)){
191 $message[]=_("Please specify a valid name for your share.");
192 }
193 if(empty($this->name)){
194 $message[]=_("Please specify a name for your share.");
195 }
196 }
198 if(preg_match("/[^a-z0-9._+ \|-]+/i",$this->description)){
199 $message[]=_("Description contains invalid characters.");
200 }
202 if(preg_match("/[^a-z0-9._+ |-]/i",$this->volume)){
203 $message[]=_("Volume contains invalid characters.");
204 }
206 if(preg_match("/\|/",$this->path)){
207 $message[]=_("Path contains invalid characters.");
208 }
210 if(!preg_match("%/%",$this->path)){
211 $message[]=_("Path must contain at least one slash.");
212 }
214 if(preg_match("/[^a-z0-9._+ \|-]/i",$this->option)){
215 $message[]=_("Option contains invalid characters.");
216 }
218 /* remove a / at the end of the path, we neither need it there nor
219 * do we want to check for it later.
220 */
221 if(substr($this->path, -1, 1) == '/') {
222 $this->path=substr($this->path, 0, -1);
223 }
225 $ldap= $this->config->get_ldap_link();
226 $ldap->cd($this->config->current['BASE']);
227 $ldap->search("(objectClass=goShareServer)", array("goExportEntry"));
228 while($test = $ldap->fetch()){
229 if($test['dn']==$this->dn)
230 continue;
231 if(isset($test['goExportEntry'])){
232 foreach($test['goExportEntry'] as $entry){
233 $tmp = split("\|",$entry);
234 if($tmp[0] == $this->name){
235 $message[]="Name already in use";
236 }
237 }
238 }
239 }
240 return ($message);
241 }
244 /* Save to LDAP */
245 function save()
246 {
247 /* Everything seems perfect, lets
248 generate an new export Entry
249 */
251 $s_return = "";
253 $s_return.= $this->name."|";
254 $s_return.= $this->description."|";
255 $s_return.= $this->type."|";
256 $s_return.= $this->charset."|";
258 /* Encode path if it contains non ascii letters */
259 $path= $this->path;
260 if (!preg_match('=^[a-z0-9+_/%-]+$=i', $path)){
261 $path= base64_encode($this->path);
262 }
264 $s_return.= $path."|";
265 $s_return.= $this->option."|";
266 $s_return.= $this->volume;
268 return(array($this->name=>$s_return));
269 }
271 function should_create_mount() {
272 return $this->create_mount;
273 }
275 /* Return plugin informations for acl handling */
276 function plInfo()
277 {
278 return (array(
279 "plShortName" => _("NFS"),
280 "plDescription" => _("NFS service"),
281 "plSelfModify" => FALSE,
282 "plDepends" => array(),
283 "plPriority" => 0,
284 "plSection" => array("administration"),
285 "plCategory" => array("server"),
287 "plProvidedAcls"=> array(
288 "description" => _("Description"),
289 "type" => _("Type"),
290 "charset" => _("Charset"),
291 "path" => _("Path"),
292 "option" => _("Option"),
293 "volume" => _("Volume"))
294 ));
295 }
296 }
298 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
299 ?>