Completed
Pull Request — master (#10)
by
unknown
02:50
created

admin.php (16 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;
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...
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'] . "')");
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...
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";
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...
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.">
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...
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">
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...
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");
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...
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
						
165
							<div id="ResponseMessage"></div>
166
							<div id="ResponseCaptcha"></div>
167
						
168
					</content>
169
				</article>
170
			
171
				<aside class="topSidebar col-sm-4 sidebar-outer">
172
					<div class="fixed">
173
						<article>
174
							
175
						</article>
176
					</div>
177
				</aside>
178
			</div>
179
			<div id="sortJodelBy" class="row">
180
				<div class="col-sm-12">
181
					<div class="row">
182
						
183
					</div>
184
				</div>	
185
			</div>
186
		</div>
187
		
188
		
189
		<!-- jQuery, Tether, Bootstrap JS and own-->
190
		<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...
191
    	<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...
192
    	<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...
193
    	<script src="js/jQueryEmoji.js"></script>
194
195
		<script>
196
			//delayed voting
197
			var rekData;
198
			function vote(type)
199
			{
200
				var id = $("#postIdDelay").val();
201
				var quantity = parseInt($("#quantityDelay").val());
202
				var minTime = parseFloat($("#minDelay").val());
203
				var maxTime = parseFloat($("#maxDelay").val());
204
								
205
				var data = {"vote": type,
206
						   "id":id,
207
							"i": 1,
208
						   "quantity":quantity,
209
						   "minTime":minTime,
210
						   "maxTime":maxTime};
211
				
212
				$("#progressDelay").attr("max", quantity);
213
				$("#progressDelay").val(0);
214
				voteRek(data);
215
			}
216
			
217
			function voteRek(data)
218
			{
219
				$.ajax({
220
				  type: "POST",
221
				  url: "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...
222
				  data: {"vote" : data["vote"],
223
						 "postId" : data["id"]},
224
				  success: function(result){
225
					  $("#progressDelay").val(data["i"]);
226
					  var response = JSON.parse(result);
227
					  if (response["success"] != true)
228
					  {
229
						  $("#ResponseMessage").html(response["message"]);
230
						  if (response["captcha"] != null) {
231
							  rekData = data;
232
							  $("#ResponseCaptcha").append( "<div id='captchaWrapper_" + data["i"] + "'><img src='" + response["captcha"]["image_url"] + "' style='width:100%'><input type='text' id='captcha_"+ data["i"]  +"'><button onClick=\"verifyAccount(" + data["i"] + ", '" + response["captcha"]["key"] + "' , '" + response["accessToken"] + "');\">Verify</button></div>");
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 355 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...
233
						  }
234
					  }
235
					  else if (data["i"] < data["quantity"])
236
					  {
237
						  $("#ResponseMessage").html(data["i"] + " of " + data["quantity"]);
238
						  data["i"] += 1;
239
						  setTimeout(function(){voteRek(data)}, getRandomFloat(data["minTime"],data["maxTime"])*1000);
240
					  } else {
241
						  $("#ResponseMessage").html(data["quantity"] + " votes completed");
242
					  }
243
				  }
244
				});
245
			}
246
			
247
			function verifyAccount(id, key, token)
248
			{
249
				var solution = $("#captcha_"+id).val();
250
				$.ajax({
251
				  type: "POST",
252
				  url: "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...
253
				  data: {"accessToken" : token},
254
				  success: function(result){
255
					  var response = JSON.parse(result);
256
					  console.log("Verification = "+response["success"])
257
					  $("#captchaWrapper_"+id).remove();
258
					  voteRek(rekData);
259
				  }
260
				});
261
			}
262
			
263
			function getRandomFloat(min, max)
264
			{
265
			  return Math.floor(Math.random() * (max - min)) + min;
266
			}
267
			
268
			//BackButton
269
			function goBack()
270
			{
271
				window.history.back();
272
			}
273
274
			$(document).ready(function()
275
			{
276
277
278
				//Transform UTF-8 Emoji to img
279
				$('.jodel > content').Emoji();
280
281
				$('a').on('click', function(){
282
				    $('a').removeClass('selected');
283
				    $(this).addClass('selected');
284
				});
285
286
				function scrollToAnchor(aid){
287
				    var aTag = $("article[id='"+ aid +"']");
288
				    $('html,body').animate({scrollTop: aTag.offset().top-90},'slow');
289
				}
290
			});	
291
292
		</script>
293
	</body>
294
</html>