-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
executable file
·70 lines (63 loc) · 2.32 KB
/
index.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
<?php
/**
* Chronolabs IP Lookup's REST API File
*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @copyright Chronolabs Cooperative http://labs.coop
* @license General Public License version 3 (http://labs.coop/briefs/legal/general-public-licence/13,3.html)
* @package lookups
* @since 1.1.2
* @author Simon Roberts <[email protected]>
* @version $Id: index.php 1000 2013-06-07 01:20:22Z mynamesnot $
* @subpackage api
* @description Internet Protocol Address Information API Service REST
*/
include __DIR__ . DIRECTORY_SEPARATOR . 'apiconfig.php';
$help=false;
if ((!isset($_GET['mode']) || empty($_GET['mode'])) && (!isset($_GET['basis']) || empty($_GET['basis']) && (!isset($_GET['source']) || empty($_GET['source'])))) {
$help=true;
} elseif (isset($_GET['mode']) && !empty($_GET['mode']) && isset($_GET['source']) && !empty($_GET['source']) && isset($_GET['output']) && !empty($_GET['output'])) {
$mode = trim($_GET['mode']);
$basis = trim($_GET['basis']);
$source = trim($_GET['source']);
$output = trim($_GET['output']);
} else {
$help=true;
}
if ($help==true) {
if (function_exists('http_response_code'))
http_response_code(400);
include dirname(__FILE__).'/help.php';
exit;
}
if (function_exists('http_response_code'))
http_response_code(200);
$data = getAPIData($source, $mode, $basis);
switch ($output) {
case 'raw':
header('Content-type: application/x-httpd-php');
echo ('<?php'."\n\n".'return ' . var_export($data, true) . ";\n\n?>");
break;
default:
case 'json':
header('Content-type: application/json');
echo json_encode($data);
break;
case 'serial':
header('Content-type: text/html');
echo serialize($data);
break;
case 'xml':
header('Content-type: application/xml');
$dom = new XmlDomConstruct('1.0', 'utf-8');
$dom->fromMixed(array('root'=>$data));
echo $dom->saveXML();
break;
}
?>