Rev 5 | Go to most recent revision | Blame | Last modification | View Log | RSS feed
#!/usr/bin/php
<?php
#
# VGWhoIs (ViaThinkSoft Global WhoIs, a fork of generic Whois / gwhois)
# Maintenance / Developer utilities
#
# (c) 2012-2019 by Daniel Marschall, ViaThinkSoft <info@daniel-marschall.de>
#
# License: https://www.gnu.org/licenses/gpl-2.0.html (GPL version 2)
#
require_once __DIR__ . '/../../../shared/php_includes/common_functions.inc.php';
$patterns = glob(__DIR__ . '/../../../main/pattern/*');
#$bs = '\\b';
#$be = '\\b';
$vc = '[\p{L}a-zA-Z0-9_\\-\\+\\*\\.]';
$bs = '(?<!'.$vc.')';
$be = '(?!'.$vc.')';
foreach ($patterns as $pattern_file) {
$pattern = file($pattern_file);
$pattern[] = ':end';
$content = '';
foreach ($pattern as $p) {
$p = trim($p);
if ($p == '') continue;
if ($p[0] == '#') continue; // comment
if (preg_match('@^\\^redirect:@ismU', $p, $m)) continue;
$p = str_replace(array('(.*)', '(.+)'), '', $p);
if ($p[0] == ':') {
$content = '';
} else {
if ($p[0] == '=') {
// IP
$p_ = substr($p, 1);
// ignore for now
continue;
} else if ($p[0] == '*') {
// ASN
preg_match('#\*(.*):(\d+)(-(\d+)){0,1}#isU', $p, $m);
$prefix = $m[1];
$min = $m[2];
$max = (isset($m[4])) ? $m[4] : $min;
// ignore for now
continue;
} else if (preg_match('@^(urn:){0,1}oid:(.*)@i', $p, $m)) {
// OIDs
$regex = normalize_oid($m[2]);
$regex = str_replace('.', '\\.0*', $regex);
$regex = '@('.$bs.$regex.'(\\.\\d+)*'.$be.')@iU';
echo "$regex\n";
} else {
// REGEX
$regex = $p;
if ($regex == '.') continue; // last resort
$regex = preg_replace('@(?<!(?<!\\\\)\\$)$@', $vc.'*', $regex);
$regex = preg_replace('@(?<!\\\\)\\$$@', '', $regex);
$regex = preg_replace('@^(?!\\^)@', $vc.'*', $regex);
$regex = preg_replace('@^\\^@', '', $regex);
$regex = preg_replace('@(?>!\\$)$@', $vc.'*', $regex);
$regex = preg_replace('@\\$$@', '', $regex);
$regex = '@('.$bs.$regex.$be.')@iUu';
echo "$regex\n";
}
}
}
}