Completed
Push — master ( 4a8418...a8d532 )
by mains
03:04
created
php/Requests/AbstractRequest.php 1 patch
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -2,21 +2,21 @@  discard block
 block discarded – undo
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 = 'cYjTAwjdJyiuXAyrMhkCDiVZhshhLhotNotLiPVu';
8
-    const USERAGENT = 'Jodel/4.35.6 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
9
-    const CLIENT_TYPE = 'android_4.35.6';
5
+	const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26';
6
+	const APIURL = 'https://api.go-tellm.com/api';
7
+	const SECRET = 'cYjTAwjdJyiuXAyrMhkCDiVZhshhLhotNotLiPVu';
8
+	const USERAGENT = 'Jodel/4.35.6 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
9
+	const CLIENT_TYPE = 'android_4.35.6';
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
-    {
19
-        $result = new \stdClass();
17
+	public function execute()
18
+	{
19
+		$result = new \stdClass();
20 20
 		        
21 21
 		$this->payLoad = $this->getPayload();
22 22
 		$device_uid = '';
@@ -25,16 +25,16 @@  discard block
 block discarded – undo
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,112 +45,112 @@  discard block
 block discarded – undo
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
-        }
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 73
 
74
-        http_response_code($result->status_code);
74
+		http_response_code($result->status_code);
75 75
 
76
-        switch ($result->status_code) {
77
-            case 200:
78
-                $result = json_decode($result->body, true);
79
-                break;
80
-            case 204:
81
-                $result = 'Success';
82
-                http_response_code(200);
83
-                break;
84
-            case 400:
85
-                $result = json_decode($result->body, true);
86
-                error_log('Error 400 - ' . print_r($result, true));
87
-                break;
88
-            case 401:
89
-                $result = json_decode($result->body, true);
76
+		switch ($result->status_code) {
77
+			case 200:
78
+				$result = json_decode($result->body, true);
79
+				break;
80
+			case 204:
81
+				$result = 'Success';
82
+				http_response_code(200);
83
+				break;
84
+			case 400:
85
+				$result = json_decode($result->body, true);
86
+				error_log('Error 400 - ' . print_r($result, true));
87
+				break;
88
+			case 401:
89
+				$result = json_decode($result->body, true);
90 90
 
91
-                if(array_key_exists('error', $result) && $result['error'] == 'length')
92
-                {
91
+				if(array_key_exists('error', $result) && $result['error'] == 'length')
92
+				{
93 93
 
94
-                }
95
-                else
96
-                {
97
-                    error_log('Error 401 - ' . print_r($result, true));
98
-                }
99
-                break;
100
-            case 404:
101
-                error_log('Error 404 - ' . print_r($result, true));
102
-                $result = json_decode($result->body, true);
103
-                break;
94
+				}
95
+				else
96
+				{
97
+					error_log('Error 401 - ' . print_r($result, true));
98
+				}
99
+				break;
100
+			case 404:
101
+				error_log('Error 404 - ' . print_r($result, true));
102
+				$result = json_decode($result->body, true);
103
+				break;
104 104
 			case 477:
105
-                $result = json_decode($result->body, true);
106
-                error_log('Error 477 - ' . print_r($result, true));
107
-                break;
108
-            case 429:
109
-                error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true));
110
-            	exit("Error 429: Too Many Requests");
111
-            	break;
112
-            case 403:
113
-                error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true));
114
-                $result = json_decode($result->body, true);
115
-                break;
116
-            case 502:
117
-                error_log('Error 502 - ' . print_r($result, true));
118
-                $result = json_decode($result->body, true);
119
-                header('location:'.$_SERVER['PHP_SELF']);
120
-                break;
121
-            case 503:
122
-                error_log('Error 503 - ' . print_r($result, true));
123
-                $result = json_decode($result->body, true);
105
+				$result = json_decode($result->body, true);
106
+				error_log('Error 477 - ' . print_r($result, true));
107
+				break;
108
+			case 429:
109
+				error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true));
110
+				exit("Error 429: Too Many Requests");
111
+				break;
112
+			case 403:
113
+				error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true));
114
+				$result = json_decode($result->body, true);
115
+				break;
116
+			case 502:
117
+				error_log('Error 502 - ' . print_r($result, true));
118
+				$result = json_decode($result->body, true);
119
+				header('location:'.$_SERVER['PHP_SELF']);
120
+				break;
121
+			case 503:
122
+				error_log('Error 503 - ' . print_r($result, true));
123
+				$result = json_decode($result->body, true);
124 124
 
125
-                if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable')
126
-                {
127
-                    header('location:'.$_SERVER['PHP_SELF']); 
128
-                }
129
-                break;
130
-            default:
131
-                error_log('Error '.$result->status_code.' - unknown error');
132
-                $result = json_decode($result->body, true);
133
-        }
125
+				if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable')
126
+				{
127
+					header('location:'.$_SERVER['PHP_SELF']); 
128
+				}
129
+				break;
130
+			default:
131
+				error_log('Error '.$result->status_code.' - unknown error');
132
+				$result = json_decode($result->body, true);
133
+		}
134 134
 
135
-        //important for account refresh
136
-        if($device_uid != '')
137
-        {
135
+		//important for account refresh
136
+		if($device_uid != '')
137
+		{
138 138
 			$result[0] = $result;
139 139
 			$result[1] = $device_uid;
140
-        }
140
+		}
141 141
 
142 142
         
143
-        /* var_dump($result); */
143
+		/* var_dump($result); */
144 144
         
145
-        return $result;
146
-    }
147
-    abstract function getPayload();
148
-    /**
149
-     * Gets Sign headers
150
-     * @return array headers
151
-     */
152
-    private function getSignHeaders()
153
-    {
145
+		return $result;
146
+	}
147
+	abstract function getPayload();
148
+	/**
149
+	 * Gets Sign headers
150
+	 * @return array headers
151
+	 */
152
+	private function getSignHeaders()
153
+	{
154 154
 			if($this->getAccessToken() == null) {
155 155
 				$payload_accessToken = "";
156 156
 			}
@@ -159,54 +159,54 @@  discard block
 block discarded – undo
159 159
 			}
160 160
 			
161 161
 			
162
-        $headers = array(
163
-            "Connection" => "keep-alive",
164
-            "Accept-Encoding" => "gzip",
165
-            "Content-Type" => "application/json; charset=UTF-8",
166
-            "User-Agent" => self::USERAGENT
167
-        );
168
-        $timestamp = new DateTime();
169
-        $timestamp = $timestamp->format(DateTime::ATOM);
170
-        $timestamp = substr($timestamp, 0, -6);
171
-        $timestamp .= "Z";
172
-        $urlParts = parse_url($this->getFullUrl());
173
-        $url2 = "";
174
-        $req = [$this->getMethod(),
175
-            $urlParts['host'],
176
-            "443",
177
-            $urlParts['path'],
178
-            $payload_accessToken,
179
-            $timestamp,
180
-            $url2,
181
-            $this->payLoad];
182
-        $reqString = implode("%", $req);
183
-        $secret = self::SECRET;
184
-        $signature = hash_hmac('sha1', $reqString, $secret);
185
-        $signature = strtoupper($signature);
186
-        $headers['X-Authorization'] = 'HMAC ' . $signature;
187
-        $headers['X-Client-Type'] = self::CLIENT_TYPE;
188
-        $headers['X-Timestamp'] = $timestamp;
189
-        $headers['X-Api-Version'] = '0.2';
190
-        return $headers;
191
-    }
192
-    private function getFullUrl()
193
-    {
194
-        return self::APIURL . $this->getApiEndPoint();
195
-    }
196
-    abstract function getApiEndPoint();
197
-    abstract function getMethod();
198
-    /**
199
-     * @return string
200
-     */
201
-    private function getAccessToken()
202
-    {
203
-        return $this->accessToken;
204
-    }
205
-    /**
206
-     * @param string $accessToken
207
-     */
208
-    public function setAccessToken($accessToken)
209
-    {
210
-        $this->accessToken = $accessToken;
211
-    }
162
+		$headers = array(
163
+			"Connection" => "keep-alive",
164
+			"Accept-Encoding" => "gzip",
165
+			"Content-Type" => "application/json; charset=UTF-8",
166
+			"User-Agent" => self::USERAGENT
167
+		);
168
+		$timestamp = new DateTime();
169
+		$timestamp = $timestamp->format(DateTime::ATOM);
170
+		$timestamp = substr($timestamp, 0, -6);
171
+		$timestamp .= "Z";
172
+		$urlParts = parse_url($this->getFullUrl());
173
+		$url2 = "";
174
+		$req = [$this->getMethod(),
175
+			$urlParts['host'],
176
+			"443",
177
+			$urlParts['path'],
178
+			$payload_accessToken,
179
+			$timestamp,
180
+			$url2,
181
+			$this->payLoad];
182
+		$reqString = implode("%", $req);
183
+		$secret = self::SECRET;
184
+		$signature = hash_hmac('sha1', $reqString, $secret);
185
+		$signature = strtoupper($signature);
186
+		$headers['X-Authorization'] = 'HMAC ' . $signature;
187
+		$headers['X-Client-Type'] = self::CLIENT_TYPE;
188
+		$headers['X-Timestamp'] = $timestamp;
189
+		$headers['X-Api-Version'] = '0.2';
190
+		return $headers;
191
+	}
192
+	private function getFullUrl()
193
+	{
194
+		return self::APIURL . $this->getApiEndPoint();
195
+	}
196
+	abstract function getApiEndPoint();
197
+	abstract function getMethod();
198
+	/**
199
+	 * @return string
200
+	 */
201
+	private function getAccessToken()
202
+	{
203
+		return $this->accessToken;
204
+	}
205
+	/**
206
+	 * @param string $accessToken
207
+	 */
208
+	public function setAccessToken($accessToken)
209
+	{
210
+		$this->accessToken = $accessToken;
211
+	}
212 212
 }
Please login to merge, or discard this patch.
vote-ajax.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@  discard block
 block discarded – undo
5 5
 if(isset($_GET['postId']) && $_GET['vote'])
6 6
 {
7 7
 	header('Content-Type: application/json');
8
-    echo json_encode($jodelAccountForKarma->votePostId($_GET['postId'], $_GET['vote']));
9
-    die();
8
+	echo json_encode($jodelAccountForKarma->votePostId($_GET['postId'], $_GET['vote']));
9
+	die();
10 10
 }
11 11
 
12 12
 if(isset($_GET['solution']) && isset($_POST['deviceUid']))
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
                                 WHERE user_token='" . $_COOKIE['JodelVoterPassword'] . "'");
129 129
 					if($result === false)
130 130
 					{
131
-               			error_log("Update remaining votes failed: (" . $db->errno . ") " . $db->error);
132
-               		}
133
-               		$db->close();
131
+			   			error_log("Update remaining votes failed: (" . $db->errno . ") " . $db->error);
132
+			   		}
133
+			   		$db->close();
134 134
 					$jodelAccount->votePostId($_POST['postId'], $_POST['vote']);
135 135
 				}
136 136
 			}
Please login to merge, or discard this patch.
php/jodel-web.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -49,27 +49,27 @@  discard block
 block discarded – undo
49 49
 
50 50
 function user_log($msg)
51 51
 {
52
-    $log  = $msg . PHP_EOL;
53
-    file_put_contents(realpath(__DIR__ . '/..') . '/logs/user_log-' . date("j.n.Y") . '.txt', $log, FILE_APPEND);
52
+	$log  = $msg . PHP_EOL;
53
+	file_put_contents(realpath(__DIR__ . '/..') . '/logs/user_log-' . date("j.n.Y") . '.txt', $log, FILE_APPEND);
54 54
 }
55 55
 
56 56
 function isUserBot()
57 57
 {
58
-    preg_match('/bot|spider|google|twitter/i', $_SERVER['HTTP_USER_AGENT'], $matches);
58
+	preg_match('/bot|spider|google|twitter/i', $_SERVER['HTTP_USER_AGENT'], $matches);
59 59
 
60
-    return (isset($matches[0])) ? true : false;
60
+	return (isset($matches[0])) ? true : false;
61 61
 }
62 62
 
63 63
 function configPropertyExists($config, $property)
64 64
 {
65
-    if(!array_key_exists($property, $config) || !isset($config[$property]) || $config[$property] == '' || $config[$property] == 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
66
-    {
67
-        return FALSE;
68
-    }
69
-    else
70
-    {
71
-        return TRUE;
72
-    }
65
+	if(!array_key_exists($property, $config) || !isset($config[$property]) || $config[$property] == '' || $config[$property] == 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
66
+	{
67
+		return FALSE;
68
+	}
69
+	else
70
+	{
71
+		return TRUE;
72
+	}
73 73
 }
74 74
 
75 75
 function isUserVoter()
@@ -110,19 +110,19 @@  discard block
 block discarded – undo
110 110
 
111 111
 function isDeviceUidInDatabase($deviceUid)
112 112
 {
113
-    $db = new DatabaseConnect();  
114
-    $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid  . "'");
113
+	$db = new DatabaseConnect();  
114
+	$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid  . "'");
115 115
 
116
-    if ($result->num_rows > 0)
117
-    {
118
-    	$db->close();
119
-        return TRUE;
120
-    }
121
-    else
122
-    {
123
-    	$db->close();
124
-        return FALSE;
125
-    }
116
+	if ($result->num_rows > 0)
117
+	{
118
+		$db->close();
119
+		return TRUE;
120
+	}
121
+	else
122
+	{
123
+		$db->close();
124
+		return FALSE;
125
+	}
126 126
 }
127 127
 
128 128
 	//Check if it's a Spider or Google Bot
@@ -149,14 +149,14 @@  discard block
 block discarded – undo
149 149
 	}
150 150
 	
151 151
 	if(configPropertyExists($config, 'karmaDeviceUid'))
152
-    {
153
-    	$jodelAccountForKarma = new JodelAccount($config['karmaDeviceUid']);
154
-    }
155
-    else
156
-    {
157
-    	error_log("No Karma deviceUid set in config file");
152
+	{
153
+		$jodelAccountForKarma = new JodelAccount($config['karmaDeviceUid']);
154
+	}
155
+	else
156
+	{
157
+		error_log("No Karma deviceUid set in config file");
158 158
 		$jodelAccountForKarma = new JodelAccount($deviceUid);
159
-    }
159
+	}
160 160
 
161 161
 	/*
162 162
 	 * Cunstruct View
Please login to merge, or discard this patch.