@@ -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 | } |