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 */
23 class systemManagement extends management
24 {
25 var $plHeadline = "Systems";
26 var $plDescription = "List of systems";
27 var $plIcon = "plugins/systems/images/plugin.png";
29 // Tab definition
30 protected $tabClass = "";
31 protected $tabType = "";
32 protected $aclCategory = "";
33 protected $aclPlugin = "";
34 protected $objectName = "";
36 protected $objectInfo = array();
38 protected $opsi = NULL;
40 function __construct($config,$ui)
41 {
42 $this->config = $config;
43 $this->ui = $ui;
45 // Set storage points
46 $tD = $this->getObjectDefinitions();
47 $sP = array();
48 foreach($tD as $entry){
49 if(!empty($entry['ou']))
50 $sP[] = $entry['ou'];
51 }
52 $this->storagePoints = array_unique($sP);
54 // Build filter
55 # if (session::global_is_set(get_class($this)."_filter")){
56 # $filter= session::global_get(get_class($this)."_filter");
57 # } else {
58 $filter = new filter(get_template_path("system-filter.xml", true));
59 $filter->setObjectStorage($this->storagePoints);
60 # }
61 $this->setFilter($filter);
63 // Build headpage
64 $headpage = new listing(get_template_path("system-list.xml", true));
65 $headpage->setFilter($filter);
66 $filter->setConverter('INCOMING', 'systemManagement::incomingFilterConverter');
68 // Register Daemon Events
69 if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
70 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
71 foreach($events['TRIGGERED'] as $name => $data){
72 $this->registerAction("T_".$name,"handleEvent");
73 $this->registerAction("S_".$name,"handleEvent");
74 }
75 $this->registerAction("DaemonEvent_activate","handleEvent");
76 }
77 $this->registerAction("saveEvent","saveEventDialog");
79 // Add copy&paste and snapshot handler.
80 if ($this->config->boolValueIsTrue("main", "copyPaste")){
81 $this->cpHandler = new CopyPasteHandler($this->config);
82 }
83 if($this->config->get_cfg_value("enableSnapshots") == "true"){
84 $this->snapHandler = new SnapshotHandler($this->config);
85 }
87 // Check if we are able to communicate with the GOsa supprot daemon
88 if(class_available("gosaSupportDaemon")){
89 $o = new gosaSupportDaemon();
90 $this->si_active = $o->connect() && class_available("DaemonEvent");
91 }
93 // Check if we are able to communicate with the GOsa supprot daemon
94 if(class_available("opsi")){
95 $this->opsi = new opsi($this->config);
96 }
99 parent::__construct($config, $ui, "systems", $headpage);
100 }
103 /*! \brief Handle GOsa-si events
104 * All events are handled here.
105 */
106 function handleEvent($action="",$target=array(),$all=array())
107 {
108 // Detect whether this event is scheduled or triggered.
109 $triggered = TRUE;
110 if(preg_match("/^S_/",$action)){
111 $triggered = FALSE;
112 }
114 // Detect triggere or scheduled actions
115 $headpage = $this->getHeadpage();
116 if(preg_match("/^[TS]_/", $action)){
118 // Send special reinstall action for opsi hosts
119 $event = preg_replace("/^[TS]_/","",$action);
120 if($event == "DaemonEvent_reinstall" && $this->si_active && $this->opsi){
121 foreach($target as $key => $dn){
122 $type = $headpage->getType($dn);
124 // Send Reinstall event for opsi hosts
125 if($type == "FAKE_OC_OpsiHost"){
126 $obj = $headpage->getEntry($dn);
127 $this->opsi->job_opsi_install_client($obj['cn'][0],$obj['macAddress'][0]);
128 unset($target[$key]);
129 }
130 }
131 }
132 }
134 // Now send remaining FAI/GOsa-si events here.
135 if(count($target) && $this->si_active){
136 $mac= array();
138 // Collect target mac addresses
139 $ldap = $this->config->get_ldap_link();
140 $tD = $this->getObjectDefinitions();
141 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
142 $o_queue = new gosaSupportDaemon();
143 foreach($target as $dn){
144 $type = $headpage->getType($dn);
145 if($tD[$type]['sendEvents']){
146 $obj = $headpage->getEntry($dn);
147 if(isset($obj['macAddress'][0])){
148 $mac[] = $obj['macAddress'][0];
149 }
150 }
151 }
153 /* Skip installation or update trigerred events,
154 * if this entry is currently processing.
155 */
156 if($triggered && in_array($event,array("DaemonEvent_reinstall","DaemonEvent_update"))){
157 foreach($mac as $key => $mac_address){
158 foreach($o_queue->get_entries_by_mac(array($mac_address)) as $entry){
159 $entry['STATUS'] = strtoupper($entry['STATUS']);
160 if($entry['STATUS'] == "PROCESSING" &&
161 isset($events['QUEUED'][$entry['HEADERTAG']]) &&
162 in_array($events['QUEUED'][$entry['HEADERTAG']],array("DaemonEvent_reinstall","DaemonEvent_update"))){
163 unset($mac[$key]);
165 new log("security","systems/".get_class($this),"",array(),"Skip adding 'DaemonEvent::".$type."' for mac '".$mac_address."', there is already a job in progress.");
166 break;
167 }
168 }
169 }
170 }
172 // Prepare event to be added
173 if(count($mac) && isset($events['BY_CLASS'][$event]) && $this->si_active){
174 $event = $events['BY_CLASS'][$event];
175 $this->dialogObject = new $event['CLASS_NAME']($this->config);
176 $this->dialogObject->add_targets($mac);
178 if($triggered){
179 $this->dialogObject->set_type(TRIGGERED_EVENT);
180 $o_queue->append($this->dialogObject);
181 if($o_queue->is_error()){
182 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
183 }else{
184 $this->closeDialogs();
185 }
186 }else{
187 $this->dialogObject->set_type(SCHEDULED_EVENT);
188 }
189 }
190 }
192 // Handle system activation
193 if($action == "DaemonEvent_activate"){
194 echo "Aktivieren!";
195 }
196 }
199 function saveEventDialog()
200 {
201 $o_queue = new gosaSupportDaemon();
202 $o_queue->append($this->dialogObject);
203 if($o_queue->is_error()){
204 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
205 }else{
206 $this->closeDialogs();
207 }
209 }
212 /*! \brief Update filter part for INCOMING.
213 * Allows us to search for "systemIncomingRDN".
214 */
215 static function incomingFilterConverter($filter)
216 {
217 $rdn = preg_replace("/^[^=]*=/", "", get_ou('systemIncomingRDN'));
218 $rdn = preg_replace("/,.*$/","",$rdn);
219 return(preg_replace("/%systemIncomingRDN/", $rdn,$filter));
220 }
223 /*! \brief Queue selected objects to be removed.
224 * Checks ACLs, Locks and ask for confirmation.
225 */
226 protected function removeEntryRequested($action="",$target=array(),$all=array())
227 {
228 $disallowed = array();
229 $this->dns = array();
231 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
233 // Check permissons for each target
234 $tInfo = $this->getObjectDefinitions();
235 $headpage = $this->getHeadpage();
236 foreach($target as $dn){
237 $type = $headpage->getType($dn);
238 if(!isset($tInfo[$type])){
239 trigger_error("Unknown object type received '".$type."' please update systemManagement::getObjectDefinitions()!");
240 }else{
241 $info = $tInfo[$type];
242 $acl = $this->ui->get_permissions($dn, $info['aclCategory']."/".$info['aclClass']);
243 if(preg_match("/d/",$acl)){
244 $this->dns[] = $dn;
245 }else{
246 $disallowed[] = $dn;
247 }
248 }
249 }
250 if(count($disallowed)){
251 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
252 }
254 // We've at least one entry to delete.
255 if(count($this->dns)){
257 // check locks
258 if ($user= get_multiple_locks($this->dns)){
259 return(gen_locked_message($user,$this->dns));
260 }
262 // Add locks
263 $dns_names = array();
264 foreach($this->dns as $dn){
265 $dns_names[] =LDAP::fix($dn);
266 }
267 add_lock ($this->dns, $this->ui->dn);
269 // Display confirmation dialog.
270 $smarty = get_smarty();
271 $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
272 $smarty->assign("multiple", true);
273 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
274 }
275 }
278 /*! \brief Object removal was confirmed, now remove the requested entries.
279 *
280 * @param String 'action' The name of the action which was the used as trigger.
281 * @param Array 'target' A list of object dns, which should be affected by this method.
282 * @param Array 'all' A combination of both 'action' and 'target'.
283 */
284 function removeEntryConfirmed($action="",$target=array(),$all=array(),
285 $altTabClass="",$altTabType="",$altAclCategory="")
286 {
287 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
289 // Check permissons for each target
290 $tInfo = $this->getObjectDefinitions();
291 $headpage = $this->getHeadpage();
292 $disallowed = array();
293 foreach($this->dns as $key => $dn){
294 $type = $headpage->getType($dn);
295 if(!isset($tInfo[$type])){
296 trigger_error("Unknown object type received '".$type."' please update systemManagement::getObjectDefinitions()!");
297 }else{
299 $info = $tInfo[$type];
300 $acl = $this->ui->get_permissions($dn, $info['aclCategory']."/".$info['aclClass']);
301 if(preg_match("/d/",$acl)){
303 // Delete the object
304 $this->dn = $dn;
305 $this->tabObject= new $info['tabClass']($this->config,$this->config->data['TABS'][$info['tabDesc']],
306 $this->dn, $info['aclCategory'], true, true);
307 $this->tabObject->set_acl_base($this->dn);
308 $this->tabObject->parent = &$this;
309 $this->tabObject->delete ();
311 // Remove the lock for the current object.
312 del_lock($this->dn);
314 }else{
315 $disallowed[] = $dn;
316 new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
317 }
318 }
319 }
320 if(count($disallowed)){
321 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
322 }
324 // Cleanup
325 $this->remove_lock();
326 $this->closeDialogs();
327 }
330 /*! \brief Edit the selected system type.
331 *
332 * @param String 'action' The name of the action which was the used as trigger.
333 * @param Array 'target' A list of object dns, which should be affected by this method.
334 * @param Array 'all' A combination of both 'action' and 'target'.
335 */
336 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
337 {
338 if(count($target) == 1){
339 $tInfo = $this->getObjectDefinitions();
340 $headpage = $this->getHeadpage();
341 $dn = $target[0];
342 $type = $tInfo[$headpage->getType($dn)];
343 return(management::editEntry($action,$target,$all,$type['tabClass'],$type['tabDesc'],$type['aclCategory']));
344 }
345 }
348 /*! \brief Detects actions/events send by the ui
349 * and the corresponding targets.
350 */
351 function detectPostActions()
352 {
353 $action= management::detectPostActions();
354 if(isset($_POST['abort_event_dialog'])) $action['action'] = "cancel";
355 if(isset($_POST['save_event_dialog'])) $action['action'] = "saveEvent";
356 return($action);
357 }
360 /*! \brief Overridden render method of class mangement.
361 * this allows us to add a release selection box.
362 */
363 function renderList()
364 {
365 $headpage = $this->getHeadpage();
366 $headpage->update();
368 $tD = $this->getObjectDefinitions();
369 $smarty = get_smarty();
370 foreach($tD as $name => $obj){
371 $smarty->assign("USE_".$name, (empty($obj['TABNAME']) || class_available($obj['TABNAME'])));
372 }
374 $display = $headpage->render();
375 return($this->getHeader().$display);
376 }
379 public function getObjectDefinitions()
380 {
381 $tabs = array(
382 "FAKE_OC_OpsiHost" => array(
383 "ou" => "",
384 "plugClass" => "opsiGeneric",
385 "tabClass" => "opsi_tabs",
386 "tabDesc" => "OPSITABS",
387 "aclClass" => "opsiGeneric",
388 "sendEvents" => TRUE,
389 "aclCategory" => "opsi"),
391 "goServer" => array(
392 "ou" => get_ou('serverRDN'),
393 "plugClass" => "servgeneric",
394 "tabClass" => "servtabs",
395 "tabDesc" => "SERVTABS",
396 "aclClass" => "servgeneric",
397 "sendEvents" => TRUE,
398 "aclCategory" => "server"),
400 "gotoWorkstation" => array(
401 "ou" => get_ou('workstationRDN'),
402 "plugClass" => "workgeneric",
403 "tabClass" => "worktabs",
404 "tabDesc" => "WORKTABS",
405 "aclClass" => "workstation",
406 "sendEvents" => TRUE,
407 "aclCategory" => "workgeneric"),
409 "gotoTerminal" => array(
410 "ou" => get_ou('terminalRDN'),
411 "plugClass" => "termgeneric",
412 "tabClass" => "termtabs",
413 "sendEvents" => TRUE,
414 "tabDesc" => "TERMTABS",
415 "aclClass" => "terminal",
416 "aclCategory" => "termgeneric"),
418 "gotoPrinter" => array(
419 "ou" => get_ou('printerRDN'),
420 "plugClass" => "printgeneric",
421 "tabClass" => "printtabs",
422 "tabDesc" => "PRINTTABS",
423 "aclClass" => "printer",
424 "sendEvents" => FALSE,
425 "aclCategory" => "printgeneric"),
427 "FAKE_OC_NewDevice" => array(
428 "ou" => get_ou('systemIncomingRDN'),
429 "plugClass" => "termgeneric",
430 "tabClass" => "termtabs",
431 "sendEvents" => TRUE,
432 "tabDesc" => "TERMTABS",
433 "aclClass" => "terminal",
434 "aclCategory" => "termgeneric"),
436 "goFonHardware" => array(
437 "ou" => get_ou('phoneRDN'),
438 "plugClass" => "phoneGeneric",
439 "tabClass" => "phonetabs",
440 "tabDesc" => "PHONETABS",
441 "sendEvents" => FALSE,
442 "aclClass" => "phone",
443 "aclCategory" => "phoneGeneric"),
445 "FAKE_OC_winstation" => array(
446 "ou" => get_winstations_ou(),
447 "plugClass" => "wingeneric",
448 "sendEvents" => TRUE,
449 "tabClass" => "wintabs",
450 "tabDesc" => "WINTABS",
451 "aclClass" => "wingeneric",
452 "aclCategory" => "winworkstation"),
454 "ieee802Device" => array(
455 "ou" => get_ou('componentRDN'),
456 "plugClass" => "componentGeneric",
457 "sendEvents" => FALSE,
458 "tabClass" => "componenttabs",
459 "tabDesc" => "COMPONENTTABS",
460 "aclClass" => "componentGeneric",
461 "aclCategory" => "component"),
462 );
464 // Now map some special types
465 $tabs['FAKE_OC_NewWorkstation'] = &$tabs['gotoWorkstation'];
466 $tabs['FAKE_OC_NewTerminal'] = &$tabs['gotoTerminal'];
467 $tabs['FAKE_OC_NewServer'] = &$tabs['gotoWorkstation'];
468 $tabs['gotoWorkstation__IS_BUSY'] = &$tabs['gotoWorkstation'];
469 $tabs['gotoWorkstation__IS_ERROR'] = &$tabs['gotoWorkstation'];
470 $tabs['gotoWorkstation__IS_LOCKED'] = &$tabs['gotoWorkstation'];
471 $tabs['gotoTerminal__IS_BUSY'] = &$tabs['gotoTerminal'];
472 $tabs['gotoTerminal__IS_ERROR'] = &$tabs['gotoTerminal'];
473 $tabs['gotoTerminal__IS_LOCKED'] = &$tabs['gotoTerminal'];
474 $tabs['goServer__IS_BUSY'] = &$tabs['goServer'];
475 $tabs['goServer__IS_ERROR'] = &$tabs['goServer'];
476 $tabs['goServer__IS_LOCKED'] = &$tabs['goServer'];
478 $tabs['FAKE_OC_NewUnknownDevice'] = &$tabs['FAKE_OC_NewDevice'];
480 return($tabs);
481 }
482 }
483 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
484 ?>