bd4d649b7c7df947b59882cf3edc24aed83a19d8
1 <?php
3 class servservice extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Manage server basic 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 var $goExportEntry = array();
11 var $goTimeSource = array();
12 var $goLdapBase = "";
13 var $goXdmcpIsEnabled = "";
14 var $goFontPath = "";
15 var $goNTPServer = "";
16 var $goShareServer = false;
17 var $goLdapServer = "";
18 var $goTerminalServer = "";
19 var $goSyslogServer = "";
20 var $goCupsServer = "";
21 var $goMailServer = "";
22 var $o_subWindow = NULL;
24 /* attribute list for save action */
25 var $ignore_account= TRUE;
26 var $attributes = array("goLdapBase","goXdmcpIsEnabled","goFontPath","goExportEntry","goTimeSource");
27 var $possible_objectclasses= array( "goShareServer", "goNtpServer", "goServer", "goLdapServer",
28 "goTerminalServer", "goSyslogServer", "goCupsServer","goMailServer");
29 var $objectclasses = array( "top","goServer");
30 var $additionaloc = array( "goShareServer" => array("goExportEntry"),
31 "goNtpServer" => array("goTimeSource"),
32 "goLdapServer" => array("goLdapBase"),
33 "goTerminalServer"=> array("goXdmcpIsEnabled", "goFontPath"),
34 "goSyslogServer" => array(),
35 "goMailServer" => array(),
36 "goCupsServer" => array());
38 function servservice ($config, $dn= NULL)
39 {
40 plugin::plugin ($config, $dn);
42 /* Assemble final object class list */
43 foreach ($this->additionaloc as $oc => $dummy){
44 if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
45 $this->objectclasses[$oc]= $oc;
46 }
47 }
49 /* Load arrays */
50 foreach (array("goTimeSource") as $name){
51 $tmp= array();
52 if (isset($this->attrs[$name])){
53 for ($i= 0; $i<$this->attrs[$name]['count']; $i++){
54 $tmp[$this->attrs[$name][$i]]= $this->attrs[$name][$i];
55 }
56 }
57 $this->$name= $tmp;
58 }
61 $tmp =array();
62 $tmp2=array();
63 if(isset($this->attrs['goExportEntry'])){
64 unset($this->attrs['goExportEntry']['count']);
65 if((isset($this->attrs['goExportEntry']))&&(isset($this->attrs['goExportEntry']))){
66 foreach($this->attrs['goExportEntry'] as $entry){
67 $tmp2= split("\|",$entry);
68 $tmp[$tmp2[0]]= $entry;
69 }
70 }
71 }
72 $this->goExportEntry = $tmp;
74 /* Always is account... */
75 $this->is_account= TRUE;
77 /* Check if goShareServer is defined */
78 if((isset($this->attrs['objectClass']))&&(is_array($this->attrs['objectClass']))){
79 if(in_array("goShareServer",$this->attrs['objectClass'])){
80 $this->goShareServer = true;
81 }
82 }
83 }
85 function addToList($entry){
86 $key = key($entry);
87 $this->goExportEntry[$key]=$entry[$key];
88 }
90 function deleteFromList($id){
91 unset($this->goExportEntry[$id]);
92 }
95 function execute()
96 {
97 /* Call parent execute */
98 plugin::execute();
100 /* Fill templating stuff */
101 $smarty= get_smarty();
103 $smarty->assign("staticAddress", "");
105 if((isset($_POST['DelNfsEnt']))&&(isset($_POST['goExportEntry']))){
106 $this->deleteFromList($_POST['goExportEntry']);
107 }
109 if(isset($_POST['NewNfsAdd'])){
110 $this->o_subWindow = new servnfs($this->config, $this->dn);
111 $this->dialog = true;
112 }
114 if((isset($_POST['NewNfsEdit']))&&(isset($_POST['goExportEntry']))){
115 $entry = $this->goExportEntry[$_POST['goExportEntry']];
116 $this->o_subWindow = new servnfs($this->config, $this->dn,$entry);
117 $this->dialog = true;
118 }
120 if(isset($this->o_subWindow)){
121 $this->o_subWindow->save_object(TRUE);
122 }
124 /* Save NFS setup */
125 if(isset($_POST['NFSsave'])){
126 if(count($this->o_subWindow->check())>0){
127 foreach($this->o_subWindow->check() as $msg) {
128 print_red($msg);
129 }
130 }else{
131 $this->o_subWindow->save_object();
132 $newone = $this->o_subWindow->save();
133 $this->addToList($newone) ;
134 unset($this->o_subWindow);
135 $this->dialog = false;
136 }
137 }
139 /* Cancel NFS setup */
140 if(isset($_POST['NFScancel'])){
141 unset($this->o_subWindow);
142 $this->dialog = false;
143 }
145 /* Execute NFS setup dialog*/
146 if(isset($this->o_subWindow)){
147 return $this->o_subWindow->execute();
148 }
150 /* Here we add a new entry */
151 if(isset($_POST['NewNTPAdd']) && $_POST['NewNTPExport'] != "") {
152 $this->goTimeSource[$_POST['NewNTPExport']]= $_POST['NewNTPExport'];
153 asort($this->goTimeSource);
154 }
156 /* Deleting an Entry, is a bit more complicated than adding one*/
157 if(isset($_POST['DelNTPEnt'])) {
158 foreach ($_POST['goTimeSource'] as $entry){
159 if (isset($this->goTimeSource[$entry])){
160 unset($this->goTimeSource[$entry]);
161 }
162 }
163 }
165 /* Attributes */
166 foreach ($this->attributes as $attr){
167 $smarty->assign("$attr", $this->$attr);
168 $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
169 $smarty->assign($attr."State","");
170 }
172 $tellSmarty=array();
173 foreach($this->goExportEntry as $name=>$values){
174 $tmp = split("\|",$values);
175 $tellSmarty[$name] = $tmp[0]." ".$tmp[4];
176 }
177 $smarty->assign("goExportEntry",array_keys($tellSmarty));
178 $smarty->assign("goExportEntryKeys",($tellSmarty));
179 $smarty->assign("goExportEntryACL", chkacl($this->acl, "goExportEntry"));
181 $smarty->assign("goTimeSource", $this->goTimeSource);
182 $smarty->assign("goTimeSourceACL", chkacl($this->acl, "goTimeSource"));
183 $smarty->assign("goTimeSourceState","");
186 /* Classes... */
187 foreach ($this->additionaloc as $oc => $dummy){
188 if (isset($this->objectclasses[$oc])){
189 $smarty->assign("$oc", "checked");
190 $smarty->assign("$oc"."State", "");
191 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
193 } else {
194 $smarty->assign("$oc", "");
195 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
196 $smarty->assign("$oc"."State", "disabled");
197 }
198 }
200 if(!$this->goShareServer){
201 $smarty->assign("goShareServerState", " disabled ");
202 $smarty->assign("goExportEntryACL", " disabled ");
203 }else{
204 $smarty->assign("goShareServerState", " ");
205 $smarty->assign("goExportEntryACL", " ");
206 }
208 /* Different handling for checkbox */
209 if($this->goXdmcpIsEnabled == "true"){
210 $smarty->assign("goXdmcpIsEnabled","checked");
211 } else {
212 $smarty->assign("goXdmcpIsEnabled","");
213 }
215 return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
216 }
219 function remove_from_parent()
220 {
221 /* This cannot be removed... */
222 }
225 /* Save data to object */
226 function save_object()
227 {
228 if (isset($_POST['servicetab'])){
229 $tmp = $this->goTimeSource;
231 if(isset($_POST['goLdapBase'])){
232 $this->goLdapBase = $_POST['goLdapBase'];
233 }
235 /* Save checkbox state */
236 foreach ($this->additionaloc as $oc => $dummy){
237 if($oc == "goNtpServer") continue;
238 if (chkacl($this->acl, $oc) == ""){
239 if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
240 $this->objectclasses[$oc]= $oc;
241 } else {
242 unset($this->objectclasses[$oc]);
243 }
244 }
245 }
247 /* Save xdmcp is enabled flag */
248 if (isset($_POST['goXdmcpIsEnabled'])){
249 $this->goXdmcpIsEnabled= "true";
250 } else {
251 $this->goXdmcpIsEnabled= "false";
252 }
254 /* Save xdmcp is enabled flag */
255 if (isset($_POST['goShareServer'])){
256 $this->goShareServer = true;
257 } else {
258 $this->goShareServer = false;
259 }
260 $this->goTimeSource = array();
261 $this->goTimeSource = $tmp;
262 }
263 }
266 /* Check supplied data */
267 function check()
268 {
269 $message= array();
271 if((isset($_POST['goTerminalServer']))&&(empty($this->goFontPath))){
272 $message[]=_("Terminal server, must have fontpath specified.");
273 }
275 return ($message);
276 }
279 /* Save to LDAP */
280 function save()
281 {
282 plugin::save();
284 $tmp= array();
286 /* Remove all from this plugin */
287 foreach($this->attrs['objectClass'] as $oc){
288 if (!in_array_ics($oc, $this->possible_objectclasses)){
289 $tmp[]= $oc;
290 }
291 }
293 /* Merge our current objectclasses */
294 foreach($this->objectclasses as $oc){
295 if (!in_array_ics($oc, $tmp)){
296 $tmp[]= $oc;
297 }
298 }
300 /* Reassign cleaned value */
301 $this->attrs['objectClass']= $tmp;
303 /* Arrays */
304 foreach (array("goTimeSource", "goExportEntry") as $name){
305 $this->attrs[$name]= array();
306 foreach ($this->$name as $element){
307 $this->attrs[$name][]= $element;
308 }
309 }
311 /* Remove illegal attributes */
312 foreach ($this->additionaloc as $oc => $attrs){
313 if (!in_array($oc, $this->objectclasses)){
314 foreach ($attrs as $attr){
315 $this->attrs[$attr]= array();
316 }
317 }
318 }
320 /* Write to LDAP */
321 $ldap= $this->config->get_ldap_link();
322 $ldap->cd($this->dn);
323 $this->cleanup();
324 $ldap->modify ($this->attrs);
326 show_ldap_error($ldap->get_error());
328 /* Optionally execute a command after we're done */
329 if ($this->initially_was_account == $this->is_account){
330 if ($this->is_modified){
331 $this->handle_post_events("mofify");
332 }
333 } else {
334 $this->handle_post_events("add");
335 }
336 }
338 }
340 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
341 ?>