improved IpV6 support
This commit is contained in:
parent
553d7d8be1
commit
a66d2dc21f
3 changed files with 20 additions and 5 deletions
|
@ -12,13 +12,14 @@ $sql = 'SELECT *
|
|||
|
||||
$result = $db->query($sql);
|
||||
|
||||
$pattern = '/^queries: info: client ([.\d]+)#(\d+): query: ([+.-\w]+) ([A-Z]+) ([0-9A-Z]+) ([-+A-Z]+) \(([.\d]+)\)$/';
|
||||
$pattern = '/^queries: info: client ([:.0-9a-f]+)#(\d+): query: ([+.-\w]+) ([A-Z]+) ([0-9A-Z]+) ([-+A-Z]+) \(([:.0-9a-f]+)\)$/';
|
||||
$queries = array();
|
||||
$update = array();
|
||||
$delete = array();
|
||||
|
||||
foreach ($result as $log) {
|
||||
if (preg_match($pattern, $log['message'], $matches)) {
|
||||
$query = array('ip' => new IpV4($matches[1]),
|
||||
$query = array('ip' => (strpos($matches[1], ':') === FALSE) ? new IpV4($matches[1]) : new IpV6($matches[1]),
|
||||
'port' => (int) $matches[2],
|
||||
'hostname' => $matches[3],
|
||||
'class' => $matches[4],
|
||||
|
@ -75,7 +76,13 @@ foreach ($update as $record) {
|
|||
|
||||
$output->add('record renewed', 'success', $record, date('Y-m-d H:m:s', $record->lastAccessed));
|
||||
}
|
||||
$output->add('renewed records', 'success', $updated);
|
||||
|
||||
if ($updated > 0) {
|
||||
$output->add('renewed records', 'success', $updated);
|
||||
}
|
||||
else {
|
||||
$output->add('no records updated', 'warning');
|
||||
}
|
||||
|
||||
$output->send();
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class IpV4 implements Object {
|
|||
public function __construct($ipString) {
|
||||
if (self::isValid($ipString)) {
|
||||
$this->tuples = explode('.', $ipString);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new ValidationException('Invalid IP: ', $ipString);
|
||||
}
|
||||
|
|
10
ip.php
10
ip.php
|
@ -3,7 +3,15 @@
|
|||
require_once 'include/init.php';
|
||||
$output = Output::start();
|
||||
|
||||
$ip = new IpV4($_SERVER['REMOTE_ADDR']);
|
||||
if (IpV4::isValid($_SERVER['REMOTE_ADDR'])) {
|
||||
$ip = new IpV4($_SERVER['REMOTE_ADDR']);
|
||||
}
|
||||
else if (IpV6::isValid($_SERVER['REMOTE_ADDR'])) {
|
||||
$ip = new IpV6($_SERVER['REMOTE_ADDR']);
|
||||
}
|
||||
else {
|
||||
$output->add('can\'t determine remote addr', 'error', $_SERVER['REMOTE_ADDR']);
|
||||
}
|
||||
|
||||
$output->add('your current internet ip address', 'notice', $ip);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue