Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Brovning committed Oct 31, 2019
0 parents commit 2a69a95
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 0 deletions.
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# GruenbeckSD
Beschreibung des Moduls.

### Inhaltsverzeichnis

1. [Funktionsumfang](#1-funktionsumfang)
2. [Voraussetzungen](#2-voraussetzungen)
3. [Software-Installation](#3-software-installation)
4. [Einrichten der Instanzen in IP-Symcon](#4-einrichten-der-instanzen-in-ip-symcon)
5. [Statusvariablen und Profile](#5-statusvariablen-und-profile)
6. [WebFront](#6-webfront)
7. [PHP-Befehlsreferenz](#7-php-befehlsreferenz)

### 1. Funktionsumfang

*

### 2. Vorraussetzungen

- IP-Symcon ab Version 5.0

### 3. Software-Installation

* Über den Module Store das 'GruenbeckSD'-Modul installieren.
* Alternativ über das Module Control folgende URL hinzufügen

### 4. Einrichten der Instanzen in IP-Symcon

Unter 'Instanz hinzufügen' ist das 'GruenbeckSD'-Modul unter dem Hersteller 'Grünbeck' aufgeführt.

__Konfigurationsseite__:

Name | Beschreibung
-------- | ------------------
|
|

### 5. Statusvariablen und Profile

Die Statusvariablen/Kategorien werden automatisch angelegt. Das Löschen einzelner kann zu Fehlfunktionen führen.

#### Statusvariablen

Name | Typ | Beschreibung
------ | ------- | ------------
| |
| |

#### Profile

Name | Typ
------ | -------
|
|

### 6. WebFront

Die Funktionalität, die das Modul im WebFront bietet.

### 7. PHP-Befehlsreferenze

`boolean GSD_BeispielFunktion(integer $InstanzID);`
Erklärung der Funktion.

Beispiel:
`GSD_BeispielFunktion(12345);`
19 changes: 19 additions & 0 deletions gruenbeck/form.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"elements": [
{
"type": "ValidationTextBox",
"caption": "Username",
"name": "Username"
},
{
"type": "PasswordTextBox",
"caption": "Password",
"name": "Password"
},
{
"type": "Button",
"caption": "Login",
"onClick": "GSD_Login($id);"
}
]
}
8 changes: 8 additions & 0 deletions gruenbeck/locale.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"translations": {
"de": {
"Translation 1": "Übersetzung 1",
"Translation 2": "Übersetzung 2"
}
}
}
12 changes: 12 additions & 0 deletions gruenbeck/module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id": "{040A890B-82B2-EFCF-BE08-FF67735D40A9}",
"name": "GruenbeckSD",
"type": 3,
"vendor": "Grünbeck",
"aliases": [],
"parentRequirements": [],
"childRequirements": [],
"implemented": [],
"prefix": "GSD",
"url": ""
}
104 changes: 104 additions & 0 deletions gruenbeck/module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
class GruenbeckSD extends IPSModule {

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

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

}

public function Destroy()
{
//Never delete this line!
parent::Destroy();
}

public function ApplyChanges()
{
//Never delete this line!
parent::ApplyChanges();
}

public function Login()
{
$codeChallange = "cgCaF9zlf7HGlHsuQepqKGk1fLqmnFQ1E3EyWB4qiPs"; //Wert aus IOBroker Funktion entnommen
$this->SendAction("https://gruenbeckb2c.b2clogin.com/a50d35c1-202f-4da7-aa87-76e51a3098c6/b2c_1_signinup/oauth2/v2.0/authorize?state=NzZDNkNBRkMtOUYwOC00RTZBLUE5MkYtQTNFRDVGNTQ3MUNG&x-client-Ver=0.2.2&prompt=select_account&response_type=code&code_challenge_method=S256&x-client-OS=12.4.1&scope=https%3A%2F%2Fgruenbeckb2c.onmicrosoft.com%2Fiot%2Fuser_impersonation+openid+profile+offline_access&x-client-SKU=MSAL.iOS&code_challenge=" . $codeChallange . "&x-client-CPU=64&client-request-id=FDCD0F73-B7CD-4219-A29B-EE51A60FEE3E&redirect_uri=msal5a83cc16-ffb1-42e9-9859-9fbf07f36df8%3A%2F%2Fauth&client_id=5a83cc16-ffb1-42e9-9859-9fbf07f36df8&haschrome=1&return-client-request-id=true&x-client-DM=iPhone");
}

private function SendAction($url)
{
//Erster Aufruf | funktioniert einwandfrei
$this->SendDebug('SendAction', $url, 0);

$options = [
'http' => [
'method' => 'GET',
'header' => ''
]
];

$context = stream_context_create($options);

$result = file_get_contents($url, false, $context);

if ($result === false) {
die('Fetching data failed!');
}

//Benötigte Daten aus der Antword filtern
$jsonStart = strpos($result, "var SETTINGS = ") + 15;
$jsonEnd = strpos($result, ',"sanitizerPolicy"', $jsonStart);
$jsonString = json_decode(substr($result, $jsonStart, $jsonEnd - $jsonStart) . "}", true);
$csrf = $jsonString['csrf'];
$transId = $jsonString['transId'];
$jsonStart = strpos($result, '"hosts":') + 8;
$jsonEnd = strpos($result, '"locale') - 1;
$jsonString = json_decode(substr($result, $jsonStart, $jsonEnd - $jsonStart), true);
$tenant = $jsonString['tenant'];
$policy = $jsonString['policy'];

$this->SendDebug('Success',$result, 0);

$setCookie9 = $http_response_header[9];
$setCookie10 = $http_response_header[10];
$this->SendDebug("Cookies", print_r($http_response_header, 1), 0);
$cookie = substr($setCookie9, 11, strpos($setCookie9, "; ", 11) - 11 ) . "; " . substr($setCookie10, 11, strpos($setCookie10, "; ", 11) - 11 );

//Zweiter Aufruf | fehlerhaft
$data = [
"request_type" => "RESPONSE",
"logonIdentifier" => $this->ReadPropertyString('Username'),
"password" => $this->ReadPropertyString('Password')
];
$query = http_build_query($data);
$options = [
'http' => [
'method' => 'POST',
'header' => "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n".
"Content-Length: ". strlen($query). "\r\n".
"X-CSRF-TOKEN: $csrf\r\n".
//"Accept: application/json, text/javascript, */*; q=0.01\r\n".
"X-Request-With: XMLHttpRequest\r\n".
"Origin: https://gruenbeckb2c.b2clogin.com\r\n".
"Referer: https://gruenbeckb2c.b2clogin.com/a50d35c1-202f-4da7-aa87-76e51a3098c6/b2c_1_signinup/oauth2/v2.0/authorize?state=NzZDNkNBRkMtOUYwOC00RTZBLUE5MkYtQTNFRDVGNTQ3MUNG&x-client-Ver=0.2.2&prompt=select_account&response_type=code&code_challenge_method=S256&x-client-OS=12.4.1&scope=https%3A%2F%2Fgruenbeckb2c.onmicrosoft.com%2Fiot%2Fuser_impersonation+openid+profile+offline_access&x-client-SKU=MSAL.iOS&code_challenge=PkCmkmlW_KomPNfBLYqzBAHWi10TxFJSJsoYbI2bfZE&x-client-CPU=64&client-request-id=FDCD0F73-B7CD-4219-A29B-EE51A60FEE3E&redirect_uri=msal5a83cc16-ffb1-42e9-9859-9fbf07f36df8%3A%2F%2Fauth&client_id=5a83cc16-ffb1-42e9-9859-9fbf07f36df8&haschrome=1&return-client-request-id=true&x-client-DM=iPhone\r\n".
"Cookie: $cookie\r\n",
//"User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 12_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.2 Mobile/15E148 Safari/604.1\r\n",
'content' => $query
]
];

$context = stream_context_create($options);

$url = "https://gruenbeckb2c.b2clogin.com" . $tenant . "/SelfAsserted?tx=" . $transId . "&p=" . $policy;
$result = file_get_contents($url, false, $context);

if ($result === false) {
die('Fetching data failed!');
}
}
}

0 comments on commit 2a69a95

Please sign in to comment.