Completed
Push — master ( 335df2...311089 )
by mains
02:47
created

admin.php (8 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
if((!isset($_GET['pw']) || $config['pw'] != $_GET['pw']) && !isUserAdmin())
6
{
7
	error_log($_SERVER['REMOTE_ADDR']  . ' used a wrong password on admin.php');
8
	die();
9
}
10
else if (isset($_GET['pw']))
11
{
12
	setcookie('JodelAdminPassword', $_GET['pw'], time()+60*60*24*365*10);
13
	error_log('admin password saved for [' . $_SERVER ['HTTP_USER_AGENT'] . ']');
14
}
15
16
17
18
if(isset($_POST['createAccount']) && $_POST['createAccount'])
19
{
20
	$newJodelAccount = new JodelAccount();
21
}
22
23
24
//Vote
25
if(isset($_POST['vote']) && isset($_POST['postId']) && isset($_POST['quantity']))
26
{
27
	$i = 0;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 6 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...
28
	$result = $db->query("SELECT access_token, device_uid FROM accounts WHERE device_uid NOT IN (SELECT device_uid FROM votes WHERE postId = '" . $_POST['postId'] . "')");
29
30
	if($result->num_rows > 0)
31
	{
32
		// output data of each row
33
		while(($row = $result->fetch_assoc()) && $i < $_POST['quantity'])
34
		{
35
			$jodelAccount = new JodelAccount($row['device_uid']);
36
37
			if($jodelAccount->votePostId($_POST['postId'], $_POST['vote']))
38
			{
39
				$i++;
40
			}
41
		}
42
	}
43
	else
44
	{
45
		echo "Error: 0 results";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Error: 0 results 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...
46
	}
47
}
48
49
50
?>
51
<!DOCTYPE html>
52
<html lang="en">
53
	<head>
54
		<title>Backend - JodelBlue WebClient</title>
55
		
56
		<meta charset="utf8">
57
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
58
		<meta http-equiv="x-ua-compatible" content="ie=edge">
59
		
60
		<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.">
61
		<meta name="keywords" content="jodelblue, jodel, blue, webclient, web, client">
62
		
63
		<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">
64
				<link rel="stylesheet" href="<?php echo $baseUrl;?>css/font-awesome.min.css">
65
		<link rel="stylesheet" href="<?php echo $baseUrl;?>style.css" type="text/css">
66
		
67
		<link rel="shortcut icon" type="image/x-icon" href="<?php echo $baseUrl;?>img/favicon/favicon.ico">
68
		<link rel="icon" type="image/x-icon" href="<?php echo $baseUrl;?>img/favicon/favicon.ico">
69
		<link rel="icon" type="image/gif" href="<?php echo $baseUrl;?>img/favicon/favicon.gif">
70
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon.png">
71
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon.png">
72
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-57x57.png" sizes="57x57">
73
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-60x60.png" sizes="60x60">
74
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-72x72.png" sizes="72x72">
75
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-76x76.png" sizes="76x76">
76
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-114x114.png" sizes="114x114">
77
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-120x120.png" sizes="120x120">
78
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-128x128.png" sizes="128x128">
79
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-144x144.png" sizes="144x144">
80
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-152x152.png" sizes="152x152">
81
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-180x180.png" sizes="180x180">
82
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-precomposed.png">
83
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-16x16.png" sizes="16x16">
84
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-32x32.png" sizes="32x32">
85
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-96x96.png" sizes="96x96">
86
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-160x160.png" sizes="160x160">
87
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-192x192.png" sizes="192x192">
88
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-196x196.png" sizes="196x196">
89
		<meta name="msapplication-TileImage" content="<?php echo $baseUrl;?>img/favicon/win8-tile-144x144.png"> 
90
		<meta name="msapplication-TileColor" content="#5682a3"> 
91
		<meta name="msapplication-navbutton-color" content="#5682a3"> 
92
		<meta name="application-name" content="JodelBlue"/> 
93
		<meta name="msapplication-tooltip" content="JodelBlue"/> 
94
		<meta name="apple-mobile-web-app-title" content="JodelBlue"/> 
95
		<meta name="msapplication-square70x70logo" content="<?php echo $baseUrl;?>img/favicon/win8-tile-70x70.png"> 
96
		<meta name="msapplication-square144x144logo" content="<?php echo $baseUrl;?>img/favicon/win8-tile-144x144.png"> 
97
		<meta name="msapplication-square150x150logo" content="<?php echo $baseUrl;?>img/favicon/win8-tile-150x150.png"> 
98
		<meta name="msapplication-wide310x150logo" content="<?php echo $baseUrl;?>img/favicon/win8-tile-310x150.png"> 
99
		<meta name="msapplication-square310x310logo" content="<?php echo $baseUrl;?>img/favicon/win8-tile-310x310.png"> 
100
	</head>
101
	
102
	<body>
103
		<header>
104
			<nav class="navbar navbar-full navbar-dark navbar-fixed-top">
105
				<div class="container">					
106
						<h1>
107
						<a href="./" class="spinnable">
108
						
109
						JodelBlue <i class="fa fa-refresh fa-1x"></i></a>
110
					</h1>					
111
				</div>
112
			</nav>
113
		</header>
114
		
115
		<div class="mainContent container">		
116
			<div class="content row">
117
				<article class="topContent col-sm-8">
118
119
					<content id="posts" class="adminpanel">
120
						<h2>account management</h2>
121
						<form method="post">
122
							<div>
123
							<?php
124
								$result = $db->query("SELECT COUNT(*) FROM accounts");
125
								echo $result->fetch_row()[0];
126
							?>
127
							accounts in the database</div>
128
							<button type="submit" name="createAccount" value="TRUE">Create new Account</button>
129
						</form>
130
						<hr>
131
						<h2>Voting</h2>
132
							<input placeholder="quantity" id="quantityDelay" type="number" name="quantity"><br>
133
							<input placeholder="min interval" id="minDelay" value="<?php echo $config["minInterval"]?>" type="text" name="min"><br>
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal minInterval 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...
134
							<input placeholder="max interval" id="maxDelay" value="<?php echo $config["maxInterval"]?>" type="text" name="max"><br>
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal maxInterval 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...
135
							<input placeholder="postId" id="postIdDelay" value="<?php echo $_GET["postId"]?>" type="text" name="postId"><br>
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal postId 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...
136
							<button name="vote" value="up" class="half" onClick="vote('up');">Upvote</button>
137
							<button name="vote" value="down" class="half" onClick="vote('down');">Downvote</button><br>
138
							<progress id="progressDelay" value="0" max="100"></progress>
139
							<div id="ResponseMessage"></div>
140
							<div id="ResponseCaptcha"></div>	
141
					</content>
142
				</article>
143
			</div>
144
		</div>
145
		
146
		
147
		<!-- jQuery, Tether, Bootstrap JS and own-->
148
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha384-3ceskX3iaEnIogmQchP8opvBy3Mi7Ce34nWjpBIwVTHfGYWQS9jwHDVRnpKKHJg7" crossorigin="anonymous"></script>
149
    	<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.7/js/tether.min.js" integrity="sha384-XTs3FgkjiBgo8qjEjBk0tGmf3wPrWtA6coPfQDfFEY8AnYJwjalXCiosYRBIBZX8" crossorigin="anonymous"></script>
150
    	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/js/bootstrap.min.js" integrity="sha384-BLiI7JTZm+JWlgKa0M0kGRpJbF2J8q+qreVrKBC47e3K6BW78kGLrCkeRX6I9RoK" crossorigin="anonymous"></script>
151
152
		<script>
153
			//delayed voting
154
			var rekData;
155
			function vote(type)
156
			{
157
				var id = $("#postIdDelay").val();
158
				var quantity = parseInt($("#quantityDelay").val());
159
				var minTime = parseFloat($("#minDelay").val());
160
				var maxTime = parseFloat($("#maxDelay").val());	
161
				var data = {"vote": type,
162
						   "id":id,
163
							"i": 1,
164
						   "quantity":quantity,
165
						   "minTime":minTime,
166
						   "maxTime":maxTime};
167
				
168
				$("#progressDelay").attr("max", quantity);
169
				$("#progressDelay").val(0);
170
				if (minTime > maxTime)
171
				{
172
					$("#ResponseMessage").html("min interval is greater than max interval");
173
					
174
				}
175
				else if (id == "")
176
				{
177
					$("#ResponseMessage").html("please enter a postId");
178
				}
179
				else if (isNaN(quantity))
180
				{
181
					$("#ResponseMessage").html("please enter a valid quantity of votes");
182
				}
183
				else 
184
				{
185
					voteRek(data);
186
				}
187
			}
188
			
189
			function voteRek(data)
190
			{
191
				$.ajax({
192
				  type: "POST",
193
				  url: "<?php echo $baseUrl;?>vote-ajax.php?pw=<?php echo $_GET["pw"]?>",
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal pw 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...
194
				  data: {"vote" : data["vote"],
195
						 "postId" : data["id"]},
196
				  success: function(result){
197
					  $("#progressDelay").val(data["i"]);
198
					  var response;
199
					  try 
200
					  {
201
						response = JSON.parse(result);
202
					  } catch (e) {
203
						//voteRek(data);
204
					  }
205
					  if (response["success"] != true)
206
					  {
207
						  $("#ResponseMessage").html(response["message"]);
208
						  if (response["captcha"] != null) {
209
							  rekData = data;
210
							  $("#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["deviceUid"] + "');\">Verify</button></div>");
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 644 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...
211
							  //verifyAccount(data["i"], response["captcha"]["key"], response["deviceUid"]);
212
						  }
213
					  }
214
					  else if (data["i"] < data["quantity"])
215
					  {
216
						  $("#ResponseMessage").html(data["i"] + " of " + data["quantity"]);
217
						  data["i"] += 1;
218
						  setTimeout(function(){voteRek(data)}, getRandomFloat(data["minTime"],data["maxTime"])*1000);
219
					  } else {
220
						  $("#ResponseMessage").html(data["quantity"] + " votes completed");
221
					  }
222
				  }
223
				});
224
			}
225
			
226
			function verifyAccount(id, key, deviceUid)
227
			{
228
				var solution = "";
229
				for (i=0; i<9; i++) {
230
					var box = $("#box_"+i);
231
					if (box.is(':checked') == true)
232
					{
233
						if (solution != "")
234
						{
235
							solution += "-" + i;
236
						}
237
						else 
238
						{
239
							solution = i;
240
						}
241
242
					}
243
				}
244
				console.log(solution);
245
				$.ajax({
246
				  type: "POST",
247
				  url: "<?php echo $baseUrl;?>vote-ajax.php?pw=<?php echo $_GET["pw"]?>&solution=" + solution + "&key="+key,
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal pw 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...
248
				  data: {"deviceUid" : deviceUid},
249
				  success: function(result){
250
					  var response = JSON.parse(result);
251
					  console.log("Verification = "+response["success"])
252
					  $("#captchaWrapper_"+id).remove();
253
					  voteRek(rekData);
254
				  }
255
				});
256
			}
257
			
258
			function getRandomFloat(min, max)
259
			{
260
			  return Math.floor(Math.random() * (max - min)) + min;
261
			}
262
263
		</script>
264
	</body>
265
</html>