Skip to content

Commit

Permalink
implement default values
Browse files Browse the repository at this point in the history
  • Loading branch information
tm1000 committed Apr 16, 2018
1 parent 3ae1a32 commit 3880bc0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
25 changes: 14 additions & 11 deletions includes/processors/superfecta_multi.php
Expand Up @@ -19,7 +19,7 @@ function __construct($options=array()) {
$this->path_location = $options['path_location'];
$this->multifecta_id = $options['multifecta_id'];
$this->source = $options['source'];
$this->trunk_info = $options['trunk_info'];
$this->trunk_info = $options['trunk_info'];
//Check if we are a multifecta child, if so, get our variables from our child record
$this->multi_type = $this->multifecta_id ? 'CHILD' : 'PARENT';

Expand Down Expand Up @@ -64,10 +64,10 @@ function get_results() {
}

function run_parent() {

global $db;
global $amp_conf;

// We are a multifecta parent
$multifecta_start_time = $this->mctime_float();
// Clean up multifecta records that are over 10 minutes old
Expand All @@ -82,11 +82,11 @@ function run_parent() {

// Prepare for launching children.
$query = "INSERT INTO superfecta_mf (
timestamp_start,
scheme,
cidnum,
extension,
prefix,
timestamp_start,
scheme,
cidnum,
extension,
prefix,
debug
) VALUES (
" . $this->db->quoteSmart($multifecta_start_time) . ",
Expand All @@ -101,7 +101,7 @@ function run_parent() {
if (DB::IsError($res2)) {
$this->DebugDie("Unable to create parent record: " . $res2->getMessage());
}
// (jkiel - 01/04/2011) Get id of the parent record
// (jkiel - 01/04/2011) Get id of the parent record
// (jkiel - 01/04/2011) [Insert complaints on Pear DB not supporting a last_insert_id method here]
// (jkiel - 01/04/2011) What is the point of an abstraction layer when you are forced to bypass it?!?!?
// instead of complaining, just fix it
Expand Down Expand Up @@ -145,7 +145,7 @@ function run_parent() {
$trunk_info = base64_encode(serialize($this->trunk_info));
if ($this->isDebug()) {
$this->DebugPrint("Spawning child " . $superfecta_mf_child_id . ":" . $data);
exec('/usr/bin/php '.$amp_conf['AMPWEBROOT'].'/admin/modules/superfecta/includes/callerid.php -s ' . $this->scheme_name . ' -d ' . $this->getDebug() . ' -m ' . $superfecta_mf_child_id . ' -t ' . $trunk_info . ' -r ' . $data . ' > log-' . $superfecta_mf_child_id . '.log 2>&1 &');
exec('/usr/bin/php '.$amp_conf['AMPWEBROOT'].'/admin/modules/superfecta/includes/callerid.php -s ' . $this->scheme_name . ' -d ' . $this->getDebug() . ' -m ' . $superfecta_mf_child_id . ' -t ' . $trunk_info . ' -r ' . $data . ' > log-' . $superfecta_mf_child_id . '.log 2>&1 &');
} else {
exec('/usr/bin/php '.$amp_conf['AMPWEBROOT'].'/admin/modules/superfecta/includes/callerid.php -s ' . $this->scheme_name . ' -m ' . $superfecta_mf_child_id . ' -t ' . $trunk_info . ' -r ' . $data . ' > /dev/null 2>&1 &');
}
Expand Down Expand Up @@ -303,7 +303,9 @@ function run_child() {
$source_class->set_DB($this->db);
$source_class->set_AsteriskManager($this->astman);
$source_class->set_TrunkInfo($this->trunk_info);


$run_param = $source_class->getRunParams($run_param);

if (method_exists($source_class, 'get_caller_id')) {
$caller_id = $source_class->get_caller_id($this->trunk_info['callerid'], $run_param);
$this->setSpam($source_class->isSpam());
Expand Down Expand Up @@ -364,6 +366,7 @@ function send_results($caller_id) {
$source_class = NEW $source_name;
$source_class->set_DB($this->db);
$source_class->setDebug($this->isDebug());
$run_param = $source_class->getRunParams($run_param);
if (method_exists($source_class, 'post_processing')) {
$source_class->post_processing($this->isCacheFound(), NULL, $caller_id, $run_param, $this->trunk_info['callerid']);
} else {
Expand Down
5 changes: 5 additions & 0 deletions includes/processors/superfecta_single.php
Expand Up @@ -48,6 +48,8 @@ function get_results() {
$source_class->set_AsteriskManager($this->astman);
$source_class->set_TrunkInfo($this->trunk_info);

$run_params = $source_class->getRunParams($run_params);

if (method_exists($source_class, 'get_caller_id')) {
if ($this->isDebug()) {
print '<i class="fa fa-arrow-right"></i> '._('Executing'). ' '. str_replace("_"," ",$data).'<br/>';
Expand Down Expand Up @@ -110,6 +112,9 @@ function send_results($caller_id) {
$source_class->set_DB($this->db);
$source_class->set_AsteriskManager($this->astman);
$source_class->set_TrunkInfo($this->trunk_info);

$run_param = $source_class->getRunParams($run_param);

if (method_exists($source_class, 'post_processing')) {
if ($this->isDebug()) {
print '<i class="fa fa-arrow-right"></i> '._('Executing'). ' '. str_replace("_"," ",$source_name).'<br/>';
Expand Down
19 changes: 19 additions & 0 deletions includes/superfecta_base.php
Expand Up @@ -30,6 +30,25 @@ class superfecta_base {
protected $spam_count = 0;
public $debug_log = array(); //Send all log information here

function getRunParams($settings=array()) {
$final = array();
if(empty($this->source_param)) {
return $final;
}
foreach($this->source_param as $key => $values) {
if(isset($settings[$key])) {
$final[$key] = $settings[$key];
} else {
if(isset($values['default'])) {
$final[$key] = $values['default'];
} else {
$final[$key] = null;
}
}
}
return $final;
}

function isCLI() {
return $this->cli;
}
Expand Down
10 changes: 4 additions & 6 deletions sources/source-Who_Called.module
Expand Up @@ -66,19 +66,17 @@ class Who_Called extends superfecta_base {
$debug = $this->debug;

// username and password are optional, but it one is provided both must be
if($run_param['Username'] || $run_param['Password']) {
if(empty($run_param['Username']) || empty($run_param['Password'])) {
$this->DebugPrint("The whocalled username and password are optional, but if one is set, they both must be.");
return '';
}
if((!empty($run_param['Username']) && empty($run_param['Password'])) || (empty($run_param['Username']) && !empty($run_param['Password']))) {
$this->DebugPrint("The whocalled username and password are optional, but if one is set, they both must be.");
return '';
}

// Site is for NANP numbers only, trim to 10 digits, lookup will succeed with 11 digits, but return nothing
$thenumber = substr($thenumber, -10);


// Perform spam score lookup if enabled
if ($run_param['Spam_Scoring']) {
if (!empty($run_param['Spam_Scoring'])) {
$this->DebugPrint("Searching Who Called for number of user reports ... ");
$url = "https://whocalled.us/do?action=getScore&name=" . $run_param['Username'] . "&pass=" . $run_param['Password'] . "&phoneNumber=$thenumber&days=". $run_param['Report_Age'];
$this->DebugPrint("SPAM URL: ".$url,3);
Expand Down
2 changes: 1 addition & 1 deletion utests/source-Who_CalledTest.php
Expand Up @@ -14,7 +14,7 @@ public static function setUpBeforeClass() {
}

public function testCnam(){
$cnam = self::$o->get_caller_id('6305424316',array('CNAM_Lookup' => true));
$cnam = self::$o->get_caller_id('6305424316',self::$o->getRunParams(array('CNAM_Lookup' => true)));
$this->assertEquals("Schaumburg%2C+IL", $cnam, "The lookup returned an unexpected result for 6305434316");
}
}

0 comments on commit 3880bc0

Please sign in to comment.