Skip to content

Commit

Permalink
Add whitelist to fcc source
Browse files Browse the repository at this point in the history
  • Loading branch information
jfinstrom authored and tm1000 committed Jun 14, 2016
1 parent 3d6f499 commit 75f9d8a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion sources/source-FccComplaints.module
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,31 @@ class FccComplaints extends superfecta_base {
'description' => _('Optional API token to allow throttling by app rather than IP'),
'type' => 'text',
'default' => ''
),
'Whitelist' => array(
'description' => _('Whitelist of numbers to consider neverspam. One per line in the format NPA-NPX-XXXX'),
'type' => 'textarea',
'default' => ''
)
);
}

function get_caller_id($thenumber, $run_param=array()) {
$apikey = isset($run_param['API_KEY'])?$run_param['API_KEY']:'';
$spamcount = isset($run_param['SPAM_Threshold'])?$run_param['SPAM_Threshold']:1;
$whitelist = isset($run_param['Whitelist'])?explode("\n",trim($run_param['Whitelist'])):array();
$caller_id = null;
//http://stackoverflow.com/a/10741461 phone number normalization
$thenumber = preg_replace('~.*(\d{3})[^\d]{0,7}(\d{3})[^\d]{0,7}(\d{4}).*~', '$1-$2-$3', $thenumber);
if (!$this->IsValidNumber("US,CA", $thenumber)) {
$this->DebugPrint(_("Skipping Source - Non US/CAN number").": {$thenumber}");
} else {
$this->DebugPrint(_("Searching FCC Data source..."));

if(in_array($thenumber, $whitelist)){
$this->DebugPrint(sprintf(_("The number %s is in the whitelist, skipping"),$thenumber));
$this->spam = false;
return $caller_id;
}
$url = "https://opendata.fcc.gov/resource/sr6c-syda.json?caller_id_number=".$thenumber;
if(!empty($apikey)){
$url .= '&$$app_token='.$apikey;
Expand Down

0 comments on commit 75f9d8a

Please sign in to comment.