- Languages (lang.de.php) (Needs a Translate in other Languages)-

Add: $lang["navbar"]["groupassigner"], $lang["grouppage"]["title"], $lang["grouppage"]["tsuid"], $lang["grouppage"]["tsgroup"], $lang["grouppage"]["send"],
$lang["grouppage"]["error"]["offline"], $lang["grouppage"]["error"]["notallowed"], $lang["grouppage"]["error"]["duplicate"], $lang["grouppage"]["success"]["success"]

- Config (config.template.php) (Needs a Change in your Config) -
Add:
$config["groupassigner"], $config["groups"]["allowgroups"]

- Header (header.php) -
When the Groupassigner is active, then "Server Viewer" is a Dropdown Menu with the Link for the Groupassigner, when is inactive then is only a Link to the "Server Viewer"

- Groupassigner (groupassigner.php)
When the Groupassigner is active, then shows a Form with the UID and the ServerGroups was in the Config ($config["groups"]["allowgroups"]).
If the form is manipulated, and the server group is not in $config["groups"]["allowgroups"] then it will also output an error if the server is offline, or the login data for Server Query is incorrect.
This commit is contained in:
derrobin154
2018-04-04 22:08:05 +02:00
parent df13723f60
commit a47a07b093
4 changed files with 142 additions and 1 deletions

106
groupassigner.php Normal file
View File

@ -0,0 +1,106 @@
<?php
ob_start();
$groupPage = true;
require_once __DIR__ . "/include/header.php";
require_once __DIR__ . "/include/tsutils.php";
require_once __DIR__ . "/include/cacheutils.class.php";
$cacheutils = new CacheUtils('grouplist');
if($cacheutils->isExpired()) {
$cacheutils->setValue([getServerGroups(), date('d.m.Y H:i:s')], 300);
}
$grouplist = $cacheutils->getValue();
try {
$tsAdmin = getTeamspeakConnection("#no_query_clients");
} catch (Exception $e){
if ($e->getCode() == 1281) {
echo '';
} else {
echo '<div class="alert alert-danger"><p class="text-center">' . translate($lang["general"]["scripterror"], [$e->getCode(), $e->getMessage()]) . '</p></div>';
exit;
}
}
if(isset($_POST["absenden"])){
$uid = htmlspecialchars($_POST['uid']);
if(in_array(htmlspecialchars($_POST['group']), $config["groups"]["allowgroups"])){
try {
$tsAdmin->clientGetByUid($uid)->addServerGroup(htmlspecialchars($_POST['group']));
setCookie("tsuid", $uid);
$success = "success";
} catch(Exception $e) {
if(strpos($e, "invalid clientID") == true){
$error = "offline";
}elseif(strpos($e, "duplicate entry") == true){
$error = "duplicate";
}
}
}else{
$error = "notallowed";
}
}
?>
<?php if($config["groupassigner"] == 1){ ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-ban" aria-hidden="true"></i> <?php tl($lang["grouppage"]["title"]); ?></h3>
</div>
<div class="panel-body">
<?php if(isset($error)) { ?>
<div class="alert alert-danger">
<p class="text-center"><?php tl($lang["grouppage"]["error"][$error]); ?></p>
</div>
<?php } elseif(isset($success)) { ?>
<div class="alert alert-success">
<p class="text-center"><?php tl($lang["grouppage"]["success"][$success]) ?></p>
</div>
<? } ?>
<form method="POST" action="groupassigner.php">
<p align="center"><?php tl($lang["grouppage"]["tsuid"]); ?></p>
<input type="text" name="uid" required placeholder="<?php tl($lang["grouppage"]["tsuid"]); ?>" value="<?php if(isset($_COOKIE['tsuid'])){echo $_COOKIE['tsuid']; } ?>" class="form-control" style="width: 70%; margin-left:15%; margin-bottom: 5%;">
<p align="center"><?php tl($lang["grouppage"]["tsgroup"]); ?></p>
<select name="group" class="form-control" style="width: 70%; margin-left:15%;">
<?php
$servergroups = $tsAdmin->servergroupList(array("type" => 1));
foreach($servergroups as $sg){
if(!in_array($sg->sgid, $config["groups"]["allowgroups"])) continue;
echo "<option name='".$sg->name."' value='".$sg->sgid."'>".$sg->name."</option> ";
}
?>
</select>
<br><br>
<button type="submit" name="absenden" class="btn btn-success " style="margin-left: 45%;"><?php tl($lang["grouppage"]["send"]); ?></button>
</form>
</div>
</div>
<?php }?>
<?php
function getServerGroups() {
global $lang;
try {
$tsAdmin = getTeamspeakConnection("#no_query_clients");
} catch (TeamSpeak3_Exception $e) {
if ($e->getCode() == 1281) {
return '';
} else {
return '<div class="alert alert-danger"><p class="text-center">' . translate($lang["general"]["scripterror"], [$e->getCode(), $e->getMessage()]) . '</p></div>';
}
}
}
require_once __DIR__ . "/include/footer.php";
?>