First release of 2.0! :D

This commit is contained in:
Wruczek
2018-12-27 18:59:49 +01:00
parent 7396a76816
commit 628af52b54
293 changed files with 12641 additions and 3 deletions

87
src/api/getclientinfo.php Normal file
View File

@@ -0,0 +1,87 @@
<?php
use Wruczek\TSWebsite\CacheManager;
require_once __DIR__ . "/../private/php/load.php";
if (empty($_GET["cldbid"])) {
$returnJson = ["success" => false, "message" => "No CLDBID provided"];
} else {
$cldbid = (int) $_GET["cldbid"];
$clientList = CacheManager::i()->getClientList();
$clientData = null;
foreach ($clientList as $client) {
if ($client["client_database_id"] === $cldbid) {
$clientData = $client;
break;
}
}
if ($clientData !== null) {
$returnJson = [
"success" => true,
"timenow" => time(),
"data" => buildInfoArray($clientData)
];
} else {
$returnJson = ["success" => false, "message" => "Client not found"];
}
}
header("Content-Type: application/json");
echo json_encode($returnJson);
// Helper function
function buildInfoArray($clientData) {
$ret = [];
$fields = [
"clid",
"cid",
"client_database_id",
"client_nickname",
"client_type",
"client_away",
"client_away_message",
"client_flag_talking",
"client_input_muted",
"client_output_muted",
"client_input_hardware",
"client_output_hardware",
"client_talk_power",
"client_is_talker",
"client_is_priority_speaker",
"client_is_recording",
"client_is_channel_commander",
"client_unique_identifier",
"client_servergroups",
"client_channel_group_id",
"client_channel_group_inherited_channel_id",
"client_version",
"client_platform",
"client_idle_time",
"client_created",
"client_lastconnected",
"client_icon_id",
"client_country",
"client_badges"
];
// Get wanted fields from the clientData, convert TS String Objects
// into normal strings and put everything into returnData
foreach ($fields as $field) {
$val = $clientData[$field];
if ($val instanceof TeamSpeak3_Helper_String) {
$val = (string) $val;
}
$ret[$field] = $val;
}
$ret["client_version_short"] = (string) TeamSpeak3_Helper_Convert::versionShort($ret["client_version"]);
$ret["client_servergroups_list"] = array_map("intval", explode(",", $ret["client_servergroups"]));
return $ret;
}

40
src/api/geticon.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
use Wruczek\TSWebsite\ServerIconCache;
require_once __DIR__ . "/../private/php/load.php";
if (!isset($_GET["iconid"])) {
http_response_code(400);
echo "You need to provide an iconid";
exit;
}
$iconId = $_GET["iconid"];
if (!is_numeric($iconId)) {
http_response_code(400);
echo "iconid need to be a numeric value";
exit;
}
$iconId = (int) $iconId;
if (ServerIconCache::isLocal($iconId)) {
header("Location: ../img/ts-icons/group_$iconId.svg");
return;
}
$iconIdUnsigned = ServerIconCache::unsignIcon($iconId);
$iconData = ServerIconCache::getIconBytes($iconIdUnsigned);
if ($iconData === null) {
http_response_code(404);
echo "404 icon not found";
exit;
}
header("Content-Type: " . TeamSpeak3_Helper_Convert::imageMimeType($iconData));
header('ETag: "' . $iconIdUnsigned . '"');
header('Cache-Control: only-if-cached');
echo $iconData;

54
src/api/getstatus.php Normal file
View File

@@ -0,0 +1,54 @@
<?php
use Wruczek\TSWebsite\CacheManager;
use Wruczek\TSWebsite\Config;
require_once __DIR__ . "/../private/php/load.php";
$sinfoMeta = CacheManager::i()->getServerInfo(true); // Server info + cache meta
$sinfo = $sinfoMeta["data"]; // Server info array
$returnJson = ["success" => false, "generated" => $sinfoMeta["time"]];
if ($sinfo !== null) {
// START Online Record
$onlineNow = $sinfo["virtualserver_clientsonline"] - $sinfo["virtualserver_queryclientsonline"];
$onlineRecord = (int) Config::get("onlinerecord_value");
$onlineRecordDate = (int) Config::get("onlinerecord_date");
if ($onlineNow > $onlineRecord) {
$onlineRecord = $onlineNow;
$onlineRecordDate = time();
Config::i()->setValue("onlinerecord_value", $onlineRecord);
Config::i()->setValue("onlinerecord_date", $onlineRecordDate);
}
// END Online Record
$returnJson["success"] = true;
$returnJson["data"] = [
"uid" => (string) $sinfo["virtualserver_unique_identifier"],
"name" => (string) $sinfo["virtualserver_name"],
"nicknames" => (string) $sinfo["virtualserver_nickname"],
"channelCount" => $sinfo["virtualserver_channelsonline"],
"serverIconId" => $sinfo["virtualserver_icon_id"],
"clientsOnline" => $onlineNow,
"maxClients" => $sinfo["virtualserver_maxclients"],
"reservedSlots" => $sinfo["virtualserver_reserved_slots"],
"onlineRecord" => $onlineRecord,
"onlineRecordDate" => $onlineRecordDate,
"version" => (string) TeamSpeak3_Helper_Convert::versionShort($sinfo["virtualserver_version"]),
"platform" => (string) $sinfo["virtualserver_platform"],
"uptime" => $sinfo["virtualserver_uptime"],
"uptimeFormatted" => describeSeconds($sinfo["virtualserver_uptime"]),
"averagePacketloss" => (float) ((string) $sinfo["virtualserver_total_packetloss_total"]),
"averagePing" => (float) ((string) $sinfo["virtualserver_total_ping"])
];
}
header("Content-Type: application/json");
echo json_encode($returnJson);
function describeSeconds($seconds) {
return TeamSpeak3_Helper_Convert::seconds($seconds, false, "%dd %02dh %02dm");
}

14
src/api/getviewerhtml.php Normal file
View File

@@ -0,0 +1,14 @@
<?php
use Wruczek\TSWebsite\ViewerRenderer;
require_once __DIR__ . "/../private/php/load.php";
$html = null;
$viewerRenderer = new ViewerRenderer("img/ts-icons");
if ($viewerRenderer->checkRequiredData()) {
$html = $viewerRenderer->renderViewer();
}
echo $html;

59
src/api/login.php Normal file
View File

@@ -0,0 +1,59 @@
<?php
use Wruczek\TSWebsite\Auth;
use Wruczek\TSWebsite\Utils\ApiUtils;
require_once __DIR__ . "/../private/php/load.php";
$method = ApiUtils::getPostParam("method");
if ($method === "logout") {
Auth::logout();
ApiUtils::jsonSuccess();
} else if ($method === "getclients") {
$users = Auth::getTsUsersByIp();
if ($users === null) {
ApiUtils::jsonError("Cannot retrieve client list", "ERROR_CLIENT_LIST");
} else {
ApiUtils::jsonSuccess(["data" => $users]);
}
} else if ($method === "selectaccount") {
$cldbid = (int) ApiUtils::getPostParam("cldbid");
if (!Auth::checkClientIp($cldbid)) {
ApiUtils::jsonError("User not found", "USER_NOT_FOUND");
exit;
}
if (Auth::getConfirmationCode($cldbid) !== null) {
ApiUtils::jsonError("Code is already generated for this user", "CODE_ALREADY_GENERATED");
exit;
}
$code = Auth::generateConfirmationCode($cldbid);
if ($code === null) {
ApiUtils::jsonError("User not found", "USER_NOT_FOUND");
} else if ($code === false) {
ApiUtils::jsonError("Error sending code. Try again.", "ERROR_SENDING_CODE");
} else {
ApiUtils::jsonSuccess();
}
} else if ($method === "login") {
if (Auth::isLoggedIn()) {
ApiUtils::jsonError("You are already logged in", "ALREADY_AUTHENTICATED");
exit;
}
$code = ApiUtils::getPostParam("code");
$cldbid = (int) ApiUtils::getPostParam("cldbid");
if (Auth::checkCodeAndLogin($cldbid, $code)) {
ApiUtils::jsonSuccess();
} else {
ApiUtils::jsonError("Invalid or expired code", "INVALID_CODE");
}
} else {
ApiUtils::jsonError("Invalid method name", "INVALID_METHOD");
}

33
src/api/setlang.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
use Wruczek\TSWebsite\Utils\Language\LanguageUtils;
require_once __DIR__ . "/../private/php/load.php";
if (empty($_POST["lang"])) {
http_response_code(400);
echo 'Required post parameter "lang" not set or is empty';
exit;
}
$lang = LanguageUtils::i()->getLanguageByCode($_POST["lang"]);
if ($lang === null) {
http_response_code(400);
echo 'Invalid language code';
exit;
}
setcookie("tswebsite_language", $lang->getLanguageCode(), time() + (60 * 60 * 24) * 60, "/"); // 60 days
$_SESSION["userlanguageid"] = $lang->getLanguageId();
$returnTo = "../";
if (!empty($_POST["return-to"])) {
// Check if the address start with a "/" and is not for example with "http://evilwebsite.com"
if (mb_strpos($_POST["return-to"], "/") === 0) {
$returnTo = $_POST["return-to"];
}
}
header("Location: $returnTo");