Guest User

Untitled

a guest
Jul 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. Copyright by Master18 geschrieben von Master18 am 20.03.2012
  5. */
  6.  
  7. require_once(WCF_DIR.'lib/page/AbstractPage.class.php');
  8.  
  9. class TS3TokensPage extends AbstractPage {
  10. public $templateName = 'TS3Token';
  11. public $FMToken = Array();
  12. public $debug = false;
  13. // Fill in connection-information for your TS3-Server
  14. // Ab hier die nötigen Informationen deines TS3-Servers eintragen
  15.  
  16. // IP-Adress of the TS3-Server
  17. // IP-Adresse des TS3-Servers
  18. public $ip = 'mc.bigginhd.de:8888';
  19.  
  20. // query-port of the TS3-Server (default: 10011)
  21. // Query-Port des TS3-Servers (Standard: 10011)
  22. public $t_port = '10011';
  23.  
  24. // ID of the virtual server
  25. // Server-ID des virtuellen Servers
  26. public $sid = '2';
  27.  
  28. // Login-name for query
  29. // Login-Name zur Abfrage
  30. public $Login_Name = 'ts3token';
  31.  
  32. // password for query-user
  33. // Passwort zur Abfrage
  34. public $Login_pwd = '****';
  35.  
  36. // ID of the group tokens will be displayed from
  37. // ID der Gruppe dessen Tokens angezeigt werden sollen
  38. public $Group_id = '14';
  39.  
  40. // Message if there are no tokens availible
  41. // Nachrit wenn keine Tokens verfügbar sind
  42. public $NoTokens = 'Keine Tokens verf&uuml;gbar!';
  43.  
  44. //Ab Hier nichts mehr ändern !!!!!!!!!!!!!!!!!!!
  45. //--------------------------------------------------------------------------
  46. // Generate a Token if there is none (0=No, display message instead | 1=Yes)
  47. // Neues Token erstellen falls keines verfügbar (0 = Nein, zeige die Meldung stattdessen | 1 = Yes)
  48. public $GenerateToken = '1';
  49.  
  50. // Don't change anything from here on (Except you are knowing what you are doing)!
  51. // Ab hier keine Änderungen mehr vornehmen (außer du weist was du tust)!
  52. // //-------------------------------------------------------------------------------------------
  53.  
  54. /**
  55. * @see Page::assignVariables()
  56. */
  57. public function assignVariables() {
  58. parent::assignVariables();
  59. ini_set('display_errors', 1);
  60.  
  61. $error = array();
  62.  
  63. error_reporting(E_ALL);
  64.  
  65. $fp = @fsockopen($this->ip, $this->t_port, $errno, $errstr, 2);
  66. if($fp){
  67. $cmd = "use sid=".$this->sid."\n";
  68. if(!($select = $this->sendCmd($fp, $cmd))){
  69. echo ("Auf Server 1 geschaltet");
  70. $error[] = 'Wrong Server ID';
  71. }
  72. $cmd="login ".$this->Login_Name." ".$this->Login_pwd."\n";
  73. if(!($sinfo = $this->sendCmd($fp, $cmd))){
  74. $error[] = 'Login Denied';
  75. }
  76. $this->FMToken = $this->readToken($fp);
  77. if ($this->FMToken[0] === $this->NoTokens){
  78. if ($this->GenerateToken === '1'){
  79. $NewToken = $this->makeToken($fp);
  80. $this->FMToken = $this->readToken($fp);
  81. }else{
  82. // Token-Erstellung ist abgeschaltet
  83. }
  84. }
  85. }else{
  86. $error[] = 'Can not connect to the server';
  87. }
  88. // die (print_r($this->FMToken));
  89.  
  90. WCF::getTPL()->assign(
  91. array(
  92. 'TS3Tokens' => $this->FMToken
  93. )
  94. );
  95. }
  96.  
  97. /*
  98. * Sends a command to the TS3-Server and retunrs the answer
  99. * Parameter: Socket to Server, Command
  100. * Sendet ein Komando an den TS3-Server und gibt die Antwort zurück
  101. * Parameter: Socket zum Server, Komando
  102. */
  103.  
  104. function sendCmd($fp, $cmd){
  105. $msg = '';
  106. if ($this->debug) echo "<pre>sende: ".$cmd."\n";
  107. fputs($fp, $cmd);
  108. while(strpos($msg, 'msg=') === false){
  109. $msg .= fread($fp, 8096);
  110. }
  111. if ($this->debug) echo "Antwort: ".$msg."</pre>\n\n";
  112. if(!strpos($msg, 'msg=ok')){
  113. return false;
  114. }else{
  115. return $msg;
  116. }
  117. }
  118.  
  119. /*
  120. * Retunrns all availible Tokens as an array
  121. * Parameter: Socket to Server
  122. * Gibt alle verfügbaren Token als Arraly zurück
  123. * Parameter: Socket zum Server
  124. */
  125. function readToken ($fp){
  126. $FMToken[0] = $this->NoTokens;
  127. $cmd="tokenlist\n";
  128. $i=0;
  129. if(!($tokens = $this->sendCmd($fp, $cmd))){
  130. $error[] = 'no tokens availible';
  131. }else{
  132. $zeichen = explode('|',$tokens);
  133. foreach ($zeichen as &$token) {
  134. $token = explode(' ',$token);
  135. $needed="token_id1=".$this->Group_id;
  136. if ($token[2]==$needed){
  137. $ausgabe = explode('=',$token[0]);
  138. $FMToken[$i] = stripcslashes($ausgabe[1]);
  139. $i++;
  140. } else {
  141. // print "Falsches Token: ".$token[0];
  142. }
  143. }
  144. }
  145. return $FMToken;
  146. }
  147.  
  148. /*
  149. * Retunrs an newly generated Token
  150. * Parameter: Socket to Server
  151. * Erstellt ein neues Token und gibt dieses zurück
  152. * Parameter: Socket zum Server
  153. */
  154. function makeToken ($fp){
  155. $cmd="tokenadd tokentype=0 tokenid1=".$this->Group_id." tokenid2=0\n";
  156. $newToken = $this->sendCmd($fp, $cmd);
  157. return $newToken;
  158. }
  159. }
  160. ?>
Add Comment
Please, Sign In to add comment