Welcome to Geeklog, Anonymous Thursday, March 28 2024 @ 06:17 am EDT

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.
 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?
 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

Text Formatted Code
NAME: Other Side of Special
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

Text Formatted Code
CLIENTCOUNT: 0
 


Is this what you wanted?
 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:
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;
}

 
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 Giving it a try
 Quote

Status: offline

deek

Forum User
Junior
Registered: 06/03/05
Posts: 34
thanks for the response. a few years back i took a class on php. i rememger a function that would run a command on the system. would that be possible get the command_output for the function?
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
system() should do fine.
 Quote

Status: offline

deek

Forum User
Junior
Registered: 06/03/05
Posts: 34
Will the above code work if there is more than 9 users?
 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?
 Quote

Status: offline

deek

Forum User
Junior
Registered: 06/03/05
Posts: 34
Here is the code I have right now
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.
 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?
 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
Text Formatted Code
//Ventrilo Status
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;
}
 
 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:
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
 Quote

Status: offline

deek

Forum User
Junior
Registered: 06/03/05
Posts: 34
excited
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?
 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:
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;
}

 
just a noob myself yaknow Leaves me speechless
 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.
Text Formatted Code
//Ventrilo Status
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;
}
 
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
Laughing I was going to suggest passthru or exec last time, but didn't want to push my luck.
 Quote

Status: offline

deek

Forum User
Junior
Registered: 06/03/05
Posts: 34
So get CLIENTCOUNT: 1 from the status variable.


what would i need to do now is to this to strip only what comes after the : so can get rid of of the CLIENTCOUTN and just have a number. Any ideas on that one?
 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.:
Text Formatted Code

$status = eregi_replace('CLIENTCOUNT: ', '', $status);

 
 Quote

Status: offline

deek

Forum User
Junior
Registered: 06/03/05
Posts: 34
THIS BLOCK IS FINISHED Very Happy

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;
}
 
 Quote

All times are EDT. The time is now 06:17 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