Completed
Push — master ( 311089...9992d6 )
by mains
18:35
created

admin.php (13 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
include 'php/jodel-web.php';
4
5
6
if(isset($_GET['pw']))
7
{
8
	setcookie('JodelAdminPassword', $_GET['pw'], time()+60*60*24*365*10);
9
	error_log('admin password saved for [' . $_SERVER ['HTTP_USER_AGENT'] . ']');
10
	header('Location: ' . $baseUrl . 'admin.php');
11
	exit;
12
}
13
else if(isset($_GET['voterPw']))
14
{
15
	setcookie('JodelVoterPassword', $_GET['voterPw'], time()+60*60*24*365*10);
16
	error_log('voter password saved for [' . $_SERVER ['HTTP_USER_AGENT'] . ']');
17
	header('Location: ' . $baseUrl . 'admin.php');
18
	exit;
19
}
20
21
if(isUserAdmin())
22
{
23
	$userIsAdmin = true;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 4 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...
24
	$userIsVoter = true;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 4 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...
25
	$votesRemaining = 'Unlimited';
26
}
27
else if(isUserVoter())
28
{
29
	$userIsAdmin = false;
30
	$userIsVoter = true;
31
32
	$result = $db->query("SELECT user_token, remaining_votes FROM users WHERE user_token = '" . $_COOKIE['JodelVoterPassword'] . "'");
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 131 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
33
	if($result->num_rows > 0)
34
	{
35
		$row = $result->fetch_assoc();
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 12 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...
36
		$votesRemaining = $row['remaining_votes'];
37
	}
38
	else
39
	{
40
		error_log('Hard error: isUser voter, get remaining votes in admin.php');
41
	}
42
}
43
else
44
{
45
	error_log($_SERVER['REMOTE_ADDR']  . ' used a wrong voterPw / pw on admin.php');
46
	die();
47
}
48
49
50
if($userIsAdmin && isset($_POST['createAccount']) && $_POST['createAccount'])
51
{
52
	$newJodelAccount = new JodelAccount();
53
}
54
55
if($userIsAdmin && isset($_POST['createVoter']) && $_POST['createVoter'])
56
{
57
	//insert voter into db
58
	$db = new DatabaseConnect();
59
    $result = $db->query("INSERT INTO users (user_token, remaining_votes, device_uid, rights)
60
                    VALUES ('" 	. $db->escape_string($_POST['user_token'])
61
                    	. "','" . $db->escape_string($_POST['remaining_votes'])
62
                    	. "','" . $db->escape_string($_POST['device_uid'])
63
                    	. "','" . $db->escape_string($_POST['rights']) . "')");
64
    
65 View Code Duplication
    if($result === false){
66
            $error = db_error();
67
            error_log($error);
68
            error_log("Adding Voter failed: (" . $result->errno . ") " . $result->error);
69
    } 
70
}
71
72
//Vote
73
/*
74
if($userIsVoter && isset($_POST['vote']) && isset($_POST['postId']) && isset($_POST['quantity']))
75
{
76
	$i = 0;
77
	$result = $db->query("SELECT access_token, device_uid FROM accounts WHERE device_uid NOT IN (SELECT device_uid FROM votes WHERE postId = '" . $_POST['postId'] . "')");
78
79
	if($result->num_rows > 0)
80
	{
81
		// output data of each row
82
		while(($row = $result->fetch_assoc()) && $i < $_POST['quantity'])
83
		{
84
			$jodelAccount = new JodelAccount($row['device_uid']);
85
86
			if($jodelAccount->votePostId($_POST['postId'], $_POST['vote']))
87
			{
88
				$i++;
89
			}
90
		}
91
	}
92
	else
93
	{
94
		error_log("Error: 0 results");
95
	}
96
}
97
*/
98
99
?>
100
<!DOCTYPE html>
101
<html lang="en">
102
	<head>
103
		<title>Backend - JodelBlue WebClient</title>
104
		
105
		<meta charset="utf8">
106
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
107
		<meta http-equiv="x-ua-compatible" content="ie=edge">
108
		
109
		<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.">
110
		<meta name="keywords" content="jodelblue, jodel, blue, webclient, web, client">
111
		
112
		<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">
113
				<link rel="stylesheet" href="<?php echo $baseUrl;?>css/font-awesome.min.css">
114
		<link rel="stylesheet" href="<?php echo $baseUrl;?>style.css" type="text/css">
115
		
116
		<link rel="shortcut icon" type="image/x-icon" href="<?php echo $baseUrl;?>img/favicon/favicon.ico">
117
		<link rel="icon" type="image/x-icon" href="<?php echo $baseUrl;?>img/favicon/favicon.ico">
118
		<link rel="icon" type="image/gif" href="<?php echo $baseUrl;?>img/favicon/favicon.gif">
119
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon.png">
120
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon.png">
121
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-57x57.png" sizes="57x57">
122
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-60x60.png" sizes="60x60">
123
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-72x72.png" sizes="72x72">
124
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-76x76.png" sizes="76x76">
125
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-114x114.png" sizes="114x114">
126
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-120x120.png" sizes="120x120">
127
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-128x128.png" sizes="128x128">
128
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-144x144.png" sizes="144x144">
129
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-152x152.png" sizes="152x152">
130
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-180x180.png" sizes="180x180">
131
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-precomposed.png">
132
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-16x16.png" sizes="16x16">
133
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-32x32.png" sizes="32x32">
134
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-96x96.png" sizes="96x96">
135
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-160x160.png" sizes="160x160">
136
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-192x192.png" sizes="192x192">
137
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-196x196.png" sizes="196x196">
138
		<meta name="msapplication-TileImage" content="<?php echo $baseUrl;?>img/favicon/win8-tile-144x144.png"> 
139
		<meta name="msapplication-TileColor" content="#5682a3"> 
140
		<meta name="msapplication-navbutton-color" content="#5682a3"> 
141
		<meta name="application-name" content="JodelBlue"/> 
142
		<meta name="msapplication-tooltip" content="JodelBlue"/> 
143
		<meta name="apple-mobile-web-app-title" content="JodelBlue"/> 
144
		<meta name="msapplication-square70x70logo" content="<?php echo $baseUrl;?>img/favicon/win8-tile-70x70.png"> 
145
		<meta name="msapplication-square144x144logo" content="<?php echo $baseUrl;?>img/favicon/win8-tile-144x144.png"> 
146
		<meta name="msapplication-square150x150logo" content="<?php echo $baseUrl;?>img/favicon/win8-tile-150x150.png"> 
147
		<meta name="msapplication-wide310x150logo" content="<?php echo $baseUrl;?>img/favicon/win8-tile-310x150.png"> 
148
		<meta name="msapplication-square310x310logo" content="<?php echo $baseUrl;?>img/favicon/win8-tile-310x310.png"> 
149
	</head>
150
	
151
	<body>
152
		<header>
153
			<nav class="navbar navbar-full navbar-dark navbar-fixed-top">
154
				<div class="container">					
155
					<h1>
156
						<a href="./admin.php" class="spinnable">						
157
							JodelBlue <i class="fa fa-refresh fa-1x"></i>
158
						</a>
159
					</h1>					
160
				</div>
161
			</nav>
162
		</header>
163
		
164
		<div class="mainContent container">		
165
			<div class="row">
166
				<article class="topContent col-12 col-sm-12">
167
					<content id="posts" class="adminpanel">
168
						<?php if($userIsAdmin) { ?>
169
							<div class="row">
170
								<div class="col-md-12">
171
									<h2>Account management</h2>
172
								</div>
173
174
								<div class="col-md-4">
175
										<h3>User accounts</h3>
176
										<form method="post">
177
											<div>
178
												<?php
179
													$result = $db->query("SELECT COUNT(*) FROM accounts");
180
													echo $result->fetch_row()[0];
181
												?>
182
												accounts in the database
183
											</div>
184
											<button type="submit" name="createAccount" value="TRUE">Create new Account</button>
185
										</form>
186
								</div>
187
188
								<div class="col-md-8">
189
									<h3>Create Voter</h3>
190
									<form method="post">
191
										<div class="form-group">
192
											<label for="user_token">User token</label>
193
											<input type="text" class="form-control" id="user_token" name="user_token" placeholder="user_token" required="true">
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 126 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
194
										</div>
195
										<div class="form-group">
196
											<label for="remaining_votes">Remaining votes</label>
197
											<input type="number" class="form-control" name="remaining_votes" placeholder="remaining_votes" required="true">
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 122 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
198
										</div>
199
										<div class="form-group">
200
											<label for="device_uid">Device Uid</label>
201
											<input type="text" class="form-control" name="device_uid" placeholder="device_uid" required="true">
202
										</div>
203
										<div class="form-group">
204
											<label for="rights">Rights</label>
205
											<input type="text" class="form-control" name="rights" placeholder="rights" required="true">
206
										</div>
207
										<button type="submit" name="createVoter" value="TRUE">Create new Voter</button>
208
									</form>
209
								</div>							
210
							</div>
211
						<hr>
212
						<?php
213
						}
214
215
						if($userIsVoter) {
216
						?>
217
							<div class="row">								
218
								<div class="col-12 col-sm-12">
219
								<h2>Voting (<?php echo $votesRemaining;?> votes remaining)</h2>
220
									<form>
221
										<div class="form-group">
222
											<label for="quantityDelay">Quantity</label>
223
											<input placeholder="quantity" class="form-control" id="quantityDelay" type="number" name="quantity">
224
										</div>
225
										<div class="form-group">
226
											<label for="minDelay">Minimum delay</label>
227
											<input placeholder="min interval" class="form-control" id="minDelay" value="<?php echo $config['minInterval'];?>" type="number" name="min">
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 150 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
228
										</div>
229
										<div class="form-group">
230
											<label for="maxDelay">Maximum delay</label>
231
											<input placeholder="max interval" class="form-control" id="maxDelay" value="<?php echo $config['maxInterval'];?>" type="number" name="max">
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 150 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
232
										</div>
233
										<div class="form-group">
234
											<label for="postIdDelay">Post Id</label>
235
											<input placeholder="postId" class="form-control" id="postIdDelay" value="<?php if(isset($_GET['postId'])) echo $_GET['postId'];?>" type="text" name="postId">
236
										</div>
237
										<div class="row">
238
											<div class="col-6 col-sm-6"><button type="button" name="vote" value="up" class="half" onclick="voteWithAjax('up');">Upvote</button></div>
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 148 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
239
											<div class="col-6 col-sm-6"><button type="button" name="vote" value="down" class="half" onclick="voteWithAjax('down');">Downvote</button></div>
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 154 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
240
										</div>
241
									</form>
242
									<progress id="progressDelay" value="0" max="100"></progress>
243
									<div id="ResponseMessage"></div>
244
									<div id="ResponseCaptcha"></div>
245
								</div>
246
							</div>
247
						<?php } ?>
248
					</content>
249
				</article>
250
			</div>
251
		</div>
252
		
253
		
254
		<!-- jQuery, Tether, Bootstrap JS and own-->
255
		<script
256
			  src="https://code.jquery.com/jquery-3.1.1.min.js"
257
			  integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
258
			  crossorigin="anonymous"></script>
259
	    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 205 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
260
	    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 212 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
261
	    <script src="<?php echo $baseUrl;?>js/jQueryEmoji.js"></script>
262
	    <script src="https://cdnjs.cloudflare.com/ajax/libs/ekko-lightbox/5.1.1/ekko-lightbox.min.js" integrity="sha256-1odJPEl+KoMUaA1T7QNMGSSU/r5LCKCRC6SL8P0r2gY=" crossorigin="anonymous"></script>
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 196 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
263
264
		<script>
265
			//delayed voting
266
			var rekData;
267
			function voteWithAjax(type)
268
			{
269
				var id = $("#postIdDelay").val();
270
				var quantity = parseInt($("#quantityDelay").val());
271
				var minTime = parseFloat($("#minDelay").val());
272
				var maxTime = parseFloat($("#maxDelay").val());	
273
				var data = {"vote": type,
274
						   "id":id,
275
							"i": 1,
276
						   "quantity":quantity,
277
						   "minTime":minTime,
278
						   "maxTime":maxTime};
279
				
280
				$("#progressDelay").attr("max", quantity);
281
				$("#progressDelay").val(0);
282
				if (minTime > maxTime)
283
				{
284
					$("#ResponseMessage").html("min interval is greater than max interval");
285
					
286
				}
287
				else if (id == "")
288
				{
289
					$("#ResponseMessage").html("please enter a postId");
290
				}
291
				else if (isNaN(quantity))
292
				{
293
					$("#ResponseMessage").html("please enter a valid quantity of votes");
294
				}
295
				else 
296
				{
297
					voteRek(data);
298
				}
299
			}
300
			
301
			function voteRek(data)
302
			{
303
				$.ajax({
304
				  type: "POST",
305
				  url: "<?php echo $baseUrl;?>vote-ajax.php",
306
				  data: {"vote" : data["vote"],
307
						 "postId" : data["id"]},
308
				  success: function(result){
309
					  $("#progressDelay").val(data["i"]);
310
					  var response;
311
					  try 
312
					  {
313
						response = JSON.parse(result);
314
					  } catch (e) {
315
						//voteRek(data);
316
					  }
317
					  if (response["success"] != true)
318
					  {
319
						  $("#ResponseMessage").html(response["message"]);
320
						  if (response["captcha"] != null) {
321
							  rekData = data;
322
							  $("#ResponseCaptcha").append( "<div id='captchaWrapper_" + data["i"] + "'><form><p>Check all images with Coons on it (Coons look like <img style=\"height: 1.0em; width: unset;\" src=\"img/coon.png\">).</p><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 type=\"button\" onclick=\"verifyAccount(" + data["i"] + ", '" + response["captcha"]["key"] + "' , '" + response["deviceUid"] + "');\">Verify</button></form></div>");
323
							  //verifyAccount(data["i"], response["captcha"]["key"], response["deviceUid"]);
324
						  }
325
					  }
326
					  else if (data["i"] < data["quantity"])
327
					  {
328
						  $("#ResponseMessage").html(data["i"] + " of " + data["quantity"]);
329
						  data["i"] += 1;
330
						  setTimeout(function(){voteRek(data)}, getRandomFloat(data["minTime"],data["maxTime"])*1000);
331
					  } else {
332
						  $("#ResponseMessage").html(data["quantity"] + " votes completed");
333
					  }
334
				  }
335
				});
336
			}
337
			
338
			function verifyAccount(id, key, deviceUid)
339
			{
340
				var solution = "";
341
				for (i=0; i<9; i++) {
342
					var box = $("#box_"+i);
343
					if (box.is(':checked') == true)
344
					{
345
						if (solution != "")
346
						{
347
							solution += "-" + i;
348
						}
349
						else 
350
						{
351
							solution = i;
352
						}
353
354
					}
355
				}
356
				console.log(solution);
357
				$.ajax({
358
				  type: "POST",
359
				  url: "<?php echo $baseUrl;?>vote-ajax.php?solution=" + solution + "&key="+key,
360
				  data: {"deviceUid" : deviceUid},
361
				  success: function(result){
362
					  var response = JSON.parse(result);
363
					  console.log("Verification = "+response["success"])
364
					  $("#captchaWrapper_"+id).remove();
365
					  voteRek(rekData);
366
				  }
367
				});
368
			}
369
			
370
			function getRandomFloat(min, max)
371
			{
372
			  return Math.floor(Math.random() * (max - min)) + min;
373
			}
374
375
		</script>
376
	</body>
377
</html>