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("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 }else{
76 $this->attributes[] = "name";
77 }
79 $this->create_mount_init = $mount;
80 }
82 function execute()
83 {
84 /* Call parent execute */
85 plugin::execute();
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 $smarty->assign("nameACL","");
99 $smarty->assign("name",$this->name);
101 if($this->is_edit){
102 $smarty->assign("nameACL"," disabled ");
103 }
105 $smarty->assign("allow_mounts", $this->allow_mounts);
106 $smarty->assign("mount_checked", "");
109 $appleMountsACL=chkacl($this->acl,"gotoShareAppleMounts");
110 $appleMountsACLset=strpos($appleMountsACL, "disabled");
111 $smarty->assign("appleMountsACL", $appleMountsACL);
112 $smarty->assign("appleMountsACLset", $appleMountsACLset);
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 plugin::save_object(TRUE);
157 if(isset($_POST['path'])){
158 foreach($this->attributes as $attr){
159 $this->$attr = $_POST[$attr];
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 }
171 /* Check supplied data */
172 function check()
173 {
174 /* Call common method to give check the hook */
175 $message= plugin::check();
177 // fixme : a check for the path ? ?
178 if(empty($this->path)){
179 $message[]=_("Please specify a valid path for your setup.");
180 }
182 // only 0-9a-z
183 if(!$this->is_edit){
184 if(preg_match("/[^a-z0-9\.\-_]/i",$this->name)){
185 $message[]=_("Please specify a valid name for your share.");
186 }
187 if(empty($this->name)){
188 $message[]=_("Please specify a name for your share.");
189 }
190 }
192 if(preg_match("/\|/",$this->description)){
193 $message[]=_("Description contains invalid characters.");
194 }
196 if(preg_match("/\|/",$this->volume)){
197 $message[]=_("Volume contains invalid characters.");
198 }
200 if(preg_match("/\|/",$this->path)){
201 $message[]=_("Path contains invalid characters.");
202 }
204 if(preg_match("/\|/",$this->option)){
205 $message[]=_("Option contains invalid characters.");
206 }
208 /* remove a / at the end of the path, we neither need it there nor
209 * do we want to check for it later.
210 */
211 if(substr($this->path, -1, 1) == '/') {
212 $this->path=substr($this->path, 0, -1);
213 }
215 $ldap= $this->config->get_ldap_link();
216 $ldap->cd($this->config->current['BASE']);
217 $ldap->search("(objectClass=goShareServer)", array("goExportEntry"));
218 while($test = $ldap->fetch()){
219 if($test['dn']==$this->dn)
220 continue;
221 if(isset($test['goExportEntry'])){
222 foreach($test['goExportEntry'] as $entry){
223 $tmp = split("\|",$entry);
224 if($tmp[0] == $this->name){
225 $message[]="Name already in use";
226 }
227 }
228 }
229 }
230 return ($message);
231 }
234 /* Save to LDAP */
235 function save()
236 {
237 /* Everything seems perfect, lets
238 generate an new export Entry
239 */
241 $s_return = "";
243 $s_return.= $this->name."|";
244 $s_return.= $this->description."|";
245 $s_return.= $this->type."|";
246 $s_return.= $this->charset."|";
247 $s_return.= $this->path."|";
248 $s_return.= $this->option."|";
249 $s_return.= $this->volume;
251 return(array($this->name=>$s_return));
252 }
254 function should_create_mount() {
255 return $this->create_mount;
256 }
258 }
260 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
261 ?>