first commit

This commit is contained in:
2023-09-12 21:41:04 +02:00
commit 3361a7f053
13284 changed files with 2116755 additions and 0 deletions

View File

@@ -0,0 +1,104 @@
<?php
if (!defined('WORDFENCE_VERSION')) { exit; }
require_once(dirname(__FILE__) . '/../../vendor/autoload.php');
use GeoIp2\Database\Reader;
class wfGeoIP2 {
const DB_WFLOGS = 'wflogs';
const DB_BUNDLED = 'bundled';
static $_shared = array();
private $_reader;
/**
* Returns the singleton wfGeoIP2, optionally forcing use of a specific database.
*
* @return wfGeoIP2|bool
*/
public static function shared($whichDB = false) {
try {
if (file_exists(WFWAF_LOG_PATH . '/GeoLite2-Country.mmdb') && ($whichDB === false || $whichDB == self::DB_WFLOGS)) {
if (isset(self::$_shared[self::DB_WFLOGS])) {
return self::$_shared[self::DB_WFLOGS];
}
$reader = new Reader(WFWAF_LOG_PATH . '/GeoLite2-Country.mmdb');
self::$_shared[self::DB_WFLOGS] = new wfGeoIP2($reader);
return self::$_shared[self::DB_WFLOGS];
}
}
catch (Exception $e) {
//Fall through to bundled copy
}
if ($whichDB == self::DB_WFLOGS) {
return false;
}
if (isset(self::$_shared[self::DB_BUNDLED])) {
return self::$_shared[self::DB_BUNDLED];
}
$reader = new Reader(__DIR__ . '/../../lib/GeoLite2-Country.mmdb'); //Can throw, but we don't catch it here
self::$_shared[self::DB_BUNDLED] = new wfGeoIP2($reader);
return self::$_shared[self::DB_BUNDLED];
}
/**
* Automatically uses the wflogs version of the DB if present, otherwise uses the bundled one.
*
* @param \GeoIp2\Database\Reader $reader If provided, uses the reader passed instead.
*/
public function __construct($reader = false) {
if ($reader !== false) {
$this->_reader = $reader;
return;
}
try {
if (file_exists(WFWAF_LOG_PATH . '/GeoLite2-Country.mmdb')) {
$this->_reader = new Reader(WFWAF_LOG_PATH . '/GeoLite2-Country.mmdb');
return;
}
}
catch (Exception $e) {
//Fall through to bundled copy
}
$this->_reader = new Reader(__DIR__ . '/../../lib/GeoLite2-Country.mmdb'); //Can throw, but we don't catch it because it means the installation is likely corrupt and needs fixed anyway
}
/**
* Returns the database version in use. This is the timestamp of when it was packaged.
*
* @return null|int
*/
public function version() {
try {
return $this->_reader->metadata()->buildEpoch;
}
catch (Exception $e) {
//Fall through
}
return null;
}
/**
* Returns the country code for the IP if known.
*
* @param string $ip
* @return null|string
*/
public function countryCode($ip) {
try {
$record = $this->_reader->country($ip);
return $record->country->isoCode;
}
catch (Exception $e) {
//Fall through
}
return null;
}
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* Defines a UI tab.
*
* @property string $id
* @property string $a
* @property string $tabTitle
* @property string $pageTitle
* @property bool $active
*/
class wfTab {
protected $_id;
protected $_a;
protected $_tabTitle;
protected $_pageTitle;
protected $_active;
public function __construct($id, $a, $tabTitle, $pageTitle, $active = false) {
$this->_id = $id;
$this->_a = $a;
$this->_tabTitle = $tabTitle;
$this->_pageTitle = $pageTitle;
$this->_active = $active;
}
public function __get($name) {
switch ($name) {
case 'id':
return $this->_id;
case 'a':
return $this->_a;
case 'tabTitle':
return $this->_tabTitle;
case 'pageTitle':
return $this->_pageTitle;
case 'active':
return $this->_active;
}
throw new OutOfBoundsException('Invalid key: ' . $name);
}
}