release 1.3.9

This commit is contained in:
Newcomer1989
2020-08-03 13:02:27 +02:00
parent 2336177eca
commit d196dfb1f6
62 changed files with 3731 additions and 4211 deletions

View File

@@ -1,7 +1,7 @@
<?PHP
header("Content-Type: application/json; charset=UTF-8");
require_once('../other/dbconfig.php');
require_once('../other/config.php');
$dbname = $db['dbname'];
$dbtype = $db['type'];
@@ -16,18 +16,49 @@ if($db['type'] != "type") {
}
}
if (isset($_GET['apikey'])) {
$matchkey = 0;
foreach($cfg['stats_api_keys'] as $apikey => $desc) {
if ($apikey == $_GET['apikey']) $matchkey = 1;
}
if ($matchkey == 0) {
$json = array(
"Error" => array(
"invalid" => array(
"apikey" => "API Key is invalid"
)
)
);
echo json_encode($json);
exit;
}
} else {
$json = array(
"Error" => array(
"required" => array(
"apikey" => array(
"desc" => "API Key for authentification. API keys can be created inside the Ranksystem Webinterface",
"usage" => "Use \$_GET parameter 'apikey' and add as value a valid API key",
"example" => "/api/?apikey=XXXXX"
)
)
)
);
echo json_encode($json);
exit;
}
$limit = (isset($_GET['limit']) && is_numeric($_GET['limit']) && $_GET['limit'] > 0 && $_GET['limit'] <= 1000) ? $_GET['limit'] : 100;
$sort = (isset($_GET['sort'])) ? htmlspecialchars_decode($_GET['sort']) : '1';
$order = (isset($_GET['order']) && strtolower($_GET['order']) == 'desc') ? 'DESC' : 'ASC';
$part = (isset($_GET['part']) && is_numeric($_GET['part']) && $_GET['part'] > 0) ? (($_GET['part'] - 1) * $limit) : 0;
if (isset($_GET['groups'])) {
$sgidname = $all = '----------_none_selected_----------';
$sgid = -1;
if(isset($_GET['all'])) {
$all = 1;
}
if(isset($_GET['sgid'])) {
$sgid = htmlspecialchars_decode($_GET['sgid']);
}
if(isset($_GET['sgidname'])) {
$sgidname = htmlspecialchars_decode($_GET['sgidname']);
}
if(isset($_GET['all'])) $all = 1;
if(isset($_GET['sgid'])) $sgid = htmlspecialchars_decode($_GET['sgid']);
if(isset($_GET['sgidname'])) $sgidname = htmlspecialchars_decode($_GET['sgidname']);
if($sgid == -1 && $sgidname == '----------_none_selected_----------' && $all == '----------_none_selected_----------') {
$json = array(
@@ -37,6 +68,16 @@ if (isset($_GET['groups'])) {
"usage" => "Use \$_GET parameter 'all' without any value",
"example" => "/api/?groups&all"
),
"limit" => array(
"desc" => "Define a number that limits the number of results. Maximum value is 1000. Default is 100.",
"usage" => "Use \$_GET parameter 'limit' and add as value a number above 1",
"example" => "/api/?groups&limit=10"
),
"order" => array(
"desc" => "Define a sorting order. Value of 'sort' param is necessary.",
"usage" => "Use \$_GET parameter 'order' and add as value 'asc' for ascending or 'desc' for descending",
"example" => "/api/?groups&all&sort=sgid&order=asc"
),
"sgid" => array(
"desc" => "Get details about TeamSpeak servergroups by the servergroup TS-database-ID",
"usage" => "Use \$_GET parameter 'sgid' and add as value the servergroup TS-database-ID",
@@ -45,25 +86,54 @@ if (isset($_GET['groups'])) {
"sgidname" => array(
"desc" => "Get details about TeamSpeak servergroups by servergroup name or a part of it",
"usage" => "Use \$_GET parameter 'sgidname' and add as value a name or a part of it",
"example" => "/api/?groups&sgidname=Level01"
"example" => array(
"1" => array(
"desc" => "Filter by servergroup name",
"url" => "/api/?groups&sgidname=Level01"
),
"2" => array(
"desc" => "Filter by servergroup name with a percent sign as placeholder",
"url" => "/api/?groups&sgidname=Level%"
)
)
),
"sort" => array(
"desc" => "Define a sorting. Available is each column name, which is given back as a result.",
"usage" => "Use \$_GET parameter 'sort' and add as value a column name",
"example" => array(
"1" => array(
"desc" => "Sort by servergroup name",
"url" => "/api/?groups&all&sort=sgidname"
),
"2" => array(
"desc" => "Sort by TeamSpeak sort-ID",
"url" => "/api/?groups&all&sort=sortid"
)
)
)
)
);
} else {
if ($all == 1) {
$dbdata = $mysqlcon->prepare("SELECT * FROM `$dbname`.`groups`");
$dbdata = $mysqlcon->prepare("SELECT * FROM `$dbname`.`groups` ORDER BY {$sort} {$order} LIMIT :start, :limit");
} else {
$dbdata = $mysqlcon->prepare("SELECT * FROM `$dbname`.`groups` WHERE (`sgidname` LIKE :sgidname OR `sgid` LIKE :sgid)");
$dbdata = $mysqlcon->prepare("SELECT * FROM `$dbname`.`groups` WHERE (`sgidname` LIKE :sgidname OR `sgid` LIKE :sgid) ORDER BY {$sort} {$order} LIMIT :start, :limit");
$dbdata->bindValue(':sgidname', '%'.$sgidname.'%', PDO::PARAM_STR);
$dbdata->bindValue(':sgid', (int) $sgid, PDO::PARAM_INT);
}
$dbdata->bindValue(':sgidname', '%'.$sgidname.'%', PDO::PARAM_STR);
$dbdata->bindValue(':sgid', (int) $sgid, PDO::PARAM_INT);
$dbdata->bindValue(':start', (int) $part, PDO::PARAM_INT);
$dbdata->bindValue(':limit', (int) $limit, PDO::PARAM_INT);
$dbdata->execute();
$json = $dbdata->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_UNIQUE);
foreach ($json as $sgid => $sqlpart) {
if ($sqlpart['icondate'] != 0 && $sqlpart['sgidname'] == 'ServerIcon') {
$json[$sgid]['iconpath'] = './tsicons/servericon.png';
} elseif ($sqlpart['iconid'] != 0) {
$json[$sgid]['iconpath'] = './tsicons/'.$sqlpart['iconid'].'.png';
$json[$sgid]['iconpath'] = './tsicons/servericon.'.$sqlpart['ext'];
} elseif ($sqlpart['icondate'] == 0 && $sqlpart['iconid'] > 0 && $sqlpart['iconid'] < 601) {
$json[$sgid]['iconpath'] = './tsicons/'.$sqlpart['iconid'].'.'.$sqlpart['ext'];
} elseif ($sqlpart['icondate'] != 0) {
$json[$sgid]['iconpath'] = './tsicons/'.$sgid.'.'.$sqlpart['ext'];
} else {
$json[$sgid]['iconpath'] = '';
}
}
}
@@ -99,69 +169,180 @@ if (isset($_GET['groups'])) {
} elseif (isset($_GET['user'])) {
$uuid = $name = '----------_none_selected_----------';
$filter = '';
$part = $cldbid = 0;
if(isset($_GET['uuid'])) {
$uuid = htmlspecialchars_decode($_GET['uuid']);
}
if(isset($_GET['cldbid'])) {
$cldbid = htmlspecialchars_decode($_GET['cldbid']);
}
if(isset($_GET['name'])) {
$name = htmlspecialchars_decode($_GET['name']);
}
if(isset($_GET['part'])) {
$part = (htmlspecialchars_decode($_GET['part']) - 1) * 100;
}
$part = $cldbid = $all = 0;
if(!isset($_GET['sort'])) $sort = '`rank`';
if(isset($_GET['all'])) $all = 1;
if(isset($_GET['uuid'])) $uuid = htmlspecialchars_decode($_GET['uuid']);
if(isset($_GET['cldbid'])) $cldbid = htmlspecialchars_decode($_GET['cldbid']);
if(isset($_GET['name'])) $name = htmlspecialchars_decode($_GET['name']);
if(isset($_GET['part'])) $part = (htmlspecialchars_decode($_GET['part']) - 1) * 100;
if(isset($_GET['online']) && $uuid == '----------_none_selected_----------' && $name == '----------_none_selected_----------' && $cldbid == 0) {
$filter = '`online`=1';
} elseif(isset($_GET['online'])) {
$filter = '(`uuid` LIKE :uuid OR `cldbid` LIKE :cldbid OR `name` LIKE :name) AND `online`=1';
} else {
} elseif($uuid != '----------_none_selected_----------' || $name != '----------_none_selected_----------' || $cldbid != 0) {
$filter = '(`uuid` LIKE :uuid OR `cldbid` LIKE :cldbid OR `name` LIKE :name)';
}
if($uuid == '----------_none_selected_----------' && $name == '----------_none_selected_----------' && $filter == '' && $cldbid == 0) {
if($uuid == '----------_none_selected_----------' && $name == '----------_none_selected_----------' && $filter == '' && $cldbid == 0 && $all == 0) {
$json = array(
"usage" => array(
"uuid" => array(
"desc" => "Get details about TeamSpeak user by unique client ID",
"usage" => "Use \$_GET parameter 'uuid' and add as value one unique client ID or a part of it",
"example" => "/api/?user&uuid=xrTKhT/HDl4ea0WoFDQH2zOpmKg="
"all" => array(
"desc" => "Get details about all TeamSpeak user. Result is limited by 100 entries.",
"usage" => "Use \$_GET parameter 'all' without any value",
"example" => "/api/?user&all"
),
"cldbid" => array(
"desc" => "Get details about TeamSpeak user by client TS-database ID",
"usage" => "Use \$_GET parameter 'cldbid' and add as value a single client TS-database ID",
"example" => "/api/?user&cldbid=7775"
),
"limit" => array(
"desc" => "Define a number that limits the number of results. Maximum value is 1000. Default is 100.",
"usage" => "Use \$_GET parameter 'limit' and add as value a number above 1",
"example" => "/api/?user&all&limit=10"
),
"name" => array(
"desc" => "Get details about TeamSpeak user by client nickname",
"usage" => "Use \$_GET parameter 'name' and add as value a name or a part of it",
"example" => "/api/?user&name=Newcomer1989"
"example" => array(
"1" => array(
"desc" => "Filter by client nickname",
"url" => "/api/?user&name=Newcomer1989"
),
"2" => array(
"desc" => "Filter by client nickname with a percent sign as placeholder",
"url" => "/api/?user&name=%user%"
)
)
),
"online" => array(
"desc" => "Get the online TeamSpeak user",
"usage" => "Use \$_GET parameter 'online' without any value",
"example" => "/api/?user&online"
),
"order" => array(
"desc" => "Define a sorting order.",
"usage" => "Use \$_GET parameter 'order' and add as value 'asc' for ascending or 'desc' for descending",
"example" => "/api/?user&all&order=asc"
),
"part" => array(
"desc" => "Define, which part of the result you want to get. This is needed, when more then 10 clients are inside the result. At default you will get the first 100 clients. To get the next 100 clients, you will need to answer for part 2.",
"desc" => "Define, which part of the result you want to get. This is needed, when more then 100 clients are inside the result. At default you will get the first 100 clients. To get the next 100 clients, you will need to ask for part 2.",
"usage" => "Use \$_GET parameter 'part' and add as value a number above 1",
"example" => "/api/?user&name=TeamSpeakUser&part=2"
),
"sort" => array(
"desc" => "Define a sorting. Available is each column name, which is given back as a result.",
"usage" => "Use \$_GET parameter 'sort' and add as value a column name",
"example" => array(
"1" => array(
"desc" => "Sort by online time",
"url" => "/api/?user&all&sort=count"
),
"2" => array(
"desc" => "Sort by active time",
"url" => "/api/?user&all&sort=(count-idle)"
),
"3" => array(
"desc" => "Sort by rank",
"url" => "/api/?user&all&sort=rank"
)
)
),
"uuid" => array(
"desc" => "Get details about TeamSpeak user by unique client ID",
"usage" => "Use \$_GET parameter 'uuid' and add as value one unique client ID or a part of it",
"example" => "/api/?user&uuid=xrTKhT/HDl4ea0WoFDQH2zOpmKg="
)
)
);
} else {
$dbdata = $mysqlcon->prepare("SELECT `uuid`,`cldbid`,`rank`,`count`,`name`,`idle`,`cldgroup`,`online`,`nextup`,`lastseen`,`grpid`,`except`,`grpsince` FROM `$dbname`.`user` WHERE {$filter} LIMIT :start, :limit");
if($filter != '`online`=1') {
if ($all == 1) {
$dbdata = $mysqlcon->prepare("SELECT * FROM `$dbname`.`user` ORDER BY {$sort} {$order} LIMIT :start, :limit");
} else {
$dbdata = $mysqlcon->prepare("SELECT * FROM `$dbname`.`user` WHERE {$filter} ORDER BY {$sort} {$order} LIMIT :start, :limit");
}
if($filter != '`online`=1' && $all == 0) {
$dbdata->bindValue(':uuid', '%'.$uuid.'%', PDO::PARAM_STR);
$dbdata->bindValue(':cldbid', (int) $cldbid, PDO::PARAM_INT);
$dbdata->bindValue(':name', '%'.$name.'%', PDO::PARAM_STR);
}
$dbdata->bindValue(':start', (int) $part, PDO::PARAM_INT);
$dbdata->bindValue(':limit', (int) 100, PDO::PARAM_INT);
$dbdata->bindValue(':limit', (int) $limit, PDO::PARAM_INT);
$dbdata->execute();
$json = $dbdata->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_UNIQUE);
}
}
} elseif (isset($_GET['userstats'])) {
$uuid = '----------_none_selected_----------';
$filter = '';
$part = $all = 0;
if(isset($_GET['all'])) $all = 1;
if(!isset($_GET['sort'])) $sort = '`count_week`';
if(isset($_GET['uuid'])) {
$uuid = htmlspecialchars_decode($_GET['uuid']);
$filter = '`stats_user`.`uuid` LIKE :uuid';
}
if($uuid == '----------_none_selected_----------' && $all == 0 && $filter == '') {
$json = array(
"usage" => array(
"all" => array(
"desc" => "Get additional statistics about all TeamSpeak user. Result is limited by 100 entries.",
"usage" => "Use \$_GET parameter 'all' without any value",
"example" => "/api/?userstats&all"
),
"limit" => array(
"desc" => "Define a number that limits the number of results. Maximum value is 1000. Default is 100.",
"usage" => "Use \$_GET parameter 'limit' and add as value a number above 1",
"example" => "/api/?userstats&limit=10"
),
"order" => array(
"desc" => "Define a sorting order.",
"usage" => "Use \$_GET parameter 'order' and add as value 'asc' for ascending or 'desc' for descending",
"example" => "/api/?userstats&all&order=asc"
),
"part" => array(
"desc" => "Define, which part of the result you want to get. This is needed, when more then 100 clients are inside the result. At default you will get the first 100 clients. To get the next 100 clients, you will need to ask for part 2.",
"usage" => "Use \$_GET parameter 'part' and add as value a number above 1",
"example" => "/api/?userstats&all&part=2"
),
"sort" => array(
"desc" => "Define a sorting. Available is each column name, which is given back as a result.",
"usage" => "Use \$_GET parameter 'sort' and add as value a column name",
"example" => array(
"1" => array(
"desc" => "Sort by online time of the week",
"url" => "/api/?userstats&all&sort=count_week"
),
"2" => array(
"desc" => "Sort by active time of the week",
"url" => "/api/?userstats&all&sort=(count_week-idle_week)"
),
"3" => array(
"desc" => "Sort by online time of the month",
"url" => "/api/?userstats&all&sort=count_month"
)
)
),
"uuid" => array(
"desc" => "Get additional statistics about TeamSpeak user by unique client ID",
"usage" => "Use \$_GET parameter 'uuid' and add as value one unique client ID or a part of it",
"example" => "/api/?userstats&uuid=xrTKhT/HDl4ea0WoFDQH2zOpmKg="
)
)
);
} else {
if ($all == 1) {
$dbdata = $mysqlcon->prepare("SELECT * FROM `$dbname`.`stats_user` INNER JOIN `user` ON `user`.`uuid` = `stats_user`.`uuid` ORDER BY {$sort} {$order} LIMIT :start, :limit");
} else {
$dbdata = $mysqlcon->prepare("SELECT * FROM `$dbname`.`stats_user` INNER JOIN `user` ON `user`.`uuid` = `stats_user`.`uuid` WHERE {$filter} ORDER BY {$sort} {$order} LIMIT :start, :limit");
$dbdata->bindValue(':uuid', '%'.$uuid.'%', PDO::PARAM_STR);
}
$dbdata->bindValue(':start', (int) $part, PDO::PARAM_INT);
$dbdata->bindValue(':limit', (int) $limit, PDO::PARAM_INT);
$dbdata->execute();
$json = $dbdata->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_UNIQUE);
}
} else {
$json = array(
"usage" => array(
@@ -184,6 +365,11 @@ if (isset($_GET['groups'])) {
"desc" => "Get details about the TeamSpeak user",
"usage" => "Use \$_GET parameter 'user'",
"example" => "/api/?user"
),
"userstats" => array(
"desc" => "Get additional statistics about the TeamSpeak user",
"usage" => "Use \$_GET parameter 'userstats'",
"example" => "/api/?userstats"
)
)
);