Welcome to Geeklog, Anonymous Friday, November 29 2024 @ 04:46 am EST
Geeklog Forums
Block Idea
Status: offline
deek
Forum User
Junior
Registered: 06/03/05
Posts: 34
On my webserver I run a VoIP sever (Ventrilo) and there is a status program that comes with it. I am very new to PHP but am wanting to create a block that will parse the few lines of text that comes out and tell if the server is up (its up if there is text) and how many users are online.
Is there anyone out there who could provide me some direction on how to do this? Thanks.
Is there anyone out there who could provide me some direction on how to do this? Thanks.
14
8
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
care to give an example of those few lines of text you refer to?
13
11
Quote
Status: offline
deek
Forum User
Junior
Registered: 06/03/05
Posts: 34
The command ./ventrilo_status -c2 -t127.0.0.1 returns the following
PHONETIC: Other Side of Special
COMMENT:
AUTH: 1
MAXCLIENTS: 8
VOICECODEC: 0,GSM 6.10
VOICEFORMAT: 3,44100 Hz%2C 16 bit
UPTIME: 19591
PLATFORM: Linux-i386
VERSION: 2.2.0
CHANNELCOUNT: 0
CLIENTCOUNT: 0
and when you GREP it ( ./ventrilo_status -c2 -t127.0.0.1 | grep 'CLIENTCOUNT')
you get
Is this what you wanted?
Text Formatted Code
NAME: Other Side of SpecialPHONETIC: Other Side of Special
COMMENT:
AUTH: 1
MAXCLIENTS: 8
VOICECODEC: 0,GSM 6.10
VOICEFORMAT: 3,44100 Hz%2C 16 bit
UPTIME: 19591
PLATFORM: Linux-i386
VERSION: 2.2.0
CHANNELCOUNT: 0
CLIENTCOUNT: 0
and when you GREP it ( ./ventrilo_status -c2 -t127.0.0.1 | grep 'CLIENTCOUNT')
you get
Text Formatted Code
CLIENTCOUNT: 0Is this what you wanted?
13
11
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
try this type of idea--for your lib-custom.php if you create a php block:
function phpblock_voipOutput(){
global $command_output;
if(empty($command_output)){
$retval = '';
} else {
$pos = strpos($command_output,'CLIENTCOUNT') + 14;//accounts for ': '
$clients = substr($command_output, $pos);
$retval = '<p>Clients online: ' . $clients . '</p>';
}
return $retval;
}
I don't know ventrilo so I cant be accurate at all. And I'm not sure how you'll pass your output to the function, but once it's there, something along these lines should help.
just off the top of my head
Text Formatted Code
function phpblock_voipOutput(){
global $command_output;
if(empty($command_output)){
$retval = '';
} else {
$pos = strpos($command_output,'CLIENTCOUNT') + 14;//accounts for ': '
$clients = substr($command_output, $pos);
$retval = '<p>Clients online: ' . $clients . '</p>';
}
return $retval;
}
just off the top of my head
13
12
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
yes... substr() in the above code will take everything from "clientcount" to the end of the string. If the client count is at the end of the string then all is well, if another piece of data comes after then we have a problem. So we would add a check somehow to create a third parm for substr() telling it where to stop. Perhaps the check would find the position any character not an integer that comes after our count and let that position-1 be substr()'s third parm.
make sense?
make sense?
16
16
Quote
Status: offline
deek
Forum User
Junior
Registered: 06/03/05
Posts: 34
Here is the code I have right now
global $command_output;
$command_output = system("./ventrilo/ventrilo_status -c2 -t127.0.0.1 | grep 'CLIENTCOUNT'");
if(empty($command_output)){
$retval = '';
} else {
$pos = strpos($command_output,'CLIENTCOUNT') + 14;//accounts for ': ';
$clients = substr($command_output, $pos);
$retval = '<p>Clients online: ' . $clients . '</p>';
}
return $retval;
}
I have no idea if i have the syntax on the system correct. I never did get how to use ' or "
The ventrilo_status program will only run when it is then folder. How do I make sure the path is correct. The command I have there will run the program as if i were in my home dir.
Text Formatted Code
function phpblock_voipOutput(){global $command_output;
$command_output = system("./ventrilo/ventrilo_status -c2 -t127.0.0.1 | grep 'CLIENTCOUNT'");
if(empty($command_output)){
$retval = '';
} else {
$pos = strpos($command_output,'CLIENTCOUNT') + 14;//accounts for ': ';
$clients = substr($command_output, $pos);
$retval = '<p>Clients online: ' . $clients . '</p>';
}
return $retval;
}
I have no idea if i have the syntax on the system correct. I never did get how to use ' or "
The ventrilo_status program will only run when it is then folder. How do I make sure the path is correct. The command I have there will run the program as if i were in my home dir.
13
15
Quote
mach
Anonymous
you wont need the "global" line.
and the quickest way to test a path is right or not is to test the script.
have you run it yet? did it work? any errors?
and the quickest way to test a path is right or not is to test the script.
have you run it yet? did it work? any errors?
14
14
Quote
Status: offline
deek
Forum User
Junior
Registered: 06/03/05
Posts: 34
is the system command correct?
here is the block as i have it in lib-custom.php
function phpblock_voipoutput() {
// global $command_output;
$command_output = system("/home/tupper/ventrilo/ventrilo_status -c2 -t127.0.0.1 | grep 'CLIENTCOUNT'");
if(empty($command_output)) {
$retval = 'NOT ON';
} else {
$pos = strpos($command_output,'CLIENTCOUNT') + 14;//accounts for ':
$clients = substr($command_output, $pos);
$retval = '<p>Clients online: ' . $clients . '</p>';
}
return $retval;
}
here is the block as i have it in lib-custom.php
Text Formatted Code
//Ventrilo Statusfunction phpblock_voipoutput() {
// global $command_output;
$command_output = system("/home/tupper/ventrilo/ventrilo_status -c2 -t127.0.0.1 | grep 'CLIENTCOUNT'");
if(empty($command_output)) {
$retval = 'NOT ON';
} else {
$pos = strpos($command_output,'CLIENTCOUNT') + 14;//accounts for ':
$clients = substr($command_output, $pos);
$retval = '<p>Clients online: ' . $clients . '</p>';
}
return $retval;
}
13
12
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
as I said earlier, I don't know the voip software and so the command itself is up to you. But let me make a quick change or two:
//Ventrilo Status
function phpblock_voipoutput() {
//system() only returns last line
$last_line = system("/home/tupper/ventrilo/ventrilo_status -c2 -t127.0.0.1 | grep 'CLIENTCOUNT'", $count);
if(empty($count)) {
$retval = '<p>NOT ON</p>';
} else {
$retval = '<p>Clients online: ' . $count . '</p>';
}
return $retval;
}
adding the 2nd parm to system loads its output into that variable. and because your command uses grep for the clientcount, all the string pos stuff is unnecessary.
HTH
Text Formatted Code
//Ventrilo Status
function phpblock_voipoutput() {
//system() only returns last line
$last_line = system("/home/tupper/ventrilo/ventrilo_status -c2 -t127.0.0.1 | grep 'CLIENTCOUNT'", $count);
if(empty($count)) {
$retval = '<p>NOT ON</p>';
} else {
$retval = '<p>Clients online: ' . $count . '</p>';
}
return $retval;
}
adding the 2nd parm to system loads its output into that variable. and because your command uses grep for the clientcount, all the string pos stuff is unnecessary.
HTH
10
11
Quote
It will now spit out Client online but even if there are 2 or more people on it still only says 1.
So obvioulsy the command to the system is working but not the stripping. Would putting the return value in an array and then stripping after the space and returning the digits work, or is that way to inefficient?
So obvioulsy the command to the system is working but not the stripping. Would putting the return value in an array and then stripping after the space and returning the digits work, or is that way to inefficient?
17
12
Quote
mach
Anonymous
if $count doesn't contain the value then it doesn't matter what you do with it, you won't get anything else than TRUE, which it seems to be now.
my last try:
//Ventrilo Status
function phpblock_voipoutput() {
//system() only returns last line
system("/home/tupper/ventrilo/ventrilo_status -c2 -t127.0.0.1 | grep 'CLIENTCOUNT'", $count);
if(empty($count)) {
$retval = '<p>NOT ON</p>';
} else {
$retval = '<p> . $count . '</p>';
}
return $retval;
}
just a noob myself yaknow
my last try:
Text Formatted Code
//Ventrilo Status
function phpblock_voipoutput() {
//system() only returns last line
system("/home/tupper/ventrilo/ventrilo_status -c2 -t127.0.0.1 | grep 'CLIENTCOUNT'", $count);
if(empty($count)) {
$retval = '<p>NOT ON</p>';
} else {
$retval = '<p> . $count . '</p>';
}
return $retval;
}
11
10
Quote
Status: offline
deek
Forum User
Junior
Registered: 06/03/05
Posts: 34
Thanks so much for your help. I got it working and this is the final code.
function phpblock_voipoutput() {
//system() only returns last line
$status = exec('./ventrilo_status -c2 -t127.0.0.1 | grep 'CLIENTCOUNT'');
if(empty($status)) {
$retval = '<p>Server address: www.othersideofspecial.com:3784</p><p><strong><font color="#FF0000">OFFLINE</font></strong></p><p><a href="http://www.ventrilo.com">Get Ventrilo</a></p>';
} else {
$retval = '<p>Server address: www.othersideofspecial.com:3784</p><p><strong><font color="#00FF00">ONLINE</font></strong><p>' . $status . '</p><p><a href="http://www.ventrilo.com">Get Ventrilo</a></p>';
}
return $retval;
}
Text Formatted Code
//Ventrilo Statusfunction phpblock_voipoutput() {
//system() only returns last line
$status = exec('./ventrilo_status -c2 -t127.0.0.1 | grep 'CLIENTCOUNT'');
if(empty($status)) {
$retval = '<p>Server address: www.othersideofspecial.com:3784</p><p><strong><font color="#FF0000">OFFLINE</font></strong></p><p><a href="http://www.ventrilo.com">Get Ventrilo</a></p>';
} else {
$retval = '<p>Server address: www.othersideofspecial.com:3784</p><p><strong><font color="#00FF00">ONLINE</font></strong><p>' . $status . '</p><p><a href="http://www.ventrilo.com">Get Ventrilo</a></p>';
}
return $retval;
}
13
11
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
I was going to suggest passthru or exec last time, but didn't want to push my luck.
13
10
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
use eregi_replace() to clean your string of the unwanted text.
e.g.:
$status = eregi_replace('CLIENTCOUNT: ', '', $status);
e.g.:
Text Formatted Code
$status = eregi_replace('CLIENTCOUNT: ', '', $status);
10
11
Quote
Status: offline
deek
Forum User
Junior
Registered: 06/03/05
Posts: 34
THIS BLOCK IS FINISHED
Thank you so much for your help. That last little bit just cleaned it up nice and tidy. I had to do a little variable work cause if there is noone online empty() would return false, but it now works exactly like i want it to.
Here is the final code.
//Ventrilo Status
function phpblock_voipoutput() {
$status = exec('./ventrilo_status -c2 -t127.0.0.1 | grep \'CLIENTCOUNT\'');
// Have to put the status variable so that empty() will not return false if noone is logged on
$srvstatus = $status;
$status = eregi_replace('CLIENTCOUNT: ', '', $status);
if(empty($srvstatus)) {
$retval = '<p>Server address: www.othersideofspecial.com:3784</p><p><strong><font color="#FF0000">OFFLINE</font></strong></p><p><a href="http://www.ventrilo.com">Get Ventrilo</a></p>';
} else {
$retval = '<p>Server address: www.othersideofspecial.com:3784</p><p><strong><font color="#00FF00">ONLINE</font></strong></p><p>Clients Online : ' . $status . '</p></p><p><a href="http://www.ventrilo.com">Get Ventrilo</a></p>';
}
return $retval;
}
Thank you so much for your help. That last little bit just cleaned it up nice and tidy. I had to do a little variable work cause if there is noone online empty() would return false, but it now works exactly like i want it to.
Here is the final code.
Text Formatted Code
//Ventrilo Status
function phpblock_voipoutput() {
$status = exec('./ventrilo_status -c2 -t127.0.0.1 | grep \'CLIENTCOUNT\'');
// Have to put the status variable so that empty() will not return false if noone is logged on
$srvstatus = $status;
$status = eregi_replace('CLIENTCOUNT: ', '', $status);
if(empty($srvstatus)) {
$retval = '<p>Server address: www.othersideofspecial.com:3784</p><p><strong><font color="#FF0000">OFFLINE</font></strong></p><p><a href="http://www.ventrilo.com">Get Ventrilo</a></p>';
} else {
$retval = '<p>Server address: www.othersideofspecial.com:3784</p><p><strong><font color="#00FF00">ONLINE</font></strong></p><p>Clients Online : ' . $status . '</p></p><p><a href="http://www.ventrilo.com">Get Ventrilo</a></p>';
}
return $retval;
}
14
13
Quote
All times are EST. The time is now 04:46 am.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content