-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjsapi.php
More file actions
172 lines (144 loc) · 6.18 KB
/
jsapi.php
File metadata and controls
172 lines (144 loc) · 6.18 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
<?php
session_start();
if(!isset($_SESSION['login']) || $_SESSION['login'] != true)
{
header("location: login.php");
exit;
}
require_once("/var/www/html/mysql.php");
$hostname = "";
if(isset($_REQUEST['hostname']))
$hostname = trim(mysqli_real_escape_string($link, $_REQUEST['hostname']));
if(isset($_REQUEST['dnsmasqLog']))
dnsmasqLog($hostname);
if(isset($_REQUEST['dnsmasqBlockedHosts']))
dnsmasqBlockedHosts();
if(isset($_REQUEST['HostAPd']))
HostAPd();
if(isset($_REQUEST['doStats']))
doStats();
exit;
function dnsmasqLog($hostname = "", $maxlen = 30)
{
global $link;
$lines = "";
echo "<table style='width:100%'>";
echo "<tr><th>When</th><th>Type</th><th style='width:250px;'>Hostname</th><th>Client</th><th>Status</th><th>Action</th></tr>";
$query = "select *,UNIX_TIMESTAMP(`when`) as `when` from `dnslog` where `when` >= now() - INTERVAL 30 DAY order by `when` desc limit 50";
if($hostname != "")
$query = "select *,UNIX_TIMESTAMP(`when`) as `when` from `dnslog` where `hostname`='$hostname' and `when` >= now() - INTERVAL 30 DAY order by `when` desc limit 50";
$res = mysqli_query($link, $query);
while($row = mysqli_fetch_assoc($res))
{
$status = "<div title='Forwarded to ${row['DNSIP']}' style='text-decoration:underline;'>OK (forwarded)</div>";
if($row['status'] == "config")
$status = "blocked";
if($row['status'] == "cached")
$status = "OK (cached)";
$len = strlen($row['hostname']);
echo "<tr><td>".date("H:i:s", $row['when'])."</td><td>${row['qtype']}</td><td><a href='blacklist.php?hostname=${row['hostname']}' title='http:/"."/".$row['hostname']."'>";
echo @substr($row['hostname'], 0, $maxlen);
if($len > $maxlen)
echo "...";
echo "</a></td><td>${row['client']}</td><td>$status</td><td>";
if($status == "blocked")
{
echo "<a class='btn btn-success' target='_blank' href='https://adfree.odiousapps.com/exceptions.php?hostname=${row['hostname']}&whiteblack=white'>Whitelist</a>";
} else {
echo "<a class='btn btn-danger' target='_blank' href='https://adfree.odiousapps.com/exceptions.php?hostname=${row['hostname']}&whiteblack=black'>Blacklist</a>";
}
echo "</td></tr>";
}
echo "</table>";
}
function dnsmasqBlockedHosts($maxlen = 60)
{
global $link;
echo "<table style='width:100%'>\n";
echo "<tr><th style='width:550px;'>Hostname</th><th>DNS Hits</th><th>Action</th></tr>";
$query = "select `hostname`, count(`hostname`) as `hits`, `status` from `dnslog` where `status`='config' and `when` >= now() - INTERVAL 30 DAY group by `hostname` order by count(`hostname`) desc";
$res = mysqli_query($link, $query);
while($row = mysqli_fetch_assoc($res))
{
$len = strlen($row['hostname']);
echo "<tr><td><a href='blacklist.php?hostname=${row['hostname']}' title='${row['hostname']}'>";
echo @substr($row['hostname'], 0, $maxlen);
if($len > $maxlen)
echo "...";
echo "</a></td><td>".$row['hits']."</td><td>";
echo "<a class='btn btn-success' target='_blank' href='https://adfree.odiousapps.com/exceptions.php?hostname=${row['hostname']}&whiteblack=white'>Whitelist</a>";
echo "</td></tr>";
}
echo "</table>";
}
function HostAPd()
{
echo trim(file_get_contents("/var/log/hostapd.log"));
}
function doStats($maxlen = 30)
{
global $link;
$blcount = trim(`cat "/etc/dnsmasq.d/adfree.conf"|wc -l`);
$query = "select count(`hostname`) as `hostnames` from `dnslog` where `when` >= now() - INTERVAL 30 DAY";
$res = mysqli_query($link, $query);
$total = mysqli_fetch_assoc($res)['hostnames'];
$query = "select count(`hostname`) as `hostnames` from `dnslog` where `status`='config' and `when` >= now() - INTERVAL 30 DAY";
$res = mysqli_query($link, $query);
$blocked = mysqli_fetch_assoc($res)['hostnames'];
$percent = round($blocked / $total * 100, 2);
$query = "select count(`client`) as `count` from `dnslog` where `when` >= now() - INTERVAL 30 DAY group by `client`";
$res = mysqli_query($link, $query);
$clis = mysqli_num_rows($res);
?>
<div style="width:23%;height:100px;float:left;border:1px solid;padding:5px;margin:5px;">
<div class="card-block">
<h3 style="text-align:center;"><?=number_format($total)?></h3>
<p style="text-align:center;font-size:0.9em;">Total Queries (<?=$clis?> Cli)</p>
</div>
</div>
<div style="width:23%;height:100px;float:left;border:1px solid;padding:5px;margin:5px;">
<div class="card-block">
<h3 style="text-align:center;"><?=number_format($blocked)?></h3>
<p style="text-align:center;font-size:0.9em;">Queries Blocked</p>
</div>
</div>
<div style="width:23%;height:100px;float:left;border:1px solid;padding:5px;margin:5px;">
<div class="card-block">
<h3 style="text-align:center;"><?=$percent?>%</h3>
<p style="text-align:center;font-size:0.9em;">Percent Blocked</p>
</div>
</div>
<div style="width:23%;height:100px;float:left;border:1px solid;padding:5px;margin:5px;">
<div class="card-block">
<h3 style="text-align:center;"><?=number_format($blcount)?></h3>
<p style="text-align:center;font-size:0.9em,">Hosts in the Blacklist</p>
</div>
</div>
<br style="clear:left">
<table class="stats" style="width:48%;float:left;">
<tr><th>Hostname</th><th>Hits</th></tr>
<?php
$query = "select `hostname`, count(`hostname`) as `count` from `dnslog` where `when` >= now() - INTERVAL 30 DAY group by `hostname` order by count(`hostname`) desc limit 10";
$res = mysqli_query($link, $query);
while($row = mysqli_fetch_assoc($res))
{
$len = strlen($row['hostname']);
echo "<tr><td><a href='blacklist.php?hostname=${row['hostname']}' title='${row['hostname']}'>";
echo @substr($row['hostname'], 0, $maxlen);
if($len > $maxlen)
echo "...";
echo "</a></td><td>${row['count']}</td></tr>\n";
}
?>
</table>
<table class="stats" style="width:48%;float:left;margin-left:10px;">
<tr><th>Client IP</th><th>Requests</th></tr>
<?php
$query = "select `client`, count(`client`) as `count` from `dnslog` where `when` >= now() - INTERVAL 30 DAY group by `client` order by count(`client`) desc limit 10";
$res = mysqli_query($link, $query);
while($row = mysqli_fetch_assoc($res))
{
echo "<tr><td>${row['client']}</td><td>${row['count']}</td></tr>\n";
}
echo "</table>\n";
}