ip=$anIp; $this->ipFile = self::getIpFile( $this->ip ); $myIpFile = $this->getFile(); if ( is_file( $myIpFile ) ) { $myIp = unserialize( file_get_contents( $myIpFile ) ); $this->ipDir=$myIp->ipDir; $this->whoisData=$myIp->whoisData; $this->tentative=$myIp->tentative; //$this->ipSessions=$myIp->ipSessions; } else { $this->tentative=0; //$this->ipSessions=new \darkauth\db\session\DwIpSessions(); while ( is_dir( $this->getDir() ) ) $this->ipDir++; $myIpDir=$this->getDir(); mkdir( $myIpDir ); $data = array(); foreach( \darkphp\string\DwString::explodeByTwoNewLine( \shell_exec("whois -B {$anIp} 2>&1") ) as $strWhois ) { $dataClear = array(); $matches = array(); if ( preg_match_all('/([^\n\:]*)\:\s+(.*)\n/m' ,$strWhois ,$matches ) ) { foreach( $matches[1] as $idx => $key ) { if ( ! isset( $dataClear[ $key ] ) ) $dataClear[ $key ] = array(); $dataClear[ $key ][]=$matches[2][ $idx ]; } $data[]=$dataClear; } } //die( print_r( $data ,true ) ); $this->whoisData = $data; file_put_contents( $this->getFile() ,serialize( $this ) ); } } public function getBrowsers() : array { $browsers = array(); foreach( scandir( $this->getDir() ) as $myPath ) if ( is_file( $myPath ) ) $browsers[] = unserialize( "{$this->getDir()}/{$myPath}" ); return $browsers; } public function writeXml( $xml ,$child ) { $xmlIp = $xml->createElement( "ip" ); $child->appendChild( $xmlIp ); $xmlIp->setAttribute("ipDir", $this->ipDir ); $xmlIp->appendChild( $xml->createElement( "address", $this->ip ) ); $xmlIp->appendChild( $xml->createElement( "ipDir", $this->ipDir ) ); $missingKey=array(); if ( is_array($this->whoisData) ) foreach( $this->whoisData as $whoisData ) { $xmlWhois=$xml->createElement( "whois" ); $xmlIp->appendChild( $xmlWhois ); foreach( $whoisData as $key => $whoisData ) if ( is_array( $whoisData ) ) foreach( $whoisData as $subValue ) $xmlWhois->appendChild( $xml->createElement( $key, htmlentities( $subValue ) ) ); } //file_put_contents( \darkauth\DwDarkAuth::getDataPath( ).'/.auth/missing.dbphp' ,serialize( $missingKey ) ); return $xmlIp; } // /darkauth\db\auth\Ip::listToXml( $xml ,$child ) public static function listToXml( $xml ,$child ) { $xmlIps = $xml->createElement( "ips" ); $child->appendChild( $xmlIps ); foreach( scandir( self::$ipsDir ) as $anValue ) if ( $anValue=="." || $anValue==".." ) continue; elseif ( is_file( ( $serializedFile = self::$ipsDir."/$anValue" ) ) ) ( unserialize( file_get_contents( $serializedFile ) ) )->writeXml( $xml, $xmlIps ); return $xmlIps; } public function getDir() { return self::$ipsDir."/ip-".$this->ipDir; } public function getFile() { return self::getIpFilePath( $this->ipFile ); } // \darkauth\db\auth\Ip::getIpFile( $anIp ); public static function getIpFile( string $anIp ) : string { return str_replace( array('.',':') ,'-', $anIp); } public static function getIpFilePath( string $ipFile ) : string { return self::$ipsDir."/".$ipFile.".dbphp"; } // \darkauth\db\auth\Ip::fromApache2authTentative( $_SERVER ); public static function fromApache2authTentative( $myServer ) : int { $answer=-1; $myIpFile=self::getIpFilePath( self::getIpFile( $myServer['REMOTE_ADDR'] ) ); if ( is_file( $myIpFile ) ) { $myIp = unserialize( file_get_contents( $myIpFile ) ); $myIp->tentative++; file_put_contents( $myIpFile ,serialize( $myIp ) ); $answer=$myIp->tentative; } else $answer=0; return $answer; } // \darkauth\db\auth\Ip::getTentativeCompteur( $ip ); public static function getTentativeCompteur( $ip ) : int { $answer=-1; $myIpFile=self::getIpFilePath( self::getIpFile( $ip ) ); if ( is_file( $myIpFile ) ) { $myIp = unserialize( file_get_contents( $myIpFile ) ); $answer=$myIp->tentative; } else $answer=0; return $answer; } // \darkauth\db\auth\Ip::fromApache2getTentativeCompteur( $_SERVER ); public static function fromApache2getTentativeCompteur( $myServer ) : int { return self::getTentativeCompteur( $myServer['REMOTE_ADDR'] ); } // \darkauth\db\auth\Ip::fromApache2( $_SERVER ); public static function fromApache2( $myServer ) : ?self { return new Ip( $myServer['REMOTE_ADDR'] ); } } \darkauth\db\auth\Ip::init(); ?>