@@ -32,7 +32,7 @@ |
||
32 | 32 | * |
33 | 33 | * @param string $keystorePath Path public key store file (PHP) |
34 | 34 | * |
35 | - * @return PhpFile public key store |
|
35 | + * @return Threema\MsgApi\PublicKeyStores\PhpFile public key store |
|
36 | 36 | */ |
37 | 37 | function CreatePublicKeyStore($keystorePath) |
38 | 38 | { |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author rugk |
|
4 | - * @copyright Copyright (c) 2015 rugk |
|
5 | - * @license MIT |
|
6 | - */ |
|
3 | + * @author rugk |
|
4 | + * @copyright Copyright (c) 2015 rugk |
|
5 | + * @license MIT |
|
6 | + */ |
|
7 | 7 | |
8 | 8 | use Threema\MsgApi\Connection; |
9 | 9 | use Threema\MsgApi\ConnectionSettings; |
@@ -20,11 +20,11 @@ discard block |
||
20 | 20 | */ |
21 | 21 | function CreateConnection($keystorePath='../../keystore.php', $useTlsOptions=true) |
22 | 22 | { |
23 | - $publicKeyStore = CreatePublicKeyStore($keystorePath); |
|
24 | - $settings = CreateConnectionSettings($publicKeyStore, $useTlsOptions); |
|
25 | - $connector = InitiateConnection($settings, $publicKeyStore); |
|
23 | + $publicKeyStore = CreatePublicKeyStore($keystorePath); |
|
24 | + $settings = CreateConnectionSettings($publicKeyStore, $useTlsOptions); |
|
25 | + $connector = InitiateConnection($settings, $publicKeyStore); |
|
26 | 26 | |
27 | - return $connector; |
|
27 | + return $connector; |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | */ |
37 | 37 | function CreatePublicKeyStore($keystorePath) |
38 | 38 | { |
39 | - if (!file_exists($keystorePath)) { |
|
40 | - if (!touch($keystorePath)) { |
|
41 | - throw new Exception("PHP keystore could not be created."); |
|
42 | - } |
|
43 | - } |
|
44 | - return $publicKeyStore = new Threema\MsgApi\PublicKeyStores\PhpFile($keystorePath); |
|
39 | + if (!file_exists($keystorePath)) { |
|
40 | + if (!touch($keystorePath)) { |
|
41 | + throw new Exception("PHP keystore could not be created."); |
|
42 | + } |
|
43 | + } |
|
44 | + return $publicKeyStore = new Threema\MsgApi\PublicKeyStores\PhpFile($keystorePath); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -54,27 +54,27 @@ discard block |
||
54 | 54 | */ |
55 | 55 | function CreateConnectionSettings($publicKeyStore, $useTlsOptions) |
56 | 56 | { |
57 | - if ($useTlsOptions == true) { |
|
58 | - //create a connection with advanced options |
|
59 | - $settings = new ConnectionSettings( |
|
60 | - MSGAPI_GATEWAY_THREEMA_ID, |
|
61 | - MSGAPI_GATEWAY_THREEMA_ID_SECRET, |
|
62 | - null, |
|
63 | - [ |
|
64 | - 'forceHttps' => true, |
|
65 | - 'tlsVersion' => '1.2', |
|
66 | - 'tlsCipher' => 'ECDHE-RSA-AES128-GCM-SHA256' |
|
67 | - ] |
|
68 | - ); |
|
69 | - } else { |
|
70 | - //create a connection with default options |
|
71 | - $settings = new ConnectionSettings( |
|
72 | - MSGAPI_GATEWAY_THREEMA_ID, |
|
73 | - MSGAPI_GATEWAY_THREEMA_ID_SECRET |
|
74 | - ); |
|
75 | - } |
|
57 | + if ($useTlsOptions == true) { |
|
58 | + //create a connection with advanced options |
|
59 | + $settings = new ConnectionSettings( |
|
60 | + MSGAPI_GATEWAY_THREEMA_ID, |
|
61 | + MSGAPI_GATEWAY_THREEMA_ID_SECRET, |
|
62 | + null, |
|
63 | + [ |
|
64 | + 'forceHttps' => true, |
|
65 | + 'tlsVersion' => '1.2', |
|
66 | + 'tlsCipher' => 'ECDHE-RSA-AES128-GCM-SHA256' |
|
67 | + ] |
|
68 | + ); |
|
69 | + } else { |
|
70 | + //create a connection with default options |
|
71 | + $settings = new ConnectionSettings( |
|
72 | + MSGAPI_GATEWAY_THREEMA_ID, |
|
73 | + MSGAPI_GATEWAY_THREEMA_ID_SECRET |
|
74 | + ); |
|
75 | + } |
|
76 | 76 | |
77 | - return $settings; |
|
77 | + return $settings; |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -87,5 +87,5 @@ discard block |
||
87 | 87 | */ |
88 | 88 | function InitiateConnection($settings, $publicKeyStore) |
89 | 89 | { |
90 | - return $connector = new Connection($settings, $publicKeyStore); |
|
90 | + return $connector = new Connection($settings, $publicKeyStore); |
|
91 | 91 | } |
@@ -18,7 +18,7 @@ |
||
18 | 18 | * |
19 | 19 | * @return Connection $connector |
20 | 20 | */ |
21 | -function CreateConnection($keystorePath='../../keystore.php', $useTlsOptions=true) |
|
21 | +function CreateConnection($keystorePath = '../../keystore.php', $useTlsOptions = true) |
|
22 | 22 | { |
23 | 23 | $publicKeyStore = CreatePublicKeyStore($keystorePath); |
24 | 24 | $settings = CreateConnectionSettings($publicKeyStore, $useTlsOptions); |
@@ -34,7 +34,7 @@ |
||
34 | 34 | * @param string $threemaId The id whose public key should be fetched |
35 | 35 | * @param string $message The message to send (max 3500 characters) |
36 | 36 | * |
37 | - * @return string|Exception |
|
37 | + * @return string |
|
38 | 38 | */ |
39 | 39 | function SendMessage($connector, $threemaId, $message) |
40 | 40 | { |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | */ |
39 | 39 | function SendMessage($connector, $threemaId, $message) |
40 | 40 | { |
41 | - $e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper(KeyHexToBin(MSGAPI_PRIVATE_KEY), $connector); |
|
42 | - $result = $e2eHelper->sendTextMessage($threemaId, $message); |
|
41 | + $e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper(KeyHexToBin(MSGAPI_PRIVATE_KEY), $connector); |
|
42 | + $result = $e2eHelper->sendTextMessage($threemaId, $message); |
|
43 | 43 | |
44 | - if (true === $result->isSuccess()) { |
|
45 | - return $result->getMessageId(); |
|
46 | - } else { |
|
47 | - throw new Exception($result->getErrorMessage()); |
|
48 | - } |
|
44 | + if (true === $result->isSuccess()) { |
|
45 | + return $result->getMessageId(); |
|
46 | + } else { |
|
47 | + throw new Exception($result->getErrorMessage()); |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | //get params |
52 | 52 | if (ReturnGetPost('recieverid') && |
53 | - preg_match('/' . REGEXP_THREEMAID_ANY . '/', ReturnGetPost('recieverid')) |
|
53 | + preg_match('/' . REGEXP_THREEMAID_ANY . '/', ReturnGetPost('recieverid')) |
|
54 | 54 | ) { |
55 | - $threemaId = htmlentities(ReturnGetPost('recieverid')); |
|
56 | - $message = ReturnGetPost('message'); |
|
55 | + $threemaId = htmlentities(ReturnGetPost('recieverid')); |
|
56 | + $message = ReturnGetPost('message'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | //create connection |
@@ -61,24 +61,24 @@ discard block |
||
61 | 61 | |
62 | 62 | //Send message |
63 | 63 | if ($threemaId != null && $message != null) { |
64 | - if (!$isIncluded) { |
|
65 | - header('Content-Type: text/plain'); |
|
66 | - } |
|
67 | - $actionDone = true; |
|
64 | + if (!$isIncluded) { |
|
65 | + header('Content-Type: text/plain'); |
|
66 | + } |
|
67 | + $actionDone = true; |
|
68 | 68 | |
69 | - try { |
|
70 | - $messageId = SendMessage($connector, $threemaId, $message); |
|
71 | - } catch (Exception $e) { |
|
72 | - http_response_code(500); |
|
73 | - $errorMessage = $e->getMessage(); |
|
74 | - } |
|
69 | + try { |
|
70 | + $messageId = SendMessage($connector, $threemaId, $message); |
|
71 | + } catch (Exception $e) { |
|
72 | + http_response_code(500); |
|
73 | + $errorMessage = $e->getMessage(); |
|
74 | + } |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | //Show direct output if the file is called directly |
78 | 78 | if (!$isIncluded) { |
79 | - if ($errorMessage == null) { |
|
80 | - echo 'Message ID: ' . $messageId; |
|
81 | - } else { |
|
82 | - echo $errorMessage; |
|
83 | - } |
|
79 | + if ($errorMessage == null) { |
|
80 | + echo 'Message ID: ' . $messageId; |
|
81 | + } else { |
|
82 | + echo $errorMessage; |
|
83 | + } |
|
84 | 84 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | //get params |
52 | 52 | if (ReturnGetPost('recieverid') && |
53 | - preg_match('/' . REGEXP_THREEMAID_ANY . '/', ReturnGetPost('recieverid')) |
|
53 | + preg_match('/'.REGEXP_THREEMAID_ANY.'/', ReturnGetPost('recieverid')) |
|
54 | 54 | ) { |
55 | 55 | $threemaId = htmlentities(ReturnGetPost('recieverid')); |
56 | 56 | $message = ReturnGetPost('message'); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | //Show direct output if the file is called directly |
78 | 78 | if (!$isIncluded) { |
79 | 79 | if ($errorMessage == null) { |
80 | - echo 'Message ID: ' . $messageId; |
|
80 | + echo 'Message ID: '.$messageId; |
|
81 | 81 | } else { |
82 | 82 | echo $errorMessage; |
83 | 83 | } |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author rugk |
|
4 | - * @copyright Copyright (c) 2015 rugk |
|
5 | - * @license MIT |
|
6 | - */ |
|
3 | + * @author rugk |
|
4 | + * @copyright Copyright (c) 2015 rugk |
|
5 | + * @license MIT |
|
6 | + */ |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Returns the parameter from GET (preferred) or POST. |
@@ -13,12 +13,12 @@ discard block |
||
13 | 13 | */ |
14 | 14 | function ReturnGetPost($name) |
15 | 15 | { |
16 | - if (isset($_GET[$name])) { |
|
17 | - return $_GET[$name]; |
|
18 | - } |
|
19 | - if (isset($_POST[$name])) { |
|
20 | - return $_POST[$name]; |
|
21 | - } |
|
16 | + if (isset($_GET[$name])) { |
|
17 | + return $_GET[$name]; |
|
18 | + } |
|
19 | + if (isset($_POST[$name])) { |
|
20 | + return $_POST[$name]; |
|
21 | + } |
|
22 | 22 | |
23 | - return null; |
|
23 | + return null; |
|
24 | 24 | } |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author rugk |
|
4 | - * @copyright Copyright (c) 2015 rugk |
|
5 | - * @license MIT |
|
6 | - */ |
|
3 | + * @author rugk |
|
4 | + * @copyright Copyright (c) 2015 rugk |
|
5 | + * @license MIT |
|
6 | + */ |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Checks whether a HEX-key is valid. |
@@ -14,8 +14,8 @@ discard block |
||
14 | 14 | */ |
15 | 15 | function KeyCheck($publicKey, $suffix='') |
16 | 16 | { |
17 | - // RegExp: https://regex101.com/r/sU5tC8/1 |
|
18 | - return preg_match('/^(' . $suffix . ')?[[:alnum:]]{64}$/', $publicKey); |
|
17 | + // RegExp: https://regex101.com/r/sU5tC8/1 |
|
18 | + return preg_match('/^(' . $suffix . ')?[[:alnum:]]{64}$/', $publicKey); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | */ |
33 | 33 | function KeyGetUserDisplay($publicKey) |
34 | 34 | { |
35 | - //force key to be binary |
|
36 | - if (ctype_alnum($publicKey)) { |
|
37 | - $publicKey = KeyHexToBin($publicKey); |
|
38 | - } |
|
35 | + //force key to be binary |
|
36 | + if (ctype_alnum($publicKey)) { |
|
37 | + $publicKey = KeyHexToBin($publicKey); |
|
38 | + } |
|
39 | 39 | |
40 | - //create short hash |
|
41 | - $shortHash = substr(hash('sha256', $publicKey, 0, 32)); |
|
42 | - return $shortHash; |
|
40 | + //create short hash |
|
41 | + $shortHash = substr(hash('sha256', $publicKey, 0, 32)); |
|
42 | + return $shortHash; |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -51,13 +51,13 @@ discard block |
||
51 | 51 | */ |
52 | 52 | function KeyHexToBin($keyHex) |
53 | 53 | { |
54 | - //delete prefix |
|
55 | - $keyTypeCheck = substr($keyHex, 0, 8); |
|
56 | - if ($keyTypeCheck == 'private:' || $keyTypeCheck == 'public:') { |
|
57 | - $keyHex = substr($keyHex, 8); |
|
58 | - } |
|
54 | + //delete prefix |
|
55 | + $keyTypeCheck = substr($keyHex, 0, 8); |
|
56 | + if ($keyTypeCheck == 'private:' || $keyTypeCheck == 'public:') { |
|
57 | + $keyHex = substr($keyHex, 8); |
|
58 | + } |
|
59 | 59 | |
60 | - //convert key |
|
61 | - $keyBin = hex2bin($keyHex); |
|
62 | - return $keyBin; |
|
60 | + //convert key |
|
61 | + $keyBin = hex2bin($keyHex); |
|
62 | + return $keyBin; |
|
63 | 63 | } |
@@ -12,10 +12,10 @@ |
||
12 | 12 | * @param string optional suffix (usually 'private:' or 'public:') (default: '') |
13 | 13 | * @return bool whether the key is valid (true) or not (false) |
14 | 14 | */ |
15 | -function KeyCheck($publicKey, $suffix='') |
|
15 | +function KeyCheck($publicKey, $suffix = '') |
|
16 | 16 | { |
17 | 17 | // RegExp: https://regex101.com/r/sU5tC8/1 |
18 | - return preg_match('/^(' . $suffix . ')?[[:alnum:]]{64}$/', $publicKey); |
|
18 | + return preg_match('/^('.$suffix.')?[[:alnum:]]{64}$/', $publicKey); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author rugk |
|
4 | - * @copyright Copyright (c) 2015 rugk |
|
5 | - * @license MIT |
|
6 | - */ |
|
3 | + * @author rugk |
|
4 | + * @copyright Copyright (c) 2015 rugk |
|
5 | + * @license MIT |
|
6 | + */ |
|
7 | 7 | |
8 | 8 | /* CONSTANTS */ |
9 | 9 | const FILENAME_CONNCRED = 'ConnectionCredentials.php'; |
@@ -32,21 +32,21 @@ discard block |
||
32 | 32 | */ |
33 | 33 | function FetchPublicKey($connector, $threemaId) |
34 | 34 | { |
35 | - $result = $connector->fetchPublicKey($threemaId); |
|
36 | - if($result->isSuccess()) { |
|
37 | - return $result->getPublicKey(); |
|
38 | - } |
|
39 | - else { |
|
40 | - throw new Exception($result->getErrorMessage()); |
|
41 | - } |
|
35 | + $result = $connector->fetchPublicKey($threemaId); |
|
36 | + if($result->isSuccess()) { |
|
37 | + return $result->getPublicKey(); |
|
38 | + } |
|
39 | + else { |
|
40 | + throw new Exception($result->getErrorMessage()); |
|
41 | + } |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | //get params |
45 | 45 | $threemaId = null; |
46 | 46 | if (ReturnGetPost('threemaid') && |
47 | - preg_match('/' . REGEXP_THREEMAID_ANY . '/', ReturnGetPost('threemaid')) |
|
47 | + preg_match('/' . REGEXP_THREEMAID_ANY . '/', ReturnGetPost('threemaid')) |
|
48 | 48 | ) { |
49 | - $threemaId = htmlentities(ReturnGetPost('threemaid')); |
|
49 | + $threemaId = htmlentities(ReturnGetPost('threemaid')); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | //create connection |
@@ -54,15 +54,15 @@ discard block |
||
54 | 54 | |
55 | 55 | //Fetch public key and return a 500 error in case of a failure |
56 | 56 | if ($threemaId != null) { |
57 | - try { |
|
58 | - $publicKey = FetchPublicKey($connector, $threemaId); |
|
59 | - echo $publicKey; |
|
60 | - } |
|
61 | - catch (Exception $e) { |
|
62 | - http_response_code(500); |
|
63 | - echo $e->getMessage(); |
|
64 | - } |
|
57 | + try { |
|
58 | + $publicKey = FetchPublicKey($connector, $threemaId); |
|
59 | + echo $publicKey; |
|
60 | + } |
|
61 | + catch (Exception $e) { |
|
62 | + http_response_code(500); |
|
63 | + echo $e->getMessage(); |
|
64 | + } |
|
65 | 65 | } else { |
66 | - http_response_code(500); |
|
67 | - echo 'Invalid Threema ID'; |
|
66 | + http_response_code(500); |
|
67 | + echo 'Invalid Threema ID'; |
|
68 | 68 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | function FetchPublicKey($connector, $threemaId) |
34 | 34 | { |
35 | 35 | $result = $connector->fetchPublicKey($threemaId); |
36 | - if($result->isSuccess()) { |
|
36 | + if ($result->isSuccess()) { |
|
37 | 37 | return $result->getPublicKey(); |
38 | 38 | } |
39 | 39 | else { |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | //get params |
45 | 45 | $threemaId = null; |
46 | 46 | if (ReturnGetPost('threemaid') && |
47 | - preg_match('/' . REGEXP_THREEMAID_ANY . '/', ReturnGetPost('threemaid')) |
|
47 | + preg_match('/'.REGEXP_THREEMAID_ANY.'/', ReturnGetPost('threemaid')) |
|
48 | 48 | ) { |
49 | 49 | $threemaId = htmlentities(ReturnGetPost('threemaid')); |
50 | 50 | } |
@@ -35,8 +35,7 @@ discard block |
||
35 | 35 | $result = $connector->fetchPublicKey($threemaId); |
36 | 36 | if($result->isSuccess()) { |
37 | 37 | return $result->getPublicKey(); |
38 | - } |
|
39 | - else { |
|
38 | + } else { |
|
40 | 39 | throw new Exception($result->getErrorMessage()); |
41 | 40 | } |
42 | 41 | } |
@@ -57,8 +56,7 @@ discard block |
||
57 | 56 | try { |
58 | 57 | $publicKey = FetchPublicKey($connector, $threemaId); |
59 | 58 | echo $publicKey; |
60 | - } |
|
61 | - catch (Exception $e) { |
|
59 | + } catch (Exception $e) { |
|
62 | 60 | http_response_code(500); |
63 | 61 | echo $e->getMessage(); |
64 | 62 | } |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <!-- |
2 | 2 | <?php |
3 | 3 | /** |
4 | - * @author rugk |
|
5 | - * @copyright Copyright (c) 2015 rugk |
|
6 | - * @license MIT |
|
7 | - */ |
|
4 | + * @author rugk |
|
5 | + * @copyright Copyright (c) 2015 rugk |
|
6 | + * @license MIT |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | /* INCLUDES */ |
10 | 10 | require_once 'include/GlobalConstants.php'; |
@@ -18,86 +18,86 @@ discard block |
||
18 | 18 | /* SOME SMALL FUNCTIONS */ |
19 | 19 | function ShowDefaultReceiverId($addOptionsHtmlCode = false) |
20 | 20 | { |
21 | - $isShown = ReturnGetPost('threemaid') != null || ReturnGetPost('recieverid') != null || MSGAPI_DEFAULTRECEIVER <> ''; |
|
22 | - |
|
23 | - // Show previous input if there is something |
|
24 | - if ($isShown && $addOptionsHtmlCode) { |
|
25 | - echo '<option value="'; |
|
26 | - } |
|
27 | - |
|
28 | - if (ReturnGetPost('threemaid') != null) { |
|
29 | - echo htmlentities(ReturnGetPost('threemaid')); |
|
30 | - } elseif (ReturnGetPost('recieverid') != null) { |
|
31 | - echo htmlentities(ReturnGetPost('recieverid')); |
|
32 | - } elseif (MSGAPI_DEFAULTRECEIVER <> '') { |
|
33 | - // use receiver in config |
|
34 | - echo MSGAPI_DEFAULTRECEIVER; |
|
35 | - } |
|
36 | - |
|
37 | - if ($isShown && $addOptionsHtmlCode) { |
|
38 | - echo '">'; |
|
39 | - } |
|
21 | + $isShown = ReturnGetPost('threemaid') != null || ReturnGetPost('recieverid') != null || MSGAPI_DEFAULTRECEIVER <> ''; |
|
22 | + |
|
23 | + // Show previous input if there is something |
|
24 | + if ($isShown && $addOptionsHtmlCode) { |
|
25 | + echo '<option value="'; |
|
26 | + } |
|
27 | + |
|
28 | + if (ReturnGetPost('threemaid') != null) { |
|
29 | + echo htmlentities(ReturnGetPost('threemaid')); |
|
30 | + } elseif (ReturnGetPost('recieverid') != null) { |
|
31 | + echo htmlentities(ReturnGetPost('recieverid')); |
|
32 | + } elseif (MSGAPI_DEFAULTRECEIVER <> '') { |
|
33 | + // use receiver in config |
|
34 | + echo MSGAPI_DEFAULTRECEIVER; |
|
35 | + } |
|
36 | + |
|
37 | + if ($isShown && $addOptionsHtmlCode) { |
|
38 | + echo '">'; |
|
39 | + } |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | function ShowDefaultMessage() |
43 | 43 | { |
44 | - // Show previous input if there is something |
|
45 | - if (ReturnGetPost('message') != null) { |
|
46 | - echo htmlentities(ReturnGetPost('message')); |
|
47 | - } |
|
44 | + // Show previous input if there is something |
|
45 | + if (ReturnGetPost('message') != null) { |
|
46 | + echo htmlentities(ReturnGetPost('message')); |
|
47 | + } |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /* CHECK PREREQUISITES */ |
51 | 51 | $fileConnCredentErr = ''; |
52 | 52 | if (!file_exists(FILENAME_CONNCRED)) { |
53 | - $fileConnCredentErr .= ' The file does not exist.'; |
|
53 | + $fileConnCredentErr .= ' The file does not exist.'; |
|
54 | 54 | } else { |
55 | - require_once FILENAME_CONNCRED; |
|
56 | - if (!defined('MSGAPI_GATEWAY_THREEMA_ID') || |
|
57 | - !defined('MSGAPI_GATEWAY_THREEMA_ID_SECRET') |
|
58 | - ) { |
|
59 | - $fileConnCredentErr .= ' Not all required constants are defined.'; |
|
60 | - } else { |
|
61 | - if (MSGAPI_GATEWAY_THREEMA_ID == '' || |
|
62 | - !preg_match('/' . REGEXP_THREEMAID_GATEWAY . '/', MSGAPI_GATEWAY_THREEMA_ID) |
|
63 | - ) { |
|
64 | - $fileConnCredentErr .= ' \'MSGAPI_GATEWAY_THREEMA_ID\' is invalid.'; |
|
65 | - } |
|
66 | - |
|
67 | - if (MSGAPI_GATEWAY_THREEMA_ID_SECRET == '' || |
|
68 | - !ctype_alnum(MSGAPI_GATEWAY_THREEMA_ID_SECRET) |
|
69 | - ) { |
|
70 | - $fileConnCredentErr .= ' \'MSGAPI_GATEWAY_THREEMA_ID_SECRET\' is invalid.'; |
|
71 | - } |
|
72 | - |
|
73 | - // MSGAPI_DEFAULTRECEIVER is optional |
|
74 | - if (!defined('MSGAPI_DEFAULTRECEIVER')) { |
|
75 | - define('MSGAPI_DEFAULTRECEIVER', ''); |
|
76 | - } |
|
77 | - |
|
78 | - if (MSGAPI_DEFAULTRECEIVER <> '' && |
|
79 | - !preg_match('/' . REGEXP_THREEMAID_ANY . '/', MSGAPI_DEFAULTRECEIVER) |
|
80 | - ) { |
|
81 | - $fileConnCredentErr .= ' \'MSGAPI_DEFAULTRECEIVER\' is invalid.'; |
|
82 | - } |
|
83 | - } |
|
55 | + require_once FILENAME_CONNCRED; |
|
56 | + if (!defined('MSGAPI_GATEWAY_THREEMA_ID') || |
|
57 | + !defined('MSGAPI_GATEWAY_THREEMA_ID_SECRET') |
|
58 | + ) { |
|
59 | + $fileConnCredentErr .= ' Not all required constants are defined.'; |
|
60 | + } else { |
|
61 | + if (MSGAPI_GATEWAY_THREEMA_ID == '' || |
|
62 | + !preg_match('/' . REGEXP_THREEMAID_GATEWAY . '/', MSGAPI_GATEWAY_THREEMA_ID) |
|
63 | + ) { |
|
64 | + $fileConnCredentErr .= ' \'MSGAPI_GATEWAY_THREEMA_ID\' is invalid.'; |
|
65 | + } |
|
66 | + |
|
67 | + if (MSGAPI_GATEWAY_THREEMA_ID_SECRET == '' || |
|
68 | + !ctype_alnum(MSGAPI_GATEWAY_THREEMA_ID_SECRET) |
|
69 | + ) { |
|
70 | + $fileConnCredentErr .= ' \'MSGAPI_GATEWAY_THREEMA_ID_SECRET\' is invalid.'; |
|
71 | + } |
|
72 | + |
|
73 | + // MSGAPI_DEFAULTRECEIVER is optional |
|
74 | + if (!defined('MSGAPI_DEFAULTRECEIVER')) { |
|
75 | + define('MSGAPI_DEFAULTRECEIVER', ''); |
|
76 | + } |
|
77 | + |
|
78 | + if (MSGAPI_DEFAULTRECEIVER <> '' && |
|
79 | + !preg_match('/' . REGEXP_THREEMAID_ANY . '/', MSGAPI_DEFAULTRECEIVER) |
|
80 | + ) { |
|
81 | + $fileConnCredentErr .= ' \'MSGAPI_DEFAULTRECEIVER\' is invalid.'; |
|
82 | + } |
|
83 | + } |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | |
87 | 87 | $fileChkPrivateKeyErr = ''; |
88 | 88 | if (!file_exists(FILENAME_PRIVKEY)) { |
89 | - $fileChkPrivateKeyErr .= ' The file does not exist.'; |
|
89 | + $fileChkPrivateKeyErr .= ' The file does not exist.'; |
|
90 | 90 | } else { |
91 | - require_once FILENAME_PRIVKEY; |
|
92 | - if (!defined('MSGAPI_PRIVATE_KEY')) { |
|
93 | - $fileChkPrivateKeyErr .= ' Not all constants are defined.'; |
|
94 | - } else { |
|
95 | - if (MSGAPI_PRIVATE_KEY == '' || |
|
96 | - !KeyCheck(MSGAPI_PRIVATE_KEY, 'private:') |
|
97 | - ) { |
|
98 | - $fileChkPrivateKeyErr .= ' \'MSGAPI_PRIVATE_KEY\' is invalid.'; |
|
99 | - } |
|
100 | - } |
|
91 | + require_once FILENAME_PRIVKEY; |
|
92 | + if (!defined('MSGAPI_PRIVATE_KEY')) { |
|
93 | + $fileChkPrivateKeyErr .= ' Not all constants are defined.'; |
|
94 | + } else { |
|
95 | + if (MSGAPI_PRIVATE_KEY == '' || |
|
96 | + !KeyCheck(MSGAPI_PRIVATE_KEY, 'private:') |
|
97 | + ) { |
|
98 | + $fileChkPrivateKeyErr .= ' \'MSGAPI_PRIVATE_KEY\' is invalid.'; |
|
99 | + } |
|
100 | + } |
|
101 | 101 | } |
102 | 102 | ?> |
103 | 103 | --> |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | </head> |
112 | 112 | <body> |
113 | 113 | <?php |
114 | - // only shows content when it is not parsed by a PHP interpreter |
|
115 | - if (false): |
|
116 | - ?> |
|
114 | + // only shows content when it is not parsed by a PHP interpreter |
|
115 | + if (false): |
|
116 | + ?> |
|
117 | 117 | <!-- PHP parsing error message --> |
118 | 118 | <div class="warning"> |
119 | 119 | You are viewing this file within a browser. However you do need to call this file |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | PHP support and access the file like this: <code>http://127.0.0.1/threema-msgapi-sdk-php/samples/web/</code>. |
122 | 122 | </div> |
123 | 123 | <?php |
124 | - endif |
|
125 | - ?> |
|
124 | + endif |
|
125 | + ?> |
|
126 | 126 | |
127 | 127 | <h1 id="devui">Development UI - MSGAPI-PHP-SDK - Threema Gateway</h1> |
128 | 128 | <p> |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | $fileConnCredentErr .= ' Not all required constants are defined.'; |
60 | 60 | } else { |
61 | 61 | if (MSGAPI_GATEWAY_THREEMA_ID == '' || |
62 | - !preg_match('/' . REGEXP_THREEMAID_GATEWAY . '/', MSGAPI_GATEWAY_THREEMA_ID) |
|
62 | + !preg_match('/'.REGEXP_THREEMAID_GATEWAY.'/', MSGAPI_GATEWAY_THREEMA_ID) |
|
63 | 63 | ) { |
64 | 64 | $fileConnCredentErr .= ' \'MSGAPI_GATEWAY_THREEMA_ID\' is invalid.'; |
65 | 65 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | if (MSGAPI_DEFAULTRECEIVER <> '' && |
79 | - !preg_match('/' . REGEXP_THREEMAID_ANY . '/', MSGAPI_DEFAULTRECEIVER) |
|
79 | + !preg_match('/'.REGEXP_THREEMAID_ANY.'/', MSGAPI_DEFAULTRECEIVER) |
|
80 | 80 | ) { |
81 | 81 | $fileConnCredentErr .= ' \'MSGAPI_DEFAULTRECEIVER\' is invalid.'; |
82 | 82 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | <!-- files already exist - no need to show instructions --> |
135 | 135 | <?php else: ?> |
136 | 136 | <p> |
137 | - Before you can use this test you have to get credentials at <a href="https://gateway.threema.ch" title="Threema Gateway">gateway.threema.ch</a> and <a href="https://github.com/rugk/threema-msgapi-sdk-php/wiki/How-to-generate-a-new-key-pair-and-send-a-message">create a key pair</a>. After you did so, you have to open <code><?php echo FILENAME_CONNCRED . FILEEXT_EXAMPLE ?></code> and <code><?php echo FILENAME_PRIVKEY . FILEEXT_EXAMPLE ?></code> and add your credentials and private key. Save them without the <code><?php echo FILEEXT_EXAMPLE ?></code> file extension afterwards. |
|
137 | + Before you can use this test you have to get credentials at <a href="https://gateway.threema.ch" title="Threema Gateway">gateway.threema.ch</a> and <a href="https://github.com/rugk/threema-msgapi-sdk-php/wiki/How-to-generate-a-new-key-pair-and-send-a-message">create a key pair</a>. After you did so, you have to open <code><?php echo FILENAME_CONNCRED.FILEEXT_EXAMPLE ?></code> and <code><?php echo FILENAME_PRIVKEY.FILEEXT_EXAMPLE ?></code> and add your credentials and private key. Save them without the <code><?php echo FILEEXT_EXAMPLE ?></code> file extension afterwards. |
|
138 | 138 | By default these files are excluded from git pulls so you will not accidentally publish these sensitive files. |
139 | 139 | </p> |
140 | 140 | <?php endif ?> |
@@ -221,9 +221,9 @@ discard block |
||
221 | 221 | </fieldset> |
222 | 222 | <fieldset id="field_method"> |
223 | 223 | <legend>Method</legend> |
224 | - <input id="SrvMethodGet" name="servermethod" type="radio" <?php if ($_SERVER['REQUEST_METHOD'] == 'GET') {echo 'checked="checked"';}?> value="get"> |
|
224 | + <input id="SrvMethodGet" name="servermethod" type="radio" <?php if ($_SERVER['REQUEST_METHOD'] == 'GET') {echo 'checked="checked"'; }?> value="get"> |
|
225 | 225 | <label for="SrvMethodGet">GET</label> |
226 | - <input id="SrvMethodPost" name="servermethod" type="radio" <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') {echo 'checked="checked"';}?> value="post"> |
|
226 | + <input id="SrvMethodPost" name="servermethod" type="radio" <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') {echo 'checked="checked"'; }?> value="post"> |
|
227 | 227 | <label for="SrvMethodPost">POST</label> |
228 | 228 | <br /> |
229 | 229 | <input id="ButtonExternalScript" name="isExternal" type="checkbox"> |
@@ -132,7 +132,8 @@ discard block |
||
132 | 132 | <h2 id="prerequisites">Prerequisites</h2> |
133 | 133 | <?php if ($fileConnCredentErr == '' && $fileChkPrivateKeyErr == ''): ?> |
134 | 134 | <!-- files already exist - no need to show instructions --> |
135 | - <?php else: ?> |
|
135 | + <?php else { |
|
136 | + : ?> |
|
136 | 137 | <p> |
137 | 138 | Before you can use this test you have to get credentials at <a href="https://gateway.threema.ch" title="Threema Gateway">gateway.threema.ch</a> and <a href="https://github.com/rugk/threema-msgapi-sdk-php/wiki/How-to-generate-a-new-key-pair-and-send-a-message">create a key pair</a>. After you did so, you have to open <code><?php echo FILENAME_CONNCRED . FILEEXT_EXAMPLE ?></code> and <code><?php echo FILENAME_PRIVKEY . FILEEXT_EXAMPLE ?></code> and add your credentials and private key. Save them without the <code><?php echo FILEEXT_EXAMPLE ?></code> file extension afterwards. |
138 | 139 | By default these files are excluded from git pulls so you will not accidentally publish these sensitive files. |
@@ -192,7 +193,9 @@ discard block |
||
192 | 193 | You did not prepared your setup correctly to use the test. Please follow the intructions above to setup your environment. |
193 | 194 | </div> |
194 | 195 | <?php else: ?> |
195 | - <form id="mainform" action="." method="<?php echo $_SERVER['REQUEST_METHOD']; ?>"> |
|
196 | + <form id="mainform" action="." method="<?php echo $_SERVER['REQUEST_METHOD']; |
|
197 | +} |
|
198 | +?>"> |
|
196 | 199 | <div class="formcontainer"> |
197 | 200 | <fieldset id="field_generalsettings"> |
198 | 201 | <legend>General settings</legend> |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author rugk |
|
4 | - * @copyright Copyright (c) 2015 rugk |
|
5 | - * @license MIT |
|
6 | - */ |
|
3 | + * @author rugk |
|
4 | + * @copyright Copyright (c) 2015 rugk |
|
5 | + * @license MIT |
|
6 | + */ |
|
7 | 7 | |
8 | 8 | header('Content-Type: text/plain'); |
9 | 9 | |
@@ -31,19 +31,19 @@ discard block |
||
31 | 31 | */ |
32 | 32 | function SendText($connector, $receiverId, $message) |
33 | 33 | { |
34 | - //get private key |
|
35 | - $privateKey = KeyHexToBin(MSGAPI_PRIVATE_KEY); |
|
36 | - |
|
37 | - //send message |
|
38 | - $e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper($privateKey, $connector); |
|
39 | - $result = $e2eHelper->sendTextMessage($receiverId, $message); |
|
40 | - |
|
41 | - //show result |
|
42 | - if(true === $result->isSuccess()) { |
|
43 | - echo 'Message ID: '.$result->getMessageId() . "\n"; |
|
44 | - } else { |
|
45 | - echo 'Error: '.$result->getErrorMessage() . "\n"; |
|
46 | - } |
|
34 | + //get private key |
|
35 | + $privateKey = KeyHexToBin(MSGAPI_PRIVATE_KEY); |
|
36 | + |
|
37 | + //send message |
|
38 | + $e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper($privateKey, $connector); |
|
39 | + $result = $e2eHelper->sendTextMessage($receiverId, $message); |
|
40 | + |
|
41 | + //show result |
|
42 | + if(true === $result->isSuccess()) { |
|
43 | + echo 'Message ID: '.$result->getMessageId() . "\n"; |
|
44 | + } else { |
|
45 | + echo 'Error: '.$result->getErrorMessage() . "\n"; |
|
46 | + } |
|
47 | 47 | |
48 | 48 | } |
49 | 49 |
@@ -39,10 +39,10 @@ |
||
39 | 39 | $result = $e2eHelper->sendTextMessage($receiverId, $message); |
40 | 40 | |
41 | 41 | //show result |
42 | - if(true === $result->isSuccess()) { |
|
43 | - echo 'Message ID: '.$result->getMessageId() . "\n"; |
|
42 | + if (true === $result->isSuccess()) { |
|
43 | + echo 'Message ID: '.$result->getMessageId()."\n"; |
|
44 | 44 | } else { |
45 | - echo 'Error: '.$result->getErrorMessage() . "\n"; |
|
45 | + echo 'Error: '.$result->getErrorMessage()."\n"; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | } |