forked from mikelynn2/blacklistmonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapiDocumentation.php
149 lines (124 loc) · 3.94 KB
/
apiDocumentation.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
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
<?php
class_exists('Setup', false) or include('classes/Setup.class.php');
class_exists('Utilities', false) or include('classes/Utilities.class.php');
if(Utilities::isLoggedIn()===false){
header('Location: login.php');
exit();
}
$titlePreFix = "api documentation";
include('header.inc.php');
include('accountSubnav.inc.php');
$user = Utilities::getAccount();
?>
<h4>API Documentation</h4>
<p>
The API is a JSON HTTP POST based API.
All responses from the API are JSON.
</p>
<h4>POST URL: <?php echo Setup::$settings['base_url']; ?>/api.php</h4>
<table border="1">
<tr>
<th>Post Variable:</th>
<th></th>
</tr>
<tr>
<td>apiKey</td>
<td>Your api key: <?php echo $user['apiKey'];?></td>
</tr>
<tr>
<td>type</td>
<td>
updateDomains - pass data var of whitespace delimited domains. Whitespace can be any tabs, spaces, new lines.<br/><br/>
updateIPs - pass data var of whitespace delimited ip addresses/ranges. Whitespace can be any tabs, spaces, new lines.<br/><br/>
checkHostStatus - pass data var of a single ip (not a range) or domain name for current black list status.<br/><br/>
blacklistStatus - data var - all (default) | blocked | changed | clean. Returns blacklist status of all current ips and domains<br/><br/>
</td>
</tr>
<tr>
<td>data</td>
<td>When calling functions that need data passed use the var data.</td>
</tr>
</table>
<br/>
<h4>Response</h4>
<p>
Below is an example response from the API in JSON. It will always include a status. Either success or failure and if a result is required for the call it will be included as well as with the
blacklistStatus call.
</p>
<pre>
{"status":"success","result":""}
</pre>
<h4>PHP Example - Pulling all hosts current status</h4>
<br/>
<pre>
<?php
$apiKey = '<?php echo $user['apiKey'];?>';
$requestBody =
"apiKey=".urlencode($apiKey).
"&type=blacklistStatus".
"&data=all";
$return = httpPost('<?php echo Setup::$settings['base_url']; ?>/api.php', $requestBody);
$return = json_decode($return, true);
$results = $return['result'];
$body = "";
$body .= "<table border='1'>";
$body .= "<tr>";
$body .= "<th>host</th>";
$body .= "<th>status</th>";
$body .= "</tr>";
foreach($results as $result){
$body .= "<tr>";
$body .= "<td>".htmlentities($result['host'])."</td>";
$body .= "<td nowrap>";
if($result['isBlocked']==0){
$body .= "OK";
}else{
foreach($result['status'] as $r){
if($r[1] == false || $r[1] == ''){
}else{
$body .= htmlentities($r[0]) . " - " . htmlentities($r[1])."<br>";
}
}
}
$body .= "</td>";
$body .= "</tr>";
}
$body .= "</table>";
echo $body;
function httpPost($url, $vars){
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_FAILONERROR,true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_POSTFIELDS,$vars);
//execute post
return curl_exec($ch);
}
</pre>
<br/><br/><br/>
<a name="callBack"></a>
<h4>Callback API</h4>
<p>
A JSON array will be posted for each host upon a status change with that host. Each host will be called back in seperate requests. You set the call back URL on your <a href="account.php">profile</a> page.
</p>
<h4>Example Posted JSON</h4>
<pre>
{
"host":"samplehosttest.com",
"isBlocked":true,
"rDNS":"reverse-dns-sample.samplehosttest.com",
"blocks":[
["l2.apews.org","Listed at APEWS-L2 - visit http:\/\/www.apews.org\/?page=test&C=131&E=1402188&ip=127.0.0.1"],
["b.barracudacentral.org","127.0.0.2"]
]
}
</pre>
<br/><br/><br/>
<br/><br/><br/>
<?php
include('footer.inc.php');
?>