[Asterisk-cvs] astcc astcc-users.cgi,NONE,1.1

markster at lists.digium.com markster at lists.digium.com
Thu Sep 16 23:51:49 CDT 2004


Update of /usr/cvsroot/astcc
In directory mongoose.digium.com:/tmp/cvs-serv2987

Added Files:
	astcc-users.cgi 
Log Message:
Merge darren's astcc-users.cgi (bug #2459)


--- NEW FILE: astcc-users.cgi ---
#!/usr/bin/perl
#
# Asterisk(tm) Calling Card Platform
#
# Copyright (C) 2004, Digium, Inc.
#
# Mark Spencer <markster at digium.com
#
# This is the user agent that can be posted in a location on
# the web where the public can access it.  I'm not sure on
# security details.  It was created by Darren Wiebe
# darren at hagenhomes.com by brutally butchering Mark Spencers
# code.  Thanks Mark
#
# This program is Free Software and is distributed under the
# terms of the GNU General Public License version 2 or later
# at your option.
#
use CGI qw/:standard/;
use DBI;
use POSIX qw(strftime);

print header;
my $copyright = "Asterisk&trade; Calling Card User Sheet by Mark Spencer, &copy;2004 Digium, Inc.";
@modes = ( "Cards", );
@languages =  ("en", "de", "fr", "es");
@incs = ("6", "60");
my $dbh;

sub load_config() {
	open(CFG, "</var/lib/astcc/astcc-config.conf");
	while(<CFG>) {
		chomp;
		my ($var, $val) = split(/\s*\=\s*/);
		$config{$var} = $val;
	}
	close(CFG);
}

sub connect_db() {
	my $dsn = "DBI:mysql:database=$config{'dbname'};host=$config{'dbhost'}";
	$dbh->disconnect if $dbh;
	$dbh = DBI->connect($dsn, $config{'dbuser'}, $config{'dbpass'});
}


sub build_home() {
	return "<table width=400><tr><td>Welcome to the Asterisk&trade; Calling Card User Sheet.  Please select " .
	"a function from the menu on the left.</td></tr></table>"
}

sub getcard() {
	my ($cardno) = @_;
	my $res;
	$sth = $dbh->prepare("SELECT * FROM cards WHERE number=" . $dbh->quote($cardno));
	$sth->execute;
	$res = $sth->fetchrow_hashref;
	$sth->finish;
	return $res;
}

sub build_cards() {
	my $total, $used;
	my $pennies, $count, $brand;
	return "Cannot edit cards until database is configured" unless $dbh;
#	my $brands = list_brands();
#	return "Please define at least one brand before creating cards" unless $brands;
	$body = "<table><tr><td>" . start_form . "</td></tr>";
	$body .= "<tr><td>Get information on card&nbsp;&nbsp;" . hidden(-name => "mode", -value => "Cards") .
		textfield(-name => "cardnum", -size => 15)  . "&nbsp;&nbsp;&nbsp;&nbsp;" .
		submit(-name => "action", -value => "Information...") . "</td></tr>";
	$body .= "</table>";
	if ((param('action') eq "Information...") && length(param('cardnum'))) {
		my $cardinfo;
		my $status;
		$cardinfo = &getcard(param('cardnum'));
		if ($cardinfo->{'number'}) {
			$status = "Card&nbsp;&nbsp;</i><b>" . param('cardnum') . "&nbsp;&nbsp;</b><i> has used&nbsp;&nbsp;" .
			"</i><b>$cardinfo->{used}</b></i>" . "&nbsp;&nbsp;of&nbsp;&nbsp;" .
			"</i><b>$cardinfo->{facevalue}</b></i>&nbsp;&nbsp;units\n";
		} else {
			$status = "No such card number '" . param('cardnum') . "' found!\n";
		}
		$body .= "<table>";
		$body .= "<tr bgcolor=ffffff><tdcolspan=4><i>" . $status . "</i></td></tr>\n";
		if ($cardinfo->{'number'}) {
			$body .= "<tr bgcolor=ccccff><td>Caller*ID</td><td>Called Number</td><td>Trunk</td><td>Disposition</td><td>Billable Seconds</td><td>Billed Cost</td></tr>\n";
			my $sth = $dbh->prepare("SELECT * FROM cdrs WHERE cardnum=" . $dbh->quote($cardinfo->{'number'}));
			my $res;
			my $count;
			my $callerid;
			$sth->execute;
			while(($res = $sth->fetchrow_hashref)) {
				$callerid = $res->{callerid};
				$callerid = "&lt;unknown&gt;" unless $callerid;
				$count++;
				if (!($count % 2)) {
					$color = "#ccffcc";
				} else {
					$color = "#ffffcc";
				}
				$body .= "<tr bgcolor=$color><td>$callerid</td><td>$res->{callednum}</td><td>$res->{trunk}</td>" .
					"<td>$res->{disposition}</td><td>$res->{billseconds}</td><td>$res->{billcost}</td></tr>";
			}
		}
		$body .= "</table>";
	}	
	return $body;
}

sub build_body() {
	my ($mode) = @_;
	my $body;
	return &build_cards();
}

my $body;
$mode = "Cards";

&load_config;
&connect_db;

$msg = "&nbsp;";
$body = &build_body($mode);
#$menu = &build_menu($mode);
$msg = "<i>Database unavailable -- please check configuration</i>" unless $dbh;

print "<title>Asterisk&trade; Calling Card Info Sheet</title>\n";
print "<body><table align=center width=800>\n";
print "   <tr><td><img src=\"/_astcc/astcc.png\"></td><td align=center><font face=helvetica size=5>Asterisk&trade; Calling Card Info Sheet</font>" .
		"<br><font face=helvetica color=#444444>$msg</font></td></tr>";
print "   <tr><td height=350 valign=top>$menu</td><td valign=top width=90% align=center><font face=helvetica>$body</font></td></tr>";
print "<tr><td align=center colspan=2><hr><font face=helvetica size=-1>$copyright</font></td></tr>\n";
print "</table></body>\n";




More information about the svn-commits mailing list