Skip to content

Commit

Permalink
Resolve issues in #239
Browse files Browse the repository at this point in the history
  • Loading branch information
tm1000 committed Jan 17, 2015
1 parent 105c225 commit 6ac5b37
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions Superfecta.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ public function execute($scheme='ALL', $request, $debug=0) {
$trunk_info[$key] = $value;
}

//Remove all invalid characters from number! (\D = Anything other than a digit)
//$trunk_info['callerid'] = preg_replace('/\D/i', '', $trunk_info['callerid']);
//$trunk_info['did'] = preg_replace('/\D/i', '', $trunk_info['did']);

//Remove leading +1-9 on numbers.
$trunk_info['callerid'] = trim(preg_replace('/^\+[1-9]/', '', $trunk_info['callerid']));
$trunk_info['calleridname'] = trim(preg_replace('/^\+[1-9]/', '', $trunk_info['calleridname']));

$this->out("CID Superfecta: Scheme is '" . $scheme . "'");

$this->out("CID Superfecta: The DID is: " . $trunk_info['extension']);
Expand Down Expand Up @@ -104,6 +96,11 @@ public function execute($scheme='ALL', $request, $debug=0) {
);

foreach ($schemes as $s) {
//reset these each time
$cnum = $trunk_info['callerid'];
$cnam = $trunk_info['calleridname'];
$did = $trunk_info['extension'];

$options['scheme_settings'] = $this->getScheme($s['name']);;
$options['module_parameters'] = $this->getSchemeAllModuleSettings($s['name']);

Expand All @@ -123,11 +120,11 @@ public function execute($scheme='ALL', $request, $debug=0) {

$superfecta->setDebug($debug);
$superfecta->setCLI(true);
$superfecta->setDID($trunk_info['did']);
$superfecta->setDID($did);
$superfecta->set_CurlTimeout($scheme_param['Curl_Timeout']);

// Determine if this is the correct DID, if this scheme is limited to a DID.
$rule_match = $superfecta->match_pattern_all((isset($options['scheme_settings']['DID'])) ? $options['scheme_settings']['DID'] : '', $trunk_info['did']);
$rule_match = $superfecta->match_pattern_all((isset($options['scheme_settings']['DID'])) ? $options['scheme_settings']['DID'] : '', $did);
if ($rule_match['number']) {
$this->out("Matched DID Rule: '" . $rule_match['pattern'] . "' with '" . $rule_match['number'] . "'");
} elseif ($rule_match['status']) {
Expand All @@ -136,10 +133,10 @@ public function execute($scheme='ALL', $request, $debug=0) {
}

// Determine if the CID matches any patterns defined for this scheme
$rule_match = $superfecta->match_pattern_all((isset($options['scheme_settings']['CID_rules'])) ? $options['scheme_settings']['CID_rules'] : '', $trunk_info['callerid']);
$rule_match = $superfecta->match_pattern_all((isset($options['scheme_settings']['CID_rules'])) ? $options['scheme_settings']['CID_rules'] : '', $cnum);
if ($rule_match['number']) {
$this->out("Matched CID Rule: '" . $rule_match['pattern'] . "' with '" . $rule_match['number'] . "'");
$trunk_info['callerid'] = $rule_match['number'];
$cnum = $rule_match['number'];
} elseif ($rule_match['status'] && $run_this_scheme) {
$this->out("No matching CID rules. Skipping scheme");
continue;
Expand All @@ -151,7 +148,7 @@ public function execute($scheme='ALL', $request, $debug=0) {
if ((isset($scheme_param['Prefix_URL'])) && (trim($scheme_param['Prefix_URL']) != '')) {
$start_time = $superfecta->mctime_float();

$superfecta->set_Prefix($superfecta->get_url_contents(str_replace("[thenumber]", $trunk_info['callerid'], $options['scheme_settings']['Prefix_URL'])));
$superfecta->set_Prefix($superfecta->get_url_contents(str_replace("[thenumber]", $cnum, $options['scheme_settings']['Prefix_URL'])));

if ($superfecta->prefix != '') {
$this->out("Prefix Url defined ... returned: " . $superfecta->get_Prefix());
Expand All @@ -171,7 +168,9 @@ public function execute($scheme='ALL', $request, $debug=0) {

$callerid = trim($callerid);

$found = false;
if (!empty($callerid)) {
$found = true;
//$first_caller_id = _utf8_decode($first_caller_id);
$callerid = trim(strip_tags($callerid));
if ($superfecta->isCharSetIA5()) {
Expand All @@ -195,7 +194,7 @@ public function execute($scheme='ALL', $request, $debug=0) {

// Display issues on phones and CDR with special characters
// convert CNAM to UTF-8 to fix
if (function_exists('mb_convert_encoding')) {
if ($found && function_exists('mb_convert_encoding')) {
$this->out("Converting result to UTF-8");
$callerid = mb_convert_encoding($callerid, "UTF-8");
}
Expand All @@ -209,8 +208,12 @@ public function execute($scheme='ALL', $request, $debug=0) {
//stop all processing at this point, the spam score is too high
return $callerid;
}
if(!empty($callerid)) {
return $callerid;
}
}
return $callerid;
//No callerid so I guess?
return $trunk_info['calleridname'];
}

public function getSpamScore() {
Expand Down
Empty file modified page.superfecta.php
100755 → 100644
Empty file.
Empty file modified views/scheme.php
100755 → 100644
Empty file.

0 comments on commit 6ac5b37

Please sign in to comment.