PATH:
home
/
centosnipponia
/
public_html
/
nipponiacom2
/
libraries
/
regularlabs
/
src
/
Condition
<?php /** * @package Regular Labs Library * @version 19.2.10100 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2019 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; /** * Class Ip * @package RegularLabs\Library\Condition */ class Ip extends \RegularLabs\Library\Condition { public function pass() { if (is_array($this->selection)) { $this->selection = implode(',', $this->selection); } $this->selection = explode(',', str_replace([' ', "\r", "\n"], ['', '', ','], $this->selection)); $pass = $this->checkIPList(); return $this->_($pass); } private function checkIPList() { foreach ($this->selection as $range) { // Check next range if this one doesn't match if ( ! $this->checkIP($range)) { continue; } // Match found, so return true! return true; } // No matches found, so return false return false; } private function checkIP($range) { if (empty($range)) { return false; } if (strpos($range, '-') !== false) { // Selection is an IP range return $this->checkIPRange($range); } // Selection is a single IP (part) return $this->checkIPPart($range); } private function checkIPRange($range) { $ip = $_SERVER['REMOTE_ADDR']; // Return if no IP address can be found (shouldn't happen, but who knows) if (empty($ip)) { return false; } // check if IP is between or equal to the from and to IP range list($min, $max) = explode('-', trim($range), 2); // Return false if IP is smaller than the range start if ($ip < trim($min)) { return false; } $max = $this->fillMaxRange($max, $min); // Return false if IP is larger than the range end if ($ip > trim($max)) { return false; } return true; } /* Fill the max range by prefixing it with the missing parts from the min range * So 101.102.103.104-201.202 becomes: * max: 101.102.201.202 */ private function fillMaxRange($max, $min) { $max_parts = explode('.', $max); if (count($max_parts) == 4) { return $max; } $min_parts = explode('.', $min); $prefix = array_slice($min_parts, 0, count($min_parts) - count($max_parts)); return implode('.', $prefix) . '.' . implode('.', $max_parts); } private function checkIPPart($range) { $ip = $_SERVER['REMOTE_ADDR']; // Return if no IP address can be found (shouldn't happen, but who knows) if (empty($ip)) { return false; } $ip_parts = explode('.', $ip); $range_parts = explode('.', trim($range)); // Trim the IP to the part length of the range $ip = implode('.', array_slice($ip_parts, 0, count($range_parts))); // Return false if ip does not match the range if ($range != $ip) { return false; } return true; } }
[+]
..
[-] Agent.php
[edit]
[-] AgentBrowser.php
[edit]
[-] AgentDevice.php
[edit]
[-] AgentOs.php
[edit]
[-] Akeebasubs.php
[edit]
[-] AkeebasubsLevel.php
[edit]
[-] AkeebasubsPagetype.php
[edit]
[-] Component.php
[edit]
[-] Content.php
[edit]
[-] ContentArticle.php
[edit]
[-] ContentCategory.php
[edit]
[-] ContentPagetype.php
[edit]
[-] Cookieconfirm.php
[edit]
[-] Date.php
[edit]
[-] DateDate.php
[edit]
[-] DateDay.php
[edit]
[-] DateMonth.php
[edit]
[-] DateSeason.php
[edit]
[-] DateTime.php
[edit]
[-] Easyblog.php
[edit]
[-] EasyblogCategory.php
[edit]
[-] EasyblogItem.php
[edit]
[-] EasyblogKeyword.php
[edit]
[-] EasyblogPagetype.php
[edit]
[-] EasyblogTag.php
[edit]
[-] Flexicontent.php
[edit]
[-] FlexicontentPagetype.php
[edit]
[-] FlexicontentTag.php
[edit]
[-] FlexicontentType.php
[edit]
[-] Form2content.php
[edit]
[-] Form2contentProject.php
[edit]
[-] Geo.php
[edit]
[-] GeoContinent.php
[edit]
[-] GeoCountry.php
[edit]
[-] GeoPostalcode.php
[edit]
[-] GeoRegion.php
[edit]
[-] Hikashop.php
[edit]
[-] HikashopCategory.php
[edit]
[-] HikashopPagetype.php
[edit]
[-] HikashopProduct.php
[edit]
[-] Homepage.php
[edit]
[-] Ip.php
[edit]
[-] K2.php
[edit]
[-] K2Category.php
[edit]
[-] K2Item.php
[edit]
[-] K2Pagetype.php
[edit]
[-] K2Tag.php
[edit]
[-] Language.php
[edit]
[-] Menu.php
[edit]
[-] Mijoshop.php
[edit]
[-] MijoshopCategory.php
[edit]
[-] MijoshopPagetype.php
[edit]
[-] MijoshopProduct.php
[edit]
[-] Php.php
[edit]
[-] Redshop.php
[edit]
[-] RedshopCategory.php
[edit]
[-] RedshopPagetype.php
[edit]
[-] RedshopProduct.php
[edit]
[-] Tag.php
[edit]
[-] Template.php
[edit]
[-] Url.php
[edit]
[-] User.php
[edit]
[-] UserAccesslevel.php
[edit]
[-] UserGrouplevel.php
[edit]
[-] UserUser.php
[edit]
[-] Virtuemart.php
[edit]
[-] VirtuemartCategory.php
[edit]
[-] VirtuemartPagetype.php
[edit]
[-] VirtuemartProduct.php
[edit]
[-] Zoo.php
[edit]
[-] ZooCategory.php
[edit]
[-] ZooItem.php
[edit]
[-] ZooPagetype.php
[edit]
[-] .htaccess.disabled
[edit]