0b96923ca78fd71e90dd2d3f6f343931628f7f2c
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");
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 $types =array(); // Array Types NFS/Samba/NCP
21 var $charsets =array(); // Array with charsets
22 var $path =""; // Path
23 var $option =""; // Options
24 var $is_edit =false;
27 function servnfs ($config, $dn= NULL,$entry = false)
28 {
29 plugin::plugin ($config, $dn);
30 $this->types = array("NFS"=>"NFS","samba"=>"samba","NCP"=>"NCP");
32 $this->charsets = array();
34 if(!file_exists("/etc/gosa/encodings")){
35 print_red(_("The file '/etc/gosa/encodings' does not exist, can't get supported charsets."));
36 }else{
37 if(!is_readable("/etc/gosa/encodings")){
38 print_red(_("Can't read '/etc/gosa/encodings', please check permissions."));
39 }else{
40 $fp = fopen("/etc/gosa/encodings","r");
41 $i = 100;
42 while(!feof($fp)&&$i){
43 $i -- ;
44 $str = trim(fgets($fp,256));
46 /* Skip comments */
47 if(!preg_match("/^#/",$str)){
48 $arr = split("\=",$str);
49 if(count($arr)==2){
50 $this->charsets[$arr[0]]=$arr[1];
51 }
52 }
53 }
56 }
57 }
59 if($entry){
60 $tmp = split("\|",$entry);
61 $this->name = $tmp[0]; // Name of NFS
62 $this->description = $tmp[1]; // description
63 $this->type = $tmp[2]; // Type NFS/Samba/NCP
64 $this->charset = $tmp[3]; // charset
65 $this->path = $tmp[4]; // Path
66 $this->option = $tmp[5]; // Options
67 $this->is_edit = true;
68 }else{
69 $this->attributes[] = "name";
70 }
71 }
73 function execute()
74 {
75 /* Call parent execute */
76 plugin::execute();
78 /* Fill templating stuff */
79 $smarty= get_smarty();
81 $smarty->assign("charsets" ,$this->charsets);
82 $smarty->assign("types" ,$this->types);
84 /* attrs to smarty*/
85 foreach($this->attributes as $attr){
86 $smarty->assign($attr,$this->$attr);
87 }
89 $smarty->assign("nameACL","");
90 $smarty->assign("name",$this->name);
92 if($this->is_edit){
93 $smarty->assign("nameACL"," disabled ");
94 }
96 $display= $smarty->fetch(get_template_path('servnfs.tpl', TRUE));
97 return($display);
98 }
100 function remove_from_parent()
101 {
102 /* This cannot be removed... */
103 }
106 /* Save data to object */
107 function save_object()
108 {
109 plugin::save_object(TRUE);
110 if(isset($_POST['path'])){
111 foreach($this->attributes as $attr){
112 $this->$attr = $_POST[$attr];
113 }
114 }
115 }
118 /* Check supplied data */
119 function check()
120 {
121 /* Call common method to give check the hook */
122 $message= plugin::check();
124 // fixme : a check for the path ? ?
125 if(empty($this->path)){
126 $message[]=_("Please specify a valid path for your setup.");
127 }
129 // only 0-9a-z
130 if(!$this->is_edit){
131 if(preg_match("/[^a-z0-9\.\-_]/i",$this->name)){
132 $message[]=_("Please specify a valid name for your setup.");
133 }
134 if(empty($this->name)){
135 $message[]=_("Please specify a name for your setup.");
136 }
137 }
139 if(preg_match("/\|/",$this->description)){
140 $message[]=_("Description contains invalid characters.");
141 }
143 if(preg_match("/\|/",$this->path)){
144 $message[]=_("Path contains invalid characters.");
145 }
147 if(preg_match("/\|/",$this->option)){
148 $message[]=_("Option contains invalid characters.");
149 }
151 $ldap= $this->config->get_ldap_link();
152 $ldap->cd($this->config->current['BASE']);
153 $ldap->search("(objectClass=goShareServer)", array("goExportEntry"));
154 while($test = $ldap->fetch()){
155 if($test['dn']==$this->dn)
156 continue;
157 foreach($test['goExportEntry'] as $entry){
158 $tmp = split("\|",$entry);
159 if($tmp[0] == $this->name){
160 $message[]="Name already in use";
161 }
162 }
163 }
164 return ($message);
165 }
168 /* Save to LDAP */
169 function save()
170 {
171 /* Everything seems perfect, lets
172 generate an new export Entry
173 */
175 $s_return = "";
177 $s_return.= $this->name."|";
178 $s_return.= $this->description."|";
179 $s_return.= $this->type."|";
180 $s_return.= $this->charset."|";
181 $s_return.= $this->path."|";
182 $s_return.= $this->option;
184 return(array($this->name=>$s_return));
185 }
187 }
189 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
190 ?>