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 $create_mount_init = false; //mount entry set for this entry (while editing)?
28 var $create_mount = false; //save mount entry
30 var $parent = NULL;
32 function servnfs ($config, $parent,$entry= false,$mount =false)
33 {
34 $this->parent = $parent;
35 $dn = $parent->dn;
36 plugin::plugin ($config, $dn);
38 $this->types = array("CIFS" => "CIFS", "NFS"=>"NFS","samba"=>"samba","netatalk"=>"netatalk","NCP"=>"NCP");
39 if($dn){
40 $this->host = substr($dn, 3, strpos($dn, ',')-3);
41 }
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 }else{
76 $this->attributes[] = "name";
77 }
80 $this->create_mount_init = $mount;
81 }
83 function execute()
84 {
85 /* Call parent execute */
86 plugin::execute();
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->getacl("name")));
107 }
109 $smarty->assign("allow_mounts", $this->parent->allow_mounts);
110 $smarty->assign("mount_checked", "");
112 $smarty->assign("appleMountsACL", $this->getacl("appleMounts"));
114 if (($this->type == "netatalk") || ($this->type == "NFS")) {
115 if ($this->create_mount_init) {
116 $smarty->assign("mount_checked", "checked");
117 } else {
118 $tmp = split(",", $this->dn);
119 $clip = $tmp[0] . ",ou=servers,ou=systems,";
120 $mountsdn = "cn=mounts," . substr($this->dn, strlen($clip));
121 switch ($this->type) {
122 case "netatalk" : {
123 $mountdn = "cn=".$this->host.":/".$this->name.",".$mountsdn;
124 break;
125 }
126 case "NFS" : {
127 $mountdn = "cn=".$this->host.":".$this->path.",".$mountsdn;
128 break;
129 }
130 default : {
131 continue;
132 }
133 }
134 $ldap = $this->config->get_ldap_link();
135 $ldap->cat($mountdn, array('dn'));
136 $attrs = $ldap->fetch();
137 if (count($attrs) > 0) {
138 $smarty->assign("mount_checked", "checked");
139 }
140 }
141 }
143 $display= $smarty->fetch(get_template_path('servnfs.tpl', TRUE));
144 return($display);
145 }
147 function remove_from_parent()
148 {
149 /* This cannot be removed... */
150 }
153 /* Save data to object */
154 function save_object()
155 {
156 if(isset($_POST['path'])){
158 foreach($this->attributes as $name){
159 if($this->parent->acl_is_writeable($name) && isset($_POST[$name])){
160 $this->$name = $_POST[$name];
161 }
162 }
164 if ((isset($_POST['netatalk_mount'])) && (($this->type == "netatalk") || ($this->type == "NFS"))) {
165 $this->create_mount = true;
166 } else {
167 $this->create_mount = false;
168 }
169 }
170 }
173 /* Check supplied data */
174 function check()
175 {
176 /* Call common method to give check the hook */
177 $message= plugin::check();
179 // fixme : a check for the path ? ?
180 if(empty($this->path)){
181 $message[]=_("Please specify a valid path for your setup.");
182 }
184 // only 0-9a-z
185 if(!$this->is_edit){
186 if(!preg_match("/^[a-z0-9\.\-_]+$/i",$this->name)){
187 $message[]=_("Please specify a valid name for your share.");
188 }
189 if(empty($this->name)){
190 $message[]=_("Please specify a name for your share.");
191 }
192 }
194 if(preg_match("/[^a-z0-9._+ \|-]+/i",$this->description)){
195 $message[]=_("Description contains invalid characters.");
196 }
198 if(preg_match("/[^a-z0-9._+ |-]/i",$this->volume)){
199 $message[]=_("Volume contains invalid characters.");
200 }
202 if(preg_match("/\|/",$this->path)){
203 $message[]=_("Path contains invalid characters.");
204 }
206 if(preg_match("/[^a-z0-9._+ \|-]/i",$this->option)){
207 $message[]=_("Option contains invalid characters.");
208 }
210 /* remove a / at the end of the path, we neither need it there nor
211 * do we want to check for it later.
212 */
213 if(substr($this->path, -1, 1) == '/') {
214 $this->path=substr($this->path, 0, -1);
215 }
217 $ldap= $this->config->get_ldap_link();
218 $ldap->cd($this->config->current['BASE']);
219 $ldap->search("(objectClass=goShareServer)", array("goExportEntry"));
220 while($test = $ldap->fetch()){
221 if($test['dn']==$this->dn)
222 continue;
223 if(isset($test['goExportEntry'])){
224 foreach($test['goExportEntry'] as $entry){
225 $tmp = split("\|",$entry);
226 if($tmp[0] == $this->name){
227 $message[]="Name already in use";
228 }
229 }
230 }
231 }
232 return ($message);
233 }
236 /* Save to LDAP */
237 function save()
238 {
239 /* Everything seems perfect, lets
240 generate an new export Entry
241 */
243 $s_return = "";
245 $s_return.= $this->name."|";
246 $s_return.= $this->description."|";
247 $s_return.= $this->type."|";
248 $s_return.= $this->charset."|";
249 $s_return.= $this->path."|";
250 $s_return.= $this->option."|";
251 $s_return.= $this->volume;
253 return(array($this->name=>$s_return));
254 }
256 function should_create_mount() {
257 return $this->create_mount;
258 }
261 }
263 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
264 ?>