Completed
Pull Request — master (#28)
by rugk
02:50
created
source/Threema/MsgApi/Tools/CryptTool.php 3 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author Threema GmbH
4
- * @copyright Copyright (c) 2015 Threema GmbH
5
- */
3
+	 * @author Threema GmbH
4
+	 * @copyright Copyright (c) 2015 Threema GmbH
5
+	 */
6 6
 
7 7
 
8 8
 namespace Threema\MsgApi\Tools;
Please login to merge, or discard this patch.
Doc Comments   +16 added lines, -4 removed lines patch added patch discarded remove patch
@@ -145,6 +145,11 @@  discard block
 block discarded – undo
145 145
 		return $this->makeBox($message, $nonce, $senderPrivateKey, $recipientPublicKey);
146 146
 	}
147 147
 
148
+	/**
149
+	 * @param string $senderPrivateKey
150
+	 * @param string $recipientPublicKey
151
+	 * @param string $nonce
152
+	 */
148 153
 	final public function encryptFileMessage(UploadFileResult $uploadFileResult,
149 154
 											 EncryptResult $encryptResult,
150 155
 											 UploadFileResult $thumbnailUploadFileResult = null,
@@ -193,9 +198,9 @@  discard block
 block discarded – undo
193 198
 	 * make a secret box
194 199
 	 *
195 200
 	 * @param $data
196
-	 * @param $nonce
201
+	 * @param string $nonce
197 202
 	 * @param $key
198
-	 * @return mixed
203
+	 * @return string
199 204
 	 */
200 205
 	abstract protected function makeSecretBox($data, $nonce, $key);
201 206
 
@@ -337,6 +342,9 @@  discard block
 block discarded – undo
337 342
 		return hash_hmac('sha256', $phoneNoClean, self::PHONENO_HMAC_KEY);
338 343
 	}
339 344
 
345
+	/**
346
+	 * @return string
347
+	 */
340 348
 	abstract protected function createRandom($size);
341 349
 
342 350
 	/**
@@ -379,7 +387,7 @@  discard block
 block discarded – undo
379 387
 	abstract public function validate();
380 388
 
381 389
 	/**
382
-	 * @param $data
390
+	 * @param string $data
383 391
 	 * @return EncryptResult
384 392
 	 */
385 393
 	public final function encryptFile($data) {
@@ -391,7 +399,7 @@  discard block
 block discarded – undo
391 399
 	/**
392 400
 	 * @param string $data as binary
393 401
 	 * @param string $key as binary
394
-	 * @return null|string
402
+	 * @return string
395 403
 	 */
396 404
 	public final function decryptFile($data, $key) {
397 405
 		$result =  $this->openSecretBox($data, self::FILE_NONCE, $key);
@@ -408,6 +416,10 @@  discard block
 block discarded – undo
408 416
 		return new EncryptResult($box, $key,  self::FILE_THUMBNAIL_NONCE, strlen($box));
409 417
 	}
410 418
 
419
+	/**
420
+	 * @param string $data
421
+	 * @param string $key
422
+	 */
411 423
 	public final function decryptFileThumbnail($data, $key) {
412 424
 		$result = $this->openSecretBox($data, self::FILE_THUMBNAIL_NONCE, $key);
413 425
 		return false === $result ? null : $result;
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 	 * @return CryptTool
43 43
 	 */
44 44
 	public static function getInstance() {
45
-		if(null === self::$instance) {
46
-			foreach(array(
45
+		if (null === self::$instance) {
46
+			foreach (array(
47 47
 				function() {
48 48
 					return self::createInstance(self::TYPE_SODIUM);
49 49
 				},
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 					return self::createInstance(self::TYPE_SALT);
52 52
 				}) as $instanceGenerator) {
53 53
 				$i = $instanceGenerator->__invoke();
54
-				if(null !== $i) {
54
+				if (null !== $i) {
55 55
 					self::$instance = $i;
56 56
 					break;
57 57
 				}
@@ -66,18 +66,18 @@  discard block
 block discarded – undo
66 66
 	 * @return null|CryptTool null on unknown type
67 67
 	 */
68 68
 	public static function createInstance($type) {
69
-		switch($type) {
69
+		switch ($type) {
70 70
 			case self::TYPE_SODIUM:
71 71
 				$instance = new CryptToolSodium();
72
-				if(false === $instance->isSupported()) {
72
+				if (false === $instance->isSupported()) {
73 73
 					//try to instance old version of sodium wrapper
74 74
 					/** @noinspection PhpDeprecationInspection */
75 75
 					$instance = new CryptToolSodiumDep();
76 76
 				}
77
-				return $instance->isSupported() ? $instance :null;
77
+				return $instance->isSupported() ? $instance : null;
78 78
 			case self::TYPE_SALT:
79 79
 				$instance = new CryptToolSalt();
80
-				return $instance->isSupported() ? $instance :null;
80
+				return $instance->isSupported() ? $instance : null;
81 81
 			default:
82 82
 				return null;
83 83
 		}
@@ -104,14 +104,14 @@  discard block
 block discarded – undo
104 104
 	 */
105 105
 	final public function encryptMessageText($text, $senderPrivateKey, $recipientPublicKey, $nonce) {
106 106
 		/* prepend type byte (0x01) to message data */
107
-		$textBytes = "\x01" . $text;
107
+		$textBytes = "\x01".$text;
108 108
 
109 109
 		/* determine random amount of PKCS7 padding */
110 110
 		$padbytes = mt_rand(1, 255);
111 111
 
112 112
 		/* append padding */
113 113
 		$padbytes = 0;
114
-		while($padbytes < 1 || $padbytes > 255) {
114
+		while ($padbytes < 1 || $padbytes > 255) {
115 115
 			$padbytes = ord($this->createRandom(1));
116 116
 		}
117 117
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 			$senderPrivateKey,
133 133
 			$recipientPublicKey,
134 134
 			$nonce) {
135
-		$message = "\x02" . hex2bin($uploadFileResult->getBlobId());
135
+		$message = "\x02".hex2bin($uploadFileResult->getBlobId());
136 136
 		$message .= pack('V', $encryptResult->getSize());
137 137
 		$message .= $encryptResult->getNonce();
138 138
 
@@ -163,11 +163,11 @@  discard block
 block discarded – undo
163 163
 			'i' => 0
164 164
 		);
165 165
 
166
-		if($thumbnailUploadFileResult != null && strlen($thumbnailUploadFileResult->getBlobId()) > 0) {
166
+		if ($thumbnailUploadFileResult != null && strlen($thumbnailUploadFileResult->getBlobId()) > 0) {
167 167
 			$messageContent['t'] = $thumbnailUploadFileResult->getBlobId();
168 168
 		}
169 169
 
170
-		$message = "\x17" . json_encode($messageContent);
170
+		$message = "\x17".json_encode($messageContent);
171 171
 
172 172
 		/* determine random amount of PKCS7 padding */
173 173
 		$padbytes = mt_rand(1, 255);
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 
241 241
 		/* remove padding */
242 242
 		$padbytes = ord($data[strlen($data)-1]);
243
-		$realDataLength = strlen($data) - $padbytes;
243
+		$realDataLength = strlen($data)-$padbytes;
244 244
 		if ($realDataLength < 1) {
245 245
 			throw new BadMessageException();
246 246
 		}
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 				return new TextMessage(substr($data, 1));
267 267
 			case DeliveryReceipt::TYPE_CODE:
268 268
 				/* Delivery receipt */
269
-				if ($realDataLength < (self::MESSAGE_ID_LEN-2) || (($realDataLength - 2) % self::MESSAGE_ID_LEN) != 0)  {
269
+				if ($realDataLength < (self::MESSAGE_ID_LEN-2) || (($realDataLength-2)%self::MESSAGE_ID_LEN) != 0) {
270 270
 					throw new BadMessageException();
271 271
 				}
272 272
 
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 				return new DeliveryReceipt($receiptType, $messageIds);
277 277
 			case ImageMessage::TYPE_CODE:
278 278
 				/* Image Message */
279
-				if ($realDataLength != 1 + self::BLOB_ID_LEN + self::IMAGE_FILE_SIZE_LEN + self::IMAGE_NONCE_LEN)  {
279
+				if ($realDataLength != 1+self::BLOB_ID_LEN+self::IMAGE_FILE_SIZE_LEN+self::IMAGE_NONCE_LEN) {
280 280
 					throw new BadMessageException();
281 281
 				}
282 282
 
@@ -287,12 +287,12 @@  discard block
 block discarded – undo
287 287
 			case FileMessage::TYPE_CODE:
288 288
 				/* Image Message */
289 289
 				$decodeResult = json_decode(substr($data, 1), true);
290
-				if(null === $decodeResult || false === $decodeResult) {
290
+				if (null === $decodeResult || false === $decodeResult) {
291 291
 					throw new BadMessageException();
292 292
 				}
293 293
 
294 294
 				$values = AssocArray::byJsonString(substr($data, 1), array('b', 't', 'k', 'm', 'n', 's'));
295
-				if(null === $values) {
295
+				if (null === $values) {
296 296
 					throw new BadMessageException();
297 297
 				}
298 298
 
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
 	 * @return null|string
395 395
 	 */
396 396
 	public final function decryptFile($data, $key) {
397
-		$result =  $this->openSecretBox($data, self::FILE_NONCE, $key);
397
+		$result = $this->openSecretBox($data, self::FILE_NONCE, $key);
398 398
 		return false === $result ? null : $result;
399 399
 	}
400 400
 
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
 	 */
406 406
 	public final function encryptFileThumbnail($data, $key) {
407 407
 		$box = $this->makeSecretBox($data, self::FILE_THUMBNAIL_NONCE, $key);
408
-		return new EncryptResult($box, $key,  self::FILE_THUMBNAIL_NONCE, strlen($box));
408
+		return new EncryptResult($box, $key, self::FILE_THUMBNAIL_NONCE, strlen($box));
409 409
 	}
410 410
 
411 411
 	public final function decryptFileThumbnail($data, $key) {
Please login to merge, or discard this patch.
source/Threema/MsgApi/Tools/CryptToolSodium.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author Threema GmbH
4
- * @copyright Copyright (c) 2015 Threema GmbH
5
- */
3
+	 * @author Threema GmbH
4
+	 * @copyright Copyright (c) 2015 Threema GmbH
5
+	 */
6 6
 
7 7
 
8 8
 namespace Threema\MsgApi\Tools;
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -124,7 +124,7 @@
 block discarded – undo
124 124
 	 * @throws Exception
125 125
 	 */
126 126
 	public function validate() {
127
-		if(false === $this->isSupported()) {
127
+		if (false === $this->isSupported()) {
128 128
 			throw new Exception('Sodium implementation not supported');
129 129
 		}
130 130
 		return true;
Please login to merge, or discard this patch.
source/Threema/MsgApi/Tools/EncryptResult.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author Threema GmbH
4
- * @copyright Copyright (c) 2015 Threema GmbH
5
- */
3
+	 * @author Threema GmbH
4
+	 * @copyright Copyright (c) 2015 Threema GmbH
5
+	 */
6 6
 
7 7
 
8 8
 namespace Threema\MsgApi\Tools;
Please login to merge, or discard this patch.
source/Threema/MsgApi/Tools/FileAnalysisResult.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author Threema GmbH
4
- * @copyright Copyright (c) 2015 Threema GmbH
5
- */
3
+	 * @author Threema GmbH
4
+	 * @copyright Copyright (c) 2015 Threema GmbH
5
+	 */
6 6
 
7 7
 
8 8
 namespace Threema\MsgApi\Tools;
Please login to merge, or discard this patch.
samples/web/include/Connection.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
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
 {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
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);
Please login to merge, or discard this patch.
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
20 20
  */
21 21
 function CreateConnection($keystorePath='../../keystore.php', $useTlsOptions=true)
22 22
 {
23
-    $publicKeyStore = CreatePublicKeyStore($keystorePath);
24
-    $settings = CreateConnectionSettings($useTlsOptions);
25
-    $connector = InitiateConnection($settings, $publicKeyStore);
23
+	$publicKeyStore = CreatePublicKeyStore($keystorePath);
24
+	$settings = CreateConnectionSettings($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
 block discarded – undo
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 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 new Threema\MsgApi\PublicKeyStores\PhpFile($keystorePath);
45 45
 }
46 46
 
47 47
 /**
@@ -53,27 +53,27 @@  discard block
 block discarded – undo
53 53
  */
54 54
 function CreateConnectionSettings($useTlsOptions)
55 55
 {
56
-    if ($useTlsOptions == true) {
57
-        //create a connection with advanced options
58
-        $settings = new ConnectionSettings(
59
-            MSGAPI_GATEWAY_THREEMA_ID,
60
-            MSGAPI_GATEWAY_THREEMA_ID_SECRET,
61
-            null,
62
-            [
63
-                'forceHttps' => true,
64
-                'tlsVersion' => '1.2',
65
-                'tlsCipher' => 'ECDHE-RSA-AES128-GCM-SHA256'
66
-            ]
67
-        );
68
-    } else {
69
-        //create a connection with default options
70
-        $settings = new ConnectionSettings(
71
-            MSGAPI_GATEWAY_THREEMA_ID,
72
-            MSGAPI_GATEWAY_THREEMA_ID_SECRET
73
-        );
74
-    }
56
+	if ($useTlsOptions == true) {
57
+		//create a connection with advanced options
58
+		$settings = new ConnectionSettings(
59
+			MSGAPI_GATEWAY_THREEMA_ID,
60
+			MSGAPI_GATEWAY_THREEMA_ID_SECRET,
61
+			null,
62
+			[
63
+				'forceHttps' => true,
64
+				'tlsVersion' => '1.2',
65
+				'tlsCipher' => 'ECDHE-RSA-AES128-GCM-SHA256'
66
+			]
67
+		);
68
+	} else {
69
+		//create a connection with default options
70
+		$settings = new ConnectionSettings(
71
+			MSGAPI_GATEWAY_THREEMA_ID,
72
+			MSGAPI_GATEWAY_THREEMA_ID_SECRET
73
+		);
74
+	}
75 75
 
76
-    return $settings;
76
+	return $settings;
77 77
 }
78 78
 
79 79
 /**
@@ -86,5 +86,5 @@  discard block
 block discarded – undo
86 86
  */
87 87
 function InitiateConnection($settings, $publicKeyStore)
88 88
 {
89
-    return new Connection($settings, $publicKeyStore);
89
+	return new Connection($settings, $publicKeyStore);
90 90
 }
Please login to merge, or discard this patch.
samples/web/SendTextMessage.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
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
 {
Please login to merge, or discard this patch.
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
samples/web/include/GetPost.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
samples/web/include/GlobalConstants.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@
 block discarded – undo
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';
Please login to merge, or discard this patch.
samples/web/index.php 3 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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">
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -132,7 +132,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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>
Please login to merge, or discard this patch.
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@  discard block
 block discarded – undo
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,87 +18,87 @@  discard block
 block discarded – undo
18 18
 /* SOME SMALL FUNCTIONS */
19 19
 function ShowDefaultReceiverId($addOptionsHtmlCode = false)
20 20
 {
21
-    $isShown = ReturnGetPost('threemaid') != null || ReturnGetPost('recieverid')
22
-    != null || MSGAPI_DEFAULTRECEIVER <> '';
23
-
24
-    // Show previous input if there is something
25
-    if ($isShown && $addOptionsHtmlCode) {
26
-        echo '<option value="';
27
-    }
28
-
29
-    if (ReturnGetPost('threemaid') != null) {
30
-        echo htmlentities(ReturnGetPost('threemaid'));
31
-    } elseif (ReturnGetPost('recieverid') != null) {
32
-        echo htmlentities(ReturnGetPost('recieverid'));
33
-    } elseif (MSGAPI_DEFAULTRECEIVER <> '') {
34
-        // use receiver in config
35
-        echo MSGAPI_DEFAULTRECEIVER;
36
-    }
37
-
38
-    if ($isShown && $addOptionsHtmlCode) {
39
-        echo '">';
40
-    }
21
+	$isShown = ReturnGetPost('threemaid') != null || ReturnGetPost('recieverid')
22
+	!= null || MSGAPI_DEFAULTRECEIVER <> '';
23
+
24
+	// Show previous input if there is something
25
+	if ($isShown && $addOptionsHtmlCode) {
26
+		echo '<option value="';
27
+	}
28
+
29
+	if (ReturnGetPost('threemaid') != null) {
30
+		echo htmlentities(ReturnGetPost('threemaid'));
31
+	} elseif (ReturnGetPost('recieverid') != null) {
32
+		echo htmlentities(ReturnGetPost('recieverid'));
33
+	} elseif (MSGAPI_DEFAULTRECEIVER <> '') {
34
+		// use receiver in config
35
+		echo MSGAPI_DEFAULTRECEIVER;
36
+	}
37
+
38
+	if ($isShown && $addOptionsHtmlCode) {
39
+		echo '">';
40
+	}
41 41
 }
42 42
 
43 43
 function ShowDefaultMessage()
44 44
 {
45
-    // Show previous input if there is something
46
-    if (ReturnGetPost('message') != null) {
47
-        echo htmlentities(ReturnGetPost('message'));
48
-    }
45
+	// Show previous input if there is something
46
+	if (ReturnGetPost('message') != null) {
47
+		echo htmlentities(ReturnGetPost('message'));
48
+	}
49 49
 }
50 50
 
51 51
 /* CHECK PREREQUISITES */
52 52
 $fileConnCredentErr = '';
53 53
 if (!file_exists(FILENAME_CONNCRED)) {
54
-    $fileConnCredentErr .= ' The file does not exist.';
54
+	$fileConnCredentErr .= ' The file does not exist.';
55 55
 } else {
56
-    require_once FILENAME_CONNCRED;
57
-    if (!defined('MSGAPI_GATEWAY_THREEMA_ID') ||
58
-        !defined('MSGAPI_GATEWAY_THREEMA_ID_SECRET')
59
-    ) {
60
-        $fileConnCredentErr .= ' Not all required constants are defined.';
61
-    } else {
62
-        if (MSGAPI_GATEWAY_THREEMA_ID == '' ||
63
-            !preg_match('/' . REGEXP_THREEMAID_GATEWAY . '/', MSGAPI_GATEWAY_THREEMA_ID)
64
-        ) {
65
-            $fileConnCredentErr .= ' \'MSGAPI_GATEWAY_THREEMA_ID\' is invalid.';
66
-        }
67
-
68
-        if (MSGAPI_GATEWAY_THREEMA_ID_SECRET == '' ||
69
-            !ctype_alnum(MSGAPI_GATEWAY_THREEMA_ID_SECRET)
70
-        ) {
71
-            $fileConnCredentErr .= ' \'MSGAPI_GATEWAY_THREEMA_ID_SECRET\' is invalid.';
72
-        }
73
-
74
-        // MSGAPI_DEFAULTRECEIVER is optional
75
-        if (!defined('MSGAPI_DEFAULTRECEIVER')) {
76
-            define('MSGAPI_DEFAULTRECEIVER', '');
77
-        }
78
-
79
-        if (MSGAPI_DEFAULTRECEIVER <> '' &&
80
-            !preg_match('/' . REGEXP_THREEMAID_ANY . '/', MSGAPI_DEFAULTRECEIVER)
81
-        ) {
82
-            $fileConnCredentErr .= ' \'MSGAPI_DEFAULTRECEIVER\' is invalid.';
83
-        }
84
-    }
56
+	require_once FILENAME_CONNCRED;
57
+	if (!defined('MSGAPI_GATEWAY_THREEMA_ID') ||
58
+		!defined('MSGAPI_GATEWAY_THREEMA_ID_SECRET')
59
+	) {
60
+		$fileConnCredentErr .= ' Not all required constants are defined.';
61
+	} else {
62
+		if (MSGAPI_GATEWAY_THREEMA_ID == '' ||
63
+			!preg_match('/' . REGEXP_THREEMAID_GATEWAY . '/', MSGAPI_GATEWAY_THREEMA_ID)
64
+		) {
65
+			$fileConnCredentErr .= ' \'MSGAPI_GATEWAY_THREEMA_ID\' is invalid.';
66
+		}
67
+
68
+		if (MSGAPI_GATEWAY_THREEMA_ID_SECRET == '' ||
69
+			!ctype_alnum(MSGAPI_GATEWAY_THREEMA_ID_SECRET)
70
+		) {
71
+			$fileConnCredentErr .= ' \'MSGAPI_GATEWAY_THREEMA_ID_SECRET\' is invalid.';
72
+		}
73
+
74
+		// MSGAPI_DEFAULTRECEIVER is optional
75
+		if (!defined('MSGAPI_DEFAULTRECEIVER')) {
76
+			define('MSGAPI_DEFAULTRECEIVER', '');
77
+		}
78
+
79
+		if (MSGAPI_DEFAULTRECEIVER <> '' &&
80
+			!preg_match('/' . REGEXP_THREEMAID_ANY . '/', MSGAPI_DEFAULTRECEIVER)
81
+		) {
82
+			$fileConnCredentErr .= ' \'MSGAPI_DEFAULTRECEIVER\' is invalid.';
83
+		}
84
+	}
85 85
 }
86 86
 
87 87
 
88 88
 $fileChkPrivateKeyErr = '';
89 89
 if (!file_exists(FILENAME_PRIVKEY)) {
90
-    $fileChkPrivateKeyErr .= ' The file does not exist.';
90
+	$fileChkPrivateKeyErr .= ' The file does not exist.';
91 91
 } else {
92
-    require_once FILENAME_PRIVKEY;
93
-    if (!defined('MSGAPI_PRIVATE_KEY')) {
94
-        $fileChkPrivateKeyErr .= ' Not all constants are defined.';
95
-    } else {
96
-        if (MSGAPI_PRIVATE_KEY == '' ||
97
-            !KeyCheck(MSGAPI_PRIVATE_KEY, 'private:')
98
-        ) {
99
-            $fileChkPrivateKeyErr .= ' \'MSGAPI_PRIVATE_KEY\' is invalid.';
100
-        }
101
-    }
92
+	require_once FILENAME_PRIVKEY;
93
+	if (!defined('MSGAPI_PRIVATE_KEY')) {
94
+		$fileChkPrivateKeyErr .= ' Not all constants are defined.';
95
+	} else {
96
+		if (MSGAPI_PRIVATE_KEY == '' ||
97
+			!KeyCheck(MSGAPI_PRIVATE_KEY, 'private:')
98
+		) {
99
+			$fileChkPrivateKeyErr .= ' \'MSGAPI_PRIVATE_KEY\' is invalid.';
100
+		}
101
+	}
102 102
 }
103 103
 ?>
104 104
 -->
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
     </head>
113 113
     <body>
114 114
         <?php
115
-        // only shows content when it is not parsed by a PHP interpreter
116
-        if (false):
117
-        ?>
115
+		// only shows content when it is not parsed by a PHP interpreter
116
+		if (false):
117
+		?>
118 118
         <!-- PHP parsing error message -->
119 119
         <div class="warning">
120 120
             You are viewing this file within a browser. However you do need to call this file
@@ -122,8 +122,8 @@  discard block
 block discarded – undo
122 122
             PHP support and access the file like this: <code>http://127.0.0.1/threema-msgapi-sdk-php/samples/web/</code>.
123 123
         </div>
124 124
         <?php
125
-        endif
126
-        ?>
125
+		endif
126
+		?>
127 127
 
128 128
         <h1 id="devui">Development UI - MSGAPI-PHP-SDK - Threema Gateway</h1>
129 129
         <p>
Please login to merge, or discard this patch.