Completed
Push — master ( 5c086a...710747 )
by mains
07:28
created

vote-ajax.php (2 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
error_reporting(0);
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 vote-ajax.php');
8
	$respone = array("message" => $_SERVER['REMOTE_ADDR']  . ' used a wrong password on vote-ajax.php',"success" => false);
9
	echo json_encode($response);
10
	die();
11
}
12
else
13
{
14
15 View Code Duplication
if(isset($_GET['solution']) && isset($_GET['key']) && isset($_POST['deviceUid']))
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...
16
{
17
	$jodelAccount = new JodelAccount($_POST['deviceUid']);
18
	$response = array("success" => $jodelAccount->verifyCaptcha());
19
	echo json_encode($response);
20
	die();
21
}
22
23
$message = "";
24
$success = true;
25
$token = "";
26
	if(isset($_POST['vote']) && isset($_POST['postId']))
27
	{
28
		$i = 0;
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'] . "')");
30
31
		if($result->num_rows > 0)
32
		{
33
			$row = $result->fetch_assoc();
34
			$accessToken = $row['access_token'];
35
			$deviceUid = $row['device_uid'];
36
			
37
			$jodelAccount = new JodelAccount($deviceUid);
38
39
			if(!$jodelAccount->isAccountVerified())
40
			{
41
				$view = new View();
42
				$message = "This account is not verified. Please verify this account first.";
43
				$captcha = $view->getCaptcha($accessToken);
0 ignored issues
show
The method getCaptcha() does not seem to exist on object<View>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
				/* save captcha images
45
				$filename = explode("/", $captcha['image_url']);
46
				$filename = $filename[count($filename) - 1];
47
				if (!file_exists("captcha/".$filename))
48
				{
49
					$image = file_get_contents($captcha['image_url']);
50
					$fp = fopen("captcha/".$filename, 'w');
51
					fwrite($fp, $image);
52
					fclose($fp);
53
				}
54
				*/
55
					$captchaCodes = array("1CEAFRH69O" => "7-8",
56
									 "2QT6JRL06T" => "1-2",
57
									 "4GEIEE5P8P" => "2-6-8",
58
									 "5VI2JTJYWY" => "0-5",
59
									 "6UHC4L53DG" => "0-2-3",
60
									 "18FTBXVIJC" => "1-3-5",
61
									 "AKWROEYSD3" => "1-5-7",
62
									 "BL5901E1JS" => "0-4",
63
									 "BNB1P58AJ6" => "4",
64
									 "CORKCXU0TA" => "2-4-5",
65
									 "D3SKGYMB0C" => "1",
66
									 "DB96PZYUM7" => "2-7",
67
									 "EJSHC2LTY1" => "5-6-8",
68
									 "G6X12MP9DW" => "3",
69
									 "IGDPXAFRE8" => "1-6-7",
70
									 "IH92Z2ETIE" => "1-2-7",
71
									 "JGA66GP5TG" => "1-5-8",
72
									 "KUD8PU6UAB" => "5",
73
									 "MF7ZX46TQQ" => "0-1-8",
74
									 "MFDV8CMHHG" => "2-7-8",
75
									 "MI9R8R1YIZ" => "1-7-8",
76
									 "NI1A0RU1VJ" => "3-4-6",
77
									 "OFJP966MXD" => "1-4-6",
78
									 "OQZBADCV8I" => "2-5-8",
79
									 "QNLPAJ8XGM" => "3-7-8",
80
									 "RXNR1VZPUC" => "0-4-6",
81
									 "YLJB76EJDY" => "3-4",
82
									 "YO9E3X95IG" => "0-1-7",
83
									 "ZJP7PW2LRG" => "4-5");
84
					$filename = explode("/", $captcha['image_url']);
85
					$filename = explode(".", $filename[count($filename) - 1])[0];
86
					$_GET['solution'] = $captchaCodes[$filename];
87
					$_GET['key'] = $captcha["key"];
88
					$_GET['deviceUid'] = $deviceUid;
89
					$response = array("success" => $jodelAccount->verifyCaptcha());
90
					echo json_encode($response);
91
					die();
92
				$success = false;
93
			}
94
			else
95
			{
96
				$jodelAccount->votePostId($_POST['postId'], $_POST['vote']);
97
			}
98
		}
99
		else
100
		{
101
			$message = 'There is no account available for this jodel. Please create at least one new account to vote this jodel.';
102
			$success = false;
103
		}
104
	}
105
106
if (isset($captcha))
107
{
108
	$response = array("success" => $success, "message" => $message, "captcha" => $captcha, "deviceUid" => $deviceUid);
109
}
110
else 
111
{
112
	$response = array("success" => $success, "message" => $message);
113
}
114
}
115
echo json_encode($response);
116
?>