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

admin.php (15 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
							<button type="submit" name="createAccount" value="TRUE">Create new Account</button>
140
						</form>
141
						<hr>
142
						<h2>voting</h2>
143
						<form method="post">
144
							<input placeholder="quantity" type="number" name="quantity"><br>
145
							<input placeholder="postId" type="text" name="postId"><br>
146
							<button type="submit" name="vote" value="up" class="half">Upvote</button>
147
							<button type="submit" name="vote" value="down" class="half">Downvote</button>
148
						</form>
149
						<hr>
150
						<h2>delayed voting</h2>
151
							<input placeholder="quantity" id="quantityDelay" type="number" name="quantity"><br>
152
							<input placeholder="min interval" id="minDelay" type="text" name="min"><br>
153
							<input placeholder="max interval" id="maxDelay" type="text" name="max"><br>
154
							<input placeholder="postId" id="postIdDelay" type="text" name="postId"><br>
155
							<button name="vote" value="up" class="half" onClick="vote('up');">Upvote</button>
156
							<button name="vote" value="down" class="half" onClick="vote('down');">Downvote</button><br>
157
							<progress id="progressDelay" value="0" max="100"></progress>
158
						
159
							<div id="ResponseMessage"></div>
160
							<div id="ResponseCaptcha"></div>
161
						
162
					</content>
163
				</article>
164
			
165
				<aside class="topSidebar col-sm-4 sidebar-outer">
166
					<div class="fixed">
167
						<article>
168
							
169
						</article>
170
					</div>
171
				</aside>
172
			</div>
173
			<div id="sortJodelBy" class="row">
174
				<div class="col-sm-12">
175
					<div class="row">
176
						
177
					</div>
178
				</div>	
179
			</div>
180
		</div>
181
		
182
		
183
		<!-- jQuery, Tether, Bootstrap JS and own-->
184
		<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...
185
    	<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...
186
    	<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...
187
    	<script src="js/jQueryEmoji.js"></script>
188
189
		<script>
190
			//delayed voting
191
			var rekData;
192
			function vote(type)
193
			{
194
				var id = $("#postIdDelay").val();
195
				var quantity = parseInt($("#quantityDelay").val());
196
				var minTime = parseFloat($("#minDelay").val());
197
				var maxTime = parseFloat($("#maxDelay").val());
198
								
199
				var data = {"vote": type,
200
						   "id":id,
201
							"i": 1,
202
						   "quantity":quantity,
203
						   "minTime":minTime,
204
						   "maxTime":maxTime};
205
				
206
				$("#progressDelay").attr("max", quantity);
207
				$("#progressDelay").val(0);
208
				voteRek(data);
209
			}
210
			
211
			function voteRek(data)
212
			{
213
				$.ajax({
214
				  type: "POST",
215
				  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...
216
				  data: {"vote" : data["vote"],
217
						 "postId" : data["id"]},
218
				  success: function(result){
219
					  $("#progressDelay").val(data["i"]);
220
					  var response = JSON.parse(result);
221
					  if (response["success"] != true)
222
					  {
223
						  $("#ResponseMessage").html(response["message"]);
224
						  if (response["captcha"] != null) {
225
							  rekData = data;
226
							  $("#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...
227
						  }
228
					  }
229
					  else if (data["i"] < data["quantity"])
230
					  {
231
						  $("#ResponseMessage").html(data["i"] + " of " + data["quantity"]);
232
						  data["i"] += 1;
233
						  setTimeout(function(){voteRek(data)}, getRandomFloat(data["minTime"],data["maxTime"])*1000);
234
					  } else {
235
						  $("#ResponseMessage").html(data["quantity"] + " votes completed");
236
					  }
237
				  }
238
				});
239
			}
240
			
241
			function verifyAccount(id, key, token)
242
			{
243
				var solution = $("#captcha_"+id).val();
244
				$.ajax({
245
				  type: "POST",
246
				  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...
247
				  data: {"accessToken" : token},
248
				  success: function(result){
249
					  var response = JSON.parse(result);
250
					  console.log("Verification = "+response["success"])
251
					  $("#captchaWrapper_"+id).remove();
252
					  voteRek(rekData);
253
				  }
254
				});
255
			}
256
			
257
			function getRandomFloat(min, max)
258
			{
259
			  return Math.floor(Math.random() * (max - min)) + min;
260
			}
261
			
262
			//BackButton
263
			function goBack()
264
			{
265
				window.history.back();
266
			}
267
268
			$(document).ready(function()
269
			{
270
271
272
				//Transform UTF-8 Emoji to img
273
				$('.jodel > content').Emoji();
274
275
				$('a').on('click', function(){
276
				    $('a').removeClass('selected');
277
				    $(this).addClass('selected');
278
				});
279
280
				function scrollToAnchor(aid){
281
				    var aTag = $("article[id='"+ aid +"']");
282
				    $('html,body').animate({scrollTop: aTag.offset().top-90},'slow');
283
				}
284
			});	
285
286
		</script>
287
	</body>
288
</html>