[TS3 STATUS BOT]

Discussion in 'PHP' started by codex, Jan 7, 2017.

  1. codex

    codex New Member

    Code written for fun. I decided to share with you ;)
    PHP:
    <?php

    require_once('libraries/TeamSpeak3/TeamSpeak3.php');

        
    /*
         * Config Server
        */
        
    $cfg = array('address' => 'YOUR IP'//IP Address
                     
    'serveradmin' => 'YOUR USERNAME'//Login Name ServerQuery
                     
    'password' => 'YOUR PASSWORD'//Login Password Server Query
                     
    'queryport' => '10011'//Login Port Server Query
                     
    'port' => '9987'//Server Port
                     
    'nickname' => 'BOT-Status'); //Nickname Query

        
    try {
          
            
    /*
             * Connection TeamSpeak
            */
          
            
    $ts3_VirtualServer TeamSpeak3::factory("serverquery://{$cfg['serveradmin']}:{$cfg['password']}@{$cfg['address']}:{$cfg['queryport']}/?server_port={$cfg['port']}&nickname={$cfg['nickname']}");
          
            
    /*
             * TeamSpeak Server Name
            */
          
            
    $ServerName $ts3_VirtualServer->virtualserver_name;
          
            
    /*
             * Status Server
            */
          
            
    $ServerStatus $ts3_VirtualServer->virtualserver_status;
          
            
    /*
             * IP Address and Port
            */
          
            
    $ServerIP $ts3_VirtualServer->getAdapterHost() . ":" $ts3_VirtualServer->virtualserver_port;
          
            
    /*
             * Online User
            */
          
            
    $OnlineUser $ts3_VirtualServer->virtualserver_clientsonline "/" $ts3_VirtualServer->virtualserver_maxclients;

            
    /*
             * Channels Online
            */
          
            
    $channels $ts3_VirtualServer->virtualserver_channelsonline;
          
            
    /*
             * Server Created
            */
          
            
    $CreatedInSecond $ts3_VirtualServer->virtualserver_created;
            
    $created date('d/m/Y H:i:s',$CreatedInSecond);
          
            
    /*
             * Server Version
            */
          
            
    $ServerVersion TeamSpeak3_Helper_Convert::versionShort($ts3_VirtualServer->virtualserver_version);
          
            
    /*
             * Server Platform
            */
          
            
    $platform $ts3_VirtualServer->virtualserver_platform;
          
            
    /*
             * Status Admin (Online/Offline)
            */
          
            
    $Users $ts3_VirtualServer->clientList();
                                                              
            
    $IsAdminOnline false;
          
            foreach (
    $Users as $User)
            {
                if(
    $User['client_unique_identifier'] == 'ru1zvdZR3hpt/E7lhQJRoLQgaeQ=')
                {
                    
    $IsAdminOnline true;
                    
    $nickname $User['client_nickname'];
                }
            }
          
            if (
    $IsAdminOnline)
                
    $statusAdmin "<b>$nickname</b>" " " '<span class="AdminOnline">ONLINE</span>';
            else
                
    $statusAdmin '<span class="AdminOffline">OFFLINE</span>';
          
        } catch(
    TeamSpeak3_Exception $e) {
            echo 
    '<div class="container">
                    <div class="panel panel-danger">
                        <div class="panel-heading">' "Error: " 
    $e->getCode() . ' </div>
                        <div class="panel-body">' 
    $e->getMessage() . '</div>
                    </div>
                  </div>'
    ;

        }
      
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>TS3 Status - <?php  echo $ServerName ?></title>
        <!-- Bootstrap -->
        <link href="https://cdn.jsdelivr.net/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

        <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->

        <style>
            body {
                margin-top: 20px;
                background: #606060;
                font-size: 16px;
            }
          
            .panel {
                border: none;
                box-shadow: none;
            }
          
            .panel-default {
                border-color: transparent;
            }
          
            .panel-default > .panel-heading {
                background-color: #414141;
                border-color: transparent;
            }
          
            .default-text {
                color: rgb(0, 204, 255);
                text-shadow: rgb(35, 201, 242) 0px 0px 8px;
            }
          
            .deafult2-text {
                color: rgb(255, 215, 0);
                text-shadow: rgb(255, 215, 0) 0px 0px 5px;
            }
          
            .AdminOnline {
                color: rgb(0, 204, 0);
                text-shadow: rgb(42, 255, 0) 1px 0px 10px;
            }
          
            .AdminOffline {
                color: red;
                text-shadow: red 1px 0px 10px;
            }

        </style>

    </head>

    <body>

        <div class="container">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <?php echo $ServerName ?>
                </div>
                <div class="panel-body">
                    <table>
                        <tr>
                            <td>
                                <b>Status:</b> <span class="default-text "><?php echo $ServerStatus?></span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <b>IP:</b> <span class="default-text "><?php echo $ServerIP?></span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <b>User:</b> <span class="deafult2-text"><?php echo $OnlineUser?></span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <b>Channel:</b> <span class="deafult2-text"><?php echo $channels?></span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <b>Created:</b> <span class="deafult2-text"><?php echo $created?></span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <b>Version:</b> <span class="deafult2-text"><?php echo $ServerVersion?></span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <b>Platform:</b> <span class="deafult2-text"> <?php echo $platform;  ?></span>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">Admin</div>
                <div class="panel-body">
                    <?php echo $statusAdmin?>
                </div>
            </div>
        </div>

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    </body>

    </html>
     
    Last edited: Jan 7, 2017
  2. Ridicc

    Ridicc Super Mod

    Why would you create a string for everything if you're just printing it out anyways? Just do it like this?
    PHP:
    <title>TS3 Status - <?php echo $ts3_VirtualServer->virtualserver_name?></title>
     
  3. codex

    codex New Member

    for the clarity :)
     
  4. MadKill

    MadKill VIP

    Code:
    if($User['client_unique_identifier'] == 'ru1zvdZR3hpt/E7lhQJRoLQgaeQ=')
    why you dont use by permission ?
     
  5. codex

    codex New Member

    dirty code, check a user only
     

Share This Page