@@ -2,20 +2,20 @@ 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 = 'LDWWpuUigOnKCbCLpoNMDHCqHCWbLKPzHbnIUKIf'; |
|
| 8 | - const USERAGENT = 'Jodel/4.33.2 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )'; |
|
| 9 | - const CLIENT_TYPE = 'android_4.33.2'; |
|
| 5 | + const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
| 6 | + const APIURL = 'https://api.go-tellm.com/api'; |
|
| 7 | + const SECRET = 'LDWWpuUigOnKCbCLpoNMDHCqHCWbLKPzHbnIUKIf'; |
|
| 8 | + const USERAGENT = 'Jodel/4.33.2 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )'; |
|
| 9 | + const CLIENT_TYPE = 'android_4.33.2'; |
|
| 10 | 10 | |
| 11 | - private $accessToken = null; |
|
| 12 | - private $payLoad; |
|
| 13 | - public $expects = ''; |
|
| 14 | - public $version = 'v2'; |
|
| 15 | - public $hasPayload = FALSE; |
|
| 11 | + private $accessToken = null; |
|
| 12 | + private $payLoad; |
|
| 13 | + public $expects = ''; |
|
| 14 | + public $version = 'v2'; |
|
| 15 | + public $hasPayload = FALSE; |
|
| 16 | 16 | |
| 17 | - public function execute() |
|
| 18 | - { |
|
| 17 | + public function execute() |
|
| 18 | + { |
|
| 19 | 19 | $result = new \stdClass(); |
| 20 | 20 | |
| 21 | 21 | $this->payLoad = $this->getPayload(); |
@@ -25,16 +25,16 @@ discard block |
||
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - $this->payLoad = json_encode($this->payLoad); |
|
| 29 | - $header = $this->getSignHeaders(); |
|
| 30 | - $url = $this->getFullUrl(); |
|
| 28 | + $this->payLoad = json_encode($this->payLoad); |
|
| 29 | + $header = $this->getSignHeaders(); |
|
| 30 | + $url = $this->getFullUrl(); |
|
| 31 | 31 | |
| 32 | - if ($this->getAccessToken()) { |
|
| 33 | - $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
| 34 | - } |
|
| 35 | - //Comment out to debug the Request: |
|
| 32 | + if ($this->getAccessToken()) { |
|
| 33 | + $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
|
| 34 | + } |
|
| 35 | + //Comment out to debug the Request: |
|
| 36 | 36 | |
| 37 | - /* |
|
| 37 | + /* |
|
| 38 | 38 | printf("URL: "); |
| 39 | 39 | var_dump($url); |
| 40 | 40 | echo "<br />"; |
@@ -45,88 +45,88 @@ discard block |
||
| 45 | 45 | var_dump($this->payLoad); |
| 46 | 46 | echo "<br />"; |
| 47 | 47 | */ |
| 48 | - /* |
|
| 48 | + /* |
|
| 49 | 49 | $options = array( |
| 50 | 50 | 'timeout' => 100, |
| 51 | 51 | 'connect_timeout' => 100, |
| 52 | 52 | 'proxy' => '186.103.169.165:8080', |
| 53 | 53 | );*/ |
| 54 | 54 | |
| 55 | - switch ($this->getMethod()) { |
|
| 56 | - case 'POST': |
|
| 57 | - $result = Requests::post($url, $header, $this->payLoad); |
|
| 58 | - break; |
|
| 59 | - case 'GET': |
|
| 60 | - if($this->hasPayload) |
|
| 61 | - { |
|
| 62 | - $result = Requests::get($url, $header, $this->payLoad); |
|
| 63 | - } |
|
| 64 | - else |
|
| 65 | - { |
|
| 66 | - $result = Requests::get($url, $header); |
|
| 67 | - } |
|
| 68 | - break; |
|
| 69 | - case 'PUT': |
|
| 70 | - $result = Requests::put($url, $header, $this->payLoad); |
|
| 71 | - break; |
|
| 72 | - } |
|
| 73 | - switch ($result->status_code) { |
|
| 74 | - case 200: |
|
| 75 | - $result = json_decode($result->body, true); |
|
| 76 | - break; |
|
| 77 | - case 204: |
|
| 78 | - $result = "Success"; |
|
| 79 | - break; |
|
| 80 | - case 400: |
|
| 81 | - //throw new \Exception('Unauthorized'); |
|
| 82 | - error_log('Error 400 - Fehlerhafte Anfrage'); // - JodelDeviceId:' . $deviceUid); |
|
| 83 | - break; |
|
| 84 | - case 401: |
|
| 55 | + switch ($this->getMethod()) { |
|
| 56 | + case 'POST': |
|
| 57 | + $result = Requests::post($url, $header, $this->payLoad); |
|
| 58 | + break; |
|
| 59 | + case 'GET': |
|
| 60 | + if($this->hasPayload) |
|
| 61 | + { |
|
| 62 | + $result = Requests::get($url, $header, $this->payLoad); |
|
| 63 | + } |
|
| 64 | + else |
|
| 65 | + { |
|
| 66 | + $result = Requests::get($url, $header); |
|
| 67 | + } |
|
| 68 | + break; |
|
| 69 | + case 'PUT': |
|
| 70 | + $result = Requests::put($url, $header, $this->payLoad); |
|
| 71 | + break; |
|
| 72 | + } |
|
| 73 | + switch ($result->status_code) { |
|
| 74 | + case 200: |
|
| 75 | + $result = json_decode($result->body, true); |
|
| 76 | + break; |
|
| 77 | + case 204: |
|
| 78 | + $result = "Success"; |
|
| 79 | + break; |
|
| 80 | + case 400: |
|
| 81 | + //throw new \Exception('Unauthorized'); |
|
| 82 | + error_log('Error 400 - Fehlerhafte Anfrage'); // - JodelDeviceId:' . $deviceUid); |
|
| 83 | + break; |
|
| 84 | + case 401: |
|
| 85 | 85 | //throw new \Exception('Unauthorized'); |
| 86 | - error_log(print_r($header, true)); |
|
| 87 | - error_log('Error 401 - Unauthorized'); // - JodelDeviceId:' . $deviceUid); |
|
| 88 | - error_log(print_r($result, true)); |
|
| 89 | - break; |
|
| 90 | - case 404: |
|
| 91 | - //echo "Es wurde bereits gevoted"; |
|
| 92 | - error_log('Error 404 - Es wurde bereits gevoted'); // - JodelDeviceId:' . $deviceUid); |
|
| 86 | + error_log(print_r($header, true)); |
|
| 87 | + error_log('Error 401 - Unauthorized'); // - JodelDeviceId:' . $deviceUid); |
|
| 88 | + error_log(print_r($result, true)); |
|
| 89 | + break; |
|
| 90 | + case 404: |
|
| 91 | + //echo "Es wurde bereits gevoted"; |
|
| 92 | + error_log('Error 404 - Es wurde bereits gevoted'); // - JodelDeviceId:' . $deviceUid); |
|
| 93 | 93 | case 477: |
| 94 | - //echo "Es wurde bereits gevoted"; |
|
| 95 | - //throw new \Exception('Signing failed!'); |
|
| 96 | - error_log('Error 477 - Signing failed'); // - JodelDeviceId:' . $deviceUid); |
|
| 97 | - break; |
|
| 98 | - case 429: |
|
| 99 | - error_log('Error 429 - Too Many Requests'); // - JodelDeviceId:' . $deviceUid); |
|
| 100 | - exit("Error 429: Too Many Requests"); |
|
| 101 | - break; |
|
| 102 | - case 403: |
|
| 103 | - error_log('Error 403 - Access denied'); // - JodelDeviceId:' . $deviceUid); |
|
| 104 | - exit("Error 403: Access denied"); |
|
| 105 | - break; |
|
| 106 | - default: |
|
| 107 | - error_log('Error '.$result->status_code.' - Unauthorized'); // - JodelDeviceId:' . $deviceUid); |
|
| 108 | - //throw new \Exception('Unknown Error: '.$result->status_code); |
|
| 109 | - } |
|
| 94 | + //echo "Es wurde bereits gevoted"; |
|
| 95 | + //throw new \Exception('Signing failed!'); |
|
| 96 | + error_log('Error 477 - Signing failed'); // - JodelDeviceId:' . $deviceUid); |
|
| 97 | + break; |
|
| 98 | + case 429: |
|
| 99 | + error_log('Error 429 - Too Many Requests'); // - JodelDeviceId:' . $deviceUid); |
|
| 100 | + exit("Error 429: Too Many Requests"); |
|
| 101 | + break; |
|
| 102 | + case 403: |
|
| 103 | + error_log('Error 403 - Access denied'); // - JodelDeviceId:' . $deviceUid); |
|
| 104 | + exit("Error 403: Access denied"); |
|
| 105 | + break; |
|
| 106 | + default: |
|
| 107 | + error_log('Error '.$result->status_code.' - Unauthorized'); // - JodelDeviceId:' . $deviceUid); |
|
| 108 | + //throw new \Exception('Unknown Error: '.$result->status_code); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - if($device_uid != '') |
|
| 112 | - { |
|
| 111 | + if($device_uid != '') |
|
| 112 | + { |
|
| 113 | 113 | $result[0] = $result; |
| 114 | 114 | $result[1] = $device_uid; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - /* |
|
| 117 | + /* |
|
| 118 | 118 | var_dump($result); |
| 119 | 119 | */ |
| 120 | 120 | |
| 121 | - return $result; |
|
| 122 | - } |
|
| 123 | - abstract function getPayload(); |
|
| 124 | - /** |
|
| 125 | - * Gets Sign headers |
|
| 126 | - * @return array headers |
|
| 127 | - */ |
|
| 128 | - private function getSignHeaders() |
|
| 129 | - { |
|
| 121 | + return $result; |
|
| 122 | + } |
|
| 123 | + abstract function getPayload(); |
|
| 124 | + /** |
|
| 125 | + * Gets Sign headers |
|
| 126 | + * @return array headers |
|
| 127 | + */ |
|
| 128 | + private function getSignHeaders() |
|
| 129 | + { |
|
| 130 | 130 | if($this->getAccessToken() == null) { |
| 131 | 131 | $payload_accessToken = ""; |
| 132 | 132 | } |
@@ -135,54 +135,54 @@ discard block |
||
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
| 138 | - $headers = array( |
|
| 139 | - "Connection" => "keep-alive", |
|
| 140 | - "Accept-Encoding" => "gzip", |
|
| 141 | - "Content-Type" => "application/json; charset=UTF-8", |
|
| 142 | - "User-Agent" => self::USERAGENT |
|
| 143 | - ); |
|
| 144 | - $timestamp = new DateTime(); |
|
| 145 | - $timestamp = $timestamp->format(DateTime::ATOM); |
|
| 146 | - $timestamp = substr($timestamp, 0, -6); |
|
| 147 | - $timestamp .= "Z"; |
|
| 148 | - $urlParts = parse_url($this->getFullUrl()); |
|
| 149 | - $url2 = ""; |
|
| 150 | - $req = [$this->getMethod(), |
|
| 151 | - $urlParts['host'], |
|
| 152 | - "443", |
|
| 153 | - $urlParts['path'], |
|
| 154 | - $payload_accessToken, |
|
| 155 | - $timestamp, |
|
| 156 | - $url2, |
|
| 157 | - $this->payLoad]; |
|
| 158 | - $reqString = implode("%", $req); |
|
| 159 | - $secret = self::SECRET; |
|
| 160 | - $signature = hash_hmac('sha1', $reqString, $secret); |
|
| 161 | - $signature = strtoupper($signature); |
|
| 162 | - $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
| 163 | - $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
| 164 | - $headers['X-Timestamp'] = $timestamp; |
|
| 165 | - $headers['X-Api-Version'] = '0.2'; |
|
| 166 | - return $headers; |
|
| 167 | - } |
|
| 168 | - private function getFullUrl() |
|
| 169 | - { |
|
| 170 | - return self::APIURL . $this->getApiEndPoint(); |
|
| 171 | - } |
|
| 172 | - abstract function getApiEndPoint(); |
|
| 173 | - abstract function getMethod(); |
|
| 174 | - /** |
|
| 175 | - * @return string |
|
| 176 | - */ |
|
| 177 | - private function getAccessToken() |
|
| 178 | - { |
|
| 179 | - return $this->accessToken; |
|
| 180 | - } |
|
| 181 | - /** |
|
| 182 | - * @param string $accessToken |
|
| 183 | - */ |
|
| 184 | - public function setAccessToken($accessToken) |
|
| 185 | - { |
|
| 186 | - $this->accessToken = $accessToken; |
|
| 187 | - } |
|
| 138 | + $headers = array( |
|
| 139 | + "Connection" => "keep-alive", |
|
| 140 | + "Accept-Encoding" => "gzip", |
|
| 141 | + "Content-Type" => "application/json; charset=UTF-8", |
|
| 142 | + "User-Agent" => self::USERAGENT |
|
| 143 | + ); |
|
| 144 | + $timestamp = new DateTime(); |
|
| 145 | + $timestamp = $timestamp->format(DateTime::ATOM); |
|
| 146 | + $timestamp = substr($timestamp, 0, -6); |
|
| 147 | + $timestamp .= "Z"; |
|
| 148 | + $urlParts = parse_url($this->getFullUrl()); |
|
| 149 | + $url2 = ""; |
|
| 150 | + $req = [$this->getMethod(), |
|
| 151 | + $urlParts['host'], |
|
| 152 | + "443", |
|
| 153 | + $urlParts['path'], |
|
| 154 | + $payload_accessToken, |
|
| 155 | + $timestamp, |
|
| 156 | + $url2, |
|
| 157 | + $this->payLoad]; |
|
| 158 | + $reqString = implode("%", $req); |
|
| 159 | + $secret = self::SECRET; |
|
| 160 | + $signature = hash_hmac('sha1', $reqString, $secret); |
|
| 161 | + $signature = strtoupper($signature); |
|
| 162 | + $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
| 163 | + $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
| 164 | + $headers['X-Timestamp'] = $timestamp; |
|
| 165 | + $headers['X-Api-Version'] = '0.2'; |
|
| 166 | + return $headers; |
|
| 167 | + } |
|
| 168 | + private function getFullUrl() |
|
| 169 | + { |
|
| 170 | + return self::APIURL . $this->getApiEndPoint(); |
|
| 171 | + } |
|
| 172 | + abstract function getApiEndPoint(); |
|
| 173 | + abstract function getMethod(); |
|
| 174 | + /** |
|
| 175 | + * @return string |
|
| 176 | + */ |
|
| 177 | + private function getAccessToken() |
|
| 178 | + { |
|
| 179 | + return $this->accessToken; |
|
| 180 | + } |
|
| 181 | + /** |
|
| 182 | + * @param string $accessToken |
|
| 183 | + */ |
|
| 184 | + public function setAccessToken($accessToken) |
|
| 185 | + { |
|
| 186 | + $this->accessToken = $accessToken; |
|
| 187 | + } |
|
| 188 | 188 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | const USERAGENT = 'Jodel/4.33.2 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )'; |
| 9 | 9 | const CLIENT_TYPE = 'android_4.33.2'; |
| 10 | 10 | |
| 11 | - private $accessToken = null; |
|
| 11 | + private $accessToken = NULL; |
|
| 12 | 12 | private $payLoad; |
| 13 | 13 | public $expects = ''; |
| 14 | 14 | public $version = 'v2'; |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | switch ($result->status_code) { |
| 74 | 74 | case 200: |
| 75 | - $result = json_decode($result->body, true); |
|
| 75 | + $result = json_decode($result->body, TRUE); |
|
| 76 | 76 | break; |
| 77 | 77 | case 204: |
| 78 | 78 | $result = "Success"; |
@@ -83,9 +83,9 @@ discard block |
||
| 83 | 83 | break; |
| 84 | 84 | case 401: |
| 85 | 85 | //throw new \Exception('Unauthorized'); |
| 86 | - error_log(print_r($header, true)); |
|
| 86 | + error_log(print_r($header, TRUE)); |
|
| 87 | 87 | error_log('Error 401 - Unauthorized'); // - JodelDeviceId:' . $deviceUid); |
| 88 | - error_log(print_r($result, true)); |
|
| 88 | + error_log(print_r($result, TRUE)); |
|
| 89 | 89 | break; |
| 90 | 90 | case 404: |
| 91 | 91 | //echo "Es wurde bereits gevoted"; |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | private function getSignHeaders() |
| 129 | 129 | { |
| 130 | - if($this->getAccessToken() == null) { |
|
| 130 | + if($this->getAccessToken() == NULL) { |
|
| 131 | 131 | $payload_accessToken = ""; |
| 132 | 132 | } |
| 133 | 133 | else { |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | function user_log($msg) |
| 41 | 41 | { |
| 42 | - $log = $msg . PHP_EOL; |
|
| 42 | + $log = $msg . PHP_EOL; |
|
| 43 | 43 | file_put_contents(realpath(__DIR__ . '/..') . '/logs/user_log-' . date("j.n.Y") . '.txt', $log, FILE_APPEND); |
| 44 | 44 | } |
| 45 | 45 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | { |
| 48 | 48 | preg_match('/bot|spider|google|twitter/i', $_SERVER['HTTP_USER_AGENT'], $matches); |
| 49 | 49 | |
| 50 | - return (isset($matches[0])) ? true : false; |
|
| 50 | + return (isset($matches[0]))?true : false; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | function configPropertyExists($config, $property) |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | function isUserAdmin() { |
| 65 | 65 | global $config; |
| 66 | - if (isset($_COOKIE['JodelAdminPassword']) && configPropertyExists($config, 'pw') && $config['pw'] == $_COOKIE['JodelAdminPassword']) |
|
| 66 | + if(isset($_COOKIE['JodelAdminPassword']) && configPropertyExists($config, 'pw') && $config['pw'] == $_COOKIE['JodelAdminPassword']) |
|
| 67 | 67 | { |
| 68 | 68 | return TRUE; |
| 69 | 69 | } |
@@ -76,9 +76,9 @@ discard block |
||
| 76 | 76 | function isDeviceUidInDatabase($deviceUid) |
| 77 | 77 | { |
| 78 | 78 | $db = new DatabaseConnect(); |
| 79 | - $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid . "'"); |
|
| 79 | + $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid . "'"); |
|
| 80 | 80 | |
| 81 | - if ($result->num_rows > 0) |
|
| 81 | + if($result->num_rows > 0) |
|
| 82 | 82 | { |
| 83 | 83 | return TRUE; |
| 84 | 84 | } |
@@ -100,8 +100,8 @@ discard block |
||
| 100 | 100 | if(!isset($_COOKIE['JodelDeviceId']) || !isDeviceUidInDatabase($_COOKIE['JodelDeviceId'])) |
| 101 | 101 | { |
| 102 | 102 | $jodelAccountForView = new JodelAccount(); |
| 103 | - setcookie('JodelDeviceId', $jodelAccountForView->deviceUid, time()+60*60*24*365*10); |
|
| 104 | - user_log('Created account with JodelDeviceId:' . $jodelAccountForView->deviceUid . ' for [' . $_SERVER ['HTTP_USER_AGENT'] . ']'); |
|
| 103 | + setcookie('JodelDeviceId', $jodelAccountForView->deviceUid, time() + 60 * 60 * 24 * 365 * 10); |
|
| 104 | + user_log('Created account with JodelDeviceId:' . $jodelAccountForView->deviceUid . ' for [' . $_SERVER ['HTTP_USER_AGENT'] . ']'); |
|
| 105 | 105 | |
| 106 | 106 | } |
| 107 | 107 | else |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | if(isset($_GET['search'])) |
| 131 | 131 | { |
| 132 | 132 | |
| 133 | - user_log('User with JodelDeviceId:' . $jodelAccountForView->deviceUid . ' [' . $_SERVER['REMOTE_ADDR'] . '][' . $_SERVER ['HTTP_USER_AGENT'] . '] searched for ' . $_GET['search']); |
|
| 133 | + user_log('User with JodelDeviceId:' . $jodelAccountForView->deviceUid . ' [' . $_SERVER['REMOTE_ADDR'] . '][' . $_SERVER ['HTTP_USER_AGENT'] . '] searched for ' . $_GET['search']); |
|
| 134 | 134 | |
| 135 | 135 | if(substr($_GET['search'], 0, 1) === "#") |
| 136 | 136 | { |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | if(isset($_GET['view'])) |
| 187 | 187 | { |
| 188 | - switch ($_GET['view']) { |
|
| 188 | + switch($_GET['view']) { |
|
| 189 | 189 | case 'discussed': |
| 190 | 190 | $view = 'discussed'; |
| 191 | 191 | break; |