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");
31 $this->charsets = array("UTF-8" => "UTF-8",
32 "ISO8859-1"=>"ISO8859-1 (Latin 1)",
33 "ISO8859-2"=>"ISO8859-2 (Latin 2)",
34 "ISO8859-3"=>"ISO8859-3 (Latin 3)",
35 "ISO8859-4"=>"ISO8859-4 (Latin 4)",
36 "ISO8859-5"=>"ISO8859-5 (Latin 5)");
38 if($entry){
39 $tmp = split("\|",$entry);
40 $this->name = $tmp[0]; // Name of NFS
41 $this->description = $tmp[1]; // description
42 $this->type = $tmp[2]; // Type NFS/Samba/NCP
43 $this->charset = $tmp[3]; // charset
44 $this->path = $tmp[4]; // Path
45 $this->option = $tmp[5]; // Options
46 $this->is_edit = true;
47 }else{
48 $this->attributes[] = "name";
49 }
50 }
52 function execute()
53 {
54 /* Fill templating stuff */
55 $smarty= get_smarty();
57 $smarty->assign("charsets" ,$this->charsets);
58 $smarty->assign("types" ,$this->types);
60 /* attrs to smarty*/
61 foreach($this->attributes as $attr){
62 $smarty->assign($attr,$this->$attr);
63 }
65 $smarty->assign("nameACL","");
66 $smarty->assign("name",$this->name);
68 if($this->is_edit){
69 $smarty->assign("nameACL"," disabled ");
70 }
72 $display= $smarty->fetch(get_template_path('servnfs.tpl', TRUE));
73 return($display);
74 }
76 function remove_from_parent()
77 {
78 /* This cannot be removed... */
79 }
82 /* Save data to object */
83 function save_object()
84 {
85 plugin::save_object(TRUE);
86 if(isset($_POST['path'])){
87 foreach($this->attributes as $attr){
88 $this->$attr = $_POST[$attr];
89 }
90 }
91 }
94 /* Check supplied data */
95 function check()
96 {
97 $message= array();
99 // fixme : a check for the path ? ?
100 if(empty($this->path)){
101 $message[]=_("Please specify a valid path for your setup.");
102 }
104 // only 0-9a-z
105 if(!$this->is_edit){
106 if(preg_match("/[^a-z0-9]/i",$this->name)){
107 $message[]=_("Please specify a valid name for your setup.");
108 }
109 if(empty($this->name)){
110 $message[]=_("Please specify a name for your setup.");
111 }
112 }
114 if(preg_match("/\|/",$this->description)){
115 $message[]=_("Description contains invalid characters.");
116 }
118 if(preg_match("/\|/",$this->path)){
119 $message[]=_("Path contains invalid characters.");
120 }
122 if(preg_match("/\|/",$this->option)){
123 $message[]=_("Option contains invalid characters.");
124 }
126 $ldap= $this->config->get_ldap_link();
127 $ldap->cd($this->config->current['BASE']);
128 $ldap->search("(objectClass=goShareServer)", array("goExportEntry"));
129 while($test = $ldap->fetch()){
130 if($test['dn']==$this->dn)
131 continue;
132 foreach($test['goExportEntry'] as $entry){
133 $tmp = split("\|",$entry);
134 if($tmp[0] == $this->name){
135 $message[]="Name already in use";
136 }
137 }
138 }
139 return ($message);
140 }
143 /* Save to LDAP */
144 function save()
145 {
146 /* Everything seems perfect, lets
147 generate an new export Entry
148 */
150 $s_return = "";
152 $s_return.= $this->name."|";
153 $s_return.= $this->description."|";
154 $s_return.= $this->type."|";
155 $s_return.= $this->charset."|";
156 $s_return.= $this->path."|";
157 $s_return.= $this->option;
159 return(array($this->name=>$s_return));
160 }
162 }
164 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
165 ?>