This commit is contained in:
Timo Ley 2020-08-21 23:23:43 +02:00
commit 07a0c485bc
6 changed files with 218 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
vars.php
.idea

68
acapi.php Normal file
View File

@ -0,0 +1,68 @@
<?php
include 'vars.php';
$path = explode("/", $_SERVER["PATH_INFO"]);
$obj = new stdClass();
$obj->status = 404;
if($path[1] == "users") {
$users = array();
$query = "SELECT * FROM users";
if ($_GET["hasmc"] == "true") {
$query = addCondition("mcuuid IS NOT NULL", $query);
} elseif ($_GET["hasmc"] == "false") {
$query = addCondition("mcuuid IS NULL", $query);
}
$res_users = mysqli_query($accon, $query);
checksql($res_users);
while ($row = mysqli_fetch_array( $res_users, MYSQLI_ASSOC)) {
$user = new stdClass();
$user->id = $row["discord"];
if (isset($row["mcuuid"])) {
$minecraft = new stdClass();
$minecraft->uuid = $row["mcuuid"];
$user->minecraft = $minecraft;
}
$user->roles = explode(",", $row["roles"]);
if (isset($row["twchannel"])) {
$user->twitchlink = $row["twchannel"];
}
if (isset($row["ytchannel"])) {
$user->youtubelink = $row["ytchannel"];
}
array_push($users, $user);
}
mysqli_free_result($res_users);
$obj->users = $users;
$obj->status = 200;
}
else {
}
header('Content-Type: application/json');
echo json_encode($obj, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
function addCondition($cond, $query) {
if (strpos($query, "WHERE")) {
$query = $query . " AND " . $cond;
} else {
$query = $query . " WHERE " . $cond;
}
return $query;
}
function checksql($res) {
global $accon;
global $obj;
if (!$res) {
$obj->status = 500;
$obj->error = mysqli_error($accon);
}
}

39
acapi/discord.php Normal file
View File

@ -0,0 +1,39 @@
<?php
include '../vars.php';
global $dctoken;
if ($_GET["token"] != null) {
$dctoken = $_GET["token"];
}
$curl_h = curl_init('https://discord.com/api/users/' . $_GET["id"] . '/profile');
curl_setopt($curl_h, CURLOPT_HTTPHEADER,
array(
'Authorization: ' . $dctoken,
)
);
curl_setopt($curl_h, CURLOPT_RETURNTRANSFER, true);
$json = json_decode(curl_exec($curl_h));
$obj = new stdClass();
if ($json->{'user'} != null) {
$obj->status = 200;
$obj->username = $json->{'user'}->{'username'} . "#" . $json->{'user'}->{'discriminator'};
$obj->accounts = $json->{'connected_accounts'};
if (is_array($json->{'connected_accounts'})) {
foreach ($json->{'connected_accounts'} as $acc) {
if ($acc->{'type'} == "youtube") {
$obj->ytchannel = "https://www.youtube.com/channel/" . $acc->{'id'};
}
elseif ($acc->{'type'} == "twitch") {
$obj->twchannel = "https://www.twitch.tv/". $acc->{'name'};
}
}
}
} else {
$obj->status = 404;
}
echo stripslashes(json_encode($obj));

14
acapi/mcuuid.php Normal file
View File

@ -0,0 +1,14 @@
<?php
$curl_h = curl_init('https://api.minetools.eu/uuid/' . $_GET["id"]);
curl_setopt($curl_h, CURLOPT_RETURNTRANSFER, true);
$json = json_decode(curl_exec($curl_h));
$obj = new stdClass();
if ($json->{'status'} == "OK") {
$obj->status = 200;
$obj->uuid = $json->{'id'};
$obj->name = $json->{'name'};
} else {
$obj->status = 404;
}
echo json_encode($obj);

9
mpt.php Normal file
View File

@ -0,0 +1,9 @@
<?php
include "maven/mavenresolv.php";
if ($_SERVER["PATH_INFO"] == "/latest") {
header('Content-Type: text/plain');
echo "https://data.tilera.xyz/file/mpt/mpt-1.2-SNAPSHOT.jar";
} elseif ($_SERVER["PATH_INFO"] == "/latestnew") {
echo mavenLatest("ley.anvil", "modpacktools");
}

86
twitch.php Normal file
View File

@ -0,0 +1,86 @@
<?php
include 'vars.php';
global $twtoken;
if ($_SERVER['PATH_INFO'] == "/werfolgt" || $_SERVER['PATH_INFO'] == "/wemfolgt") {
if ($_GET["user"] != null) {
$curl_h = curl_init('https://id.twitch.tv/oauth2/validate');
curl_setopt($curl_h, CURLOPT_HTTPHEADER,
array(
'Authorization: Bearer ' . $twtoken,
)
);
curl_setopt($curl_h, CURLOPT_RETURNTRANSFER, true);
$json = json_decode(curl_exec($curl_h));
$client_id = $json->{'client_id'};
$curl_h = curl_init('https://api.twitch.tv/helix/users?login=' . $_GET["user"]);
curl_setopt($curl_h, CURLOPT_HTTPHEADER,
array(
'Authorization: Bearer ' . $twtoken,
'Client-ID: ' . $client_id,
)
);
curl_setopt($curl_h, CURLOPT_RETURNTRANSFER, true);
$json = json_decode(curl_exec($curl_h));
$userid = $json->{'data'}[0]->{'id'};
$username = $json->{'data'}[0]->{'display_name'};
if ($userid != null) {
if ($_SERVER['PATH_INFO'] == "/werfolgt") {
echo "<h1>" . $username . " wird gefolgt von:</h1>";
getFollows("from");
}
else if ($_SERVER['PATH_INFO'] == "/wemfolgt") {
echo "<h1>" . $username . " folgt:</h1>";
getFollows("to");
}
} else {
echo "Der Nutzer " . $_GET["user"] . " existiert nicht.";
}
} else {
echo "Nutzernamen angeben: ?user=(twitch username) an den Link anhängen";
}
} else {
echo "<a href='/api/twitch.php/werfolgt'>Wer folgt...</a><br><a href='/api/twitch.php/wemfolgt'>Wem folgt...</a><br>";
}
function getFollows($dir) {
$cursor = null;
do {
$json = req($cursor, $dir);
$cursor = $json->{'pagination'}->{'cursor'};
foreach ($json->{'data'} as $fol) {
echo "<a href='https://twitch.tv/" . $fol->{$dir . '_name'} . "'>" . $fol->{$dir . '_name'} . "</a></br>";
}
} while($cursor != null);
}
function req($cursor, $dir) {
global $client_id;
global $userid;
global $dctoken;
$side = "from";
if ($dir == "from")
$side = "to";
if ($cursor == null) {
$curl_h = curl_init('https://api.twitch.tv/helix/users/follows?' . $side . '_id='. $userid . '&first=100');
}
else {
$curl_h = curl_init('https://api.twitch.tv/helix/users/follows?' . $side . '_id=' . $userid .'&first=100&after=' . $cursor);
}
curl_setopt($curl_h, CURLOPT_HTTPHEADER,
array(
'Authorization: Bearer ' . $dctoken,
'Client-ID: ' . $client_id,
)
);
curl_setopt($curl_h, CURLOPT_RETURNTRANSFER, true);
return json_decode(curl_exec($curl_h));
}