1 <?php
3 class servnfs extends plugin
4 {
5 /* attribute list for save action */
6 var $ignore_account = TRUE;
7 var $attributes = array("description","type","charset","path","option", "volume");
8 var $objectclasses = array("whatever");
9 var $is_account = true;
11 var $name =""; // Name of
12 var $description =""; // description
13 var $type =""; // Type FS/Samba/NCP
14 var $charset =""; // charset
15 var $host =""; // hostname
16 var $types =array(); // Array Types NFS/Samba/NCP/netatalk
17 var $charsets =array(); // Array with charsets
18 var $path =""; // Path
19 var $volume =""; // Volume
20 var $option =""; // Options
21 var $is_edit =false;
22 var $create_mount_init = false; //mount entry set for this entry (while editing)?
23 var $create_mount = false; //save mount entry
25 var $parent = NULL;
26 var $view_logged = FALSE;
28 function servnfs (&$config, $parent,$entry= false,$mount =false)
29 {
30 $this->parent = $parent;
31 $dn = $parent->dn;
32 plugin::plugin ($config, $dn);
34 $this->types = array("CIFS" => "CIFS", "NFS"=>"NFS","samba"=>"samba","netatalk"=>"netatalk","NCP"=>"NCP");
35 if($dn){
36 $this->host = substr($dn, 3, strpos($dn, ',')-3);
37 }
39 $this->charsets = array();
41 if(!file_exists(CONFIG_DIR."/encodings")){
42 print_red(sprintf(_("The file '%s/encodings' does not exist, can't get supported charsets."),CONFIG_DIR));
43 }else{
44 if(!is_readable(CONFIG_DIR."/encodings")){
45 print_red(sprintf(_("Can't read '%s/encodings', please check permissions."),CONFIG_DIR));
46 }else{
47 $fp = fopen(CONFIG_DIR."/encodings","r");
48 $i = 100;
49 while(!feof($fp)&&$i){
50 $i -- ;
51 $str = trim(fgets($fp,256));
53 /* Skip comments */
54 if(!preg_match("/^#/",$str)){
55 $arr = split("\=",$str);
56 if(count($arr)==2){
57 $this->charsets[$arr[0]]=$arr[1];
58 }
59 }
60 }
61 }
62 }
64 if($entry){
65 list($this->name, $this->description, $this->type, $this->charset,
66 $this->path, $this->option, $this->volume)= split("\|",$entry."|");
67 $this->is_edit = true;
69 }else{
70 $this->attributes[] = "name";
71 }
74 $this->create_mount_init = $mount;
75 }
77 function execute()
78 {
79 /* Call parent execute */
80 plugin::execute();
82 if($this->is_account && !$this->view_logged){
83 $this->view_logged = TRUE;
84 new log("view","server/".get_class($this),$this->dn);
85 }
87 /* Fill templating stuff */
88 $smarty= get_smarty();
90 $smarty->assign("charsets" ,$this->charsets);
91 $smarty->assign("types" ,$this->types);
93 /* attrs to smarty*/
94 foreach($this->attributes as $attr){
95 $smarty->assign($attr,$this->$attr);
96 }
98 $tmp = $this->parent->plInfo();
99 foreach($tmp['plProvidedAcls'] as $name => $translation){
100 $smarty->assign($name."ACL",$this->parent->getacl($name));
101 }
103 $smarty->assign("name",$this->name);
104 if($this->is_edit){
105 $smarty->assign("nameACL", preg_replace("/w/","",$this->parent->getacl("name")));
106 }
107 $smarty->assign("allow_mounts", $this->parent->allow_mounts);
108 $smarty->assign("mount_checked", "");
110 $smarty->assign("appleMountsACL", $this->getacl("appleMounts"));
112 if (($this->type == "netatalk") || ($this->type == "NFS")) {
113 if ($this->create_mount_init) {
114 $smarty->assign("mount_checked", "checked");
115 } else {
116 $tmp = split(",", $this->dn);
117 $clip = $tmp[0] . ",".get_ou('serverou');
118 $mountsdn = "cn=mounts," . substr($this->dn, strlen($clip));
119 switch ($this->type) {
120 case "netatalk" : {
121 $mountdn = "cn=".$this->host.":/".$this->name.",".$mountsdn;
122 break;
123 }
124 case "NFS" : {
125 $mountdn = "cn=".$this->host.":".$this->path.",".$mountsdn;
126 break;
127 }
128 default : {
129 continue;
130 }
131 }
132 $ldap = $this->config->get_ldap_link();
133 $ldap->cat($mountdn, array('dn'));
134 $attrs = $ldap->fetch();
135 if (count($attrs) > 0) {
136 $smarty->assign("mount_checked", "checked");
137 }
138 }
139 }
141 $display= $smarty->fetch(get_template_path('servnfs.tpl', TRUE));
142 return($display);
143 }
145 function remove_from_parent()
146 {
147 /* This cannot be removed... */
148 }
151 /* Save data to object */
152 function save_object()
153 {
154 if(isset($_POST['servnfs_posted'])){
156 foreach($this->attributes as $name){
157 if($this->parent->acl_is_writeable($name) && isset($_POST[$name])){
158 $this->$name = $_POST[$name];
159 }
160 }
162 if ((isset($_POST['netatalk_mount'])) && (($this->type == "netatalk") || ($this->type == "NFS"))) {
163 $this->create_mount = true;
164 } else {
165 $this->create_mount = false;
166 }
167 }
168 }
171 /* Check supplied data */
172 function check()
173 {
174 /* Call common method to give check the hook */
175 $message= plugin::check();
177 if(empty($this->path)){
178 $message[]= msgPool::required(_("Path"));
179 }
181 if(!test::is_path($this->path)){
182 $message[]= msgPool::invalid(_("Path"));
183 }
185 // only 0-9a-z
186 if(!$this->is_edit){
187 if(empty($this->name)){
188 $message[]= msgPool::required(_("Name"));
189 }
190 if(!preg_match("/^[a-z0-9\._äüö]*$/ui",$this->name)){
191 $message[]= msgPool::invalid(_("Name"),$this->name,"/[a-z0-9\._äüö]/ui");
192 }
193 }
195 if(!empty($this->description) && preg_match("/^[^a-z0-9\._äüö\+ -]*$/ui",$this->description)){
196 $message[]= msgPool::invalid(_("Description"),$this->description,"/^[a-z0-9\._äüö\+ -]*$/ui");
197 }
199 if(!empty($this->volume) && preg_match("/^[^a-z0-9\._äüö\+ -]*$/ui",$this->volume)){
200 $message[]= msgPool::invalid(_("Volume"),$this->volume,"/^[a-z0-9\._äüö\+ -]*$/ui");
201 }
203 if(!empty($this->option) && preg_match("/^[^a-z0-9\._äüö,=\+ -]*$/ui",$this->option)){
204 $message[]= msgPool::invalid(_("Option"),$this->option,"/^[a-z0-9\._äüö\+ -]*$/ui");
205 }
207 /* remove a / at the end of the path, we neither need it there nor
208 * do we want to check for it later.
209 */
210 if(substr($this->path, -1, 1) == '/') {
211 $this->path=substr($this->path, 0, -1);
212 }
214 $ldap= $this->config->get_ldap_link();
215 $ldap->cd($this->config->current['BASE']);
216 $ldap->search("(objectClass=goShareServer)", array("goExportEntry"));
217 while($test = $ldap->fetch()){
218 if($test['dn']==$this->dn)
219 continue;
220 if(isset($test['goExportEntry'])){
221 foreach($test['goExportEntry'] as $entry){
222 $tmp = split("\|",$entry);
223 if($tmp[0] == $this->name){
224 $message[]="Name already in use";
225 }
226 }
227 }
228 }
229 return ($message);
230 }
233 /* Save to LDAP */
234 function save()
235 {
236 /* Everything seems perfect, lets
237 generate an new export Entry
238 */
240 $s_return = "";
242 $s_return.= $this->name."|";
243 $s_return.= $this->description."|";
244 $s_return.= $this->type."|";
245 $s_return.= $this->charset."|";
246 $s_return.= $this->path."|";
247 $s_return.= $this->option."|";
248 $s_return.= $this->volume;
250 return(array($this->name=>$s_return));
251 }
253 function should_create_mount() {
254 return $this->create_mount;
255 }
258 }
260 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
261 ?>