Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Copyright by Master18 geschrieben von Master18 am 20.03.2012
- */
- require_once(WCF_DIR.'lib/page/AbstractPage.class.php');
- class TS3TokensPage extends AbstractPage {
- public $templateName = 'TS3Token';
- public $FMToken = Array();
- public $debug = false;
- // Fill in connection-information for your TS3-Server
- // Ab hier die nötigen Informationen deines TS3-Servers eintragen
- // IP-Adress of the TS3-Server
- // IP-Adresse des TS3-Servers
- public $ip = 'mc.bigginhd.de:8888';
- // query-port of the TS3-Server (default: 10011)
- // Query-Port des TS3-Servers (Standard: 10011)
- public $t_port = '10011';
- // ID of the virtual server
- // Server-ID des virtuellen Servers
- public $sid = '2';
- // Login-name for query
- // Login-Name zur Abfrage
- public $Login_Name = 'ts3token';
- // password for query-user
- // Passwort zur Abfrage
- public $Login_pwd = '****';
- // ID of the group tokens will be displayed from
- // ID der Gruppe dessen Tokens angezeigt werden sollen
- public $Group_id = '14';
- // Message if there are no tokens availible
- // Nachrit wenn keine Tokens verfügbar sind
- public $NoTokens = 'Keine Tokens verfügbar!';
- //Ab Hier nichts mehr ändern !!!!!!!!!!!!!!!!!!!
- //--------------------------------------------------------------------------
- // Generate a Token if there is none (0=No, display message instead | 1=Yes)
- // Neues Token erstellen falls keines verfügbar (0 = Nein, zeige die Meldung stattdessen | 1 = Yes)
- public $GenerateToken = '1';
- // Don't change anything from here on (Except you are knowing what you are doing)!
- // Ab hier keine Änderungen mehr vornehmen (außer du weist was du tust)!
- // //-------------------------------------------------------------------------------------------
- /**
- * @see Page::assignVariables()
- */
- public function assignVariables() {
- parent::assignVariables();
- ini_set('display_errors', 1);
- $error = array();
- error_reporting(E_ALL);
- $fp = @fsockopen($this->ip, $this->t_port, $errno, $errstr, 2);
- if($fp){
- $cmd = "use sid=".$this->sid."\n";
- if(!($select = $this->sendCmd($fp, $cmd))){
- echo ("Auf Server 1 geschaltet");
- $error[] = 'Wrong Server ID';
- }
- $cmd="login ".$this->Login_Name." ".$this->Login_pwd."\n";
- if(!($sinfo = $this->sendCmd($fp, $cmd))){
- $error[] = 'Login Denied';
- }
- $this->FMToken = $this->readToken($fp);
- if ($this->FMToken[0] === $this->NoTokens){
- if ($this->GenerateToken === '1'){
- $NewToken = $this->makeToken($fp);
- $this->FMToken = $this->readToken($fp);
- }else{
- // Token-Erstellung ist abgeschaltet
- }
- }
- }else{
- $error[] = 'Can not connect to the server';
- }
- // die (print_r($this->FMToken));
- WCF::getTPL()->assign(
- array(
- 'TS3Tokens' => $this->FMToken
- )
- );
- }
- /*
- * Sends a command to the TS3-Server and retunrs the answer
- * Parameter: Socket to Server, Command
- * Sendet ein Komando an den TS3-Server und gibt die Antwort zurück
- * Parameter: Socket zum Server, Komando
- */
- function sendCmd($fp, $cmd){
- $msg = '';
- if ($this->debug) echo "<pre>sende: ".$cmd."\n";
- fputs($fp, $cmd);
- while(strpos($msg, 'msg=') === false){
- $msg .= fread($fp, 8096);
- }
- if ($this->debug) echo "Antwort: ".$msg."</pre>\n\n";
- if(!strpos($msg, 'msg=ok')){
- return false;
- }else{
- return $msg;
- }
- }
- /*
- * Retunrns all availible Tokens as an array
- * Parameter: Socket to Server
- * Gibt alle verfügbaren Token als Arraly zurück
- * Parameter: Socket zum Server
- */
- function readToken ($fp){
- $FMToken[0] = $this->NoTokens;
- $cmd="tokenlist\n";
- $i=0;
- if(!($tokens = $this->sendCmd($fp, $cmd))){
- $error[] = 'no tokens availible';
- }else{
- $zeichen = explode('|',$tokens);
- foreach ($zeichen as &$token) {
- $token = explode(' ',$token);
- $needed="token_id1=".$this->Group_id;
- if ($token[2]==$needed){
- $ausgabe = explode('=',$token[0]);
- $FMToken[$i] = stripcslashes($ausgabe[1]);
- $i++;
- } else {
- // print "Falsches Token: ".$token[0];
- }
- }
- }
- return $FMToken;
- }
- /*
- * Retunrs an newly generated Token
- * Parameter: Socket to Server
- * Erstellt ein neues Token und gibt dieses zurück
- * Parameter: Socket zum Server
- */
- function makeToken ($fp){
- $cmd="tokenadd tokentype=0 tokenid1=".$this->Group_id." tokenid2=0\n";
- $newToken = $this->sendCmd($fp, $cmd);
- return $newToken;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment