Repository navigation
Expand file tree
/
Copy pathcid.php
More file actions
236 lines (192 loc) · 6.25 KB
/
Copy pathcid.php
File metadata and controls
236 lines (192 loc) · 6.25 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
// Report all PHP errors
error_reporting(-1);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
$debug = getVar( "debug", true );
include( $_SERVER['DOCUMENT_ROOT']."/../cid_config.php" );
if ( getVar( "key", true ) !== CID_API_KEY )
{
// Delay against brute force
sleep( 2 );
die( "UNAUTHORIZED" );
exit( 0 );
}
define( "COUNTRY", "31" );
define( "REGION", "45" );
define( "PLUS", "00" );
require_once( "numbers.php" );
// Normalize the number
$arrNumberInfo = normalizeNumber( getVar( "number", true ) );
if ( $debug )
{
var_dump( getVar( "number", true ) );
var_dump( $arrNumberInfo );
}
// Extension? try and get from dialplan
if ( $arrNumberInfo['type'] == "extension" )
{
echo getExtension( $arrNumberInfo['local'] );
exit;
}
require_once( "db_sqlite.php" );
$fetchList = [];
include( "fetch/contacts.php" ); // personal directory
include( "fetch/nummerzoeker.php" ); // business listings only
include( "fetch/nummerid.php" ); // name (old database)
include( "fetch/nationaletelefoongids.php" ); // score 0-5
include( "fetch/telefoonnummerinformatie.php" ); // score text
include( "fetch/telenummer.php" ); // score text (small DB?)
include( "fetch/gebelddoor.php" ); // score 0-10?
include( "fetch/telefoonboek.php" ); // score 0-10
include( "fetch/wiegebeld.php" ); // score 0-10
include( "fetch/acm.php" ); // ported telco (NOTE: unported blocks are in the numbers list)
include( "fetch/telguarder.php" ); // (slow) score 0-180->0-10
include( "fetch/telefoonnummerzoeken.php" ); // (slow) no score
//include( "fetch/wieheeftmijgebeld.php" ); // no score, spam copy of wieheeftgebeld?
//include( "fetch/wieheeftgebeld.php" ); // no score
// Try and fetch the number from the local database
// TODO: "lease" time on local entries
if ( $strName = dbLookup( $arrNumberInfo ))
{
echo $strName;
exit;
}
// Fetch number from website (check last get timestamp to prevent DoS
// put result in DB
$strName = fetchWebsiteResult( $arrNumberInfo );
if ( is_array( $strName ) )
{
print_r( $strName );
exit;
}
else if ( $strName )
{
echo $strName;
exit;
}
// Nothing on the websites? Try and find the number in the array
if ( isset( $arrNumberInfo['international'] ))
{
//echo "array";
$strName = _getInfo( str_split( $arrNumberInfo['international'] ));
echo $strName;
exit;
}
function fetchWebsiteResult( $_arrNumberInfo, $_bAll = false )
{
global $fetchList, $debug;
$resultList = [];
foreach ( $fetchList as $value )
{
if ( $debug )
echo $value.": ";
$result = ($value)($_arrNumberInfo);
if ( $result )
{
if ( $_bAll )
$resultList[] = $result;
else
return $result;
}
}
return $_bAll ? $resultList : false;
}
function getExtension( $_strExtension )
{
return false;
return "Ext. ".$_strExtension;
}
function normalizeNumber( $_strNumber )
{
$arrInfo = array();
$_strNumber = preg_replace('/[\s-]/', '', $_strNumber);
// Extensions start with 1 or 9 and can have any length
if ( preg_match( "/^([19]\d+)/", $_strNumber, $matches ))
{
$arrInfo['local'] = $matches[1];
$arrInfo['type'] = 'extension';
return $arrInfo;
}
// Short and long local numbers (depending on region length)
if ( preg_match( '/^([2-8]\d{'.(8 - strlen( REGION )).'}$)/', $_strNumber, $matches ))
$_strNumber = COUNTRY.REGION.$matches[1];
elseif ( preg_match( '/^(?: |\+|00)(\d+)/', $_strNumber, $matches ))
$_strNumber = $matches[1];
elseif ( preg_match( '/^0([1-9]\d{6,9})$/', $_strNumber, $matches ))
$_strNumber = COUNTRY.$matches[1];
$arrInfo['country'] = intval( substr( $_strNumber, 0, 2 ));
$arrInfo['international'] = $_strNumber;
$arrInfo['type'] = 'international';
// National number?
if ( $arrInfo['country'] == intval( COUNTRY ))
{
// only works with countries of 2 digits; replaces it wiht a 0
$arrInfo['national'] = "0".substr( $_strNumber, 2 );
$arrInfo['type'] = 'national';
}
return $arrInfo;
};
function GetInfo( $_strNumber )
{
global $arrNumbers;
//if ( substr( $_strNumber, 1, 1 ) == "+"
// Add region + country on quick dials
$_strNumber = preg_replace( "/^([2345678])/", COUNTRY.REGION.'$1', $_strNumber );
// Add country on national dials
$_strNumber = preg_replace( "/^(0)([^0].*)/", COUNTRY.'$2', $_strNumber );
// Replace + and 00 international symbols before parsing
$_strNumber = preg_replace( "/^(\+|00)/", '', $_strNumber );
return _getInfo( str_split( $_strNumber ));
};
function _getInfo( $_arrNumber )
{
global $arrNumbers;
$arrInfo = array();
$arrNumberInfo = $arrNumbers;
$nIndent = 0;
$strDigits = "";
$strDetailedInfo = "";
foreach ( $_arrNumber as $digit )
{
if ( isset( $arrNumberInfo[$digit] ) )
{
$strDigits .= $digit;
$arrNumberInfo = $arrNumberInfo[$digit];
if ( isset( $arrNumberInfo['info'] ) )
{
$arrInfo[] = str_repeat( "-", $nIndent ) . $strDigits . " " . $arrNumberInfo['info'];
$strDigits = "";
$strDetailedInfo = $arrNumberInfo['info'];
}
$nIndent++;
} else {
break;
}
}
return $strDetailedInfo;
}
////////////////////////////////////////////////////////////////////////////////
// Helpers
////////////////////////////////////////////////////////////////////////////////
function getVar( $_strVarName, $_bAllowGet = false )
{
if ( isset( $_POST[ $_strVarName ] ) )
{
// If _POST var is set, return _POST var
return $_POST[ $_strVarName ];
}
else if ( isset( $_GET[ $_strVarName ] ) && ($_bAllowGet == true) )
{
// If _GET var is set and is allowed, return _GET var
return $_GET[ $_strVarName ];
}
else
{
// requested var not found: return NULL
return NULL;
}
}
?>