1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
24 #
25 # NewDevices
26 # -> Edit
27 # |- SelectDeviceType() (Allows to select target SystemType and OGroup)
28 # -> Save
29 # |-> systemTypeChosen() (Queue entry to be activated)
30 # |-> handleActivationQueue() (Now acticvate queued objects)
31 # |-> Ogroup selected
32 # | |-> Try to adapt values from ogroup and save directly.
33 # |
34 # |-> NO Ogroup selected
35 # | |-> Open dialogs of the target system type and allow modifcations.
36 # |
37 # |->activate_new_device() (Finally activate the device - FAIsate=..)
38 #
39 #
40 # NewArpDevices (NewUnknwonDevices )
41 # -> Edit
42 # |-> editEntry - ArpNewDeviceTabs
43 # -> Save
44 # |-> NO gotoIntegeration
45 # | |-> Save DHCP and DNS entries, then remove the source entry from ldap.
46 # |
47 # |-> gotoIntegration selected (Handle object like a NewDevice now)
48 # |-> systemTypeChosen() (Queue entry to be activated)
49 # |-> handleActivationQueue() (Now acticvate queued objects)
50 # |-> Ogroup selected
51 # | |-> Try to adapt values from ogroup and save directly.
52 # |
53 # |-> NO Ogroup selected
54 # | |-> Open dialogs of the target system type and allow modifcations.
55 # |
56 # |->activate_new_device() (Finally activate the device - FAIsate=..)
57 #
58 class systemManagement extends management
59 {
60 var $plHeadline = "Systems";
61 var $plDescription = "Manage systems, their services and prepare them for use with GOsa";
62 var $plIcon = "plugins/systems/images/plugin.png";
64 // Tab definition
65 protected $tabClass = "";
66 protected $tabType = "";
67 protected $aclCategory = "";
68 protected $aclPlugin = "";
69 protected $objectName = "system";
70 protected $objectInfo = array();
71 protected $opsi = NULL;
72 protected $activationQueue = array();
74 function __construct($config,$ui)
75 {
76 $this->config = $config;
77 $this->ui = $ui;
79 // Set storage points
80 $tD = $this->getObjectDefinitions();
81 $sP = array();
82 foreach($tD as $entry){
83 if(!empty($entry['ou']))
84 $sP[] = $entry['ou'];
85 }
86 $this->storagePoints = array_unique($sP);
88 // Build filter
89 if (session::global_is_set(get_class($this)."_filter")){
90 $filter= session::global_get(get_class($this)."_filter");
91 } else {
92 $filter = new filter(get_template_path("system-filter.xml", true));
93 $filter->setObjectStorage($this->storagePoints);
94 }
95 $this->setFilter($filter);
97 // Build headpage
98 $headpage = new listing(get_template_path("system-list.xml", true));
99 $headpage->registerElementFilter("systemRelease", "systemManagement::systemRelease");
100 $headpage->registerElementFilter("filterSystemDescription", "systemManagement::filterSystemDescription");
101 $headpage->setFilter($filter);
102 $filter->setConverter('systemManagement::incomingFilterConverter');
104 // Register Daemon Events
105 if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
106 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
107 foreach($events['TRIGGERED'] as $name => $data){
108 $this->registerAction("T_".$name,"handleEvent");
109 $this->registerAction("S_".$name,"handleEvent");
110 }
111 $this->registerAction("activateMultiple","activateMultiple");
112 }
113 $this->registerAction("saveEvent","saveEventDialog");
114 $this->registerAction("createISO","createISO");
115 $this->registerAction("initiateISOcreation","initiateISOcreation");
116 $this->registerAction("performIsoCreation","performIsoCreation");
117 $this->registerAction("systemTypeChosen","systemTypeChosen");
118 $this->registerAction("handleActivationQueue","handleActivationQueue");
120 $this->registerAction("new_goServer", "newEntry");
121 $this->registerAction("new_gotoWorkstation", "newEntry");
122 $this->registerAction("new_gotoTerminal", "newEntry");
123 $this->registerAction("new_gotoPrinter", "newEntry");
124 $this->registerAction("new_goFonHardware", "newEntry");
125 $this->registerAction("new_ieee802Device", "newEntry");
126 $this->registerAction("new_FAKE_OC_OpsiHost", "newEntry");
128 $this->registerAction("setPassword", "setPassword");
129 $this->registerAction("passwordChangeConfirmed", "passwordChangeConfirmed");
131 // Add copy&paste and snapshot handler.
132 if ($this->config->boolValueIsTrue("main", "copyPaste")){
133 $this->cpHandler = new CopyPasteHandler($this->config);
134 }
135 if($this->config->get_cfg_value("core","enableSnapshots") == "true"){
136 $this->snapHandler = new SnapshotHandler($this->config);
137 }
139 // Check if we are able to communicate with the GOsa supprot daemon
140 if(class_available("gosaSupportDaemon")){
141 $o = new gosaSupportDaemon();
142 $this->si_active = $o->connect() && class_available("DaemonEvent");
143 }
145 // Check if we are able to communicate with the GOsa supprot daemon
146 if(class_available("opsi")){
147 $this->opsi = new opsi($this->config);
148 }
149 parent::__construct($config, $ui, "systems", $headpage);
150 }
153 /*! \brief Act on password change requests.
154 */
155 function setPassword($action,$target)
156 {
157 if(count($target) == 1){
158 $tDefs= $this->getObjectDefinitions();
159 $headpage = $this->getHeadpage();
160 $dn = array_pop($target);
161 $type = $headpage->getType($dn);
162 $entry = $headpage->getEntry($dn);
163 $ui = get_userinfo();
164 $smarty = get_smarty();
165 if(in_array("FAKE_OC_PWD_changeAble", $entry['objectClass'])){
166 $acl = $tDefs[$type]['aclCategory'].'/'.$tDefs[$type]['aclClass'];
167 $tabacl = $ui->get_permissions($dn,$acl,"userPassword");
168 if(preg_match("/w/",$tabacl)){
169 $this->dn= $dn;
170 set_object_info($this->dn);
171 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
172 }else{
173 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
174 }
175 }
176 }
177 }
180 /*! \brief This method is used to queue and process copy&paste actions.
181 * Allows to copy, cut and paste mutliple entries at once.
182 * @param String 'action' The name of the action which was the used as trigger.
183 * @param Array 'target' A list of object dns, which should be affected by this method.
184 * @param Array 'all' A combination of both 'action' and 'target'.
185 */
186 function copyPasteHandler($action="",$target=array(),$all=array(),
187 $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
188 {
189 // Return without any actions while copy&paste handler is disabled.
190 if(!is_object($this->cpHandler)) return("");
192 // Save user input
193 $this->cpHandler->save_object();
195 // Add entries to queue
196 if($action == "copy" || $action == "cut"){
198 $tDefs= $this->getObjectDefinitions();
199 $headpage = $this->getHeadpage();
200 $ui = get_userinfo();
201 $this->cpHandler->cleanup_queue();
202 foreach($target as $dn){
204 $type = $headpage->getType($dn);
205 $entry = $headpage->getEntry($dn);
207 $aclCategory = $tDefs[$type]['aclCategory'];
208 $aclPlugin = $tDefs[$type]['aclClass'];
209 $tabClass = $tDefs[$type]['tabClass'];
210 $tabType = $tDefs[$type]['tabDesc'];
212 if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
213 $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory,$this);
214 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!");
215 }
216 if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
217 $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory,$this);
218 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!");
219 }
220 }
221 }
223 // Initiate pasting
224 if($action == "paste"){
225 $this->cpPastingStarted = TRUE;
226 }
228 // Display any c&p dialogs, eg. object modifications required before pasting.
229 if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
230 $headpage = $this->getHeadpage();
231 $this->cpHandler->SetVar("base",$headpage->getBase());
232 $data = $this->cpHandler->execute();
233 if(!empty($data)){
234 return($data);
235 }
236 }
238 // Automatically disable pasting process since there is no entry left to paste.
239 if(!$this->cpHandler->entries_queued()){
240 $this->cpPastingStarted = FALSE;
241 }
242 return("");
243 }
246 /*! \brief Password change confirmed, now try to change the systems pwd.
247 */
248 function passwordChangeConfirmed()
249 {
250 $tDefs= $this->getObjectDefinitions();
251 $headpage = $this->getHeadpage();
252 $type = $headpage->getType($this->dn);
253 $entry = $headpage->getEntry($this->dn);
254 $ui = get_userinfo();
255 $smarty = get_smarty();
257 if(!in_array('FAKE_OC_PWD_changeAble', $entry['objectClass'])){
258 trigger_error("Tried to change pwd, for invalid object!");
259 }elseif ($_POST['new_password'] != $_POST['repeated_password']){
260 msg_dialog::display(_("Error"),
261 _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
262 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
263 }else{
264 $acl = $tDefs[$type]['aclCategory'].'/'.$tDefs[$type]['aclClass'];
265 $tabacl = $ui->get_permissions($this->dn,$acl,"userPassword");
267 // Check acls
268 if(!preg_match("/w/",$tabacl)){
269 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
270 }else{
271 $ldap = $this->config->get_ldap_link();
272 $ldap->cd($this->dn);
273 $ldap->cat($this->dn);
274 $old_attrs = $ldap->fetch();
276 $attrs= array();
277 if ($_POST['new_password'] == ""){
279 /* Remove password attribute
280 */
281 if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
282 $attrs['objectClass'] = array();
283 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
284 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
285 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
286 }
287 }
288 }
289 $attrs['userPassword']= array();
290 } else {
292 /* Add/modify password attribute
293 */
294 if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
295 $attrs['objectClass'] = array();
296 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
297 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
298 }
299 $attrs['objectClass'][] = "simpleSecurityObject";
300 }
302 if(class_available("passwordMethodCrypt")){
303 $pwd_m = new passwordMethodCrypt($this->config);
304 $pwd_m->set_hash("crypt/md5");
305 $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
306 }else{
307 msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
308 $attrs = array();
309 }
310 }
311 $ldap->modify($attrs);
312 if (!$ldap->success()){
313 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, $type));
314 }else{
315 if(class_available($tDefs[$type]['plugClass'])){
316 $plug = $tDefs[$type]['plugClass'];
317 $p = new $plug($this->config,$this->dn);
318 $p->handle_post_events("modify");
319 }
320 }
321 new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
322 }
323 set_object_info();
324 }
325 }
328 /*! \brief The method gets called when somebody clicked the CD icon
329 * in the system listing.
330 * A confirmation will be shown to acknowledge the creation.
331 */
332 function createISO($action,$target)
333 {
334 if(count($target) == 1){
335 $smarty = get_smarty();
336 $this->dn= array_pop($target);
337 set_object_info($this->dn);
338 return ($smarty->fetch(get_template_path('goto/gencd.tpl', TRUE)));
340 }
341 }
344 /*! \brief Once the user has confirmed the ISO creation in 'createISO',
345 * this method gets called.
346 * An iFrame is shown which then used 'performIsoCreation' as contents.
347 */
348 function initiateISOcreation()
349 {
350 $smarty = get_smarty();
351 $smarty->assign("src", "?plug=".$_GET['plug']."&PerformIsoCreation");
352 return ($smarty->fetch(get_template_path('goto/gencd_frame.tpl', TRUE)));
353 }
356 /*! \brief ISO creation confirmed and iFrame is visible, now create the ISO
357 * and display the status to fill the iFrame.
358 */
359 function performIsoCreation()
360 {
361 $return_button = "<form method='get' action='main.php' target='_parent'>
362 <input type='submit' value='"._("Back")."'>
363 <input type='hidden' name='plug' value='".$_GET['plug']."'/>
364 </form>";
366 $dsc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
368 /* Get and check command */
369 $command= $this->config->search("workgeneric", "SYSTEMISOHOOK",array('tabs'));
370 if (check_command($command)){
371 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
373 /* Print out html introduction */
374 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
375 <html>
376 <head>
377 <title></title>
378 <style type="text/css">@import url("themes/default/style.css");</style>
379 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
380 </head>
381 <body style="background: none; margin:4px;" id="body" >
382 <pre>';
384 /* Open process handle and check if it is a valid process */
385 $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
386 if (is_resource($process)) {
387 fclose($pipes[0]);
389 /* Print out returned lines && write JS to scroll down each line */
390 while (!feof($pipes[1])){
391 $cur_dat = fgets($pipes[1], 1024);
392 echo $cur_dat;
393 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
394 flush();
395 }
396 }
398 /* Get error string && close streams */
399 $buffer= stream_get_contents($pipes[2]);
401 fclose($pipes[1]);
402 fclose($pipes[2]);
403 echo "</pre>";
405 /* Check return code */
406 $ret= proc_close($process);
407 if ($ret != 0){
408 echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
409 echo "<pre style='color:red'>$buffer</pre>";
410 }
411 echo $return_button."<br>";
412 } else {
413 $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
414 echo $tmp;
415 echo $return_button."<br>";
416 }
418 /* Scroll down completly */
419 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
420 echo '</body></html>';
421 flush();
422 exit;
423 }
426 /*! \brief Handle GOsa-si events
427 * All schedules and triggered events are handled here.
428 */
429 function handleEvent($action="",$target=array(),$all=array())
430 {
431 // Detect whether this event is scheduled or triggered.
432 $triggered = TRUE;
433 if(preg_match("/^S_/",$action)){
434 $triggered = FALSE;
435 }
437 // Detect triggere or scheduled actions
438 $headpage = $this->getHeadpage();
439 $event = preg_replace("/^[TS]_/","",$action);
440 if(preg_match("/^[TS]_/", $action)){
442 // Send special reinstall action for opsi hosts
443 if($event == "DaemonEvent_reinstall" && $this->si_active && $this->opsi){
444 foreach($target as $key => $dn){
445 $type = $headpage->getType($dn);
447 // Send Reinstall event for opsi hosts
448 if($type == "FAKE_OC_OpsiHost"){
449 $obj = $headpage->getEntry($dn);
450 $this->opsi->job_opsi_install_client($obj['cn'][0],$obj['macAddress'][0]);
451 unset($target[$key]);
452 }
453 }
454 }
455 }
457 // Now send remaining FAI/GOsa-si events here.
458 if(count($target) && $this->si_active){
459 $mac= array();
461 // Collect target mac addresses
462 $ldap = $this->config->get_ldap_link();
463 $tD = $this->getObjectDefinitions();
464 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
465 $o_queue = new gosaSupportDaemon();
466 foreach($target as $dn){
467 $type = $headpage->getType($dn);
468 if($tD[$type]['sendEvents']){
469 $obj = $headpage->getEntry($dn);
470 if(isset($obj['macAddress'][0])){
471 $mac[] = $obj['macAddress'][0];
472 }
473 }
474 }
476 /* Skip installation or update trigerred events,
477 * if this entry is currently processing.
478 */
479 if($triggered && in_array($event,array("DaemonEvent_reinstall","DaemonEvent_update"))){
480 foreach($mac as $key => $mac_address){
481 foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
482 $entry['STATUS'] = strtoupper($entry['STATUS']);
483 if($entry['STATUS'] == "PROCESSING" &&
484 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
485 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
486 unset($mac[$key]);
488 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
489 break;
490 }
491 }
492 }
493 }
495 // Prepare event to be added
496 if(count($mac) && isset($events['BY_CLASS'][$event]) && $this->si_active){
497 $event = $events['BY_CLASS'][$event];
498 $this->dialogObject = new $event['CLASS_NAME']($this->config);
499 $this->dialogObject->add_targets($mac);
501 if($triggered){
502 $this->dialogObject->set_type(TRIGGERED_EVENT);
503 $o_queue->append($this->dialogObject);
504 if($o_queue->is_error()){
505 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
506 }else{
507 $this->closeDialogs();
508 }
509 }else{
510 $this->dialogObject->set_type(SCHEDULED_EVENT);
511 }
512 }
513 }
514 }
517 /*! \brief Close all dialogs and reset the activationQueue.
518 */
519 function cancelEdit()
520 {
521 management::cancelEdit();
522 $this->activationQueue = array();
523 }
526 /*! \brief Save event dialogs.
527 * And append the new GOsa-si event.
528 */
529 function saveEventDialog()
530 {
531 $o_queue = new gosaSupportDaemon();
532 $o_queue->append($this->dialogObject);
533 if($o_queue->is_error()){
534 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
535 }else{
536 $this->closeDialogs();
537 }
538 }
541 /*! \brief Update filter part for INCOMING.
542 * Allows us to search for "systemIncomingRDN".
543 */
544 static function incomingFilterConverter($filter)
545 {
546 $rdn = preg_replace("/^[^=]*=/", "", get_ou('systemIncomingRDN'));
547 $rdn = preg_replace("/,.*$/","",$rdn);
548 return(preg_replace("/%systemIncomingRDN/", $rdn,$filter));
549 }
552 /*! \brief Queue selected objects to be removed.
553 * Checks ACLs, Locks and ask for confirmation.
554 */
555 protected function removeEntryRequested($action="",$target=array(),$all=array())
556 {
557 // Close dialogs and remove locks for currently handled dns
558 $this->cancelEdit();
560 $disallowed = array();
561 $this->dns = array();
563 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
565 // Check permissons for each target
566 $tInfo = $this->getObjectDefinitions();
567 $headpage = $this->getHeadpage();
568 foreach($target as $dn){
569 $type = $headpage->getType($dn);
570 if(!isset($tInfo[$type])){
571 trigger_error("Unknown object type received '".$type."' please update systemManagement::getObjectDefinitions()!");
572 }else{
573 $info = $tInfo[$type];
574 $acl = $this->ui->get_permissions($dn, $info['aclCategory']."/".$info['aclClass']);
575 if(preg_match("/d/",$acl)){
576 $this->dns[] = $dn;
577 }else{
578 $disallowed[] = $dn;
579 }
580 }
581 }
582 if(count($disallowed)){
583 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
584 }
586 // We've at least one entry to delete.
587 if(count($this->dns)){
589 // check locks
590 if ($user= get_multiple_locks($this->dns)){
591 return(gen_locked_message($user,$this->dns));
592 }
594 // Add locks
595 $dns_names = array();
596 $types = array();
597 $h = $this->getHeadpage();
599 // Build list of object -labels
600 foreach($h->objectTypes as $type){
601 $map[$type['objectClass']]= $type['label'];
602 }
604 foreach($this->dns as $dn){
605 $tmp = $h->getType($dn);
606 if(isset($map[$tmp])){
607 $dns_names[] = '('._($map[$tmp]).') - '.LDAP::fix($dn);
608 }else{
609 $dns_names[] =LDAP::fix($dn);
610 }
611 }
612 add_lock ($this->dns, $this->ui->dn);
614 // Display confirmation dialog.
615 $smarty = get_smarty();
616 $smarty->assign("info", msgPool::deleteInfo($dns_names));
617 return($smarty->fetch(get_template_path('removeEntries.tpl')));
618 }
619 }
622 /*! \brief Object removal was confirmed, now remove the requested entries.
623 *
624 * @param String 'action' The name of the action which was the used as trigger.
625 * @param Array 'target' A list of object dns, which should be affected by this method.
626 * @param Array 'all' A combination of both 'action' and 'target'.
627 */
628 function removeEntryConfirmed($action="",$target=array(),$all=array(),
629 $altTabClass="",$altTabType="",$altAclCategory="", $aclPlugin="")
630 {
631 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
633 // Check permissons for each target
634 $tInfo = $this->getObjectDefinitions();
635 $headpage = $this->getHeadpage();
636 $disallowed = array();
637 foreach($this->dns as $key => $dn){
638 $type = $headpage->getType($dn);
639 if(!isset($tInfo[$type])){
640 trigger_error("Unknown object type received '".$type."' please update systemManagement::getObjectDefinitions()!");
641 }else{
643 $info = $tInfo[$type];
644 $acl = $this->ui->get_permissions($dn, $info['aclCategory']."/".$info['aclClass']);
645 if(preg_match("/d/",$acl)){
647 // Delete the object
648 $this->dn = $dn;
649 if($info['tabClass'] == "phonetabs"){
650 $this->tabObject= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
651 $this->tabObject->set_acl_base($dn);
652 $this->tabObject->by_object['phoneGeneric']->remove_from_parent ();
653 }else{
654 $this->tabObject= new $info['tabClass']($this->config,$this->config->data['TABS'][$info['tabDesc']],
655 $this->dn, $info['aclCategory'], true, true);
656 $this->tabObject->set_acl_base($this->dn);
657 $this->tabObject->parent = &$this;
658 $this->tabObject->delete ();
659 }
661 // Remove the lock for the current object.
662 del_lock($this->dn);
664 }else{
665 $disallowed[] = $dn;
666 new log("security","system/".get_class($this),$dn,array(),"Tried to trick deletion.");
667 }
668 }
669 }
670 if(count($disallowed)){
671 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
672 }
674 // Cleanup
675 $this->remove_lock();
676 $this->closeDialogs();
677 }
680 /*! \brief Edit the selected system type.
681 * NewDevice and ArpNewDevice are handled here separately
682 */
683 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
684 {
685 if(count($target) == 1){
686 $tInfo = $this->getObjectDefinitions();
687 $headpage = $this->getHeadpage();
688 $dn = $target[0];
689 $type =$headpage->getType($dn);
690 $tData = $tInfo[$type];
692 if($type == "FAKE_OC_ArpNewDevice"){
693 if(!class_available("ArpNewDeviceTabs")){
694 msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
695 }else{
696 return(management::editEntry($action,$target,$all,"ArpNewDeviceTabs","ARPNEWDEVICETABS","incoming"));
697 }
698 }elseif($type == "FAKE_OC_NewDevice"){
699 if(!class_available("SelectDeviceType")){
700 msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
701 }else{
702 $this->activationQueue[$dn] = array();
703 $this->dialogObject = new SelectDeviceType($this->config,$dn);
704 $this->dialogObject->set_acl_category("incoming");
705 $this->skipFooter = TRUE;
706 $this->displayApplyBtn = FALSE;
707 // see condition -$s_action == "::systemTypeChosen"- for further handling
708 }
709 }else{
710 return(management::editEntry($action,$target,$all,$tData['tabClass'],$tData['tabDesc'],$tData['aclCategory']));
711 }
712 }
713 }
716 /*! \brief Edit the selected system type.
717 *
718 * @param String 'action' The name of the action which was the used as trigger.
719 * @param Array 'target' A list of object dns, which should be affected by this method.
720 * @param Array 'all' A combination of both 'action' and 'target'.
721 */
722 function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
723 {
724 $tInfo = $this->getObjectDefinitions();
725 $info = preg_replace("/^new_/","",$action);
726 if(!isset($tInfo[$info])){
727 trigger_error("Unknown action type '".$action."' cant create a new system!");
728 }else{
729 return(management::newEntry($action,$target,$all,
730 $tInfo[$info]['tabClass'],
731 $tInfo[$info]['tabDesc'],
732 $tInfo[$info]['aclCategory']));
733 }
734 }
737 /*! \brief Activates all selcted 'NewDevices' at once.
738 * Enqueues the selected Devices in the activation queue.
739 */
740 function activateMultiple($action,$target)
741 {
742 $headpage = $this->getHeadpage();
743 foreach($target as $dn) {
744 if($headpage->getType($dn) == "FAKE_OC_NewDevice"){
745 $this->activationQueue[$dn] = array();
746 }
747 }
748 if(count($this->activationQueue)){
749 $this->dialogObject = new SelectDeviceType($this->config, array_keys($this->activationQueue));
750 $this->skipFooter = TRUE;
751 }
752 }
755 /*! \brief The system selection dialog was closed.
756 * We will now queue the given entry to be activated.
757 */
758 function systemTypeChosen()
759 {
760 // Detect the systems target type
761 $tInfo = $this->getObjectDefinitions();
762 $selected_group = "none";
763 if(isset($_POST['ObjectGroup'])){
764 $selected_group = $_POST['ObjectGroup'];
765 }
766 $selected_system = $_POST['SystemType'];
767 $tmp = array();
768 foreach($this->activationQueue as $dn => $data){
769 $tmp[$dn]['OG'] = $selected_group;
770 $tmp[$dn]['SS'] = $selected_system;
771 }
772 $this->closeDialogs();
773 $this->activationQueue = $tmp;
774 return($this->handleActivationQueue());
775 }
778 /*! \brief Activate queued goto systems.
779 */
780 function handleActivationQueue()
781 {
782 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
783 'Entries left: '.count($this->activationQueue), "<b>Handling system activation queue!</b>");
785 if(!count($this->activationQueue)) return("");
787 $ldap = $this->config->get_ldap_link();
788 $pInfo = $this->getObjectDefinitions();
789 $ui = get_userinfo();
790 $headpage = $this->getHeadpage();
791 $ldap->cd($this->config->current['BASE']);
793 // Walk through systems to activate
794 while(count($this->activationQueue)){
796 // Get next entry
797 reset($this->activationQueue);
798 $dn = key($this->activationQueue);
799 $data= $this->activationQueue[$dn];
801 // Validate the given system type.
802 if(!isset($data['SS'])) continue;
803 $sysType = $data['SS'];
804 if(!isset($pInfo[$sysType])){
805 trigger_error('Unknown type \''.$sysType.'\'!');
806 continue;
807 }
808 $type = $pInfo[$sysType];
810 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
811 $dn, "<b>Try to activate:</b>");
813 // Get target type definition
814 $plugClass = $type["plugClass"];
815 $tabClass = $type["tabClass"];
816 $aclCategory = $type["aclCategory"];
817 $tabDesc = $type["tabDesc"];
819 if(!class_available($tabClass)){
820 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
821 unset($this->activationQueue[$dn]);
822 continue;
823 }else{
825 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
826 $sysType, "<b>System type:</b>");
828 // Load permissions for selected 'dn' and check if we're allowed to create this 'dn'
829 $this->dn = $dn;
830 $acls = $ui->get_permissions($this->dn,$aclCategory."/".$plugClass);
832 // Check permissions
833 if(!preg_match("/c/",$acls)){
834 unset($this->activationQueue[$dn]);
835 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
837 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
838 $acls, "<b>Insufficient permissions!</b>");
839 continue;
840 }else{
842 // Open object an preset some values like the objects base
843 del_lock($dn);
844 management::editEntry('editEntry',array($dn),array(),$tabClass,$tabDesc, $aclCategory);
845 $this->displayApplyBtn = FALSE;
846 $this->tabObject->set_acl_base($headpage->getBase());
848 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
849 $data['OG'], "<b>Selected ogroup:</b>");
851 if($data['OG'] != "none"){
852 $this->tabObject->base = preg_replace("/^[^,]+,".preg_quote(get_ou('ogroupRDN'), '/')."/i", "", $data['OG']);
853 $this->tabObject->by_object[$plugClass]->baseSelector->setBase($this->tabObject->base);
854 } else {
855 $this->tabObject->by_object[$plugClass]->baseSelector->setBase($headpage->getBase());
856 $this->tabObject->base = $headpage->getBase();
857 }
859 // Assign some default values for opsi hosts
860 if($this->tabObject instanceOf opsi_tabs){
861 $ldap = $this->config->get_ldap_link();
862 $ldap->cat($dn);
863 $source_attrs = $ldap->fetch();
864 foreach(array("macAddress" => "mac" ,"cn" => "hostId","description" => "description") as $src => $attr){
865 if(isset($source_attrs[$src][0])){
866 $this->tabObject->by_object['opsiGeneric']->$attr = $source_attrs[$src][0];
867 }
868 }
869 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
870 "", "<b>OPSI attributes adapted</b>");
871 }
873 // Queue entry to be activated, when it is saved.
874 if($data['OG'] != "none"){
876 // Set gotoMode to active if there was an ogroup selected.
877 $found = false;
878 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
879 if(isset($this->tabObject->by_object[$tab]->gotoMode)) {
880 $found = true;
881 $this->tabObject->by_object[$tab]->gotoMode = $value;
882 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
883 $tab."->gotoMode = {$value}", "<b>Setting gotoMode to: </b>");
884 }
885 }
886 if(!$found){
887 msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
888 }
890 // Update object group membership
891 $og = new ogroup($this->config,$data['OG']);
892 if($og){
893 $og->AddDelMembership($this->tabObject->dn);
894 $og->save();
895 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
896 $og->dn, "<b>Adding system to ogroup</b>");
897 }
899 // Set default system specific attributes
900 foreach (array("workgeneric", "termgeneric") as $cls){
901 if (isset($this->tabObject->by_object[$cls])){
902 $this->tabObject->by_object[$cls]->set_everything_to_inherited();
903 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
904 $og->dn, "<b>Calling {$cls}->set_everything_to_inherited()</b>");
905 }
906 }
908 // Enable activation
909 foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
910 if (isset($this->tabObject->by_object[$cls])){
911 $this->tabObject->by_object[$cls]->auto_activate= TRUE;
912 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
913 $cls, "<b>Setting auto_activate=TRUE for</b>");
914 }
915 }
917 // Enable sending of LDAP events
918 if (isset($this->tabObject->by_object["workstartup"])){
919 $this->tabObject->by_object["workstartup"]->gotoLdap_inherit= TRUE;
920 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
921 "", "<b>Setting workstartup->gotoLdap_inherit=TRUE</b>");
922 }
923 }
925 // Try to inherit everythin from the selected object group and then save
926 // the entry, normally this should work without any problems.
927 // But if there is any, then display the dialogs.
928 if($data['OG'] != "none"){
929 $str = $this->saveChanges();
931 // There was a problem, skip activation here and allow to fix the problems..
932 if(is_object($this->tabObject)){
933 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
934 "", "<b>Automatic saving failed, let the user fix the issues now.</b>");
935 return;
936 }
937 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
938 "", "<b>System activated!</b>");
939 }else{
940 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
941 "", "<b>Open dialogs now</b>");
942 return;
943 }
944 }
945 }
946 }
947 }
950 /*! \brief Save object modifications here and any dialogs too.
951 * After a successfull update of the object data, close
952 * the dialogs.
953 */
954 protected function saveChanges()
955 {
956 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
957 get_class($this->tabObject).": ".$this->tabObject->dn, "<b>Save</b>");
959 // Handle 'New Unknown Devices' here.
960 if($this->tabObject instanceOf ArpNewDeviceTabs){
961 $this->tabObject->save_object();
963 if($this->tabObject->by_object['ArpNewDevice']->gotoIntegration){
964 $message = $this->tabObject->check();
965 if(count($message)){
966 msg_dialog::displayChecks($message);
967 }else{
968 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
969 get_class($this->tabObject).": ".$this->tabObject->dn, "<b>Queued for goto activation</b>");
970 $this->tabObject->save();
971 $this->activationQueue[$this->tabObject->dn]=array();
972 $this->closeDialogs();
973 $this->systemTypeChosen();
974 }
975 return;
976 }
977 }
979 // Try to save changes here.
980 $str = management::saveChanges();
981 if($this->tabObject) return("");
983 // Activate system if required..
984 if(isset($this->activationQueue[$this->last_dn])){
985 $dn = $this->last_tabObject->dn;
986 $this->activate_new_device($dn);
987 unset($this->activationQueue[$this->last_dn]);
988 }
990 /* Post handling for activated systems
991 target opsi -> Remove source.
992 target gosa -> Activate system.
993 */
994 if($this->last_tabObject instanceOf opsi_tabs){
995 $ldap = $this->config->get_ldap_link();
996 $ldap->cd($this->config->current['BASE']);
997 $ldap->rmdir ($this->last_tabObject->dn);
998 @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__,
999 "Source removed: ".$this->tabObject->dn,"<b>Opsi host activated</b>");
1001 $hostId = $this->last_tabObject->by_object['opsiGeneric']->hostId;
1002 $mac = $this->last_tabObject->by_object['opsiGeneric']->mac;
1003 $this->opsi->job_opsi_activate_client($hostId,$mac);
1005 }elseif(isset($this->last_tabObject->was_activated) && $this->last_tabObject->was_activated){
1006 $this->activate_new_device($this->last_tabObject->dn);
1007 }
1009 // Avoid using values from an older input dialog
1010 $_POST = array();
1011 $this->handleActivationQueue();
1012 }
1015 /*! \brief Save object modifications here and any dialogs too.
1016 * Keep dialogs opened.
1017 */
1018 protected function applyChanges()
1019 {
1020 $str = management::applyChanges();
1021 if($str) return($str);
1023 /* Post handling for activated systems
1024 target opsi -> Remove source.
1025 target gosa -> Activate system.
1026 */
1027 if($this->tabObject instanceOf opsi_tabs){
1028 $ldap = $this->config->get_ldap_link();
1029 $ldap->cd($this->config->current['BASE']);
1030 $ldap->rmdir ($this->tabObject->dn);
1031 @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__,
1032 "Source removed: ".$this->tabObject->dn,"<b>Opsi host activated</b>");
1034 $hostId = $this->tabObject->by_object['opsiGeneric']->hostId;
1035 $mac = $this->tabObject->by_object['opsiGeneric']->mac;
1036 $this->opsi->job_opsi_activate_client($hostId,$mac);
1037 $this->tabObject->set_acl_base($this->dn);
1039 }elseif(isset($this->tabObject->was_activated) && $this->tabObject->was_activated){
1040 $this->activate_new_device($this->tabObject->dn);
1041 }
1042 }
1045 /*! \brief Sets FAIstate to "install" for "New Devices".
1046 This function is some kind of "Post handler" for activated systems,
1047 it is called directly after the object (workstabs,servtabs) gets saved.
1048 @param String $dn The dn of the newly activated object.
1049 @return Boolean TRUE if activated else FALSE
1050 */
1051 function activate_new_device($dn)
1052 {
1053 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1054 $dn, "<b>Activating system:</b>");
1055 $ldap = $this->config->get_ldap_link();
1056 $ldap->cd($this->config->current['BASE']);
1057 $ldap->cat($dn);
1058 if($ldap->count()){
1059 $attrs = $ldap->fetch();
1060 if(count(array_intersect(array('goServer','gotoWorkstation'), $attrs['objectClass']))){
1061 $ocs = $attrs['objectClass'];
1062 unset($ocs['count']);
1063 $new_attrs = array();
1064 if(!in_array("FAIobject",$ocs)){
1065 $ocs[] = "FAIobject";
1066 $new_attrs['objectClass'] = $ocs;
1067 }
1068 $new_attrs['FAIstate'] = "install";
1069 $ldap->cd($dn);
1070 $ldap->modify($new_attrs);
1071 if (!$ldap->success()){
1072 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn,
1073 LDAP_MOD, "activate_new_device($dn)"));
1074 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1075 $dn, "<b>Failed!</b>");
1076 }else{
1077 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1078 $dn, "<b>Success</b>");
1079 return(TRUE);
1080 }
1081 }else{
1082 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1083 $dn, "<b>FAIstate not set to install, this is only done for gotoWorkstation/goServer!</b>");
1084 }
1085 }
1086 return(FALSE);
1087 }
1090 /*! \brief Opens the snapshot creation dialog for the given target.
1091 *
1092 * @param String 'action' The name of the action which was the used as trigger.
1093 * @param Array 'target' A list of object dns, which should be affected by this method.
1094 * @param Array 'all' A combination of both 'action' and 'target'.
1095 */
1096 function createSnapshotDialog($action="",$target=array(),$all=array())
1097 {
1098 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Snaptshot creation initiated!");
1100 $pInfo = $this->getObjectDefinitions();
1101 $headpage = $this->getHeadpage();
1102 foreach($target as $dn){
1104 $entry = $headpage->getEntry($dn);
1105 $type = $headpage->getType($dn);
1106 if(!isset($pInfo[$type])) {
1107 trigger_error('Unknown system type \''.$type.'\'!');
1108 return;
1109 }
1111 if(!empty($dn) && $this->ui->allow_snapshot_create($dn,$pInfo[$type]['aclCategory'])){
1112 $this->dialogObject = new SnapShotDialog($this->config,$dn,$this);
1113 $this->dialogObject->aclCategories = array($pInfo[$type]['aclCategory']);
1114 $this->dialogObject->parent = &$this;
1116 }else{
1117 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$dn),
1118 ERROR_DIALOG);
1119 }
1120 }
1121 }
1124 /*! \brief Displays the "Restore snapshot dialog" for a given target.
1125 * If no target is specified, open the restore removed object
1126 * dialog.
1127 * @param String 'action' The name of the action which was the used as trigger.
1128 * @param Array 'target' A list of object dns, which should be affected by this method.
1129 * @param Array 'all' A combination of both 'action' and 'target'.
1130 */
1131 function restoreSnapshotDialog($action="",$target=array(),$all=array())
1132 {
1133 // Set current restore base for snapshot handling.
1134 $headpage = $this->getHeadpage();
1135 $pInfo = $this->getObjectDefinitions();
1136 if(is_object($this->snapHandler)){
1137 $bases = array();
1138 foreach($this->storagePoints as $sp){
1139 $bases[] = $sp.$headpage->getBase();
1140 }
1141 }
1143 // No bases specified? Try base
1144 if(!count($bases)) $bases[] = $this->headpage->getBase();
1146 // No target, open the restore removed object dialog.
1147 if(!count($target)){
1149 $cats = array();
1150 foreach($pInfo as $data){
1151 $cats[] = $data['aclCategory'];
1152 }
1153 $cats = array_unique($cats);
1155 $entry = $headpage->getBase();
1156 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$cats)){
1157 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
1158 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
1159 $this->dialogObject->set_snapshot_bases($bases);
1160 $this->dialogObject->display_all_removed_objects = true;
1161 $this->dialogObject->display_restore_dialog = true;
1162 $this->dialogObject->parent = &$this;
1163 }else{
1164 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
1165 ERROR_DIALOG);
1166 }
1167 }else{
1169 // Display the restore points for a given object.
1170 $dn = array_pop($target);
1171 $entry = $headpage->getEntry($dn);
1172 $type = $headpage->getType($dn);
1173 if(!isset($pInfo[$type])) {
1174 trigger_error('Unknown system type \''.$type.'\'!');
1175 return;
1176 }
1178 if(!empty($dn) && $this->ui->allow_snapshot_create($dn,$pInfo[$type]['aclCategory'])){
1179 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Snaptshot restoring initiated!");
1180 $this->dialogObject = new SnapShotDialog($this->config,$dn,$this);
1181 $this->dialogObject->set_snapshot_bases($bases);
1182 $this->dialogObject->display_restore_dialog = true;
1183 $this->dialogObject->parent = &$this;
1184 }else{
1185 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$dn),
1186 ERROR_DIALOG);
1187 }
1188 }
1189 }
1192 /*! \brief Restores a snapshot object.
1193 * The dn of the snapshot entry has to be given as ['target'] parameter.
1194 *
1195 * @param String 'action' The name of the action which was the used as trigger.
1196 * @param Array 'target' A list of object dns, which should be affected by this method.
1197 * @param Array 'all' A combination of both 'action' and 'target'.
1198 */
1199 function restoreSnapshot($action="",$target=array(),$all=array())
1200 {
1201 $dn = array_pop($target);
1202 $this->snapHandler->restore_snapshot($dn);
1203 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Snaptshot restored!");
1204 $this->closeDialogs();
1205 }
1208 /*! \brief Detects actions/events send by the ui
1209 * and the corresponding targets.
1210 */
1211 function detectPostActions()
1212 {
1213 $action= management::detectPostActions();
1214 if(isset($_POST['abort_event_dialog'])) $action['action'] = "cancel";
1215 if(isset($_POST['save_event_dialog'])) $action['action'] = "saveEvent";
1216 if(isset($_POST['cd_create'])) $action['action'] = "initiateISOcreation";
1217 if(isset($_GET['PerformIsoCreation'])) $action['action'] = "performIsoCreation";
1218 if(isset($_POST['SystemTypeAborted'])) $action['action'] = "cancel";
1219 if(isset($_POST['password_cancel'])) $action['action'] = "cancel";
1220 if(isset($_POST['password_finish'])) $action['action'] = "passwordChangeConfirmed";
1222 if(isset($_POST['new_goServer'])) $action['action'] = "new_goServer";
1223 if(isset($_POST['new_gotoWorkstation'])) $action['action'] = "new_gotoWorkstation";
1224 if(isset($_POST['new_gotoTerminal'])) $action['action'] = "new_gotoTerminal";
1225 if(isset($_POST['new_gotoPrinter'])) $action['action'] = "new_gotoPrinter";
1226 if(isset($_POST['new_goFonHardware'])) $action['action'] = "new_goFonHardware";
1227 if(isset($_POST['new_ieee802Device'])) $action['action'] = "new_ieee802Device";
1228 if(isset($_POST['new_FAKE_OC_OpsiHost'])) $action['action'] = "new_FAKE_OC_OpsiHost";
1230 if(!is_object($this->tabObject) && !is_object($this->dialogObject)){
1231 if(count($this->activationQueue)) $action['action'] = "handleActivationQueue";
1232 }
1234 if(isset($_POST['systemTypeChosen'])) $action['action'] = "systemTypeChosen";
1236 return($action);
1237 }
1240 /*! \brief Overridden render method of class management.
1241 * this allows us to add a release selection box.
1242 */
1243 function renderList()
1244 {
1245 $headpage = $this->getHeadpage();
1246 $headpage->update();
1248 $tD = $this->getObjectDefinitions();
1249 $smarty = get_smarty();
1250 foreach($tD as $name => $obj){
1251 $smarty->assign("USE_".$name, (empty($obj['TABNAME']) || class_available($obj['TABNAME'])));
1252 }
1254 $display = $headpage->render();
1255 return($this->getHeader().$display);
1256 }
1259 public function getObjectDefinitions()
1260 {
1261 $tabs = array(
1262 "FAKE_OC_OpsiHost" => array(
1263 "ou" => "",
1264 "plugClass" => "opsiGeneric",
1265 "tabClass" => "opsi_tabs",
1266 "tabDesc" => "OPSITABS",
1267 "aclClass" => "opsiGeneric",
1268 "sendEvents" => TRUE,
1269 "aclCategory" => "opsi"),
1271 "goServer" => array(
1272 "ou" => get_ou('serverRDN'),
1273 "plugClass" => "servgeneric",
1274 "tabClass" => "servtabs",
1275 "tabDesc" => "SERVTABS",
1276 "aclClass" => "servgeneric",
1277 "sendEvents" => TRUE,
1278 "aclCategory" => "server"),
1280 "gotoWorkstation" => array(
1281 "ou" => get_ou('workstationRDN'),
1282 "plugClass" => "workgeneric",
1283 "tabClass" => "worktabs",
1284 "tabDesc" => "WORKTABS",
1285 "aclClass" => "workgeneric",
1286 "sendEvents" => TRUE,
1287 "aclCategory" => "workstation"),
1289 "gotoTerminal" => array(
1290 "ou" => get_ou('terminalRDN'),
1291 "plugClass" => "termgeneric",
1292 "tabClass" => "termtabs",
1293 "sendEvents" => TRUE,
1294 "tabDesc" => "TERMTABS",
1295 "aclClass" => "termgeneric",
1296 "aclCategory" => "terminal"),
1298 "gotoPrinter" => array(
1299 "ou" => get_ou('printerRDN'),
1300 "plugClass" => "printgeneric",
1301 "tabClass" => "printtabs",
1302 "tabDesc" => "PRINTTABS",
1303 "aclClass" => "printgeneric",
1304 "sendEvents" => FALSE,
1305 "aclCategory" => "printer"),
1307 "FAKE_OC_NewDevice" => array(
1308 "ou" => get_ou('systemIncomingRDN'),
1309 "plugClass" => "termgeneric",
1310 "tabClass" => "termtabs",
1311 "sendEvents" => TRUE,
1312 "tabDesc" => "TERMTABS",
1313 "aclClass" => "termgeneric",
1314 "aclCategory" => "terminal"),
1316 "goFonHardware" => array(
1317 "ou" => get_ou('phoneRDN'),
1318 "plugClass" => "phoneGeneric",
1319 "tabClass" => "phonetabs",
1320 "tabDesc" => "PHONETABS",
1321 "sendEvents" => FALSE,
1322 "aclClass" => "phoneGeneric",
1323 "aclCategory" => "phone"),
1325 "FAKE_OC_winstation" => array(
1326 "ou" => get_winstations_ou(),
1327 "plugClass" => "wingeneric",
1328 "sendEvents" => TRUE,
1329 "tabClass" => "wintabs",
1330 "tabDesc" => "WINTABS",
1331 "aclClass" => "wingeneric",
1332 "aclCategory" => "winworkstation"),
1334 "ieee802Device" => array(
1335 "ou" => get_ou('componentRDN'),
1336 "plugClass" => "componentGeneric",
1337 "sendEvents" => FALSE,
1338 "tabClass" => "componenttabs",
1339 "tabDesc" => "COMPONENTTABS",
1340 "aclClass" => "componentGeneric",
1341 "aclCategory" => "component"),
1342 );
1344 // Now map some special types
1345 $tabs['FAKE_OC_NewWorkstation'] = &$tabs['gotoWorkstation'];
1346 $tabs['FAKE_OC_NewTerminal'] = &$tabs['gotoTerminal'];
1347 $tabs['FAKE_OC_NewServer'] = &$tabs['gotoWorkstation'];
1348 $tabs['gotoWorkstation__IS_BUSY'] = &$tabs['gotoWorkstation'];
1349 $tabs['gotoWorkstation__IS_ERROR'] = &$tabs['gotoWorkstation'];
1350 $tabs['gotoWorkstation__IS_LOCKED'] = &$tabs['gotoWorkstation'];
1351 $tabs['gotoTerminal__IS_BUSY'] = &$tabs['gotoTerminal'];
1352 $tabs['gotoTerminal__IS_ERROR'] = &$tabs['gotoTerminal'];
1353 $tabs['gotoTerminal__IS_LOCKED'] = &$tabs['gotoTerminal'];
1354 $tabs['FAKE_OC_TerminalTemplate'] = &$tabs['gotoTerminal'];
1355 $tabs['FAKE_OC_WorkstationTemplate'] = &$tabs['gotoTerminal'];
1356 $tabs['goServer__IS_BUSY'] = &$tabs['goServer'];
1357 $tabs['goServer__IS_ERROR'] = &$tabs['goServer'];
1358 $tabs['goServer__IS_LOCKED'] = &$tabs['goServer'];
1360 $tabs['FAKE_OC_ArpNewDevice'] = &$tabs['FAKE_OC_NewDevice'];
1362 return($tabs);
1363 }
1366 static function filterSystemDescription($row,$dn,$pid,$state,$description=array())
1367 {
1368 $dn= LDAP::fix(func_get_arg(1));
1369 $desc = isset($description[0])?$description[0]:" ";
1370 $rc = "";
1371 switch($state){
1372 case 'locked' : $rc = "<rowClass:entry-locked/><rowLabel:locked/>"; break;
1373 case 'error' : $rc = "<rowClass:entry-error/><rowLabel:error/>"; break;
1374 case 'busy' : $rc = "<rowClass:entry-busy/><rowLabel:busy/>"; break;
1375 case 'warning' : $rc = "<rowClass:entry-warning/><rowLabel:warning/>"; break;
1376 }
1377 return("<a href='?plug=".$_GET['plug']."&PID={$pid}&act=listing_edit_{$row}' title='{$dn}'>{$desc}</a>{$rc}");
1378 }
1380 static function systemRelease($a,$b,$c,$objectclasses= null,$class= null)
1381 {
1382 global $config;
1384 // No objectclasses set - go ahead
1385 if(!$objectclasses) return(" ");
1387 // Skip non fai objects
1388 if (!in_array_ics("FAIobject", $objectclasses)) {
1389 return " ";
1390 }
1392 // If we've an own fai class, just use this
1393 if ($class && is_array($class)) {
1394 foreach (explode(' ', $class[0]) as $element) {
1395 if ($element[0] == ":") {
1396 return " ".image('images/empty.png')." ".mb_substr($element, 1);
1397 }
1398 }
1399 }
1401 // Load information if needed
1402 $ldap = $config->get_ldap_link();
1403 $ldap->cd($config->current['BASE']);
1404 $ldap->search("(&(objectClass=gosaGroupOfNames)(FAIclass=*)(member=".$b."))",array('FAIclass','cn'));
1405 while($attrs = $ldap->fetch()){
1406 $rel = preg_replace("/^.*:/","",$attrs['FAIclass'][0]);
1407 $sys = sprintf(_("Inherited from %s"),$attrs['cn'][0]);
1408 $str = " ".image('plugins/ogroups/images/ogroup.png', "", $sys)." ".$rel;
1409 return($str);
1410 }
1412 return(" ");
1413 }
1416 /*! \brief !! Incoming dummy acls, required to defined acls for incoming objects
1417 */
1418 static function plInfo()
1419 {
1420 return (array(
1421 "plShortName" => _("Incoming objects"),
1422 "plDescription" => _("Incoming objects"),
1423 "plSelfModify" => FALSE,
1424 "plDepends" => array(),
1425 "plPriority" => 99,
1426 "plSection" => array("administration"),
1427 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1428 "objectClass" => "")),
1429 "plProvidedAcls"=> array()
1430 ));
1431 }
1432 }
1433 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1434 ?>