[Asterisk-cvs] astcc astcc-admin.cgi,1.14,1.15 astcc.agi,1.12,1.13

kpfleming at lists.digium.com kpfleming at lists.digium.com
Sun May 15 01:45:59 CDT 2005


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

Modified Files:
	astcc-admin.cgi astcc.agi 
Log Message:
add support for PINs to calling cards (bug #2796)


Index: astcc-admin.cgi
===================================================================
RCS file: /usr/cvsroot/astcc/astcc-admin.cgi,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- astcc-admin.cgi	27 Apr 2005 03:18:09 -0000	1.14
+++ astcc-admin.cgi	15 May 2005 05:51:28 -0000	1.15
@@ -87,7 +87,7 @@
 	connect_db();
 	return -1 unless $dbh;
 	return -1 unless $dbh->do("CREATE TABLE brands (name CHAR(40) PRIMARY KEY, language CHAR(10), publishednum CHAR(40), did char(40), markup INTEGER, inc INTEGER, fee INTEGER, days INTEGER)");
-	return -1 unless $dbh->do("CREATE TABLE cards (number CHAR(20) PRIMARY KEY, language CHAR(10), facevalue INTEGER, used INTEGER NOT NULL, inc INTEGER NOT NULL, markup INTEGER NOT NULL, creation TIMESTAMP, firstuse TIMESTAMP, expiration TIMESTAMP, inuse INTEGER, brand CHAR(40), nextfee INTEGER)");
+	return -1 unless $dbh->do("CREATE TABLE cards (number CHAR(20) PRIMARY KEY, language CHAR(10), facevalue INTEGER, used INTEGER NOT NULL, inc INTEGER NOT NULL, markup INTEGER NOT NULL, creation TIMESTAMP, firstuse TIMESTAMP, expiration TIMESTAMP, inuse INTEGER, brand CHAR(40), nextfee INTEGER, pin INTEGER)");
 	return -1 unless $dbh->do("CREATE TABLE trunks (name CHAR(40) PRIMARY KEY, tech CHAR(10), path CHAR(40) NOT NULL)");
 	return -1 unless $dbh->do("CREATE TABLE routes (pattern CHAR(40) PRIMARY KEY, comment CHAR(80), trunks CHAR(80), connectcost INTEGER NOT NULL, includedseconds INTEGER NOT NULL, cost INTEGER NOT NULL)");
 	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)");
@@ -95,10 +95,22 @@
 }
 
 sub users_update_db() {
-       return -1 unless $dbh->do("ALTER TABLE cdrs ADD COLUMN callstart CHAR(24)");
+       $dbh->do("ALTER TABLE cdrs ADD COLUMN callstart CHAR(24)");
 	return 0;
 }	
 
+sub update_db() {
+		$dbh->do("ALTER TABLE cdrs ADD COLUMN callstart CHAR(24)");
+      	$dbh->do("ALTER TABLE cards ADD COLUMN pin INTEGER");
+      	$dbh->do("ALTER TABLE cards ADD COLUMN expiration TIMESTAMP");
+      	$dbh->do("ALTER TABLE cards ADD COLUMN creation TIMESTAMP");
+      	$dbh->do("ALTER TABLE cards ADD COLUMN firstuse TIMESTAMP");            
+      	$dbh->do("ALTER TABLE cards ADD COLUMN nextfee INTEGER");
+      	$dbh->do("ALTER TABLE cards ADD COLUMN brand CHAR(40)");
+      	$dbh->do("ALTER TABLE cards ADD COLUMN pin INTEGER");
+	return 0;
+}
+
 sub save_config() {
 	my $tmp;
 	open(CFG, ">/var/lib/astcc/astcc-config.conf");
@@ -241,9 +253,12 @@
 
 sub addcard() {
 	my ($number, $language, $seconds, $inc, $markup, $brand, $nextfee) = @_;
-	my $tmp = "INSERT INTO cards (number,language,inc,facevalue,markup,used,brand,nextfee) VALUES (" .
+	my $pin = &findunique;
+	my $pin = substr($pin, 0, $config{'pinlength'});
+	my $tmp = "INSERT INTO cards (number,language,inc,facevalue,markup,used,brand,nextfee,pin) VALUES (" .
 		$dbh->quote($number) . ", " . $dbh->quote($language) . ", " . $dbh->quote($inc) . ", " . $dbh->quote($seconds) .
-		", " . $dbh->quote($markup) . ",0,". $dbh->quote($brand) ."," . $dbh->quote($nextfee) .")";
+		", " . $dbh->quote($markup) . ",0,". $dbh->quote($brand) ."," . $dbh->quote($nextfee) .
+		", " . $dbh->quote($pin) . ")";
 	$dbh->do($tmp) || print "$tmp failed";
 }
 
@@ -258,9 +273,9 @@
 	my $sth = $dbh->prepare("SELECT * FROM brands WHERE name = " . $dbh->quote($brand));
 	$sth->execute;
 	if ($config{'email'} eq "YES") {
-		open (EMAIL, "| $config{mailprog} $config{emailadd} -s 'New Cards Created'") ||
+		open (EMAIL, "| $config{mailprog} $config{emailadd} -s 'New Card(s) Created'") ||
 			die "Error - could not write to $config{mailprog}\n";
-		print EMAIL "You have added $count $brand cards in the amount of $pennies cents. \n\n"; 
+		print EMAIL "You have added $count $brand card(s) in the amount of $pennies cents. \n\n"; 
 	}
 	if ($row = $sth->fetchrow_hashref) {
 		($language, $inc, $markup, $nextfee) = ($row->{language}, $row->{inc}, $row->{markup}, $row->{days});
@@ -275,9 +290,9 @@
 		}
 		&addcard($number, $language, $pennies * 100, $inc, $markup, $brand, $nextfee);
 		if ($config{'email'} eq "YES") {
-			print EMAIL "$number \n";
+			print EMAIL "Number: $number Pin: $pin \n";
 		}
-		$status .= "$number<br>";
+		$status .= "Number: $number Pin: $pin<br>";
 	}
 	if ($config{'email'} eq "YES") {
 		print EMAIL ".\n";
@@ -320,10 +335,12 @@
 			print EMAIL_ADMIN "Account Number: $number \n";
 			print EMAIL_ADMIN "Password: $secret \n";
 			print EMAIL_ADMIN "Balance (Pennies): $pennies \n";
+			print EMAIL_ADMIN "Pin: $pin \n";
 		}
 		print USERS_EMAIL "Account Number: $number \n";
 		print USERS_EMAIL "Password: $secret \n";
 		print USERS_EMAIL "Balance (cents): $pennies \n";
+		print USERS_EMAIL "Pin: $pin \n";
 		if ($sip eq "y" ) {
 			&add_sip_user($number, $secret);
 		}
@@ -477,7 +494,7 @@
 		@cardlist = &list_cards();
 		$body .= "<table>";
 		$body .= "<tr bgcolor=ffffff><tdcolspan=4><i>" . $status . "</i></td></tr>\n";
-		$body .= "<tr bgcolor=ccccff><td>Card Number</td><td>Brand</td><td>Amount Used</td><td>Face Value</td><td>Markup</td><td>Creation</td><td>First Use</td><td>Expiration</td><td>In Use</td></tr>\n";
+		$body .= "<tr bgcolor=ccccff><td>Card Number</td><td>Brand</td><td>Amount Used</td><td>Face Value</td><td>Markup</td><td>Creation</td><td>First Use</td><td>Expiration</td><td>In Use</td><td>Pin</td></tr>\n";
 		foreach (@cardlist) {
 			$cardnum = $_;
 			$cardinfo = &getcard($cardnum);
@@ -489,7 +506,7 @@
 					$color = "#ffffcc";
 				}
 
-			$body .= "<tr bgcolor=$color><td>$cardnum</td><td>$cardinfo->{brand}</td><td>$cardinfo->{used}</td><td>$cardinfo->{facevalue}</td><td>$cardinfo->{markup}</td><td>$cardinfo->{creation}</td><td>$cardinfo->{firstuse}</td><td>$cardinfo->{expiration}</td><td>$cardinfo->{inuse}"; 
+			$body .= "<tr bgcolor=$color><td>$cardnum</td><td>$cardinfo->{brand}</td><td>$cardinfo->{used}</td><td>$cardinfo->{facevalue}</td><td>$cardinfo->{markup}</td><td>$cardinfo->{creation}</td><td>$cardinfo->{firstuse}</td><td>$cardinfo->{expiration}</td><td>$cardinfo->{inuse}</td><td>$cardinfo->{pin}"; 
 			$body .= "</td></tr>\n";
 			}
 		}
@@ -911,7 +928,7 @@
 	my $body = start_form;
 	my $activity = "<br>";
 	my $action = param('action');
-	if (($action eq "Save") || ($action eq "Create Database")) {
+	if (($action eq "Save") || ($action eq "Create Database") || ($action eq "Update Database")) {
 		$config{dbuser} = param('dbuser');
 		$config{dbpass} = param('dbpass');
 		$config{dbname} = param('dbname');
@@ -925,6 +942,8 @@
 		$config{maintverbose} = param('maintverbose');
 		$config{maintcdr} = param('maintcdr');
 		$config{maintname} = param('maintname');
+		$config{pinstatus} = param('pinstatus');
+		$config{pinlength} = param('pinlength');		
 		&save_config();
 		$activity = "Configuration saved...";
 		if ($action eq "Create Database") {
@@ -933,6 +952,12 @@
 			} else {
 				$activity = "Database creation failed!";
 			}
+		} elsif ($action eq "Update Database") {
+			if (!&update_db()) {i
+				$activity = "Database Updated!";
+			} else {
+				$activity = "Database Update failed!";
+			}
 		}
 		&connect_db;
 	}
@@ -953,7 +978,10 @@
 	$body .= "<tr><td>Verbose account maintainence (YES/NO) </td><td>" . textfield(-name => 'maintverbose', -default => $config{maintverbose}) . "</td></tr>";
 	$body .= "<tr><td>Modify CDR to show maintainence fee (YES/NO) </td><td>" . textfield(-name => 'maintcdr', -default => $config{maintcdr}) . "</td></tr>";
 	$body .= "<tr><td>CDR Text for maintainence fee</td><td>" . textfield(-name => 'maintname', -default => $config{maintname}) . "</td></tr>";
+	$body .= "<tr><td>Pin Length  (4-20) </td><td>" . textfield(-name => 'pinlength', -default => $config{pinlength}) . "</td></tr>";
+	$body .= "<tr><td>Require Pins (Yes/NO)</td><td>" . textfield(-name => 'pinstatus', -default => $config{pinstatus}) . "</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;
 }

Index: astcc.agi
===================================================================
RCS file: /usr/cvsroot/astcc/astcc.agi,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- astcc.agi	12 Mar 2005 06:52:38 -0000	1.12
+++ astcc.agi	15 May 2005 05:51:28 -0000	1.13
@@ -289,7 +289,7 @@
 	$sth->finish;
 	return "CHANUNAVAIL" unless $res;
 	if ($res->{tech} eq "Local") {
-		$dialstr = "Local/$phone/$res->{path}|30|HL(" . ($maxtime * 60 * 1000) . ":60000:30000)";
+		$dialstr = "Local/$phone/$res->{path}|30|HL/n(" . ($maxtime * 60 * 1000) . ":60000:30000)";
 		$res = $AGI->exec("DIAL $dialstr");
 		$answeredtime = $AGI->get_variable("ANSWEREDTIME");
 		$dialstatus = $AGI->get_variable("DIALSTATUS");
@@ -329,10 +329,10 @@
 
 sub calccost() {
 	my ($adjconn, $adjcost, $answeredtime, $increment) = @_;
-	my $adjtime = int(($answeredtime + $increment - 1) / $increment) * $increment;
+	eval { my $adjtime = int(($answeredtime + $increment - 1) / $increment) * $increment };
 	my $cost;
 	print STDERR "Adjusted time is $adjtime, cost is $adjcost with $adjconn fee\n";
-	$cost = int($adjcost * $adjtime / 60);
+	eval { $cost = int($adjcost * $adjtime / 60) };
 	$cost += $adjconn;
 	print STDERR "Total cost is $cost\n";
 	return $cost;
@@ -441,7 +441,9 @@
 		if (length($res) > 0) {
 			$cardno = $AGI->get_data("astcc-silence");
 		} else {
-			$cardno = $AGI->get_data("astcc-accountnum");
+			$res = &mystreamfile("astcc-pleasepin");  # Please enter your
+			$res = &mysaynumber($config{'cardlength'});  # How many digits long
+			$cardno = $AGI->get_data("astcc-accountnum2"); #digit account number skipping any punctuation followed by the pound sign
 		}
 		exit if $cardno < 0;
 		$cardno = $res . $cardno;
@@ -481,6 +483,31 @@
 #
 # At this point we have a valid card number.
 #
+$tries = 0;
+if ($config{'pinstatus'} eq "YES") {
+	$correctpin = $carddata->{pin};
+	while ($pin ne $correctpin) {
+		$tries++;
+		if ($quiet < 5 ) {
+			$res = &mystreamfile("astcc-pleasepin");
+			$res = &mysaynumber($config{'pinlength'});
+			$pin = $AGI->get_data("astcc-pin");
+		} else { $res = "silent"; }
+		if ($tries > 1) {
+			$res = &mystreamfile("astcc-invalidpin");
+		}
+		if ($tries > 2) {
+			if ($quiet < 2 ) {
+				$AGI->stream_file("vm-goodbye");
+			}
+			exit(0);
+		}
+	}
+}
+#
+# At this point we have a valid card and pin number.
+#
+
 &checkexpired($carddata->{number});
 &checkinuse($carddata->{number});
 &setinuse($carddata->{number}, 1);




More information about the svn-commits mailing list