-
Notifications
You must be signed in to change notification settings - Fork 1
/
blacklist.php
292 lines (262 loc) · 10.2 KB
/
blacklist.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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<?php
session_start();
if(!isset($_SESSION['login']) || $_SESSION['login'] != true)
{
header("location: login.php");
exit;
}
$okmsg = $errmsg = "";
if(isset($_POST['button']) && !isset($_POST['enableBL']))
$do = `sudo rm -f "/etc/adfree.conf" "/etc/cron.daily/blacklist.sh" "/etc/dnsmasq.d/adfree.conf"`;
if((isset($_POST['button']) || isset($_POST['dlBlacklist'])) && isset($_POST['enableBL']) && $_POST['enableBL'] == "yes")
{
$email = substr(escapeshellarg($_POST['email']), 1, -1);
$passphrase = substr(escapeshellarg($_POST['passphrase']), 1, -1);
if($email != "" && !filter_var($email, FILTER_VALIDATE_EMAIL))
$errmsg = "Invalid email address";
if($errmsg == "" && $email != "" && $passphrase == "")
{
if(file_exists("/etc/adfree.conf"))
{
$do = `sudo cat "/etc/adfree.conf"`;
list($email, $passphrase) = explode("\n", trim($do), 2);
list($crud, $email) = explode("=", $email, 2);
list($crud, $passphrase) = explode("=", $passphrase, 2);
}
}
if($errmsg == "" && $email != "" && $passphrase != "")
{
$url = "https://adfree-hosts.odiousapps.com/dnsmasq.php";
$url .= "?username=".urlencode($email)."&password=".urlencode($passphrase);
$ret = file_get_contents($url."&checkup=1");
if($ret != "ok")
$errmsg = $ret;
else
$okmsg = "Email and Passphrase was accepted and saved.";
}
if($errmsg == "")
{
$do = `echo "email=$email\npassphrase=$passphrase" | sudo tee "/etc/adfree.conf"`;
$do = `sudo chmod 600 "/etc/adfree.conf"`;
$do = `sudo echo "#!/bin/sh\n\n/var/www/html/scripts/update-blacklist.php" | sudo tee "/etc/cron.daily/blacklist.sh"`;
$do = `sudo chmod 755 "/etc/cron.daily/blacklist.sh"`;
}
}
if(isset($_POST['dlBlacklist']) && isset($_POST['enableBL']) && $_POST['enableBL'] == "yes")
{
if(!file_exists("/etc/adfree.conf"))
{
$do = `sudo touch "/etc/adfree.conf"`;
$do = `sudo chmod 600 "/etc/adfree.conf"`;
}
$do = `sudo "/var/www/html/scripts/update-blacklist.php"`;
$okmsg = "The system has updated the Blacklist.";
} else if(isset($_POST['dlBlacklist']) && !isset($_POST['enableBL'])) {
$errmsg = "Blacklisting isn't enabled.";
}
$enableBL = "no";
if(file_exists("/etc/adfree.conf"))
{
$enableBL = "yes";
$do = `sudo cat "/etc/adfree.conf"`;
@list($email, $passphrase) = explode("\n", trim($do), 2);
@list($crud, $email) = explode("=", $email, 2);
@list($crud, $passphrase) = explode("=", $passphrase, 2);
}
$email = urlencode($email);
$passphrase = urlencode($passphrase);
$hostname = "";
if(isset($_REQUEST['hostname']))
$hostname = trim($_REQUEST['hostname']);
$page = 8;
$pageTitle = "Blacklist Settings";
include_once("header.php");
$tab = 1;
if($hostname != "" || isset($_REQUEST['viewAll']))
$tab = 2;
?>
<div id="page-wrapper">
<div id="page-inner">
<div class="row" style="padding-right:15px;padding-left:15px;">
<div class="col-md-12">
<h2><?=$pageTitle?></h2>
</div>
</div>
<hr />
<div class="row" style="padding-right:15px;">
<div class="col-lg-4 col-md-4">
<ul class="nav nav-tabs">
<li class="<?php if($tab == 1) echo "active";?>"><a href="#graphs" data-toggle="tab">Graphs</a></li>
<li class="<?php if($tab == 2) echo "active";?>"><a href="#logging" data-toggle="tab">Logging</a></li>
<li class=""><a href="#hostnames" data-toggle="tab">Blocked</a></li>
<li class=""><a href="#stats" data-toggle="tab">Statistics</a></li>
<li class=""><a href="#settings" data-toggle="tab">Settings</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane fade<?php if($tab == 1) echo " active in";?>" id="graphs">
<h4>Graphs</h4>
<div class="row" style="padding-right:15px;padding-left:15px;width:800px;">
<div class="panel panel-primary">
<div class="panel-heading">DNS Graphs</div>
<div class="panel-body" id="panel-body4">
<iframe style="border:0px;width:750px;height:550px;" src="daily-DNS.php"></iframe>
</div>
</div>
</div>
</div>
<div class="tab-pane fade<?php if($tab == 2) echo " active in";?>" id="logging">
<h4>Logging</h4>
<div class="row" style="padding-right:15px;padding-left:15px;width:800px;">
<div style="width:180px;float:left">Auto refresh every 60s</div><input type="checkbox" style="width:25px;float:left;margin-left:10px;" class="form-control" checked id="autoRefresh1"><br style="clear:left;"/>
<?php if($hostname != "") { ?><a href='blacklist.php?viewAll=1'>View All</a><br style="clear:left;"/><?php } ?>
<div class="panel panel-primary">
<div class="panel-heading">DNS Logs</div>
<div class="panel-body" id="panel-body1">
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="hostnames">
<h4>Blocked Hostnames</h4>
<div class="row" style="padding-right:15px;padding-left:15px;width:800px;">
<div style="width:180px;float:left;">Auto refresh every 60s</div><input type="checkbox" style="width:25px;float:left;margin-left:10px;" class="form-control" checked id="autoRefresh2"><br style="clear:left;"/>
<div class="panel panel-primary">
<div class="panel-heading">Blocked Hostnames</div>
<div class="panel-body" id="panel-body2">
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="stats">
<h4>Statistics</h4>
<div class="row" style="padding-right:15px;padding-left:15px;width:800px;">
<div style="width:180px;float:left">Auto refresh every 60s</div><input type="checkbox" style="width:25px;float:left;margin-left:10px;" class="form-control" checked id="autoRefresh3"><br style="clear:left;"/>
<div class="panel panel-primary">
<div class="panel-heading">DNS Stats</div>
<div class="panel-body" id="panel-body3">
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="settings">
<h4>Settings</h4>
<div class="row" style="padding-right:15px;padding-left:15px;">
<?php if($errmsg != "") { ?>
<p><div class="alert alert-warning alert-dismissable"><?=$errmsg?><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button></div></p>
<?php } ?>
<?php if($okmsg != "") { ?>
<p><div class="alert alert-success alert-dismissable"><?=$okmsg?><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button></div></p>
<?php } ?>
<form method="post" autocomplete="off" action="<?=$_SERVER['PHP_SELF']?>">
<div style="width:140px;float:left">Enable blacklisting?</div>
<input type="checkbox" style="width:25px;float:left;margin-left:20px;" class="form-control" name="enableBL" value="yes"<?php if($enableBL == "yes") { echo " checked"; } ?> /><br style="clear:left;"/>
<p><a target="_blank" href="https://adfree.odiousapps.com">Adfree</a> is a crowdsourced list of advertising hostnames which can be used for free, with or without an account, although donations are welcome.</p>
<div style="width:140px;float:left">Adfree email:</div>
<input type="text" style="width:200px;float:left;" class="form-control" name="email" value="<?=urldecode($email)?>" placeholder="Adfree email" /><br style="clear:left;"/>
<div style="width:140px;float:left">Adfree Passphrase:</div>
<input type="text" style="width:200px;float:left;" class="form-control" id="passphrase" name="passphrase" placeholder="Adfree passphrase" /><br style="clear:left;"/>
<input type="submit" class="btn btn-primary" name="button" value="Save Settings" />
<input type="submit" class="btn btn-primary" name="dlBlacklist" value="Download Blacklist Now" />
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" charset="utf-8">
<!--//
var http1 = getHTTPObject();
var http2 = getHTTPObject();
var http3 = getHTTPObject();
function getHTTPObject()
{
var request = null;
if(typeof XMLHttpRequest != 'undefined')
{
request = new XMLHttpRequest();
} else {
try
{
request = new ActiveXObject('Msxml2.XMLHTTP')
} catch(e) {
try
{
request = new ActiveXObject('Microsoft.XMLHTTP')
} catch(e) {
request = null
}
}
}
return request;
}
function switchType()
{
document.getElementById('passphrase').type = "password";
}
function updateDisplay(name, val)
{
var element = document.getElementById(name);
if(!element)
return;
element.innerHTML = val;
}
function updateLog()
{
setTimeout("updateLog();", 60000);
if(document.getElementById("autoRefresh1").checked)
{
try
{
http1.open('GET', '/jsapi.php?dnsmasqLog=1<?php if($hostname != "") echo "&hostname=$hostname"; ?>&date='+new Date().getTime(), true);
http1.onreadystatechange = function()
{
if(http1.readyState == 4 && http1.status == 200)
updateDisplay('panel-body1', http1.responseText);
}
http1.send();
} catch (e) {}
}
}
function updateHosts()
{
setTimeout("updateHosts();", 60000);
if(document.getElementById("autoRefresh2").checked)
{
try
{
http2.open('GET', '/jsapi.php?dnsmasqBlockedHosts=1&date='+new Date().getTime(), true);
http2.onreadystatechange = function()
{
if(http2.readyState == 4 && http2.status == 200)
updateDisplay('panel-body2', http2.responseText);
}
http2.send();
} catch (e) {}
}
}
function doStats()
{
setTimeout("doStats();", 60000);
if(document.getElementById("autoRefresh3").checked)
{
try
{
http3.open('GET', '/jsapi.php?doStats=1&date='+new Date().getTime(), true);
http3.onreadystatechange = function()
{
if(http3.readyState == 4 && http3.status == 200)
updateDisplay('panel-body3', http3.responseText);
}
http3.send();
} catch (e) {}
}
}
setTimeout("switchType();", 1000);
updateLog();
updateHosts();
doStats();
//-->
</script>
<?php include_once("footer.php"); ?>