Merge pull request #233 from nonmakina/ipCounter
Hourly, daily, weekly IP counter
This commit is contained in:
commit
b68daf1607
|
@ -36,7 +36,9 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>{% trans "Board" %}</th>
|
<th>{% trans "Board" %}</th>
|
||||||
<th>{% trans "PPH" %}</th>
|
<th>{% trans "PPH" %}</th>
|
||||||
<th>{% trans "Recent IPs" %}</th>
|
<th>{% trans "IPs last hour" %}</th>
|
||||||
|
<th>{% trans "IPs last day" %}</th>
|
||||||
|
<th>{% trans "IPs last week" %}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -48,7 +50,13 @@
|
||||||
<span>{{ stats.pph }}</span>
|
<span>{{ stats.pph }}</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="minimal">
|
<td class="minimal">
|
||||||
<span>{{ stats.recent_ips }}</span>
|
<span>{{ stats.hourly_ips }}</span>
|
||||||
|
</td>
|
||||||
|
<td class="minimal">
|
||||||
|
<span>{{ stats.daily_ips }}</span>
|
||||||
|
</td>
|
||||||
|
<td class="minimal">
|
||||||
|
<span>{{ stats.weekly_ips }}</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% for boardStat in stats.boards %}
|
{% for boardStat in stats.boards %}
|
||||||
|
@ -60,7 +68,13 @@
|
||||||
<span>{{ boardStat.pph }}</span>
|
<span>{{ boardStat.pph }}</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="minimal">
|
<td class="minimal">
|
||||||
<span>{{ boardStat.recent_ips }}</span>
|
<span>{{ boardStat.hourly_ips }}</span>
|
||||||
|
</td>
|
||||||
|
<td class="minimal">
|
||||||
|
<span>{{ boardStat.daily_ips }}</span>
|
||||||
|
</td>
|
||||||
|
<td class="minimal">
|
||||||
|
<span>{{ boardStat.weekly_ips }}</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -100,8 +100,14 @@
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$HOUR = 3600;
|
||||||
|
$DAY = $HOUR * 24;
|
||||||
|
$WEEK = $DAY * 7;
|
||||||
|
|
||||||
$stats = [];
|
$stats = [];
|
||||||
$unique = [];
|
$hourly = [];
|
||||||
|
$daily = [];
|
||||||
|
$weekly = [];
|
||||||
|
|
||||||
foreach (array_merge(... $config['boards']) as $uri) {
|
foreach (array_merge(... $config['boards']) as $uri) {
|
||||||
$_board = getBoardInfo($uri);
|
$_board = getBoardInfo($uri);
|
||||||
|
@ -112,6 +118,10 @@
|
||||||
|
|
||||||
$boardStat['title'] = $_board['title'];
|
$boardStat['title'] = $_board['title'];
|
||||||
|
|
||||||
|
$boardStat['hourly_ips'] = Categories::countUniqueIps($hourly, $HOUR, $_board);
|
||||||
|
$boardStat['daily_ips'] = Categories::countUniqueIps($daily, $DAY, $_board);
|
||||||
|
$boardStat['weekly_ips'] = Categories::countUniqueIps($weekly, $WEEK, $_board);
|
||||||
|
|
||||||
$pph_query = query(
|
$pph_query = query(
|
||||||
sprintf("SELECT COUNT(*) AS count FROM ``posts_%s`` WHERE time > %d",
|
sprintf("SELECT COUNT(*) AS count FROM ``posts_%s`` WHERE time > %d",
|
||||||
$_board['uri'],
|
$_board['uri'],
|
||||||
|
@ -120,29 +130,30 @@
|
||||||
|
|
||||||
$boardStat['pph'] = $pph_query->fetch()['count'];
|
$boardStat['pph'] = $pph_query->fetch()['count'];
|
||||||
|
|
||||||
$unique_query = query(
|
|
||||||
sprintf("SELECT DISTINCT ip FROM ``posts_%s`` WHERE time > %d",
|
|
||||||
$_board['uri'],
|
|
||||||
time()-3600)
|
|
||||||
) or error(db_error());
|
|
||||||
|
|
||||||
$unique_ips = $unique_query->fetchAll();
|
|
||||||
$boardStat['recent_ips'] = count($unique_ips);
|
|
||||||
|
|
||||||
foreach ($unique_ips as $_k => $row) {
|
|
||||||
$unique[$row['ip']] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$stats['boards'][] = $boardStat;
|
$stats['boards'][] = $boardStat;
|
||||||
}
|
}
|
||||||
|
|
||||||
$stats['recent_ips'] = count($unique);
|
$stats['hourly_ips'] = count($hourly);
|
||||||
|
$stats['daily_ips'] = count($daily);
|
||||||
|
$stats['weekly_ips'] = count($weekly);
|
||||||
$stats['pph'] = array_sum(array_column($stats['boards'], 'pph'));
|
$stats['pph'] = array_sum(array_column($stats['boards'], 'pph'));
|
||||||
|
|
||||||
return $stats;
|
return $stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function countUniqueIps($markAsCounted, $timespan, $_board) {
|
||||||
|
$unique_query = query(
|
||||||
|
sprintf("SELECT DISTINCT ip FROM ``posts_%s`` WHERE time > %d",
|
||||||
|
$_board['uri'],
|
||||||
|
time()-$timespan)
|
||||||
|
) or error(db_error());
|
||||||
|
$uniqueIps = $unique_query->fetchAll();
|
||||||
|
foreach ($uniqueIps as $_k => $row) {
|
||||||
|
$markAsCounted[$row['ip']] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count($uniqueIps);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue