Completed
Push — master ( 027077...76536b )
by mains
02:56
created

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