This sample shows how to issue a shell command on the gateway system as a result of pushing a soft button on the user interface
This sample invoilves two pieces of configuration, the first is the UI generation to create a button and the second an event handling for the event the button generates. The communication between the two is an event.
The gateway uses light weight events for its communbication, these can be generated by webbricks, internally or in this case by accessing a URI on the gateway host. Any access to /sendevent on the gatewway will create an event, this event has an event source of the remainder of the URI, i.e. /sendevent/command/restart will generate an event source of command/restart. The default event type is http://id.webbrick.co.uk/events/uri, this can be changes by appending a type parameter to the URI e.f. /sendevent/command/restart?type=system/command (some characters will need escaping). Any other parameters in the URI will be added to the event payload as name value pairs.
The UI
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?python
kid.enable_import()
import WebBrickGateway.templates.master
?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#" xmlns:wb="http://id.webbrick.co.uk/"
py:extends="WebBrickGateway.templates.master">
${output_head("Shell Command")}
<body>
${output_nav("Shell Command")}
<table>
<colgroup span="4" width="25%"></colgroup>
<tr>
<wb:caption colspan="2">Shell Command</wb:caption>
</tr>
<tr>
<wb:simpleButton wbTarget="/sendevent/command/restart" >
Restart gateway
</wb:simpleButton>
</tr>
</table>
${output_site_info_bar()}
</body>
</html>
This puts a simpleButtonj on the UI with a target of sendevent.
The Xml
<eventInterfaces>
<eventInterface module='EventHandlers.HttpAction' name='HttpAction'>
<eventtype type="http://id.webbrick.co.uk/events/uri">
<eventsource source="command/stop" >
<event>
<command cmd='cmd.exe' params='net stop "WebBrick Gateway"' />
</event>
</eventsource>
</eventtype>
</eventInterface>
</eventInterfaces>
element: <eventInterfaces>
Each event despatch control file has a single top level container element called eventInterfaces, inside of which are 1 or more eventInterface elements.
element: <eventInterface>
An eventInterface element configures one instance of a named eventInterface, the configuration of an instance is private to itself. Most of the event interfaces can be loaded multiple times in the same configuration files or across multiple configuration files. A few can only be loaded once as they use dedicated resources or there is no point loading multiple times - these are typically listed in BaseHandlers.xml.
An event interface element lists two attributes that are used to dynamically load the event interface, these will be documented for each event interface. The dynamic loading means that it is possible to develop bespoke event interfaces and deploy without rebuilding the complete gateway. Each event interface element typically has one or more eventType elements, not typically but it is possible to have event interfaces that handle the configuration differently.
The sample above loads the event interface ShellAction, this event interface performs uses the system command shell to perform a local command, beware this could be catastrophic.
element: <eventtype>
Most event interface then lists one or more event types that it is interested in, this may be blank if it wants to see all event types and filter on the other things. The event log is an example of an event interface that listend to all events from all event sources (see BaseHandlers.xml).
The sample above listens for the event type "http://id.webbrick.co.uk/events/uri".
element: <eventsource>
Within the event type element the event interface lists one or more eventsource entries, these are the event source's that the interface it is interested in. It is possible again to put the empty string in here which means listen to all events of the named type.
The sample listens for command/restart.
element: <event>
The elements contained within the eventsource element tend to be more event interface dependant and reference should be made to the event interface documentation at. http://docs.webbrick.co.uk/eventinterfaces/EventInterfaces.html
In the case of the ShellAction each event source element contains one event element, within each of these is one or more command elements.
element: <command>
Each command element has 2 attributes. These are 'cmd' the excutable to run, in this case the command shell and 'params' the parameters to the command. The parameters may use substitution from the event payload.
In the sample we issue a .
Comment
This command is valid for windows only and leaves a gateway stopped and no way to restart it.
