Forum


Notice to all users

We are migrating towards a new forum system located at community.teamspeak.com, as such this forum will become read-only on January 29, 2020

Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Join Date
    January 2010
    Location
    Duesseldorf, Germany
    Posts
    33

    Script for displaying actually valid token

    You can implement this script in a resticted area of your Homepage and your users will see all valied tokens. New generated tokens will be displayed automatically and used tokens will disappear automaticaly too.

    You have to fill some variables at the beginning and you can change the outfit of the output at the end.

    PHP Code:
    <?php
    /*
    This script will connect to a TS3-Server via query-port and display
    all actualy valied tokens for a desired servergroup.

    Written by Nils Cibula

    Dieses Script verbindet über den Query-Port zu einem TS3-Server und zeigt alle 
    aktuell verfügbaren Tokens für eine ausgewählte Gruppe an

    Geschrieben von Nils Cibula
    */

    // 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
    $ip 'xx.xx.xx.xx';

    // query-port of the TS3-Server (default: 10011)
    // Query-Port des TS3-Servers (Standard: 10011)
    $t_port '10011';

    // ID of the virtual server
    // Server-ID des virtuellen Servers
    $sid '1';

    // Login-name for query
    // Login-Name zur Abfrage
    $Login_Name 'serveradmin';

    // password for query-user
    // Passwort zur Abfrage
    $Login_pwd '********';

    // ID of the group tokens will be displayed from
    // ID der Gruppe dessen Tokens angezeigt werden sollen
    $Group_id '7';

    // 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)!
    // ------------------------------------------------------------------------------------------------------------

    $error = array();

    function 
    sendCmd($fp$cmd){
        
    $msg '';
        
    fputs($fp$cmd);
        while(
    strpos($msg'msg=') === false){
            
    $msg .= fread($fp8096);
        }
        if(!
    strpos($msg'msg=ok')){
            return 
    false;
        }else{
            return 
    $msg;
        }
    }

    error_reporting(E_ALL);

        
    $i 0;

        
    $fp = @fsockopen($ip$t_port$errno$errstr2);
        if(
    $fp){
            
    $cmd "use sid=".$sid."\n";
            if(!(
    $select sendCmd($fp$cmd))){
                echo (
    "Auf Server 1 geschaltet");
                
    $error[] = 'Wrong Server ID';
            }

            
    $cmd="login $Login_Name $Login_pwd\n";
            if(!(
    $sinfo sendCmd($fp$cmd))){
                
    $error[] = 'Login Denied';
            }

            
    $cmd="tokenlist\n";
            if(!(
    $tokens sendCmd($fp$cmd))){
                
    $error[] = 'no tokens availible';
            }else{
                
    $zeichen explode('|',$tokens);
                foreach (
    $zeichen as &$token) {
                    
    $token explode(' ',$token);
                    if (
    $token[2]=='token_id1='.$Group_id){
                        
    $ausgabe explode('=',$token[0]);
                        
    $FMToken[$i] = $ausgabe[1];
                        
    $i++;
                    }
                }
            }
        }else{
            
    $error[] = 'Can not connect to the server';
        }

    // here is the loop for the output. Add HTML-Code if you want a nice result
    // Hier ist die Schleife für die Ausgabe. Fürge HTML-code hinzu, wenn du eine schönere Ausgabe wünscht.


        
    foreach ($FMToken as &$AToken){
            echo (
    stripcslashes($AToken)."<br><br>");
        }


    ?>
    I hope this will be usefull for some of you.

  2. #2
    Join Date
    January 2010
    Location
    Germany
    Posts
    2
    This is very nice, great work!

    Must i use the serveradmin logindate, i think this is a high risk.

  3. #3
    Join Date
    January 2010
    Location
    Duesseldorf, Germany
    Posts
    33
    Hello,

    I'm happy that you enjoy my script. At the Moment I don't have another solution but using the serveradmin.

    Knowing the risk I've opend another thread yesterday (http://forum.teamspeak.com/showthread.php?t=49680), but it seems to be impossible otherwise.

    If anyone finds a better way I will be very happy and change my script then.

  4. #4
    Join Date
    June 2005
    Location
    Germany
    Posts
    47
    Notice: Undefined variable: FMToken in F:\XAMPP\HS_Uncut_XAMPP_Paket\xampp\htdocs\afk\tes t.php on line 99

    Warning: Invalid argument supplied for foreach() in F:\XAMPP\HS_Uncut_XAMPP_Paket\xampp\htdocs\afk\tes t.php on line 99

    Sourcecode:
    PHP Code:
        foreach ($FMToken as &$AToken){
            echo (
    stripcslashes($AToken)."<br><br>");
        } 

  5. #5
    Join Date
    January 2010
    Location
    Duesseldorf, Germany
    Posts
    33
    I tested the script again and it works fine for me.

    But checking the code again I noticed, that I forgot to carry a about the situation, that there are no tokens availible. May be this is your situation.
    I will try it later today an post an update of my script if nessesary.

    Meanwhile you can try, wether there are actually tokens for the configured group or not. If not please generate one and try again.

  6. #6
    Join Date
    December 2009
    Location
    Germany
    Posts
    26
    On my site running the script

  7. #7
    Join Date
    January 2010
    Location
    Duesseldorf, Germany
    Posts
    33
    I have tested the script and got no errors. If there are no tokens availible, I got no output.
    But I improved my script with some new features:

    PHP Code:
    <?php
    /*
    This script will connect to a TS3-Server via query-port and display
    all actualy valied tokens for a desired servergroup.

    Written by Nils Cibula

    Dieses Script verbindet über den Query-Port zu einem TS3-Server und zeigt alle 
    aktuell verfügbaren Tokens für eine ausgewählte Gruppe an

    Geschrieben von Nils Cibula
    */

    // 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
    $ip 'XX.XX.XX.XX';

    // query-port of the TS3-Server (default: 10011)
    // Query-Port des TS3-Servers (Standard: 10011)
    $t_port '10011';

    // ID of the virtual server
    // Server-ID des virtuellen Servers
    $sid '1';

    // Login-name for query
    // Login-Name zur Abfrage
    $Login_Name 'serveradmin';

    // password for query-user
    // Passwort zur Abfrage
    $Login_pwd '********';

    // ID of the group tokens will be displayed from
    // ID der Gruppe dessen Tokens angezeigt werden sollen
    $Group_id '7';

    // Message if there are no tokens availible
    // Nachrit wenn keine Tokens verfügbar sind
    $NoTokens 'No Tokens generated, please see your serveradministrator!';

    // 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)
    $GenerateToken '1';

    // Here you can enter Text to be displayed before and after each token 
    // (e.g. before="<li>" and after = "</li>" to display Tokens in an unordered list)
    // Hier kann Text festgelegt werden, der vor und nach jedem Token ausgegeben wird
    // (z.B. vorher="<li>" und nachher = "</li>" um die Tokens in einer Liste auszugeben
    $TextBefore '';
    $TextAfter '<br /><br />';


    // 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)!
    // ------------------------------------------------------------------------------------------------------------

    $error = array();

    function 
    sendCmd($fp$cmd){
        
    $msg '';
        
    fputs($fp$cmd);
        while(
    strpos($msg'msg=') === false){
            
    $msg .= fread($fp8096);
        }
        if(!
    strpos($msg'msg=ok')){
            return 
    false;
        }else{
            return 
    $msg;
        }
    }

    function 
    readToken ($fp){
        global 
    $Group_id;
        global 
    $NoTokens;
        
    $FMToken[0] = $NoTokens;
        
    $cmd="tokenlist\n";
        
    $i=0;
        if(!(
    $tokens sendCmd($fp$cmd))){
            
    $error[] = 'no tokens availible';
        }else{
            
    $zeichen explode('|',$tokens);
            foreach (
    $zeichen as &$token) {
                
    $token explode(' ',$token);
                if (
    $token[2]=='token_id1='.$Group_id){
                    
    $ausgabe explode('=',$token[0]);
                    
    $FMToken[$i] = stripcslashes($ausgabe[1]);
                    
    $i++;
                }
            }
        }
        return 
    $FMToken;
    }

    function 
    makeToken ($fp){
        global 
    $Group_id;
        
    $cmd="tokenadd tokentype=0 tokenid1=".$Group_id." tokenid2=0\n";
        
    $newToken=sendCmd($fp$cmd);
        return 
    $newToken;
    }

    error_reporting(E_ALL);

    $fp = @fsockopen($ip$t_port$errno$errstr2);
    if(
    $fp){
        
    $cmd "use sid=".$sid."\n";
        if(!(
    $select sendCmd($fp$cmd))){
            echo (
    "Auf Server 1 geschaltet");
            
    $error[] = 'Wrong Server ID';
        }

        
    $cmd="login $Login_Name $Login_pwd\n";
        if(!(
    $sinfo sendCmd($fp$cmd))){
            
    $error[] = 'Login Denied';
        }

        
    $FMToken readToken($fp);
        if (
    $FMToken[0] === $NoTokens){
            if (
    $GenerateToken === '1'){
                
    $NewToken makeToken($fp);
                
    $FMToken readToken($fp);
            }
        }

        
    }else{
        
    $error[] = 'Can not connect to the server';
    }

    // here is the loop for the output. Add HTML-Code if you want a nice result
    // Hier ist die Schleife für die Ausgabe. Fürge HTML-code hinzu, wenn du eine schönere Ausgabe wünscht.


    foreach ($FMToken as $AToken){
        echo 
    $TextBefore.($AToken).$TextAfter;
    }

    ?>
    Now you can decide what the script will do, when no tokens are availible. You can let it generate a new token and dislplay it, or you can display a message instead.
    Further you can define strings to be outputtet before and after each token.

    Please report, wether this version works.
    Last edited by Harry.Fox; January 15th, 2010 at 10:08 PM.

  8. #8
    Join Date
    January 2010
    Location
    Duesseldorf, Germany
    Posts
    33
    I've found a littel mistake in the script above and corrected it.
    If you've copied the code bevore this post please copy it again!

    Best regards
    Harry.Fox

    P.S.: I wold be happy about some feedback

  9. #9
    Join Date
    December 2009
    Location
    Germany
    Posts
    26
    It works well

  10. #10
    Join Date
    January 2010
    Location
    Switzerland
    Posts
    10
    Thanks. I could have written it myself, but this way I easily saved an hour. You're the best!

  11. #11
    Join Date
    January 2010
    Location
    Secret Base in Arctic Region
    Posts
    1,671
    If the server is running with MySQL you could do some queries on the "tokens" table directly instead of using the server-query function.

  12. #12
    Join Date
    June 2005
    Location
    Germany
    Posts
    47
    ill test it if im at home, maybe i got the "bug" because i allready got the beta13 for testing, and on beta13, the tokes got other stuff. PM me to get more infos about it. btw on pm you can speak german with me.

    greetz
    Cobra

  13. #13
    Join Date
    December 2009
    Location
    Germany
    Posts
    26
    no works with new Beta15 Server

  14. #14
    Join Date
    January 2010
    Location
    uk
    Posts
    4
    From ur first script i get:

    Notice: Undefined variable: FMToken in /home/alpha10/public_html/ts3php.php on line 99

    Warning: Invalid argument supplied for foreach() in /home/alpha10/public_html/ts3php.php on line 99

    Also get same for the 2nd script (line 127 then i think)

    Could i ask, are you running this from the host or remotely?

  15. #15
    Join Date
    April 2007
    Location
    Germany
    Posts
    98
    Quote Originally Posted by MIKEYK255 View Post
    Notice: Undefined variable: FMToken in /home/alpha10/public_html/ts3php.php on line 99

    Warning: Invalid argument supplied for foreach() in /home/alpha10/public_html/ts3php.php on line 99
    This error is shown if you use "localhost" or equivalent terms (like 127.0.0.1) instead of your external IP!

    @author:
    You should add a exception for this case You should also fix the exception thrown for "No connection" because there is no error shown at the moment.
    And you should declare all variables at the beginning of the script to avoid errors.

    Maybe you want to use this version instead:
    PHP Code:
    <?php
    /*
    This script will connect to a TS3-Server via query-port and display
    all actualy valied tokens for a desired servergroup.

    Written by Nils Cibula

    Dieses Script verbindet über den Query-Port zu einem TS3-Server und zeigt alle 
    aktuell verfügbaren Tokens für eine ausgewählte Gruppe an

    Geschrieben von Nils Cibula
    */

    // Fill in connection-information for your TS3-Server
    // Ab hier die nötigen Informationen deines TS3-Servers eintragen

    // IP-Adress of the TS3-Server (NOT localhost or 127.0.0.1)
    // IP-Adresse des TS3-Servers (NICHT localhost or 127.0.0.1)
    $ip '';

    // query-port of the TS3-Server (default: 10011)
    // Query-Port des TS3-Servers (Standard: 10011)
    $t_port '10011';

    // ID of the virtual server
    // Server-ID des virtuellen Servers
    $sid '1';

    // Login-name for query
    // Login-Name zur Abfrage
    $Login_Name 'serveradmin';

    // password for query-user
    // Passwort zur Abfrage
    $Login_pwd '*********';

    // ID of the group tokens will be displayed from
    // ID der Gruppe dessen Tokens angezeigt werden sollen
    $Group_id '7';

    // Message if there are no tokens available
    // Nachrit wenn keine Tokens verfügbar sind
    $NoTokens 'No tokens available, please contact your serveradministrator!';

    // 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)
    $GenerateToken false;

    // Here you can enter Text to be displayed before and after each token 
    // (e.g. before="<li>" and after = "</li>" to display Tokens in an unordered list)
    // Hier kann Text festgelegt werden, der vor und nach jedem Token ausgegeben wird
    // (z.B. vorher="<li>" und nachher = "</li>" um die Tokens in einer Liste auszugeben
    $TextBefore '';
    $TextAfter '<br /><br />';

    // Here you are able to activate the debug-mode (true / false)
    // Hier kannst du den Debugmodus aktiveren (true = an / false = aus)
    $debug true;

    // Don't change anything from here on (Except you know what you are doing)!
    // Ab hier keine Änderungen mehr vornehmen (außer du weist was du tust)!
    // ------------------------------------------------------------------------------------------------------------

    $error = array();
    $FMToken = array();

    function 
    sendCmd($fp$cmd){
        
    $msg '';
        
    fputs($fp$cmd);
        while(
    strpos($msg'msg=') === false){
            
    $msg .= fread($fp8096);
        }
        if(!
    strpos($msg'msg=ok')){
            return 
    false;
        }else{
            return 
    $msg;
        }
    }

    function 
    readToken ($fp){
        global 
    $Group_id;
        global 
    $NoTokens;
        
    $FMToken[0] = $NoTokens;
        
    $cmd="tokenlist\n";
        
    $i=0;
        if(!(
    $tokens sendCmd($fp$cmd))){
            
    $error[] = 'no tokens availible';
        }else{
            
    $zeichen explode('|',$tokens);
            foreach (
    $zeichen as &$token) {
                
    $token explode(' ',$token);
                if (
    $token[2]=='token_id1='.$Group_id){
                    
    $ausgabe explode('=',$token[0]);
                    
    $FMToken[$i] = stripcslashes($ausgabe[1]);
                    
    $i++;
                }
            }
        }
        return 
    $FMToken;
    }

    function 
    makeToken ($fp){
        global 
    $Group_id;
        
    $cmd="tokenadd tokentype=0 tokenid1=".$Group_id." tokenid2=0\n";
        
    $newToken=sendCmd($fp$cmd);
        return 
    $newToken;
    }

    error_reporting(E_ALL);

        
    If (
    $ip === "127.0.0.1" || $ip === "localhost") {
      
    $error[] = 'Connection failed! Use your external IP, <b>NOT</b> "localhost" or "127.0.0.1"!';
    } else {
      
    $fp = @fsockopen($ip$t_port$errno$errstr2);
      if(
    $fp){
          
    $cmd "use sid=".$sid."\n";
          if(!(
    $select sendCmd($fp$cmd))){
              echo (
    "Auf Server 1 geschaltet");
              
    $error[] = 'Wrong Server ID';
          }
      
          
    $cmd="login $Login_Name $Login_pwd\n";
          if(!(
    $sinfo sendCmd($fp$cmd))){
              
    $error[] = 'Login Denied';
          }
      
          
    $FMToken readToken($fp);
          if (
    $FMToken[0] === $NoTokens){
              if (
    $GenerateToken){
                  
    $NewToken makeToken($fp);
                  
    $FMToken readToken($fp);
              }
          }
      
          
      }else{
          
    $error[] = 'Can not connect to the server';
      }
    }

    // here is the loop for the output. Add HTML-Code if you want a nice result
    // Hier ist die Schleife für die Ausgabe. Fürge HTML-code hinzu, wenn du eine schönere Ausgabe wünscht.

    If ($debug) {
      echo 
    "<b>Debug Mode activated!</b><br>The following errors where thrown:<br><font color='red'>";
      foreach (
    $error as $aerror){
        echo 
    $aerror."<br>";
      }
      echo 
    "</font><br><br>";
    } else {
      foreach (
    $FMToken as $AToken){
        echo 
    $TextBefore.($AToken).$TextAfter;
      }
    }

    ?>
    Fixed the most epic english-fails I noticed Fixed some typos, added additional checks and added $FMToken to $error (beginning). Feel free to use it...


    Quote Originally Posted by MIKEYK255 View Post
    Could i ask, are you running this from the host or remotely?
    Use your external IP, not with 127.0.0.1 or anthing like that.
    I think it can be also run remotely but I don't promise anything

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Create token by php script ?
    By snowflake in forum General Questions
    Replies: 8
    Last Post: June 3rd, 2011, 03:50 PM
  2. [Help] Token add and Show Script
    By Siggi in forum Tools / Web Based
    Replies: 5
    Last Post: January 15th, 2010, 07:15 PM
  3. Create token by php script and mysql
    By Wikibear in forum Permission System
    Replies: 6
    Last Post: December 28th, 2009, 07:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •