6540df2c44b256833c5fb6c49c8cdf91bd51e5d0
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 '/' and no special characters!");
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 else {
205 if (!preg_match("/^[^\$].*\$$/", $this->name)) {
206 $message[] = _("Hidden shares must have the '$' at the end of the name!");
207 }
208 }
209 }
211 if(!empty($this->description) && preg_match("/^[^a-z0-9\._äüö\+ -]*$/ui",$this->description)){
212 $message[]= msgPool::invalid(_("Description"),$this->description,"/^[a-z0-9\._äüö\+ -]*$/ui");
213 }
215 if(!empty($this->volume) && preg_match("/^[^a-z0-9\._äüö\+ -]*$/ui",$this->volume)){
216 $message[]= msgPool::invalid(_("Volume"),$this->volume,"/^[a-z0-9\._äüö\+ -]*$/ui");
217 }
219 if(!empty($this->option) && preg_match("/^[^a-z0-9\._äüö,=\+ -]*$/ui",$this->option)){
220 $message[]= msgPool::invalid(_("Option"),$this->option,"/^[a-z0-9\._äüö\+ -]*$/ui");
221 }
223 /* remove a / at the end of the path, we neither need it there nor
224 * do we want to check for it later.
225 */
226 if(substr($this->path, -1, 1) == '/') {
227 $this->path=substr($this->path, 0, -1);
228 }
230 $this_cn = preg_replace("/,ou=.*$/","",$this->dn);
231 $this_cn = preg_replace("/cn=/","",$this_cn);
232 $ldap= $this->config->get_ldap_link();
233 $ldap->cd($this->config->current['BASE']);
234 $ldap->search("(objectClass=goShareServer)", array("goExportEntry", "cn", "gosaUnitTag"));
235 while($test = $ldap->fetch()){
236 if($test['dn']==$this->dn)
237 continue;
238 if(isset($test['goExportEntry'])){
239 foreach($test['goExportEntry'] as $entry){
240 $tmp = split("\|",$entry);
241 if($tmp[0] == $this->name && $test['cn'][0] == $this_cn){
242 /* The selected share name is identical to another share name. Furthermore, that other share is
243 on a server with the same name. Reject this unless the other server is in a different
244 adminstrative domain. */
245 if (!isset($test['gosaUnitTag']) || $test['gosaUnitTag'][0] == $this->gosaUnitTag){
246 $message[]= sprintf(_("The share '%s' on another server '%s' already exists."), $this->name, $this_cn);
247 }
248 }
249 }
250 }
251 }
252 return ($message);
253 }
256 /* Save to LDAP */
257 function save()
258 {
259 /* Everything seems perfect, lets
260 generate an new export Entry
261 */
263 $s_return = "";
265 $s_return.= $this->name."|";
266 $s_return.= $this->description."|";
267 $s_return.= $this->type."|";
268 $s_return.= $this->charset."|";
269 $s_return.= $this->path."|";
270 $s_return.= $this->option."|";
271 $s_return.= $this->volume;
273 return(array($this->name=>$s_return));
274 }
276 function should_create_mount() {
277 return $this->create_mount;
278 }
281 }
283 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
284 ?>