| Server IP : 159.223.102.202 / Your IP : 216.73.216.193 Web Server : nginx/1.26.0 System : Linux Gen1-cloudpanel2ubuntu2404-1vcpu-1gb-nyc1-01 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64 User : albasshbotta ( 1021) PHP Version : 8.2.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /proc/self/cwd/licen/ |
Upload File : |
<?php
/*
$ip = new IpBlock();
var_dump($ip->validateIp());
$ip->addIpBlock("127.0.0.1");
//para guardar los hash
$ipNew = new IpBlock("hash_usados.ls", "back/",".bak");
$ipNew->addIpBlock("asdfasdfdbgsdfbv");
var_dump($ip->validateHash("asdfasdfdbgsdfbv"));
var_dump( $ipNew->getPathFile() );
die;
*/
class IpBlock{
private $path_file = "ip_blocks.ls";
private $prefijo_bak = "back/";
private $ext_bak = ".bak";
public function getPathFile(){
return $this->path_file;
}
public function __construct( ) {
$args = func_get_args();
switch (func_num_args()) {
case 3:
if(isset( $args[0] ) ){
$this->path_file = $args[0] ;
}
if(isset( $args[1] ) ){
$this->prefijo_bak = $args[1] ;
}
if(isset( $args[2] ) ){
$this->ext_bak = $args[2] ;
}
break;
default:
break;
}
}
public function addIpBlock($ipToBlock){
try{
$items_recuperados = $this->readJsonIp();
if( in_array($ipToBlock, $items_recuperados ) ){
}else{
array_push($items_recuperados, $ipToBlock);
if( copy( $this->path_file, $this->name_back() )) {
file_put_contents( $this->path_file, json_encode($items_recuperados));
}
}
return true;
}catch(Excepcion $ex){
return false;
}
}
/**
* Add hash, re-usando el bloque addHashBlock
*/
public function addHashBlock( $hashBlock ){
return $this->addIpBlock( $hashBlock );
}
public function readJsonIp(){
try{
$content = file_get_contents($this->path_file);
$items_recuperados = json_decode($content);
if( isset($items_recuperados) && count($items_recuperados) > 0 ){
}else{
$items_recuperados = array();
}
return $items_recuperados;
}catch(Excepcion $ex){
return array();
}
}
public function validateIp( $ipTest = null ){
$ipTest = isset($ipTest) ? $ipTest : $this->get_client_ip() ;
try{
if( in_array($ipTest, $this->readJsonIp()) ){
return false;
}else{
return true;
}
}catch(Excepcion $ex){
return true;
}
}
/**
* Validar hash, si ya existe, retorna false.
*/
public function validateHash( $hashTest ){
return $this->validateIp( $hashTest );
}
private function name_back(){
return $this->prefijo_bak . date('Y-m-d_h-i-s') . $this->path_file . $this->ext_bak;
}
public function get_client_ip() {
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
}
?>