Skip to content

Commit 6631b88

Browse files
committed
Release 2.1
0 parents  commit 6631b88

29 files changed

+2373
-0
lines changed

MinecraftUUID.php

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
<?php
2+
class MinecraftProfile {
3+
private $username;
4+
private $uuid;
5+
private $properties;
6+
7+
/**
8+
* @param string $username The player's username.
9+
* @param string $uuid The player's UUID.
10+
* @param array $properties The player's properties specified on their Mojang profile.
11+
*/
12+
function __CONSTRUCT($username, $uuid, $properties = array()) {
13+
$this->username = $username;
14+
$this->uuid = $uuid;
15+
$this->properties = $properties;
16+
}
17+
18+
/**
19+
* @return string The player's username.
20+
*/
21+
public function getUsername() {
22+
return $this->username;
23+
}
24+
25+
/**
26+
* @return string The player's UUID.
27+
*/
28+
public function getUUID() {
29+
return $this->uuid;
30+
}
31+
32+
/**
33+
* @return array The player's properties listed on their mojang profile.
34+
*/
35+
public function getProperties() {
36+
return $this->properties;
37+
}
38+
39+
/**
40+
* @return array Returns an array with keys of 'properties, usernname and uuid'.
41+
*/
42+
public function getProfileAsArray() {
43+
return array("username" => $this->username, "uuid" => $this->uuid, "properties" => $this->properties);
44+
}
45+
}
46+
47+
class ProfileUtils {
48+
/**
49+
* @param string $identifier Either the player's Username or UUID.
50+
* @param int $timeout The length in seconds of the http request timeout.
51+
* @return MinecraftProfile|null Returns null if fetching of profile failed. Else returns completed user profile.
52+
*/
53+
public static function getProfile($identifier, $timeout = 5) {
54+
if(strlen($identifier) <= 16){
55+
$identifier = ProfileUtils::getUUIDFromUsername($identifier, $timeout);
56+
$url = "https://sessionserver.mojang.com/session/minecraft/profile/".$identifier['uuid'];
57+
} else {
58+
$url = "https://sessionserver.mojang.com/session/minecraft/profile/".$identifier;
59+
}
60+
$ctx = stream_context_create(
61+
array(
62+
'http' => array(
63+
'timeout' => $timeout
64+
)
65+
)
66+
);
67+
$ret = file_get_contents($url, 0, $ctx);
68+
if(isset($ret) && $ret != null && $ret != false) {
69+
$data = json_decode($ret, true);
70+
return new MinecraftProfile($data['name'], $data['id'], $data['properties']);
71+
}else {
72+
return null;
73+
}
74+
}
75+
76+
/**
77+
* @param int $timeout http timeout in seconds
78+
* @param $username string Minecraft username.
79+
* @return array (Key => Value) "username" => Minecraft username (properly capitalized) "uuid" => Minecraft UUID
80+
*/
81+
public static function getUUIDFromUsername($username, $timeout = 5) {
82+
if(strlen($username) > 16)
83+
return array("username" => "", "uuid" => "");
84+
$url = 'https://api.mojang.com/profiles/minecraft';
85+
$options = array(
86+
'http' => array(
87+
'header' => "Content-type: application/json\r\n",
88+
'method' => 'POST',
89+
'content' => '["'.$username.'"]',
90+
'timeout' => $timeout
91+
),
92+
);
93+
$context = stream_context_create($options);
94+
$result = file_get_contents($url, false, $context);
95+
96+
// Verification
97+
if(isset($result) && $result != null && $result != false)
98+
{
99+
$ress = json_decode($result, true);
100+
$ress = $ress[0];
101+
$res = Array("username" => $ress['name'], "uuid" => $ress['id']);
102+
return $res;
103+
}
104+
else
105+
return null;
106+
}
107+
108+
/**
109+
* @param $usernames array of usernames to be collected. Maximum of 100 usernames.
110+
* @param int $timeout http timeout in seconds
111+
* @return array of array (Key => Value) "username" => Minecraft username (properly capitalized) "uuid" => Minecraft UUID
112+
*/
113+
public static function getUUIDsFromUsernames($usernames, $timeout = 5){
114+
$usernames = array_splice($usernames, 0, 100);
115+
foreach($usernames as $user)
116+
if(strlen($user) > 16)
117+
return array("username" => "", "uuid" => "");
118+
119+
$url = 'https://api.mojang.com/profiles/minecraft';
120+
$first = true;
121+
$contents = "[";
122+
foreach ($usernames as $user) {
123+
if(!$first) {
124+
$contents .= ", ";
125+
}
126+
$contents .= '"' . $user . '"';
127+
$first = false;
128+
}
129+
$contents = "]";
130+
131+
$options = array(
132+
'http' => array(
133+
'header' => "Content-type: application/json\r\n",
134+
'method' => 'POST',
135+
'content' => $contents,
136+
'timeout' => $timeout
137+
)
138+
);
139+
140+
$context = stream_context_create($options);
141+
$result = file_get_contents($url, false, $context);
142+
143+
// Verification
144+
if(isset($result) && $result != null && $result != false)
145+
{
146+
$output = array();
147+
$ress = json_decode($result, true);
148+
for($i = 0; $i < count($ress); $i++){
149+
$ress = $ress[$i];
150+
$res = Array("username" => $ress['name'], "uuid" => $ress['id']);
151+
array_push($output, $res);
152+
}
153+
154+
return $output;
155+
}
156+
else
157+
return null;
158+
}
159+
160+
/**
161+
* @param $uuid string UUID to format
162+
* @return string Properly formatted UUID (According to UUID v4 Standards xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx WHERE y = 8,9,A,or B and x = random digits.)
163+
*/
164+
public static function formatUUID($uuid) {
165+
$uid = "";
166+
$uid .= substr($uuid, 0, 8)."-";
167+
$uid .= substr($uuid, 8, 4)."-";
168+
$uid .= substr($uuid, 12, 4)."-";
169+
$uid .= substr($uuid, 16, 4)."-";
170+
$uid .= substr($uuid, 20);
171+
return $uid;
172+
}
173+
}

accounts.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
if(!file_exists("mysql.php")){
3+
header("Location: setup/index.php");
4+
exit;
5+
}
6+
session_start();
7+
require("datamanager.php");
8+
require('assets/languages/lang_'.getSetting("lang").'.php');
9+
if(!isset($_SESSION["username"])){
10+
?>
11+
<meta http-equiv="refresh" content="0; URL=login.php">
12+
<?php
13+
exit;
14+
} else if(!getAccountRank($_SESSION["username"]) > 1){
15+
?>
16+
<meta http-equiv="refresh" content="0; URL=mytickets.php">
17+
<?php
18+
exit;
19+
}
20+
?>
21+
<!DOCTYPE html>
22+
<html lang="en" dir="ltr">
23+
<head>
24+
<meta charset="utf-8">
25+
<title>Accounts</title>
26+
<link rel="stylesheet" href="assets/css/main.css">
27+
<link href="https://fonts.googleapis.com/css?family=Quicksand&display=swap" rel="stylesheet">
28+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
29+
<script
30+
src="https://code.jquery.com/jquery-3.4.1.min.js"
31+
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
32+
crossorigin="anonymous"></script>
33+
<link rel="stylesheet" href="assets/css/jquery.sweet-modal.min.css" />
34+
<script src="assets/js/jquery.sweet-modal.min.js"></script>
35+
</head>
36+
<body>
37+
<div class="flex">
38+
<div class="flex-item">
39+
<script type="text/javascript">
40+
function openConfirm(name){
41+
$.sweetModal.confirm('Do you want to delete <strong>'+name+'</strong>?', function() {
42+
var request = new XMLHttpRequest();
43+
request.open('post', 'ajax.php?del', true);
44+
request.send("name="+name);
45+
$.sweetModal({
46+
content: '<strong>'+name+'</strong> was successfully deleted!',
47+
icon: $.sweetModal.ICON_SUCCESS
48+
});
49+
});
50+
}
51+
</script>
52+
<h1>Accounts</h1>
53+
<?php
54+
require("mysql.php");
55+
$stmt = $mysql->prepare("SELECT * FROM accounts");
56+
$stmt->execute();
57+
?>
58+
<table>
59+
<tr>
60+
<th>Username</th>
61+
<th>Email</th>
62+
<th>Last login</th>
63+
<th>First login</th>
64+
<th>Rank</th>
65+
<th>Action</th>
66+
</tr>
67+
<?php
68+
while ($row = $stmt->fetch()) {
69+
?>
70+
<tr>
71+
<td><?php echo $row["USERNAME"]; ?></td>
72+
<td><?php echo $row["EMAIL"]; ?></td>
73+
<td><?php echo displayTimestamp($row["LASTLOGIN"]); ?></td>
74+
<td><?php echo displayTimestamp($row["FIRSTLOGIN"]); ?></td>
75+
<td><?php
76+
if(getAccountRank($row["USERNAME"]) == 0){
77+
echo "User";
78+
} if(getAccountRank($row["USERNAME"]) == 1){
79+
echo "Team";
80+
} else {
81+
echo "Admin";
82+
}
83+
?></td>
84+
<td><?php
85+
if(!getAccountRank($row["USERNAME"]) == 3){
86+
?>
87+
<button onclick="openConfirm('<?php echo $row["USERNAME"]; ?>');" class="btn"><i class="fas fa-trash"></i></button>
88+
<?php
89+
}
90+
?>
91+
<button onclick="openConfirm('<?php echo $row["USERNAME"]; ?>');" class="btn"><i class="fas fa-trash"></i></button>
92+
93+
</td>
94+
</tr>
95+
<?php
96+
}
97+
?>
98+
</table>
99+
</div>
100+
<div class="flex-item sidebar">
101+
<?php require('assets/inc/sidebar.inc.php'); ?>
102+
</div>
103+
</div>
104+
</body>
105+
</html>

addcategory.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
if(!file_exists("mysql.php")){
3+
header("Location: setup/index.php");
4+
exit;
5+
}
6+
session_start();
7+
require("datamanager.php");
8+
require('assets/languages/lang_'.getSetting("lang").'.php');
9+
if(!isset($_SESSION["username"])){
10+
?>
11+
<meta http-equiv="refresh" content="0; URL=login.php">
12+
<?php
13+
exit;
14+
} else if(getAccountRank($_SESSION["username"]) < 3){
15+
?>
16+
<meta http-equiv="refresh" content="0; URL=mytickets.php">
17+
<?php
18+
exit;
19+
}
20+
?>
21+
<!DOCTYPE html>
22+
<html lang="en" dir="ltr">
23+
<head>
24+
<meta charset="utf-8">
25+
<title><?php echo CAT_CREATE_HEADING; ?></title>
26+
<link rel="stylesheet" href="assets/css/main.css">
27+
<link href="https://fonts.googleapis.com/css?family=Quicksand&display=swap" rel="stylesheet">
28+
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
29+
</head>
30+
<body>
31+
<div class="flex">
32+
<div class="flex-item">
33+
<?php
34+
require("mysql.php");
35+
if(isset($_POST["submit"])){
36+
$stmt = $mysql->prepare("INSERT INTO categorys (NAME, STATUS)
37+
VALUES (:cat, 0)");
38+
$stmt->bindParam(":cat", $_POST["name"], PDO::PARAM_STR);
39+
$stmt->execute();
40+
?>
41+
<meta http-equiv="refresh" content="0; URL=admin.php">
42+
<?php
43+
}
44+
?>
45+
<h1><?php echo CAT_CREATE_HEADING; ?></h1>
46+
<form action="addcategory.php" method="post">
47+
<input type="text" name="name" placeholder="<?php echo CATEGORY; ?>" minlength="3" required><br>
48+
<button type="submit" name="submit"><?php echo ADD; ?></button><br>
49+
</form>
50+
</div>
51+
<div class="flex-item sidebar">
52+
<?php require('assets/inc/sidebar.inc.php'); ?>
53+
</div>
54+
</div>
55+
</body>
56+
</html>

addfaq.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
if(!file_exists("mysql.php")){
3+
header("Location: setup/index.php");
4+
exit;
5+
}
6+
session_start();
7+
require("datamanager.php");
8+
require('assets/languages/lang_'.getSetting("lang").'.php');
9+
if(!isset($_SESSION["username"])){
10+
?>
11+
<meta http-equiv="refresh" content="0; URL=login.php">
12+
<?php
13+
exit;
14+
} else if(getAccountRank($_SESSION["username"]) < 3){
15+
?>
16+
<meta http-equiv="refresh" content="0; URL=mytickets.php">
17+
<?php
18+
exit;
19+
}
20+
?>
21+
<!DOCTYPE html>
22+
<html lang="en" dir="ltr">
23+
<head>
24+
<meta charset="utf-8">
25+
<title><?php echo FAQ_CREATE_HEADING; ?></title>
26+
<link rel="stylesheet" href="assets/css/main.css">
27+
<link href="https://fonts.googleapis.com/css?family=Quicksand&display=swap" rel="stylesheet">
28+
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
29+
</head>
30+
<body>
31+
<div class="flex">
32+
<div class="flex-item">
33+
<?php
34+
require("mysql.php");
35+
if(isset($_POST["submit"])){
36+
$stmt = $mysql->prepare("INSERT INTO faq (QUESTION, ANSWER)
37+
VALUES (:q, :a)");
38+
$stmt->bindParam(":q", $_POST["question"], PDO::PARAM_STR);
39+
$stmt->bindParam(":a", $_POST["answer"], PDO::PARAM_STR);
40+
$stmt->execute();
41+
?>
42+
<meta http-equiv="refresh" content="0; URL=admin.php">
43+
<?php
44+
}
45+
?>
46+
<h1><?php echo FAQ_CREATE_HEADING; ?></h1>
47+
<form action="addfaq.php" method="post">
48+
<input type="text" name="question" placeholder="<?php echo QUESTION; ?>" minlength="3" required><br>
49+
<textarea name="answer" rows="8" cols="80" placeholder="<?php echo ANSWER; ?>" minlength="16" required></textarea><br>
50+
<button type="submit" name="submit"><?php echo ADD; ?></button><br>
51+
</form>
52+
</div>
53+
<div class="flex-item sidebar">
54+
<?php require('assets/inc/sidebar.inc.php'); ?>
55+
</div>
56+
</div>
57+
</body>
58+
</html>

0 commit comments

Comments
 (0)