Commit 38432eb4 authored by Côme Bernigaud's avatar Côme Bernigaud

Fixes #4364 Removed DaemonEvent, added clean argonautAction class instead

parent bf62227b
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2006 Fabian Hickert
Copyright (C) 2011-2015 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class TimeHisAttribute extends CompositeAttribute
{
function __construct($label, $description, $ldapName, $required, $acl = '')
{
$attributes = array(
new IntAttribute (
'', _('Hours'),
$ldapName.'_hours', TRUE,
0, 23, 1
),
new IntAttribute (
':', _('Minutes'),
$ldapName.'_minutes', TRUE,
0, 59, 0
),
new IntAttribute (
':', _('Seconds'),
$ldapName.'_seconds', TRUE,
0, 59, 0
)
);
parent::__construct($description, $ldapName, $attributes, '/^(\d\d)(\d\d)(\d\d)$/', '%2d%2d%2d', $acl, $label);
$this->setLinearRendering(TRUE);
}
}
class DateTimeAttribute extends CompositeAttribute
{
function __construct($label, $description, $ldapName, $required, $acl = '')
{
$attributes = array(
new DateAttribute(
_('Date'), '',
$ldapName.'_date', $required,
'Ymd'
),
new TimeHisAttribute(
_('Time'), '',
$ldapName.'_time', $required
)
);
parent::__construct($description, $ldapName, $attributes, '/^(\d{8})(\d{6})$/', '%s%s', $acl, $label);
}
}
class MacsAttribute extends GenericDialogAttribute
{
protected $dialogClass = 'SystemSelectDialog';
function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = array(), $display_attr = 'cn', $acl = '')
{
parent::__construct ($label, $description, $ldapName, $required, $defaultValue, 'macAddress', $display_attr, $acl);
}
}
class argonautAction extends simplePlugin
{
static function plInfo()
{
return array(
'plShortName' => _('Argonaut task'),
'plDescription' => _('Schedule an argonaut task'),
'plObjectType' => array('argonautTask' => array(
'name' => _('Argonaut task'),
'aclCategory' => 'argonautQueue',
'icon' => 'geticon.php?context=applications&icon=argonaut&size=16',
)),
'plProvidedAcls' => parent::generatePlProvidedAcls(self::getAttributesInfo())
);
}
static function getAttributesInfo ()
{
return array(
'main' => array(
'name' => _('Schedule'),
'attrs' => array(
new HiddenAttribute(
'action'
),
new HiddenAttribute(
'scheduled', FALSE,
TRUE
),
new DateTimeAttribute(
_('Schedule'), '',
'datetime', FALSE
),
new BooleanAttribute(
_('Periodical job'), _('Wether this job should repeat in time'),
'periodical', FALSE
),
new CompositeAttribute(
_('How often this task should be repeated'), 'period',
array(
new IntAttribute(
'', '',
'periodValue', FALSE,
1, FALSE, 7
),
new SelectAttribute(
'', '',
'periodType', TRUE,
array('minutes', 'hours', 'days', 'weeks', 'months'), 'days',
array(_('Minutes'), _('Hours'), _('Days'), _('Weeks'), _('Months'))
)
),
'/^(\d+)_(minutes|hours|days|weeks|months)$/',
'%s_%s',
'',
_('Period')
)
)
),
'targets' => array(
'name' => _('Targets'),
'attrs' => array(
new MacsAttribute(
'', _('Targets for this task'),
'targets', TRUE
)
)
)
);
}
public function __construct($config, $action)
{
parent::__construct($config, $config->current['BASE']);
$this->attributesAccess['scheduled']->setManagedAttributes(
array(
'erase' => array (
FALSE => array (
'datetime', 'period'
)
)
)
);
$this->attributesAccess['periodical']->setManagedAttributes(
array(
'disable' => array (
FALSE => array (
'period'
)
)
)
);
$this->attributesAccess['period']->setLinearRendering(TRUE);
$this->datetime = date('YmdHis');
$this->action = $action;
}
protected function loadAttributes()
{
foreach ($this->attributesAccess as &$attribute) {
$attribute->setInLdap(FALSE);
}
unset($attribute);
parent::loadAttributes();
}
function execute()
{
return parent::execute().$this->getFooter();
}
/*! \brief Returns the plugin footer (save cancel), displayed in the template.
@return String HTML footer part.
*/
protected function getFooter()
{
if (!$this->displayPlugin) {
return '';
}
return '<p class="plugbottom">'.
' <input type="submit" name="save_event_dialog" value="'.msgPool::saveButton().'"/>'.
' <input type="submit" name="abort_event_dialog" value="'.msgPool::cancelButton().'"/>'.
'</p>';
}
/*! brief Returns an array containing all attributes \
That should be written.
@return Array e.g. 'status' => 'bla blub'
*/
public function computeData()
{
timezone::get_default_timezone();
$ret = array('args' => array());
if ($this->scheduled) {
$ret['timestamp'] = strtotime($this->datetime);
if ($this->periodical) {
$ret['periodic'] = $this->period;
}
}
return $ret;
}
/*! \brief Returns event information, like menu strings, images ...
@return Array Event informations.
*/
static public function get_event_info($action)
{
$events = self::get_event_types();
if (isset($events[$action])) {
$infos = $events[$action];
$infos['menuimg'] = '<img src="'.$infos['img'].'" alt="'.$infos['name'].'" class="center"/>';
$infos['listimg'] = '<img src="'.$infos['img'].'" title="'.$infos['name'].
'"alt="'.$infos['name'].'" class="center"/>';
return $infos;
} else {
return FALSE;
}
}
/*! \brief Returns a complete list of all available events.
@return Array Containing info for all available events.
*/
static public function get_event_types()
{
return array(
'System.halt' => array(
'name' => _('Switch off'),
'img' => 'geticon.php?context=actions&icon=system-shutdown&size=16'
),
'Deployment.reboot' => array(
'name' => _('Reboot'),
'img' => 'geticon.php?context=actions&icon=system-reboot&size=16'
),
'Deployment.wake' => array(
'name' => _('Wake up'),
'img' => 'geticon.php?context=status&icon=task-running&size=16'
),
'Deployment.update' => array(
'name' => _('Software update'),
'img' => 'geticon.php?context=actions&icon=system-update&size=16'
),
'Deployment.reinstall' => array(
'name' => _('(Re)Install'),
'img' => 'geticon.php?context=actions&icon=system-reinstall&size=16'
),
);
}
}
?>
......@@ -86,7 +86,7 @@ class argonautImportFile extends simplePlugin
$this->parent = $parent;
$this->events = array();
$this->daemon_events = DaemonEvent::get_event_types();
$this->daemon_events = argonautAction::get_event_types();
}
function execute()
......@@ -129,15 +129,12 @@ class argonautImportFile extends simplePlugin
foreach ($events as $key => $event) {
/* Create event */
$object = new DaemonEvent($this->config, $event['HEADER'], $event);
$object->add_targets(array($event['MAC']));
if (empty($event['TIMESTAMP'])) {
$object->set_type(TRIGGERED_EVENT);
$data = array();
} else {
$object->set_type(SCHEDULED_EVENT);
$data = array('timestamp' => $event['TIMESTAMP']);
}
$this->parent->o_queue->append($object);
$this->parent->o_queue->append_call($event['HEADER'], array($event['MAC']), $data);
if ($this->parent->o_queue->is_error()) {
msg_dialog::display(_('Infrastructure service'), msgPool::siError($this->parent->o_queue->get_error()), ERROR_DIALOG);
$fail++;
......
......@@ -103,7 +103,7 @@ class argonautQueue extends simpleManagement
$task = $tmp['EVENT'];
/* Create a printable job name/description */
$infos = DaemonEvent::get_event_info($task['HEADERTAG']);
$infos = argonautAction::get_event_info($task['HEADERTAG']);
if ($infos) {
$j_name = $task['ID']." - ".$infos['name']."&nbsp;".$task['MACADDRESS'];
} else {
......@@ -130,7 +130,7 @@ class argonautQueue extends simpleManagement
foreach ($this->dns as $dn) {
$tmp = $this->headpage->getEntry($dn);
$task = $tmp['EVENT'];
$infos = DaemonEvent::get_event_info($task['HEADERTAG']);
$infos = argonautAction::get_event_info($task['HEADERTAG']);
if ($infos) {
$objects[] = array(
'name' => $infos['name'],
......@@ -183,10 +183,7 @@ class argonautQueue extends simpleManagement
$taskids[] = $tmp['EVENT']['ID'];
}
$tmp = new DaemonEvent($this->config, 'wakeup');
$tmp->add_targets($macs);
$tmp->set_type(TRIGGERED_EVENT);
$this->o_queue->append($tmp);
$this->o_queue->append_call('wakeup', $macs, array());
if ($this->o_queue->is_error()) {
msg_dialog::display(_('Info'), sprintf(_('%s'), $this->o_queue->get_error()), INFO_DIALOG);
}
......@@ -293,7 +290,7 @@ class argonautQueue extends simpleManagement
/* Check if this event exists as Daemon class
* In this case, display a more accurate entry.
*/
$infos = DaemonEvent::get_event_info($tag);
$infos = argonautAction::get_event_info($tag);
if ($infos) {
$str = $infos['name'];
......
......@@ -27,7 +27,7 @@ class filterArgonautEvents extends filterLDAP
global $config;
$o_queue = new supportDaemon();
$events = DaemonEvent::get_event_types();
$events = argonautAction::get_event_types();
/* Get tags that will be used in queue searches */
$event_tags = array("none");
......
{if $is_new}
<table style='width:100%;'>
<tr>
<td style='width:50%; vertical-align:top; border-right:1px solid #AAA'>
<table>
<tr>
<td style='vertical-align:top'><b>{t}Schedule{/t}</b><br><br>
{$timestamp}</td>
</tr>
</table>
</td>
<td style='width:50%; vertical-align:top;'>
<table style='width:100%;'>
<tr>
<td>
<b>{t}System list{/t}</b>
<br>
{$target_list}
</td>
</tr>
</table>
</td>
</tr>
</table>
{else}
<table style='width:100%;'>
<tr>
<td style='width:50%; vertical-align:top;'>
<table>
<tr>
<td>{t}ID{/t}</td>
<td>{$data.ID}</td>
</tr>
<tr>
<td>{t}Status{/t}</td>
<td>{$data.STATUS}</td>
</tr>
<tr>
<td>{t}Result{/t}</td>
<td>{$data.RESULT}</td>
</tr>
<tr>
<td>{t}Target{/t}</td>
<td>{$data.MACADDRESS}</td>
</tr>
<tr>
<td style='vertical-align:top'>{t}Timestamp{/t}</td>
<td>{$timestamp}</td>
</tr>
</table>
</td>
<td style='width:50%; vertical-align:top;'>
<table >
</table>
</td>
</tr>
</table>
{/if}
This diff is collapsed.
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2010 Cajus Pollmeier
Copyright (C) 2011-2015 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class EventAddSystemDialog extends management
{
// Tab definition
protected $skipFooter = TRUE;
protected $skipHeader = TRUE;
function __construct($config, $ui)
{
$this->config = $config;
$this->ui = $ui;
$this->storagePoints = array(
get_ou("serverRDN"),
get_ou("workstationRDN"),
get_ou("sambaMachineAccountRDN"),
get_ou("ogroupRDN"),
get_ou("terminalRDN"));
// Build filter
$filter = new filter(get_template_path("../../addons/argonaut/events/eventTargetSystems-filter.xml", TRUE));
$filter->setObjectStorage($this->storagePoints);
$this->setFilter($filter);
// Build headpage
$headpage = new listing(get_template_path("../../addons/argonaut/events/eventTargetSystems-list.xml", TRUE));
$headpage->setFilter($filter);
parent::__construct($config, $ui, "object", $headpage);
}
function save_object()
{
}
function save()
{
$act = $this->detectPostActions();
$headpage = $this->getHeadpage();
if (!isset($act['targets'])) {
return array();
}
$ret = array();
foreach ($act['targets'] as $dn) {
$ret[] = $headpage->getEntry($dn);
}
return $ret;
}
function get_selected_targets()
{
// Collect mac addresses
$entries = $this->save();
$macs = array();
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
$member_dns = array();
foreach ($entries as $entry) {
if (isset($entry['macAddress'][0])) {
$macs[] = $entry['macAddress'][0];
}
if (in_array("gosaGroupOfNames", $entry['objectClass'])) {
$ldap->cat($entry['dn']);
if ($ldap->count()) {
$attrs = $ldap->fetch();
if (isset($attrs['member'])) {
for ($i = 0; $i < $attrs['member']['count']; $i++) {
$member_dns[] = $attrs['member'][$i];
}
}
}
}
}
foreach ($member_dns as $dn) {
$ldap->cat($dn, array('macAddress'));
if ($ldap->count()) {
$attrs = $ldap->fetch();
if (isset($attrs['macAddress'])) {
$macs[] = $attrs['macAddress'][0];
}
}
}
return $macs;
}
}
?>
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2010 Cajus Pollmeier
Copyright (C) 2011-2015 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class filterSystemByIp extends filterLDAP
{
static function query($parent, $base, $scope, $filter, $attributes, $category, $objectStorage = "")
{
// IP Range selection
$filterByIP = preg_match("/__FilterByIP__/", $filter);
$filter = preg_replace("/__FilterByIP__/", "", $filter);
$ipstart = "";
$ipstop = "";
if (preg_match("/__IPSTART__=/", $filter)) {
$ipstart = trim(preg_replace("/^.*__IPSTART__=([^_]*)__.*$/", "\\1", $filter), "*");
}
if (preg_match("/__IPSTOP__=/", $filter)) {
$ipstop = trim(preg_replace("/^.*__IPSTOP__=([^_]*)__.*$/", "\\1", $filter), "*");
}
// Get entries
$filter = preg_replace("/__IPSTART.*$/", "", $filter);
$entries = filterLDAP::query($parent, $base, $scope, $filter, $attributes, $category, $objectStorage);
// Filter entries by IP-Address
if ($filterByIP) {
foreach ($entries as $key => $entry) {
if (!isset($entry['ipHostNumber'])) {
unset($entries[$key]);
continue;
}
if (!tests::is_in_ip_range($ipstart, $ipstop, $entry['ipHostNumber'][0])) {
unset($entries[$key]);
continue;
}
}
}
return array_values($entries);
}
}
?>
<div class="contentboxh">
<p class="contentboxh">
{t}Filter{/t}
</p>
</div>
<div class="contentboxb">
{$SERVER}&nbsp;<LABEL for='SERVER'>{t}Show servers{/t}</LABEL><br/>
{$WORKSTATION}&nbsp;<LABEL for='WORKSTATION'>{t}Show workstations{/t}</LABEL><br/>
{$TERMINAL}&nbsp;<LABEL for='TERMINAL'>{t}Show terminals{/t}</LABEL><br/>
{$WINSTATION}&nbsp;<LABEL for='WINSTATION'>{t}Show winstations{/t}</LABEL><br/>
{$BYIP}&nbsp;<LABEL for='BYIP'>{t}Filter by IP address range{/t}</LABEL><br/>
<div style="display:block;width=100%;border-top:1px solid #AAAAAA;"></div>
{$SCOPE}
<table style="width:100%;border-top:1px solid #B0B0B0;">
<tr>
<td>
<label for="NAME">
<img src="geticon.php?context=actions&icon=system-search&size=16" align=middle>&nbsp;{t}Name{/t}
</label>
</td>
<td>
{$NAME}
</td>
</tr>
<tr>
<td>
<label for="IPSTART">
<img src="geticon.php?context=actions&icon=system-search&size=16" align=middle>&nbsp;IP Start
</label>
</td>
<td>
{$IPSTART}
</td>
</tr>
<tr>
<td>
<label for="IPSTOP">
<img src="geticon.php?context=actions&icon=system-search&size=16" align=middle>&nbsp;IP Stop
</label>
</td>
<td>
{$IPSTOP}
</td>
</tr>
</table>
<table width="100%" style="background:#EEEEEE;border-top:1px solid #B0B0B0;">
<tr>
<td style="width:100%;text-align:right;">
{$APPLY}
</td>
</tr>
</table>
</div>
<?xml version="1.0" encoding="UTF-8"?>
<filterdef>
<definition>
<category>server</category>
<template>../../addons/argonaut/events/eventTargetSystems-filter.tpl</template>
<initial>true</initial>
</definition>
<search>
<query>
<backend>SystemByIp</backend>
<filter>(&amp;(|$SERVER $WORKSTATION $TERMINAL $WINSTATION $OGROUP) $NAME) $IPSTART $IPSTOP $BYIP</filter>
<attribute>dn</attribute>
<attribute>objectClass</attribute>
<attribute>cn</attribute>
<attribute>description</attribute>
<attribute>macAddress</attribute>
<attribute>ipHostNumber</attribute>
</query>
<scope>auto</scope>
</search>
<element>
<type>textfield</type>
<tag>NAME</tag>
<size>20</size>
<maxlength>60</maxlength>
<default></default>
<unset></unset>
<set>(cn=*$*)</set>
<alphabet>true</alphabet>
<autocomplete>
<backend>SystemByIp</backend>
<filter>(cn=*$NAME*)</filter>
<attribute>cn</attribute>
<frequency>0.5</frequency>
<characters>3</characters>
</autocomplete>
</element>
<element>
<type>textfield</type>
<tag>IPSTART</tag>
<size>20</size>
<maxlength>60</maxlength>
<default>0.0.0.0</default>
<unset></unset>
<set>__IPSTART__=*$*__</set>
<alphabet>true</alphabet>
<autocomplete>
<backend>LDAP</backend>
<filter>__IPSTART__=*$IPSTART*__</filter>
<attribute>cn</attribute>
<frequency>0.5</frequency>
<characters>3</characters>
</autocomplete>
</element>
<element>
<type>textfield</type>
<tag>IPSTOP</tag>
<size>20</size>
<maxlength>60</maxlength>
<default>255.255.255.255</default>
<unset></unset>
<set>__IPSTOP__=*$*__</set>
<alphabet>true</alphabet>
<autocomplete>
<backend>LDAP</backend>