@@ -2,19 +2,19 @@ discard block |
||
2 | 2 | |
3 | 3 | abstract class AbstractRequest |
4 | 4 | { |
5 | - const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
6 | - const APIURL = 'https://api.go-tellm.com/api'; |
|
7 | - const SECRET = 'plerFToqEdWlzShdZlTywaCHRuzlKIMsNmOJVDGE'; |
|
8 | - const USERAGENT = 'Jodel/4.31.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )'; |
|
9 | - const CLIENT_TYPE = 'android_4.31.1'; |
|
5 | + const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
6 | + const APIURL = 'https://api.go-tellm.com/api'; |
|
7 | + const SECRET = 'plerFToqEdWlzShdZlTywaCHRuzlKIMsNmOJVDGE'; |
|
8 | + const USERAGENT = 'Jodel/4.31.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )'; |
|
9 | + const CLIENT_TYPE = 'android_4.31.1'; |
|
10 | 10 | |
11 | - private $accessToken = null; |
|
12 | - private $payLoad; |
|
13 | - public $expects = ""; |
|
14 | - public $version = 'v2'; |
|
11 | + private $accessToken = null; |
|
12 | + private $payLoad; |
|
13 | + public $expects = ""; |
|
14 | + public $version = 'v2'; |
|
15 | 15 | |
16 | - public function execute() |
|
17 | - { |
|
16 | + public function execute() |
|
17 | + { |
|
18 | 18 | $result = new \stdClass(); |
19 | 19 | |
20 | 20 | $this->payLoad = $this->getPayload(); |
@@ -24,90 +24,90 @@ discard block |
||
24 | 24 | } |
25 | 25 | |
26 | 26 | |
27 | - $this->payLoad = json_encode($this->payLoad); |
|
28 | - $header = $this->getSignHeaders(); |
|
29 | - $url = $this->getFullUrl(); |
|
27 | + $this->payLoad = json_encode($this->payLoad); |
|
28 | + $header = $this->getSignHeaders(); |
|
29 | + $url = $this->getFullUrl(); |
|
30 | 30 | |
31 | - if ($this->getAccessToken()) { |
|
32 | - $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
33 | - } |
|
34 | - //Comment out to debug the Request: |
|
31 | + if ($this->getAccessToken()) { |
|
32 | + $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
33 | + } |
|
34 | + //Comment out to debug the Request: |
|
35 | 35 | |
36 | - /* |
|
36 | + /* |
|
37 | 37 | var_dump($url); |
38 | 38 | var_dump($header); |
39 | 39 | var_dump($this->payLoad); |
40 | 40 | */ |
41 | 41 | |
42 | - $options = array( |
|
43 | - 'timeout' => 100, |
|
44 | - 'connect_timeout' => 100, |
|
45 | - 'proxy' => '186.103.169.165:8080', |
|
46 | - ); |
|
42 | + $options = array( |
|
43 | + 'timeout' => 100, |
|
44 | + 'connect_timeout' => 100, |
|
45 | + 'proxy' => '186.103.169.165:8080', |
|
46 | + ); |
|
47 | 47 | |
48 | - switch ($this->getMethod()) { |
|
49 | - case 'POST': |
|
50 | - $result = Requests::post($url, $header, $this->payLoad, $options); |
|
51 | - break; |
|
52 | - case 'GET': |
|
53 | - if($this->version == 'v3') |
|
54 | - { |
|
55 | - $result = Requests::get($url, $header); |
|
56 | - } |
|
57 | - else |
|
58 | - { |
|
59 | - $result = Requests::get($url, $header); |
|
60 | - } |
|
61 | - break; |
|
62 | - case 'PUT': |
|
63 | - $result = Requests::put($url, $header, $this->payLoad); |
|
64 | - break; |
|
65 | - } |
|
66 | - switch ($result->status_code) { |
|
67 | - case 200: |
|
68 | - $result = json_decode($result->body, true); |
|
69 | - break; |
|
70 | - case 204: |
|
71 | - $result = "Success"; |
|
72 | - break; |
|
73 | - case 401: |
|
48 | + switch ($this->getMethod()) { |
|
49 | + case 'POST': |
|
50 | + $result = Requests::post($url, $header, $this->payLoad, $options); |
|
51 | + break; |
|
52 | + case 'GET': |
|
53 | + if($this->version == 'v3') |
|
54 | + { |
|
55 | + $result = Requests::get($url, $header); |
|
56 | + } |
|
57 | + else |
|
58 | + { |
|
59 | + $result = Requests::get($url, $header); |
|
60 | + } |
|
61 | + break; |
|
62 | + case 'PUT': |
|
63 | + $result = Requests::put($url, $header, $this->payLoad); |
|
64 | + break; |
|
65 | + } |
|
66 | + switch ($result->status_code) { |
|
67 | + case 200: |
|
68 | + $result = json_decode($result->body, true); |
|
69 | + break; |
|
70 | + case 204: |
|
71 | + $result = "Success"; |
|
72 | + break; |
|
73 | + case 401: |
|
74 | 74 | //throw new \Exception('Unauthorized'); |
75 | - break; |
|
76 | - case 404: |
|
77 | - //echo "Es wurde bereits gevoted"; |
|
75 | + break; |
|
76 | + case 404: |
|
77 | + //echo "Es wurde bereits gevoted"; |
|
78 | 78 | case 477: |
79 | - //echo "Es wurde bereits gevoted"; |
|
80 | - //throw new \Exception('Signing failed!'); |
|
81 | - break; |
|
82 | - case 429: |
|
83 | - exit("Error 429: Too Many Requests"); |
|
84 | - break; |
|
85 | - case 403: |
|
86 | - exit("Error 403: Access denied"); |
|
87 | - break; |
|
88 | - default: |
|
89 | - throw new \Exception('Unknown Error: '.$result->status_code); |
|
90 | - } |
|
79 | + //echo "Es wurde bereits gevoted"; |
|
80 | + //throw new \Exception('Signing failed!'); |
|
81 | + break; |
|
82 | + case 429: |
|
83 | + exit("Error 429: Too Many Requests"); |
|
84 | + break; |
|
85 | + case 403: |
|
86 | + exit("Error 403: Access denied"); |
|
87 | + break; |
|
88 | + default: |
|
89 | + throw new \Exception('Unknown Error: '.$result->status_code); |
|
90 | + } |
|
91 | 91 | |
92 | - if($device_uid != "") |
|
93 | - { |
|
92 | + if($device_uid != "") |
|
93 | + { |
|
94 | 94 | $result[0] = $result; |
95 | 95 | $result[1] = $device_uid; |
96 | 96 | } |
97 | 97 | |
98 | 98 | |
99 | - /*var_dump($result);*/ |
|
99 | + /*var_dump($result);*/ |
|
100 | 100 | |
101 | 101 | |
102 | - return $result; |
|
103 | - } |
|
104 | - abstract function getPayload(); |
|
105 | - /** |
|
106 | - * Gets Sign headers |
|
107 | - * @return array headers |
|
108 | - */ |
|
109 | - private function getSignHeaders() |
|
110 | - { |
|
102 | + return $result; |
|
103 | + } |
|
104 | + abstract function getPayload(); |
|
105 | + /** |
|
106 | + * Gets Sign headers |
|
107 | + * @return array headers |
|
108 | + */ |
|
109 | + private function getSignHeaders() |
|
110 | + { |
|
111 | 111 | if($this->getAccessToken() == null) { |
112 | 112 | $payload_accessToken = ""; |
113 | 113 | } |
@@ -116,54 +116,54 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | |
119 | - $headers = array( |
|
120 | - "Connection" => "keep-alive", |
|
121 | - "Accept-Encoding" => "gzip", |
|
122 | - "Content-Type" => "application/json; charset=UTF-8", |
|
123 | - "User-Agent" => self::USERAGENT |
|
124 | - ); |
|
125 | - $timestamp = new DateTime(); |
|
126 | - $timestamp = $timestamp->format(DateTime::ATOM); |
|
127 | - $timestamp = substr($timestamp, 0, -6); |
|
128 | - $timestamp .= "Z"; |
|
129 | - $urlParts = parse_url($this->getFullUrl()); |
|
130 | - $url2 = ""; |
|
131 | - $req = [$this->getMethod(), |
|
132 | - $urlParts['host'], |
|
133 | - "443", |
|
134 | - $urlParts['path'], |
|
135 | - $payload_accessToken, |
|
136 | - $timestamp, |
|
137 | - $url2, |
|
138 | - $this->payLoad]; |
|
139 | - $reqString = implode("%", $req); |
|
140 | - $secret = self::SECRET; |
|
141 | - $signature = hash_hmac('sha1', $reqString, $secret); |
|
142 | - $signature = strtoupper($signature); |
|
143 | - $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
144 | - $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
145 | - $headers['X-Timestamp'] = $timestamp; |
|
146 | - $headers['X-Api-Version'] = '0.2'; |
|
147 | - return $headers; |
|
148 | - } |
|
149 | - private function getFullUrl() |
|
150 | - { |
|
151 | - return self::APIURL . $this->getApiEndPoint(); |
|
152 | - } |
|
153 | - abstract function getApiEndPoint(); |
|
154 | - abstract function getMethod(); |
|
155 | - /** |
|
156 | - * @return string |
|
157 | - */ |
|
158 | - private function getAccessToken() |
|
159 | - { |
|
160 | - return $this->accessToken; |
|
161 | - } |
|
162 | - /** |
|
163 | - * @param string $accessToken |
|
164 | - */ |
|
165 | - public function setAccessToken($accessToken) |
|
166 | - { |
|
167 | - $this->accessToken = $accessToken; |
|
168 | - } |
|
119 | + $headers = array( |
|
120 | + "Connection" => "keep-alive", |
|
121 | + "Accept-Encoding" => "gzip", |
|
122 | + "Content-Type" => "application/json; charset=UTF-8", |
|
123 | + "User-Agent" => self::USERAGENT |
|
124 | + ); |
|
125 | + $timestamp = new DateTime(); |
|
126 | + $timestamp = $timestamp->format(DateTime::ATOM); |
|
127 | + $timestamp = substr($timestamp, 0, -6); |
|
128 | + $timestamp .= "Z"; |
|
129 | + $urlParts = parse_url($this->getFullUrl()); |
|
130 | + $url2 = ""; |
|
131 | + $req = [$this->getMethod(), |
|
132 | + $urlParts['host'], |
|
133 | + "443", |
|
134 | + $urlParts['path'], |
|
135 | + $payload_accessToken, |
|
136 | + $timestamp, |
|
137 | + $url2, |
|
138 | + $this->payLoad]; |
|
139 | + $reqString = implode("%", $req); |
|
140 | + $secret = self::SECRET; |
|
141 | + $signature = hash_hmac('sha1', $reqString, $secret); |
|
142 | + $signature = strtoupper($signature); |
|
143 | + $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
144 | + $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
145 | + $headers['X-Timestamp'] = $timestamp; |
|
146 | + $headers['X-Api-Version'] = '0.2'; |
|
147 | + return $headers; |
|
148 | + } |
|
149 | + private function getFullUrl() |
|
150 | + { |
|
151 | + return self::APIURL . $this->getApiEndPoint(); |
|
152 | + } |
|
153 | + abstract function getApiEndPoint(); |
|
154 | + abstract function getMethod(); |
|
155 | + /** |
|
156 | + * @return string |
|
157 | + */ |
|
158 | + private function getAccessToken() |
|
159 | + { |
|
160 | + return $this->accessToken; |
|
161 | + } |
|
162 | + /** |
|
163 | + * @param string $accessToken |
|
164 | + */ |
|
165 | + public function setAccessToken($accessToken) |
|
166 | + { |
|
167 | + $this->accessToken = $accessToken; |
|
168 | + } |
|
169 | 169 | } |
@@ -3,7 +3,7 @@ |
||
3 | 3 | $config = parse_ini_file('config/config.ini.php'); |
4 | 4 | if(!isset($_GET['pw']) || $config['pw'] != $_GET['pw']) |
5 | 5 | { |
6 | - error_log($_SERVER['REMOTE_ADDR'] . ' used a wrong password on admin.php'); |
|
6 | + error_log($_SERVER['REMOTE_ADDR'] . ' used a wrong password on admin.php'); |
|
7 | 7 | die(); |
8 | 8 | } |
9 | 9 |
@@ -14,8 +14,8 @@ discard block |
||
14 | 14 | if(!isset($_COOKIE["JodelDeviceId"])) |
15 | 15 | { |
16 | 16 | $deviceUid = createAccount(); |
17 | - setcookie('JodelDeviceId', $deviceUid, time()+60*60*24*365*10); |
|
18 | - error_log('Created account with JodelDeviceId:' . $deviceUid . ' for ' . $_SERVER['REMOTE_ADDR']); |
|
17 | + setcookie('JodelDeviceId', $deviceUid, time() + 60 * 60 * 24 * 365 * 10); |
|
18 | + error_log('Created account with JodelDeviceId:' . $deviceUid . ' for ' . $_SERVER['REMOTE_ADDR']); |
|
19 | 19 | |
20 | 20 | } |
21 | 21 | else |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | //Set View |
35 | 35 | if(isset($_GET['view'])) |
36 | 36 | { |
37 | - switch ($_GET['view']) { |
|
37 | + switch($_GET['view']) { |
|
38 | 38 | case 'comment': |
39 | 39 | $view = 'comment'; |
40 | 40 | break; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | if(isset($_POST['color'])) |
127 | 127 | { |
128 | 128 | $color = $_POST['color']; |
129 | - switch ($color) { |
|
129 | + switch($color) { |
|
130 | 130 | case '8ABDB0': |
131 | 131 | $color = '8ABDB0'; |
132 | 132 | break; |
@@ -304,13 +304,13 @@ discard block |
||
304 | 304 | else |
305 | 305 | { |
306 | 306 | $version = 'v2'; |
307 | - if($view=='comment') |
|
307 | + if($view == 'comment') |
|
308 | 308 | { |
309 | 309 | $url = "/v2/posts/location/discussed/"; |
310 | 310 | } |
311 | 311 | else |
312 | 312 | { |
313 | - if($view=='upVote') |
|
313 | + if($view == 'upVote') |
|
314 | 314 | { |
315 | 315 | $url = "/v2/posts/location/popular/"; |
316 | 316 | } |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | } |
335 | 335 | |
336 | 336 | |
337 | - for($i = 0; $i<$loops; $i++) |
|
337 | + for($i = 0; $i < $loops; $i++) |
|
338 | 338 | { |
339 | 339 | if(array_key_exists($i, $posts)) |
340 | 340 | { |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | <?php if(isset($_GET['postID']) && isset($_GET['getPostDetails'])) { ?> |
379 | 379 | <h2>Comment on Jodel</h2> |
380 | 380 | <form method="POST"> |
381 | - <input type="hidden" name="ancestor" value="<?php echo htmlspecialchars($_GET['postID']);?>" /> |
|
381 | + <input type="hidden" name="ancestor" value="<?php echo htmlspecialchars($_GET['postID']); ?>" /> |
|
382 | 382 | <textarea id="message" name="message" placeholder="Send a comment on a Jodel to all students within 10km" required></textarea> |
383 | 383 | <br /> |
384 | 384 | <input type="submit" value="SEND" /> |
@@ -415,13 +415,13 @@ discard block |
||
415 | 415 | <div class="col-sm-12"> |
416 | 416 | <div class="row"> |
417 | 417 | <div class="col-sm-3"> |
418 | - <a href="index.php" <?php if($view=='time') echo 'class="active"';?>><i class="fa fa-clock-o fa-3x"></i></a> |
|
418 | + <a href="index.php" <?php if($view == 'time') echo 'class="active"'; ?>><i class="fa fa-clock-o fa-3x"></i></a> |
|
419 | 419 | </div> |
420 | 420 | <div class="col-sm-3"> |
421 | - <a href="index.php?view=comment" <?php if($view=='comment') echo 'class="active"';?>><i class="fa fa-commenting-o fa-3x"></i></a> |
|
421 | + <a href="index.php?view=comment" <?php if($view == 'comment') echo 'class="active"'; ?>><i class="fa fa-commenting-o fa-3x"></i></a> |
|
422 | 422 | </div> |
423 | 423 | <div class="col-sm-3"> |
424 | - <a href="index.php?view=upVote" <?php if($view=='upVote') echo 'class="active"';?>><i class="fa fa-angle-up fa-3x"></i></a> |
|
424 | + <a href="index.php?view=upVote" <?php if($view == 'upVote') echo 'class="active"'; ?>><i class="fa fa-angle-up fa-3x"></i></a> |
|
425 | 425 | </div> |
426 | 426 | <div class="col-sm-3"> |
427 | 427 | <nav> |