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 gotomasses extends management
24 {
26 var $plHeadline = "System deployment status";
27 var $plDescription = "System deployment status";
28 var $plIcon = "plugins/goto/images/goto.png";
30 var $current = FALSE;
31 var $dialog = FALSE;
32 var $ids_to_remove = array();
34 var $events = array();
35 var $event_tags = array();
36 var $recently_removed = array();
38 function __construct(&$config, $ui)
39 {
40 /* Include config object */
41 $this->config= &$config;
42 $this->o_queue = new gosaSupportDaemon(TRUE,5);
43 $this->events = DaemonEvent::get_event_types( SYSTEM_EVENT);
45 /* Get tags that will be used in queue searches */
46 $this->event_tags = array("none");
47 foreach($this->events['SCHEDULED'] as $evt){
48 $this->event_tags[] = $evt['s_Queued_Action'];
49 }
51 // Build filter
52 # if (session::global_is_set(get_class($this)."_filter")){
53 # $filter= session::global_get(get_class($this)."_filter");
54 # } else {
55 $filter = new filter(get_template_path("deploy-filter.xml", true));
56 $filter->setObjectStorage($this->storagePoints);
57 # }
58 $this->setFilter($filter);
60 // Build headpage
61 $headpage = new listing(get_template_path("deploy-list.xml", true));
62 $headpage->registerElementFilter("hostName", "gotomasses::filterHostName");
63 $headpage->registerElementFilter("filterTask","gotomasses::filterTask");
64 $headpage->registerElementFilter("filterPeriod","gotomasses::filterPeriod");
65 $headpage->registerElementFilter("filterSchedule","gotomasses::filterSchedule");
66 $headpage->registerElementFilter("filterStatus","gotomasses::filterStatus");
67 $headpage->setFilter($filter);
69 parent::__construct($config, $ui, "Events", $headpage);
71 $this->registerAction('prioDown', "prioDown");
72 $this->registerAction('prioUp', "prioUp");
73 $this->registerAction('prioPause', "prioPause");
74 $this->registerAction('processNow', "processNow");
75 $this->registerAction('viewLogs', "viewLogs");
76 }
78 static function filterHostName($mac, $name ="")
79 {
80 if(isset($name[0]) && $name[0] != "none"){
81 return($name[0]);
82 }
83 return($mac[0]);
84 }
86 static function filterTask($tag)
87 {
88 $tag = $tag[0];
89 $str = $tag;
91 /* Check if this event exists as Daemon class
92 * In this case, display a more accurate entry.
93 */
94 $events = DaemonEvent::get_event_types( SYSTEM_EVENT);
95 if(isset($events['QUEUED'][$tag])){
96 $evt_name = $events['QUEUED'][$tag];
97 $event_type = $events['BY_CLASS'][$evt_name];
98 $str = $event_type['s_Menu_Name'];
100 if(strlen($str) > 20){
101 $str = substr($str,0,18)."...";
102 }
104 if(isset($event_type['ListImage']) && !empty($event_type['ListImage'])){
105 $str = $event_type['ListImage']." ".$str;
106 }
107 }
108 return($str);
109 }
111 static function filterPeriod($periodic=array())
112 {
113 $period = " -";
114 if(isset($periodic[0]) && !preg_match("/none/i",$periodic[0])){
115 $tmp = explode("_", $periodic[0]);
116 if(count($tmp) == 2){
117 $period= $tmp[0]." "._($tmp[1]);
118 }
119 }
120 return($period);
121 }
123 static function filterSchedule($stamp)
124 {
125 if ($stamp['0'] == "19700101000000"){
126 return(_("immediately"));
127 } else {
128 return(date("d.m.Y H:i:s",strtotime($stamp[0])));
129 }
130 }
133 static function filterStatus($status, $mac,$headertag, $progress)
134 {
136 $mac = $mac[0];
137 $status = $status[0];
138 $progress = $progress[0];
139 $headertag = $headertag[0];
141 if($status == "waiting"){
142 $status = "<img class='center' src='plugins/goto/images/clock.png' alt=''> "._("Waiting");
143 }
144 if($status == "error"){
145 $status = "<img class='center' src='images/false.png' alt=''> "._("Error");
146 }
147 if($status == "processed"){
148 $status = "<img class='center' src='images/true.png' alt=''> "._("Processed");
149 }
151 /* Special handling for all entries that have
152 STATUS == "processing" && PROGRESS == NUMERIC
153 */
154 if($status == "processing" && $progress){
155 $percent = $progress;
157 /* Show activation? */
158 if ($percent == "goto-activation"){
159 $status = "<img class='center' src='images/lists/off.png' alt=''> "._("Locked");
161 /* Show hardware detect? */
162 } elseif ($percent == "goto-hardware-detection") {
163 $status = "<img class='center' src='plugins/goto/images/hardware.png' alt=''> "._("Detection");
165 /* Real percent */
166 } else {
167 if (preg_match('/install/', $headertag)){
168 $status = "<img src='progress.php?x=80&y=13&p=".$progress."' alt=''
169 id='progress_".preg_replace("/:/","_",$mac)."'>";
170 } else {
171 $status = preg_replace('/ /', ' ', _("in progress"));
172 }
173 }
174 }
175 return($status);
176 }
178 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
179 {
180 print_a($all);
181 }
183 function removeEntryRequested($action="",$target=array(),$all=array())
184 {
185 print_a($all);
186 }
188 function prioDown($action="",$target=array(),$all=array())
189 {
190 if(count($target) == 1){
191 $this->update_priority($target[0], 'down');
192 }
193 }
195 function prioUp($action="",$target=array(),$all=array())
196 {
197 if(count($target) == 1){
198 $this->update_priority($target[0], 'up');
199 }
200 }
202 function prioPause($action="",$target=array(),$all=array())
203 {
204 print_a($all);
205 }
207 function processNow($action="",$target=array(),$all=array())
208 {
209 print_a($all);
210 }
212 function viewLogs($action="",$target=array(),$all=array())
213 {
214 print_a($all);
215 }
217 /*! \brief Move an entry up or down in the queue, by updating its execution timestamp
218 @param $id Integer The ID of the entry which should be updated.
219 @param $type String "up" / "down"
220 @return boolean TRUE in case of success else FALSE
221 */
222 public function update_priority($id,$type = "up")
223 {
224 $headpage = $this->getHeadpage();
225 $entries = $headpage->getEntries();
226 $entry = $headpage->getEntry($id);
228 $map = array();
229 $last = 0;
230 $next = 0;
231 foreach($entries as $pa){
232 $map[$pa['TIMESTAMP'][0]] = $pa['TIMESTAMP'][0];
233 }
234 krsort($map);
235 $found = 0;
236 $cur = 0;
237 foreach($map as $ts){
238 if($found){
239 $next = $ts;
240 break;
241 }
242 if($ts == $entry['TIMESTAMP'][0]){
243 $found = TRUE;
244 $cur = $ts;
245 }else{
246 $last = $ts;
247 }
248 }
250 if($type == "up" && $next != 0){
251 echo "Von: ".date('d.m.Y H:i:s', strtotime($entry['TIMESTAMP'][0]))." nach ".date('d.m.Y H:i:s',strtotime($next))."<br>";
252 return($this->o_queue->update_entries(array($id),array("timestamp" => $next)));
253 }elseif($type == "down" && $last != 0){
254 echo "Von: ".date('d.m.Y H:i:s', strtotime($entry['TIMESTAMP'][0]))." nach ".date('d.m.Y H:i:s',strtotime($last))."<br>";
255 return($this->o_queue->update_entries(array($id),array("timestamp" => $last)));
256 }
257 }
261 function _execute()
262 {
264 /************
265 * Import CSV file
266 ************/
268 if($s_action == "import_file" && $this->acl_is_writeable("")){
269 $this->dialog = new goto_import_file($this->config,$this);
270 }
272 if(isset($_POST['import_abort'])){
273 $this->dialog = FALSE;
274 }
277 /************
278 * Handle Priority modifications
279 ************/
281 if(preg_match("/^prio_/",$s_action) && $this->acl_is_writeable("")){
282 switch($s_action){
283 case 'prio_down' : $this->update_priority($s_entry,"down");break;
284 case 'prio_up' : $this->update_priority($s_entry,"up");break;
285 }
286 }
288 /************
289 * Handle pause/resume/execute modifications
290 ************/
292 if(preg_match("/^resume/",$s_action) ||
293 preg_match("/^pause/",$s_action) ||
294 preg_match("/^abort_process/",$s_action) ||
295 preg_match("/^execute_process/",$s_action)){
297 if($this->acl_is_writeable("")){
298 switch($s_action){
299 case 'resume' : $this->resume_queue_entries (array($s_entry));break;
300 case 'pause' : $this->pause_queue_entries (array($s_entry));break;
301 case 'execute_process': $this->execute_queue_entries (array($s_entry));break;
302 case 'abort_process' : $this->abort_queue_entries (array($s_entry));break;
303 case 'resume_all' : $this->resume_queue_entries ($this->list_get_selected_items());break;
304 case 'pause_all' : $this->pause_queue_entries ($this->list_get_selected_items());break;
305 case 'execute_process_all': $this->execute_queue_entries ($this->list_get_selected_items());break;
306 case 'abort_process_all' : $this->abort_queue_entries ($this->list_get_selected_items());break;
308 default : trigger_error("Undefined action setting used (".$s_action.").");
309 }
310 }
311 if($this->o_queue->is_error()){
312 msg_dialog::display(_("Error"), $this->o_queue->get_error(), ERROR_DIALOG);
313 }
314 }
316 /************
317 * ADD
318 ************/
320 if(preg_match("/^add_event_/",$s_action) && $this->acl_is_writeable("")){
321 $type = preg_replace("/^add_event_/","",$s_action);
322 if(isset($this->events['BY_CLASS'][$type])){
323 $e_data = $this->events['BY_CLASS'][$type];
324 $this->dialog = new $e_data['CLASS_NAME']($this->config);
325 }
326 }
328 /************
329 * EDIT
330 ************/
332 if($s_action == "edit" && $this->acl_is_writeable("")){
333 $id = $s_entry;
334 $type = FALSE;
335 if(isset($this->entries[$id])){
336 $event = $this->entries[$s_entry];
337 if($event['STATUS'] == "waiting" && isset($this->events['QUEUED'][$event['HEADERTAG']])){
338 $evt_name = $this->events['QUEUED'][$event['HEADERTAG']];
339 $type = $this->events['BY_CLASS'][$evt_name];
340 $this->dialog = new $type['CLASS_NAME']($this->config,$event);
341 }
342 }
343 }
346 /************
347 * LOG VIEW
348 ************/
350 if($s_action == "logview" && $this->acl_is_readable("")){
351 $id = $s_entry;
352 $type = FALSE;
353 if(isset($this->entries[$id])){
354 $event = $this->entries[$s_entry];
355 $this->dialog = new gotoLogView($this->config,"",$event,$this);
356 }
357 }
360 /************
361 * REMOVE
362 ************/
364 /* Remove multiple */
365 if($s_action == "remove_multiple" || $s_action == "remove"){
367 if(!$this->acl_is_removeable()){
368 msg_dialog::display(_("Permission"), msgPool::permDelete(), ERROR_DIALOG);
369 }else{
371 if($s_action == "remove"){
372 $ids = array($s_entry);
373 }else{
374 $ids = $this->list_get_selected_items();
375 }
377 $this->ids_to_remove = array();
379 if(count($ids)){
380 $ret = $this->o_queue->ids_exist($ids);
381 $ret = $this->o_queue->get_entries_by_id($ret);
382 $tmp = "";
384 $deleteable_jobs = array();
385 $not_deleteable_jobs = array();
386 foreach($ret as $task){
388 /* Create a printable job name/description */
389 if(isset($this->events['QUEUED'][$task['HEADERTAG']])){
390 $evt_name = $this->events['QUEUED'][$task['HEADERTAG']];
391 $evt = $this->events['BY_CLASS'][$evt_name];
392 $j_name = $task['ID']." - ".$evt['s_Menu_Name']." ".$task['MACADDRESS'];
393 }else{
394 $j_name = $task['ID']." - ".$task['HEADERTAG']." ".$task['MACADDRESS'];
395 }
397 /* Only remove WAITING or ERROR entries */
398 if(in_array($task['STATUS'],array("waiting","error","processed")) ||
399 ($task['STATUS'] == "processing" && !preg_match("/install/",$task['HEADERTAG'])) ){
400 $this->ids_to_remove[] = $task['ID'];
401 $deleteable_jobs[] = $j_name;
402 }else{
403 $not_deleteable_jobs[] = $j_name;
404 }
405 }
406 if(count($not_deleteable_jobs)){
407 msg_dialog::display(_("Remove"),
408 sprintf(_("The following jobs couldn't be deleted, they have to be aborted: %s"),
409 "<br>".msgPool::buildList($not_deleteable_jobs)),INFO_DIALOG);
410 }
412 if(count($this->ids_to_remove)){
413 $smarty->assign("multiple", TRUE);
414 $smarty->assign("info",msgPool::deleteInfo($deleteable_jobs));
415 $this->current = $s_entry;
416 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
417 }
418 }
419 }
420 }
422 /* Remove specified tasks */
423 if(count($this->ids_to_remove) && isset($_POST['delete_multiple_confirm'])){
425 /* Reboot hosts with not yet startet installations and timestamps in the past
426 */
427 if($this->acl_is_removeable("")){
428 timezone::get_default_timezone();
429 foreach($this->ids_to_remove as $id){
430 $entry = $this->o_queue->get_entries_by_id(array($id));
431 if(isset($entry['ANSWER1'])){
432 $entry = $entry['ANSWER1'];
433 if( $entry['STATUS'] == "waiting" &&
434 $entry['HEADERTAG'] == "trigger_action_reinstall"){
435 $evt = new DaemonEvent_reinstall($this->config,$entry);
436 if($evt->get_timestamp(FALSE) < time()){
437 $r_evt = new DaemonEvent_localboot($this->config);
438 $r_evt->add_targets(array($entry['MACADDRESS']));
439 $r_evt->set_type(TRIGGERED_EVENT);
440 $this->o_queue->append($r_evt);
441 }
442 }
443 }
444 }
446 $this->o_queue->remove_entries($this->ids_to_remove);
447 $this->save();
448 }
449 }
451 /* Remove aborted */
452 if(isset($_POST['delete_cancel'])){
453 $this->ids_to_remove = array();;
454 }
457 /************
458 * EDIT
459 ************/
461 /* Close dialog */
462 if(isset($_POST['save_event_dialog'])){
463 if(is_object($this->dialog)){
464 $this->dialog->save_object();
465 if(!$this->o_queue->append($this->dialog)){
466 msg_dialog::display(_("Service infrastructure"),msgPool::siError($this->o_queue->get_error()),ERROR_DIALOG);
467 }else{
468 $this->dialog = FALSE;
469 $this->current = -1;
470 }
471 }
472 }
475 /* Close dialog */
476 if(isset($_POST['abort_event_dialog'])){
477 $this->dialog = FALSE;
478 $this->current = -1;
479 }
481 /* Display dialogs if currently opened */
482 if(is_object($this->dialog)){
483 $this->dialog->save_object();
484 $display = $this->dialog->execute();
486 if($this->dialog instanceOf goto_import_file && $this->dialog->import_successful){
487 $this->dialog = FALSE;
488 }else{
489 return($display);
490 }
491 }
493 /************
494 * Handle Divlist
495 ************/
497 $divlist = new MultiSelectWindow($this->config,"gotoMasses",array("gotomasses"));
498 $divlist->SetInformation(_("This menu allows you to remove and change the properties of GOsa tasks."));
499 $divlist->SetSummary(_("List of queued jobs"));
500 $divlist->EnableCloseButton(FALSE);
501 $divlist->EnableSaveButton(FALSE);
502 $divlist->SetHeadpageMode();
503 $s = ".|"._("Actions")."|\n";
504 $s.= "..|<img src='images/lists/new.png' alt='' border='0' class='center'> "._("Create")."\n";
506 if($this->acl_is_writeable("")){
507 foreach($this->events['SCHEDULED'] as $name => $event){
508 $s.= "...|".$event['MenuImage']." ".$event['s_Menu_Name']."|add_event_".$name."\n";
509 }
510 }
511 if($this->acl_is_removeable()){
512 $s.= "..|---|\n";
513 $s.= "..|<img src='images/lists/import.png' alt='' border='0' class='center'> "._("Import")."|import_file\n";
514 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'> "._("Remove")."|remove_multiple\n";
515 }
516 if(preg_match("/w/",$this->getacl(""))){
517 $s.= "..|---|\n";
518 $s.= "..|<img alt='"._("Resume")."' src='images/status_start.png' border='0' class='center'> "._("Resume")."|resume_all\n";
519 $s.= "..|<img alt='"._("Pause")."' src='images/status_pause.png' border='0' class='center'> "._("Pause")."|pause_all\n";
520 $s.= "..|<img alt='"._("Abort")."' src='images/small_error.png' border='0' class='center'> "._("Abort")."|abort_process_all\n";
521 $s.= "..|<img alt='"._("Execute")."' src='images/rocket.png' border='0' class='center'> "._("Execute")."|execute_process_all\n";
522 }
524 $divlist->SetDropDownHeaderMenu($s);
526 if($this->sort_dir == "up"){
527 $sort_img = "<img src='images/lists/sort-up.png' alt='/\' border=0>";
528 }else{
529 $sort_img = "<img src='images/lists/sort-down.png' alt='\/' border=0>";
530 }
532 if($this->sort_by == "TargetName"){ $sort_img_1 = $sort_img; } else { $sort_img_1 = "" ;}
533 if($this->sort_by == "TaskID"){ $sort_img_2 = $sort_img; } else { $sort_img_2 = "" ;}
534 if($this->sort_by == "Schedule"){ $sort_img_3 = $sort_img; } else { $sort_img_3 = "" ;}
535 if($this->sort_by == "Action"){ $sort_img_4 = $sort_img; } else { $sort_img_4 = "" ;}
537 /* Create divlist */
538 $divlist->SetListHeader("<input type='image' src='images/lists/reload.png' title='"._("Reload")."'>");
540 $plug = $_GET['plug'];
541 $chk = "<input type='checkbox' id='select_all' name='select_all'
542 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
544 /* set Page header */
545 $divlist->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
546 $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&sort=TargetName'>"._("Target").$sort_img_1."</a>"));
547 $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&sort=TaskID'>"._("Task").$sort_img_2."</a>",
548 "attach"=>"style='width:120px;'"));
549 $divlist->AddHeader(array("string"=>_("Period"),
550 "attach"=>"style='width:60px;'"));
551 $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&sort=Schedule'>"._("Schedule").$sort_img_3."</a>",
552 "attach"=>"style='width:140px;'"));
553 $divlist->AddHeader(array("string"=>"<a href='?plug=".$plug."&sort=Action'>"._("Status").$sort_img_4."</a>",
554 "attach"=>"style='width:80px;'"));
555 $divlist->AddHeader(array("string"=>_("Action"),
556 "attach"=>"style='border-right:0px;width:140px;'"));
559 /* Reload the list of entries */
560 $this->reload();
562 foreach($this->entries as $key => $task){
564 $prio_actions="";
565 $action = "";
568 /* If WAITING add priority action
569 */
570 if(in_array($task['STATUS'],array("waiting")) && $this->acl_is_writeable("")){
571 $prio_actions.= "<input class='center' type='image' src='plugins/goto/images/prio_increase.png'
572 title='"._("Move up")."' name='prio_up_".$key."'> ";
573 $prio_actions.= "<input class='center' type='image' src='plugins/goto/images/prio_decrease.png'
574 title='"._("Move down")."' name='prio_down_".$key."'> ";
575 }
577 /* If WAITING add pause action
578 */
579 if(in_array($task['STATUS'],array("waiting")) && $this->acl_is_writeable("")){
580 $prio_actions.= "<input class='center' type='image' src='images/status_pause.png'
581 title='"._("Pause job")."' name='pause_".$key."'> ";
582 }
584 /* If PAUSED add resume action
585 */
586 if(in_array($task['STATUS'],array("paused")) && $this->acl_is_writeable("")){
587 $prio_actions.= "<input class='center' type='image' src='images/status_start.png'
588 title='"._("Resume job")."' name='resume_".$key."'> ";
589 }
591 /* If PAUSED or WAITING add execution action
592 */
593 if(in_array($task['STATUS'],array("paused","waiting")) && $this->acl_is_writeable("")){
594 $prio_actions.= "<input class='center' type='image' src='images/rocket.png'
595 title='"._("Execute now")."' name='execute_process_".$key."'> ";
596 }
598 /* Add logview button, currently ever.
599 */
600 if($this->acl_is_readable("")){
601 $action .= "<input type='image' src='plugins/goto/images/view_logs.png' name='log_view_".$key."'
602 class='center' title='"._("View logs")."' alt='"._("View logs")."'> ";
603 }
605 /* If PAUSED or WAITING add edit action
606 */
607 if(in_array($task['STATUS'],array("waiting")) && $this->acl_is_writeable("")){
608 $action.= "<input type='image' src='images/lists/edit.png' name='edit_task_".$key."'
609 class='center' title='"._("Edit")."' alt='"._("Edit")."'>";
610 }
612 /* If PROCESSING add abort action
613 */
614 if(in_array($task['STATUS'],array("processing")) && preg_match("/install/",$task['HEADERTAG']) && $this->acl_is_writeable("")){
615 $action.= "<img src='images/empty.png' alt=''>";
616 $action.= "<input class='center' type='image' src='images/small_error.png'
617 title='"._("Abort job")."' name='abort_process_".$key."'>";
618 }
620 /* If WAITING or ERROR add remove action
621 */
622 if( $this->acl_is_removeable() && in_array($task['STATUS'],array("waiting","error","processed"))){
623 $action.= "<input type='image' src='images/lists/trash.png' name='remove_task_".$key."'
624 class='center' title='"._("Remove")."' alt='"._("Remove")."'>";
625 }
626 if($this->acl_is_writeable("") && in_array($task['STATUS'],array("processing")) && !preg_match("/install/",$task['HEADERTAG'])){
627 $action.= "<input type='image' src='images/lists/trash.png' name='remove_task_".$key."'
628 class='center' title='"._("Remove")."' alt='"._("Remove")."'>";
629 }
631 /* Create entry display name and tooltip */
632 $color = "";
633 $display = $task['MACADDRESS'];
634 $tooltip = "";
635 if(isset($task['PLAINNAME']) && !preg_match("/none/i",$task['PLAINNAME'])){
636 $display = $task['PLAINNAME'];
637 $tooltip = " title='".$task['MACADDRESS']."' ";
638 }
641 $display2= $task['HEADERTAG'];
643 /* Check if this event exists as Daemon class
644 * In this case, display a more accurate entry.
645 */
646 if(isset($this->events['QUEUED'][$task['HEADERTAG']])){
647 $evt_name = $this->events['QUEUED'][$task['HEADERTAG']];
648 $event_type = $this->events['BY_CLASS'][$evt_name];
649 $display2 = $event_type['s_Menu_Name'];
651 if(strlen($display2) > 20){
652 $display2 = substr($display2,0,18)."...";
653 }
655 if(isset($event_type['ListImage']) && !empty($event_type['ListImage'])){
656 $display2 = $event_type['ListImage']." ".$display2;
657 }
658 }
660 $status = $task['STATUS'];
662 if($status == "waiting"){
663 $status = "<img class='center' src='plugins/goto/images/clock.png' alt=''> "._("Waiting");
664 }
665 if($status == "error"){
666 $status = "<img class='center' src='images/false.png' alt=''> "._("Error");
667 }
668 if($status == "processed"){
669 $status = "<img class='center' src='images/true.png' alt=''> "._("Processed");
670 }
672 /* Special handling for all entries that have
673 STATUS == "processing" && PROGRESS == NUMERIC
674 */
675 if($status == "processing" && isset($task['PROGRESS'])){
676 $percent = $task['PROGRESS'];
678 /* Show activation? */
679 if ($percent == "goto-activation"){
680 $status = "<img class='center' src='images/lists/off.png' alt=''> "._("Locked");
682 /* Show hardware detect? */
683 } elseif ($percent == "goto-hardware-detection") {
684 $status = "<img class='center' src='plugins/goto/images/hardware.png' alt=''> "._("Detection");
686 /* Real percent */
687 } else {
688 if (preg_match('/install/', $task['HEADERTAG'])){
689 $status = "<img src='progress.php?x=80&y=13&p=".$task['PROGRESS']."' alt=''
690 id='progress_".preg_replace("/:/","_",$task['MACADDRESS'])."'>";
691 } else {
692 $status = preg_replace('/ /', ' ', _("in progress"));
693 }
694 }
695 }
697 // Check whether this is a periodical job or not.
698 $period = "";
699 if(isset($task['PERIODIC']) && !preg_match("/none/i",$task['PERIODIC'])){
700 $tmp = explode("_", $task['PERIODIC']);
701 if(count($tmp) == 2){
702 $period= $tmp[0]." "._($tmp[1]);
703 }
704 }
706 /* Create each field */
707 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$task['ID']."' name='item_selected_".$key."'>" ,
708 "attach" => "style='width:20px;".$color."'");
709 $field1 = array("string" => $display,
710 "attach" => $tooltip."style='".$color."'");
711 $field1a= array("string" => $display2,
712 "attach" => "style='".$color.";width:120px;'");
713 $field1b= array("string" => $period,
714 "attach" => "style='".$color.";width:60px;'");
715 if ($task['TIMESTAMP'] == "19700101000000"){
716 $field2 = array("string" => _("immediately"),"attach" => "style='".$color.";width:140px;'");
717 } else {
718 $field2 = array("string" => date("d.m.Y H:i:s",strtotime($task['TIMESTAMP'])),"attach" => "style='".$color.";width:140px;'");
719 }
720 $field3 = array("string" => $status,"attach" => "style='".$color.";width:80px;'");
721 $field4 = array("string" => $prio_actions.$action,"attach" => "style='".$color.";text-align:right;width:140px;border-right:0px;'");
722 $divlist->AddElement(array($field0,$field1,$field1a,$field1b,$field2,$field3,$field4));
723 }
725 $smarty = get_smarty();
726 $smarty->assign("events",$this->events);
727 $smarty->assign("start",$this->start);
728 $smarty->assign("start_real", ($this->start + 1));
729 $smarty->assign("ranges", array("10" => "10",
730 "20" => "20",
731 "25" => "25",
732 "50" => "50",
733 "100"=> "100",
734 "200"=> "200",
735 "9999" => "*"));
737 $count = $this->o_queue->number_of_queued_entries($this->event_tags);
738 if(!$count) $count = $this->range;
739 $divlist->SetListFooter(range_selector($count, $this->start, $this->range,"range"));
740 $smarty->assign("range",$this->range);
741 $smarty->assign("div",$divlist->Draw());
743 return(management::execute());
744 return($smarty->fetch (get_template_path('gotomasses.tpl', TRUE, dirname(__FILE__))));
745 }
748 /*! \brief Resumes to status 'waiting'.
749 * @return Boolean TRUE in case of success, else FALSE.
750 */
751 private function resume_queue_entries($ids)
752 {
753 if(!count($ids)){
754 return;
755 }
757 /* Entries are resumed by setting the status to
758 * 'waiting'
759 */
760 $data = array("status" => "waiting");
762 /* Check if given ids are valid and check if the status
763 * allows resuming.
764 */
765 $update_ids = array();
766 foreach($this->o_queue->get_entries_by_id($ids) as $entry){
767 if(isset($entry['STATUS']) && preg_match("/paused/",$entry['STATUS'])){
768 $update_ids[] = $entry['ID'];
769 }
770 }
772 /* Tell the daemon that we have entries to update.
773 */
774 if(count($update_ids)){
775 if(!$this->o_queue->update_entries($update_ids,$data)){
776 msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entry: %s"),$id) , ERROR_DIALOG);
777 return(FALSE);
778 }
779 }
780 return(TRUE);
781 }
784 /*! \brief Force queue job to be done as far as possible.
785 * @return Boolean TRUE in case of success, else FALSE.
786 */
787 private function execute_queue_entries($ids)
788 {
789 if(!count($ids)){
790 return;
791 }
793 /* Execution is forced by updating the status to
794 * waiting and setting the timestamp to current time.
795 */
796 $data = array( "timestamp" => date("YmdHis",time()),
797 "status" => "waiting");
799 /* Only allow execution of paused or waiting entries
800 */
801 $update_ids = array();
802 foreach($this->o_queue->get_entries_by_id($ids) as $entry){
803 if(in_array($entry['STATUS'],array("paused","waiting"))){
804 $update_ids[] = $entry['ID'];
805 }
806 }
808 /* Tell the daemon that we want to update some entries
809 */
810 if(count($update_ids)){
811 if(!$this->o_queue->update_entries($update_ids,$data)){
812 msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entries.")) , ERROR_DIALOG);
813 return(FALSE);
814 }
815 }
816 return(TRUE);
817 }
820 /*! \brief Force queue job to be done as far as possible.
821 * @return Boolean TRUE in case of success, else FALSE.
822 */
823 private function abort_queue_entries($ids)
824 {
825 if(!count($ids)){
826 return;
827 }
829 /* Entries are paused by setting the status to
830 * something different from 'waiting'.
831 * We simply use 'paused'.
832 */
833 $data = array("status" => "paused");
835 /* Detect if the ids we got are valid and
836 * check if the status allows pausing.
837 */
838 $update_ids = array();
839 foreach($this->o_queue->get_entries_by_id($ids) as $entry){
840 if(isset($entry['STATUS']) && preg_match("/processing/",$entry['STATUS'])){
841 if(isset($entry['MACADDRESS'])){
842 $update_ids[] = $entry['MACADDRESS'];
843 }else{
844 trigger_error("No mac address found in event.");
845 }
846 }
847 }
849 if(class_available("DaemonEvent_faireboot")){
850 $tmp = new DaemonEvent_faireboot($this->config);
851 $tmp->add_targets($update_ids);
852 $tmp->set_type(TRIGGERED_EVENT);
853 $this->recently_removed = $update_ids;
855 if(!$this->o_queue->append($tmp)){
856 msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entry: %s"),$id) , ERROR_DIALOG);
857 return(FALSE);
858 }
859 }else{
860 msg_dialog::display(_("Error"),
861 sprintf(_("Required class '%s' cannot be found: job not aborted!"),
862 "DaemonEvent_faireboot") , ERROR_DIALOG);
863 }
864 }
867 /*! \brief Pauses the specified queue entry from execution.
868 * @return Boolean TRUE in case of success, else FALSE.
869 */
870 private function pause_queue_entries($ids)
871 {
872 if(!count($ids)){
873 return;
874 }
876 /* Entries are paused by setting the status to
877 * something different from 'waiting'.
878 * We simply use 'paused'.
879 */
880 $data = array("status" => "paused");
882 /* Detect if the ids we got are valid and
883 * check if the status allows pausing.
884 */
885 $update_ids = array();
886 foreach($this->o_queue->get_entries_by_id($ids) as $entry){
887 if(isset($entry['STATUS']) && preg_match("/waiting/",$entry['STATUS'])){
888 $update_ids[] = $entry['ID'];
889 }
890 }
892 /* Tell the daemon that we want to update some entries
893 */
894 if(count($update_ids)){
895 if(!$this->o_queue->update_entries($update_ids,$data)){
896 msg_dialog::display(_("Error"), sprintf(_("Cannot update queue entry: %s"),$id) , ERROR_DIALOG);
897 return(FALSE);
898 }
899 }
900 return(TRUE);
901 }
904 /*! \brief Request list of queued jobs.
905 * @return Returns an array of all queued jobs.
906 */
907 function reload()
908 {
910 /* Sort map html-post-name => daemon-col-name
911 */
912 $map = array(
913 "QueuePosition" => "id",
914 "Action" => "status",
915 "TaskID" => "headertag",
916 "TargetName" => "macaddress",
917 "Schedule" => "timestamp");
919 /* Create sort header
920 */
921 if(!isset($map[$this->sort_by])){
922 $sort = "id DESC";
923 }else{
924 $sort = $map[$this->sort_by];
925 if($this->sort_dir == "up"){
926 $sort.= " ASC";
927 }else{
928 $sort.= " DESC";
929 }
930 }
932 /* Get entries. */
933 $start = $this->start;
934 $stop = $this->range;
935 $entries = $this->o_queue->get_queued_entries($this->event_tags,$start,$stop,$sort);
936 if ($this->o_queue->is_error()){
937 msg_dialog::display(_("Error"), sprintf(_("Cannot load queue entries: %s"), "<br><br>".$this->o_queue->get_error()), ERROR_DIALOG);
938 }
940 /* Assign entries by id.
941 */
942 $this->entries = array();
944 foreach($entries as $entry){
946 /* Skip entries which will be removed within the next seconds */
947 if(isset($entry['MACADDRESS']) && in_array($entry['MACADDRESS'],$this->recently_removed)){
948 continue;
949 }
950 $this->entries[$entry['ID']]= $entry;
951 }
952 $this->recently_removed = array();
953 }
955 function save_object(){}
957 /*! \brief Handle post jobs, like sorting.
958 */
959 function _save_object()
960 {
961 /* Check for sorting changes
962 */
963 $sort_vals = array("Action","QueuePosition","TargetName","Schedule","TaskID");
964 if(isset($_GET['sort']) && in_array($_GET['sort'],$sort_vals)){
965 $sort = $_GET['sort'];
966 if($this->sort_by == $sort){
967 if($this->sort_dir == "up"){
968 $this->sort_dir = "down";
969 }else{
970 $this->sort_dir = "up";
971 }
972 }
973 $this->sort_by = $sort;
974 }
976 /* Range selection used? */
977 if(isset($_POST['range']) && is_numeric($_POST['range'])){
978 $this->range = $_POST['range'];
979 }
981 /* Save filter settings */
982 $gotomasses_filter = session::get("gotomasses_filter");
983 foreach(array("range","sort_by","sort_dir") as $attr){
984 $gotomasses_filter[$attr] = $this->$attr;
985 }
986 session::set("gotomasses_filter",$gotomasses_filter);
988 /* Page changed. */
989 if(isset($_GET['start'])){
990 $start = $_GET['start'];
991 if(is_numeric($start) || $start == 0){
992 $this->start = $start;
993 }
994 }
996 /* Check start stop and reset if necessary */
997 $count = $this->o_queue->number_of_queued_entries($this->event_tags);
998 if($this->start >= $count){
999 $this->start = $count -1;
1000 }
1001 if($this->start < 0){
1002 $this->start = 0;
1003 }
1004 }
1007 function save()
1008 {
1009 // We do not save anything here.
1010 }
1013 /*! \brief Return a list of all selected items.
1014 @return Array Returns an array containing all selected item ids.
1015 */
1016 function list_get_selected_items()
1017 {
1018 $ids = array();
1019 foreach($_POST as $name => $value){
1020 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1021 $id = preg_replace("/^item_selected_/","",$name);
1022 $ids[$id] = $id;
1023 }
1024 }
1025 return($ids);
1026 }
1029 static function plInfo()
1030 {
1031 return (array(
1032 "plShortName" => _("System deployment"),
1033 "plDescription" => _("Provide a mechanism to automatically activate systems"),
1034 "plSelfModify" => FALSE,
1035 "plDepends" => array(),
1036 "plPriority" => 0,
1037 "plSection" => array("addon"),
1038 "plCategory" => array("gotomasses" => array("objectClass" => "none", "description" => _("System deployment"))),
1039 "plProvidedAcls" => array("Comment" => _("Description"))
1040 ));
1041 }
1044 function set_acl_base($base)
1045 {
1046 $this->acl_base= $base;
1047 }
1050 function set_acl_category($category)
1051 {
1052 $this->acl_category= "$category/";
1053 }
1056 function acl_is_writeable($attribute,$skip_write = FALSE)
1057 {
1058 if($this->read_only) return(FALSE);
1059 $ui= get_userinfo();
1060 return preg_match('/w/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute, $skip_write));
1061 }
1064 function acl_is_readable($attribute)
1065 {
1066 $ui= get_userinfo();
1067 return preg_match('/r/', $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute));
1068 }
1071 function acl_is_createable($base ="")
1072 {
1073 if($this->read_only) return(FALSE);
1074 $ui= get_userinfo();
1075 if($base == "") $base = $this->acl_base;
1076 return preg_match('/c/', $ui->get_permissions($base, $this->acl_category.get_class($this), '0'));
1077 }
1080 function acl_is_removeable($base ="")
1081 {
1082 if($this->read_only) return(FALSE);
1083 $ui= get_userinfo();
1084 if($base == "") $base = $this->acl_base;
1085 return preg_match('/d/', $ui->get_permissions($base, $this->acl_category.get_class($this), '0'));
1086 }
1088 function acl_is_moveable($base = "")
1089 {
1090 if($this->read_only) return(FALSE);
1091 $ui= get_userinfo();
1092 if($base == "") $base = $this->acl_base;
1093 return preg_match('/m/', $ui->get_permissions($base, $this->acl_category.get_class($this), '0'));
1094 }
1097 function getacl($attribute,$skip_write= FALSE)
1098 {
1099 $ui= get_userinfo();
1100 $skip_write |= $this->read_only;
1101 return $ui->get_permissions($this->acl_base, $this->acl_category.get_class($this), $attribute,$skip_write);
1102 }
1104 }
1105 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1106 ?>