A secure PHP wrapper for TeamSpeak server owners to safely gather server information and send it to authorized applications.
- Secure connection to TeamSpeak server
- Minimal required permissions
- Data filtering capabilities
- Debug logging
- Easy to integrate with web applications
- Secure configuration management
- Protected sensitive data
- Automatic API key generation
- Secure API authentication
- Multiple authentication methods
teamspeak-query-wrapper/
├── config/ # Configuration files (protected)
│ └── config.php # Main configuration file
├── logs/ # Log directory (protected)
├── public/ # Public web root
│ └── api.php # Public API endpoint
├── src/ # Source code
│ └── TeamSpeakQueryWrapper.php
├── .gitignore
└── README.md
The wrapper requires the following TeamSpeak server permissions:
b_virtualserver_info_view
b_virtualserver_channel_list
b_virtualserver_client_list
b_client_remoteaddress_view
b_serverquery_login
b_client_create_modify_serverquery_login
You may use your existing serveradmin query account for authentication. Since the wrapper runs on your own server, your credentials remain secure and are never exposed externally.
-
Clone the repository:
git clone https://github.com/my-ts-org/teamspeak-query-wrapper.git cd teamspeak-query-wrapper
-
Configure your web server:
- Set the document root to the
public
directory - Ensure the
config
andlogs
directories are not web-accessible - Configure proper permissions for the
logs
directory - Ensure the web server has write permissions to the
config
directory
- Set the document root to the
-
Create configuration:
- Copy
config/config.example.php
toconfig/config.php
- Edit
config/config.php
with your settings:return [ 'teamspeak' => [ 'host' => 'localhost', 'queryPort' => 10011, 'username' => 'your_username', 'password' => 'your_password' ], 'webapp' => [ 'endpoint' => 'https://your-webapp.com/api', 'apiKey' => '' // Leave empty for automatic generation ], 'debug' => [ 'enabled' => false, // Set to true only during testing 'logFile' => __DIR__ . '/../logs/ts_wrapper.log' ] ];
- Copy
-
Configure your TeamSpeak server:
- Create a server query login
- Assign the required permissions
- Note down the username and password
You may use your existing serveradmin query account for authentication. Since the wrapper runs on your own server, your credentials remain secure and are never exposed externally.
Make a POST request to the API endpoint using one of the following authentication methods:
curl -X POST \
-H "Content-Type: application/json" \
-d "{\"api_key\":\"your-api-key\"}" \
http://your-server.com/api.php
curl -X POST \
-F "api_key=your-api-key" \
http://your-server.com/api.php
curl -X POST \
-H "X-API-Key: your-api-key" \
http://your-server.com/api.php
The API will return a JSON response containing:
- Server information
- Channel list
- Client list
The API endpoint requires authentication using one of the following methods:
- JSON body with
api_key
field - Form data with
api_key
field - Custom header
X-API-Key
The API key must match the one stored in your configuration file.
- Exposes sensitive information in error responses
- Logs detailed information about requests
- May reveal API keys and other sensitive data
To disable debug mode in production:
- Open
config/config.php
- Set
'enabled' => false
in the debug section - Ensure the log file is not web-accessible
The wrapper will automatically generate a secure API key when:
- The API key is empty in the configuration
- The API key is set to the default value ('1234567890')
The generated key will be:
- 64 characters long
- Cryptographically secure
- Automatically saved to the configuration file
You can use this API key to authenticate requests to your web application.
You can set up a custom filter to modify the data before it's sent to your webapp:
$ts->setDataFilter(function($data) {
// Example: Remove client IP addresses
foreach ($data['clients'] as &$client) {
unset($client['client_ip']);
}
return $data;
});
- Configuration files are protected outside the web root
- Log files are stored in a protected directory
- Source code is not directly accessible
- Only the public API endpoint is exposed
- Minimal required permissions for TeamSpeak server
- All data can be filtered before sending
- Debug mode helps identify issues (disable in production)
- Connection timeouts prevent hanging
- Error handling for failed connections
- Secure API key generation and management
- POST-only API endpoint
- API key authentication required
- JSON request body validation
- Multiple authentication methods supported
- Debug information available when enabled (disable in production)
Add this to your .htaccess
in the root directory:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
Update your server configuration:
server {
root /path/to/teamspeak-query-wrapper/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
}
MIT License - Feel free to use and modify for your needs.
Contributions are welcome! Please feel free to submit a Pull Request.