Documentation
WebHook Control
Require: IP-Symcon >= 4.0
Description
The WebHook Control module offers the possibility to call up scripts via a browser. Calls outside the local network are also possible via the Symcon Connect service.
It also offers the option of supplying data to the script.
Scripts executed by the Webhook include these Systemvariables
WebSocket Support
Since IP-Symcon Version 5.2, the WebHook Control uses WebSockets and thus enables real-time transmission.
Received data can be recorded and output as follows:
// When receiving, the data end up in the php://input stream. IPS_LogMessage("WebSocket", file_get_contents("php://input"));
Integration in IP-Symcon
The WebHook Control is one of the core instances and can therefore be configured immediately.
Within a browser, the respectively linked script can be called with "IP:PORT/hook/HOOKNAME".
To set up a hook, "Add" must be clicked on in the "WebHook Control" instance. The call name of the hook must first be entered and then the script to be executed by the hook must be selected.
Calls via Connect Control are also possible.
Example
Script call
The sample script to be called is "WebHook TestScript" with ObjectID "35909".
IPS_LogMessage("WebHook GET", print_r($_GET, true)); IPS_LogMessage("WebHook POST", print_r($_POST, true)); IPS_LogMessage("WebHook IPS", print_r($_IPS, true)); IPS_LogMessage("WebHook RAW", file_get_contents("php://input")); echo "Message: " . $_GET['Message'];
The call and the result would be as follows:
The data is passed to the script in arrays at IP-Symcon.
Authentication
An example of how automatic authentication was implemented via the Control module.
"Symcon" was selected as the user name and "password" was selected as the password.
Authentication is always recommended to prevent unauthorized access to IP-Symcon from outside.
Source code
if(!isset($_SERVER['PHP_AUTH_USER'])) $_SERVER['PHP_AUTH_USER'] = ""; if(!isset($_SERVER['PHP_AUTH_PW'])) $_SERVER['PHP_AUTH_PW'] = ""; if(($_SERVER['PHP_AUTH_USER'] != "Symcon") || ($_SERVER['PHP_AUTH_PW'] != "passwort")) { header('WWW-Authenticate: Basic Realm="Geofency WebHook"'); header('HTTP/1.0 401 Unauthorized'); echo "Authorization required"; return; } echo "Welcome to the protected area";
If the hook is called, the query for username and password appears. And the data is sent to the script via $post array.
Integration via PHP-Module
In addition to the call via script, it is also possible to react to hook calls within a PHP module using the "ProcessHookData()" function.
To do this, a hook is registered on an individual InstanceID. The "ProcessHookData()" function is then automatically called by the hook control.
Example
The example HookServe contains the source code for handling a WebHook via PHP module.