Completed
Push — master ( 306300...8aacdd )
by mains
02:51
created

admin.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
$config = parse_ini_file('config/config.ini.php');
4
if(!isset($_GET['pw']) || $config['pw'] != $_GET['pw'])
5
{
6
	error_log($_SERVER['REMOTE_ADDR']  . ' used a wrong password on admin.php');
7
	die();
8
}
9
10
include 'php/jodel-web.php';
11
12
$location = new Location();
13
$location->setLat('52.5134288');
14
$location->setLng('13.2746394');
15
$location->setCityName('Berlin');
16
17
18
19
if(isset($_POST['createAccount']) && $_POST['createAccount'])
20
{
21
	createAccount();
22
}
23
24
25
//Vote
26
if(isset($_POST['vote']) && isset($_POST['postId']) && isset($_POST['quantity']))
27
{
28
	$i = 0;
29
	$result = $db->query("SELECT access_token, device_uid FROM accounts WHERE device_uid NOT IN (SELECT device_uid FROM votes WHERE postId = '" . $_POST['postId'] . "')");
30
31
	if($result->num_rows > 0)
32
	{
33
		// output data of each row
34
		while(($row = $result->fetch_assoc()) && $i < $_POST['quantity'])
35
		{
36
			$accessToken = $row['access_token'];
37
			
38
			$location = getLocationByAccessToken($accessToken);
39
40
			$accessToken = isTokenFreshByAccessToken($location, $accessToken);
41
42
43 View Code Duplication
			if($_POST['vote'] == "up") {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style Comprehensibility introduced by
The string literal up does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
44
				$accountCreator = new Upvote();
45
			}
46
			else if($_POST['vote'] == "down") {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal down does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
47
				$accountCreator = new Downvote();
48
			}
49
50
			$accountCreator->setAccessToken($accessToken);
51
			$accountCreator->postId = $_POST['postId'];
52
			$data = $accountCreator->execute();
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 19 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
53
			if(array_key_exists('post', $data))
54
			{
55
				addVoteWithPostIdAndTypeToDeviceUid($_POST['postId'], $_POST['vote'], $row['device_uid']);
56
				$i++;
57
			}
58
		}
59
	}
60
	else
61
	{
62
		echo "Error: 0 results";
63
	}
64
}
65
66
67
?>
68
<!DOCTYPE html>
69
<html lang="en">
70
	<head>
71
		<title>Backend - JodelBlue WebClient</title>
72
		
73
		<meta charset="utf8">
74
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
75
		<meta http-equiv="x-ua-compatible" content="ie=edge">
76
		
77
		<meta name="description" content="JodelBlue is a WebClient for the Jodel App. No registration required! Browse Jodels all over the world. Send your own Jodels or upvote others.">
78
		<meta name="keywords" content="jodelblue, jodel, blue, webclient, web, client">
79
		
80
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous">
81
		<link rel="stylesheet" href="css/font-awesome.min.css">
82
		<link rel="stylesheet" href="style.css" type="text/css">
83
		
84
		<link rel="shortcut icon" type="image/x-icon" href="./img/favicon/favicon.ico">
85
		<link rel="icon" type="image/x-icon" href="./img/favicon/favicon.ico">
86
		<link rel="icon" type="image/gif" href="./img/favicon/favicon.gif">
87
		<link rel="icon" type="image/png" href="./img/favicon/favicon.png">
88
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon.png">
89
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-57x57.png" sizes="57x57">
90
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-60x60.png" sizes="60x60">
91
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-72x72.png" sizes="72x72">
92
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-76x76.png" sizes="76x76">
93
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-114x114.png" sizes="114x114">
94
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-120x120.png" sizes="120x120">
95
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-128x128.png" sizes="128x128">
96
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-144x144.png" sizes="144x144">
97
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-152x152.png" sizes="152x152">
98
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-180x180.png" sizes="180x180">
99
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-precomposed.png">
100
		<link rel="icon" type="image/png" href="./img/favicon/favicon-16x16.png" sizes="16x16">
101
		<link rel="icon" type="image/png" href="./img/favicon/favicon-32x32.png" sizes="32x32">
102
		<link rel="icon" type="image/png" href="./img/favicon/favicon-96x96.png" sizes="96x96">
103
		<link rel="icon" type="image/png" href="./img/favicon/favicon-160x160.png" sizes="160x160">
104
		<link rel="icon" type="image/png" href="./img/favicon/favicon-192x192.png" sizes="192x192">
105
		<link rel="icon" type="image/png" href="./img/favicon/favicon-196x196.png" sizes="196x196">
106
		<meta name="msapplication-TileImage" content="./img/favicon/win8-tile-144x144.png"> 
107
		<meta name="msapplication-TileColor" content="#5682a3"> 
108
		<meta name="msapplication-navbutton-color" content="#5682a3"> 
109
		<meta name="application-name" content="JodelBlue"/> 
110
		<meta name="msapplication-tooltip" content="JodelBlue"/> 
111
		<meta name="apple-mobile-web-app-title" content="JodelBlue"/> 
112
		<meta name="msapplication-square70x70logo" content="./img/favicon/win8-tile-70x70.png"> 
113
		<meta name="msapplication-square144x144logo" content="./img/favicon/win8-tile-144x144.png"> 
114
		<meta name="msapplication-square150x150logo" content="./img/favicon/win8-tile-150x150.png"> 
115
		<meta name="msapplication-wide310x150logo" content="./img/favicon/win8-tile-310x150.png"> 
116
		<meta name="msapplication-square310x310logo" content="./img/favicon/win8-tile-310x310.png"> 
117
	</head>
118
	
119
	<body>
120
		<header>
121
			<nav class="navbar navbar-full navbar-dark navbar-fixed-top">
122
				<div class="container">					
123
						<h1>
124
						<a href="./" class="spinnable">
125
						
126
						JodelBlue <i class="fa fa-refresh fa-1x"></i></a>
127
					</h1>					
128
				</div>
129
			</nav>
130
		</header>
131
		
132
		<div class="mainContent container">		
133
			<div class="content row">
134
				<article class="topContent col-sm-8">
135
136
					<content id="posts" class="adminpanel">
137
						<h2>account management</h2>
138
						<form method="post">
139
							<div>
140
							<?php
141
								$result = $db->query("SELECT COUNT(*) FROM accounts");
142
								echo $result->fetch_row()[0];
143
							?>
144
							accounts in the database</div>
145
							<button type="submit" name="createAccount" value="TRUE">Create new Account</button>
146
						</form>
147
						<hr>
148
						<h2>voting</h2>
149
						<form method="post">
150
							<input placeholder="quantity" type="number" name="quantity"><br>
151
							<input placeholder="postId" type="text" name="postId"><br>
152
							<button type="submit" name="vote" value="up" class="half">Upvote</button>
153
							<button type="submit" name="vote" value="down" class="half">Downvote</button>
154
						</form>
155
						<hr>
156
						<h2>delayed voting</h2>
157
							<input placeholder="quantity" id="quantityDelay" type="number" name="quantity"><br>
158
							<input placeholder="min interval" id="minDelay" type="text" name="min"><br>
159
							<input placeholder="max interval" id="maxDelay" type="text" name="max"><br>
160
							<input placeholder="postId" id="postIdDelay" type="text" name="postId"><br>
161
							<button name="vote" value="up" class="half" onClick="vote('up');">Upvote</button>
162
							<button name="vote" value="down" class="half" onClick="vote('down');">Downvote</button><br>
163
							<progress id="progressDelay" value="0" max="100"></progress>
164
							<div id="ResponseMessage"></div>
165
							<div id="ResponseCaptcha"></div>
166
						
167
					</content>
168
				</article>
169
			
170
				<aside class="topSidebar col-sm-4 sidebar-outer">
171
					<div class="fixed">
172
						<article>
173
							
174
						</article>
175
					</div>
176
				</aside>
177
			</div>
178
			<div id="sortJodelBy" class="row">
179
				<div class="col-sm-12">
180
					<div class="row">
181
						
182
					</div>
183
				</div>	
184
			</div>
185
		</div>
186
		
187
		
188
		<!-- jQuery, Tether, Bootstrap JS and own-->
189
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha384-3ceskX3iaEnIogmQchP8opvBy3Mi7Ce34nWjpBIwVTHfGYWQS9jwHDVRnpKKHJg7" crossorigin="anonymous"></script>
190
    	<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.7/js/tether.min.js" integrity="sha384-XTs3FgkjiBgo8qjEjBk0tGmf3wPrWtA6coPfQDfFEY8AnYJwjalXCiosYRBIBZX8" crossorigin="anonymous"></script>
191
    	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/js/bootstrap.min.js" integrity="sha384-BLiI7JTZm+JWlgKa0M0kGRpJbF2J8q+qreVrKBC47e3K6BW78kGLrCkeRX6I9RoK" crossorigin="anonymous"></script>
192
    	<script src="js/jQueryEmoji.js"></script>
193
194
		<script>
195
			//delayed voting
196
			var rekData;
197
			function vote(type)
198
			{
199
				var id = $("#postIdDelay").val();
200
				var quantity = parseInt($("#quantityDelay").val());
201
				var minTime = parseFloat($("#minDelay").val());
202
				var maxTime = parseFloat($("#maxDelay").val());
203
								
204
				var data = {"vote": type,
205
						   "id":id,
206
							"i": 1,
207
						   "quantity":quantity,
208
						   "minTime":minTime,
209
						   "maxTime":maxTime};
210
				
211
				$("#progressDelay").attr("max", quantity);
212
				$("#progressDelay").val(0);
213
				voteRek(data);
214
			}
215
			
216
			function voteRek(data)
217
			{
218
				$.ajax({
219
				  type: "POST",
220
				  url: "vote-ajax.php?pw=<?php echo $_GET["pw"]?>",
221
				  data: {"vote" : data["vote"],
222
						 "postId" : data["id"]},
223
				  success: function(result){
224
					  $("#progressDelay").val(data["i"]);
225
					  var response = JSON.parse(result);
226
					  if (response["success"] != true)
227
					  {
228
						  $("#ResponseMessage").html(response["message"]);
229
						  if (response["captcha"] != null) {
230
							  rekData = data;
231
							  $("#ResponseCaptcha").append( "<div id='captchaWrapper_" + data["i"] + "'><img src='" + response["captcha"]["image_url"] + "' style='width:100%'><div class='captchaWrapper'><input id='box_0' type='checkbox'><input id='box_1' type='checkbox'><input id='box_2' type='checkbox'><input id='box_3' type='checkbox'><input id='box_4' type='checkbox'><input id='box_5' type='checkbox'><input id='box_6' type='checkbox'><input id='box_7' type='checkbox'><input id='box_8' type='checkbox'></div><button onClick=\"verifyAccount(" + data["i"] + ", '" + response["captcha"]["key"] + "' , '" + response["accessToken"] + "');\">Verify</button></div>");
232
						  }
233
					  }
234
					  else if (data["i"] < data["quantity"])
235
					  {
236
						  $("#ResponseMessage").html(data["i"] + " of " + data["quantity"]);
237
						  data["i"] += 1;
238
						  setTimeout(function(){voteRek(data)}, getRandomFloat(data["minTime"],data["maxTime"])*1000);
239
					  } else {
240
						  $("#ResponseMessage").html(data["quantity"] + " votes completed");
241
					  }
242
				  }
243
				});
244
			}
245
			
246
			function verifyAccount(id, key, token)
247
			{
248
				var solution = "";
249
				for (i=0; i<9; i++) {
250
					var box = $("#box_"+i);
251
					if (box.is(':checked') == true)
252
					{
253
						if (solution != "")
254
						{
255
							solution += "-" + i;
256
						}
257
						else 
258
						{
259
							solution = i;
260
						}
261
262
					}
263
				}
264
				console.log(solution);
265
				$.ajax({
266
				  type: "POST",
267
				  url: "vote-ajax.php?pw=<?php echo $_GET["pw"]?>&solution=" + solution + "&key="+key,
268
				  data: {"accessToken" : token},
269
				  success: function(result){
270
					  var response = JSON.parse(result);
271
					  console.log("Verification = "+response["success"])
272
					  $("#captchaWrapper_"+id).remove();
273
					  voteRek(rekData);
274
				  }
275
				});
276
			}
277
			
278
			function getRandomFloat(min, max)
279
			{
280
			  return Math.floor(Math.random() * (max - min)) + min;
281
			}
282
			
283
			//BackButton
284
			function goBack()
285
			{
286
				window.history.back();
287
			}
288
289
			$(document).ready(function()
290
			{
291
292
293
				//Transform UTF-8 Emoji to img
294
				$('.jodel > content').Emoji();
295
296
				$('a').on('click', function(){
297
				    $('a').removeClass('selected');
298
				    $(this).addClass('selected');
299
				});
300
301
				function scrollToAnchor(aid){
302
				    var aTag = $("article[id='"+ aid +"']");
303
				    $('html,body').animate({scrollTop: aTag.offset().top-90},'slow');
304
				}
305
			});	
306
307
		</script>
308
	</body>
309
</html>