#!/usr/bin/php -q Extension_Name", one per line. // There should be a sample with this file. // ***** That's it for configurable stuff, the rest is my rambling and is for // informational purposes only! lol please don't think this document can teach // you the proper way to write php! // // // $internal_users[]="1"; if (file_exists("pbxmonitor.db")) { $dbthing = file("pbxmonitor.db"); foreach ($dbthing as $dbline) { $le = explode("\t", trim($dbline)); $internal_users[$le[0]]=$le[1]; } } $tf = tempnam("$tempdir", "pbxmonitor_"); function return_og_cid($zc) { global $ast, $tf; system("$ast -rx 'show channel $zc' | grep 'Caller ID:'> $tf"); $m = file($tf); if (!isset($m[0])) return "Disconnected or something"; else return substr(trim($m[0]), 11); if (file_exists($tf)) unlink($tf); } function return_og_cid_name($zc) { global $ast, $tf; system("$ast -rx 'show channel $zc' | grep 'Caller ID Name:'> $tf"); $m = file($tf); if (!isset($m[0])) return "Disconnected or something"; else return substr(trim($m[0]), 11); if (file_exists($tf)) unlink($tf); } function return_name($addr) { global $internal_users; if (strstr($addr, "Zap")) return return_og_cid($addr."-1"); else if (isset($internal_users["$addr"])) return $internal_users["$addr"]; else return "Unconfigured extension"; } system("$ast -rx 'show channels' | grep 'Bridged Call' > $tf"); $a = file ($tf); $i=0; if (isset($a[0])) { foreach ($a as $b) { $bt=trim($b); $caller = $c[$i]['caller'] = substr($bt,63,7); if (strstr($caller, "Zap")) $caller = $c[$i]['caller'] = substr($bt,63,5); $caller_name = return_name($caller); if (strstr($bt, "Zap")) { $callee = $c[$i]['callee'] = substr($bt,0,5); if (strstr($callee, "SIP")) $callee = $c[$i]['callee'] = substr($bt,0,7); else if (strstr($callee, "IAX2")) $callee = $c[$i]['callee'] = substr($bt,0,8); $og_cid = $c[$i]['og_cid'] = return_og_cid($callee."-1"); //$og_cid_name = $c[$i]['og_cid_name'] = return_og_cid_name($callee."-1"); if (strstr($callee, "SIP") || strstr($callee, "IAX2")) $og_cid = $c[$i]['og_cid'] = return_name($callee); $c[$i]['tech'] = "Zap"; //$callee_name="'$og_cid_name' <$og_cid>"; $callee_name=$og_cid; } else { if (strstr($bt, "SIP")) { $callee = $c[$i]['callee'] = substr($bt,0,7); $c[$i]['tech'] = "SIP"; } else if (strstr($bt, "IAX2")) { $callee = $c[$i]['callee'] = substr($bt,0,8); $c[$i]['tech'] = "IAX2"; } $callee_name = return_name($callee); } echo "$caller_name > $callee_name\n"; } } else echo "There are no active conversations.\n"; // now for local extens // SAMPLE LINE: // SIP/112-6814 777@internalaugmente Up VoiceMailMain(s112@internalaug // system("$ast -rx 'show channels' > $tf"); system("grep VoiceMail $tf > $tf.2"); system("grep MeetMe $tf >> $tf.2"); system("grep Echo $tf >> $tf.2"); system("grep Playback $tf >> $tf.2"); system("grep BackGround $tf >> $tf.2"); system("grep AGI $tf >> $tf.2"); $thelines=file("$tf.2"); if (isset($thelines[0])) { foreach ($thelines as $aline) { $le = explode(" ", $aline); $chan1 = explode("-", $le[0]); $chan = $chan1[0]; $chan_name = return_name($chan); if (preg_match("/Playback\(([[:alpha:].\-_]*)/", $aline, $matches)) { echo "$chan_name hearing sound file {$matches[1]}\n"; } else if (preg_match("/BackGround\(([[:alpha:].\-_]*)/", $aline, $matches)) { echo "$chan_name hearing sound file {$matches[1]}\n"; } else if (strstr($aline, "VoiceMailMain")) { echo "$chan_name checking Voicemail\n"; } else if (strstr($aline, "Echo")) { echo "$chan_name in Echo chamber\n"; } else if (preg_match("/VoiceMail\([[:alpha:]]*([0-9]*)\@[[:alpha:]]*/", $aline, $matches)) { echo "$chan_name leaving voicemail for> {$matches[1]}\n"; } else if (preg_match("/AGI\(([[:alpha:]._]*)/", $aline, $matches)) { echo "$chan_name in application {$matches[1]}\n"; } else if (preg_match("/MeetMe\(([0-9]*)/", $aline, $matches)) { echo "$chan_name in MeetMe Conference {$matches[1]}\n"; } } @unlink("$tf.2"); } // now let's do parkedcalls: system("$ast -rx 'show parkedcalls' | grep -v Channel | grep -v 'parked call' > $tf"); $thelines=file($tf); if (isset($thelines[0])) { foreach($thelines as $aline) { $alt = trim($aline); $epe = explode(" ", $alt); $pe = $epe[0]; $pchan = substr($alt, 17, 20); $pchan2 = explode("-", $pchan); $pchan3 = $pchan2[0]; if (strstr($pchan3, "SIP") || strstr($pchan3, "IAX2")) { $pchane = explode(" ", $pchan); $pchan = $pchane[0]; $cid = return_name($pchan3); } else { $pchane = explode(" ", $pchan); $pchan = $pchane[0]; $cid = return_og_cid(trim($pchan3)."-1"); } echo "$cid parked on $pe\n"; } } if (file_exists($tf)) @unlink($tf); ?>