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

admin.php (5 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;
24
	$userIsVoter = true;
25
}
26
else if(isUserVoter())
27
{
28
	$userIsAdmin = false;
29
	$userIsVoter = true;
30
}
31
else
32
{
33
	error_log($_SERVER['REMOTE_ADDR']  . ' used a wrong voterPw / pw on admin.php');
34
	die();
35
}
36
37
38
if($userIsAdmin && isset($_POST['createAccount']) && $_POST['createAccount'])
39
{
40
	$newJodelAccount = new JodelAccount();
41
}
42
43
if($userIsAdmin && isset($_POST['createVoter']) && $_POST['createVoter'])
44
{
45
	//insert voter into db
46
	$db = new DatabaseConnect();
47
    $result = $db->query("INSERT INTO users (user_token, remaining_votes, device_uid, rights)
48
                    VALUES ('" 	. $db->escape_string($_POST['user_token'])
49
                    	. "','" . $db->escape_string($_POST['remaining_votes'])
50
                    	. "','" . $db->escape_string($_POST['device_uid'])
51
                    	. "','" . $db->escape_string($_POST['rights']) . "')");
52
    
53 View Code Duplication
    if($result === false){
54
            $error = db_error();
55
            error_log($error);
56
            error_log("Adding Voter failed: (" . $result->errno . ") " . $result->error);
57
    } 
58
}
59
60
//Vote
61
/*
62
if($userIsVoter && isset($_POST['vote']) && isset($_POST['postId']) && isset($_POST['quantity']))
63
{
64
	$i = 0;
65
	$result = $db->query("SELECT access_token, device_uid FROM accounts WHERE device_uid NOT IN (SELECT device_uid FROM votes WHERE postId = '" . $_POST['postId'] . "')");
66
67
	if($result->num_rows > 0)
68
	{
69
		// output data of each row
70
		while(($row = $result->fetch_assoc()) && $i < $_POST['quantity'])
71
		{
72
			$jodelAccount = new JodelAccount($row['device_uid']);
73
74
			if($jodelAccount->votePostId($_POST['postId'], $_POST['vote']))
75
			{
76
				$i++;
77
			}
78
		}
79
	}
80
	else
81
	{
82
		error_log("Error: 0 results");
83
	}
84
}
85
*/
86
87
?>
88
<!DOCTYPE html>
89
<html lang="en">
90
	<head>
91
		<title>Backend - JodelBlue WebClient</title>
92
		
93
		<meta charset="utf8">
94
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
95
		<meta http-equiv="x-ua-compatible" content="ie=edge">
96
		
97
		<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.">
98
		<meta name="keywords" content="jodelblue, jodel, blue, webclient, web, client">
99
		
100
		<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">
101
				<link rel="stylesheet" href="<?php echo $baseUrl;?>css/font-awesome.min.css">
102
		<link rel="stylesheet" href="<?php echo $baseUrl;?>style.css" type="text/css">
103
		
104
		<link rel="shortcut icon" type="image/x-icon" href="<?php echo $baseUrl;?>img/favicon/favicon.ico">
105
		<link rel="icon" type="image/x-icon" href="<?php echo $baseUrl;?>img/favicon/favicon.ico">
106
		<link rel="icon" type="image/gif" href="<?php echo $baseUrl;?>img/favicon/favicon.gif">
107
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon.png">
108
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon.png">
109
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-57x57.png" sizes="57x57">
110
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-60x60.png" sizes="60x60">
111
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-72x72.png" sizes="72x72">
112
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-76x76.png" sizes="76x76">
113
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-114x114.png" sizes="114x114">
114
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-120x120.png" sizes="120x120">
115
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-128x128.png" sizes="128x128">
116
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-144x144.png" sizes="144x144">
117
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-152x152.png" sizes="152x152">
118
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-180x180.png" sizes="180x180">
119
		<link rel="apple-touch-icon" href="<?php echo $baseUrl;?>img/favicon/apple-touch-icon-precomposed.png">
120
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-16x16.png" sizes="16x16">
121
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-32x32.png" sizes="32x32">
122
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-96x96.png" sizes="96x96">
123
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-160x160.png" sizes="160x160">
124
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-192x192.png" sizes="192x192">
125
		<link rel="icon" type="image/png" href="<?php echo $baseUrl;?>img/favicon/favicon-196x196.png" sizes="196x196">
126
		<meta name="msapplication-TileImage" content="<?php echo $baseUrl;?>img/favicon/win8-tile-144x144.png"> 
127
		<meta name="msapplication-TileColor" content="#5682a3"> 
128
		<meta name="msapplication-navbutton-color" content="#5682a3"> 
129
		<meta name="application-name" content="JodelBlue"/> 
130
		<meta name="msapplication-tooltip" content="JodelBlue"/> 
131
		<meta name="apple-mobile-web-app-title" content="JodelBlue"/> 
132
		<meta name="msapplication-square70x70logo" content="<?php echo $baseUrl;?>img/favicon/win8-tile-70x70.png"> 
133
		<meta name="msapplication-square144x144logo" content="<?php echo $baseUrl;?>img/favicon/win8-tile-144x144.png"> 
134
		<meta name="msapplication-square150x150logo" content="<?php echo $baseUrl;?>img/favicon/win8-tile-150x150.png"> 
135
		<meta name="msapplication-wide310x150logo" content="<?php echo $baseUrl;?>img/favicon/win8-tile-310x150.png"> 
136
		<meta name="msapplication-square310x310logo" content="<?php echo $baseUrl;?>img/favicon/win8-tile-310x310.png"> 
137
	</head>
138
	
139
	<body>
140
		<header>
141
			<nav class="navbar navbar-full navbar-dark navbar-fixed-top">
142
				<div class="container">					
143
						<h1>
144
						<a href="./admin.php" class="spinnable">
145
						
146
						JodelBlue <i class="fa fa-refresh fa-1x"></i></a>
147
					</h1>					
148
				</div>
149
			</nav>
150
		</header>
151
		
152
		<div class="mainContent container">		
153
			<div class="content row">
154
				<article class="topContent col-sm-8">
155
156
					<content id="posts" class="adminpanel">
157
						<?php if($userIsAdmin) { ?>
158
						<h2>account management</h2>
159
						<form method="post">
160
							<div>
161
							<?php
162
								$result = $db->query("SELECT COUNT(*) FROM accounts");
163
								echo $result->fetch_row()[0];
164
							?>
165
							accounts in the database</div>
166
							<button type="submit" name="createAccount" value="TRUE">Create new Account</button>
167
						</form>
168
						<br>
169
						<h3>Create Voter</h3>
170
						<form method="post">
171
							<div>
172
							<input type="text" name="user_token" placeholder="user_token" required="true"><br>
173
							<input type="number" name="remaining_votes" placeholder="remaining_votes" required="true"><br>
174
							<input type="text" name="device_uid" placeholder="device_uid" required="true"><br>
175
							<input type="text" name="rights" placeholder="rights" required="true"><br>
176
							<button type="submit" name="createVoter" value="TRUE">Create new Voter</button>
177
						</form>
178
						<hr>
179
						<?php
180
						}
181
182
						if($userIsVoter) {
183
						?>
184
						<h2>Voting</h2>
185
						<form>
186
							<input placeholder="quantity" id="quantityDelay" type="number" name="quantity"><br>
187
							<input placeholder="min interval" id="minDelay" value="<?php echo $config['minInterval'];?>" type="text" name="min"><br>
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 127 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...
188
							<input placeholder="max interval" id="maxDelay" value="<?php echo $config['maxInterval'];?>" type="text" name="max"><br>
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 127 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...
189
							<input placeholder="postId" id="postIdDelay" value="<?php if(isset($_GET['postId'])) echo $_GET['postId'];?>" type="text" name="postId"><br>
190
							<button type="button" name="vote" value="up" class="half" onclick="voteWithAjax('up');">Upvote</button>
191
							<button type="button" name="vote" value="down" class="half" onclick="voteWithAjax('down');">Downvote</button><br>
192
						</form>
193
							<progress id="progressDelay" value="0" max="100"></progress>
194
							<div id="ResponseMessage"></div>
195
							<div id="ResponseCaptcha"></div>
196
197
						<?php } ?>
198
					</content>
199
				</article>
200
			</div>
201
		</div>
202
		
203
		
204
		<!-- jQuery, Tether, Bootstrap JS and own-->
205
		<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...
206
    	<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...
207
    	<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...
208
209
		<script>
210
			//delayed voting
211
			var rekData;
212
			function voteWithAjax(type)
213
			{
214
				var id = $("#postIdDelay").val();
215
				var quantity = parseInt($("#quantityDelay").val());
216
				var minTime = parseFloat($("#minDelay").val());
217
				var maxTime = parseFloat($("#maxDelay").val());	
218
				var data = {"vote": type,
219
						   "id":id,
220
							"i": 1,
221
						   "quantity":quantity,
222
						   "minTime":minTime,
223
						   "maxTime":maxTime};
224
				
225
				$("#progressDelay").attr("max", quantity);
226
				$("#progressDelay").val(0);
227
				if (minTime > maxTime)
228
				{
229
					$("#ResponseMessage").html("min interval is greater than max interval");
230
					
231
				}
232
				else if (id == "")
233
				{
234
					$("#ResponseMessage").html("please enter a postId");
235
				}
236
				else if (isNaN(quantity))
237
				{
238
					$("#ResponseMessage").html("please enter a valid quantity of votes");
239
				}
240
				else 
241
				{
242
					voteRek(data);
243
				}
244
			}
245
			
246
			function voteRek(data)
247
			{
248
				$.ajax({
249
				  type: "POST",
250
				  url: "<?php echo $baseUrl;?>vote-ajax.php",
251
				  data: {"vote" : data["vote"],
252
						 "postId" : data["id"]},
253
				  success: function(result){
254
					  $("#progressDelay").val(data["i"]);
255
					  var response;
256
					  try 
257
					  {
258
						response = JSON.parse(result);
259
					  } catch (e) {
260
						//voteRek(data);
261
					  }
262
					  if (response["success"] != true)
263
					  {
264
						  $("#ResponseMessage").html(response["message"]);
265
						  if (response["captcha"] != null) {
266
							  rekData = data;
267
							  $("#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>");
268
							  //verifyAccount(data["i"], response["captcha"]["key"], response["deviceUid"]);
269
						  }
270
					  }
271
					  else if (data["i"] < data["quantity"])
272
					  {
273
						  $("#ResponseMessage").html(data["i"] + " of " + data["quantity"]);
274
						  data["i"] += 1;
275
						  setTimeout(function(){voteRek(data)}, getRandomFloat(data["minTime"],data["maxTime"])*1000);
276
					  } else {
277
						  $("#ResponseMessage").html(data["quantity"] + " votes completed");
278
					  }
279
				  }
280
				});
281
			}
282
			
283
			function verifyAccount(id, key, deviceUid)
284
			{
285
				var solution = "";
286
				for (i=0; i<9; i++) {
287
					var box = $("#box_"+i);
288
					if (box.is(':checked') == true)
289
					{
290
						if (solution != "")
291
						{
292
							solution += "-" + i;
293
						}
294
						else 
295
						{
296
							solution = i;
297
						}
298
299
					}
300
				}
301
				console.log(solution);
302
				$.ajax({
303
				  type: "POST",
304
				  url: "<?php echo $baseUrl;?>vote-ajax.php?solution=" + solution + "&key="+key,
305
				  data: {"deviceUid" : deviceUid},
306
				  success: function(result){
307
					  var response = JSON.parse(result);
308
					  console.log("Verification = "+response["success"])
309
					  $("#captchaWrapper_"+id).remove();
310
					  voteRek(rekData);
311
				  }
312
				});
313
			}
314
			
315
			function getRandomFloat(min, max)
316
			{
317
			  return Math.floor(Math.random() * (max - min)) + min;
318
			}
319
320
		</script>
321
	</body>
322
</html>