Remove all Groups of a Client

Discussion in 'Script requests' started by ServerVerwaltung, May 16, 2017.

  1. ServerVerwaltung

    ServerVerwaltung New Member

    Hello, im searching for a Script like these...
    Name of the script: Client Group Cleaner
    Functions of the script: The Script will remove all groups from a client (so that he is only in the guest server group)
    Why do you want it: Im new to coding and want to learn something about it and i think this would be nice for cleaning up old clients or members that leave a clan
    Screenshots:
    Original source (if any):
    Other notes: Based on PHP. It shoud be based on Teamspeak PHP Framework or ts3adminclass. Thank you a lot :)
     
  2. Erza86

    Erza86 Member

    Just remove the Client from the teamspeak db and its done.
     
    LetsBlade likes this.
  3. ServerVerwaltung

    ServerVerwaltung New Member

    I want to keep some informations about the client like first connect and number of connections, but thanks to share that kind of information.
    Has got anybody a Script like im searching for O.O :D ?
     
  4. Kieran

    Kieran Tag me

    Doesn't look like anybody is on this so I'm gonna try to make something decent. One sec
     
  5. Ridicc

    Ridicc Super Mod

    Just loop through his groups and remove them? That's like 10 lines of code.
     
  6. Kieran

    Kieran Tag me

    Usage: http://example.com/remove_groups.php?uid=vK6YEsyil2NLRnytCjfbHump8Hk= (works with offline client)
    OR
    http://example.com/remove_groups.php?name=Kieran (only works if the client is online)
    PHP:
    <?php
    //Path to the TS3 PHP Framework
    require_once('./TeamSpeak3/TeamSpeak3.php');
    //Path to your QueryLogin
    require_once('./config.php');


    try{
    $ts3 TeamSpeak3::factory("serverquery://" $config["Username"] . ":" $config["Password"] . "@" $config["IP"] . ":" $config["qPort"] . "/?server_port=" $config["Port"] . "&nickname=" $config["Nickname"] . "");


    if (isset(
    $_GET['uid'])) {
        
    $UID $_GET['uid'];
    }else{
        
    $UID '';
    }

    if (isset(
    $_GET['name'])){
        
    $name $_GET['name'];
    }else{
        
    $name '';
    }

    if ( 
    $name == '' AND $UID == ''){
        echo 
    'Nah fam';
    }
    else{
            
    //If name method is used, it gets the client data via username, then gets the DBID from the UID. Only works if client is ONLINE
            
    if ( isset($_GET['name']) ){
                
    $client $ts3->clientGetByName($name);
                
    $clientdbid $ts3->clientFindDb($client['client_unique_identifier'], TRUE);
            }
            
    //Searches for DBID with specified UID then gets client data
            
    else if ( isset($_GET['uid']) ){
                
    $clientdbid $ts3->clientFindDb($UIDTRUE);
                
    $client $ts3->clientGetByDbid($clientdbid[0]);
            }
            
    //Explodes all groupIDs into an array
            
    $groupsArr explode(','$client['client_servergroups']);
            
    //Prints all groups the client has
            
    print_r($groupsArr);
            
    //Loops throught the array and removes the groups from the DBID
            
    foreach($groupsArr as $group){
                
    $ts3->serverGroupClientDel($group$clientdbid);
            }
            
    //echo $client['client_servergroups'];
        
    }
    }
    catch(
    TeamSpeak3_Exception $error)
    {
        
    $errorCode $error->getCode();
        
    $errorMessage "Error " $error->getCode() . ": " $error->getMessage();
        echo 
    $errorMessage;
    }
    Example of config:
    PHP:
    <?php
    $config 
    = array(
      
    'Username'   =>    'name',                          //Query Login tsBot
      
    'Password'   =>    'pass',                          //Query Password zbaTudRH
      
    'IP'         =>    '1.1.1.1',                       //Server IP/Domain
      
    'Port'       =>    '9987',                          //Server Port
      
    'qPort'      =>    '10011',                         //Query Port, Default 10011
      
    'Username'   =>    rawurlencode('Name'.rand(1,99))  //Convertes Botname to a URI friendly Format
    );
    ?>
     
    Last edited: May 20, 2017 at 9:53 AM
    ServerVerwaltung likes this.
  7. Kieran

    Kieran Tag me

    Hard if you don't know PHP or never worked with the framework
     
  8. Kieran

    Kieran Tag me

    B1uscr34m likes this.
  9. B1uscr34m

    B1uscr34m Active Member

    Kieran likes this.
  10. Kieran

    Kieran Tag me

    Oh neat. Didn't know that.

    But since his name is "Server Management" and he asked for PHP, I think he'd like to implement it somewhere.
     
    Kleberstoff likes this.
  11. Ridicc

    Ridicc Super Mod

    Why would you define the config values after you defined the var as an array? Just set all values while you create the var. You should also check if the get var you are checking is existing before you check if it's empty. Not required but recommend :)
     
  12. spamek23

    spamek23 VIP

    List All client > Delete from db?? :>

    Regards
     
  13. Kieran

    Kieran Tag me


    I wanted to do that first but I don't really know how so I left it out lol. Do you have an example? Or just wrap another if(isset(get)) around the "empty-check"? What I would do is split the empty check in 2 checks and wrap one if(isset(get[uid or name])) around each of them
    EDIT: Okay what do you think of this? It's ugly but that should work, right?

    About the config, I think it looks better this way and is easier to change.
     
    Last edited: May 19, 2017 at 3:12 PM
  14. ServerVerwaltung

    ServerVerwaltung New Member

    This is what i was looking for :)
    Thank you so much :))
    The removing of groups works great but only for the ?name variable not for the uid :-/
    I got an : Error 1281: database empty result set
    but if i try to reset this client over name it works great!
    I Think the issue is the removing of a character.
    Ive got echo the variables in the error i will become an result like this "M18Z M5uZnr4PGSusd/smft3Y9g=" there will be removed the "+" the original id will called "M18Z+M5uZnr4PGSusd/smft3Y9g="
    Have you got an idea to solve this ?
     
  15. Kieran

    Kieran Tag me

    Oh yea you have to replace the + with %2B. It's a reserved character or something like that.
    So yours would look like this: http://example.com/remove_groups.php?uid=M18Z%2BM5uZnr4PGSusd/smft3Y9g=
    I don't think there's a way to do replace this server-side because it's how URLs work and the browser already translates it. You could just put $UID = 'M18Z+M5uZnr4PGSusd/smft3Y9g='; in the file I think.

    That's like the %20. You can't have a space in an URL so it get's replaced with %20.
     
  16. Ridicc

    Ridicc Super Mod

    PHP:
    if(isset($_GET['name'] && !empty($_GET['name'])

     
    //Do something
    }
    But keep in mind that empty considers 0 as false so it's not possible to set the name to 0 by using an int.

    Btw the config file could look like this.
    PHP:
    $config = array(
      
    'Username'   =>    'name',                          //Query Login tsAGB
      
    'Password'   =>    'pass',                          //Query Password zbCTuqRH
      
    'IP'         =>    '1.1.1.1',                       //Server IP/Domain
      
    'Port'       =>    '9987',                          //Server Port
      
    'qPort'      =>    '10011',                         //Query Port, Default 10011
      
    'Username'   =>    rawurlencode('Name'.rand(1,99))  //Convertes Botname to a URI friendly Format
    );
     
    Kieran likes this.
  17. ServerVerwaltung

    ServerVerwaltung New Member

    Ive got an idea to fix that, ive tested it sometimes and it works if + is the only character that have to be replaced.
    Code:
    <?php
    $RUID = $UID;
    $RUID = str_ireplace(" ", "+", $text);
    echo $RUID;
    ?>
    for example:
    Code:
    <?php
    $text = "M18Z M5uZnr4PGSusd/smft3Y9g=";
    $text = str_ireplace(" ", "+", $text);
    echo $text;
    ?>
    With this we clone and rename a variable and than search for an empty character (space) and replace it with an +.
    If anybody has an better idea, it will be nice to hear.
    Thanks you a lot :)
     
    Kieran likes this.
  18. Kieran

    Kieran Tag me

    Oh that is a smart idea. Didn't even think about that.
     

Share This Page