Skip to content

Commit

Permalink
Update Style
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunnyka98 committed Nov 15, 2023
1 parent 32d05b1 commit a674ca6
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 142 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
- name: Checkout module
uses: actions/checkout@master
- name: Check style
uses: symcon/action-style@master
uses: symcon/action-style@v3
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.idea/
.phpunit.*
.php_cs.cache
.php_cs.cache
.php-cs-fixer.cache
2 changes: 1 addition & 1 deletion .style
Submodule .style updated 3 files
+42 −33 .php-cs-fixer.php
+22 −0 README.md
+85 −0 json-check.php
17 changes: 12 additions & 5 deletions EgiGeoZone/form.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{
"elements":
[
{ "name": "Username", "type": "ValidationTextBox", "caption": "Username" },
{ "name": "Password", "type": "PasswordTextBox", "caption": "Password" }
]
"elements": [
{
"name": "Username",
"type": "ValidationTextBox",
"caption": "Username"
},
{
"name": "Password",
"type": "PasswordTextBox",
"caption": "Password"
}
]
}
12 changes: 6 additions & 6 deletions EgiGeoZone/locale.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"translations": {
"de": {
"Username": "Benutzername",
"Password": "Passwort"
}
}
"translations": {
"de": {
"Username": "Benutzername",
"Password": "Passwort"
}
}
}
27 changes: 13 additions & 14 deletions EgiGeoZone/module.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"id": "{0100CA50-D2DA-11E4-8830-0800200C9A67}",
"name": "EgiGeoZone",
"type": 0,
"vendor": "",
"aliases":
[
"EgiGeoZone"
],
"parentRequirements": [],
"childRequirements": [],
"implemented": [],
"prefix": "EGZ",
"url": "https://github.com/symcon/EgiGeoZone/tree/master/EgiGeoZone"
}
"id": "{0100CA50-D2DA-11E4-8830-0800200C9A67}",
"name": "EgiGeoZone",
"type": 0,
"vendor": "",
"aliases": [
"EgiGeoZone"
],
"parentRequirements": [],
"childRequirements": [],
"implemented": [],
"prefix": "EGZ",
"url": "https://github.com/symcon/EgiGeoZone/tree/master/EgiGeoZone"
}
190 changes: 95 additions & 95 deletions EgiGeoZone/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,124 +4,124 @@

include_once __DIR__ . '/../libs/WebHookModule.php';

class EgiGeoZone extends WebHookModule
class EgiGeoZone extends WebHookModule
{
public function __construct($InstanceID)
{
public function __construct($InstanceID)
{
parent::__construct($InstanceID, 'egigeozone');
}
parent::__construct($InstanceID, 'egigeozone');
}

public function Create()
{
public function Create()
{

//Never delete this line!
parent::Create();
//Never delete this line!
parent::Create();

//Properties
$this->RegisterPropertyString('Username', '');
$this->RegisterPropertyString('Password', '');
}
//Properties
$this->RegisterPropertyString('Username', '');
$this->RegisterPropertyString('Password', '');
}

public function ApplyChanges()
{
public function ApplyChanges()
{

//Never delete this line!
parent::ApplyChanges();
//Never delete this line!
parent::ApplyChanges();

//Cleanup old hook script
$id = @IPS_GetObjectIDByIdent('Hook', $this->InstanceID);
if ($id > 0) {
IPS_DeleteScript($id, true);
}
//Cleanup old hook script
$id = @IPS_GetObjectIDByIdent('Hook', $this->InstanceID);
if ($id > 0) {
IPS_DeleteScript($id, true);
}
}

/**
* This function will be called by the hook control. Visibility should be protected!
*/
protected function ProcessHookData()
{

//Never delete this line!
parent::ProcessHookData();

if ((IPS_GetProperty($this->InstanceID, 'Username') != '') || (IPS_GetProperty($this->InstanceID, 'Password') != '')) {
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'] != IPS_GetProperty($this->InstanceID, 'Username')) || ($_SERVER['PHP_AUTH_PW'] != IPS_GetProperty($this->InstanceID, 'Password'))) {
header('WWW-Authenticate: Basic Realm="Geofency WebHook"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization required';
return;
}
}
/**
* This function will be called by the hook control. Visibility should be protected!
*/
protected function ProcessHookData()
{

if (!isset($_GET['device']) || !isset($_GET['id']) || !isset($_GET['name'])) {
$this->SendDebug('EgiGeoZone', 'Malformed data: ' . print_r($_GET, true), 0);
return;
//Never delete this line!
parent::ProcessHookData();

if ((IPS_GetProperty($this->InstanceID, 'Username') != '') || (IPS_GetProperty($this->InstanceID, 'Password') != '')) {
if (!isset($_SERVER['PHP_AUTH_USER'])) {
$_SERVER['PHP_AUTH_USER'] = '';
}
if (!isset($_SERVER['PHP_AUTH_PW'])) {
$_SERVER['PHP_AUTH_PW'] = '';
}

//Adding a missing '+' in front of the timezone to get a strtotime() convertable string
//Example:
//"2016-08-12T17:40:13 0000" => "2016-08-12T17:40:13 +0000"
if (strlen($_GET['date']) == 24) {
$_GET['date'] = implode('+', str_split($_GET['date'], 20));
if (($_SERVER['PHP_AUTH_USER'] != IPS_GetProperty($this->InstanceID, 'Username')) || ($_SERVER['PHP_AUTH_PW'] != IPS_GetProperty($this->InstanceID, 'Password'))) {
header('WWW-Authenticate: Basic Realm="Geofency WebHook"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization required';
return;
}
}

$deviceID = $this->CreateInstanceByIdent($this->InstanceID, $this->ReduceGUIDToIdent($_GET['device']), 'Device');
SetValue($this->CreateVariableByIdent($deviceID, 'Latitude', 'Latitude', 2), floatval($_GET['latitude']));
SetValue($this->CreateVariableByIdent($deviceID, 'Longitude', 'Longitude', 2), floatval($_GET['longitude']));
SetValue($this->CreateVariableByIdent($deviceID, 'Timestamp', 'Timestamp', 1, '~UnixTimestamp'), intval(strtotime($_GET['date'])));
SetValue($this->CreateVariableByIdent($deviceID, $this->ReduceToAllowedIdent($_GET['name']), utf8_decode($_GET['name']), 0, '~Presence'), intval($_GET['entry']) > 0);
if (!isset($_GET['device']) || !isset($_GET['id']) || !isset($_GET['name'])) {
$this->SendDebug('EgiGeoZone', 'Malformed data: ' . print_r($_GET, true), 0);
return;
}

private function ReduceGUIDToIdent($guid)
{
return str_replace(['{', '-', '}'], '', $guid);
//Adding a missing '+' in front of the timezone to get a strtotime() convertable string
//Example:
//"2016-08-12T17:40:13 0000" => "2016-08-12T17:40:13 +0000"
if (strlen($_GET['date']) == 24) {
$_GET['date'] = implode('+', str_split($_GET['date'], 20));
}

private function CreateVariableByIdent($id, $ident, $name, $type, $profile = '')
{
$vid = @IPS_GetObjectIDByIdent($ident, $id);
if ($vid === false) {
$vid = IPS_CreateVariable($type);
IPS_SetParent($vid, $id);
IPS_SetName($vid, $name);
IPS_SetIdent($vid, $ident);
if ($profile != '') {
IPS_SetVariableCustomProfile($vid, $profile);
}
$deviceID = $this->CreateInstanceByIdent($this->InstanceID, $this->ReduceGUIDToIdent($_GET['device']), 'Device');
SetValue($this->CreateVariableByIdent($deviceID, 'Latitude', 'Latitude', 2), floatval($_GET['latitude']));
SetValue($this->CreateVariableByIdent($deviceID, 'Longitude', 'Longitude', 2), floatval($_GET['longitude']));
SetValue($this->CreateVariableByIdent($deviceID, 'Timestamp', 'Timestamp', 1, '~UnixTimestamp'), intval(strtotime($_GET['date'])));
SetValue($this->CreateVariableByIdent($deviceID, $this->ReduceToAllowedIdent($_GET['name']), utf8_decode($_GET['name']), 0, '~Presence'), intval($_GET['entry']) > 0);
}

private function ReduceGUIDToIdent($guid)
{
return str_replace(['{', '-', '}'], '', $guid);
}

private function CreateVariableByIdent($id, $ident, $name, $type, $profile = '')
{
$vid = @IPS_GetObjectIDByIdent($ident, $id);
if ($vid === false) {
$vid = IPS_CreateVariable($type);
IPS_SetParent($vid, $id);
IPS_SetName($vid, $name);
IPS_SetIdent($vid, $ident);
if ($profile != '') {
IPS_SetVariableCustomProfile($vid, $profile);
}
return $vid;
}
return $vid;
}

private function CreateInstanceByIdent($id, $ident, $name, $moduleid = '{485D0419-BE97-4548-AA9C-C083EB82E61E}')
{
$iid = @IPS_GetObjectIDByIdent($ident, $id);
if ($iid === false) {
$iid = IPS_CreateInstance($moduleid);
IPS_SetParent($iid, $id);
IPS_SetName($iid, $name);
IPS_SetIdent($iid, $ident);
}
return $iid;
private function CreateInstanceByIdent($id, $ident, $name, $moduleid = '{485D0419-BE97-4548-AA9C-C083EB82E61E}')
{
$iid = @IPS_GetObjectIDByIdent($ident, $id);
if ($iid === false) {
$iid = IPS_CreateInstance($moduleid);
IPS_SetParent($iid, $id);
IPS_SetName($iid, $name);
IPS_SetIdent($iid, $ident);
}
return $iid;
}

//Replaces all unallowed Chars of a String with "_"
//Allowed Chars: "a..z", "A..Z", "_", "0..9"
private function ReduceToAllowedIdent($String)
{
for ($i = 0; $i < strlen($String); $i++) {
$val = ord($String[$i]);
// Between (1..9) Between (A..Z) Underscore (_) Between (a..z)
if (!(($val >= 48 && $val <= 57) || ($val >= 65 && $val <= 90) || ($val == 95) || ($val >= 97 && $val <= 122))) {
$String[$i] = '_';
}
//Replaces all unallowed Chars of a String with "_"
//Allowed Chars: "a..z", "A..Z", "_", "0..9"
private function ReduceToAllowedIdent($String)
{
for ($i = 0; $i < strlen($String); $i++) {
$val = ord($String[$i]);
// Between (1..9) Between (A..Z) Underscore (_) Between (a..z)
if (!(($val >= 48 && $val <= 57) || ($val >= 65 && $val <= 90) || ($val == 95) || ($val >= 97 && $val <= 122))) {
$String[$i] = '_';
}
return $String;
}
return $String;
}
}
22 changes: 11 additions & 11 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"id": "{A7F865AA-E499-4026-A100-A63234B15DDD}",
"author": "Symcon GmbH",
"name": "EgiGeoZone",
"url": "https://www.symcon.de/",
"compatibility": {
"version": "4.2"
},
"version": "1.0",
"build": 0,
"date": 0
}
"id": "{A7F865AA-E499-4026-A100-A63234B15DDD}",
"author": "Symcon GmbH",
"name": "EgiGeoZone",
"url": "https://www.symcon.de/",
"compatibility": {
"version": "4.2"
},
"version": "1.0",
"build": 0,
"date": 0
}
16 changes: 8 additions & 8 deletions libs/WebHookModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public function ApplyChanges()
}
}

/**
* This function will be called by the hook control. Visibility should be protected!
*/
protected function ProcessHookData()
{
$this->SendDebug('WebHook', 'Array POST: ' . print_r($_POST, true), 0);
}

private function RegisterHook($WebHook)
{
$ids = IPS_GetInstanceListByModuleID('{015A6EB8-D6E5-4B93-B496-0D3F77AE9FE1}');
Expand All @@ -76,12 +84,4 @@ private function RegisterHook($WebHook)
IPS_ApplyChanges($ids[0]);
}
}

/**
* This function will be called by the hook control. Visibility should be protected!
*/
protected function ProcessHookData()
{
$this->SendDebug('WebHook', 'Array POST: ' . print_r($_POST, true), 0);
}
}

0 comments on commit a674ca6

Please sign in to comment.