PDA

View Full Version : Simple "Online/Offline" Status Script


[FBI]_Inque187
14-06-2005, 20:53
Here is a small but simple script I made for those folks who just want to show that their Teamspeak server is "offline" or "online" via their webpage.

Save the below script to a file called "ts_status.php" <?PHP
$ts_ip = "123.45.67.89"; // Change to your server's IP external or domain name
$ts_port = "51234"; // Make sure this port is open on the router or firewall

$output = @fsockopen("$ts_ip", $ts_port, $errno, $errstr, 2);
socket_set_timeout($output, 000002);

if (!$output) {
echo "<FONT COLOR=#DD0000><B>OFFLINE</B></FONT>";
} else {
echo "<FONT COLOR=#00DD00><B>ONLINE</B></FONT>";
}
@fclose($output);
?> Upload the "ts_status.php" file to your FTP Domain.

Then you need to add this line of scipt to whatever page you want the staus to show on: <?PHP include("/home/www/public_html/ts_status.php"); ?> make sure you enter the correct path to where you place the file on your FTP domain. Upload and view the status of your Teamspeak server. Be sure to check the results by turning your server off and on.

You can view a sample demo on this website: http://www.fbi-clan.org/portal.php

cerunsen
02-08-2005, 11:32
your script is exactly what i was looking for.

so I tried it but i got an error :

"Warning: socket_set_timeout(): supplied argument is not a valid stream resource in ...../ts_status.php on line 6"

and the status is always shown "offline"

do you know where it can come from please ?

(excuse my poor english :o )

Deadfred
30-08-2005, 02:09
Thanks man, that really helped, I thought it would be harder than that, like I would need .bat files or something.

And to answer your question cerunsen, you need to add the TCP Query port. If your TS2 server is a local one (as in, it's part of your network) go to the TS2 Server directory and look for server.ini, in there should be the TCP Query port. Copy it and past it into the PHP file.

I did it for mine and it works :)

marcelrx
30-08-2005, 11:23
This script above only checks if the Teamspeak Daemon is running.
It dosn't check if your Virtual Server with maybe server port 8767 is running.

I would use this Script from www.germeshausen.de
<?php
function check_ts($ip, $tcp, $udp, $timeout=1) { //Function for the Check
$fp = @fsockopen($ip, $tcp, $errno, $errstr, $timeout);
if (!$fp) {
$stat = false;
} else {
if (fgets($fp) == "[TS]\r\n") {
fputs($fp, "SEL $udp\r\n");
if (fgets($fp) == "OK\r\n") {
$stat = true;
} else {
$stat = false;
}
} else {
$stat = false;
}
if (is_resource($fp))
@fclose($fp);
return $stat;
}
}

if (check_ts("localhost", 51234, 8767)) { //Change IP, Query-Port and TS-Port
echo "<FONT COLOR=#00DD00><B>ONLINE</B></FONT>";
} else {
echo "<FONT COLOR=#DD0000><B>OFFLINE</B></FONT>";
}
?>

Fredux
18-05-2006, 22:55
hello!
I am trying to setup this script, i done as its told me to, but i get all time Offline eve if the server and prots are open.
Can any one help mne please? i really want to make this work,
Thanks
Antonio

Bastian
19-05-2006, 08:21
As PHP is a server side application, your website hoster must have allowed outgoing connections to other servers. If this functionality is disabled or blocked by a firewall or proxy, you won't be able to run such a script.

Fredux
19-05-2006, 09:11
As PHP is a server side application, your website hoster must have allowed outgoing connections to other servers. If this functionality is disabled or blocked by a firewall or proxy, you won't be able to run such a script.

How do i know if its disabled or now? in my host? will it be saying somewher ein my host panel?
Thanks

ScP
19-05-2006, 12:03
Simply remove the @-char in front of the fsockopen()-function.

Mickey
27-11-2006, 00:50
This script above only checks if the Teamspeak Daemon is running.
It dosn't check if your Virtual Server with maybe server port 8767 is running.

I would use this Script from www.germeshausen.de
<?php
function check_ts($ip, $tcp, $udp, $timeout=1) { //Function for the Check
$fp = @fsockopen($ip, $tcp, $errno, $errstr, $timeout);
if (!$fp) {
$stat = false;
} else {
if (fgets($fp) == "[TS]\r\n") {
fputs($fp, "SEL $udp\r\n");
if (fgets($fp) == "OK\r\n") {
$stat = true;
} else {
$stat = false;
}
} else {
$stat = false;
}
if (is_resource($fp))
@fclose($fp);
return $stat;
}
}

if (check_ts("localhost", 51234, 8767)) { //Change IP, Query-Port and TS-Port
echo "<FONT COLOR=#00DD00><B>ONLINE</B></FONT>";
} else {
echo "<FONT COLOR=#DD0000><B>OFFLINE</B></FONT>";
}
?>

So hey is this what I do?:



<?php
function check_ts($ip, $tcp, $udp, $timeout=1) { //Function for the Check
$fp = @fsockopen($ip, $tcp, $errno, $errstr, $timeout);
if (!$fp) {
$stat = false;
} else {
if (fgets($fp) == "[TS]\r\n") {
fputs($fp, "SEL $udp\r\n");
if (fgets($fp) == "OK\r\n") {
$stat = true;
} else {
$stat = false;
}
} else {
$stat = false;
}
if (is_resource($fp))
@fclose($fp);
return $stat;
}
}

if (check_ts("my ip here", 51234, 8767)) { //
echo "<FONT COLOR=#00DD00><B>ONLINE</B></FONT>";
} else {
echo "<FONT COLOR=#DD0000><B>OFFLINE</B></FONT>";
}
?>

Reedy Boy
27-11-2006, 10:41
So hey is this what I do?:



<?php
function check_ts($ip, $tcp, $udp, $timeout=1) { //Function for the Check
$fp = @fsockopen($ip, $tcp, $errno, $errstr, $timeout);
if (!$fp) {
$stat = false;
} else {
if (fgets($fp) == "[TS]\r\n") {
fputs($fp, "SEL $udp\r\n");
if (fgets($fp) == "OK\r\n") {
$stat = true;
} else {
$stat = false;
}
} else {
$stat = false;
}
if (is_resource($fp))
@fclose($fp);
return $stat;
}
}

if (check_ts("my ip here", 51234, 8767)) { //
echo "<FONT COLOR=#00DD00><B>ONLINE</B></FONT>";
} else {
echo "<FONT COLOR=#DD0000><B>OFFLINE</B></FONT>";
}
?>


No exactly

You need to enter your IP of your TS server in the place where it says "my ip here"

Stick that code in a file called ts_status.php

And then were you want it on your web server

<?PHP include("./ts_status.php"); ?>