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("NBD" => "NBD", "CIFS" => "CIFS", "NFS"=>"NFS","samba"=>"samba","netatalk"=>"netatalk","NCP"=>"NCP");
35 if($dn){
36 $this->host = substr($dn, 3, strpos($dn, ',')-3);
37 }
38 asort($this->types);
40 $this->charsets = array();
42 if(!file_exists(CONFIG_DIR."/encodings")){
43 msg_dialog::display(_("Error"), msgPool::fileDoesNotExist(CONFIG_DIR."/encodings"), ERROR_DIALOG);
44 }else{
45 if(!is_readable(CONFIG_DIR."/encodings")){
46 msg_dialog::display(_("Error"), msgPool::cannotReadFile(CONFIG_DIR."/encodings"), ERROR_DIALOG);
47 }else{
48 $fp = fopen(CONFIG_DIR."/encodings","r");
49 $i = 100;
50 while(!feof($fp)&&$i){
51 $i -- ;
52 $str = trim(fgets($fp,256));
54 /* Skip comments */
55 if(!preg_match("/^#/",$str)){
56 $arr = split("\=",$str);
57 if(count($arr)==2){
58 $this->charsets[$arr[0]]=$arr[1];
59 }
60 }
61 }
62 }
63 }
65 if($entry){
66 list($this->name, $this->description, $this->type, $this->charset,
67 $this->path, $this->option, $this->volume)= split("\|",$entry."|");
68 $this->is_edit = true;
70 }else{
71 $this->attributes[] = "name";
72 }
75 $this->create_mount_init = $mount;
76 }
78 function execute()
79 {
80 /* Call parent execute */
81 plugin::execute();
83 if($this->is_account && !$this->view_logged){
84 $this->view_logged = TRUE;
85 new log("view","server/".get_class($this),$this->dn);
86 }
88 /* Fill templating stuff */
89 $smarty= get_smarty();
91 $smarty->assign("charsets" ,$this->charsets);
92 $smarty->assign("types" ,$this->types);
94 /* attrs to smarty*/
95 foreach($this->attributes as $attr){
96 $smarty->assign($attr,$this->$attr);
97 }
99 $tmp = $this->parent->plInfo();
100 foreach($tmp['plProvidedAcls'] as $name => $translation){
101 $smarty->assign($name."ACL",$this->parent->getacl($name));
102 }
104 $smarty->assign("name",$this->name);
105 if($this->is_edit){
106 $smarty->assign("nameACL", preg_replace("/w/","",$this->parent->getacl("name")));
107 }
108 $smarty->assign("allow_mounts", $this->parent->allow_mounts);
109 $smarty->assign("mount_checked", "");
111 $smarty->assign("appleMountsACL", $this->getacl("appleMounts"));
113 if (($this->type == "netatalk") || ($this->type == "NFS")) {
114 if ($this->create_mount_init) {
115 $smarty->assign("mount_checked", "checked");
116 } else {
117 $tmp = split(",", $this->dn);
118 $clip = $tmp[0] . ",".get_ou('serverRDN');
119 $mountsdn = "cn=mounts," . substr($this->dn, strlen($clip));
120 switch ($this->type) {
121 case "netatalk" : {
122 $mountdn = "cn=".$this->host.":/".$this->name.",".$mountsdn;
123 break;
124 }
125 case "NFS" : {
126 $mountdn = "cn=".$this->host.":".$this->path.",".$mountsdn;
127 break;
128 }
129 default : {
130 continue;
131 }
132 }
133 $ldap = $this->config->get_ldap_link();
134 $ldap->cat($mountdn, array('dn'));
135 $attrs = $ldap->fetch();
136 if (count($attrs) > 0) {
137 $smarty->assign("mount_checked", "checked");
138 }
139 }
140 }
142 $display= $smarty->fetch(get_template_path('servnfs.tpl', TRUE, dirname(__FILE__)));
143 return($display);
144 }
146 function remove_from_parent()
147 {
148 /* This cannot be removed... */
149 }
152 /* Save data to object */
153 function save_object()
154 {
155 if(isset($_POST['servnfs_posted'])){
157 foreach($this->attributes as $name){
158 if($this->parent->acl_is_writeable($name) && isset($_POST[$name])){
159 $this->$name = $_POST[$name];
160 }
161 }
163 if ((isset($_POST['netatalk_mount'])) && (($this->type == "netatalk") || ($this->type == "NFS"))) {
164 $this->create_mount = true;
165 } else {
166 $this->create_mount = false;
167 }
168 }
169 }
172 /* Check supplied data */
173 function check()
174 {
175 /* Call common method to give check the hook */
176 $message= plugin::check();
178 if(empty($this->path)){
179 $message[]= msgPool::required(_("Path"));
180 }
182 if($this->type == "NBD") {
183 if (!preg_match('/^[a-z0-9-]+:[0-9]+$/', $this->path)){
184 $message[]= _("'Path / Volume' must be of format 'server:port'!");
185 }
186 } else {
187 if (!tests::is_path($this->path)){
188 $message[]= _("'Path / Volume' must contain at least one '/'!");
189 }
190 }
192 if(!in_array($this->type,$this->types)){
193 $message[]= msgPool::required(_("Type"));
194 }
196 // only 0-9a-z
197 if(!$this->is_edit){
198 if(empty($this->name)){
199 $message[]= msgPool::required(_("Name"));
200 }
201 if(!preg_match("/^[a-z0-9\._äüö]*$/ui",$this->name)){
202 $message[]= msgPool::invalid(_("Name"),$this->name,"/[a-z0-9\._äüö]/ui");
203 }
204 }
206 if(!empty($this->description) && preg_match("/^[^a-z0-9\._äüö\+ -]*$/ui",$this->description)){
207 $message[]= msgPool::invalid(_("Description"),$this->description,"/^[a-z0-9\._äüö\+ -]*$/ui");
208 }
210 if(!empty($this->volume) && preg_match("/^[^a-z0-9\._äüö\+ -]*$/ui",$this->volume)){
211 $message[]= msgPool::invalid(_("Volume"),$this->volume,"/^[a-z0-9\._äüö\+ -]*$/ui");
212 }
214 if(!empty($this->option) && preg_match("/^[^a-z0-9\._äüö,=\+ -]*$/ui",$this->option)){
215 $message[]= msgPool::invalid(_("Option"),$this->option,"/^[a-z0-9\._äüö\+ -]*$/ui");
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[]= msgPool::duplicated(_("Name"));
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."|";
257 $s_return.= $this->path."|";
258 $s_return.= $this->option."|";
259 $s_return.= $this->volume;
261 return(array($this->name=>$s_return));
262 }
264 function should_create_mount() {
265 return $this->create_mount;
266 }
269 }
271 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
272 ?>