- 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

View File

@ -75,3 +75,12 @@ $config['contact']['items'][] = ["TeamSpeak", "Support channel", "ts3server://te
$config['contact']['items'][] = ["Email", "contact@email.com", "mailto:contact@email.com"];
$config['contact']['items'][] = ["Telegram", "@Telegram", "https://t.me/Telegram"];
$config['contact']['items'][] = ["Twitter", "@Twitter", "https://twitter.com/Twitter"];
/************* Groupassigner configuration *************/
// Enable / Disable the GroupAssigner
$config["groupassigner"] = 1;
// Server groups to be assigned
$config["groups"]["allowgroups"] = array("41","42");

View File

@ -22,6 +22,8 @@ $lang["navbar"]["rules"] = "Server Regeln";
$lang["navbar"]["connect"] = "Mit Server verbinden";
$lang["navbar"]["connecttooltip"] = "Klicken um mit {0} zu verbinden";
$lang["navbar"]["groupassigner"] = "Gruppenzuweiser";
/************* Footer *************/
@ -102,3 +104,16 @@ $lang["banlist"]["table"]["expires"] = "Läuft ab am";
$lang["rules"]["title"] = "Server Regeln";
$lang["rules"]["filenotfound"] = "Fehler: Die Datei <code>config/rules.md</code> wurde nicht gefunden!";
$lang["rules"]["readerror"] = "Fehler: Nicht genügend Rechte um auf <code>config/rules.md</code> zuzugreifen!";
/************* Groupassigner - groupassigner.php *************/
$lang["grouppage"]["title"] = "Gruppenzuweiser";
$lang["grouppage"]["tsuid"] = "Teamspeak-UID";
$lang["grouppage"]["tsgroup"] = "Teamspeak Gruppe";
$lang["grouppage"]["send"] = "Absenden";
$lang["grouppage"]["error"]["offline"] = "Du musst online sein zur Vergabe einer Gruppe";
$lang["grouppage"]["error"]["notallowed"] = "Diese Servergruppe darf nicht vergeben werden.";
$lang["grouppage"]["error"]["duplicate"] = "Du besitzt die Servergruppe bereits.";
$lang["grouppage"]["success"]["success"] = "Dir wurde die Servergruppe zugewiesen";

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";
?>

View File

@ -72,7 +72,18 @@ $htalink = $config["general"]["enablehta"] ? "" : ".php";
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="viewer<?php echo $htalink ?>"><i class="fa fa-eye" aria-hidden="true"></i> <?php tl($lang["navbar"]["viewer"]); ?></a></li>
<?php if($config['groupassigner'] == 1){ ?>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><i class="fa fa-television" aria-hidden="true"></i></i><?php tl($lang["navbar"]["viewer"]); ?> <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="viewer<?php echo $htalink ?>"><i class="fa fa-eye" aria-hidden="true"></i> <?php tl($lang["navbar"]["viewer"]); ?></a></li>
<li><a href="groupassigner<?php echo $htalink ?>"><i class="fa fa-sign-in" aria-hidden="true"></i> <?php tl($lang["navbar"]["groupassigner"]); ?></a></li>
</ul>
</li>
<?php }else{ ?>
<li><a href="viewer<?php echo $htalink ?>"><i class="fa fa-eye" aria-hidden="true"></i> <?php tl($lang["navbar"]["viewer"]); ?></a></li>
<?php } ?>
<li><a href="bans<?php echo $htalink ?>"><i class="fa fa-ban" aria-hidden="true"></i> <?php tl($lang["navbar"]["bans"]); ?></a></li>
<li><a href="rules<?php echo $htalink ?>"><i class="fa fa-book" aria-hidden="true"></i> <?php tl($lang["navbar"]["rules"]); ?></a></li>
<!-- I don't have time for this.