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 #
62 class systemManagement extends management
63 {
64 var $plHeadline = "Systems";
65 var $plDescription = "List of systems";
66 var $plIcon = "plugins/systems/images/plugin.png";
68 // Tab definition
69 protected $tabClass = "";
70 protected $tabType = "";
71 protected $aclCategory = "";
72 protected $aclPlugin = "";
73 protected $objectName = "system";
74 protected $objectInfo = array();
75 protected $opsi = NULL;
76 protected $activationQueue = array();
78 function __construct($config,$ui)
79 {
80 $this->config = $config;
81 $this->ui = $ui;
83 // Set storage points
84 $tD = $this->getObjectDefinitions();
85 $sP = array();
86 foreach($tD as $entry){
87 if(!empty($entry['ou']))
88 $sP[] = $entry['ou'];
89 }
90 $this->storagePoints = array_unique($sP);
92 // Build filter
93 if (session::global_is_set(get_class($this)."_filter")){
94 $filter= session::global_get(get_class($this)."_filter");
95 } else {
96 $filter = new filter(get_template_path("system-filter.xml", true));
97 $filter->setObjectStorage($this->storagePoints);
98 }
99 $this->setFilter($filter);
101 // Build headpage
102 $headpage = new listing(get_template_path("system-list.xml", true));
103 $headpage->setFilter($filter);
104 $filter->setConverter('INCOMING', 'systemManagement::incomingFilterConverter');
106 // Register Daemon Events
107 if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
108 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
109 foreach($events['TRIGGERED'] as $name => $data){
110 $this->registerAction("T_".$name,"handleEvent");
111 $this->registerAction("S_".$name,"handleEvent");
112 }
113 $this->registerAction("activateMultiple","activateMultiple");
114 }
115 $this->registerAction("saveEvent","saveEventDialog");
116 $this->registerAction("createISO","createISO");
117 $this->registerAction("initiateISOcreation","initiateISOcreation");
118 $this->registerAction("performIsoCreation","performIsoCreation");
119 $this->registerAction("systemTypeChosen","systemTypeChosen");
120 $this->registerAction("handleActivationQueue","handleActivationQueue");
122 $this->registerAction("new_goServer", "newEntry");
123 $this->registerAction("new_gotoWorkstation", "newEntry");
124 $this->registerAction("new_gotoTerminal", "newEntry");
125 $this->registerAction("new_gotoPrinter", "newEntry");
126 $this->registerAction("new_goFonHardware", "newEntry");
127 $this->registerAction("new_ieee802Device", "newEntry");
128 $this->registerAction("new_FAKE_OC_OpsiHost", "newEntry");
130 $this->registerAction("setPassword", "setPassword");
131 $this->registerAction("passwordChangeConfirmed", "passwordChangeConfirmed");
133 // Add copy&paste and snapshot handler.
134 if ($this->config->boolValueIsTrue("main", "copyPaste")){
135 $this->cpHandler = new CopyPasteHandler($this->config);
136 }
137 if($this->config->get_cfg_value("enableSnapshots") == "true"){
138 $this->snapHandler = new SnapshotHandler($this->config);
139 }
141 // Check if we are able to communicate with the GOsa supprot daemon
142 if(class_available("gosaSupportDaemon")){
143 $o = new gosaSupportDaemon();
144 $this->si_active = $o->connect() && class_available("DaemonEvent");
145 }
147 // Check if we are able to communicate with the GOsa supprot daemon
148 if(class_available("opsi")){
149 $this->opsi = new opsi($this->config);
150 }
151 parent::__construct($config, $ui, "systems", $headpage);
152 }
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 }
181 /*! \brief This method is used to queue and process copy&paste actions.
182 * Allows to copy, cut and paste mutliple entries at once.
183 * @param String 'action' The name of the action which was the used as trigger.
184 * @param Array 'target' A list of object dns, which should be affected by this method.
185 * @param Array 'all' A combination of both 'action' and 'target'.
186 */
187 function copyPasteHandler($action="",$target=array(),$all=array(),
188 $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
189 {
190 // Return without any actions while copy&paste handler is disabled.
191 if(!is_object($this->cpHandler)) return("");
193 // Save user input
194 $this->cpHandler->save_object();
196 // Add entries to queue
197 if($action == "copy" || $action == "cut"){
199 $tDefs= $this->getObjectDefinitions();
200 $headpage = $this->getHeadpage();
201 $ui = get_userinfo();
202 $this->cpHandler->cleanup_queue();
203 foreach($target as $dn){
205 $type = $headpage->getType($dn);
206 $entry = $headpage->getEntry($dn);
208 $aclCategory = $tDefs[$type]['aclCategory'];
209 $aclPlugin = $tDefs[$type]['aclClass'];
210 $tabClass = $tDefs[$type]['tabClass'];
211 $tabType = $tDefs[$type]['tabDesc'];
213 if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
214 $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory,$this);
215 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!");
216 }
217 if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
218 $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory,$this);
219 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!");
220 }
221 }
222 }
224 // Initiate pasting
225 if($action == "paste"){
226 $this->cpPastingStarted = TRUE;
227 }
229 // Display any c&p dialogs, eg. object modifications required before pasting.
230 if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
231 $headpage = $this->getHeadpage();
232 $this->cpHandler->SetVar("base",$headpage->getBase());
233 $data = $this->cpHandler->execute();
234 if(!empty($data)){
235 return($data);
236 }
237 }
239 // Automatically disable pasting process since there is no entry left to paste.
240 if(!$this->cpHandler->entries_queued()){
241 $this->cpPastingStarted = FALSE;
242 }
243 return("");
244 }
247 function passwordChangeConfirmed()
248 {
249 $tDefs= $this->getObjectDefinitions();
250 $headpage = $this->getHeadpage();
251 $type = $headpage->getType($this->dn);
252 $entry = $headpage->getEntry($this->dn);
253 $ui = get_userinfo();
254 $smarty = get_smarty();
256 if(!in_array('FAKE_OC_PWD_changeAble', $entry['objectClass'])){
257 trigger_error("Tried to change pwd, for invalid object!");
258 }elseif ($_POST['new_password'] != $_POST['repeated_password']){
259 msg_dialog::display(_("Error"),
260 _("The passwords you've entered as 'New password' and 'Repeated password' do not match!"), ERROR_DIALOG);
261 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
262 }else{
263 $acl = $tDefs[$type]['aclCategory'].'/'.$tDefs[$type]['aclClass'];
264 $tabacl = $ui->get_permissions($this->dn,$acl,"userPassword");
266 // Check acls
267 if(!preg_match("/w/",$tabacl)){
268 msg_dialog::display(_("Permission error"), _("You have no permission to change this password!"), ERROR_DIALOG);
269 }else{
270 $ldap = $this->config->get_ldap_link();
271 $ldap->cd($this->dn);
272 $ldap->cat($this->dn);
273 $old_attrs = $ldap->fetch();
275 $attrs= array();
276 if ($_POST['new_password'] == ""){
278 /* Remove password attribute
279 */
280 if(in_array("simpleSecurityObject",$old_attrs['objectClass'])){
281 $attrs['objectClass'] = array();
282 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
283 if(!preg_match("/simpleSecurityObject/i",$old_attrs['objectClass'][$i])){
284 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
285 }
286 }
287 }
288 $attrs['userPassword']= array();
289 } else {
291 /* Add/modify password attribute
292 */
293 if(!in_array("simpleSecurityObject",$old_attrs['objectClass'])){
294 $attrs['objectClass'] = array();
295 for($i = 0 ; $i < $old_attrs['objectClass']['count'] ; $i ++){
296 $attrs['objectClass'][] = $old_attrs['objectClass'][$i];
297 }
298 $attrs['objectClass'][] = "simpleSecurityObject";
299 }
301 if(class_available("passwordMethodCrypt")){
302 $pwd_m = new passwordMethodCrypt($this->config);
303 $pwd_m->set_hash("crypt/md5");
304 $attrs['userPassword'] = $pwd_m->generate_hash($_POST['new_password']);
305 }else{
306 msg_dialog::display(_("Password method"),_("Password method crypt is missing. Cannot set system password."));
307 $attrs = array();
308 }
309 }
310 $ldap->modify($attrs);
311 if (!$ldap->success()){
312 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, $type));
313 }else{
314 if(class_available($tDefs[$type]['plugClass'])){
315 $plug = $tDefs[$type]['plugClass'];
316 $p = new $plug($this->config,$this->dn);
317 $p->handle_post_events("modify");
318 }
319 }
320 new log("security","systems/".get_class($this),$this->dn,array_keys($attrs),$ldap->get_error());
321 }
322 set_object_info();
323 }
324 }
327 /*! \brief The method gets called when somebody clicked the CD icon
328 * in the system listing.
329 * A confirmation will be shown to acknowledge the creation.
330 */
331 function createISO($action,$target)
332 {
333 if(count($target) == 1){
334 $smarty = get_smarty();
335 $this->dn= array_pop($target);
336 set_object_info($this->dn);
337 return ($smarty->fetch(get_template_path('goto/gencd.tpl', TRUE)));
339 }
340 }
343 /*! \brief Once the user has confirmed the ISO creation in 'createISO',
344 * this method gets called.
345 * An iFrame is shown which then used 'performIsoCreation' as contents.
346 */
347 function initiateISOcreation()
348 {
349 $smarty = get_smarty();
350 $smarty->assign("src", "?plug=".$_GET['plug']."&PerformIsoCreation");
351 return ($smarty->fetch(get_template_path('goto/gencd_frame.tpl', TRUE)));
352 }
355 /*! \brief ISO creation confirmed and iFrame is visible, now create the ISO
356 * and display the status to fill the iFrame.
357 */
358 function performIsoCreation()
359 {
360 $return_button = "<form method='get' action='main.php' target='_parent'>
361 <input type='submit' value='"._("Back")."'>
362 <input type='hidden' name='plug' value='".$_GET['plug']."'/>
363 </form>";
365 $dsc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
367 /* Get and check command */
368 $command= $this->config->search("workgeneric", "SYSTEMISOHOOK",array('tabs'));
369 if (check_command($command)){
370 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
372 /* Print out html introduction */
373 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
374 <html>
375 <head>
376 <title></title>
377 <style type="text/css">@import url("themes/default/style.css");</style>
378 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
379 </head>
380 <body style="background: none; margin:4px;" id="body" >
381 <pre>';
383 /* Open process handle and check if it is a valid process */
384 $process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
385 if (is_resource($process)) {
386 fclose($pipes[0]);
388 /* Print out returned lines && write JS to scroll down each line */
389 while (!feof($pipes[1])){
390 $cur_dat = fgets($pipes[1], 1024);
391 echo $cur_dat;
392 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
393 flush();
394 }
395 }
397 /* Get error string && close streams */
398 $buffer= stream_get_contents($pipes[2]);
400 fclose($pipes[1]);
401 fclose($pipes[2]);
402 echo "</pre>";
404 /* Check return code */
405 $ret= proc_close($process);
406 if ($ret != 0){
407 echo "<h1 style='color:red'>"._("Creating the image failed. Please see the report below.")."</h1>";
408 echo "<pre style='color:red'>$buffer</pre>";
409 }
410 echo $return_button."<br>";
411 } else {
412 $tmp= "<h1 style='color:red'>".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."</h1>";
413 echo $tmp;
414 echo $return_button."<br>";
415 }
417 /* Scroll down completly */
418 echo '<script language="javascript" type="text/javascript">scrollDown2();</script>' ;
419 echo '</body></html>';
420 flush();
421 exit;
422 }
425 /*! \brief Handle GOsa-si events
426 * All schedules and triggered events are handled here.
427 */
428 function handleEvent($action="",$target=array(),$all=array())
429 {
430 // Detect whether this event is scheduled or triggered.
431 $triggered = TRUE;
432 if(preg_match("/^S_/",$action)){
433 $triggered = FALSE;
434 }
436 // Detect triggere or scheduled actions
437 $headpage = $this->getHeadpage();
438 $event = preg_replace("/^[TS]_/","",$action);
439 if(preg_match("/^[TS]_/", $action)){
441 // Send special reinstall action for opsi hosts
442 if($event == "DaemonEvent_reinstall" && $this->si_active && $this->opsi){
443 foreach($target as $key => $dn){
444 $type = $headpage->getType($dn);
446 // Send Reinstall event for opsi hosts
447 if($type == "FAKE_OC_OpsiHost"){
448 $obj = $headpage->getEntry($dn);
449 $this->opsi->job_opsi_install_client($obj['cn'][0],$obj['macAddress'][0]);
450 unset($target[$key]);
451 }
452 }
453 }
454 }
456 // Now send remaining FAI/GOsa-si events here.
457 if(count($target) && $this->si_active){
458 $mac= array();
460 // Collect target mac addresses
461 $ldap = $this->config->get_ldap_link();
462 $tD = $this->getObjectDefinitions();
463 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
464 $o_queue = new gosaSupportDaemon();
465 foreach($target as $dn){
466 $type = $headpage->getType($dn);
467 if($tD[$type]['sendEvents']){
468 $obj = $headpage->getEntry($dn);
469 if(isset($obj['macAddress'][0])){
470 $mac[] = $obj['macAddress'][0];
471 }
472 }
473 }
475 /* Skip installation or update trigerred events,
476 * if this entry is currently processing.
477 */
478 if($triggered && in_array($event,array("DaemonEvent_reinstall","DaemonEvent_update"))){
479 foreach($mac as $key => $mac_address){
480 foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
481 $entry['STATUS'] = strtoupper($entry['STATUS']);
482 if($entry['STATUS'] == "PROCESSING" &&
483 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
484 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
485 unset($mac[$key]);
487 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
488 break;
489 }
490 }
491 }
492 }
494 // Prepare event to be added
495 if(count($mac) && isset($events['BY_CLASS'][$event]) && $this->si_active){
496 $event = $events['BY_CLASS'][$event];
497 $this->dialogObject = new $event['CLASS_NAME']($this->config);
498 $this->dialogObject->add_targets($mac);
500 if($triggered){
501 $this->dialogObject->set_type(TRIGGERED_EVENT);
502 $o_queue->append($this->dialogObject);
503 if($o_queue->is_error()){
504 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
505 }else{
506 $this->closeDialogs();
507 }
508 }else{
509 $this->dialogObject->set_type(SCHEDULED_EVENT);
510 }
511 }
512 }
513 }
516 /*! \brief Close all dialogs and reset the activationQueue.
517 */
518 function cancelEdit()
519 {
520 management::cancelEdit();
521 $this->activationQueue = array();
522 }
525 /*! \brief Save event dialogs.
526 * And append the new GOsa-si event.
527 */
528 function saveEventDialog()
529 {
530 $o_queue = new gosaSupportDaemon();
531 $o_queue->append($this->dialogObject);
532 if($o_queue->is_error()){
533 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
534 }else{
535 $this->closeDialogs();
536 }
537 }
540 /*! \brief Update filter part for INCOMING.
541 * Allows us to search for "systemIncomingRDN".
542 */
543 static function incomingFilterConverter($filter)
544 {
545 $rdn = preg_replace("/^[^=]*=/", "", get_ou('systemIncomingRDN'));
546 $rdn = preg_replace("/,.*$/","",$rdn);
547 return(preg_replace("/%systemIncomingRDN/", $rdn,$filter));
548 }
551 /*! \brief Queue selected objects to be removed.
552 * Checks ACLs, Locks and ask for confirmation.
553 */
554 protected function removeEntryRequested($action="",$target=array(),$all=array())
555 {
556 $disallowed = array();
557 $this->dns = array();
559 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
561 // Check permissons for each target
562 $tInfo = $this->getObjectDefinitions();
563 $headpage = $this->getHeadpage();
564 foreach($target as $dn){
565 $type = $headpage->getType($dn);
566 if(!isset($tInfo[$type])){
567 trigger_error("Unknown object type received '".$type."' please update systemManagement::getObjectDefinitions()!");
568 }else{
569 $info = $tInfo[$type];
570 $acl = $this->ui->get_permissions($dn, $info['aclCategory']."/".$info['aclClass']);
571 if(preg_match("/d/",$acl)){
572 $this->dns[] = $dn;
573 }else{
574 $disallowed[] = $dn;
575 }
576 }
577 }
578 if(count($disallowed)){
579 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
580 }
582 // We've at least one entry to delete.
583 if(count($this->dns)){
585 // check locks
586 if ($user= get_multiple_locks($this->dns)){
587 return(gen_locked_message($user,$this->dns));
588 }
590 // Add locks
591 $dns_names = array();
592 foreach($this->dns as $dn){
593 $dns_names[] =LDAP::fix($dn);
594 }
595 add_lock ($this->dns, $this->ui->dn);
597 // Display confirmation dialog.
598 $smarty = get_smarty();
599 $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
600 $smarty->assign("multiple", true);
601 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
602 }
603 }
606 /*! \brief Object removal was confirmed, now remove the requested entries.
607 *
608 * @param String 'action' The name of the action which was the used as trigger.
609 * @param Array 'target' A list of object dns, which should be affected by this method.
610 * @param Array 'all' A combination of both 'action' and 'target'.
611 */
612 function removeEntryConfirmed($action="",$target=array(),$all=array(),
613 $altTabClass="",$altTabType="",$altAclCategory="")
614 {
615 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
617 // Check permissons for each target
618 $tInfo = $this->getObjectDefinitions();
619 $headpage = $this->getHeadpage();
620 $disallowed = array();
621 foreach($this->dns as $key => $dn){
622 $type = $headpage->getType($dn);
623 if(!isset($tInfo[$type])){
624 trigger_error("Unknown object type received '".$type."' please update systemManagement::getObjectDefinitions()!");
625 }else{
627 $info = $tInfo[$type];
628 $acl = $this->ui->get_permissions($dn, $info['aclCategory']."/".$info['aclClass']);
629 if(preg_match("/d/",$acl)){
631 // Delete the object
632 $this->dn = $dn;
633 if($info['tabClass'] == "phonetabs"){
634 $this->tabObject= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $dn,$type);
635 $this->tabObject->set_acl_base($dn);
636 $this->tabObject->by_object['phoneGeneric']->remove_from_parent ();
637 }else{
638 $this->tabObject= new $info['tabClass']($this->config,$this->config->data['TABS'][$info['tabDesc']],
639 $this->dn, $info['aclCategory'], true, true);
640 $this->tabObject->set_acl_base($this->dn);
641 $this->tabObject->parent = &$this;
642 $this->tabObject->delete ();
643 }
645 // Remove the lock for the current object.
646 del_lock($this->dn);
648 }else{
649 $disallowed[] = $dn;
650 new log("security","system/".get_class($this),$dn,array(),"Tried to trick deletion.");
651 }
652 }
653 }
654 if(count($disallowed)){
655 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
656 }
658 // Cleanup
659 $this->remove_lock();
660 $this->closeDialogs();
661 }
664 /*! \brief Edit the selected system type.
665 * NewDevice and ArpNewDevice are handled here separately
666 */
667 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
668 {
669 if(count($target) == 1){
670 $tInfo = $this->getObjectDefinitions();
671 $headpage = $this->getHeadpage();
672 $dn = $target[0];
673 $type =$headpage->getType($dn);
674 $tData = $tInfo[$type];
676 if($type == "FAKE_OC_ArpNewDevice"){
677 if(!class_available("ArpNewDeviceTabs")){
678 msg_dialog::display(_("Error"), msgPool::class_not_found("ArpNewDevice"), ERROR_DIALOG);
679 }else{
680 return(management::editEntry($action,$target,$all,"ArpNewDeviceTabs","ARPNEWDEVICETABS","incoming"));
681 }
682 }elseif($type == "FAKE_OC_NewDevice"){
683 if(!class_available("SelectDeviceType")){
684 msg_dialog::display(_("Error"), msgPool::class_not_found("SelectDeviceType"), ERROR_DIALOG);
685 }else{
686 $this->activationQueue[$dn] = array();
687 $this->dialogObject = new SelectDeviceType($this->config,$dn);
688 $this->skipFooter = TRUE;
689 $this->displayApplyBtn = FALSE;
690 // see condition -$s_action == "::systemTypeChosen"- for further handling
691 }
692 }else{
693 return(management::editEntry($action,$target,$all,$tData['tabClass'],$tData['tabDesc'],$tData['aclCategory']));
694 }
695 }
696 }
699 /*! \brief Edit the selected system type.
700 *
701 * @param String 'action' The name of the action which was the used as trigger.
702 * @param Array 'target' A list of object dns, which should be affected by this method.
703 * @param Array 'all' A combination of both 'action' and 'target'.
704 */
705 function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
706 {
707 $tInfo = $this->getObjectDefinitions();
708 $info = preg_replace("/^new_/","",$action);
709 if(!isset($tInfo[$info])){
710 trigger_error("Unknown action type '".$action."' cant create a new system!");
711 }else{
712 management::newEntry($action,$target,$all,
713 $tInfo[$info]['tabClass'],
714 $tInfo[$info]['tabDesc'],
715 $tInfo[$info]['aclCategory']);
716 }
717 }
720 /*! \brief Activates all selcted 'NewDevices' at once.
721 * Enqueues the selected Devices in the activation queue.
722 */
723 function activateMultiple($action,$target)
724 {
725 $headpage = $this->getHeadpage();
726 foreach($target as $dn) {
727 if($headpage->getType($dn) == "FAKE_OC_NewDevice"){
728 $this->activationQueue[$dn] = array();
729 }
730 }
731 if(count($this->activationQueue)){
732 $this->dialogObject = new SelectDeviceType($this->config, array_keys($this->activationQueue));
733 $this->skipFooter = TRUE;
734 }
735 }
740 function systemTypeChosen()
741 {
742 // Detect the systems target type
743 $tInfo = $this->getObjectDefinitions();
744 $selected_group = "none";
745 if(isset($_POST['ObjectGroup'])){
746 $selected_group = $_POST['ObjectGroup'];
747 }
748 $selected_system = $_POST['SystemType'];
749 $tmp = array();
750 foreach($this->activationQueue as $dn => $data){
751 $tmp[$dn]['OG'] = $selected_group;
752 $tmp[$dn]['SS'] = $selected_system;
753 }
754 $this->closeDialogs();
755 $this->activationQueue = $tmp;
756 return($this->handleActivationQueue());
757 }
760 function handleActivationQueue()
761 {
762 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
763 'Entries left: '.count($this->activationQueue), "<b>Handling system activation queue!</b>");
765 if(!count($this->activationQueue)) return("");
767 $ldap = $this->config->get_ldap_link();
768 $pInfo = $this->getObjectDefinitions();
769 $ui = get_userinfo();
770 $headpage = $this->getHeadpage();
771 $ldap->cd($this->config->current['BASE']);
773 // Walk through systems to activate
774 while(count($this->activationQueue)){
776 // Get next entry
777 reset($this->activationQueue);
778 $dn = key($this->activationQueue);
779 $data= $this->activationQueue[$dn];
781 // Validate the given system type.
782 if(!isset($data['SS'])) continue;
783 $sysType = $data['SS'];
784 if(!isset($pInfo[$sysType])){
785 trigger_error('Unknown type \''.$sysType.'\'!');
786 continue;
787 }
788 $type = $pInfo[$sysType];
790 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
791 $dn, "<b>Try to activate:</b>");
793 // Get target type definition
794 $plugClass = $type["plugClass"];
795 $tabClass = $type["tabClass"];
796 $aclCategory = $type["aclCategory"];
797 $tabDesc = $type["tabDesc"];
799 if(!class_available($tabClass)){
800 msg_dialog::display(_("Error"), msgPool::class_not_found($tabclass), ERROR_DIALOG);
801 unset($this->activationQueue[$dn]);
802 continue;
803 }else{
805 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
806 $sysType, "<b>System type:</b>");
808 // Load permissions for selected 'dn' and check if we're allowed to create this 'dn'
809 $this->dn = $dn;
810 $acls = $ui->get_permissions($this->dn,$aclCategory."/".$plugClass);
812 // Check permissions
813 if(!preg_match("/c/",$acls)){
814 unset($this->activationQueue[$dn]);
815 msg_dialog::display(_("Error"), msgPool::permCreate(), ERROR_DIALOG);
817 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
818 $acls, "<b>Insufficient permissions!</b>");
819 continue;
820 }else{
822 // Open object an preset some values like the objects base
823 del_lock($dn);
824 management::editEntry('editEntry',array($dn),array(),$tabClass,$tabDesc, $aclCategory);
825 $this->displayApplyBtn = FALSE;
826 $this->tabObject->set_acl_base($headpage->getBase());
828 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
829 $data['OG'], "<b>Selected ogroup:</b>");
831 if($data['OG'] != "none"){
832 $this->tabObject->base = preg_replace("/^[^,]+,".preg_quote(get_ou('ogroupRDN'), '/')."/i", "", $data['OG']);
833 $this->tabObject->by_object[$plugClass]->base = $this->tabObject->base;
834 } else {
835 $this->tabObject->by_object[$plugClass]->base = $headpage->getBase();
836 $this->tabObject->base = $headpage->getBase();
837 }
839 // Assign some default values for opsi hosts
840 if($this->tabObject instanceOf opsi_tabs){
841 $ldap = $this->config->get_ldap_link();
842 $ldap->cat($dn);
843 $source_attrs = $ldap->fetch();
844 foreach(array("macAddress" => "mac" ,"cn" => "hostId","description" => "description") as $src => $attr){
845 if(isset($source_attrs[$src][0])){
846 $this->tabObject->by_object['opsiGeneric']->$attr = $source_attrs[$src][0];
847 }
848 }
849 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
850 "", "<b>OPSI attributes adapted</b>");
851 }
853 // Queue entry to be activated, when it is saved.
854 if($data['OG'] != "none"){
856 // Set gotoMode to active if there was an ogroup selected.
857 $found = false;
858 foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"active") as $tab => $value){
859 if(isset($this->tabObject->by_object[$tab]->gotoMode)) {
860 $found = true;
861 $this->tabObject->by_object[$tab]->gotoMode = $value;
862 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
863 $tab."->gotoMode = {$value}", "<b>Setting gotoMode to: </b>");
864 }
865 }
866 if(!$found){
867 msg_dialog::display(_("Internal error"), _("Cannot set mode to 'active'!"), ERROR_DIALOG);
868 }
870 // Update object group membership
871 $og = new ogroup($this->config,$data['OG']);
872 if($og){
873 $og->AddDelMembership($this->tabObject->dn);
874 $og->save();
875 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
876 $og->dn, "<b>Adding system to ogroup</b>");
877 }
879 // Set default system specific attributes
880 foreach (array("workgeneric", "termgeneric") as $cls){
881 if (isset($this->tabObject->by_object[$cls])){
882 $this->tabObject->by_object[$cls]->set_everything_to_inherited();
883 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
884 $og->dn, "<b>Calling {$cls}->set_everything_to_inherited()</b>");
885 }
886 }
888 // Enable activation
889 foreach (array("servgeneric", "workgeneric", "termgeneric") as $cls){
890 if (isset($this->tabObject->by_object[$cls])){
891 $this->tabObject->by_object[$cls]->auto_activate= TRUE;
892 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
893 $cls, "<b>Setting auto_activate=TRUE for</b>");
894 }
895 }
897 // Enable sending of LDAP events
898 if (isset($this->tabObject->by_object["workstartup"])){
899 $this->tabObject->by_object["workstartup"]->gotoLdap_inherit= TRUE;
900 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
901 "", "<b>Setting workstartup->gotoLdap_inherit=TRUE</b>");
902 }
903 }
905 // Try to inherit everythin from the selected object group and then save
906 // the entry, normally this should work without any problems.
907 // But if there is any, then display the dialogs.
908 if($data['OG'] != "none"){
909 $str = $this->saveChanges();
911 // There was a problem, skip activation here and allow to fix the problems..
912 if(is_object($this->tabObject)){
913 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
914 "", "<b>Automatic saving failed, let the user fix the issues now.</b>");
915 return;
916 }
917 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
918 "", "<b>System activated!</b>");
919 }else{
920 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
921 "", "<b>Open dialogs now</b>");
922 return;
923 }
924 }
925 }
926 }
927 }
930 /*! \brief Save object modifications here and any dialogs too.
931 * After a successfull update of the object data, close
932 * the dialogs.
933 */
934 protected function saveChanges()
935 {
936 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
937 get_class($this->tabObject).": ".$this->tabObject->dn, "<b>Save</b>");
939 // Handle 'New Unknown Devices' here.
940 if($this->tabObject instanceOf ArpNewDeviceTabs){
941 $this->tabObject->save_object();
943 if($this->tabObject->by_object['ArpNewDevice']->gotoIntegration){
944 $message = $this->tabObject->check();
945 if(count($message)){
946 msg_dialog::displayChecks($message);
947 }else{
948 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
949 get_class($this->tabObject).": ".$this->tabObject->dn, "<b>Queued for goto activation</b>");
950 $this->tabObject->save();
951 $this->activationQueue[$this->tabObject->dn]=array();
952 $this->closeDialogs();
953 $this->systemTypeChosen();
954 }
955 return;
956 }
957 }
959 // Try to save changes here.
960 $str = management::saveChanges();
961 if($this->tabObject) return("");
963 // Activate system if required..
964 if(isset($this->activationQueue[$this->last_dn])){
965 $dn = $this->last_tabObject->dn;
966 $this->activate_new_device($dn);
967 unset($this->activationQueue[$this->last_dn]);
968 }
970 /* Post handling for activated systems
971 target opsi -> Remove source.
972 target gosa -> Activate system.
973 */
974 if($this->last_tabObject instanceOf opsi_tabs){
975 $ldap = $this->config->get_ldap_link();
976 $ldap->cd($this->config->current['BASE']);
977 $ldap->rmdir ($this->last_tabObject->dn);
978 @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__,
979 "Source removed: ".$this->tabObject->dn,"<b>Opsi host activated</b>");
981 $hostId = $this->last_tabObject->by_object['opsiGeneric']->hostId;
982 $mac = $this->last_tabObject->by_object['opsiGeneric']->mac;
983 $this->opsi->job_opsi_activate_client($hostId,$mac);
985 }elseif(isset($this->last_tabObject->was_activated) && $this->last_tabObject->was_activated){
986 $this->activate_new_device($this->last_tabObject->dn);
987 }
989 // Avoid using values from an older input dialog
990 $_POST = array();
991 $this->handleActivationQueue();
992 }
995 /*! \brief Save object modifications here and any dialogs too.
996 * Keep dialogs opened.
997 */
998 protected function applyChanges()
999 {
1000 $str = management::applyChanges();
1001 if($str) return($str);
1003 /* Post handling for activated systems
1004 target opsi -> Remove source.
1005 target gosa -> Activate system.
1006 */
1007 if($this->tabObject instanceOf opsi_tabs){
1008 $ldap = $this->config->get_ldap_link();
1009 $ldap->cd($this->config->current['BASE']);
1010 $ldap->rmdir ($this->tabObject->dn);
1011 @DEBUG(DEBUG_LDAP,__LINE__, __FUNCTION__, __FILE__,
1012 "Source removed: ".$this->tabObject->dn,"<b>Opsi host activated</b>");
1014 $hostId = $this->tabObject->by_object['opsiGeneric']->hostId;
1015 $mac = $this->tabObject->by_object['opsiGeneric']->mac;
1016 $this->opsi->job_opsi_activate_client($hostId,$mac);
1018 }elseif(isset($this->tabObject->was_activated) && $this->tabObject->was_activated){
1019 $this->activate_new_device($this->tabObject->dn);
1020 }
1021 }
1024 /*! \brief Sets FAIstate to "install" for "New Devices".
1025 This function is some kind of "Post handler" for activated systems,
1026 it is called directly after the object (workstabs,servtabs) gets saved.
1027 @param String $dn The dn of the newly activated object.
1028 @return Boolean TRUE if activated else FALSE
1029 */
1030 function activate_new_device($dn)
1031 {
1032 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1033 $dn, "<b>Activating system:</b>");
1034 $ldap = $this->config->get_ldap_link();
1035 $ldap->cd($this->config->current['BASE']);
1036 $ldap->cat($dn);
1037 if($ldap->count()){
1038 $attrs = $ldap->fetch();
1039 if(count(array_intersect(array('goServer','gotoWorkstation'), $attrs['objectClass']))){
1040 $ocs = $attrs['objectClass'];
1041 unset($ocs['count']);
1042 $new_attrs = array();
1043 if(!in_array("FAIobject",$ocs)){
1044 $ocs[] = "FAIobject";
1045 $new_attrs['objectClass'] = $ocs;
1046 }
1047 $new_attrs['FAIstate'] = "install";
1048 $ldap->cd($dn);
1049 $ldap->modify($new_attrs);
1050 if (!$ldap->success()){
1051 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn,
1052 LDAP_MOD, "activate_new_device($dn)"));
1053 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1054 $dn, "<b>Failed!</b>");
1055 }else{
1056 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1057 $dn, "<b>Success</b>");
1058 return(TRUE);
1059 }
1060 }else{
1061 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
1062 $dn, "<b>FAIstate not set to install, this is only done for gotoWorkstation/goServer!</b>");
1063 }
1064 }
1065 return(FALSE);
1066 }
1070 /*! \brief Detects actions/events send by the ui
1071 * and the corresponding targets.
1072 */
1073 function detectPostActions()
1074 {
1075 $action= management::detectPostActions();
1076 if(isset($_POST['abort_event_dialog'])) $action['action'] = "cancel";
1077 if(isset($_POST['save_event_dialog'])) $action['action'] = "saveEvent";
1078 if(isset($_POST['cd_create'])) $action['action'] = "initiateISOcreation";
1079 if(isset($_GET['PerformIsoCreation'])) $action['action'] = "performIsoCreation";
1080 if(isset($_POST['SystemTypeAborted'])) $action['action'] = "cancel";
1081 if(isset($_POST['password_cancel'])) $action['action'] = "cancel";
1082 if(isset($_POST['password_finish'])) $action['action'] = "passwordChangeConfirmed";
1084 if(isset($_POST['new_goServer'])) $action['action'] = "new_goServer";
1085 if(isset($_POST['new_gotoWorkstation'])) $action['action'] = "new_gotoWorkstation";
1086 if(isset($_POST['new_gotoTerminal'])) $action['action'] = "new_gotoTerminal";
1087 if(isset($_POST['new_gotoPrinter'])) $action['action'] = "new_gotoPrinter";
1088 if(isset($_POST['new_goFonHardware'])) $action['action'] = "new_goFonHardware";
1089 if(isset($_POST['new_ieee802Device'])) $action['action'] = "new_ieee802Device";
1090 if(isset($_POST['new_FAKE_OC_OpsiHost'])) $action['action'] = "new_FAKE_OC_OpsiHost";
1092 if(!is_object($this->tabObject) && !is_object($this->dialogObject)){
1093 if(count($this->activationQueue)) $action['action'] = "handleActivationQueue";
1094 }
1096 if(isset($_POST['systemTypeChosen'])) $action['action'] = "systemTypeChosen";
1098 return($action);
1099 }
1102 /*! \brief Overridden render method of class management.
1103 * this allows us to add a release selection box.
1104 */
1105 function renderList()
1106 {
1107 $headpage = $this->getHeadpage();
1108 $headpage->update();
1110 $tD = $this->getObjectDefinitions();
1111 $smarty = get_smarty();
1112 foreach($tD as $name => $obj){
1113 $smarty->assign("USE_".$name, (empty($obj['TABNAME']) || class_available($obj['TABNAME'])));
1114 }
1116 $display = $headpage->render();
1117 return($this->getHeader().$display);
1118 }
1121 public function getObjectDefinitions()
1122 {
1123 $tabs = array(
1124 "FAKE_OC_OpsiHost" => array(
1125 "ou" => "",
1126 "plugClass" => "opsiGeneric",
1127 "tabClass" => "opsi_tabs",
1128 "tabDesc" => "OPSITABS",
1129 "aclClass" => "opsiGeneric",
1130 "sendEvents" => TRUE,
1131 "aclCategory" => "opsi"),
1133 "goServer" => array(
1134 "ou" => get_ou('serverRDN'),
1135 "plugClass" => "servgeneric",
1136 "tabClass" => "servtabs",
1137 "tabDesc" => "SERVTABS",
1138 "aclClass" => "servgeneric",
1139 "sendEvents" => TRUE,
1140 "aclCategory" => "server"),
1142 "gotoWorkstation" => array(
1143 "ou" => get_ou('workstationRDN'),
1144 "plugClass" => "workgeneric",
1145 "tabClass" => "worktabs",
1146 "tabDesc" => "WORKTABS",
1147 "aclClass" => "workstation",
1148 "sendEvents" => TRUE,
1149 "aclCategory" => "workgeneric"),
1151 "gotoTerminal" => array(
1152 "ou" => get_ou('terminalRDN'),
1153 "plugClass" => "termgeneric",
1154 "tabClass" => "termtabs",
1155 "sendEvents" => TRUE,
1156 "tabDesc" => "TERMTABS",
1157 "aclClass" => "terminal",
1158 "aclCategory" => "termgeneric"),
1160 "gotoPrinter" => array(
1161 "ou" => get_ou('printerRDN'),
1162 "plugClass" => "printgeneric",
1163 "tabClass" => "printtabs",
1164 "tabDesc" => "PRINTTABS",
1165 "aclClass" => "printer",
1166 "sendEvents" => FALSE,
1167 "aclCategory" => "printgeneric"),
1169 "FAKE_OC_NewDevice" => array(
1170 "ou" => get_ou('systemIncomingRDN'),
1171 "plugClass" => "termgeneric",
1172 "tabClass" => "termtabs",
1173 "sendEvents" => TRUE,
1174 "tabDesc" => "TERMTABS",
1175 "aclClass" => "terminal",
1176 "aclCategory" => "termgeneric"),
1178 "goFonHardware" => array(
1179 "ou" => get_ou('phoneRDN'),
1180 "plugClass" => "phoneGeneric",
1181 "tabClass" => "phonetabs",
1182 "tabDesc" => "PHONETABS",
1183 "sendEvents" => FALSE,
1184 "aclClass" => "phone",
1185 "aclCategory" => "phoneGeneric"),
1187 "FAKE_OC_winstation" => array(
1188 "ou" => get_winstations_ou(),
1189 "plugClass" => "wingeneric",
1190 "sendEvents" => TRUE,
1191 "tabClass" => "wintabs",
1192 "tabDesc" => "WINTABS",
1193 "aclClass" => "wingeneric",
1194 "aclCategory" => "winworkstation"),
1196 "ieee802Device" => array(
1197 "ou" => get_ou('componentRDN'),
1198 "plugClass" => "componentGeneric",
1199 "sendEvents" => FALSE,
1200 "tabClass" => "componenttabs",
1201 "tabDesc" => "COMPONENTTABS",
1202 "aclClass" => "componentGeneric",
1203 "aclCategory" => "component"),
1204 );
1206 // Now map some special types
1207 $tabs['FAKE_OC_NewWorkstation'] = &$tabs['gotoWorkstation'];
1208 $tabs['FAKE_OC_NewTerminal'] = &$tabs['gotoTerminal'];
1209 $tabs['FAKE_OC_NewServer'] = &$tabs['gotoWorkstation'];
1210 $tabs['gotoWorkstation__IS_BUSY'] = &$tabs['gotoWorkstation'];
1211 $tabs['gotoWorkstation__IS_ERROR'] = &$tabs['gotoWorkstation'];
1212 $tabs['gotoWorkstation__IS_LOCKED'] = &$tabs['gotoWorkstation'];
1213 $tabs['gotoTerminal__IS_BUSY'] = &$tabs['gotoTerminal'];
1214 $tabs['gotoTerminal__IS_ERROR'] = &$tabs['gotoTerminal'];
1215 $tabs['gotoTerminal__IS_LOCKED'] = &$tabs['gotoTerminal'];
1216 $tabs['goServer__IS_BUSY'] = &$tabs['goServer'];
1217 $tabs['goServer__IS_ERROR'] = &$tabs['goServer'];
1218 $tabs['goServer__IS_LOCKED'] = &$tabs['goServer'];
1220 $tabs['FAKE_OC_ArpNewDevice'] = &$tabs['FAKE_OC_NewDevice'];
1222 return($tabs);
1223 }
1226 /*! \brief !! Incoming dummy acls, required to defined acls for incoming objects
1227 */
1228 static function plInfo()
1229 {
1230 return (array(
1231 "plShortName" => _("Incoming objects"),
1232 "plDescription" => _("Incoming objects"),
1233 "plSelfModify" => FALSE,
1234 "plDepends" => array(),
1235 "plPriority" => 99,
1236 "plSection" => array("administration"),
1237 "plCategory" => array("incoming" => array( "description" => _("Incoming"),
1238 "objectClass" => "")),
1239 "plProvidedAcls"=> array()
1240 ));
1241 }
1242 }
1243 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1244 ?>