1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 require "tabs_terminal.inc";
21 require "tabs_workstation.inc";
22 require "tabs_printers.inc";
23 require "tabs_phone.inc";
24 require "tabs_server.inc";
25 require "tabs_component.inc";
26 require "tabs_winstation.inc";
29 class systems extends plugin
30 {
31 /* Definitions */
32 var $plHeadline = "Systems";
33 var $plDescription = "This does something";
34 var $departments = array();
36 /* Dialog attributes */
37 var $systab = NULL;
38 var $terminals= array();
39 var $ui = NULL;
40 var $DivListSystem;
42 function systems ($config, $ui)
43 {
44 /* Save configuration for internal use */
45 $this->config= $config;
46 $this->ui= $ui;
48 /* Creat dialog object */
49 $this->DivListSystem = new divListSystem($this->config,$this);
50 }
52 function execute()
53 {
54 /* Call parent execute */
55 plugin::execute();
57 $_SESSION['LOCK_VARS_TO_USE'] = array("/^user_edit_/i","/^user_del_/","/^act/","/^id/");
59 /********************
60 Check for functional posts, edit|delete|add|... system devices
61 ********************/
62 $s_action = ""; // Contains the action to proceed
63 $s_entry = ""; // The value for s_action
64 $base_back = ""; // The Link for Backbutton
65 $smarty = get_smarty();
67 /* Test Posts */
68 foreach($_POST as $key => $val){
69 // Post for delete
70 if(preg_match("/user_del.*/",$key)){
71 $s_action = "del";
72 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
73 // Post for edit
74 }elseif(preg_match("/user_edit_.*/",$key)){
75 $s_action="edit";
76 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
77 // Post for new
78 }elseif(preg_match("/user_new.*/",$key)){
79 $s_action="new";
80 }elseif(preg_match("/user_tplnew.*/i",$key)){
81 $s_action="new_tpl";
82 }elseif(preg_match("/user_setpwd_.*/i",$key)){
83 $s_action="change_pw";
84 $s_entry = preg_replace("/user_setpwd_/i","",$key);
85 }elseif(preg_match("/gen_cd_.*/i",$key)){
86 $s_action="gen_cd";
87 $s_entry = preg_replace("/gen_cd_/i","",$key);
88 }elseif(preg_match("/newsystem_.*/i",$key)){
89 $s_action="newsystem";
90 $s_entry = preg_replace("/newsystem_/i","",$key);
91 }
92 }
94 /* Incoming handling
95 * If someone made a systemtype and ogroup selection
96 * Display the new requested entry type ... servtab in case of server and so on.
97 */
98 if(isset($_POST['SystemTypeChoosen'])){
99 $s_action = "SelectedSystemType";
100 $s_entry = $_POST['SystemType'];
101 $_SESSION['SelectedSystemType']['ogroup'] = $_POST['ObjectGroup'];
102 $this->systab = NULL;
103 }
105 /* remove image tags from posted entry (posts looks like this 'name_x')*/
106 $s_entry = preg_replace("/_.$/","",$s_entry);
108 /* Edit was requested by pressing the name(link) of an item */
109 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
110 $s_action ="edit";
111 $s_entry = $_GET['id'];
112 }
114 /* Check for exeeded sizelimit */
115 if (($message= check_sizelimit()) != ""){
116 return($message);
117 }
119 /* Try to get informations about what kind of system to create */
120 if ($s_action=="new") {
121 return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
122 }
125 /********************
126 Create FAI CD ...
127 ********************/
128 if ($s_action=="gen_cd"){
129 $this->dn= $this->terminals[$s_entry]['dn'];
130 $_SESSION['objectinfo']= $this->dn;
131 return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
132 }
135 /********************
136 Create new system ...
137 ********************/
138 /* Create new default terminal
139 * Or create specified object of selected system type, from given incoming object
140 */
141 if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
143 /* If the current entry is an incoming object
144 * $sw = System type as posted in new incoming handling dialog
145 */
146 if($s_action == "SelectedSystemType") {
147 $sw = $s_entry;
148 }else{
149 if(isset($_POST['system'])){
150 $sw = $_POST['system'];
151 }else{
152 $sw = $s_entry;
153 }
154 $this->dn= "new";
155 }
156 $tabs = array(
157 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
158 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
159 "server" => array("CLASS"=>"SERVTABS", "TABNAME"=>"servgeneric", "TABCLASS" =>"servtabs", "ACL"=> "server"),
160 "printer" => array("CLASS"=>"PRINTTABS", "TABNAME"=>"printgeneric", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
161 "phone" => array("CLASS"=>"PHONETABS", "TABNAME"=>"phonegeneric", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
162 "component" => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentgeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
164 if(isset($tabs[$sw])){
165 $class = $tabs[$sw]["CLASS"];
166 $tabname = $tabs[$sw]["TABNAME"];
167 $tabclass = $tabs[$sw]["TABCLASS"];
168 $acl_cat = $tabs[$sw]["ACL"];
170 /* Load permissions for selected 'dn' and check if
171 we're allowed to remove this 'dn' */
172 $ui = get_userinfo();
173 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
174 if(preg_match("/c/",$tabacl)){
175 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
176 $this->systab->set_acl_base($this->DivListSystem->selectedBase);
177 $this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
178 $this->systab->base = $this->DivListSystem->selectedBase;
179 }else{
180 print_red(_("You are not allowed to create a new object of this type."));
181 }
182 }
183 }
185 /********************
186 Edit system ...
187 ********************/
189 /* User wants to edit data? */
190 if (($s_action == "edit") && (!isset($this->systab->config))){
192 $this->dn= $this->terminals[$s_entry]['dn'];
194 /* Check locking, save current plugin in 'back_plugin', so
195 the dialog knows where to return. */
196 if (($user= get_lock($this->dn)) != ""){
197 return(gen_locked_message ($user, $this->dn));
198 }
200 /* Find out more about the object type */
201 $ldap= $this->config->get_ldap_link();
202 $ldap->cat($this->dn, array('objectClass'));
203 $attrs= $ldap->fetch();
204 $type= $this->get_system_type($attrs['objectClass']);
206 /* Lock the current entry, so everyone will get the
207 above dialog */
208 $tabs = array(
209 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
210 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
211 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server"),
212 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
213 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
214 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation"),
215 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
218 if($type == "NewDevice"){
219 $this->systab = new SelectDeviceType($this->config,$this->dn) ;
220 }elseif(isset($tabs[$type])){
222 $class = $tabs[$type]["CLASS"];
223 $acl_cat = $tabs[$type]["ACL"];
224 $tabclass = $tabs[$type]["TABCLASS"];
226 $this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
227 $this->systab->set_acl_base($this->dn);
228 $_SESSION['objectinfo']= $this->dn;
229 add_lock ($this->dn, $this->ui->dn);
230 }else{
231 print_red (_("You can't edit this object type yet!"));
232 del_lock($this->dn);
233 }
234 }
237 /********************
238 Change password ...
239 ********************/
241 /* Set terminals root password */
242 if ($s_action=="change_pw"){
243 $tabs = array(
244 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
245 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"));
247 $type = $this->get_system_type($this->terminals[$s_entry]['objectClass']);
248 $class = $tabs[$type]["CLASS"];
249 $tabname = $tabs[$type]["TABNAME"];
250 $acl_cat = $tabs[$type]["ACL"];
251 $tabclass = $tabs[$type]["TABCLASS"];
252 $ui = get_userinfo();
253 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
254 if(preg_match("/w/",$tabacl)){
255 $this->dn= $this->terminals[$s_entry]['dn'];
256 $_SESSION['objectinfo']= $this->dn;
257 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
258 }else{
259 print_red(_("You are not allowed to change the password for this object."));
260 }
261 }
264 /********************
265 Password change finish, but check if entered data is ok
266 ********************/
268 /* Correctly specified? */
269 if (isset($_POST['password_finish'])){
270 if ($_POST['new_password'] != $_POST['repeated_password']){
271 print_red (_("Passwords entered as new and repeated do not match!"));
272 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
273 }
274 }
276 /********************
277 Password change finish
278 ********************/
280 /* Change terminal password */
281 if (isset($_POST['password_finish']) &&
282 $_POST['new_password'] == $_POST['repeated_password']){
284 /* Check if user is allowed to set password */
285 $tabs = array(
286 "terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
287 "workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"));
289 /* Detect object type */
290 $type = "";
291 foreach($this->terminals as $terminal){
292 if($terminal['dn'] == $this->dn){
293 $type = $this->get_system_type($terminal['objectClass']);
294 break;
295 }
296 }
298 /* Type detected */
299 if(!empty($type)){
301 /* Get infos */
302 $class = $tabs[$type]["CLASS"];
303 $tabname = $tabs[$type]["TABNAME"];
304 $acl_cat = $tabs[$type]["ACL"];
305 $tabclass = $tabs[$type]["TABCLASS"];
307 /* Get acls */
308 $ui = get_userinfo();
309 $tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
311 /* Check acls */
312 if(preg_match("/w/",$tabacl)){
313 $ldap = $this->config->get_ldap_link();
314 $ldap->cd($this->dn);
316 $attrs= array();
317 if ($_POST['new_password'] == ""){
318 $attrs['gotoRootPasswd']= array();
319 } else {
320 $attrs['gotoRootPasswd']= crypt($_POST['new_password'],substr(session_id(),0,2));
321 }
322 $ldap->modify($attrs);
323 gosa_log ("Password for '".$this->dn."' has been changed");
324 }else{
325 print_red(_("You are not allowed to change the password for this object."));
326 }
327 }else{
328 print_red(_("Can't detect object to change password."));
329 }
330 unset($_SESSION['objectinfo']);
331 }
334 /********************
335 Delete system cancel
336 ********************/
338 /* Delete terminal canceled? */
339 if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
340 del_lock ($this->dn);
341 unset($_SESSION['objectinfo']);
342 }
345 /********************
346 Delete system, confirm dialog
347 ********************/
349 /* Remove terminal was requested */
350 if ($s_action=="del"){
352 /* Get 'dn' from posted termlinst */
353 $this->dn = $this->terminals[$s_entry]['dn'];
354 $attrs = $this->terminals[$s_entry];
356 $type= $this->get_system_type($attrs['objectClass']);
357 $ui = get_userinfo();
358 $tabs = array(
359 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
360 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
361 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
362 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
363 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
364 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
365 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
368 /* get object type */
369 $tabtype = "termtabs";
370 $tabobj = "TERMTABS";
371 $tabacl = "";
372 if(isset($tabs[$type])){
373 $tabtype = $tabs[$type]['TABCLASS'];
374 $tabobj = $tabs[$type]['CLASS'];
375 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
376 }
378 /* Load permissions for selected 'dn' and check if
379 we're allowed to remove this 'dn' */
380 if(preg_match("/d/",$tabacl)){
382 /* Check locking, save current plugin in 'back_plugin', so
383 the dialog knows where to return. */
384 if (($user= get_lock($this->dn)) != ""){
385 return(gen_locked_message ($user, $this->dn));
386 }
388 /* Lock the current entry, so nobody will edit it during deletion */
389 add_lock ($this->dn, $this->ui->dn);
390 $smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
391 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
392 } else {
394 /* Obviously the user isn't allowed to delete. Show message and
395 clean session. */
396 print_red (_("You are not allowed to delete this component!"));
397 }
398 }
401 /********************
402 Delete system, confirmed
403 ********************/
404 /* Confirmation for deletion has been passed. Terminal should be deleted. */
405 if (isset($_POST['delete_terminal_confirm'])){
407 /* Find out more about the object type */
408 $ldap= $this->config->get_ldap_link();
409 $ldap->cat($this->dn, array('objectClass'));
410 $attrs= $ldap->fetch();
411 $type= $this->get_system_type($attrs['objectClass']);
413 $ui = get_userinfo();
415 $tabs = array(
416 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
417 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
418 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
419 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
420 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
421 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
422 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
424 /* get object type */
425 $tabtype = "termtabs";
426 $tabobj = "TERMTABS";
427 $tabacl = "";
428 if(isset($tabs[$type])){
429 $tabtype = $tabs[$type]['TABCLASS'];
430 $tabobj = $tabs[$type]['CLASS'];
431 $tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
432 }
434 /* Check if we are allowed to remove this object */
435 if(preg_match("/d/",$tabacl)){
437 /* Delete request is permitted, perform LDAP action */
438 if($tabtype=="phonetabs"){
439 $this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
440 $this->systab->set_acl_base($this->dn);
441 $this->systab->by_object['phonegeneric']->remove_from_parent ();
442 }else{
443 $this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
444 $this->systab->set_acl_base($this->dn);
445 $this->systab->delete();
446 }
447 unset ($this->systab);
448 gosa_log ("System object'".$this->dn."' has been removed");
449 $this->systab= NULL;
451 /* Terminal list has changed, reload it. */
452 } else {
454 /* Normally this shouldn't be reached, send some extra
455 logs to notify the administrator */
456 print_red (_("You are not allowed to delete this component!"));
457 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
458 "deletion.");
459 }
461 /* Remove lock file after successfull deletion */
462 del_lock ($this->dn);
463 }
466 /********************
467 Edit system type finished, check if everything went ok
468 ********************/
469 /* Finish user edit is triggered by the tabulator dialog, so
470 the user wants to save edited data. Check and save at this
471 point. */
472 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->systab->config))){
474 /* Check tabs, will feed message array */
475 $message= $this->systab->check();
477 /* Save, or display error message? */
478 if (count($message) == 0){
480 /* Save terminal data to ldap */
481 if(isset($_SESSION['SelectedSystemType']['ogroup'])){
482 foreach (array("workservice", "termservice") as $cls){
483 if (isset($this->systab->by_object[$cls])){
484 $this->systab->by_object[$cls]->gotoXMouseport= "";
485 $this->systab->by_object[$cls]->gotoXMouseType= "";
486 $this->systab->by_object[$cls]->gotoXResolution= "";
487 $this->systab->by_object[$cls]->gotoXColordepth= "";
488 }
489 }
490 }
491 $this->systab->save();
492 gosa_log ("System object'".$this->dn."' has been saved");
494 /* Incoming behavior; you can select a system type and an ogroup membership.
495 * If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
496 * Check if we must add the new object to an object group.
497 *
498 * If this is done, delete the old incoming entry... it is still there, because this is a new
499 * entry and not an edited one, so we will delete it.
500 */
502 if(isset($_SESSION['SelectedSystemType'])){
503 $SelectedSystemType= $_SESSION['SelectedSystemType'];
504 unset($_SESSION['SelectedSystemType']);
505 if($SelectedSystemType['ogroup'] != "none"){
506 $og = new ogroup($this->config,$SelectedSystemType['ogroup']);
507 if($og){
508 $og->AddDelMembership($this->systab->dn);
509 $og->save();
510 }
511 }
512 if(!isset($ldap)){
513 $ldap = $this->config->get_ldap_link();
514 }
515 $ldap->cd ($this->dn);
516 $ldap->cat($this->dn, array('dn'));
517 if(count($ldap->fetch())){
518 $ldap->cd($this->dn);
519 $ldap->rmDir($this->dn);
520 }
521 $ldap->cd($this->config->current['BASE']);
522 }
524 if (!isset($_POST['edit_apply'])){
525 /* Terminal has been saved successfully, remove lock from
526 LDAP. */
527 if ($this->dn != "new"){
528 del_lock ($this->dn);
529 }
531 unset ($this->systab);
532 $this->systab= NULL;
533 unset($_SESSION['objectinfo']);
534 }
535 } else {
536 /* Ok. There seem to be errors regarding to the tab data,
537 show message and continue as usual. */
538 show_errors($message);
539 }
540 }
542 /********************
543 Edit system was canceled
544 ********************/
545 /* Cancel dialogs */
546 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
547 if (isset($this->systab)){
548 del_lock ($this->systab->dn);
549 unset ($this->systab);
550 }
551 $this->systab= NULL;
552 unset($_SESSION['objectinfo']);
554 /* Remove ogroup selection, which was set while editing a new incoming entry */
555 if(isset($_SESSION['SelectedSystemType'])){
556 unset($_SESSION['SelectedSystemType']);
557 }
558 }
560 /********************
561 Display edit dialog, or some other
562 ********************/
564 /* Show tab dialog if object is present */
565 if (isset($this->systab->config)){
566 $display= $this->systab->execute();
568 /* Don't show buttons if tab dialog requests this */
569 if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
570 $display.= "<p style=\"text-align:right\">\n";
571 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
572 $display.= " \n";
573 if ($this->dn != "new"){
574 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
575 $display.= " \n";
576 }
577 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
578 $display.= "</p>";
579 }
580 return ($display);
581 }
583 /* Check if there is a snapshot dialog open */
584 $base = $this->DivListSystem->selectedBase;
585 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
586 return($str);
587 }
589 /* Display dialog with system list */
590 $this->DivListSystem->parent = $this;
591 $this->DivListSystem->execute();
593 /* Add departments if subsearch is disabled */
594 if(!$this->DivListSystem->SubSearch){
595 $this->DivListSystem->AddDepartments($this->DivListSystem->selectedBase);
596 }
597 $this->reload();
598 $this->DivListSystem->setEntries($this->terminals);
599 return($this->DivListSystem->Draw());
600 }
603 /* Return departments, that will be included within snapshot detection */
604 function get_used_snapshot_bases()
605 {
606 $tmp = array();
608 /* Check acls, if we are not allowed to create and write each plugin tab, skip this object */
610 $tabs = array(
611 "terminal" => "ou=terminals,ou=systems,",
612 "workstation" => "ou=workstations,ou=systems,",
613 "server" => "ou=servers,ou=systems,",
614 "printer" => "ou=printers,ou=systems,",
615 "phone" => "ou=phones,ou=systems,",
616 "winworkstation" => get_winstations_ou(),
617 "component" => "ou=netdevices,ou=systems,"
618 );
620 foreach($tabs as $acl_cat => $dn){
622 $acl_all = $this->ui->has_complete_category_acls($dn.$this->DivListSystem->selectedBase,$acl_cat);
623 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
624 $tmp[] = $dn.$this->DivListSystem->selectedBase;
625 }
626 }
627 return($tmp);
628 }
631 function remove_from_parent()
632 {
633 /* Optionally execute a command after we're done */
634 $this->postremove();
635 }
638 /* Save data to object */
639 function save_object()
640 {
641 $this->DivListSystem->save_object();
642 }
645 /* Check values */
646 function check()
647 {
648 }
651 /* Save to LDAP */
652 function save()
653 {
654 }
656 function adapt_from_template($dn)
657 {
658 }
660 function password_change_needed()
661 {
662 }
664 function reload()
665 {
666 /* some var init */
667 $ui = get_userinfo();
668 $res = array();
669 $this->terminals = array();
670 $userregex = "";
672 /* Set base for all searches */
673 $base= $this->DivListSystem->selectedBase;
675 /* Prepare samba class name */
676 $samba ="";
677 if ($this->DivListSystem->ShowWinWorkstations){
678 if ($this->config->current['SAMBAVERSION'] == "3"){
679 $samba= "sambaSamAccount";
680 } else {
681 $samba= "sambaAccount";
682 }
683 }
685 /* This array represents the combination between checkboxes and search filters */
686 $objs = array( "ShowServers" => array("CLASS" => "goServer" ,"TREE" => "ou=servers,ou=systems," ),
687 "ShowTerminals" => array("CLASS" => "gotoTerminal" ,"TREE" => "ou=terminals,ou=systems,"),
688 "ShowPrinters" => array("CLASS" => "gotoPrinter" ,"TREE" => "ou=printers,ou=systems," ),
689 "ShowDevices" => array("CLASS" => "ieee802Device" ,"TREE" => "ou=netdevices,ou=systems," ),
690 "ShowPhones" => array("CLASS" => "goFonHardware" ,"TREE" => "ou=phones,ou=systems," ),
691 "ShowWorkstations" => array("CLASS" => "gotoWorkstation" ,"TREE" => "ou=workstations,ou=systems," ),
692 "ShowWinWorkstations"=> array("CLASS" => $samba ,"TREE" => get_winstations_ou() ));
694 /* Include the 'Display Systems of user' attribute */
695 if ((!empty($this->DivListSystem->UserRegex)) && ($this->DivListSystem->UserRegex!= "*")){
696 $userregex = "(gotoLastUser=".$this->DivListSystem->UserRegex.")";
697 }
699 /* Walk through all possible search combinations, and search for some objects if the checkbox is enabled */
700 foreach($objs as $checkBox => $oc){
701 if($this->DivListSystem->$checkBox){
702 if($this->DivListSystem->SubSearch){
703 if($oc['CLASS'] != ""){
704 $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
705 $new_res = get_list($filter, array("terminal", "workstation", "server", "phone" ,"printer"), $base,
706 array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SUBSEARCH | GL_SIZELIMIT);
708 /* Remove all objects that are not in the expected sub department */
709 foreach($new_res as $key => $obj){
710 if(preg_match("/^[^,]+,".normalizePreg($oc['TREE'])."/",$obj['dn'])){
711 $res[$obj['dn']] = $obj;
712 }
713 }
714 }
715 }else{
716 /* User filter? */
717 if($oc['CLASS'] != ""){
718 $filter = "(|(&".$userregex."(objectClass=".$oc['CLASS'].")(cn=".$this->DivListSystem->Regex.")))";
719 $res = array_merge($res,get_list($filter,array("terminal", "workstation", "server", "phone" ,"printer"),$oc['TREE'].$base,
720 array("cn", "description", "macAddress", "objectClass", "sambaDomainName", "FAIstate"), GL_NONE | GL_SIZELIMIT));
721 }
722 }
723 }
724 }
726 /* Search for incoming objects */
727 $filter = "(|(&".$userregex."(objectClass=goHard)(cn=".$this->DivListSystem->Regex.")))";
728 $res = array_merge($res,get_list($filter,array("terminal", "workstation", "server", "phone" ,"printer"),"ou=incoming,".$base,
729 array("cn", "description", "macAddress", "objectClass", "sambaDomainName"), GL_NONE | GL_SIZELIMIT));
731 /* Get all gotoTerminal's */
732 foreach ($res as $value){
734 $tmp= $value['dn'];
735 $add= "";
737 /* Extract base */
738 foreach($objs as $obj){
739 if(preg_match("/,".$obj['TREE']."/i",$value['dn'])){
740 $tmp = trim( preg_replace("/^[^,]+,[^o]*".$obj['TREE']."/i","",$value['dn']));
741 }
742 }
744 /* Create a string containing the last part of the department. */
745 $dn_name = preg_replace("#^([^/]+/)*#","",convert_department_dn(@LDAP::fix($tmp)));
746 if(empty($dn_name)){
747 $dn_name = "/";
748 }
750 /* check if current object is a new one */
751 if (preg_match ("/,ou=incoming,/i", $tmp)){
752 if (in_array_ics('gotoTerminal', $value['objectClass'])){
753 $add= "- "._("New terminal");
754 }elseif (in_array_ics('gotoWorkstation', $value['objectClass'])){
755 $add= "- "._("New workstation");
756 }elseif (in_array_ics('GOhard', $value['objectClass'])){
757 $add= "- "._("New Device");
758 }
759 }
761 /* Detect type of object and create an entry for $this->terminals */
762 $terminal = array();
764 if (in_array_ics('gotoTerminal', $value["objectClass"])){
766 /* check acl */
767 $acl = $ui->get_permissions($value['dn'],"terminal/termgeneric");
768 if($add != "" || preg_match("/r/",$acl)) {
769 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
770 $terminal = $value;
771 $terminal['type'] = "T";
772 $terminal['is_new'] = $add;
773 } else {
774 $terminal = $value;
775 $terminal['type'] = "D";
776 $terminal['message'] = _("Terminal template for")." '".$dn_name."' ";
777 $terminal['location'] = array_search($tmp, $this->config->departments);
778 }
779 }
780 } elseif (in_array_ics('gotoWorkstation', $value["objectClass"])){
782 $acl = $ui->get_permissions($value['dn'],"workstation/workgeneric");
783 if($add != "" || preg_match("/r/",$acl)) {
784 if (isset($value["macAddress"][0]) && $value["macAddress"][0] != "-"){
785 $terminal = $value;
786 $terminal['type'] = "L";
787 $terminal['is_new'] = $add;
788 } else {
789 $terminal = $value;
790 $terminal['type'] = "D";
791 $terminal['location'] = array_search($tmp, $this->config->departments);
792 $terminal['message'] = _("Workstation template for")." '".$dn_name."' ";
793 }
794 if (isset($value["FAIstate"][0])){
795 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
796 }
797 }
798 } elseif (in_array_ics('gotoPrinter', $value["objectClass"])){
801 $acl = $ui->get_permissions($value['dn'],"printer/printgeneric");
802 if($add != "" || preg_match("/r/",$acl)) {
804 $terminal = $value;
805 $terminal['type'] = "P";
806 }
807 } elseif (in_array_ics('goServer', $value["objectClass"])){
809 $acl = $ui->get_permissions($value['dn'],"server/servgeneric");
810 if($add != "" || preg_match("/r/",$acl)) {
812 $terminal = $value;
813 $terminal['type'] = "S";
814 if (isset($value["FAIstate"][0])){
815 $terminal['type']= $this->getState($terminal['type'], $value["FAIstate"][0]);
816 }
817 }
818 } elseif (in_array_ics('goFonHardware', $value["objectClass"])){
820 $acl = $ui->get_permissions($value['dn'],"phone/phoneGeneric");
821 if($add != "" || preg_match("/r/",$acl)) {
823 $terminal = $value;
824 $terminal['type'] = "F";
825 }
826 }elseif (in_array_ics("GOhard",$value['objectClass'])){
828 $acl = $ui->get_permissions($value['dn'],"server/servgeneric").
829 $ui->get_permissions($value['dn'],"terminal/termgeneric").
830 $ui->get_permissions($value['dn'],"workstation/workgeneric");
831 if($add != "" || preg_match("/r/",$acl)) {
833 $terminal = $value;
834 $terminal['type'] = "Q";
835 $terminal['is_new'] = $add;
836 }
837 } elseif (in_array_ics('ieee802Device', $value["objectClass"])){
839 $acl = $ui->get_permissions($value['dn'],"component/componentGeneric");
840 if($add != "" || preg_match("/r/",$acl)) {
842 $terminal = $value;
843 $terminal['type'] = "C";
844 }
845 } else{
847 $name= preg_replace('/\$$/', '', $value['cn'][0]);
848 if (isset($value['sambaDomainName'])){
849 $domain= " [".$value['sambaDomainName'][0]."]";
850 } else {
851 $domain= "";
852 }
853 $terminal=$value;
854 $terminal['type'] ="W";
855 $terminal['domain'] = $name.$domain;
856 }
858 if(count($terminal)){
859 $this->terminals[]=$terminal;
860 }
861 }
863 $tmp=array();
864 foreach($this->terminals as $tkey => $val ){
865 $tmp[strtolower($val['cn'][0]).$val['dn']]=$val;
866 }
867 ksort($tmp);
868 $this->terminals=array();
869 foreach($tmp as $val){
870 $this->terminals[]=$val;
871 }
872 reset ($this->terminals);
873 }
875 function remove_lock()
876 {
877 if (isset($this->systab->dn)){
878 del_lock ($this->systab->dn);
879 }
880 }
883 function get_system_type($classes)
884 {
885 $type= "";
886 if (in_array_ics('ieee802Device', $classes)){
887 $type= "component";
888 }elseif (in_array_ics('gotoTerminal', $classes)){
889 $type= "terminal";
890 }elseif (in_array_ics('gotoWorkstation', $classes)){
891 $type= "workstation";
892 }elseif (in_array_ics('gotoPrinter', $classes)){
893 $type= "printer";
894 }elseif (in_array_ics('goFonHardware', $classes)){
895 $type= "phone";
896 }elseif (in_array_ics('goServer', $classes)){
897 $type= "server";
898 }elseif (in_array_ics('GOhard', $classes)){
899 $type= "NewDevice";
900 }elseif (in_array_ics('sambaAccount', $classes) ||
901 in_array_ics('sambaSamAccount', $classes)){
902 $type= "winstation";
903 }
904 return ($type);
905 }
908 function convert_list($input)
909 {
910 $temp= "";
911 $conv= array(
912 "NQ" => array("select_newsystem.png",_("New System from incoming")),
913 "D" => array("select_default.png",_("Template")),
914 "T" => array("select_terminal.png",_("Terminal")),
915 "L" => array("select_workstation.png",_("Workstation")),
916 "GL" => array("select_workstation_green.png",_("Workstation is installing")),
917 "YL" => array("select_workstation_yellow.png",_("Workstation is waiting for action")),
918 "RL" => array("select_workstation_red.png",_("Workstation installation failed")),
919 "F" => array("select_phone.png",_("Phone")),
920 "S" => array("select_server.png",_("Server")),
921 "GS" => array("select_server_green.png",_("Server is installing")),
922 "YS" => array("select_server_yellow.png",_("Server is waiting for action")),
923 "RS" => array("select_server_red.png",_("Server installation failed")),
924 "W" => array("select_winstation.png",_("Winstation")),
925 "C" => array("select_component.png",_("Network Device")),
926 "NT"=> array("select_new_terminal.png",_("New Terminal")),
927 "NL"=> array("select_new_workstation.png",_("New Workstation")),
928 "P" => array("select_printer.png",_("Printer")));
930 if((isset($input['is_new']))&&(!empty($input['is_new']))){
931 $input['type']="N".$input['type'];
932 }
933 foreach ($conv as $key => $value){
934 if($input['type']==$key){
935 $tmp['img'] ="<img class='center' src='images/".$value[0]."' alt='".$key."' title='".$value['1']."'>";
936 $tmp['class']=$key;
937 return $tmp;
938 }
939 }
940 }
943 function getState($type, $state)
944 {
945 switch (preg_replace('/:.*$/', '', $state)) {
946 case 'installing':
947 $type= 'G'.$type;
948 break;
949 case 'error':
950 $type= 'R'.$type;
951 break;
952 case 'install':
953 $type= 'Y'.$type;
954 break;
955 case 'sysinfo':
956 $type= 'Y'.$type;
957 break;
958 case 'softupdate':
959 $type= 'Y'.$type;
960 break;
961 }
964 return ($type);
965 }
967 }
969 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
970 ?>