forked from kingarthur2/superfecta-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource-Number_Guru.module
108 lines (92 loc) · 5.17 KB
/
source-Number_Guru.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
class Number_Guru extends superfecta_base {
public $description = "http://www.numberguru.com - US free CNAM lookup.<br><br>This data source requires Superfecta Module version 2.11 or higher.";
public $version_requirement = "2.11";
public $source_param = array(
'Get_Caller_ID_Name' => array(
'description' => 'Use NumberGuru for caller id name lookup.',
'type' => 'checkbox',
'default' => 'on'
),
'Get_SPAM_Score' => array(
'description' => 'Use NumberGuru for spam scoring.',
'type' => 'checkbox',
'default' => 'on'
),
'Spam_Threshold' => array(
'description' => 'How sensitive of a spam score to use 0-100',
'type' => 'number',
'default' => '60'
),
'Ignore_keywords' => array(
'description' => 'If the trunk provided caller id includes any of the keywords listed here, the trunk provided value will be ignored and other sources will be used to find the value.<br> Seperate keywords with commas.',
'type' => 'textarea',
'default' => 'unknown, toll free, unlisted, (N/A), wireless caller'
)
);
function get_caller_id($thenumber, $run_param=array()) {
//This debug variable allows simple copy and past of most sources.
$debug = $this->debug;
//Paste old source '$usage_mode == 'get caller id' here:
$caller_id = null;
if (!$this->IsValidNumber(array('US', 'CA'), $thenumber)) {
$this->DebugPrint("Skipping Source - Not a valid US/CAN number: " . $thenumber);
} else {
if (($run_param['Get_SPAM_Score'] == 'on') || ($run_param['Get_Caller_ID_Name'] == 'on')) {
$this->DebugPrint("Searching NumberGuru ... ");
// www.numberguru.com needs a cookie
$temp_cookie_file = tempnam(function_exists('sys_get_temp_dir') ? realpath(sys_get_temp_dir()) : NULL, "CURLCOOKIE");
// Get the cookie set
$value = $this->get_url_contents("http://www.numberguru.com", false, "http://www.numberguru.com", $temp_cookie_file);
// Perform lookup using cookie
$url = "http://www.numberguru.com/s/{$thenumber}";
$value = $this->get_url_contents($url, false, "http://www.numberguru.com", $temp_cookie_file);
// Delete the temporary cookie
@unlink($temp_cookie_file);
// Check for Capture Code
if (strstr($value, "Please verify your humanity, and forgive the inconvenience")) {
$this->DebugPrint("NumberGuru has blocked searches from this IP. Please visit the site to solve the captcha first.");
return "";
}
// Check for CNAM lookup
if (isset($run_param['Get_Caller_ID_Name']) && $run_param['Get_Caller_ID_Name'] == 'on') {
// By default, the found name is empty
$name = "";
// Grab the first result from NumberGuru that matches our phone number
$pattern = "/<div class=\"callout_details_left caller_id\">Owner's Name:<\/div>\s*<div class=\"callout_details_right caller_id\">(.*)<\/div>/";
preg_match($pattern, $value, $match);
if (isset($match[1]) && strlen($match[1])) {
$name = trim(strip_tags($match[1]));
}
// If we found a match, return it
if (strlen($name) > 1 && $name <> "UNAVAILABLE") {
$keywords = (isset($run_param['Ignore_Keywords']) ? $run_param['Ignore_Keywords'] : $source_param['Ignore_Keywords']['default']);
if (!$this->ContainsKeywords($name, $keywords)) {
$caller_id = $name;
} else {
$this->DebugPrint("Result '{$name}' contains flagged key words, returning nothing");
}
} else {
$this->DebugPrint("not found");
}
}
// Check for SPAM score
if (isset($run_param['Get_SPAM_Score']) && $run_param['Get_SPAM_Score'] == 'on') {
$score = 0;
$pattern = "/<div class=\"stat_number\">(.*)%<\/div>\s*<div class=\"stat_title\">Spammer Score<\/div>/";
preg_match($pattern, $value, $match);
if (isset($match[1]) && strlen($match[1])) {
$score = $match[1];
$this->DebugPrint("SPAM score = {$score}", DEBUG_ALL);
$this->DebugPrint("Threshold = " . (isset($run_param['Spam_Threshold']) ? $run_param['Spam_Threshold'] : 0), DEBUG_ALL);
if (isset($run_param['Spam_Threshold']) && $score >= $run_param['Spam_Threshold']) {
$this->spam = true; // Flag as SPAM
$this->DebugPrint("SPAM caller");
}
}
}
}
}
return($caller_id);
}
}