From 54857ff2d17192b0f2fa4403c62c8c353b6ff5d3 Mon Sep 17 00:00:00 2001 From: mattf Date: Sun, 22 Sep 2013 18:07:49 +0000 Subject: [PATCH] Added cellphone filtering service compatibility with DNC.COM. Read the CELLPHONE_USA_TCPA_FCC_COMPLIANCE.txt doc for more information git-svn-id: svn://192.168.202.10@2022 3d104415-ff17-0410-8863-d5cf3c621b8a --- agc_2-X/trunk/UPGRADE | 5 + agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl | 33 +- agc_2-X/trunk/bin/nanpa_type_filter.pl | 448 +++++++++ agc_2-X/trunk/bin/nanpa_type_populate.pl | 327 +++++++ agc_2-X/trunk/bin/nanpa_type_preload.pl | 859 ++++++++++++++++++ .../CELLPHONE_USA_TCPA_FCC_COMPLIANCE.txt | 80 ++ agc_2-X/trunk/docs/REQUIRED_APPS_INSTALL.txt | 4 +- agc_2-X/trunk/docs/SCRATCH_INSTALL.txt | 2 + .../trunk/extras/MySQL_AST_CREATE_tables.sql | 44 +- agc_2-X/trunk/extras/upgrade_2.8.sql | 44 + .../TO_BE_TRANSLATED_2.8.txt | 1 + .../www/vicidial/NANPA_running_processes.php | 170 ++++ agc_2-X/trunk/www/vicidial/admin.php | 28 +- .../www/vicidial/admin_NANPA_updater.php | 442 +++++++++ agc_2-X/trunk/www/vicidial/nanpa_type.php | 250 +++++ 15 files changed, 2720 insertions(+), 17 deletions(-) create mode 100644 agc_2-X/trunk/bin/nanpa_type_filter.pl create mode 100644 agc_2-X/trunk/bin/nanpa_type_populate.pl create mode 100644 agc_2-X/trunk/bin/nanpa_type_preload.pl create mode 100644 agc_2-X/trunk/docs/CELLPHONE_USA_TCPA_FCC_COMPLIANCE.txt create mode 100644 agc_2-X/trunk/www/vicidial/NANPA_running_processes.php create mode 100644 agc_2-X/trunk/www/vicidial/admin_NANPA_updater.php create mode 100644 agc_2-X/trunk/www/vicidial/nanpa_type.php diff --git a/agc_2-X/trunk/UPGRADE b/agc_2-X/trunk/UPGRADE index 5a559df2..ad1d4cad 100644 --- a/agc_2-X/trunk/UPGRADE +++ b/agc_2-X/trunk/UPGRADE @@ -143,6 +143,11 @@ OTHER CHANGES: bar and several other browser options disabled. To enable this feature, just set the $window_validation variable to '1' in options.php +17. Added phone number type field/list_id updating scripts. Compatible with + DNC.COM's daily update file services. Read the + CELLPHONE_USA_TCPA_FCC_COMPLAINCE.txt file for more detailed information + on this feature. + diff --git a/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl b/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl index b02da908..28c1c3fd 100644 --- a/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl +++ b/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl @@ -86,6 +86,7 @@ # 130508-1009 - Small fix for INVALID_2ND and 3RD # 130624-0733 - Added optimize for vicidial_users due to logging IP and auth timestamp # 130716-1441 - Clear out vicidial_monitor_calls records older than 1 day old +# 130921-1044 - Small change to triggers allowing for them to be launched in a screen session if SCREEN is in the name # $DB=0; # Debug flag @@ -3209,16 +3210,17 @@ if ( ($active_asterisk_server =~ /Y/) && ( ($sounds_update =~ /Y/) || ($upload_a ################################################################################ ##### BEGIN process triggers ################################################################################ -$stmtA = "SELECT trigger_id,user,trigger_lines FROM vicidial_process_triggers where server_ip='$server_ip' and trigger_run='1' and trigger_time < NOW() order by trigger_time limit 1;"; +$stmtA = "SELECT trigger_id,user,trigger_lines,trigger_name FROM vicidial_process_triggers where server_ip='$server_ip' and trigger_run='1' and trigger_time < NOW() order by trigger_time limit 1;"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthBrows=$sthA->rows; if ($sthBrows > 0) { @aryA = $sthA->fetchrow_array; - $trigger_id = "$aryA[0]"; - $user = "$aryA[1]"; - $trigger_lines = "$aryA[2]"; + $trigger_id = $aryA[0]; + $user = $aryA[1]; + $trigger_lines = $aryA[2]; + $trigger_name = $aryA[3]; } $sthA->finish(); @@ -3235,15 +3237,23 @@ if ($sthBrows > 0) foreach(@triggers) { $trigger_results .= "$triggers[$i]\n"; - @output=@MT; - @output = `$triggers[$i]`; - $m=0; - foreach(@output) + if ($trigger_name =~ /SCREEN/) { - $trigger_results .= "$output[$m]"; - $m++; + if ($DB) {print "starting trigger process in a screen...\n";} + `/usr/bin/screen -d -m -S VT$reset_test $triggers[$i]`; + $trigger_results = 'launched in a screen'; + } + else + { + @output=@MT; + @output = `$triggers[$i]`; + $m=0; + foreach(@output) + { + $trigger_results .= "$output[$m]"; + $m++; + } } - $i++; } if ($DB) {print "DONE\n";} @@ -3255,7 +3265,6 @@ if ($sthBrows > 0) $stmtA="INSERT INTO vicidial_process_trigger_log SET trigger_id='$trigger_id',user='$user',trigger_time=NOW(),server_ip='$server_ip',trigger_lines='$trigger_lines',trigger_results='$trigger_results';"; $Iaffected_rows = $dbhA->do($stmtA); if ($DB) {print "FINISHED: $affected_rows|$Iaffected_rows";} - } ################################################################################ ##### END process triggers diff --git a/agc_2-X/trunk/bin/nanpa_type_filter.pl b/agc_2-X/trunk/bin/nanpa_type_filter.pl new file mode 100644 index 00000000..3a03bba9 --- /dev/null +++ b/agc_2-X/trunk/bin/nanpa_type_filter.pl @@ -0,0 +1,448 @@ +#!/usr/bin/perl +# +# nanpa_type_filter.pl version 2.8 +# +# DESCRIPTION: +# This script is designed to filter the leads in a list by phone number and +# put the lead into a different list if it is a cellphone or invalid +# +# It is recommended that you run this program on the local Asterisk machine +# +# Copyright (C) 2013 Matt Florell LICENSE: AGPLv2 +# +# CHANGES +# 130822-1645 - first build +# + +$secX = time(); +$MT[0]=''; + +$list_id=''; +$cellphone_list_id=''; +$landline_list_id=''; +$invalid_list_id=''; +$invalid=0; +$cellphone=0; +$landline=0; + +### begin parsing run-time options ### +if (length($ARGV[0])>1) + { + $i=0; + while ($#ARGV >= $i) + { + $args = "$args $ARGV[$i]"; + $i++; + } + + if ($args =~ /--help/i) + { + print "allowed run time options:\n"; + print " [--test] = test\n"; + print " [--quiet] = supress all normal output\n"; + print " [--debug] = verbose debug messages\n"; + print " [--debugX] = extra verbose debug messages\n"; + print " [--output-to-db] = writes output to db table\n"; + print " [--db-output-code=XXX] = code used to tag output to db table\n"; + print " [--user=XXX] = system user for lookups\n"; + print " [--pass=XXX] = system password for lookups\n"; + print " [--list-id=XXX] = list(s) that you want to filter, double-dash-delimited if more than one: 111--222\n"; + print " double-dash-delimited if more than one: 111--222\n"; + print " or you can use ---ALL--- for all lists in the system\n"; + print " [--cellphone-list-id=XXX] = list that you want to move cellphones into\n"; + print " [--landline-list-id=XXX] = OPTIONAL, list that you want to move landline phones into\n"; + print " [--invalid-list-id=XXX] = OPTIONAL, list that you want to move invalid prefix phone numbers into\n"; + print " [--vl-field-update=XXX] = OPTIONAL, field that you want to update with the phone type information\n"; + print "\n"; + exit; + } + else + { + if ($args =~ /--quiet/i) + { + $Q=1; + } + if ($args =~ /--debug/i) + { + $DB=1; + } + if ($args =~ /--debugX/i) + { + $DBX=1; + } + if ($args =~ /--output-to-db/i) + { + $output_to_db=1; + } + if ($args =~ /--db-output-code=/i) + { + @data_in = split(/--db-output-code=/,$args); + $db_output_code = $data_in[1]; + $db_output_code =~ s/ .*//gi; + if ($DB > 0) {print "\n----- DB OUTPUT CODE: $db_output_code -----\n\n";} + } + if ($args =~ /--test/i) + { + $TEST=1; + } + if ($args =~ /--user=/i) + { + @data_in = split(/--user=/,$args); + $PREFIX_user = $data_in[1]; + $PREFIX_user =~ s/ .*//gi; + $TRIGGER_user = $PREFIX_user; + if ($DB > 0) {print "\n----- USER: $PREFIX_user -----\n\n";} + } + if ($args =~ /--pass=/i) + { + @data_in = split(/--pass=/,$args); + $PREFIX_pass = $data_in[1]; + $PREFIX_pass =~ s/ .*//gi; + if ($DB > 0) {print "\n----- PASS: XXXX -----\n\n";} + } + if ($args =~ /--list-id=/i) + { + @data_in = split(/--list-id=/,$args); + $list_id = $data_in[1]; + $list_id =~ s/ .*//gi; + if ($list_id =~ /---ALL---/) + { + $list_idSQL = ''; + } + else + { + if ($list_id =~ /--/) + { + $list_idTEMP = $list_id; + $list_idTEMP =~ s/--/','/gi; + $list_idSQL = "where list_id IN('$list_idTEMP')"; + } + else + { + $list_idSQL = "where list_id='$list_id'"; + } + } + if ($DB > 0) {print "\n----- LIST ID: $list_id ($list_idSQL) -----\n\n";} + } + if ($args =~ /--cellphone-list-id=/i) + { + @data_in = split(/--cellphone-list-id=/,$args); + $cellphone_list_id = $data_in[1]; + $cellphone_list_id =~ s/ .*//gi; + if ($DB > 0) {print "\n----- CELLPHONE LIST ID: $cellphone_list_id -----\n\n";} + } + if ($args =~ /--landline-list-id=/i) + { + @data_in = split(/--landline-list-id=/,$args); + $landline_list_id = $data_in[1]; + $landline_list_id =~ s/ .*//gi; + if ($DB > 0) {print "\n----- LANDLINE LIST ID: $landline_list_id -----\n\n";} + } + if ($args =~ /--invalid-list-id=/i) + { + @data_in = split(/--invalid-list-id=/,$args); + $invalid_list_id = $data_in[1]; + $invalid_list_id =~ s/ .*//gi; + if ($DB > 0) {print "\n----- INVALID LIST ID: $invalid_list_id -----\n\n";} + } + if ($args =~ /--vl-field-update=/i) + { + @data_in = split(/--vl-field-update=/,$args); + $vl_field_update = $data_in[1]; + $vl_field_update =~ s/ .*//gi; + if ($DB > 0) {print "\n----- VL FIELD UPDATE: $vl_field_update -----\n\n";} + } + } + } +else + { + print "no command line options set\n"; + exit; + } + +### end parsing run-time options ### + + +### find wget binary +$wgetbin = ''; +if ( -e ('/bin/wget')) {$wgetbin = '/bin/wget';} +else + { + if ( -e ('/usr/bin/wget')) {$wgetbin = '/usr/bin/wget';} + else + { + if ( -e ('/usr/local/bin/wget')) {$wgetbin = '/usr/local/bin/wget';} + else + { + print "Can't find wget binary! Exiting...\n"; + exit + } + } + } + + +# default path to astguiclient configuration file: +$PATHconf = '/etc/astguiclient.conf'; +$PATHconfPREFIX = '/etc/vicidial_prefix.conf'; + +open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n"; +@conf = ; +close(conf); +$i=0; +foreach(@conf) + { + $line = $conf[$i]; + $line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi; + if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) ) + {$PATHhome = $line; $PATHhome =~ s/.*=//gi;} + if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) ) + {$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;} + if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) ) + {$PATHagi = $line; $PATHagi =~ s/.*=//gi;} + if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) ) + {$PATHweb = $line; $PATHweb =~ s/.*=//gi;} + if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) ) + {$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;} + if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) ) + {$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;} + if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) ) + {$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) ) + {$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) ) + {$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) ) + {$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) ) + {$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) ) + {$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;} + $i++; + } + +open(viciprefix, "$PATHconfPREFIX") || die "can't open $PATHconfPREFIX: $!\n"; +@viciprefix = ; +close(viciprefix); +$i=0; +foreach(@viciprefix) + { + $line = $viciprefix[$i]; + $line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi; + if ( ($line =~ /^PREFIX_url/) && ($CLI_PREFIX_url < 1) ) + {$PREFIX_url = $line; $PREFIX_url =~ s/.*=//gi;} + if ( ($line =~ /^PREFIX_user/) && (length($CLI_PREFIX_user) < 1) ) + {$PREFIX_user = $line; $PREFIX_user =~ s/.*=//gi;} + if ( ($line =~ /^PREFIX_pass/) && (length($CLI_PREFIX_pass) < 1) ) + {$PREFIX_pass = $line; $PREFIX_pass =~ s/.*=//gi;} + $i++; + } + +if ( (length($list_id)<2) || (length($PREFIX_user)<2) || (length($PREFIX_pass)<2) || (length($PREFIX_url)<2) ) + { + print "user, pass, url and list-id options must be set for this script to run: |$PREFIX_user|XXXX|$list_id|\n"; + exit; + } + +if (length($TRIGGER_user) < 2) {$TRIGGER_user = $PREFIX_user;} + +($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); +$year = ($year + 1900); +$mon++; +if ($mon < 10) {$mon = "0$mon";} +if ($mday < 10) {$mday = "0$mday";} +if ($hour < 10) {$hour = "0$hour";} +if ($min < 10) {$min = "0$min";} +if ($sec < 10) {$sec = "0$sec";} +$timestamp = "$year-$mon-$mday $hour:$min:$sec"; +$filedate = "$year$mon$mday$hour$min$sec"; +$VDrandom = int( rand(9999999)) + 10000000; + +# Customized Variables +$server_ip = $VARserver_ip; # Asterisk server IP + +if (!$VARDB_port) {$VARDB_port='3306';} + +if (length($db_output_code)<2) {$db_output_code = $filedate . "_" . $VDrandom;} + + +use DBI; + +$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") + or die "Couldn't connect to database: " . DBI->errstr; +$dbhB = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") + or die "Couldn't connect to database: " . DBI->errstr; + +($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + +if ($output_to_db) + { + $stmtA = "INSERT INTO vicidial_nanpa_filter_log SET output_code='$db_output_code',user='$TRIGGER_user',status='LAUNCHED',server_ip='$VARserver_ip',list_id='$list_id',start_time=NOW(),update_time=NOW(),status_line='Starting...',script_output=\"Starting...\nCELLPHONE LIST ID: $cellphone_list_id\nLANDLINE LIST ID: $landline_list_id\nINVALID LIST ID: $invalid_list_id\nVL FIELD UPDATE: $vl_field_update\n\" ON DUPLICATE KEY UPDATE status='LAUNCHED',server_ip='$VARserver_ip',list_id='$list_id',update_time=NOW(),status_line=\"Starting...\n\",script_output=CONCAT(script_output,\"Starting...\nCELLPHONE LIST ID: $cellphone_list_id\nLANDLINE LIST ID: $landline_list_id\nINVALID LIST ID: $invalid_list_id\nVL FIELD UPDATE: $vl_field_update\n\");"; + $affected_rows = $dbhA->do($stmtA); + if($DBX){print STDERR "\n|$affected_rows|$stmtA|\n";} + } + +@lead_ids=@MT; +@phones=@MT; +$stmtA = "SELECT lead_id,phone_number from vicidial_list $list_idSQL;"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; +$rec_count=0; +if ($DB) {print "LEADS FOUND IN LIST $list_id: |$sthArows|\n";} +if ($DBX) {print "|$stmtA|\n";} +while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $lead_ids[$rec_count] = $aryA[0]; + $phones[$rec_count] = $aryA[1]; + $rec_count++; + + if ($DB > 0) + { + if ($rec_count =~ /100$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /200$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /300$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /400$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /500$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /600$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /700$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /800$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /900$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /000$/i) {print STDERR " * $rec_count\r";} + + } + } + +if ($DB) {print "STARTING LOOKUP OF NANPA PHONE TYPE, ($rec_count records)\n";} +if ($output_to_db) + { + $stmtA = "UPDATE vicidial_nanpa_filter_log SET status='LEADS_GATHERED',leads_count='$rec_count',update_time=NOW(),status_line='Leads Gathered: $rec_count',script_output=CONCAT(script_output,\"Leads Gathered: $rec_count\n\") where output_code='$db_output_code';"; + $affected_rows = $dbhA->do($stmtA); + if($DBX){print STDERR "\n|$affected_rows|$stmtA|\n";} + } +$rec_count=0; +$batch_count=0; +$batch_phones=''; +# open(STORAGE, "> nft_output.txt"); +while ($sthArows > $rec_count) + { + $rec_next = ($rec_count + 1); + if ( ($batch_count < 1000) && ($rec_next < $sthArows) ) + { + $batch_phones .= $phones[$rec_count] . '\|'; + $batch_count++; + } + else + { + $batch_phones .= $phones[$rec_count]; + $secTEMP = time(); + # http://localhost/vicidial/nanpa_type.php?user=6666&pass=1234&phone_number=7275551212|8135551212|9545551212|9995551212 + $postdata = "user=$PREFIX_user&pass=$PREFIX_pass&phone_number=$batch_phones"; + $tempurl = $PREFIX_url; + $tempfilename = "$lead_ids[$rec_count]$phones[$rec_count]$secTEMP" . '.txt'; + $temp_wget = "$wgetbin -q --output-document=/tmp/$tempfilename $tempurl --post-data=\"$postdata\" "; + if ($DBX > 0) {print STDERR "$temp_wget\n";} + @wget_output = `$temp_wget `; + + open(tempweboutput, "/tmp/$tempfilename") || die "can't open /tmp/$tempfilename: $!\n"; + @tempweboutput = ; + close(tempweboutput); + `rm -f /tmp/$tempfilename `; + + if ($DBX > 0) {print STDERR "$tempweboutput[0]\n";} + + $b=0; + foreach(@tempweboutput) + { + $temp_rec = (($rec_count - $batch_count) + $b); + chomp($tempweboutput[$b]); + @result_split = split('|',$tempweboutput[$b]); + if ( ($phones[$temp_rec] =~ /$result_split[1]/) && (length($lead_ids[$temp_rec]) > 0) ) + { + # print STORAGE "$phones[$temp_rec]|$result_split[0]\n"; + $stmtA=''; + if ($result_split[0] =~ /I/) {$invalid++;} + if ($result_split[0] =~ /C/) {$cellphone++;} + if ($result_split[0] =~ /S/) {$landline++;} + if ( ($result_split[0] =~ /I/) && (length($invalid_list_id) > 1) ) + {$stmtA = "UPDATE vicidial_list SET list_id=$invalid_list_id where lead_id=$lead_ids[$temp_rec];";} + if ( ($result_split[0] =~ /C/) && (length($cellphone_list_id) > 1) ) + {$stmtA = "UPDATE vicidial_list SET list_id=$cellphone_list_id where lead_id=$lead_ids[$temp_rec];";} + if ( ($result_split[0] =~ /S/) && (length($landline_list_id) > 1) ) + {$stmtA = "UPDATE vicidial_list SET list_id=$landline_list_id where lead_id=$lead_ids[$temp_rec];";} + if ( (length($stmtA) > 10) && ($TEST < 1) ) + { + if($DBX){print STDERR "\n|$stmtA|$phones[$temp_rec]|\n";} + $affected_rows = $dbhA->do($stmtA); + if($DBX){print STDERR "|$affected_rows records changed|\n";} + } + if ( (length($vl_field_update)>2) && ($TEST < 1) ) + { + $stmtA = "UPDATE vicidial_list SET $vl_field_update='$result_split[0]' where lead_id=$lead_ids[$temp_rec];"; + if($DBX){print STDERR "\n|$stmtA|$phones[$temp_rec]|\n";} + $affected_rows = $dbhA->do($stmtA); + if($DBX){print STDERR "|$affected_rows records changed|\n";} + } + } + # else + # {if ($DBX > 0) {print "ERROR: |$b|$rec_count|$temp_rec|$batch_count|$phones[$temp_rec]|$lead_ids[$temp_rec]|";} } + $b++; + } + $batch_phones=''; + $batch_count=0; + + if ($output_to_db) + { + $stmtA = "UPDATE vicidial_nanpa_filter_log SET status='NANPA_LOOKUPS',update_time=NOW(),filter_count='$rec_count',status_line='(INV: $invalid|CEL: $cellphone|LND: $landline)' where output_code='$db_output_code';"; + $affected_rows = $dbhA->do($stmtA); + if($DBX){print STDERR "\n|$affected_rows|$stmtA|\n";} + } + + } + + $rec_count++; + + if ($DB > 0) + { + $dance = ' '; + if ($rec_count =~ /1\d00$/i) {$dance = '# ';} + if ($rec_count =~ /2\d00$/i) {$dance = ' # ';} + if ($rec_count =~ /3\d00$/i) {$dance = ' # ';} + if ($rec_count =~ /4\d00$/i) {$dance = ' # ';} + if ($rec_count =~ /5\d00$/i) {$dance = ' # ';} + if ($rec_count =~ /6\d00$/i) {$dance = ' #';} + if ($rec_count =~ /7\d00$/i) {$dance = ' # ';} + if ($rec_count =~ /8\d00$/i) {$dance = ' # ';} + if ($rec_count =~ /9\d00$/i) {$dance = ' # ';} + if ($rec_count =~ /0\d00$/i) {$dance = ' # ';} + if ($rec_count =~ /00$/i) {print STDERR " $dance $rec_count (INV: $invalid|CEL: $cellphone|LND: $landline)\r";} + } + } + + + + + + + +### calculate time to run script ### +$secY = time(); +$secZ = ($secY - $secX); +$secZm = ($secZ /60); + +if (!$Q) {print "CELLPHONE SCRUB FOR LIST $list_id\n";} +if (!$Q) {print "TOTAL LEADS: $rec_count\n";} +if (!$Q) {print " INVALID: $invalid\n";} +if (!$Q) {print " CELLPHONE: $cellphone\n";} +if (!$Q) {print " LANDLINE: $landline\n";} +if (!$Q) {print "script execution time in seconds: $secZ minutes: $secZm\n";} + +if ($output_to_db) + { + $stmtA = "UPDATE vicidial_nanpa_filter_log SET status='COMPLETED',filter_count='$rec_count',update_time=NOW(),status_line='Process Completed: $secZ seconds',script_output=CONCAT(script_output,\"Process Completed: $secZ seconds\n INVALID: $invalid\n CELLPHONE: $cellphone\n LANDLINE: $landline\n\n\") where output_code='$db_output_code';"; + $affected_rows = $dbhA->do($stmtA); + if($DBX){print STDERR "\n|$affected_rows|$stmtA|\n";} + } + +exit; + diff --git a/agc_2-X/trunk/bin/nanpa_type_populate.pl b/agc_2-X/trunk/bin/nanpa_type_populate.pl new file mode 100644 index 00000000..c081dd4a --- /dev/null +++ b/agc_2-X/trunk/bin/nanpa_type_populate.pl @@ -0,0 +1,327 @@ +#!/usr/bin/perl +# +# nanpa_type_populate.pl version 2.8 +# +# DESCRIPTION: +# This script is designed to filter the leads in a list by phone number and +# put the lead into a different list if it is a cellphone or invalid +# +# It is recommended that you run this program on the local Asterisk machine +# +# Copyright (C) 2013 Matt Florell LICENSE: AGPLv2 +# +# CHANGES +# 130915-1345 - first build +# + +$PATHconf = '/etc/astguiclient.conf'; +$PATHconfPREFIX = '/etc/vicidial_prefix.conf'; + +$|=1; +$start_time=time(); + +open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n"; +@conf = ; +close(conf); +$i=0; +foreach(@conf) + { + $line = $conf[$i]; + $line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi; + if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) ) + {$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;} + if ( ($line =~ /^VARfastagi_log_min_servers/) && ($CLIVARfastagi_log_min_servers < 1) ) + {$VARfastagi_log_min_servers = $line; $VARfastagi_log_min_servers =~ s/.*=//gi;} + if ( ($line =~ /^VARfastagi_log_max_servers/) && ($CLIVARfastagi_log_max_servers < 1) ) + {$VARfastagi_log_max_servers = $line; $VARfastagi_log_max_servers =~ s/.*=//gi;} + if ( ($line =~ /^VARfastagi_log_min_spare_servers/) && ($CLIVARfastagi_log_min_spare_servers < 1) ) + {$VARfastagi_log_min_spare_servers = $line; $VARfastagi_log_min_spare_servers =~ s/.*=//gi;} + if ( ($line =~ /^VARfastagi_log_max_spare_servers/) && ($CLIVARfastagi_log_max_spare_servers < 1) ) + {$VARfastagi_log_max_spare_servers = $line; $VARfastagi_log_max_spare_servers =~ s/.*=//gi;} + if ( ($line =~ /^VARfastagi_log_max_requests/) && ($CLIVARfastagi_log_max_requests < 1) ) + {$VARfastagi_log_max_requests = $line; $VARfastagi_log_max_requests =~ s/.*=//gi;} + if ( ($line =~ /^VARfastagi_log_checkfordead/) && ($CLIVARfastagi_log_checkfordead < 1) ) + {$VARfastagi_log_checkfordead = $line; $VARfastagi_log_checkfordead =~ s/.*=//gi;} + if ( ($line =~ /^VARfastagi_log_checkforwait/) && ($CLIVARfastagi_log_checkforwait < 1) ) + {$VARfastagi_log_checkforwait = $line; $VARfastagi_log_checkforwait =~ s/.*=//gi;} + if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) ) + {$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) ) + {$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) ) + {$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) ) + {$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) ) + {$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) ) + {$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;} + $i++; + } + +open(viciprefix, "$PATHconfPREFIX") || die "can't open $PATHconfPREFIX: $!\n"; +@viciprefix = ; +close(viciprefix); +$i=0; +foreach(@viciprefix) + { + $line = $viciprefix[$i]; + $line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi; + if ( ($line =~ /^PREFIX_DB_server/) && ($CLIDB_server < 1) ) + {$PREFIX_DB_server = $line; $PREFIX_DB_server =~ s/.*=//gi;} + if ( ($line =~ /^PREFIX_DB_database/) && ($CLIDB_database < 1) ) + {$PREFIX_DB_database = $line; $PREFIX_DB_database =~ s/.*=//gi;} + if ( ($line =~ /^PREFIX_DB_user/) && ($CLIDB_user < 1) ) + {$PREFIX_DB_user = $line; $PREFIX_DB_user =~ s/.*=//gi;} + if ( ($line =~ /^PREFIX_DB_pass/) && ($CLIDB_pass < 1) ) + {$PREFIX_DB_pass = $line; $PREFIX_DB_pass =~ s/.*=//gi;} + if ( ($line =~ /^PREFIX_DB_port/) && ($CLIDB_port < 1) ) + {$PREFIX_DB_port = $line; $PREFIX_DB_port =~ s/.*=//gi;} + if ( ($line =~ /^PREFIX_SFTP_server/) && ($CLI_PREFIX_SFTP_server < 1) ) + {$PREFIX_SFTP_server = $line; $PREFIX_SFTP_server =~ s/.*=//gi;} + if ( ($line =~ /^PREFIX_SFTP_user/) && ($CLI_PREFIX_SFTP_user < 1) ) + {$PREFIX_SFTP_user = $line; $PREFIX_SFTP_user =~ s/.*=//gi;} + if ( ($line =~ /^PREFIX_SFTP_pass/) && ($CLI_PREFIX_SFTP_pass < 1) ) + {$PREFIX_SFTP_pass = $line; $PREFIX_SFTP_pass =~ s/.*=//gi;} + if ( ($line =~ /^PREFIX_SFTP_port/) && ($CLI_PREFIX_SFTP_port < 1) ) + {$PREFIX_SFTP_port = $line; $PREFIX_SFTP_port =~ s/.*=//gi;} + $i++; + } + + +$secX = time(); +($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); +$MT[0]=''; +$DBX=0; + +$list_id=''; +$cellphone_list_id=''; +$landline_list_id=''; +$invalid_list_id=''; +$invalid=0; +$cellphone=0; +$landline=0; + +### begin parsing run-time options ### +if (length($ARGV[0])>1) + { + $i=0; + while ($#ARGV >= $i) + { + $args = "$args $ARGV[$i]"; + $i++; + } + + if ($args =~ /--help/i) + { + print "allowed run time options:\n"; + print " [--skip-download] = skip download of files\n"; + print " [--test] = test\n"; + print " [--quiet] = supress all normal output\n"; + print " [--debug] = verbose debug messages\n"; + print " [--debugX] = extra verbose debug messages\n"; + print "\n"; + exit; + } + else + { + if ($args =~ /--quiet/i) + { + $Q=1; + } + if ($args =~ /--debug/i) + { + $DB=1; + } + if ($args =~ /--debugX/i) + { + $DBX=1; + } + if ($args =~ /--test/i) + { + $TEST=1; + } + if ($args =~ /--skip-download/i) + { + $skip_download=1; + } + } + } +else + { + print "no command line options set\n"; + exit; + } +### end parsing run-time options ### + + +if ($skip_download < 1) + { + ##### BEGIN gather files from SFTP server and unzip ##### + use Net::SFTP::Foreign; + + if (!$Q) {print "Logging in to SFTP server: $outfile\n";} + + $sftp_more='-q'; + if ($DB > 0) {$sftp_more='-v';} + + if ($DB > 0) {print "\n getting neustar.zip\n";} + $sftp = Net::SFTP::Foreign->new($PREFIX_SFTP_user . '@' . $PREFIX_SFTP_server, password => "$PREFIX_SFTP_pass", port => "$PREFIX_SFTP_port", more => "$sftp_more"); + if ($DB > 0) + { + $sftp->get("/$PREFIX_SFTP_user/_Databases/Neustar/neustar.zip", '/tmp/neustar.zip', callback => \&readcallback) or die "file transfer failed: " . $sftp->error; + } + else + { + $sftp->get("/$PREFIX_SFTP_user/_Databases/Neustar/neustar.zip", '/tmp/neustar.zip') or die "file transfer failed: " . $sftp->error; + } + + sleep(1); + + if ($DB > 0) {print "\n getting PrefixMasterList.zip\n";} + $sftpX = Net::SFTP::Foreign->new($PREFIX_SFTP_user . '@' . $PREFIX_SFTP_server, password => "$PREFIX_SFTP_pass", port => "$PREFIX_SFTP_port", more => "$sftp_more"); + if ($DB > 0) + { + $sftpX->get("/$PREFIX_SFTP_user/_Databases/WirelessPrefix/PrefixMasterList.zip", '/tmp/PrefixMasterList.zip', callback => \&readcallback) or die "file transfer failed: " . $sftpX->error; + } + else + { + $sftpX->get("/$PREFIX_SFTP_user/_Databases/WirelessPrefix/PrefixMasterList.zip", '/tmp/PrefixMasterList.zip') or die "file transfer failed: " . $sftpX->error; + } + + if ($DB > 0) {print "\n unzipping files... PrefixMasterList.zip\n";} + `/usr/bin/unzip -u /tmp/PrefixMasterList.zip -d /tmp`; + if ($DB > 0) {print " unzipping files... neustar.zip\n";} + `/usr/bin/unzip -u /tmp/neustar.zip -d /tmp`; + + ##### END gather files from SFTP server and unzip ##### + } + + +use DBI; + +### connect to phone type prefix DB +$dbhN = DBI->connect("DBI:mysql:$PREFIX_DB_database:$PREFIX_DB_server:$PREFIX_DB_port;mysql_local_infile=1", "$PREFIX_DB_user", "$PREFIX_DB_pass") + or die "Couldn't connect to database: " . DBI->errstr; + +$stmtN = "SELECT count(*) FROM nanpa_wired_to_wireless;"; +$sthN = $dbhN->prepare($stmtN) or die "preparing: ",$dbhN->errstr; +$sthN->execute or die "executing: $stmtN ", $dbhN->errstr; +$sthNrows=$sthN->rows; +if ($sthNrows > 0) + { + @aryN = $sthN->fetchrow_array; + $nanpa_wired_to_wireless_count = $aryN[0]; + $sthN->finish(); + if ($DBX) {print " $sthNrows|$stmtN|$nanpa_wired_to_wireless_count|\n";} + } + +$stmtN = "SELECT count(*) FROM nanpa_wireless_to_wired;"; +$sthN = $dbhN->prepare($stmtN) or die "preparing: ",$dbhN->errstr; +$sthN->execute or die "executing: $stmtN ", $dbhN->errstr; +$sthNrows=$sthN->rows; +if ($sthNrows > 0) + { + @aryN = $sthN->fetchrow_array; + $nanpa_wireless_to_wired_count = $aryN[0]; + $sthN->finish(); + if ($DBX) {print " $sthNrows|$stmtN|$nanpa_wireless_to_wired_count|\n";} + } + +$stmtN = "SELECT count(*) FROM nanpa_prefix_exchanges_master;"; +$sthN = $dbhN->prepare($stmtN) or die "preparing: ",$dbhN->errstr; +$sthN->execute or die "executing: $stmtN ", $dbhN->errstr; +$sthNrows=$sthN->rows; +if ($sthNrows > 0) + { + @aryN = $sthN->fetchrow_array; + $nanpa_prefix_exchanges_master_count = $aryN[0]; + $sthN->finish(); + if ($DBX) {print " $sthNrows|$stmtN|$nanpa_prefix_exchanges_master_count|\n";} + } + +$stmtN = "SELECT count(*) FROM nanpa_prefix_exchanges_fast;"; +$sthN = $dbhN->prepare($stmtN) or die "preparing: ",$dbhN->errstr; +$sthN->execute or die "executing: $stmtN ", $dbhN->errstr; +$sthNrows=$sthN->rows; +if ($sthNrows > 0) + { + @aryN = $sthN->fetchrow_array; + $nanpa_prefix_exchanges_fast_count = $aryN[0]; + $sthN->finish(); + if ($DBX) {print " $sthNrows|$stmtN|$nanpa_prefix_exchanges_fast_count|\n";} + } + + +if ($nanpa_wireless_to_wired_count > 0) + { + $stmtN = "DELETE from nanpa_wireless_to_wired;"; + $affected_rows = $dbhN->do($stmtN); + if($DBX){print STDERR "|$affected_rows records deleted| nanpa_wireless_to_wired\n";} + } + +$stmtN = "LOAD DATA LOCAL INFILE '/tmp/WIRELESS-TO-WIRELINE-NORANGE.TXT' into table nanpa_wireless_to_wired LINES terminated by '\n' (phone);"; +$affected_rows = $dbhN->do($stmtN); +if($DBX){print STDERR "|$affected_rows records inserted| nanpa_wireless_to_wired\n";} + +if ($nanpa_wired_to_wireless_count > 0) + { + $stmtN = "DELETE from nanpa_wired_to_wireless;"; + $affected_rows = $dbhN->do($stmtN); + if($DBX){print STDERR "|$affected_rows records deleted| nanpa_wired_to_wireless\n";} + } + +$stmtN = "LOAD DATA LOCAL INFILE '/tmp/WIRELINE-TO-WIRELESS-NORANGE.TXT' into table nanpa_wired_to_wireless LINES terminated by '\n' (phone);"; +$affected_rows = $dbhN->do($stmtN); +if($DBX){print STDERR "|$affected_rows records inserted| nanpa_wired_to_wireless\n";} + +if ($nanpa_prefix_exchanges_master_count > 0) + { + $stmtN = "DELETE from nanpa_prefix_exchanges_master;"; + $affected_rows = $dbhN->do($stmtN); + if($DBX){print STDERR "|$affected_rows records deleted| nanpa_prefix_exchanges_master\n";} + } + +$stmtN = "LOAD DATA LOCAL INFILE '/tmp/PrefixMasterList.csv' into table nanpa_prefix_exchanges_master FIELDS TERMINATED BY ',' LINES terminated by '\r\n' (areacode,prefix,source,type,tier,postal_code,new_areacode,tzcode,region);"; +$affected_rows = $dbhN->do($stmtN); +if($DBX){print STDERR "|$affected_rows records inserted| nanpa_prefix_exchanges_master\n";} + +if ($nanpa_prefix_exchanges_fast_count > 0) + { + $stmtN = "DELETE from nanpa_prefix_exchanges_fast;"; + $affected_rows = $dbhN->do($stmtN); + if($DBX){print STDERR "|$affected_rows records deleted| nanpa_prefix_exchanges_fast\n";} + } + +$stmtN = "INSERT INTO nanpa_prefix_exchanges_fast (ac_prefix,type) SELECT CONCAT(areacode,prefix),type from nanpa_prefix_exchanges_master;"; +$affected_rows = $dbhN->do($stmtN); +if($DBX){print STDERR "|$affected_rows records inserted| nanpa_prefix_exchanges_fast\n";} + + +if ($DB) {print "LEADS FOUND IN LIST $list_id: |$sthArows|\n";} +if ($DBX) {print "|$stmtA|\n";} + +if ($DB) {print "STARTING LOOKUP OF NANPA PHONE TYPE, ($rec_count records)\n";} +$end_time=time; +if (!$Q) {print "Pre-scrub Elapsed time: ".($end_time-$start_time)." sec\n\n\n";} + + + +$end_time=time(); +if (!$Q) {print "TOTAL Elapsed time: ".($end_time-$start_time)." sec\n\n";} + + +### sftp callback subroutines +sub writecallback + { + my($sftp, $data, $offset, $size) = @_; + if ($DB > 0) + {print STDERR "Wrote $offset / $size bytes\r";} + } + +sub readcallback + { + my($sftp, $data, $offset, $size) = @_; + if ($DB > 0) + {print STDERR "Read $offset / $size bytes\r";} + } diff --git a/agc_2-X/trunk/bin/nanpa_type_preload.pl b/agc_2-X/trunk/bin/nanpa_type_preload.pl new file mode 100644 index 00000000..5e3acc71 --- /dev/null +++ b/agc_2-X/trunk/bin/nanpa_type_preload.pl @@ -0,0 +1,859 @@ +#!/usr/bin/perl +# +# nanpa_type_preload.pl version 2.8 +# +# DESCRIPTION: +# This script is designed to filter the leads in a list by phone number and +# put the lead into a different list if it is a cellphone or invalid +# +# It is recommended that you run this program on the local Asterisk machine +# +# Copyright (C) 2013 Matt Florell LICENSE: AGPLv2 +# +# CHANGES +# 130914-1710 - first build +# + +$PATHconf = '/etc/astguiclient.conf'; +$PATHconfPREFIX = '/etc/vicidial_prefix.conf'; + +$|=1; + +open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n"; +@conf = ; +close(conf); +$i=0; +foreach(@conf) + { + $line = $conf[$i]; + $line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi; + if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) ) + {$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;} + if ( ($line =~ /^VARfastagi_log_min_servers/) && ($CLIVARfastagi_log_min_servers < 1) ) + {$VARfastagi_log_min_servers = $line; $VARfastagi_log_min_servers =~ s/.*=//gi;} + if ( ($line =~ /^VARfastagi_log_max_servers/) && ($CLIVARfastagi_log_max_servers < 1) ) + {$VARfastagi_log_max_servers = $line; $VARfastagi_log_max_servers =~ s/.*=//gi;} + if ( ($line =~ /^VARfastagi_log_min_spare_servers/) && ($CLIVARfastagi_log_min_spare_servers < 1) ) + {$VARfastagi_log_min_spare_servers = $line; $VARfastagi_log_min_spare_servers =~ s/.*=//gi;} + if ( ($line =~ /^VARfastagi_log_max_spare_servers/) && ($CLIVARfastagi_log_max_spare_servers < 1) ) + {$VARfastagi_log_max_spare_servers = $line; $VARfastagi_log_max_spare_servers =~ s/.*=//gi;} + if ( ($line =~ /^VARfastagi_log_max_requests/) && ($CLIVARfastagi_log_max_requests < 1) ) + {$VARfastagi_log_max_requests = $line; $VARfastagi_log_max_requests =~ s/.*=//gi;} + if ( ($line =~ /^VARfastagi_log_checkfordead/) && ($CLIVARfastagi_log_checkfordead < 1) ) + {$VARfastagi_log_checkfordead = $line; $VARfastagi_log_checkfordead =~ s/.*=//gi;} + if ( ($line =~ /^VARfastagi_log_checkforwait/) && ($CLIVARfastagi_log_checkforwait < 1) ) + {$VARfastagi_log_checkforwait = $line; $VARfastagi_log_checkforwait =~ s/.*=//gi;} + if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) ) + {$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) ) + {$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) ) + {$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) ) + {$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) ) + {$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) ) + {$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;} + $i++; + } + +open(viciprefix, "$PATHconfPREFIX") || die "can't open $PATHconfPREFIX: $!\n"; +@viciprefix = ; +close(viciprefix); +$i=0; +foreach(@viciprefix) + { + $line = $viciprefix[$i]; + $line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi; + if ( ($line =~ /^PREFIX_DB_server/) && ($CLIDB_server < 1) ) + {$PREFIX_DB_server = $line; $PREFIX_DB_server =~ s/.*=//gi;} + if ( ($line =~ /^PREFIX_DB_database/) && ($CLIDB_database < 1) ) + {$PREFIX_DB_database = $line; $PREFIX_DB_database =~ s/.*=//gi;} + if ( ($line =~ /^PREFIX_DB_user/) && ($CLIDB_user < 1) ) + {$PREFIX_DB_user = $line; $PREFIX_DB_user =~ s/.*=//gi;} + if ( ($line =~ /^PREFIX_DB_pass/) && ($CLIDB_pass < 1) ) + {$PREFIX_DB_pass = $line; $PREFIX_DB_pass =~ s/.*=//gi;} + if ( ($line =~ /^PREFIX_DB_port/) && ($CLIDB_port < 1) ) + {$PREFIX_DB_port = $line; $PREFIX_DB_port =~ s/.*=//gi;} + $i++; + } +#;;;;;;;;;;;; + + +$secX = time(); +$MT[0]=''; + +$list_id=''; +$cellphone_list_id=''; +$landline_list_id=''; +$invalid_list_id=''; +$invalid=0; +$cellphone=0; +$landline=0; + +### begin parsing run-time options ### +if (length($ARGV[0])>1) + { + $i=0; + while ($#ARGV >= $i) + { + $args = "$args $ARGV[$i]"; + $i++; + } + + if ($args =~ /--help/i) + { + print "allowed run time options:\n"; + print " [--test] = test\n"; + print " [--quiet] = supress all normal output\n"; + print " [--debug] = verbose debug messages\n"; + print " [--debugX] = extra verbose debug messages\n"; + print " [--user=XXX] = system user for lookups\n"; + print " [--pass=XXX] = system password for lookups\n"; + print " [--list-id=XXX] = list(s) that you want to filter, double-dash-delimited if more than one: 111--222\n"; + print " double-dash-delimited if more than one: 111--222\n"; + print " or you can use ---ALL--- for all lists in the system\n"; + print " [--cellphone-list-id=XXX] = list that you want to move cellphones into\n"; + print " [--landline-list-id=XXX] = OPTIONAL, list that you want to move landline phones into\n"; + print " [--invalid-list-id=XXX] = OPTIONAL, list that you want to move invalid prefix phone numbers into\n"; + print " [--vl-field-update=XXX] = OPTIONAL, field that you want to update with the phone type information\n"; + print "\n"; + exit; + } + else + { + if ($args =~ /--quiet/i) + { + $Q=1; + } + if ($args =~ /--debug/i) + { + $DB=1; + } + if ($args =~ /--debugX/i) + { + $DBX=1; + } + if ($args =~ /--output-to-db/i) + { + $output_to_db=1; + } + if ($args =~ /--db-output-code=/i) + { + @data_in = split(/--db-output-code=/,$args); + $db_output_code = $data_in[1]; + $db_output_code =~ s/ .*//gi; + if ($DB > 0) {print "\n----- DB OUTPUT CODE: $db_output_code -----\n\n";} + } + if ($args =~ /--test/i) + { + $TEST=1; + } + if ($args =~ /--user=/i) + { + @data_in = split(/--user=/,$args); + $user = $data_in[1]; + $user =~ s/ .*//gi; + if ($DB > 0) {print "\n----- USER: $user -----\n\n";} + } + if ($args =~ /--pass=/i) + { + @data_in = split(/--pass=/,$args); + $pass = $data_in[1]; + $pass =~ s/ .*//gi; + if ($DB > 0) {print "\n----- PASS: XXXX -----\n\n";} + } + if ($args =~ /--list-id=/i) + { + @data_in = split(/--list-id=/,$args); + $list_id = $data_in[1]; + $list_id =~ s/ .*//gi; + if ($list_id =~ /---ALL---/) + { + $list_idSQL = ''; + } + else + { + if ($list_id =~ /--/) + { + $list_idTEMP = $list_id; + $list_idTEMP =~ s/--/','/gi; + $list_idSQL = "where list_id IN('$list_idTEMP')"; + } + else + { + $list_idSQL = "where list_id='$list_id'"; + } + } + if ($DB > 0) {print "\n----- LIST ID: $list_id ($list_idSQL) -----\n\n";} + } + if ($args =~ /--cellphone-list-id=/i) + { + @data_in = split(/--cellphone-list-id=/,$args); + $cellphone_list_id = $data_in[1]; + $cellphone_list_id =~ s/ .*//gi; + if ($DB > 0) {print "\n----- CELLPHONE LIST ID: $cellphone_list_id -----\n\n";} + } + if ($args =~ /--landline-list-id=/i) + { + @data_in = split(/--landline-list-id=/,$args); + $landline_list_id = $data_in[1]; + $landline_list_id =~ s/ .*//gi; + if ($DB > 0) {print "\n----- LANDLINE LIST ID: $landline_list_id -----\n\n";} + } + if ($args =~ /--invalid-list-id=/i) + { + @data_in = split(/--invalid-list-id=/,$args); + $invalid_list_id = $data_in[1]; + $invalid_list_id =~ s/ .*//gi; + if ($DB > 0) {print "\n----- INVALID LIST ID: $invalid_list_id -----\n\n";} + } + if ($args =~ /--vl-field-update=/i) + { + @data_in = split(/--vl-field-update=/,$args); + $vl_field_update = $data_in[1]; + $vl_field_update =~ s/ .*//gi; + if ($DB > 0) {print "\n----- VL FIELD UPDATE: $vl_field_update -----\n\n";} + } + } + } +else + { + print "no command line options set\n"; + exit; + } +# 107104 +if (length($list_id)<2) + { + print "list-id option must be set for this script to run: |$list_id|\n"; + exit; + } +### end parsing run-time options ### + +# Customized Variables +$server_ip = $VARserver_ip; # Asterisk server IP + +if (!$VARDB_port) {$VARDB_port='3306';} + +use DBI; +$dbh = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") + or die "Couldn't connect to database: " . DBI->errstr; +$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass") + or die "Couldn't connect to database: " . DBI->errstr; + +### connect to phone type prefix DB +$dbhN = DBI->connect("DBI:mysql:$PREFIX_DB_database:$PREFIX_DB_server:$PREFIX_DB_port", "$PREFIX_DB_user", "$PREFIX_DB_pass") + or die "Couldn't connect to database: " . DBI->errstr; + +if (!%six_digit_wireless_hash) {&CompilePrefixHashes;} + +($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + +@lead_ids=@MT; +@phones=@MT; +$stmtA = "SELECT lead_id,phone_number from vicidial_list $list_idSQL;"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; +$rec_count=0; +if ($DB) {print "LEADS FOUND IN LIST $list_id: |$sthArows|\n";} +if ($DBX) {print "|$stmtA|\n";} +while ($sthArows > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $lead_ids[$rec_count] = $aryA[0]; + $phones[$rec_count] = $aryA[1]; + $rec_count++; + + if ($DB > 0) + { + if ($rec_count =~ /100$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /200$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /300$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /400$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /500$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /600$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /700$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /800$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /900$/i) {print STDERR " * $rec_count\r";} + if ($rec_count =~ /000$/i) {print STDERR " * $rec_count\r";} + } + } + +if ($DB) {print "STARTING LOOKUP OF NANPA PHONE TYPE, ($rec_count records)\n";} +$end_time=time; +if (!$Q) {print "Pre-scrub Elapsed time: ".($end_time-$start_time)." sec\n\n\n";} + +$rec_count=0; +$batch_count=0; +$batch_phones=''; +# open(STORAGE, "> test_nanpa.txt"); +%type_hash=(); +while ($sthArows > $rec_count) + { + $rec_next = ($rec_count + 1); + if ( ($batch_count < 1000) && ($rec_next < $sthArows) ) + { +# $batch_phones .= $phones[$rec_count] . '\|'; + $batch_count++; + } + else + { +# $batch_phones .= $phones[$rec_count]; + $secTEMP = time(); + $batch_count=0; + } + + # NANPA prefix check + $type='I'; + if ( (length($phones[$rec_count])>9) && (length($phones[$rec_count])<11) ) + { + $pre4=substr($phones[$rec_count],0,4); + $pre5=substr($phones[$rec_count],0,5); + $pre6=substr($phones[$rec_count],0,6); + $pre7=substr($phones[$rec_count],0,7); + if ($four_digit_prefix_hash{$pre4}) + { + if ($four_digit_prefix_hash{$pre4} ne "S") + { + $type="C"; + Wireless_to_Wired($phones[$rec_count]); + } + else + { + $type="S"; + Wired_to_Wireless($phones[$rec_count]); + } + } + elsif ($five_digit_prefix_hash{$pre5}) + { + if ($five_digit_prefix_hash{$pre5} ne "S") + { + $type="C"; + Wireless_to_Wired($phones[$rec_count]); + } + else + { + $type="S"; + Wired_to_Wireless($phones[$rec_count]); + } + } + elsif ($six_digit_prefix_hash{$pre6}) + { + if ($six_digit_prefix_hash{$pre6} ne "S") + { + $type="C"; + Wireless_to_Wired($phones[$rec_count]); + } + else + { + $type="S"; + Wired_to_Wireless($phones[$rec_count]); + } + } + elsif ($seven_digit_prefix_hash{$pre7}) + { + if ($seven_digit_prefix_hash{$pre7} ne "S") + { + $type="C"; + Wireless_to_Wired($phones[$rec_count]); + } + else + { + $type="S"; + Wired_to_Wireless($phones[$rec_count]); + } + } + } + # print STORAGE "$phones[$rec_count]|$type\n"; + + #### CHECK IF 1,000 TYPES have been compiled ##### + $type_hash{$type}.=$lead_ids[$rec_count].","; + @lead_count=($type_hash{$type}=~/,/g); + if (@lead_count==1000) + { + $stmtA=""; + $type_hash{$type}=~s/,$//; + if ( ($type =~ /I/) && (length($invalid_list_id) > 1) ) + {$stmtA = "UPDATE vicidial_list SET list_id=$invalid_list_id where lead_id in ($type_hash{$type});";} + if ( ($type =~ /C/) && (length($cellphone_list_id) > 1) ) + {$stmtA = "UPDATE vicidial_list SET list_id=$cellphone_list_id where lead_id in ($type_hash{$type});";} + if ( ($type =~ /S/) && (length($landline_list_id) > 1) ) + {$stmtA = "UPDATE vicidial_list SET list_id=$landline_list_id where lead_id in ($type_hash{$type});";} + if (length($stmtA)>0) + { + if($DBX){print STDERR "\n|$stmtA|$phones[$temp_rec]|\n";} + $affected_rows = $dbhA->do($stmtA); + # print STORAGE $stmtA."\n"; + if($DBX){print STDERR "|$affected_rows records changed|\n";} + } + + if ( (length($vl_field_update)>2) && ($TEST < 1) ) + { + $stmtA = "UPDATE vicidial_list SET $vl_field_update='$type' where lead_id in ($type_hash{$type});"; + if($DBX){print STDERR "\n|$stmtA|$phones[$temp_rec]|\n";} + $affected_rows = $dbhA->do($stmtA); + # print STORAGE $stmtA."\n"; + if($DBX){print STDERR "|$affected_rows records changed|\n";} + } + $type_hash{$type}=""; + } + ################################################## + + $rec_count++; + } + +#### Update remaining leads to the appropriate type ##### +foreach $type (keys %type_hash) + { + @lead_count=($type_hash{$type}=~/,/g); + + $stmtA=""; + if (@lead_count>0) + { + $type_hash{$type}=~s/,$//; + if ( ($type =~ /I/) && (length($invalid_list_id) > 1) ) + {$stmtA = "UPDATE vicidial_list SET list_id=$invalid_list_id where lead_id in ($type_hash{$type});";} + if ( ($type =~ /C/) && (length($cellphone_list_id) > 1) ) + {$stmtA = "UPDATE vicidial_list SET list_id=$cellphone_list_id where lead_id in ($type_hash{$type});";} + if ( ($type =~ /S/) && (length($landline_list_id) > 1) ) + {$stmtA = "UPDATE vicidial_list SET list_id=$landline_list_id where lead_id in ($type_hash{$type});";} + if (length($stmtA)>0) + { + if($DBX){print STDERR "\n|$stmtA|$phones[$temp_rec]|\n";} + $affected_rows = $dbhA->do($stmtA); + # print STORAGE $stmtA."\n"; + if($DBX){print STDERR "|$affected_rows records changed|\n";} + } + + if ( (length($vl_field_update)>2) && ($TEST < 1) ) + { + $stmtA = "UPDATE vicidial_list SET $vl_field_update='$type' where lead_id in ($type_hash{$type});"; + if($DBX){print STDERR "\n|$stmtA|$phones[$temp_rec]|\n";} + $affected_rows = $dbhA->do($stmtA); + # print STORAGE $stmtA."\n"; + if($DBX){print STDERR "|$affected_rows records changed|\n";} + } + $type_hash{$type}=""; + } + } +######################################################### + +$end_time=time; +if (!$Q) {print "TOTAL Elapsed time: ".($end_time-$start_time)." sec\n\n";} + +### +sub Wired_to_Wireless { + $phone=$_[0]; + $wtw6=substr($phone,0,6); + $wtw7=substr($phone,0,7); + $wtw8=substr($phone,0,8); + $wtw9=substr($phone,0,9); + + ## May be faster if you do one giant if with "or" for each hash + + if ($six_digit_wireless_hash{$wtw6}) { + $type="C"; + } elsif ($seven_digit_wireless_hash{$wtw7}) { + $type="C"; + } elsif ($eight_digit_wireless_hash{$wtw8}) { + $type="C"; + } elsif ($nine_digit_wireless_hash{$wtw9}) { + $type="C"; + } elsif ($ten_digit_wireless_hash{$phone}) { + $type="C"; + } +} + +sub Wireless_to_Wired { + $phone=$_[0]; + $wtw6=substr($phone,0,6); + $wtw7=substr($phone,0,7); + $wtw8=substr($phone,0,8); + $wtw9=substr($phone,0,9); + + ## May be faster if you do one giant if with "or" for each hash + + if ($six_digit_wired_hash{$wtw6}) { + $type="S"; + } elsif ($seven_digit_wired_hash{$wtw7}) { + $type="S"; + } elsif ($eight_digit_wired_hash{$wtw8}) { + $type="S"; + } elsif ($nine_digit_wired_hash{$wtw9}) { + $type="S"; + } elsif ($ten_digit_wired_hash{$phone}) { + $type="S"; + } +} + +### Makes a group of hashes to do a quicker check than querying a database +sub CompilePrefixHashes { + $start_time=time; + + $exc_clause=""; + $exc_clause_prefix=""; + $ct_stmt="select count(*), count(distinct ac_prefix) from nanpa_prefix_exchanges_fast;"; + $ct_rslt=$dbhN->prepare($ct_stmt); + $ct_rslt->execute(); + @ct_row=$ct_rslt->fetchrow_array; + if ($ct_row[0]==$ct_row[1]) { + $stmt="select substr(ac_prefix,1,4) as prefix, type, count(*) as ct from nanpa_prefix_exchanges_fast group by prefix, type order by ct desc"; + $rslt=$dbhN->prepare($stmt); + $rslt->execute(); + %four_digit_prefix_hash=(); + $current_time=time; + $exc_clause4="substr(ac_prefix,1,4) not in ("; + if ($DB==1) {print "4-digit check complete. Elapsed time: ".($current_time-$start_time)." sec\n";} + while (@row=$rslt->fetchrow_array) { + if ($row[2]==1000) { + $exc_clause4.="$row[0],"; + $four_digit_prefix_hash{$row[0]}=$row[1]; + } else { + last; + } + } + $exc_clause4=~s/,$//gi; + $exc_clause4.=")"; + if (length($exc_clause4)<35) { + $exc_clause4=""; + } else { + $exc_clause_prefix=" where "; + $exc_clause=$exc_clause4; + } + if ($DB==1) {print "Prefixes: ".scalar(keys %four_digit_prefix_hash)."\n"; } + + $stmt="select substr(ac_prefix,1,5) as prefix, type, count(*) as ct from nanpa_prefix_exchanges_fast ".$exc_clause_prefix.$exc_clause." group by prefix, type order by ct desc"; + $rslt=$dbhN->prepare($stmt); + $rslt->execute(); + %five_digit_prefix_hash=(); + $current_time=time; + $exc_clause5="substr(ac_prefix,1,5) not in ("; + if ($DB==1) {print "5-digit check complete. Elapsed time: ".($current_time-$start_time)." sec\n";} + while (@row=$rslt->fetchrow_array) { + $ch4=substr($row[0],0,4); + if ($row[2]==100 && !$four_digit_prefix_hash{$ch4}) { + $exc_clause5.="$row[0],"; + $five_digit_prefix_hash{$row[0]}=$row[1]; + } else { + last; + } + } + $exc_clause5=~s/,$//gi; + $exc_clause5.=")"; + if (length($exc_clause5)<35) { + $exc_clause5=""; + } else { + $exc_clause_prefix=" where "; + $exc_clause.=" and $exc_clause5"; + } + if ($DB==1) {print "Prefixes: ".scalar(keys %five_digit_prefix_hash)."\n";} + $exc_clause=~s/^\sand\s//gi; + + $stmt="select substr(ac_prefix,1,6) as prefix, type, count(*) as ct from nanpa_prefix_exchanges_fast ".$exc_clause_prefix.$exc_clause." group by prefix, type order by ct desc"; + $rslt=$dbhN->prepare($stmt); + $rslt->execute(); + %six_digit_prefix_hash=(); + $current_time=time; + $exc_clause6="substr(ac_prefix,1,6) not in ("; + if ($DB==1) {print "6-digit check complete. Elapsed time: ".($current_time-$start_time)." sec\n";} + while (@row=$rslt->fetchrow_array) { + $ch4=substr($row[0],0,4); + $ch5=substr($row[0],0,5); + if ($row[2]==10 && !$four_digit_prefix_hash{$ch4} && !$five_digit_prefix_hash{$ch5}) { + $exc_clause6.="$row[0],"; + $six_digit_prefix_hash{$row[0]}=$row[1]; + } else { + last; + } + } + $exc_clause6=~s/,$//gi; + $exc_clause6.=")"; + if (length($exc_clause6)<35) { + $exc_clause6=""; + } else { + $exc_clause_prefix=" where "; + $exc_clause.=" and $exc_clause6"; + } + if ($DB==1) {print "Prefixes: ".scalar(keys %six_digit_prefix_hash)."\n";} + $exc_clause=~s/^\sand\s//gi; + + $stmt="select ac_prefix, type, count(*) as ct from nanpa_prefix_exchanges_fast ".$exc_clause_prefix.$exc_clause." group by ac_prefix, type order by ct desc"; + $rslt=$dbhN->prepare($stmt); + $rslt->execute(); + %seven_digit_prefix_hash=(); + $current_time=time; + if ($DB==1) {print "7-digit check complete. Elapsed time: ".($current_time-$start_time)." sec\n";} + while (@row=$rslt->fetchrow_array) { + $ch4=substr($row[0],0,4); + $ch5=substr($row[0],0,5); + $ch6=substr($row[0],0,6); + if (!$four_digit_prefix_hash{$ch4} && !$five_digit_prefix_hash{$ch5} && !$six_digit_prefix_hash{$ch6}) { + $seven_digit_prefix_hash{$row[0]}=$row[1]; + } else { + last; + } + } + if ($DB==1) {print "Prefixes: ".scalar(keys %seven_digit_prefix_hash)."\n";} + } + + + $stmt="select substr(phone,1,6) as prefix, count(*) as ct from nanpa_wired_to_wireless group by prefix order by ct desc"; + $rslt=$dbhN->prepare($stmt); + $rslt->execute(); + %six_digit_wireless_hash=(); + $current_time=time; + $exc_clause=""; + $exc_clause_prefix=""; + $exc_clause6="substr(phone,1,6) not in ("; + if ($DB==1) {print "6-digit check complete. Elapsed time: ".($current_time-$start_time)." sec\n";} + while (@row=$rslt->fetchrow_array) { + if ($row[1]==10000) { + $exc_clause6.="$row[0],"; + $six_digit_wireless_hash{$row[0]}++; + } else { + last; + } + } + $exc_clause6=~s/,$//gi; + $exc_clause6.=")"; + if (length($exc_clause6)<30) { + $exc_clause6=""; + } else { + $exc_clause_prefix=" where "; + $exc_clause=$exc_clause6; + } + if ($DB==1) {print "Prefixes: ".scalar(keys %six_digit_wireless_hash)."\n"; } + + + $stmt="select substr(phone,1,7) as prefix, count(*) as ct from nanpa_wired_to_wireless ".$exc_clause_prefix.$exc_clause." group by prefix order by ct desc"; + $rslt=$dbhN->prepare($stmt); + $rslt->execute(); + %seven_digit_wireless_hash=(); + $current_time=time; + $exc_clause7="substr(phone,1,7) not in ("; + if ($DB==1) {print "7-digit check complete. Elapsed time: ".($current_time-$start_time)." sec\n";} + while (@row=$rslt->fetchrow_array) { + $ch6=substr($row[0],0,6); + if ($row[1]==1000 && !$six_digit_wireless_hash{$ch6}) { + $exc_clause7.="$row[0],"; + $seven_digit_wireless_hash{$row[0]}++; + } else { + last; + } + } + $exc_clause7=~s/,$//gi; + $exc_clause7.=")"; + if (length($exc_clause7)<30) { + $exc_clause7=""; + } else { + $exc_clause_prefix=" where "; + $exc_clause.=" and $exc_clause7"; + } + if ($DB==1) {print "Prefixes: ".scalar(keys %seven_digit_wireless_hash)."\n";} + $exc_clause=~s/^\sand\s//gi; + + $stmt="select substr(phone,1,8) as prefix, count(*) as ct from nanpa_wired_to_wireless ".$exc_clause_prefix.$exc_clause." group by prefix order by ct desc"; + $rslt=$dbhN->prepare($stmt); + $rslt->execute(); + %eight_digit_wireless_hash=(); + $current_time=time; + $exc_clause8="substr(phone,1,8) not in ("; + if ($DB==1) {print "8-digit check complete. Elapsed time: ".($current_time-$start_time)." sec\n";} + while (@row=$rslt->fetchrow_array) { + $ch6=substr($row[0],0,6); + $ch7=substr($row[0],0,7); + if ($row[1]==100 && !$six_digit_wireless_hash{$ch6} && !$seven_digit_wireless_hash{$ch7}) { + $exc_clause8.="$row[0],"; + $eight_digit_wireless_hash{$row[0]}++; + } else { + last; + } + } + $exc_clause8=~s/,$//gi; + $exc_clause8.=")"; + if (length($exc_clause8)<30) { + $exc_clause8=""; + } else { + $exc_clause_prefix=" where "; + $exc_clause.=" and $exc_clause8"; + } + if ($DB==1) {print "Prefixes: ".scalar(keys %eight_digit_wireless_hash)."\n";} + $exc_clause=~s/^\sand\s//gi; + + $stmt="select substr(phone,1,9) as prefix, count(*) as ct from nanpa_wired_to_wireless ".$exc_clause_prefix.$exc_clause." group by prefix order by ct desc"; + $rslt=$dbhN->prepare($stmt); + $rslt->execute(); + %nine_digit_wireless_hash=(); + $current_time=time; + $exc_clause9="substr(phone,1,9) not in ("; + if ($DB==1) {print "9-digit check complete. Elapsed time: ".($current_time-$start_time)." sec\n";} + while (@row=$rslt->fetchrow_array) { + $ch6=substr($row[0],0,6); + $ch7=substr($row[0],0,7); + $ch8=substr($row[0],0,8); + if ($row[1]==10 && !$six_digit_wireless_hash{$ch6} && !$seven_digit_wireless_hash{$ch7} && !$eight_digit_wireless_hash{$ch8}) { + $exc_clause9.="$row[0],"; + $nine_digit_wireless_hash{$row[0]}++; + } else { + last; + } + } + $exc_clause9=~s/,$//gi; + $exc_clause9.=")"; + if (length($exc_clause9)<30) { + $exc_clause9=""; + } else { + $exc_clause_prefix=" where "; + $exc_clause.=" and $exc_clause9"; + } + if ($DB==1) {print "Prefixes: ".scalar(keys %nine_digit_wireless_hash)."\n";} + + $stmt="select phone from nanpa_wired_to_wireless ".$exc_clause_prefix.$exc_clause; + $rslt=$dbhN->prepare($stmt); + $rslt->execute(); + %ten_digit_wireless_hash=(); + while (@row=$rslt->fetchrow_array) { + $ch6=substr($row[0],0,6); + $ch7=substr($row[0],0,7); + $ch8=substr($row[0],0,8); + $ch9=substr($row[0],0,9); + if (!$six_digit_wireless_hash{$ch6} && !$seven_digit_wireless_hash{$ch7} && !$eight_digit_wireless_hash{$ch8} && !$nine_digit_wireless_hash{$ch9}) { + $ten_digit_wireless_hash{$row[0]}++; + } + } + if ($DB==1) {print "10-digit prefixes: ".scalar(keys %ten_digit_wireless_hash)."\n\n";} + + ########################################### + + $stmt="select substr(phone,1,6) as prefix, count(*) as ct from nanpa_wireless_to_wired group by prefix order by ct desc"; + $rslt=$dbhN->prepare($stmt); + $rslt->execute(); + %six_digit_wired_hash=(); + $current_time=time; + $exc_clause=""; + $exc_clause_prefix=""; + $exc_clause6="substr(phone,1,6) not in ("; + if ($DB==1) {print "6-digit check complete. Elapsed time: ".($current_time-$start_time)." sec\n";} + while (@row=$rslt->fetchrow_array) { + if ($row[1]==10000) { + $exc_clause6.="$row[0],"; + $six_digit_wired_hash{$row[0]}++; + } else { + last; + } + } + $exc_clause6=~s/,$//gi; + $exc_clause6.=")"; + if (length($exc_clause6)<30) { + $exc_clause6=""; + } else { + $exc_clause_prefix=" where "; + $exc_clause=$exc_clause6; + } + if ($DB==1) {print "Prefixes: ".scalar(keys %six_digit_wired_hash)."\n";} + + + $stmt="select substr(phone,1,7) as prefix, count(*) as ct from nanpa_wireless_to_wired ".$exc_clause_prefix.$exc_clause." group by prefix order by ct desc"; + $rslt=$dbhN->prepare($stmt); + $rslt->execute(); + %seven_digit_wired_hash=(); + $current_time=time; + $exc_clause7="substr(phone,1,7) not in ("; + if ($DB==1) {print "7-digit check complete. Elapsed time: ".($current_time-$start_time)." sec\n";} + while (@row=$rslt->fetchrow_array) { + $ch6=substr($row[0],0,6); + if ($row[1]==1000 && !$six_digit_wired_hash{$ch6}) { + $exc_clause7.="$row[0],"; + $seven_digit_wired_hash{$row[0]}++; + } else { + last; + } + } + $exc_clause7=~s/,$//gi; + $exc_clause7.=")"; + if (length($exc_clause7)<30) { + $exc_clause7=""; + } else { + $exc_clause_prefix=" where "; + $exc_clause.=" and $exc_clause7"; + } + if ($DB==1) {print "Prefixes: ".scalar(keys %seven_digit_wired_hash)."\n";} + $exc_clause=~s/^\sand\s//gi; + + $stmt="select substr(phone,1,8) as prefix, count(*) as ct from nanpa_wireless_to_wired ".$exc_clause_prefix.$exc_clause." group by prefix order by ct desc"; + $rslt=$dbhN->prepare($stmt); + $rslt->execute(); + %eight_digit_wired_hash=(); + $current_time=time; + $exc_clause8="substr(phone,1,8) not in ("; + if ($DB==1) {print "8-digit check complete. Elapsed time: ".($current_time-$start_time)." sec\n";} + while (@row=$rslt->fetchrow_array) { + $ch6=substr($row[0],0,6); + $ch7=substr($row[0],0,7); + if ($row[1]==100 && !$six_digit_wired_hash{$ch6} && !$seven_digit_wired_hash{$ch7}) { + $exc_clause8.="$row[0],"; + $eight_digit_wired_hash{$row[0]}++; + } else { + last; + } + } + $exc_clause8=~s/,$//gi; + $exc_clause8.=")"; + if (length($exc_clause8)<30) { + $exc_clause8=""; + } else { + $exc_clause_prefix=" where "; + $exc_clause.=" and $exc_clause8"; + } + if ($DB==1) {print "Prefixes: ".scalar(keys %eight_digit_wired_hash)."\n";} + $exc_clause=~s/^\sand\s//gi; + + $stmt="select substr(phone,1,9) as prefix, count(*) as ct from nanpa_wireless_to_wired ".$exc_clause_prefix.$exc_clause." group by prefix order by ct desc"; + $rslt=$dbhN->prepare($stmt); + $rslt->execute(); + %nine_digit_wired_hash=(); + $current_time=time; + $exc_clause9="substr(phone,1,9) not in ("; + if ($DB==1) {print "9-digit check complete. Elapsed time: ".($current_time-$start_time)." sec\n";} + while (@row=$rslt->fetchrow_array) { + $ch6=substr($row[0],0,6); + $ch7=substr($row[0],0,7); + $ch8=substr($row[0],0,8); + if ($row[1]==10 && !$six_digit_wired_hash{$ch6} && !$seven_digit_wired_hash{$ch7} && !$eight_digit_wired_hash{$ch8}) { + $exc_clause9.="$row[0],"; + $nine_digit_wired_hash{$row[0]}++; + } else { + last; + } + } + $exc_clause9=~s/,$//gi; + $exc_clause9.=")"; + if (length($exc_clause9)<30) { + $exc_clause9=""; + } else { + $exc_clause_prefix=" where "; + $exc_clause.=" and $exc_clause9"; + } + if ($DB==1) {print "Prefixes: ".scalar(keys %nine_digit_wired_hash)."\n";} + + $stmt="select phone from nanpa_wireless_to_wired ".$exc_clause_prefix.$exc_clause; + $rslt=$dbhN->prepare($stmt); + $rslt->execute(); + %ten_digit_wired_hash=(); + while (@row=$rslt->fetchrow_array) { + $ch6=substr($row[0],0,6); + $ch7=substr($row[0],0,7); + $ch8=substr($row[0],0,8); + $ch9=substr($row[0],0,9); + if (!$six_digit_wired_hash{$ch6} && !$seven_digit_wired_hash{$ch7} && !$eight_digit_wired_hash{$ch8} && !$nine_digit_wired_hash{$ch9}) { + $ten_digit_wired_hash{$row[0]}++; + } + } + if ($DB==1) {print "10-digit prefixes: ".scalar(keys %ten_digit_wired_hash)."\n";} + + + $end_time=time; + if (!$Q) {print "Elapsed time: ".($end_time-$start_time)." sec\n\n\n";} +} diff --git a/agc_2-X/trunk/docs/CELLPHONE_USA_TCPA_FCC_COMPLIANCE.txt b/agc_2-X/trunk/docs/CELLPHONE_USA_TCPA_FCC_COMPLIANCE.txt new file mode 100644 index 00000000..780ac231 --- /dev/null +++ b/agc_2-X/trunk/docs/CELLPHONE_USA_TCPA_FCC_COMPLIANCE.txt @@ -0,0 +1,80 @@ +CELLPHONE FILTERING DOC Started: 2013-09-20 Updated: 2013-09-20 + +We have received many inquiries from clients about the impending FCC deadline of October 16th, 2013 to stop auto-dialing cellphones in the USA unless you have "express consent" from the person you are calling. This document is a summary of what this means to businesses and organizations, and goes over how they can make sure they are in compliance depending on their interpretation of the regulatory language. + +First, here is a good summary of what the changes are, and what the definition of terms are: +http://www.copilevitz-canter.com/resources/articles/upcoming-fcc-rule-changes-regarding-express-consent-to-call-cell-phones + +In summary, the new regulations ban any calls to cellphones in the USA by "automatic telephone dialing systems"(or ATDS) unless you have specifically received explicit written or audio recorded permission from the person(or spouse of the person) you are calling that you are allowed to call them on their cell phone through an auto-dialer. The vague definition of ATDS that the FCC uses is, + "equipment which has the capacity + (A) to store or produce telephone numbers to be called, using a random or sequential number generator; + and + (B) to dial such numbers". +This is such a broad definition that even a modern smartphone fits it's definition. But, the FCC also has said more recently that the basic function of an ATDS is “the capacity to dial numbers without human intervention”, which should pretty much exclude smartphones, as well as dialing systems where human intervention would be necessary for any calls to be placed, such as auto-dialers. + +It is important to mention that this regulatory change has no effect on automated calls to land lines. + +For our clients that have the strictest interpretation of the regulation change, we have added a programmatic feature that is non-editable in System Settings called "Disable Auto Dial" which is disabled by default. This feature was added on July 11, 2013 and is available in svn/trunk versions 1999 and higher. To enable or disable this feature, you have to issue a MySQL command through the command line mysql interface: + + $ mysql asterisk + mysql> UPDATE system_settings SET disable_auto_dial='1'; + mysql> quit + +Once this is done, the system will be incapable of automatically placing outbound calls. This includes dial methods using ADAPT and RATIO in campaigns. If this feature is enabled and you are using those dial methods, you will see this warning on the campaign modification screen: "Auto-dialing has been disabled on this system". If your system has this feature enabled, you should only be using the MANUAL and INBOUND_MAN campaign dial methods. + +The client that we added this feature for created a separate Vicidial system just for cellphone calling that has this feature enabled, so that they are using a separate system that is completely incapable of placing phone calls without human intervention. + + + +FILTERING CELLPHONES + +The next question we usually get after explaining all of this is, "How do I filter cellphones?". With number portability this has been made a much more complex task. There are companies that offer fee-based filtering services, like DNC.COM, which several of our clients use for this purpose, and can pre-filter leads before they are imported into Vicidial. It is important to mention that there is no 100% accurate lookup service for cell phones, but using an specialized service like DNC.COM is considered a best effort solution because you can get very close to that. + +We recently added several software components to the Vicidial codebase that allows for integration with DNC.COM's on-site cellphone filtering database service. If you subscribe to this service then you can download the data files nightly and have Vicidial scrub for cellphones on the entire system and/or manually scrub inactive lists through an administrative web page. More details on these processes are included below. + +Our NANPA list that is available for clients to purchase on vicidial.org also has the "Lata Type" definition for all North American phone number prefixes which will show phone prefix blocks that are land lines(S), cell phones(C), pagers(P) and mixed use(M). There is currently no filtering script included with Vicidial that uses this data, but it could be used with a custom script as a pre-filter before sending a list to an outside filtering company. It is important to mention that this IS NOT a compliance solution and IS NOT considered a best effort option to filter your number. Also, in our extensive testing, it is only 93% accurate at best in determining whether a phone number is really a cell phone. + +This is a good place to mention the penalties for calling a cellphone with an auto-dialer. The FCC fine is up to $16,000.00 per violation, with civil fines of up to $500.00 per call that can also be levied against the offender. + + + +DNC.COM INTEGRATION FEATURES IN VICIDIAL + +Here is a list of scripts that we have added in order to integrate with DNC.COM's cellphone filtering database service. + +bin/nanpa_type_populate.pl - +Requires "Net::SFTP::Foreign" and "IO::Pty" CPAN modules to run. Automatically goes to DNC.COM SFTP server and downloads the 3 required data files(Prefixes, Wired-to-wireless, Wireless-to-wired), then loads that data into database tables on the vicidial system to be used by the other scripts. This process should be set to run in the crontab every morning. + NOTE: before you can run this script, you will need to sftp into the dnc.com server first on the Linux command line, (sftp XXXX@sftp.dncscrub.com) + +bin/nanpa_type_preload.pl - +This script is designed to load all of the prefixes and portability data into RAM and run against your entire database to scrub it for cellphone numbers every night after the data is refreshed. It takes several minutes to initialize, but runs very fast after that. This process should be set to run in the crontab every morning AFTER thee populate script is finished running. + +bin/nanpa_type_filter.pl - +This script is designed to do one list or a few lists at a time, or the entire database on smaller systems. It works together with a PHP script to perform lookups of cellphones and updating vicidial_list records depending on settings + +www/vicidial/nanpa_type.php - +PHP script designed to return S = Land line, C = Cellphone, I = Invalid for one to hundreds of numbers passed in either an HTTP GET or POST form submission to it. Also requires valid manager user credentials on the host system for it to work. + +NOTE: To find the command line options for the Perl scripts above, just run them with the "--help" flag + + +These scripts need a /etc/vicidial_prefix.conf file on their server in order to run: + (example below shows local vicidial database repository) +# Database connection information +PREFIX_DB_server => 127.0.0.1 +PREFIX_DB_database => asterisk +PREFIX_DB_user => cron +PREFIX_DB_pass => 1234 +PREFIX_DB_port => 3306 + +# URL connection information +PREFIX_url => http://127.0.0.1/vicidial/nanpa_type.php +PREFIX_user => 6666 +PREFIX_pass => 1234 + +# SFTP login information +PREFIX_SFTP_server => sftp.dncscrub.com +PREFIX_SFTP_user => DEMOVICIDIAL +PREFIX_SFTP_pass => sampLepass +PREFIX_SFTP_port => 22 + diff --git a/agc_2-X/trunk/docs/REQUIRED_APPS_INSTALL.txt b/agc_2-X/trunk/docs/REQUIRED_APPS_INSTALL.txt index 5cf5b1c3..9f4379cb 100644 --- a/agc_2-X/trunk/docs/REQUIRED_APPS_INSTALL.txt +++ b/agc_2-X/trunk/docs/REQUIRED_APPS_INSTALL.txt @@ -89,6 +89,8 @@ install IO::Socket::SSL install MIME::Base64 install MIME::QuotedPrint install Crypt::Eksblowfish::Bcrypt +install IO::Pty +install Net::SFTP::Foreign quit @@ -340,7 +342,7 @@ install Net::Domain quit cd /usr/local -wget http://voxel.dl.sourceforge.net/project/mtop/mtop/v0.6.6/mtop-0.6.6.tar.gz +wget http://superb-dca2.dl.sourceforge.net/project/mtop/mtop/v0.6.6/mtop-0.6.6.tar.gz gunzip mtop-0.6.6.tar.gz tar xvf mtop-0.6.6.tar cd mtop-0.6.6 diff --git a/agc_2-X/trunk/docs/SCRATCH_INSTALL.txt b/agc_2-X/trunk/docs/SCRATCH_INSTALL.txt index d31b1790..b4e9a871 100644 --- a/agc_2-X/trunk/docs/SCRATCH_INSTALL.txt +++ b/agc_2-X/trunk/docs/SCRATCH_INSTALL.txt @@ -463,6 +463,8 @@ following modules first: (say YES if asked to install prerequisites) - install MIME::Base64 - install MIME::QuotedPrint - install Crypt::Eksblowfish::Bcrypt + - install IO::Pty + - install Net::SFTP::Foreign - then quit cpan, you are done 5. Go to http://asterisk.gnuinter.net/ and download the asterisk-perl module (backup link: http://download.vicidial.com/packages/asterisk-perl-0.08.tar.gz) diff --git a/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql b/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql index 7aafdcd5..360257b4 100644 --- a/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql +++ b/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql @@ -2931,6 +2931,48 @@ index (campaign_id), index (monitor_time) ) ENGINE=MyISAM; +CREATE TABLE nanpa_prefix_exchanges_master ( +areacode CHAR(3) default '', +prefix CHAR(4) default '', +source CHAR(1) default '', +type CHAR(1) default '', +tier VARCHAR(20) default '', +postal_code VARCHAR(20) default '', +new_areacode CHAR(3) default '', +tzcode VARCHAR(4) default '', +region CHAR(2) default '' +) ENGINE=MyISAM; + +CREATE TABLE nanpa_prefix_exchanges_fast ( +ac_prefix CHAR(7) default '', +type CHAR(1) default '' +) ENGINE=MyISAM; + +CREATE INDEX nanpaacprefix on nanpa_prefix_exchanges_fast (ac_prefix); + +CREATE TABLE nanpa_wired_to_wireless ( +phone CHAR(10) NOT NULL UNIQUE PRIMARY KEY +) ENGINE=MyISAM; + +CREATE TABLE nanpa_wireless_to_wired ( +phone CHAR(10) NOT NULL UNIQUE PRIMARY KEY +) ENGINE=MyISAM; + +CREATE TABLE vicidial_nanpa_filter_log ( +output_code VARCHAR(30) PRIMARY KEY NOT NULL, +status VARCHAR(20) default 'BEGIN', +server_ip VARCHAR(15) default '', +list_id TEXT, +start_time DATETIME, +update_time DATETIME, +user VARCHAR(20) default '', +leads_count BIGINT(14) default '0', +filter_count BIGINT(14) default '0', +status_line VARCHAR(255) default '', +script_output TEXT, +index (start_time) +) ENGINE=MyISAM; + ALTER TABLE vicidial_email_list MODIFY message text character set utf8; @@ -3170,4 +3212,4 @@ UPDATE vicidial_configuration set value='1766' where name='qc_database_version'; UPDATE system_settings set vdc_agent_api_active='1'; -UPDATE system_settings SET db_schema_version='1355',db_schema_update_date=NOW(); +UPDATE system_settings SET db_schema_version='1356',db_schema_update_date=NOW(); diff --git a/agc_2-X/trunk/extras/upgrade_2.8.sql b/agc_2-X/trunk/extras/upgrade_2.8.sql index e6545881..beba5540 100644 --- a/agc_2-X/trunk/extras/upgrade_2.8.sql +++ b/agc_2-X/trunk/extras/upgrade_2.8.sql @@ -66,3 +66,47 @@ UPDATE system_settings SET db_schema_version='1354',db_schema_update_date=NOW() ALTER TABLE vicidial_custom_leadloader_templates ADD template_statuses VARCHAR(255); UPDATE system_settings SET db_schema_version='1355',db_schema_update_date=NOW() where db_schema_version < 1355; + +CREATE TABLE nanpa_prefix_exchanges_master ( +areacode CHAR(3) default '', +prefix CHAR(4) default '', +source CHAR(1) default '', +type CHAR(1) default '', +tier VARCHAR(20) default '', +postal_code VARCHAR(20) default '', +new_areacode CHAR(3) default '', +tzcode VARCHAR(4) default '', +region CHAR(2) default '' +) ENGINE=MyISAM; + +CREATE TABLE nanpa_prefix_exchanges_fast ( +ac_prefix CHAR(7) default '', +type CHAR(1) default '' +) ENGINE=MyISAM; + +CREATE INDEX nanpaacprefix on nanpa_prefix_exchanges_fast (ac_prefix); + +CREATE TABLE nanpa_wired_to_wireless ( +phone CHAR(10) NOT NULL UNIQUE PRIMARY KEY +) ENGINE=MyISAM; + +CREATE TABLE nanpa_wireless_to_wired ( +phone CHAR(10) NOT NULL UNIQUE PRIMARY KEY +) ENGINE=MyISAM; + +CREATE TABLE vicidial_nanpa_filter_log ( +output_code VARCHAR(30) PRIMARY KEY NOT NULL, +status VARCHAR(20) default 'BEGIN', +server_ip VARCHAR(15) default '', +list_id TEXT, +start_time DATETIME, +update_time DATETIME, +user VARCHAR(20) default '', +leads_count BIGINT(14) default '0', +filter_count BIGINT(14) default '0', +status_line VARCHAR(255) default '', +script_output TEXT, +index (start_time) +) ENGINE=MyISAM; + +UPDATE system_settings SET db_schema_version='1356',db_schema_update_date=NOW() where db_schema_version < 1356; diff --git a/agc_2-X/trunk/translations/raw_translation_files/TO_BE_TRANSLATED_2.8.txt b/agc_2-X/trunk/translations/raw_translation_files/TO_BE_TRANSLATED_2.8.txt index 31cb8e07..fd221109 100644 --- a/agc_2-X/trunk/translations/raw_translation_files/TO_BE_TRANSLATED_2.8.txt +++ b/agc_2-X/trunk/translations/raw_translation_files/TO_BE_TRANSLATED_2.8.txt @@ -229,6 +229,7 @@ The duplicate options allow you to check for duplicate entries as you load the l Add inbound and outbound holiday rule|| Add outbound holiday rule|| If set to N, the calls will queue up, even if there are no agents logged in and set to take calls from this in-group|| +Active Voicemail Server is not set|| ########################## CHANGES TO EXISTING PHRASES IN ADMIN TRANSLATION diff --git a/agc_2-X/trunk/www/vicidial/NANPA_running_processes.php b/agc_2-X/trunk/www/vicidial/NANPA_running_processes.php new file mode 100644 index 00000000..b0616cc4 --- /dev/null +++ b/agc_2-X/trunk/www/vicidial/NANPA_running_processes.php @@ -0,0 +1,170 @@ + LICENSE: AGPLv2 +# +# This script shows running NANPA filter batch proccesses +# +# CHANGELOG: +# 130921-0756 - First build of script +# + +$version = '2.8-1'; +$build = '130921-0756'; +$startMS = microtime(); + +require("dbconnect_mysqli.php"); +require("functions.php"); + +$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; +$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; +$PHP_SELF=$_SERVER['PHP_SELF']; +if (isset($_GET["output_codes_to_display"])) {$output_codes_to_display=$_GET["output_codes_to_display"];} + elseif (isset($_POST["output_codes_to_display"])) {$output_codes_to_display=$_POST["output_codes_to_display"];} + +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db FROM system_settings;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {$MAIN.="$stmt\n";} +$qm_conf_ct = mysqli_num_rows($rslt); +if ($qm_conf_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $non_latin = $row[0]; + $outbound_autodial_active = $row[1]; + $slave_db_server = $row[2]; + $reports_use_slave_db = $row[3]; + } +##### END SETTINGS LOOKUP ##### +########################################### + +if ($non_latin < 1) + { + $PHP_AUTH_USER = preg_replace('/[^-_0-9a-zA-Z]/', '', $PHP_AUTH_USER); + $PHP_AUTH_PW = preg_replace('/[^-_0-9a-zA-Z]/', '', $PHP_AUTH_PW); + } +else + { + $PHP_AUTH_PW = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_PW); + $PHP_AUTH_USER = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_USER); + } + +$NOW_DATE = date("Y-m-d"); + +$user_auth=0; +$auth=0; +$reports_auth=0; +$qc_auth=0; +$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'QC',1); +if ($auth_message == 'GOOD') + {$user_auth=1;} + +if ($user_auth > 0) + { + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 7;"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $auth=$row[0]; + + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports > 0;"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $reports_auth=$row[0]; + + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 1 and qc_enabled > 0;"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $qc_auth=$row[0]; + + $reports_only_user=0; + $qc_only_user=0; + if ( ($reports_auth > 0) and ($auth < 1) ) + { + $ADD=999999; + $reports_only_user=1; + } + if ( ($qc_auth > 0) and ($reports_auth < 1) and ($auth < 1) ) + { + if ( ($ADD != '881') and ($ADD != '100000000000000') ) + { + $ADD=100000000000000; + } + $qc_only_user=1; + } + if ( ($qc_auth < 1) and ($reports_auth < 1) and ($auth < 1) ) + { + $VDdisplayMESSAGE = "You do not have permission to be here"; + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + } +else + { + $VDdisplayMESSAGE = "Login incorrect, please try again"; + if ($auth_message == 'LOCK') + { + $VDdisplayMESSAGE = "Too many login attempts, try again in 15 minutes"; + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); + Header("HTTP/1.0 401 Unauthorized"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; + exit; + } + +$oc_ct=count($output_codes_to_display); +$oc_SQL=""; +$url_str=""; + +for ($i=0; $i<$oc_ct; $i++) { + $oc_SQL.="'$output_codes_to_display[$i]',"; + $url_str.="output_codes_to_display[]=".$output_codes_to_display[$i]; +} +$oc_SQL=substr($oc_SQL, 0, -1); + +$process_stmt="select * from vicidial_nanpa_filter_log where output_code in ($oc_SQL) and status!='COMPLETED'"; +$process_rslt=mysqli_query($link, $process_stmt); + +if (mysqli_num_rows($process_rslt)>0) { +# echo ""; +# echo ""; +# echo "NANPA running processes"; +# echo ""; +# echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + while ($row=mysqli_fetch_array($process_rslt)) { + if ($bgcolor=="#9BB9FB") {$bgcolor="#B9CBFD";} else {$bgcolor='#9BB9FB';} + $row["script_output"]=preg_replace('/\n/', '
', $row["script_output"]); + echo ""; + echo ""; + } + echo "
Currently running NANPA scrubs
Start time"; + echo "Status"; + echo "Last updated"; + echo "Leads count"; + echo "Filter count"; + echo "Status line"; + echo "Last script output"; + echo "
$row[start_time]"; + echo "$row[status]"; + echo "$row[update_time]"; + echo "$row[leads_count]"; + echo "$row[filter_count]"; + echo "$row[status_line]"; + echo "$row[script_output]"; + echo "
"; +# echo ""; +# echo ""; +} +?> diff --git a/agc_2-X/trunk/www/vicidial/admin.php b/agc_2-X/trunk/www/vicidial/admin.php index 3b83bae8..5d6db6b6 100644 --- a/agc_2-X/trunk/www/vicidial/admin.php +++ b/agc_2-X/trunk/www/vicidial/admin.php @@ -3223,12 +3223,13 @@ else # 130711-2208 - Added SYSTEM SNAPSHOT STATS as new welcome screen, and added new # 130809-1410 - Small fixes for call times and holidays # 130824-2319 - Changed to mysqli PHP functions +# 130915-0045 - Added counts for new nanpa prefix type tables # # make sure you have added a user to the vicidial_users MySQL table with at least user_level 8 to access this page the first time -$admin_version = '2.8-410a'; -$build = '130824-2319'; +$admin_version = '2.8-411a'; +$build = '130915-0045'; $STARTtime = date("U"); $SQLdate = date("Y-m-d H:i:s"); @@ -32572,6 +32573,26 @@ if ($ADD==311111111111111) $row=mysqli_fetch_row($rslt); $vicidial_nanpa_prefix_codes_count = $row[0]; + $stmt="SELECT count(*) from nanpa_prefix_exchanges_master;"; + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $nanpa_prefix_exchanges_master_count = $row[0]; + + $stmt="SELECT count(*) from nanpa_prefix_exchanges_fast;"; + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $nanpa_prefix_exchanges_fast_count = $row[0]; + + $stmt="SELECT count(*) from nanpa_wired_to_wireless;"; + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $nanpa_wired_to_wireless_count = $row[0]; + + $stmt="SELECT count(*) from nanpa_wireless_to_wired;"; + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $nanpa_wireless_to_wired_count = $row[0]; + $stmt="SELECT sum(total_calls) from vicidial_daily_max_stats where stats_flag='OPEN' and stats_type!='TOTAL';"; $rslt=mysql_to_mysqli($stmt, $link); $stats_to_print = mysqli_num_rows($rslt); @@ -32752,7 +32773,7 @@ if ($ADD==311111111111111) echo "Install Date: $install_date\n"; $pcblinkB=''; $pcblinkE=''; if ($vicidial_phone_codes_count < 1000) {$pcblinkB=''; $pcblinkE='';} - echo "Phone Codes: $pcblinkB$vicidial_phone_codes_count - $vicidial_postal_codes_count - $vicidial_nanpa_prefix_codes_count$pcblinkE\n"; + echo "Phone Codes: $pcblinkB$vicidial_phone_codes_count - $vicidial_postal_codes_count - $vicidial_nanpa_prefix_codes_count$pcblinkE - $nanpa_prefix_exchanges_master_count - $nanpa_prefix_exchanges_fast_count - $nanpa_wired_to_wireless_count - $nanpa_wireless_to_wired_count\n"; echo "Today System Stats: $ALLtotal_calls - $ALLmax_inbound - $ALLmax_outbound - $ALLchannels_count - $ALLcalls_count - $ALLagent_count\n"; echo "Use Non-Latin: $NWB#settings-use_non_latin$NWE\n"; echo "Webroot Writable: $NWB#settings-webroot_writable$NWE\n"; @@ -36341,6 +36362,7 @@ if ($ADD==999994) echo "
  • Send a Call With Custom CID Page\n"; echo "
  • Speech Voice Lab Page\n"; echo "
  • Webphone Only Page\n"; + echo "
  • NANPA batch updater\n"; echo "\n
     \n"; } diff --git a/agc_2-X/trunk/www/vicidial/admin_NANPA_updater.php b/agc_2-X/trunk/www/vicidial/admin_NANPA_updater.php new file mode 100644 index 00000000..9b8fb5df --- /dev/null +++ b/agc_2-X/trunk/www/vicidial/admin_NANPA_updater.php @@ -0,0 +1,442 @@ + LICENSE: AGPLv2 +# +# This script is designed to launch NANPA filter batch proccesses through the +# triggering process +# +# CHANGELOG: +# 130919-1503 - First build of script +# + +$version = '2.8-1'; +$build = '130919-1503'; +$startMS = microtime(); + +require("dbconnect_mysqli.php"); +require("functions.php"); + +$server_ip=$WEBserver_ip; +$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; +$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; +$PHP_SELF=$_SERVER['PHP_SELF']; +if (isset($_GET["submit_form"])) {$submit_form=$_GET["submit_form"];} + elseif (isset($_POST["submit_form"])) {$submit_form=$_POST["submit_form"];} +if (isset($_GET["delete_trigger_id"])) {$delete_trigger_id=$_GET["delete_trigger_id"];} + elseif (isset($_POST["delete_trigger_id"])) {$delete_trigger_id=$_POST["delete_trigger_id"];} +if (isset($_GET["lists"])) {$lists=$_GET["lists"];} + elseif (isset($_POST["lists"])) {$lists=$_POST["lists"];} +if (isset($_GET["fields_to_update"])) {$fields_to_update=$_GET["fields_to_update"];} + elseif (isset($_POST["fields_to_update"])) {$fields_to_update=$_POST["fields_to_update"];} +if (isset($_GET["vl_field_update"])) {$vl_field_update=$_GET["vl_field_update"];} + elseif (isset($_POST["vl_field_update"])) {$vl_field_update=$_POST["vl_field_update"];} +if (isset($_GET["cellphone_list_id"])) {$cellphone_list_id=$_GET["cellphone_list_id"];} + elseif (isset($_POST["cellphone_list_id"])) {$cellphone_list_id=$_POST["cellphone_list_id"];} +if (isset($_GET["landline_list_id"])) {$landline_list_id=$_GET["landline_list_id"];} + elseif (isset($_POST["landline_list_id"])) {$landline_list_id=$_POST["landline_list_id"];} +if (isset($_GET["invalid_list_id"])) {$invalid_list_id=$_GET["invalid_list_id"];} + elseif (isset($_POST["invalid_list_id"])) {$invalid_list_id=$_POST["invalid_list_id"];} +if (isset($_GET["activation_delay"])) {$activation_delay=$_GET["activation_delay"];} + elseif (isset($_POST["activation_delay"])) {$activation_delay=$_POST["activation_delay"];} +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} + +$block_scheduling_while_running=0; + +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,active_voicemail_server FROM system_settings;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {$MAIN.="$stmt\n";} +$qm_conf_ct = mysqli_num_rows($rslt); +if ($qm_conf_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $non_latin = $row[0]; + $outbound_autodial_active = $row[1]; + $slave_db_server = $row[2]; + $reports_use_slave_db = $row[3]; + $active_voicemail_server = $row[4]; + } +##### END SETTINGS LOOKUP ##### +########################################### + +if ($non_latin < 1) + { + $PHP_AUTH_USER = preg_replace('/[^-_0-9a-zA-Z]/', '', $PHP_AUTH_USER); + $PHP_AUTH_PW = preg_replace('/[^-_0-9a-zA-Z]/', '', $PHP_AUTH_PW); + } +else + { + $PHP_AUTH_PW = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_PW); + $PHP_AUTH_USER = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_USER); + } + +$NOW_DATE = date("Y-m-d"); + +$user_auth=0; +$auth=0; +$reports_auth=0; +$qc_auth=0; +$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'QC',1); +if ($auth_message == 'GOOD') + {$user_auth=1;} + +if ($user_auth > 0) + { + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 7;"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $auth=$row[0]; + + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports > 0;"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $reports_auth=$row[0]; + + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 1 and qc_enabled > 0;"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $qc_auth=$row[0]; + + $reports_only_user=0; + $qc_only_user=0; + if ( ($reports_auth > 0) and ($auth < 1) ) + { + $ADD=999999; + $reports_only_user=1; + } + if ( ($qc_auth > 0) and ($reports_auth < 1) and ($auth < 1) ) + { + if ( ($ADD != '881') and ($ADD != '100000000000000') ) + { + $ADD=100000000000000; + } + $qc_only_user=1; + } + if ( ($qc_auth < 1) and ($reports_auth < 1) and ($auth < 1) ) + { + $VDdisplayMESSAGE = "You do not have permission to be here"; + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + } +else + { + $VDdisplayMESSAGE = "Login incorrect, please try again"; + if ($auth_message == 'LOCK') + { + $VDdisplayMESSAGE = "Too many login attempts, try again in 15 minutes"; + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); + Header("HTTP/1.0 401 Unauthorized"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; + exit; + } + +if (strlen($active_voicemail_server)<7) + { + echo "ERROR: Admin -> System Settings -> Active Voicemail Server is not set\n"; + exit; + } + +if ($delete_trigger_id) + { + $delete_stmt="delete from vicidial_process_triggers where trigger_id='$delete_trigger_id'"; + $delete_rslt=mysqli_query($link, $delete_stmt); + } + +$list_ct=count($lists); +if ($submit_form=="SUBMIT" && $list_ct>0 && (strlen($vl_field_update)>0 || strlen($cellphone_list_id)>0 || strlen($landline_list_id)>0 || strlen($invalid_list_id)>0) ) + { + for ($i=0; $i<$list_ct; $i++) + { + if ($lists[$i]=="---ALL---") + { + unset($lists); + #$lists[0]="---ALL---"; + $i=$list_ct; + + ### Added to make sure that if ALL are selected, it's all inactives. There is nothing in the actual NANPA filtering scripts that handle it + ### but it needs to be done + $j=0; + $stmt="SELECT list_id from vicidial_lists where active='N' order by list_id asc"; + $rslt=mysqli_query($link, $stmt); + while ($row=mysqli_fetch_array($rslt)) + { + $lists[$j]=$row[0]; + $j++; + } + } + } + $list_ct=count($lists); + + $cellphone_list_id=preg_replace('/[^0-9]/', '', $cellphone_list_id); + $landline_list_id=preg_replace('/[^0-9]/', '', $landline_list_id); + $invalid_list_id=preg_replace('/[^0-9]/', '', $invalid_list_id); + + $options="--user=$PHP_AUTH_USER --pass=$PHP_AUTH_PW "; + + $list_id_str=""; + for ($i=0; $i<$list_ct; $i++) + { + $list_id_str.=$lists[$i]."--"; + } + $list_id_str=substr($list_id_str, 0, -2); + $options.="--list-id=$list_id_str "; + + if (strlen($cellphone_list_id)>0) {$options.="--cellphone-list-id=$cellphone_list_id ";} + if (strlen($landline_list_id)>0) {$options.="--landline-list-id=$landline_list_id ";} + if (strlen($invalid_list_id)>0) {$options.="--invalid-list-id=$invalid_list_id ";} + if (strlen($vl_field_update)>0) {$options.="--vl-field-update=$vl_field_update ";} + $options=trim($options); + + $uniqueid=date("U").".".rand(1, 9999); + $ins_stmt="INSERT into vicidial_process_triggers (trigger_id, trigger_name, server_ip, trigger_time, trigger_run, user, trigger_lines) VALUES('NANPA_".$uniqueid."', 'NANPA updater SCREEN', '$active_voicemail_server', now()+INTERVAL $activation_delay MINUTE, '1', '$PHP_AUTH_USER', '/usr/share/astguiclient/nanpa_type_filter.pl --output-to-db $options')"; + $ins_rslt=mysqli_query($link, $ins_stmt); + } +header ("Content-type: text/html; charset=utf-8"); +if ($SSnocache_admin=='1') + { + header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 + header ("Pragma: no-cache"); // HTTP/1.0 + } + + +$schedule_stmt="SELECT *, sec_to_time(UNIX_TIMESTAMP(trigger_time)-UNIX_TIMESTAMP(now())) as time_until_execution from vicidial_process_triggers where trigger_name='NANPA updater SCREEN' and user='$PHP_AUTH_USER' and trigger_time>=now()"; +$schedule_rslt=mysqli_query($link, $schedule_stmt); + +$running_stmt="SELECT output_code from vicidial_nanpa_filter_log where user='$PHP_AUTH_USER' and status!='COMPLETED' order by output_code asc"; +$running_rslt=mysqli_query($link, $running_stmt); +if (mysqli_num_rows($running_rslt)>0) { + $iframe_url=""; + while ($run_row=mysqli_fetch_array($running_rslt)) { + $iframe_url.="&output_codes_to_display[]=".$run_row[0]; + } +} + +echo "\n"; +echo "\n"; +echo "\n"; +echo "\n"; +echo "\n"; +echo "\n"; +if ($SSnocache_admin=='1') + { + echo "\n"; + echo "\n"; + echo "\n"; + } +if ( ($SSadmin_modify_refresh > 1) and (preg_match("/^3/",$ADD)) ) + { + $modify_refresh_set=1; + if (preg_match("/^3/",$ADD)) {$modify_url = "$PHP_SELF?$QUERY_STRING";} + echo "\n"; + } +echo "ADMIN NANPA UPDATER"; +?> + +\n"; +$ADMIN=$PHP_SELF; +$short_header=1; + +echo "\n\n"; + +require("admin_header.php"); + +echo "
    "; +echo "
    "; + +if (mysqli_num_rows($schedule_rslt)>0 || (mysqli_num_rows($running_rslt)>0)) { + + if (mysqli_num_rows($schedule_rslt)>0) { + echo ""; + } + + if (mysqli_num_rows($running_rslt)>0) { + echo ""; + } +} + +############################################ + +if ( ( (mysqli_num_rows($schedule_rslt)>0) or (mysqli_num_rows($running_rslt)>0) ) and ($block_scheduling_while_running==1) ) + {$do_nothing=1;} +else + { + echo ""; + } +echo "
    "; + echo ""; + echo ""; + echo ""; + echo ""; + while ($row=mysqli_fetch_array($schedule_rslt)) { + $trigger_array=explode(" ", $row["trigger_lines"]); + $lists=""; + $vl_update_field=""; + $conversion_lists=""; + for ($q=1; $q"; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + echo "
    Your scheduled NANPA scrubs
    Date/time"; + echo "Lists"; + echo "Update field"; + echo "Conversion lists"; + echo " "; + echo "
    $row[trigger_time]
    ($row[time_until_execution] until run time)
    $lists$vl_update_field$conversion_listsDELETE
    "; + echo "
    "; + $iframe_url="NANPA_running_processes.php?"; + while ($run_row=mysqli_fetch_array($running_rslt)) { + $iframe_url.="output_codes_to_display[]=".$run_row[0]; + } + #echo "
    "; + echo "
    "; + echo ""; + echo ""; + echo "
    "; + + echo "
    "; + + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + echo "\n"; + + echo ""; + + echo "\n"; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo "
    NANPA scrub scheduler
    Inactive lists:
    \n"; + + $stmt="SELECT list_id, list_name from vicidial_lists where active='N' order by list_id asc"; + $rslt=mysqli_query($link, $stmt); + echo "
    "; + echo "
    Field to update (optional):
    \n"; + echo "
    List conversions (optional):Time until activation:
    \n"; + echo "
    Cellphone:
    Landline:
    Invalid:
    "; + + echo "
    "; +echo "
    "; +echo ""; +echo ""; +?> diff --git a/agc_2-X/trunk/www/vicidial/nanpa_type.php b/agc_2-X/trunk/www/vicidial/nanpa_type.php new file mode 100644 index 00000000..2f500ff7 --- /dev/null +++ b/agc_2-X/trunk/www/vicidial/nanpa_type.php @@ -0,0 +1,250 @@ + LICENSE: AGPLv2 +# +# This script is designed to work with the NANPA exchange(NPA-NXX-X) data and +# the wireless-to-wired and wired-to-wireless number portability data from +# Neustar to send back a simple "C" for cellphone, "S" for standard landline or +# "I" for invalid areacode/prefix combination, followed by a pipe and the phone +# number queried(one result per line[\n]): +# C|7275551212 +# S|8135551212 +# S|9545551212 +# I|9995551212 +# +# You can pass up to 100 phone numbers at a time to this script using a pipe +# delimiter: +# http://localhost/vicidial/nanpa_type.php?user=6666&pass=1234&phone_number=7275551212|8135551212|9545551212|9995551212 +# +# Or, even more if you send in HTTP POST to this script. We recomment 1000 +# +# required variables: +# - $user +# - $pass +# - $phone_number +# optional variable: +# - $function (version,status) +# +# CHANGELOG: +# 130822-1433 - First build of script +# + +$version = '2.8-1'; +$build = '130822-1433'; + +$startMS = microtime(); + +require("dbconnect_mysqli.php"); +require("functions.php"); + +### If you have globals turned off uncomment these lines +if (isset($_GET["user"])) {$user=$_GET["user"];} + elseif (isset($_POST["user"])) {$user=$_POST["user"];} +if (isset($_GET["pass"])) {$pass=$_GET["pass"];} + elseif (isset($_POST["pass"])) {$pass=$_POST["pass"];} +if (isset($_GET["function"])) {$function=$_GET["function"];} + elseif (isset($_POST["function"])) {$function=$_POST["function"];} +if (isset($_GET["phone_number"])) {$phone_number=$_GET["phone_number"];} + elseif (isset($_POST["phone_number"])) {$phone_number=$_POST["phone_number"];} +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} + + +header ("Content-type: text/html; charset=utf-8"); +header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 +header ("Pragma: no-cache"); // HTTP/1.0 + +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmt = "SELECT pass_hash_enabled FROM system_settings;"; +$rslt=mysqli_query($link, $stmt); +$qm_conf_ct = mysqli_num_rows($rslt); +if ($qm_conf_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $SSpass_hash_enabled = $row[0]; + } +##### END SETTINGS LOOKUP ##### +########################################### + +$DB=preg_replace('/[^0-9]/','',$DB); +$user = preg_replace("/'|\"|\\\\|;/","",$user); +$pass = preg_replace("/'|\"|\\\\|;/","",$pass); +$user=preg_replace('/[^-_0-9a-zA-Z]/','',$user); +$pass=preg_replace('/[^-_0-9a-zA-Z]/','',$pass); +$function = preg_replace('/[^-\_0-9a-zA-Z]/', '',$function); +$phone_number = preg_replace('/[^\|0-9]/','',$phone_number); + + + +################################################################################ +### version - show version, date, time and time zone information for the API +################################################################################ +if ($function == 'version') + { + $NOW_TIME = date("Y-m-d H:i:s"); + $data = "VERSION: $version|BUILD: $build|DATE: $NOW_TIME"; + echo "$data\n"; + exit; + } +################################################################################ +### END version +################################################################################ + + + +##### BEGIN user authentication for all functions below ##### +$auth=0; +$auth_message = user_authorization($user,$pass,'REPORTS',1); +if ($auth_message == 'GOOD') + {$auth=1;} + +if ($auth < 1) + { + $VDdisplayMESSAGE = "ERROR: Login incorrect, please try again"; + if ($auth_message == 'LOCK') + { + $VDdisplayMESSAGE = "ERROR: Too many login attempts, try again in 15 minutes"; + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$user|$auth_message|\n"; + exit; + } + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$user|$pass|$auth_message|\n"; + exit; + } +##### END user authentication for all functions below ##### + + + +$stmt="SELECT count(*) from nanpa_prefix_exchanges_fast;"; +if ($DB>0) {echo "DEBUG: npef count query - $stmt\n";} +$rslt=mysqli_query($link, $stmt); +$row=mysqli_fetch_row($rslt); +$npef_count=$row[0]; +if ($npef_count < 100) + { + $result = 'ERROR'; + $result_reason = "nanpa_prefix_exchanges_fast table incomplete"; + echo "$result: $result_reason: |$user|$npef_count|\n"; + exit; + } +$stmt="SELECT count(*) from nanpa_wired_to_wireless;"; +if ($DB>0) {echo "DEBUG: wired count query - $stmt\n";} +$rslt=mysqli_query($link, $stmt); +$row=mysqli_fetch_row($rslt); +$wired_count=$row[0]; +if ($wired_count < 100) + { + $result = 'ERROR'; + $result_reason = "nanpa_wired_to_wireless table incomplete"; + echo "$result: $result_reason: |$user|$wired_count|\n"; + exit; + } +$stmt="SELECT count(*) from nanpa_wireless_to_wired;"; +if ($DB>0) {echo "DEBUG: wireless count query - $stmt\n";} +$rslt=mysqli_query($link, $stmt); +$row=mysqli_fetch_row($rslt); +$wireless_count=$row[0]; +if ($wireless_count < 100) + { + $result = 'ERROR'; + $result_reason = "nanpa_wired_to_wireless table incomplete"; + echo "$result: $result_reason: |$user|$wireless_count|\n"; + exit; + } + + + +################################################################################ +### status - show counts of needed tables in the database +################################################################################ +if ($function == 'status') + { + $data = "PREFIXES: $npef_count|TO_WIRELESS: $wired_count|TO_WIRED: $wireless_count"; + echo "$data\n"; + exit; + } +################################################################################ +### END status +################################################################################ + + + +################################################################################ +### BEGIN lookup of phone numbers +################################################################################ + +if (strlen($phone_number) < 10) + { + $result = 'ERROR'; + $result_reason = "invalid phone number"; + echo "$result: $result_reason: |$user|$phone_number|\n"; + exit; + } +else + { + ### BEGIN processing phone numbers ### + $numbers = explode('|',$phone_number); + $i=0; + $numbers_ct = count($numbers); + while($i < $numbers_ct) + { + $type=''; + if ( (strlen($numbers[$i]) > 9) and (strlen($numbers[$i]) < 11) ) + { + $area = substr($numbers[$i], 0, 3); + $prefix = substr($numbers[$i], 3, 4); + + $stmt="SELECT type from nanpa_prefix_exchanges_fast where ac_prefix='$area$prefix';"; + if ($DB>0) {echo "DEBUG: prefix lookup query |$numbers[$i]| - $stmt\n";} + $rslt=mysqli_query($link, $stmt); + $prefix_ct = mysqli_num_rows($rslt); + if ($prefix_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $type = $row[0]; + if ($type != 'S') + { + $type='C'; + $stmt="SELECT count(*) from nanpa_wireless_to_wired where phone='$numbers[$i]';"; + if ($DB>0) {echo "DEBUG: wireless_to_wired lookup query |$numbers[$i]| - $stmt\n";} + $rslt=mysqli_query($link, $stmt); + $row=mysqli_fetch_row($rslt); + + if ($row[0] > 0) + {$type='S';} + } + else + { + $stmt="SELECT count(*) from nanpa_wired_to_wireless where phone='$numbers[$i]';"; + if ($DB>0) {echo "DEBUG: wired_to_wireless lookup query |$numbers[$i]| - $stmt\n";} + $rslt=mysqli_query($link, $stmt); + $row=mysqli_fetch_row($rslt); + + if ($row[0] > 0) + {$type='C';} + } + } + else + {$type='I';} + } + else + {$type='I';} + + echo "$type|$numbers[$i]\n"; + $i++; + } + + $endMS = microtime(); + $startMSary = explode(" ",$startMS); + $endMSary = explode(" ",$endMS); + $runS = ($endMSary[0] - $startMSary[0]); + $runM = ($endMSary[1] - $startMSary[1]); + $TOTALrun = ($runS + $runM); + if ($DB>0) {echo "DEBUG: runtime |$TOTALrun|\n";} + } + +?> +