/asterisk-stats/trunk/summary.php |
---|
0,0 → 1,45 |
<?php |
#################################################### |
# AstWeb - Asterisk PBX Dynamic config environment # |
# # |
# Written by: Jamie Carl # |
# jazz@funkynerd.com # |
# # |
# Copyright (C) 2006 Achieve Corp # |
# # |
# Licence: This software is licenced under the # |
# GNU/GPL. Please see licence.txt for # |
# more information. # |
#################################################### |
if(!defined('IN_ASTWEB')) { |
die('Hacking attempt!'); |
} |
function add_summary($count_name, $dur_name, $interval) |
{ |
global $db, $display; |
$db->query("select count(acctid), sum(billsec) from cdr where" . BaseQuery() |
. ($interval ? " and date_trunc('" . $interval . "', calldate) = date_trunc('" |
. $interval . "', current_date)" : "")); |
$db->fetch_row_idx(); |
$display->add_variables(array($count_name => $db->get_field(0), |
$dur_name => Duration($db->get_field(1)))); |
} |
# active calls |
$db->query("select count(acctid), sum(extract(epoch from date_trunc('second',current_timestamp-linkdate)))" |
. " from activecalls where" . BaseQuery() . " and duration is null"); |
$db->fetch_row_idx(); |
$display->add_variables(array('CS_ACTIVE' => $db->get_field(0), |
'CS_ACTIVE_DUR' => Duration($db->get_field(1)))); |
add_summary('CS_TODAY', 'CS_TODAY_DUR', 'day'); |
add_summary('CS_WEEK', 'CS_WEEK_DUR', 'week'); |
add_summary('CS_MONTH', 'CS_MONTH_DUR', 'month'); |
add_summary('CS_YEAR', 'CS_YEAR_DUR', 'year'); |
add_summary('CS_TOTAL', 'CS_TOTAL_DUR', null); |
$display->add_template('summary'); |
?> |
/asterisk-stats/trunk/config.php-dist |
---|
0,0 → 1,42 |
<?php |
#################################################### |
# AstWeb - Asterisk PBX Dynamic config environment # |
# # |
# Written by: Jamie Carl # |
# jazz@funkynerd.com # |
# # |
# Copyright (C) 2006 Achieve Corp # |
# # |
# Licence: This software is licenced under the # |
# GNU/GPL. Please see licence.txt for # |
# more information. # |
#################################################### |
/* Do NOT touch this! */ |
if ( !defined('IN_ASTWEB') ) { |
die("Hacking attempt"); |
} |
/* Configuration settings */ |
$tpl_dir = 'templates'; |
$img_dir = 'images'; |
$site_title = 'Asterisk Web Interface'; |
$site_style = 'astweb.css'; |
$includes = 'includes'; |
$db_type = 'PGSQL'; |
$db_host = 'localhost'; |
$db_user = 'astweb'; |
$db_password = 'password'; |
$db_database = 'asterisk'; |
// any local specific query |
function BaseQuery() |
{ |
return " (dstchannel is null or dstchannel != '')"; |
} |
?> |
/asterisk-stats/trunk/cdr.php |
---|
0,0 → 1,190 |
<?php |
#################################################### |
# AstWeb - Asterisk PBX Dynamic config environment # |
# # |
# Written by: Jamie Carl # |
# jazz@funkynerd.com # |
# # |
# Copyright (C) 2006 Achieve Corp # |
# # |
# Licence: This software is licenced under the # |
# GNU/GPL. Please see licence.txt for # |
# more information. # |
#################################################### |
if(!defined('IN_ASTWEB')) { |
die('Hacking attempt!'); |
} |
if(array_key_exists('detail', $_GET)) { |
$cdr_detail = array(); |
$db->query_params('SELECT * FROM cdr WHERE acctid=$1', array($_GET['detail'])); |
$detail = $db->fetch_row(); |
for ($i=0;$i<$db->num_fields();$i++) { |
$col = $db->get_field_name($i); |
$cdr_detail['CDR_'.strtoupper($col)] = $detail[$col]; |
} |
$cdr_detail['CDR_STATUS'] = ($detail ? 'DONE' : 'NOT FOUND'); |
$cdr_detail['CDR_DURATION_F'] = Duration($detail['duration']); |
$cdr_detail['CDR_BILLSEC_F'] = Duration($detail['billsec']); |
$display->add_variables($cdr_detail); |
$display->add_template('cdr_detail'); |
} |
elseif(array_key_exists('active', $_GET)) { |
$cdr_detail = array(); |
$db->query_params("SELECT acctid, calldate, linkdate, clid, src, dst, dcontext," |
. " channel, dstchannel, lastapp, lastdata," |
. " extract(epoch from date_trunc('second',current_timestamp-calldate)) as duration," |
. " extract(epoch from date_trunc('second',current_timestamp-linkdate)) as billsec," |
. " disposition, amaflags, accountcode, uniqueid, userfield FROM activecalls" |
. " WHERE acctid=$1 and duration is null", array($_GET['active'])); |
$detail = $db->fetch_row(); |
for ($i=0;$i<$db->num_fields();$i++) { |
$col = $db->get_field_name($i); |
$cdr_detail['CDR_'.strtoupper($col)] = $detail[$col]; |
} |
$cdr_detail['CDR_STATUS'] = ($detail ? 'ACTIVE' : 'NOT FOUND'); |
$cdr_detail['CDR_DURATION_F'] = Duration($detail['duration']); |
$cdr_detail['CDR_BILLSEC_F'] = Duration($detail['billsec']); |
$display->add_variables($cdr_detail); |
$display->add_template('cdr_detail'); |
} |
elseif(array_key_exists('s', $_GET) || array_key_exists('list', $_GET)) { |
function do_field($sql, &$params, $fld) { |
if($fld && $_GET[$fld]) { |
$sql .= " and $fld"; |
if(array_key_exists($fld.'type', $_GET)) { |
$dType = $_GET[$fld.'type']; |
switch($dType) { |
case 1: |
array_push($params, $_GET[$fld]); |
$sql .= "=$" . count($params); |
break; |
case 2: |
array_push($params, "$_GET[$fld]%"); |
$sql .= " LIKE $" . count($params); |
break; |
case 3: |
array_push($params, "%$_GET[$fld]%"); |
$sql .= " LIKE $" . count($params); |
break; |
case 4; |
array_push($params, "%$_GET[$fld]"); |
$sql .= " LIKE $" . count($params); |
} |
} |
else { |
array_push($params, "%$_GET[$fld]%"); |
$sql .= " LIKE $" . count($params); |
} |
} |
return $sql; |
} |
function do_date_compare($period) |
{ |
return " and date_trunc('" . $period . "', calldate) = date_trunc('" |
. $period . "', current_date)"; |
} |
# Construct Query Here |
$query = BaseQuery(); |
$params = array(); |
$active = false; |
if ($_GET['before']) { |
array_push($params, $_GET['before']); |
$query .= " AND calldate < $" . count($params); |
} |
if ($_GET['after']) { |
array_push($params, $_GET['after']); |
$query .= " AND calldate > $" . count($params); |
} |
$query = do_field($query, $params, 'clid'); |
$query = do_field($query, $params, 'src'); |
$query = do_field($query, $params, 'dst'); |
$query = do_field($query, $params, 'channel'); |
$query_limit = ''; |
if(array_key_exists('list',$_GET)) { |
switch($_GET['list']) { |
case 'year': $query .= do_date_compare('year'); break; |
case 'month': $query .= do_date_compare('month'); break; |
case 'week': $query .= do_date_compare('week'); break; |
case 'today': $query .= do_date_compare('day'); break; |
case 'active': |
$active = true; |
$query .= " and duration is null"; |
break; |
default: $query_limit .= " limit 1000"; |
} |
} |
if($active) { |
$list_query = "select acctid,calldate,src,dst," |
. " extract(epoch from date_trunc('second'," |
. " current_timestamp-linkdate)) as billsec,disposition" |
. " from activecalls where" |
. $query . " order by calldate desc" . $query_limit; |
} |
else { |
$list_query = "select acctid,calldate,src,dst,billsec,disposition" |
. " from cdr where" |
. $query . " order by calldate desc" . $query_limit; |
} |
$result = $db->query_params($list_query, $params); |
$calls_number = $db->num_rows(); |
$cdr = new Table(array('ID', 'Call Date', 'Source', 'Destination', 'Duration', 'Disposition')); |
$cdr->set_table_class('stat cdr list'); |
while($line = $db->fetch_row()) { |
$cdr->newrow(); |
$cdr->addcell($line['acctid']); |
$cdr->addcell($line['calldate']); |
$cdr->addcell($line['src']); |
$cdr->addcell($line['dst']); |
$cdr->addcell($line['disposition'] == 'ANSWERED' ? Duration($line['billsec']) : ''); |
$cdr->addcell(strtolower($line['disposition'])); |
$cdr->addcell(array('class' => 'link', 'html' => |
display_link($PHP_SELF . '?m=cdr&' . ($active ? 'active' : 'detail') |
. '=' . $line['acctid'], 'Details'))); |
} |
$display->add_text($cdr->build()); |
// summary |
if($active) { |
$sum_query = "select" |
. " sum(extract(epoch from date_trunc('second',current_timestamp-calldate))) as dur," |
. " sum(extract(epoch from date_trunc('second',current_timestamp-linkdate))) as bill" |
. " from activecalls where" . $query; |
} |
else { |
$sum_query = "select sum(duration) as dur, sum(billsec) as bill from cdr where" . $query; |
} |
$result = $db->query_params($sum_query, $params); |
$line = $db->fetch_row(); |
$cdr = new Table(); |
$cdr->set_table_class('stat cdr sum'); |
$cdr->addcell(array('tag' => 'th', 'text' => 'Calls')); |
$cdr->addcell($calls_number); |
$cdr->newrow(); |
$cdr->addcell(array('tag' => 'th', 'text' => 'Call Seconds')); |
$cdr->addcell(Duration($line['dur'])); |
$cdr->newrow(); |
$cdr->addcell(array('tag' => 'th', 'text' => 'Bill Seconds')); |
$cdr->addcell(Duration($line['bill'])); |
$display->add_text($cdr->build()); |
} |
else { |
$display->add_variables(array('CDR_METHOD' => 'GET', 'CDR_ACTION' => $PHP_SELF)); |
$display->add_template('cdr'); |
} |
?> |
/asterisk-stats/trunk/includes/.htaccess |
---|
File deleted |
/asterisk-stats/trunk/includes/cdr.php |
---|
File deleted |
Property changes: |
Deleted: svn:mergeinfo |
/asterisk-stats/trunk/includes/config.php-dist |
---|
File deleted |
Property changes: |
Deleted: svn:mergeinfo |
/asterisk-stats/trunk/includes/summary.php |
---|
File deleted |
Property changes: |
Deleted: svn:mergeinfo |
/asterisk-stats/trunk/includes/db/postgresql.php |
---|
12,6 → 12,10 |
# more information. # |
#################################################### |
if ( !defined('IN_ASTWEB') ) { |
die("Hacking attempt"); |
} |
class db_obj { |
private $connection; |
private $result; |
/asterisk-stats/trunk/includes/db.php |
---|
12,9 → 12,13 |
# more information. # |
#################################################### |
if ( !defined('IN_ASTWEB') ) { |
die("Hacking attempt"); |
} |
switch($db_type) { |
case 'PGSQL': |
include('includes/db/postgresql.php'); |
include($includes.'/db/postgresql.php'); |
break; |
} |
/asterisk-stats/trunk/includes/display.php |
---|
1,4 → 1,7 |
<?php |
if ( !defined('IN_ASTWEB') ) { |
die("Hacking attempt"); |
} |
class template_handler { |
private $data = array(); |
/asterisk-stats/trunk/includes/functions.php |
---|
1,5 → 1,10 |
<?php |
if(!defined('IN_ASTWEB')) { |
die('Hacking Attempt'); |
} |
$PHP_SELF = $_SERVER['PHP_SELF']; |
function GetGet($var) { |
/asterisk-stats/trunk/astweb.php |
---|
0,0 → 1,46 |
<?php |
#################################################### |
# AstWeb - Asterisk PBX Dynamic config environment # |
# # |
# Written by: Jamie Carl # |
# jazz@funkynerd.com # |
# # |
# Copyright (C) 2006 Achieve Corp # |
# # |
# Licence: This software is licenced under the # |
# GNU/GPL. Please see licence.txt for # |
# more information. # |
#################################################### |
define('IN_ASTWEB', true); |
include_once('config.php'); |
include_once($includes.'/display.php'); |
include_once($includes.'/functions.php'); |
include_once($includes.'/db.php'); |
$display = new template_handler('template'); |
$display->add_template('header'); |
$display->add_template('menu'); |
$pg_globals = array('AST_STYLESHEET' => $site_style, |
'AST_SITETITLE' => $site_title, |
'AST_DATETIME' => date('Y-m-d H:i:s'), |
'HREF_HOME' => $PHP_SELF, |
'HREF_CDR' => $PHP_SELF.'?m=cdr', |
'HREF_CDR_LIST' => $PHP_SELF.'?m=cdr&list'); |
$display->add_variables($pg_globals); |
switch($_GET['m']) { |
case 'cdr': |
include('cdr.php'); |
break; |
default: |
include('summary.php'); |
} |
$display->add_template('footer'); |
echo $display; |
?> |
/asterisk-stats/trunk/index.php |
---|
1,44 → 1,3 |
<?php |
#################################################### |
# AstWeb - Asterisk PBX Dynamic config environment # |
# # |
# Written by: Jamie Carl # |
# jazz@funkynerd.com # |
# # |
# Copyright (C) 2006 Achieve Corp # |
# # |
# Licence: This software is licenced under the # |
# GNU/GPL. Please see licence.txt for # |
# more information. # |
#################################################### |
include_once('includes/config.php'); |
include_once('includes/display.php'); |
include_once('includes/functions.php'); |
include_once('includes/db.php'); |
$display = new template_handler('template'); |
$display->add_template('header'); |
$display->add_template('menu'); |
$pg_globals = array('AST_STYLESHEET' => $site_style, |
'AST_SITETITLE' => $site_title, |
'AST_DATETIME' => date('Y-m-d H:i:s'), |
'HREF_HOME' => $PHP_SELF, |
'HREF_CDR' => $PHP_SELF.'?m=cdr', |
'HREF_CDR_LIST' => $PHP_SELF.'?m=cdr&list'); |
$display->add_variables($pg_globals); |
switch($_GET['m']) { |
case 'cdr': |
include('includes/cdr.php'); |
break; |
default: |
include('includes/summary.php'); |
} |
$display->add_template('footer'); |
echo $display; |
header('Location: astweb.php'); |
?> |
Property changes: |
Deleted: svn:mergeinfo |