? astcc/diff
? asterisk/doc/api
? zaptel/.tmp_versions
Index: astcc/Makefile
===================================================================
RCS file: /usr/cvsroot/astcc/Makefile,v
retrieving revision 1.4
diff -u -r1.4 Makefile
--- astcc/Makefile 15 Jul 2004 00:15:54 -0000 1.4
+++ astcc/Makefile 1 Oct 2004 04:42:21 -0000
@@ -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/astcc-admin.cgi
===================================================================
RCS file: /usr/cvsroot/astcc/astcc-admin.cgi,v
retrieving revision 1.8
diff -u -r1.8 astcc-admin.cgi
--- astcc/astcc-admin.cgi 18 Sep 2004 13:59:16 -0000 1.8
+++ astcc/astcc-admin.cgi 1 Oct 2004 04:42:29 -0000
@@ -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@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.";
-@modes = ( "Home", "Brands", "Cards", "Trunks", "Routes", "Configure" );
+@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, ") {
+ 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') . "'.";
@@ -267,12 +394,22 @@
$cardinfo = &getcard(param('refillnum'));
$number = $cardinfo->{number};
$newfacevalue = $cardinfo->{facevalue} + (param('refillpennies') * 100);
- if ($dbh->do("UPDATE cards SET facevalue= $newfacevalue WHERE number= $cardinfo->{number}")) {
+ if ($dbh->do("UPDATE cards SET facevalue= " . $dbh->quote($newfacevalue) . "WHERE number=" . $dbh->quote($cardinfo->{number}))) {
$status = "Refilled card " . param('refillnum') . "'.";
} else {
$status = "Unable to Refill card". param('refillnum') . "'.";
}
- }
+ } elsif (param('action') eq "Reset...") {
+# $cardinfo = &getcard(param('refillnum'));
+ $number = param('resetnum');
+# $newfacevalue = $cardinfo->{facevalue} + (param('refillpennies') * 100);
+ $newstatus = 0;
+ if ($dbh->do("UPDATE cards SET inuse= " . $dbh->quote($newstatus) . "WHERE number= " . $dbh->quote($number) )) {
+ $status = "Reset card " . param('resetnum') . "'.";
+ } else {
+ $status = "Unable to Reset card ". param('resetnum') . "'.";
+ }
+ }
$total = &count_cards();
$used = &count_cards("WHERE firstuse > 0");
$status = "$status
" . "$total cards outstanding, $used of which have been used";
@@ -281,6 +418,10 @@
textfield(-name => "count", -size => 8) . " " . $brands . " cards of " .
textfield(-name => "pennies", -size => 8) . " pennies " .
submit(-name => "action", -value => "Generate...") . "";
+ $body .= "
| Create Custom Numbered " . hidden(-name => "mode", -value => "Cards") .
+ textfield(-name => "customnum", -size => 20) . " " . $brands . " cards of " .
+ textfield(-name => "custom_pennies", -size => 8) . " pennies " .
+ submit(-name => "action", -value => "Generate_Custom...") . " |
";
$body .= "| Add Money to Card " . hidden(-name => "mode", -value => "Cards") .
textfield(-name => "refillnum", -size => 20) . " In the Amount of " .
textfield(-name => "refillpennies", -size => 8) . " pennies " .
@@ -291,6 +432,9 @@
$body .= " |
| Delete card " . hidden(-name => "mode", -value => "Cards") .
textfield(-name => "number", -size => 20) . " " .
submit(-name => "action", -value => "Drop...") . " |
";
+ $body .= "| Reset in use info on card " . hidden(-name => "mode", -value => "Cards") .
+ textfield(-name => "resetnum", -size => 20) . " " .
+ submit(-name => "action", -value => "Reset...") . " |
";
$body .= "| List Cards " . hidden(-name => "mode", -value => "Cards") .
submit(-name => "action", -value => "List_Cards...") . " |
";
$body .= "";
@@ -769,6 +913,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") {
@@ -793,11 +938,367 @@
$body .= "| Email New Card Info (YES/NO) | " . textfield(-name => 'email', -default => $config{email}) . " |
";
$body .= "| Admin Email | " . textfield(-name => 'emailadd', -default => $config{emailadd}) . " |
";
$body .= "| Email Program | " . textfield(-name => 'mailprog', -default => $config{mailprog}) . " |
";
+ $body .= "| Enable Iax/Sip Friends DB (YES/NO) | " . textfield(-name => 'friendsdb', -default => $config{friendsdb}) . " |
";
$body .= "| " . submit(-name => 'action', -value => 'Save') . " | " . submit( -name => 'action', -value => 'Create Database') . " |
";
$body .= "";
return $body;
}
+sub build_user_configure() {
+ my $body = start_form;
+ my $activity = "
";
+ 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 .= "| Database Configuration |
";
+ $body .= "| $activity |
\n";
+ $body .= "| Host | " . textfield(-name => 'dbhost', -default => $users_config{dbhost}) . " |
";
+ $body .= "| Username | " . textfield(-name => 'dbuser', -default => $users_config{dbuser}) . " |
";
+ $body .= "| Password | " . textfield(-name => 'dbpass', -default => $users_config{dbpass}) . " |
";
+ $body .= "| Database | " . textfield(-name => 'dbname', -default => $users_config{dbname}) . " |
";
+ $body .= "| Default SIP Context | " . textfield(-name => 'sip_context', -default => $users_config{sip_context}) . " |
";
+ $body .= "| Default IAX Context | " . textfield(-name => 'iax_context', -default => $users_config{iax_context}) . " |
";
+ $body .= "| Default SIP Port | " . textfield(-name => 'sip_port', -default => $users_config{sip_port}) . " |
";
+ $body .= "| Default IAX Port | " . textfield(-name => 'iax_port', -default => $users_config{iax_port}) . " |
";
+ $body .= "| Default Reg Seconds | " . textfield(-name => 'regseconds', -default => $users_config{regseconds}) . " |
";
+ $body .= "| Default Brand | " . textfield(-name => 'brand', -default => $users_config{brand}) . " |
";
+ $body .= "| Admin Email | " . textfield(-name => 'emailadd', -default => $users_config{emailadd}) . " |
";
+ $body .= "| Email Program | " . textfield(-name => 'mailprog', -default => $users_config{mailprog}) . " |
";
+ $body .= "| " . submit(-name => 'action', -value => 'Save') . " | " . submit( -name => 'action', -value => 'Create Database') . " |
";
+ $body .= "| " . submit(-name => 'action', -value => 'Update Database') . " |
";
+ $body .= "
";
+ 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 = " ";
+ 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") . "'?
" . hidden(-name => "dropitem", -value => param("item$x")) .
+ submit(-name => "action", -value => "Yes, drop it") . " " .
+ 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 = "" .
+ "" . start_form . "$status
\n" .
+ "| " . hidden(-name => 'mode', -value => 'iaxfriends') . "User Name | Secret | Context | IP Address | Port | Reg Seconds |
\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 .= "| " . hidden(-name => "item$count", -value => $row->{name}) .
+ textfield(-name => "newname$count", -size=> 10, -default => $row->{name}) . " | " .
+ textfield(-name => "newsecret$count", -size=> 10, -default=>$row->{secret}) .
+ " | " .
+ textfield(-name => "newcontext$count", -size => 15, -default => $row->{context}) . " | " .
+ textfield(-name => "newipaddr$count", -size => 10, -default => $row->{ipaddr}) .
+ " | " .
+ textfield(-name => "newport$count", -size => 10, -default => $row->{port}) . " | " .
+ textfield(-name => "newregseconds$count", -size => 5, -default => $row->{regseconds}) . " | ";
+ $body .= "" . submit(-name => "action$count", -value => 'Save...') .
+ submit(-name => "action$count", -value => 'Cancel...');
+ $body .= " |
";
+ } else {
+ $body .= "| " . hidden(-name => "item$count", -value => $row->{name}) .
+ "$row->{name} | " .
+ "$row->{secret} | $row->{context} | " .
+ "$row->{ipaddr} | $row->{port} | $row->{regseconds} | " .
+ "";
+ if (!$editing) {
+ $body .= submit(-name => "action$count", -value => 'Edit...') .
+ submit(-name => "action$count", -value => 'Drop...');
+ } else {
+ $body .= " ";
+ }
+ $body .= " |
\n";
+ }
+ }
+ $sth->finish;
+ $count++;
+ if ($creating) {
+ $body .= "| " . hidden(-name => "item$count", -value => $row->{name}) .
+ textfield(-name => "newname$count", -size=> 10) . " | " .
+ textfield(-name => "newsecret$count", -size => 10) . " | " .
+ textfield(-name => "newcontext$count", -size => 15) . " | " .
+ textfield(-name => "newipaddr$count", -size => 10) . " | " .
+ textfield(-name => "newport$count", -size => 10) . " | " .
+ textfield(-name => "newregseconds$count", -size => 5) . " | ";
+ $body .= "" . submit(-name => "action$count", -value => 'Create...') .
+ submit(-name => "action$count", -value => 'Cancel...');
+ $body .= " |
";
+ }
+ if (!$editing) {
+ $body .=
+ "
|
\n";
+ $body .=
+ "| " . hidden(-name => "item$count", -value => "new") .
+ " | " .
+ submit(-name => "action$count", -value => "Add...") . " |
\n";
+ }
+ $body .= "
\n";
+ return $body;
+}
+
+sub build_sip_friends() {
+ my $sth;
+ my $count;
+ my $color;
+ my $tmp;
+ my $editing;
+ my $creating;
+ my $status = " ";
+ 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") . "'?
" . hidden(-name => "dropitem", -value => param("item$x")) .
+ submit(-name => "action", -value => "Yes, drop it") . " " .
+ 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 = "" .
+ "" . start_form . "$status
\n" .
+ "| " . hidden(-name => 'mode', -value => 'sipfriends') . "Name |
+ User Name | Secret | Context | IP Address | Port | Reg Seconds |
\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 .= "| " . hidden(-name => "item$count", -value => $row->{name}) .
+ textfield(-name => "newname$count", -size=> 10, -default => $row->{name}) . " | " .
+ textfield(-name => "newusername$count", -size=> 10, -default => $row->{username}) . " | " .
+ textfield(-name => "newsecret$count", -size=> 10, -default=>$row->{secret}) .
+ " | " .
+ textfield(-name => "newcontext$count", -size => 15, -default => $row->{context}) . " | " .
+ textfield(-name => "newipaddr$count", -size => 10, -default => $row->{ipaddr}) .
+ " | " .
+ textfield(-name => "newport$count", -size => 10, -default => $row->{port}) . " | " .
+ textfield(-name => "newregseconds$count", -size => 5, -default => $row->{regseconds}) . " | ";
+ $body .= "" . submit(-name => "action$count", -value => 'Save...') .
+ submit(-name => "action$count", -value => 'Cancel...');
+ $body .= " |
";
+ } else {
+ $body .= "| " . hidden(-name => "item$count", -value => $row->{name}) .
+ "$row->{name} | " .
+ "$row->{username} | $row->{secret} | $row->{context} | " .
+ "$row->{ipaddr} | $row->{port} | $row->{regseconds} | " .
+ "";
+ if (!$editing) {
+ $body .= submit(-name => "action$count", -value => 'Edit...') .
+ submit(-name => "action$count", -value => 'Drop...');
+ } else {
+ $body .= " ";
+ }
+ $body .= " |
\n";
+ }
+ }
+ $sth->finish;
+ $count++;
+ if ($creating) {
+ $body .= "| " . hidden(-name => "item$count", -value => $row->{name}) .
+ textfield(-name => "newname$count", -size=> 10) . " | " .
+ textfield(-name => "newusername$count", -size=> 10) . " | " .
+ textfield(-name => "newsecret$count", -size => 10) . " | " .
+ textfield(-name => "newcontext$count", -size => 15) . " | " .
+ textfield(-name => "newipaddr$count", -size => 10) . " | " .
+ textfield(-name => "newport$count", -size => 10) . " | " .
+ textfield(-name => "newregseconds$count", -size => 5) . " | ";
+ $body .= "" . submit(-name => "action$count", -value => 'Create...') .
+ submit(-name => "action$count", -value => 'Cancel...');
+ $body .= " |
";
+ }
+ if (!$editing) {
+ $body .=
+ "
|
\n";
+ $body .=
+ "| " . hidden(-name => "item$count", -value => "new") .
+ " | " .
+ submit(-name => "action$count", -value => "Add...") . " |
\n";
+ }
+ $body .= "
\n";
+ return $body;
+}
+
+
sub build_body() {
my ($mode) = @_;
my $body;
@@ -807,25 +1308,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 "Not Configured!
\n" if ($mode eq "Users_Configure");
+ return "Not Configured!
\n" if ($mode eq "IAX_Friends");
+ return "Not Configured!
\n" if ($mode eq "SIP_Friends");
+ }
return "Not yet implemented!
\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 = " ";
-$body = &build_body($mode);
-$menu = &build_menu($mode);
-$msg = "Database unavailable -- please check configuration" unless $dbh;
-
-print "Asterisk™ Calling Card manager: $mode\n";
-print "\n";
-print "  | Asterisk™ Calling Card Admin: $mode" .
+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 = "Database unavailable -- please check configuration" unless $dbh;
+
+ print "Asterisk™ Calling Card manager: $mode\n";
+ print "\n";
+ print "  | Asterisk™ Calling Card Admin: $mode" .
" $msg | ";
-print " | $menu | $body | ";
-print " $copyright | \n";
-print " \n";
+ print " |
| $menu | $body |
";
+ print " $copyright |
\n";
+ print "
\n";
+}
Index: astcc/astcc.agi
===================================================================
RCS file: /usr/cvsroot/astcc/astcc.agi,v
retrieving revision 1.10
diff -u -r1.10 astcc.agi
--- astcc/astcc.agi 19 Sep 2004 15:41:31 -0000 1.10
+++ astcc/astcc.agi 1 Oct 2004 04:42:31 -0000
@@ -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);