-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest_geo.php
executable file
·92 lines (76 loc) · 2.76 KB
/
test_geo.php
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
#!/usr/bin/env php
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage tests
* @copyright (C) Adam Armstrong
*
*/
// This file allows you to test geocoding using observium's libraries. It's a quick diagnostic tool.
// You probably don't need to use it.
chdir(dirname($argv[0]));
//define('OBS_DEBUG', 2);
// Get options before definitions!
$options = getopt("a:d");
include_once("includes/observium.inc.php");
include_once("html/includes/functions.inc.php");
array_shift($argv);
if (isset($options['a'])) {
array_shift($argv);
array_shift($argv);
}
if (isset($options['d'])) {
array_shift($argv);
}
//print_vars($argv);
//print_vars($options);
$address = array_pop($argv);
$geo_apis = array_keys($config['geo_api']);
if (!$address) {
print_message("%n
USAGE:
$scriptname [-d] [-a api] 'Address string'
OPTIONS:
-a API name, currently supported: " . implode(', ', $geo_apis) . "
DEBUGGING OPTIONS:
-d Enable debugging output.
-dd More verbose debugging output.
%rAddress string is empty!%n", 'color', FALSE);
exit;
}
if (isset($options['a'])) {
// Override default GEO API
//$config['geocoding']['api'] = $options['a'];
$apis = $options['a'] === 'all' ? $geo_apis : explode(',', $options['a']);
} else {
$apis = (array)$config['geocoding']['api'];
}
print_cli_table([[$address]], ['Location']);
$table_rows = [];
foreach ($apis as $api) {
$config['geocoding']['api'] = $api;
$location = get_geolocation($address, [], FALSE);
if (isset($location['location_lat'])) {
$table_row = [
'%g' . $api . '%n',
is_array($location['location_lat']) ? '%yUnknown%n' : $location['location_lat'],
is_array($location['location_lon']) ? '%yUnknown%n' : $location['location_lon'],
$location['location_country'] === 'Unknown' ? '%y' . $location['location_country'] . '%n' : $location['location_country'],
$location['location_state'] === 'Unknown' ? '%y' . $location['location_state'] . '%n' : $location['location_state'],
$location['location_county'] === 'Unknown' ? '%y' . $location['location_county'] . '%n' : $location['location_county'],
$location['location_city'] === 'Unknown' ? '%y' . $location['location_city'] . '%n' : $location['location_city'],
''
];
} else {
$table_row = ['%r' . $api . '%n', '-', '-', '-', '-', '-', '-', get_last_message()];
}
unset($GLOBALS['last_message']);
$table_rows[] = $table_row;
print_debug_vars($location);
}
print_cli_table($table_rows, ['Geo: API', 'Lat', 'Lon', 'Country', 'State', 'County', 'City', 'Error']);
// EOF