[Asterisk-cvs] astcc Makefile, 1.4, 1.5 astcc-admin.cgi, 1.10, 1.11 astcc.agi, 1.10, 1.11

markster at lists.digium.com markster at lists.digium.com
Fri Oct 1 22:46:21 CDT 2004


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

Modified Files:
	Makefile astcc-admin.cgi astcc.agi 
Log Message:
Merge darren's updated astcc patch (bug #2554)


Index: Makefile
===================================================================
RCS file: /usr/cvsroot/astcc/Makefile,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Makefile	15 Jul 2004 00:15:54 -0000	1.4
+++ Makefile	2 Oct 2004 02:48:25 -0000	1.5
@@ -31,6 +31,8 @@
 		chown $(USER) $(DESTDIR)$(ASTCC)/astcc-exten.conf
 		touch $(DESTDIR)$(ASTCC)/astcc-config.conf
 		chown $(USER) $(DESTDIR)$(ASTCC)/astcc-config.conf
+		touch $(DESTDIR)$(ASTCC)/users-astcc-config.conf
+		chown $(USER) $(DESTDIR)$(ASTCC)/users-astcc-config.conf
 		
 		for x in sounds/*.gsm; do \
 			install -m 644 $$x $(DESTDIR)$(SOUNDSDIR); \

Index: astcc-admin.cgi
===================================================================
RCS file: /usr/cvsroot/astcc/astcc-admin.cgi,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- astcc-admin.cgi	30 Sep 2004 01:08:38 -0000	1.10
+++ astcc-admin.cgi	2 Oct 2004 02:48:25 -0000	1.11
@@ -10,13 +10,20 @@
 # terms of the GNU General Public License version 2 or later
 # at your option.
 #
+# This program can be called from the web browser or from 
+# another page with options to generate a card automatically.
+# ie. http://127.0.0.1/cgi-bin/astcc-admin/astcc-admin.cgi?md=Auto&pn=500&em=root@localhost&iax=y&sip=n
+# would generate a card with 500 pennies on it and send an
+# email containing the info to root at localhost.  It would 
+# also add a user to the iaxfriends database.
+
 use CGI qw/:standard/;
 use DBI;
 use POSIX qw(strftime);
 
 print header;
 my $copyright = "Asterisk™ Calling Card Manager by Mark Spencer, ©2004 Digium, Inc.";
- at modes = ( "Home", "Brands", "Cards", "Trunks", "Routes", "Configure" );
+ at modes = ( "Home", "Brands", "Cards", "Trunks", "Routes", "Configure", "Users_Configure", "IAX_Friends", "SIP_Friends" );
 @languages =  ("en", "de", "fr", "es");
 @techs = ( "SIP", "IAX2", "Zap", "Local" );
 @incs = ("6", "60");
@@ -37,12 +44,41 @@
 	close(CFG);
 }
 
+sub users_load_config() {
+	open(CFG, "</var/lib/astcc/users-astcc-config.conf");
+	while(<CFG>) {
+		chomp;
+		my ($var, $val) = split(/\s*\=\s*/);
+		$users_config{$var} = $val;
+	}
+	close(CFG);
+}
+
+sub users_connect_db() {
+	my $users_dsn = "DBI:mysql:database=$users_config{'dbname'};host=$users_config{'dbhost'}";
+	$users_dbh->disconnect if $users_dbh;
+	$users_dbh = DBI->connect($users_dsn, $users_config{'dbuser'}, $users_config{'dbpass'});
+}
+
+
 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 users_create_db() {
+	my $users_drh = DBI->install_driver("mysql");
+	return -1 unless $users_drh;
+	return -1 unless $users_drh->func('createdb', $users_config{'dbname'}, $users_config{'dbhost'}, $users_config{'dbuser'}, 
+								$users_config{'dbpass'}, 'admin');
+	users_connect_db();
+	return -1 unless $users_dbh;
+	return -1 unless $users_dbh->do("CREATE TABLE sipfriends (name CHAR(40) NOT NULL PRIMARY KEY, username CHAR(40), secret CHAR(40) NOT NULL, context char(40) NOT NULL, ipaddr char(20) NOT NULL, port INTEGER(6) NOT NULL default '0', regseconds INTEGER(11))");
+	return -1 unless $users_dbh->do("CREATE TABLE iaxfriends (name CHAR(40) PRIMARY KEY, secret CHAR(40), context CHAR(40), ipaddr CHAR(20), port INTEGER(6), regseconds INTEGER(11) NOT NULL)");
+	return 0;
+}
+
 sub create_db() {
 	my $drh = DBI->install_driver("mysql");
 	return -1 unless $drh;
@@ -58,6 +94,11 @@
 	return 0;
 }
 
+sub users_update_db() {
+	return -1 unless $dbh->do("CREATE TABLE cdrs (cardnum CHAR(40), callerid char(80), callednum CHAR(80), trunk CHAR(40), disposition CHAR(20), billseconds INTEGER, billcost INTEGER callstart CHAR(24))");
+	return 0;
+}	
+
 sub save_config() {
 	my $tmp;
 	open(CFG, ">/var/lib/astcc/astcc-config.conf");
@@ -67,6 +108,17 @@
 	}
 	close(CFG);
 }
+
+sub users_save_config() {
+	my $tmp;
+	open(CFG, ">/var/lib/astcc/users-astcc-config.conf");
+	print CFG ";\n; Automatically created by astcc-admin.cgi.\n;\n";
+	foreach $tmp (keys %users_config) {
+		print CFG "$tmp = $users_config{$tmp}\n";
+	}
+	close(CFG);
+}
+
 sub build_menu() {
 	my ($selected) = @_;
 	my $body;
@@ -196,7 +248,7 @@
 }
 
 sub generatecards() {
-	my ($count, $pennies, $brand) = @_;
+	my ($count, $pennies, $brand, $customnum) = @_;
 	my $row;
 	my $x;
 	my $number;
@@ -216,7 +268,11 @@
 	$sth->finish;
 	# add cards -- face value is in 1/100 of a penny
 	for ($x=0; $x < $count; $x++) {
-		$number = &findunique;
+		if ($customnum ne '') {
+			$number = $customnum;
+		} else {
+			$number = &findunique;
+		}
 		&addcard($number, $language, $pennies * 100, $inc, $markup);
 		if ($config{'email'} eq "YES") {
 			print EMAIL "$number \n";
@@ -230,8 +286,69 @@
 	return $status;
 }
 
-sub getcard() {
-	my ($cardno) = @_;
+sub users_generatecards() {
+	my ($pennies, $users_email, $iax, $sip) = @_;
+	my $brand = $users_config{brand};
+#	my $pennies = $auto_pennies;
+	my $count = 1;
+	my $row;
+	my $x;
+	my $number;
+	my $status = "";
+	my ($language, $inc, $markup);
+	# Retrieve brand specifications
+	my $sth = $dbh->prepare("SELECT * FROM brands WHERE name = " . $dbh->quote($brand));
+	$sth->execute;
+	if ($users_config{'email'} eq "YES") {
+		open (EMAIL_ADMIN, "| $users_config{mailprog} $users_config{emailadd} -s 'New Cards Created'") ||
+			die "Error - could not write to $users_config{mailprog}\n";
+		print EMAIL_ADMIN "You have added $count $brand cards in the amount of $auto_pennies cents. \n\n"; 
+	}
+	open (USERS_EMAIL, "| $users_config{mailprog} $users_email -s 'Your Account Has Been Added'") ||
+			die "Error - could not write to $users_config{mailprog}\n";
+	print USERS_EMAIL "Thank you for your patronage.  Your account has been added\n";
+	if ($row = $sth->fetchrow_hashref) {
+		($language, $inc, $markup) = ($row->{language}, $row->{inc}, $row->{markup});
+	}
+	$sth->finish;
+	# add cards -- face value is in 1/100 of a penny
+#	for ($x=0; $x < $count; $x++) {
+		$number = &findunique;
+		&addcard($number, $language, $pennies * 100, $inc, $markup);
+		$secret = &findunique;
+		if ($users_config{'email'} eq "YES") {
+			print EMAIL_ADMIN "Account Number: $number \n";
+			print EMAIL_ADMIN "Password: $secret \n";
+			print EMAIL_ADMIN "Balance (Pennies): $pennies \n";
+		}
+		print USERS_EMAIL "Account Number: $number \n";
+		print USERS_EMAIL "Password: $secret \n";
+		print USERS_EMAIL "Balance (cents): $pennies \n";
+		if ($sip eq "y" ) {
+			&add_sip_user($number, $secret);
+		}
+		if ($iax eq "y" ) {	
+			&add_iax_user($number, $secret);
+		}	
+#	}
+	
+	if ($users_config{'email'} eq "YES") {
+		print EMAIL_ADMIN ".\n";
+		close (EMAIL_ADMIN);
+	}
+	
+	print USERS_EMAIL ".\n";
+	close (USERS_EMAIL);
+	$date = localtime();
+	print "Your account: $number has been created.  ";
+	print "Your password is $secret.  ";
+	print "Your accounts has $pennies cents on it.  ";
+	print "You will receive an email containing this ";
+	print "in the next few minutes.";
+}
+
+
+sub getcard() {	my ($cardno) = @_;
 	my $res;
 	$sth = $dbh->prepare("SELECT * FROM cards WHERE number=" . $dbh->quote($cardno));
 	$sth->execute;
@@ -257,6 +374,16 @@
 		} else {
 			$status = &generatecards($count, $pennies, $brand);
 		}
+	}elsif (param('action') eq "Generate_Custom...") {
+		my $count = 1;
+		my $pennies = param('custom_pennies');
+		my $brand = param('brand');
+		my $cardnumber = param('customnum');
+		if ($pennies < 1) {
+			$status = "Can't generate cards of fewer than one penny\n";
+		} else {
+			$status = &generatecards($count, $pennies, $brand, $cardnumber);
+		}		
 	} elsif (param('action') eq "Drop...") {
 		if ($dbh->do("DELETE FROM cards WHERE number = " . $dbh->quote(param('number')))) {
 			$status = "Dropped card " . param('number') . "'.";
@@ -289,6 +416,10 @@
 		textfield(-name => "count", -size => 8) . "&nbsp;" . $brands . "&nbsp;&nbsp;cards of&nbsp;&nbsp;" .
 		textfield(-name => "pennies", -size => 8) . "&nbsp;&nbsp;pennies&nbsp;&nbsp;" .
 		submit(-name => "action", -value => "Generate...") . "</td></tr>";
+	$body .= "<tr><td>Create Custom Numbered " . hidden(-name => "mode", -value => "Cards") .
+		textfield(-name => "customnum", -size => 20) . "&nbsp;" . $brands . "&nbsp;&nbsp;cards of&nbsp;&nbsp;" .
+		textfield(-name => "custom_pennies", -size => 8) . "&nbsp;&nbsp;pennies&nbsp;&nbsp;" .
+		submit(-name => "action", -value => "Generate_Custom...") . "</td></tr>";
 	$body .= "<tr><td>Add Money to Card&nbsp;&nbsp;" . hidden(-name => "mode", -value => "Cards") .
 		textfield(-name => "refillnum", -size => 20) . "&nbsp;&nbsp;In the Amount of &nbsp;&nbsp;" .
 		textfield(-name => "refillpennies", -size => 8) . "&nbsp;&nbsp;pennies&nbsp;&nbsp;" .
@@ -780,6 +911,7 @@
 		$config{email} = param('email');
 		$config{emailadd} = param('emailadd');
 		$config{mailprog} = param('mailprog');
+		$config{friendsdb} = param('friendsdb');
 		&save_config();
 		$activity = "Configuration saved...";
 		if ($action eq "Create Database") {
@@ -804,11 +936,367 @@
 	$body .= "<tr><td>Email New Card Info (YES/NO) </td><td>" . textfield(-name => 'email', -default => $config{email}) . "</td></tr>";
 	$body .= "<tr><td>Admin Email</td><td>" . textfield(-name => 'emailadd', -default => $config{emailadd}) . "</td></tr>";
 	$body .= "<tr><td>Email Program</td><td>" . textfield(-name => 'mailprog', -default => $config{mailprog}) . "</td></tr>";
+	$body .= "<tr><td>Enable Iax/Sip Friends DB (YES/NO) </td><td>" . textfield(-name => 'friendsdb', -default => $config{friendsdb}) . "</td></tr>";
+	$body .= "<tr><td align=left>&nbsp;" . submit(-name => 'action', -value => 'Save') . "</td><td align=right>" . submit( -name => 'action', -value => 'Create Database') . "&nbsp;</td></tr>";
+	$body .= "</table>";
+	return $body;
+}
+
+sub build_user_configure() {
+	my $body = start_form;
+	my $activity = "<br>";
+	my $action = param('action');
+	if (($action eq "Save") || ($action eq "Create Database") || ($action eq "Update Database")) {
+		$users_config{dbuser} = param('dbuser');
+		$users_config{dbpass} = param('dbpass');
+		$users_config{dbname} = param('dbname');
+		$users_config{dbhost} = param('dbhost');
+		$users_config{iax_context} = param('iax_context');		
+		$users_config{sip_context} = param('sip_context');
+		$users_config{iax_port} = param('iax_port');		
+		$users_config{sip_port} = param('sip_port');
+		$users_config{regseconds} = param('regseconds');			
+		$users_config{brand} = param('brand');
+		$users_config{emailadd} = param('emailadd');
+		$users_config{mailprog} = param('mailprog');
+		&users_save_config();
+		$activity = "Configuration saved...";
+		if ($action eq "Create Database") {
+			if (!&users_create_db()) {i
+				$activity = "Database created!";
+			} else {
+				$activity = "Database creation failed!";
+			}
+		} elsif ($action eq "Update Database") {
+			if (!&users_update_db()) {i
+				$activity = "Database Updated!";
+			} else {
+				$activity = "Database Update failed!";
+			}
+		}
+		&users_connect_db;
+	}
+	$body .= hidden(-name => 'mode', -default => 'Users_Configure');
+	$body .= "<table><tr><td align=left colspan=2><font color=#4444aa>Database Configuration</font></td></tr>";
+	$body .= "<tr><td colspan=2 align=center><i>$activity</i></td></tr>\n";
+	$body .= "<tr><td>Host</td><td>" . textfield(-name => 'dbhost', -default => $users_config{dbhost}) . "</td></tr>";
+	$body .= "<tr><td>Username</td><td>" . textfield(-name => 'dbuser', -default => $users_config{dbuser}) . "</td></tr>";
+	$body .= "<tr><td>Password</td><td>" . textfield(-name => 'dbpass', -default => $users_config{dbpass}) . "</td></tr>";
+	$body .= "<tr><td>Database</td><td>" . textfield(-name => 'dbname', -default => $users_config{dbname}) . "</td></tr>";
+	$body .= "<tr><td>Default SIP Context </td><td>" . textfield(-name => 'sip_context', -default => $users_config{sip_context}) . "</td></tr>";	
+	$body .= "<tr><td>Default IAX Context </td><td>" . textfield(-name => 'iax_context', -default => $users_config{iax_context}) . "</td></tr>";
+	$body .= "<tr><td>Default SIP Port </td><td>" . textfield(-name => 'sip_port', -default => $users_config{sip_port}) . "</td></tr>";	
+	$body .= "<tr><td>Default IAX Port </td><td>" . textfield(-name => 'iax_port', -default => $users_config{iax_port}) . "</td></tr>";
+	$body .= "<tr><td>Default Reg Seconds </td><td>" . textfield(-name => 'regseconds', -default => $users_config{regseconds}) . "</td></tr>";
+	$body .= "<tr><td>Default Brand </td><td>" . textfield(-name => 'brand', -default => $users_config{brand}) . "</td></tr>";
+	$body .= "<tr><td>Admin Email</td><td>" . textfield(-name => 'emailadd', -default => $users_config{emailadd}) . "</td></tr>";
+	$body .= "<tr><td>Email Program</td><td>" . textfield(-name => 'mailprog', -default => $users_config{mailprog}) . "</td></tr>";
 	$body .= "<tr><td align=left>&nbsp;" . submit(-name => 'action', -value => 'Save') . "</td><td align=right>" . submit( -name => 'action', -value => 'Create Database') . "&nbsp;</td></tr>";
+	$body .= "<tr><td align=left>&nbsp;" . submit(-name => 'action', -value => 'Update Database') . "&nbsp;</td></tr>";
 	$body .= "</table>";
 	return $body;
 }
 
+sub add_sip_user() {
+	my ($name, $secret) = @_;
+	my $username = $name;
+	my $context = $users_config{sip_context};
+	my $port = $users_config{sip_port};
+	my $regseconds = $users_config{regseconds};
+	my $brand = $users_config{brand};
+	my $ipaddr = "dynamic";
+	$tmp = "INSERT INTO sipfriends (name,username,secret,context,ipaddr,port,regseconds) VALUES (" .
+					$users_dbh->quote($name) . ", " .$users_dbh->quote($username) . ", " .
+					$users_dbh->quote($secret) . ", " .$users_dbh->quote($context) . ", " .
+					$users_dbh->quote($ipaddr) . ", " . $users_dbh->quote($port) . ", " .
+					$users_dbh->quote($regseconds).")";
+	$users_dbh->do($tmp) || print "$tmp failed";
+}
+
+sub add_iax_user() {
+	my ($name, $secret) = @_;
+	my $context = $users_config{iax_context};
+	my $port = $users_config{iax_port};
+	my $regseconds = $users_config{regseconds};
+	my $ipaddr = "dynamic";
+	$tmp = "INSERT INTO iaxfriends (name,secret,context,ipaddr,port,regseconds) VALUES (" .
+					$users_dbh->quote($name) . ", " .
+					$users_dbh->quote($secret) . ", " .$users_dbh->quote($context) . ", " .
+					$users_dbh->quote($ipaddr) . ", " . $users_dbh->quote($port) . ", " .
+					$users_dbh->quote($regseconds).")";
+	$users_dbh->do($tmp) || print "$tmp failed";
+}
+
+sub build_iax_friends() {
+	my $sth;
+	my $count;
+	my $color;
+	my $tmp;
+	my $editing;
+	my $creating;
+	my $status = "&nbsp;";
+	return "Cannot edit IAX users until database is configured" unless $users_dbh;
+	#
+	# Find what we're editing if anything
+	#
+	if (param("action") eq "Yes, drop it") {
+		if ($users_dbh->do("DELETE FROM iaxfriends WHERE name = " . $users_dbh->quote(param('dropitem')))) {
+			$status = "Dropped user '" . param('dropitem') . "'.";
+		} else {
+			$status = "Unable to drop user '" . param('dropitem') . "'.";
+		}
+	}
+	for ($x=1;length(param("item$x"));$x++) {
+		if (param("action$x") eq "Edit...") {
+			$editing = param("item$x");
+		} elsif (param("action$x") eq "Add...") {
+			$editing = param("item$x");
+			$creating = "yes";
+			$status = "Creating new entry $x";
+		} elsif (param("action$x") eq "Save...") {
+			if ($users_dbh->do("UPDATE iaxfriends SET name=" . $users_dbh->quote(param("newname$x")) .
+				" WHERE name=" . $users_dbh->quote(param("item$x")))) {
+				$tmp = "REPLACE INTO iaxfriends (name,secret,context,ipaddr,port,regseconds) VALUES (" . $users_dbh->quote(param("newname$x")) . 
+					", " . $users_dbh->quote(param("newsecret$x")) .
+					", " . $users_dbh->quote(param("newcontext$x")) . 
+					", " . $users_dbh->quote(param("newipaddr$x")) . 
+					", " . $users_dbh->quote(param("newport$x")) . 
+					", " . $users_dbh->quote(param("newregseconds$x")) . ")";
+				if ($users_dbh->do($tmp)) {
+					$status = "User '" . param("newname$x") . "' has been updated";
+				} else {
+					$status = "User '" . param("newname$x") . "' FAILED to update ($tmp)!";
+				}
+			} else {
+				$status = "Name is already in use!";
+			}
+		} elsif (param("action$x") eq "Create...") {
+				$tmp = "INSERT INTO iaxfriends (name,secret,context,ipaddr,port,regseconds) VALUES (" .
+					$users_dbh->quote(param("newname$x")) . ", " . $users_dbh->quote(param("newsecret$x")) .
+					", " . $users_dbh->quote(param("newcontext$x")) .
+					", " . $users_dbh->quote(param("newipaddr$x")) . ", " . $users_dbh->quote(param("newport$x")) . 
+					", " . $users_dbh->quote(param("newregseconds$x")) . ")";
+				if ($users_dbh->do($tmp)) {
+					$status = "User '" . param("newname$x") . "' has been created";
+				} else {
+					$status = "User '" . param("newname$x") . "' FAILED to create ($tmp)!";
+				}
+		} elsif (param("action$x") eq "Drop...") {
+			$status = "Are you sure you want to delete the user '" .
+				param("item$x") . "'?<br>" . hidden(-name => "dropitem", -value => param("item$x")) .
+				submit(-name => "action", -value => "Yes, drop it") . "&nbsp;&nbsp;&nbsp;" .
+				submit(-name => "action", -value => "Cancel");
+			$editing = "dropping something";
+			
+		}
+	}
+	$sth = $users_dbh->prepare('SELECT * FROM iaxfriends');
+	$sth->execute || return "Something is wrong with the iaxfriends database\n";
+	$body = "<table>" .
+		"<tr bgcolor=ffffff><tdcolspan=7>" . start_form . "<i>$status</i></td></tr>\n" .
+		"<tr bgcolor=ccccff><td>" . hidden(-name => 'mode', -value => 'iaxfriends') . "User Name</td><td>Secret</td><td>Context</td><td>IP Address</td><td>Port</td><td>Reg Seconds</td></tr>\n";
+	while($row = $sth->fetchrow_hashref) {
+		$count++;
+		if (!($count % 2)) {
+			$color = "#ccffcc";
+		} else {
+			$color = "#ffffcc";
+		}
+		Delete("newname$count");
+		Delete("item$count");
+		if ($editing eq $row->{name}) {
+			$body .= "<tr bgcolor=$color><td>" . hidden(-name => "item$count", -value => $row->{name}) .
+				 textfield(-name => "newname$count", -size=> 10, -default => $row->{name}) . "</td><td>" .
+		         	 textfield(-name => "newsecret$count", -size=> 10, -default=>$row->{secret}) . 
+				 "</td><td>" . 
+				 textfield(-name => "newcontext$count", -size => 15, -default => $row->{context}) . "</td><td>" .
+				 textfield(-name => "newipaddr$count", -size => 10, -default => $row->{ipaddr}) . 
+				 "</td><td>" . 
+				 textfield(-name => "newport$count", -size => 10, -default => $row->{port}) . "</td><td>" .
+				 textfield(-name => "newregseconds$count", -size => 5, -default => $row->{regseconds}) . "</td>";
+				 $body .= "<td bgcolor=white>" . submit(-name => "action$count", -value => 'Save...') .
+				 submit(-name => "action$count", -value => 'Cancel...'); 
+				$body .= "</td></tr>";
+		} else {
+			$body .= "<tr bgcolor=$color><td>" . hidden(-name => "item$count", -value => $row->{name}) .
+				 "$row->{name}</td>" .
+		         "<td>$row->{secret}</td><td>$row->{context}</td>" .
+				 "<td>$row->{ipaddr}</td><td>$row->{port}</td><td>$row->{regseconds}</td>" .
+				 "<td bgcolor=white>";
+			if (!$editing) {
+				$body .= submit(-name => "action$count", -value => 'Edit...') .
+				 submit(-name => "action$count", -value => 'Drop...');
+			} else {
+				$body .= "&nbsp;";
+			}
+			$body .= "</td></tr>\n";
+		}
+	}
+	$sth->finish;
+	$count++;
+	if ($creating) {
+			$body .= "<tr bgcolor=$color><td>" . hidden(-name => "item$count", -value => $row->{name}) .
+				 textfield(-name => "newname$count", -size=> 10) . "</td><td>" .
+		         	 textfield(-name => "newsecret$count", -size => 10) . "</td><td>" . 
+				 textfield(-name => "newcontext$count", -size => 15) . "</td><td>" .
+				 textfield(-name => "newipaddr$count", -size => 10) . "</td><td>" . 
+				 textfield(-name => "newport$count", -size => 10) . "</td><td>" .
+				 textfield(-name => "newregseconds$count", -size => 5) . "</td>";
+				 $body .= "<td bgcolor=white>" . submit(-name => "action$count", -value => 'Create...') .
+				 submit(-name => "action$count", -value => 'Cancel...');
+				$body .= "</td></tr>";
+	}
+	if (!$editing) {
+		$body .=
+			"<tr bgcolor=ffffff><td colspan=7><hr></td></tr>\n";
+		$body .=
+			"<tr bgcolor=ffffff><td colspan=6>&nbsp;" . hidden(-name => "item$count", -value => "new") . 
+			"</td><td align=right>" .
+			submit(-name => "action$count", -value => "Add...") . "</td></tr>\n";
+	}
+	$body .= "</table>\n";
+	return $body;
+}
+
+sub build_sip_friends() {
+	my $sth;
+	my $count;
+	my $color;
+	my $tmp;
+	my $editing;
+	my $creating;
+	my $status = "&nbsp;";
+	return "Cannot edit SIP users until database is configured" unless $users_dbh;
+	#
+	# Find what we're editing if anything
+	#
+	if (param("action") eq "Yes, drop it") {
+		if ($users_dbh->do("DELETE FROM sipfriends WHERE name = " . $users_dbh->quote(param('dropitem')))) {
+			$status = "Dropped user '" . param('dropitem') . "'.";
+		} else {
+			$status = "Unable to drop user '" . param('dropitem') . "'.";
+		}
+	}
+	for ($x=1;length(param("item$x"));$x++) {
+		if (param("action$x") eq "Edit...") {
+			$editing = param("item$x");
+		} elsif (param("action$x") eq "Add...") {
+			$editing = param("item$x");
+			$creating = "yes";
+			$status = "Creating new entry $x";
+		} elsif (param("action$x") eq "Save...") {
+			if ($users_dbh->do("UPDATE sipfriends SET name=" . $users_dbh->quote(param("newname$x")) .
+				" WHERE name=" . $users_dbh->quote(param("item$x")))) {
+				$tmp = "REPLACE INTO sipfriends (name,username,secret,context,ipaddr,port,regseconds) VALUES (" . $users_dbh->quote(param("newname$x")) . 
+					", " . $users_dbh->quote(param("newusername$x")) .
+					", " . $users_dbh->quote(param("newsecret$x")) .
+					", " . $users_dbh->quote(param("newcontext$x")) . 
+					", " . $users_dbh->quote(param("newipaddr$x")) . 
+					", " . $users_dbh->quote(param("newport$x")) . 
+					", " . $users_dbh->quote(param("newregseconds$x")) . ")";
+				if ($users_dbh->do($tmp)) {
+					$status = "User '" . param("newname$x") . "' has been updated";
+				} else {
+					$status = "User '" . param("newname$x") . "' FAILED to update ($tmp)!";
+				}
+			} else {
+				$status = "Name is already in use!";
+			}
+		} elsif (param("action$x") eq "Create...") {
+				$tmp = "INSERT INTO sipfriends (name,username,secret,context,ipaddr,port,regseconds) VALUES (" .
+					$users_dbh->quote(param("newname$x")) . 
+					", " . $users_dbh->quote(param("newusername$x")) .
+					", " . $users_dbh->quote(param("newsecret$x")) .
+					", " . $users_dbh->quote(param("newcontext$x")) .
+					", " . $users_dbh->quote(param("newipaddr$x")) . 
+					", " . $users_dbh->quote(param("newport$x")) . 
+					", " . $users_dbh->quote(param("newregseconds$x")) . ")";
+				if ($users_dbh->do($tmp)) {
+					$status = "User '" . param("newname$x") . "' has been created";
+				} else {
+					$status = "User '" . param("newname$x") . "' FAILED to create ($tmp)!";
+				}
+		} elsif (param("action$x") eq "Drop...") {
+			$status = "Are you sure you want to delete the user '" .
+				param("item$x") . "'?<br>" . hidden(-name => "dropitem", -value => param("item$x")) .
+				submit(-name => "action", -value => "Yes, drop it") . "&nbsp;&nbsp;&nbsp;" .
+				submit(-name => "action", -value => "Cancel");
+			$editing = "dropping something";
+			
+		}
+	}
+	$sth = $users_dbh->prepare('SELECT * FROM sipfriends');
+	$sth->execute || return "Something is wrong with the sipfriends database\n";
+	$body = "<table>" .
+		"<tr bgcolor=ffffff><tdcolspan=7>" . start_form . "<i>$status</i></td></tr>\n" .
+		"<tr bgcolor=ccccff><td>" . hidden(-name => 'mode', -value => 'sipfriends') . "Name</td>
+		<td>User Name</td><td>Secret</td><td>Context</td><td>IP Address</td><td>Port</td><td>Reg Seconds</td></tr>\n";
+	while($row = $sth->fetchrow_hashref) {
+		$count++;
+		if (!($count % 2)) {
+			$color = "#ccffcc";
+		} else {
+			$color = "#ffffcc";
+		}
+		Delete("newname$count");
+		Delete("item$count");
+		if ($editing eq $row->{name}) {
+			$body .= "<tr bgcolor=$color><td>" . hidden(-name => "item$count", -value => $row->{name}) .
+				 textfield(-name => "newname$count", -size=> 10, -default => $row->{name}) . "</td><td>" .
+				 textfield(-name => "newusername$count", -size=> 10, -default => $row->{username}) . "</td><td>" .
+		         	 textfield(-name => "newsecret$count", -size=> 10, -default=>$row->{secret}) . 
+				 "</td><td>" . 
+				 textfield(-name => "newcontext$count", -size => 15, -default => $row->{context}) . "</td><td>" .
+				 textfield(-name => "newipaddr$count", -size => 10, -default => $row->{ipaddr}) . 
+				 "</td><td>" . 
+				 textfield(-name => "newport$count", -size => 10, -default => $row->{port}) . "</td><td>" .
+				 textfield(-name => "newregseconds$count", -size => 5, -default => $row->{regseconds}) . "</td>";
+				 $body .= "<td bgcolor=white>" . submit(-name => "action$count", -value => 'Save...') .
+				 submit(-name => "action$count", -value => 'Cancel...'); 
+				$body .= "</td></tr>";
+		} else {
+			$body .= "<tr bgcolor=$color><td>" . hidden(-name => "item$count", -value => $row->{name}) .
+				 "$row->{name}</td>" .
+		        	 "<td>$row->{username}</td><td>$row->{secret}</td><td>$row->{context}</td>" .
+				 "<td>$row->{ipaddr}</td><td>$row->{port}</td><td>$row->{regseconds}</td>" .
+				 "<td bgcolor=white>";
+			if (!$editing) {
+				$body .= submit(-name => "action$count", -value => 'Edit...') .
+				 submit(-name => "action$count", -value => 'Drop...');
+			} else {
+				$body .= "&nbsp;";
+			}
+			$body .= "</td></tr>\n";
+		}
+	}
+	$sth->finish;
+	$count++;
+	if ($creating) {
+			$body .= "<tr bgcolor=$color><td>" . hidden(-name => "item$count", -value => $row->{name}) .
+				 textfield(-name => "newname$count", -size=> 10) . "</td><td>" .
+				 textfield(-name => "newusername$count", -size=> 10) . "</td><td>" .
+		         	 textfield(-name => "newsecret$count", -size => 10) . "</td><td>" . 
+				 textfield(-name => "newcontext$count", -size => 15) . "</td><td>" .
+				 textfield(-name => "newipaddr$count", -size => 10) . "</td><td>" . 
+				 textfield(-name => "newport$count", -size => 10) . "</td><td>" .
+				 textfield(-name => "newregseconds$count", -size => 5) . "</td>";
+				 $body .= "<td bgcolor=white>" . submit(-name => "action$count", -value => 'Create...') .
+				 submit(-name => "action$count", -value => 'Cancel...');
+				$body .= "</td></tr>";
+	}
+	if (!$editing) {
+		$body .=
+			"<tr bgcolor=ffffff><td colspan=7><hr></td></tr>\n";
+		$body .=
+			"<tr bgcolor=ffffff><td colspan=6>&nbsp;" . hidden(-name => "item$count", -value => "new") . 
+			"</td><td align=right>" .
+			submit(-name => "action$count", -value => "Add...") . "</td></tr>\n";
+	}
+	$body .= "</table>\n";
+	return $body;
+}
+
+
 sub build_body() {
 	my ($mode) = @_;
 	my $body;
@@ -818,25 +1306,48 @@
 	return &build_brands() if ($mode eq "Brands");
 	return &build_trunks() if ($mode eq "Trunks");
 	return &build_routes() if ($mode eq "Routes");
+	if ($config{'friendsdb'} eq "YES") {	
+		return &build_user_configure() if ($mode eq "Users_Configure");
+		return &build_iax_friends() if ($mode eq "IAX_Friends");	
+		return &build_sip_friends() if ($mode eq "SIP_Friends");
+	} elsif ($config{'friendsdb'} ne "YES") {
+		return "<h2>Not Configured!</h2>\n" if ($mode eq "Users_Configure");
+		return "<h2>Not Configured!</h2>\n" if ($mode eq "IAX_Friends");	
+		return "<h2>Not Configured!</h2>\n" if ($mode eq "SIP_Friends");
+	}		
 	return "<h2>Not yet implemented!</h2>\n";
 }
 
 my $body, $menu;
-my $mode = param('mode');
-$mode = "Home" unless grep(/^$mode$/, @modes);
+my $mode = param("mode");
+my $pn = param("pn");
+my $em = param("em");
+my $md = param("md");
+my $iax = param("iax");
+my $sip = param("sip");
 
 &load_config;
 &connect_db;
 
+if ($config{'friendsdb'} eq "YES") {
+	&users_load_config;
+	&users_connect_db;
+}
+
 $msg = "&nbsp;";
-$body = &build_body($mode);
-$menu = &build_menu($mode);
-$msg = "<i>Database unavailable -- please check configuration</i>" unless $dbh;
+if ($md eq "Auto") {
+	&users_generatecards($pn, $em, $iax, $sip);
+} else {
+	$mode = "Home" unless grep(/^$mode$/, @modes);
+	$body = &build_body($mode);
+	$menu = &build_menu($mode);
+	$msg = "<i>Database unavailable -- please check configuration</i>" unless $dbh;
 
-print "<title>Asterisk&trade; Calling Card manager: $mode</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 Admin: <b>$mode</b></font>" .
+	print "<title>Asterisk&trade; Calling Card manager: $mode</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 Admin: <b>$mode</b></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";
+	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";
+}	

Index: astcc.agi
===================================================================
RCS file: /usr/cvsroot/astcc/astcc.agi,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- astcc.agi	19 Sep 2004 15:41:31 -0000	1.10
+++ astcc.agi	2 Oct 2004 02:48:25 -0000	1.11
@@ -29,6 +29,19 @@
 # exten => 1234,2,DeadAGI(astcc.agi)
 # exten => 1234,3,Hangup
 #
+# ; If you call it with an extension of "BALANCE" and a calleridnumber, 
+# ; it will read your balance to you and then exit.
+#
+# exten => _00XXXXXXXXX,1,DeadAGI(astcc.agi,${CALLERIDNUM},BALANCE,1)
+# exten => _00XXXXXXXXX,2,Hangup
+# 
+# I have added a few different quiet to this program.  They can
+# be specified from the dial command. 
+# 
+# 1 - All warnings and messages play.
+# 2 - All warnings and card balance
+# 3 - All warnings
+# 4 - Interrogation Only
 
 use DBI;
 use Asterisk::AGI;
@@ -73,10 +86,10 @@
 }
 
 sub savecdr() {
-	my ($cardnum, $callerid, $callednum, $trunk, $disposition, $billseconds, $billcost) = @_;
-	$dbh->do("INSERT INTO cdrs (cardnum,callerid,callednum,trunk,disposition,billseconds,billcost) VALUES (" .
+	my ($cardnum, $callerid, $callednum, $trunk, $disposition, $billseconds, $billcost,$callstart) = @_;
+	$dbh->do("INSERT INTO cdrs (cardnum,callerid,callednum,trunk,disposition,billseconds,billcost,callstart) VALUES (" .
 		$dbh->quote($cardnum) . ", " . $dbh->quote($callerid) . ", " . $dbh->quote($callednum) . ", " . $dbh->quote($trunk) . ", " .
-		$dbh->quote($disposition) . ", " . $dbh->quote($billseconds) . ", " . $dbh->quote($billcost) . ")");
+		$dbh->quote($disposition) . ", " . $dbh->quote($billseconds) . ", " . $dbh->quote($billcost) . ", " . $dbh->quote($callstart) . ")");
 }
 
 # Setup some variables
@@ -124,34 +137,48 @@
 	$leftcents = $left % 100;
 	print STDERR "\nCard has face value $carddata->{facevalue} and has used $carddata->{used}\n\n";
 	print STDERR "\n$leftdollars dollars and $leftcents cents remain\n";
-	$res = &mystreamfile("astcc-youhave");
+	if ($quiet < 3 ) {
+		$res = &mystreamfile("astcc-youhave");
+	}
 	return $res if ($res);
 	if (!$leftdollars && !$leftcents) {
-		$res = &mystreamfile("astcc-nothing");
+		if ($quiet < 3 ) {
+			$res = &mystreamfile("astcc-nothing");
+		}
 		return $res if ($res);
 	} else {
 		if ($leftdollars > 0) {
-			$res = &mysaynumber($leftdollars);
+			if ($quiet < 3 ) {
+				$res = &mysaynumber($leftdollars);
+			}
 			return $res if ($res);
-			if ($leftdollars > 1) {
-				$res = &mystreamfile("astcc-dollars");
-			} else {
-				$res = &mystreamfile("astcc-dollar");
+			if ($quiet < 3 ) {
+				if ($leftdollars > 1) {
+					$res = &mystreamfile("astcc-dollars");
+				} else {
+					$res = &mystreamfile("astcc-dollar");
+				}
 			}
 			return $res if ($res);
+			if ($quiet < 3 ) {
+				if ($leftcents > 0) {
+					$res = &mystreamfile("astcc-and");
+					return $res if ($res);
+				}
+			}
+		}
+		if ($quiet < 3 ) {
 			if ($leftcents > 0) {
-				$res = &mystreamfile("astcc-and");
+				$res = &mysaynumber($leftcents);
+				return $res if ($res);
+				$res = &mystreamfile("astcc-cents");
 				return $res if ($res);
 			}
 		}
-		if ($leftcents > 0) {
-			$res = &mysaynumber($leftcents);
-			return $res if ($res);
-			$res = &mystreamfile("astcc-cents");
-			return $res if ($res);
-		}
 	}
-	$res = &mystreamfile("astcc-remaining");
+	if ($quiet < 3 ) {
+		$res = &mystreamfile("astcc-remaining");
+	}
 	return $res;
 }
 
@@ -178,24 +205,34 @@
 	$adjconn = ($numdata->{connectcost} * (10000 + $carddata->{markup})) / 10000;
 #	print STDERR "Adjusted cost is $adjcost with $adjconn fee\n";
 	print STDERR "This call will cost $adjcost cents per minute + $adjconn connect fee\n";
-	$res = &mystreamfile("astcc-willcost");
+	if ($quiet < 2 ) {
+		$res = &mystreamfile("astcc-willcost");
+	}
 	return $res if ($res);
 	if (($adjconn < 1) && ($adjcost < 1)) {
-		$res = &mystreamfile("astcc-nothing");
-		return $res;
+		if ($quiet <= 1 ) {
+			$res = &mystreamfile("astcc-nothing");
+			return $res;
+		}
+	}
+	if ($quiet <= 1 ) {
+		$res = &mysayfloat($adjcost / 100);
 	}
-	$res = &mysayfloat($adjcost / 100);
 	return $res if ($res);
-	$res = &mystreamfile("astcc-perminute");
+	if ($quiet <= 1 ) {
+		$res = &mystreamfile("astcc-perminute");
+	}
 	if ($adjconn > 0) {
-		return $res if ($res);
-		$res = &mystreamfile("astcc-connectcharge");
-		return $res if ($res);
-		$res = &mysayfloat($adjconn / 100);
-		return $res if ($res);
-		$res = &mystreamfile("astcc-cents");
-		return $res if ($res);
-		$res = &mystreamfile("astcc-forfirst");
+		if ($quiet <= 1 ) {
+			return $res if ($res);
+			$res = &mystreamfile("astcc-connectcharge");
+			return $res if ($res);
+			$res = &mysayfloat($adjconn / 100);
+			return $res if ($res);
+			$res = &mystreamfile("astcc-cents");
+			return $res if ($res);
+			$res = &mystreamfile("astcc-forfirst");
+		}	
 		return $res if ($res);
 		$incsecs = $numdata->{includedseconds} % 60;
 		$incmins = int($numdata->{includedseconds} / 60);
@@ -203,23 +240,31 @@
 			if ($incmins > 1) {
 				$res = &mysaynumber($incmins);
 				return $res if ($res);
-				$res = &mystreamfile("astcc-minutes");
+				if ($quiet <= 1 ) {
+					$res = &mystreamfile("astcc-minutes");
+				}	
 			} else {
-				$res = &mystreamfile("astcc-minute");
+				if ($quiet <= 1 ) {
+					$res = &mystreamfile("astcc-minute");
+				}
 			}
 			if ($incsecs > 0) {
 				return $res if ($res);
-				$res = &mystreamfile("astcc-and");
+				if ($quiet <= 1 ) {
+					$res = &mystreamfile("astcc-and");
+				}	
 			}
 			return $res if ($res);
 		}
-		if ($incsecs > 0) {
-			$res = &mysaynumber($incsecs);
-			return $res if ($res);
-			$res = &mystreamfile("astcc-seconds");
-			return $res if ($res);
+		if ($quiet <= 1 ) {
+			if ($incsecs > 0) {
+				$res = &mysaynumber($incsecs);
+				return $res if ($res);
+				$res = &mystreamfile("astcc-seconds");
+				return $res if ($res);
+			}
+			$res = &mystreamfile("astcc-willapply");
 		}
-		$res = &mystreamfile("astcc-willapply");
 	}
 	return $res;
 }
@@ -248,6 +293,7 @@
 		$res = $AGI->exec("DIAL $dialstr");
 		$answeredtime = $AGI->get_variable("ANSWEREDTIME");
 		$dialstatus = $AGI->get_variable("DIALSTATUS");
+		$callstart = localtime();
 		return $dialstatus;
 	}
 	
@@ -256,6 +302,7 @@
 		$res = $AGI->exec("DIAL $dialstr");
 		$answeredtime = $AGI->get_variable("ANSWEREDTIME");
 		$dialstatus = $AGI->get_variable("DIALSTATUS");
+		$callstart = localtime();		
 		return $dialstatus;
 	}
 	
@@ -264,6 +311,7 @@
 		$res = $AGI->exec("DIAL $dialstr");
                 $answeredtime = $AGI->get_variable("ANSWEREDTIME");
                 $dialstatus = $AGI->get_variable("DIALSTATUS");
+		$callstart = localtime();		
                 return $dialstatus;
 	}
 
@@ -272,6 +320,7 @@
 		$res = $AGI->exec("DIAL $dialstr");
 		$answeredtime = $AGI->get_variable("ANSWEREDTIME");
 		$dialstatus = $AGI->get_variable("DIALSTATUS");
+		$callstart = localtime();		
 		return $dialstatus;
 	}
 
@@ -295,12 +344,14 @@
 	my ($cardno) = @_;
 	my $carddata = &getcard($cardno);
 	if ($carddata->{inuse}) {
-		$AGI->stream_file("your");
-		$AGI->stream_file("card-number");
-		$AGI->stream_file("is-in-use");
-		$AGI->stream_file("please-try-again");
-		$AGI->stream_file("later");
-		$AGI->stream_file("vm-goodbye");
+		if ($quiet < 5 ) {
+			$AGI->stream_file("your");
+			$AGI->stream_file("card-number");
+			$AGI->stream_file("is-in-use");
+			$AGI->stream_file("please-try-again");
+			$AGI->stream_file("later");
+			$AGI->stream_file("vm-goodbye");
+		}	
 		exit(0);
 	}
 return;
@@ -317,7 +368,7 @@
 #
 # Answer the line right away
 #
-my ($calleridnum, $phoneno) = @ARGV;
+($calleridnum, $phoneno, $quiet) = @ARGV;
 $AGI->answer();
 #
 # Play a nice tone
@@ -325,13 +376,20 @@
 &load_config();
 &connect_db();
 if (!$dbh) {
-	$AGI->stream_file("astcc-down");
+	if ($quiet <= 4 ) {
+		$AGI->stream_file("astcc-down");
+	}	
 	exit(0);
 }
 my $res;
 &msleep(500);
-$res = &mystreamfile("astcc-tone");
+if ($quiet <= 4 ) {
+	$res = &mystreamfile("astcc-tone");
+} else { 
+	$res = "silent";
+}	
 print STDERR "Res is $res\n";
+print STDERR "Silent Level is $quiet\n";
 exit(0) if $res < 0;
 my $cardno;
 my $callerid = $input{callerid};
@@ -350,10 +408,14 @@
 		exit(0) if $cardno < 0;
 		$carddata = &getcard($cardno);
 		if (!$carddata->{number}) {
-			$res = &mystreamfile("astcc-badaccount");
+			if ($quiet < 5 ) {
+				$res = &mystreamfile("astcc-badaccount");
+			} else { $res = "silent"; }	
 			exit(0) if $res < 0;
 			if ($tries > 2) {
-				$AGI->stream_file("vm-goodbye");
+				if ($quiet < 2 ) {
+					$AGI->stream_file("vm-goodbye");
+				}	
 				exit(0);
 			}
 		}
@@ -367,8 +429,10 @@
 	exit(0) if $cardno < 0;
 	$carddata = &getcard($cardno);
 	if (!$carddata->{number}) {
-		$res = &mystreamfile("astcc-badaccount");
-		$AGI->stream_file("vm-goodbye");
+		if ($quiet < 5 ) {
+			$res = &mystreamfile("astcc-badaccount");
+			$AGI->stream_file("vm-goodbye");
+		}	
 		exit(0);
 	}
 }
@@ -382,7 +446,9 @@
 $res = &tell_time($carddata);
 
 if ($credit < 1) {
-	$AGI->stream_file("vm-goodbye");
+	if ($quiet < 5 ) {
+		$AGI->stream_file("vm-goodbye");
+	}	
 	&setinuse($carddata->{number}, 0);
 	exit(0);
 }
@@ -416,19 +482,27 @@
 		}
 		$numdata = &getphone($phoneno);
 		if (!$numdata->{pattern}) {
-			$res = &mystreamfile("astcc-badphone");
+			if ($quiet < 5 ) {
+				$res = &mystreamfile("astcc-badphone");
+			}
 			if ($res < 0) {
 				&setinuse($carddata->{number}, 0);
 				exit(0);
 			}
 			if ($tries > 2) {
-				$AGI->stream_file("vm-goodbye");
+				if ($quiet < 5 ) {
+					$AGI->stream_file("vm-goodbye");
+				}	
 				&setinuse($carddata->{number}, 0);
 				exit(0);
 			}
 		}
 	}
 }
+elsif ($phoneno eq "BALANCE") {
+		&setinuse($carddata->{number}, 0);
+		exit(0);
+}		
 else {
 	if ($phoneno < 0) {
 		&setinuse($carddata->{number}, 0);
@@ -436,8 +510,10 @@
 	}
 	$numdata = &getphone($phoneno);
 	if (!$numdata->{pattern}) {
-		$res = &mystreamfile("astcc-badphone");
-		$AGI->stream_file("vm-goodbye");
+		if ($quiet < 5 ) {
+			$res = &mystreamfile("astcc-badphone");
+			$AGI->stream_file("vm-goodbye");
+		}	
 		&setinuse($carddata->{number}, 0);
 		exit(0);
 	}
@@ -450,8 +526,10 @@
 print STDERR "Credit $credit, conn $adjconn, cost $adjcost\n";
 
 if (($adjconn > $credit) || (($adjconn < 1) && ($adjcost > $credit))){
-	$res = &mystreamfile("astcc-notenough");
-	$AGI->stream_file("vm-goodbye") if (!$res);
+	if ($quiet < 5 ) {
+		$res = &mystreamfile("astcc-notenough");
+		$AGI->stream_file("vm-goodbye") if (!$res);
+	}
 	&setinuse($carddata->{number}, 0);
 	exit(0);
 }
@@ -459,13 +537,16 @@
 
 $maxmins = int(($credit - $adjconn) / $adjcost);
 if ($maxmins <= 0.1) {
-	$res = &mystreamfile("astcc-notenough");
-	$AGI->stream_file("vm-goodbye") if (!$res);
+	if ($quiet < 5 ) {
+		$res = &mystreamfile("astcc-notenough");
+		$AGI->stream_file("vm-goodbye") if (!$res);
+	}	
 	&setinuse($carddata->{number}, 0);
 	exit(0);
 }
-
-$res = &mystreamfile("astcc-pleasewait");
+if ($quiet < 5 ) {
+	$res = &mystreamfile("astcc-pleasewait");
+}	
 
 if ($res < 0) {
 	&setinuse($carddata->{number}, 0);
@@ -490,14 +571,14 @@
 			my $cost = &calccost($adjconn, $adjcost, $answeredtime, $carddata->{inc});
 			$carddata->{used} += $cost;
 			print STDERR "Total used is now $carddata->{used}\n";
-			&savecdr($cardno, $callerid, $phoneno, $trunk, $res, $answeredtime, $cost);
+			&savecdr($cardno, $callerid, $phoneno, $trunk, $res, $answeredtime, $cost,$callstart);
 			&savedata($carddata);
 		}
 		&setinuse($carddata->{number}, 0);
 		exit(0);
 	}
 }
-$res = &mystreamfile("astcc-unavail");
+#$res = &mystreamfile("astcc-unavail");
 &savecdr($cardno, $callerid, $phoneno, $trunk, $res, 0, 0);
 &setinuse($carddata->{number}, 0);
 exit(0);




More information about the svn-commits mailing list