Example #1
0
 public static function test($_mode = 'external', $_test = true, $_timeout = 10)
 {
     if (config::byKey('network::disableMangement') == 1) {
         return true;
     }
     if ($_mode == 'internal' && netMatch('127.0.*.*', self::getNetworkAccess($_mode, 'ip', '', false))) {
         return false;
     }
     $url = trim(self::getNetworkAccess($_mode, '', '', $_test), '/') . '/here.html';
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_TIMEOUT, $_timeout);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($ch, CURLOPT_HEADER, false);
     if ($_mode == 'external') {
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     }
     $data = curl_exec($ch);
     if (curl_errno($ch)) {
         log::add('network', 'debug', 'Erreur sur ' . $url . ' => ' . curl_errno($ch));
         curl_close($ch);
         return false;
     }
     curl_close($ch);
     if (trim($data) != 'ok') {
         log::add('network', 'debug', 'Retour NOK sur ' . $url . ' => ' . $data);
         return false;
     }
     return true;
 }
Example #2
0
 public function preSave()
 {
     $this->setDatetime(date('Y-m-d H:i:s'));
     if ($this->getId() == '') {
         $connection = connection::byIp($this->getIp());
         if (is_object($connection)) {
             $this->setId($connection->getId());
         }
     }
     if ($this->getLocalisation() == '' && !netMatch('192.*.*.*', $this->getIp()) && !netMatch('127.0.0.1', $this->getIp()) && !netMatch('10.*.*.*', $this->getIp())) {
         try {
             $http = new com_http('http://ipinfo.io/' . $this->getIp());
             $http->setLogError(false);
             $details = json_decode($http->exec(1, 2), true);
             $localisation = '';
             if (is_array($details)) {
                 if (isset($details['country'])) {
                     $localisation .= $details['country'] . ' - ';
                 }
                 if (isset($details['region'])) {
                     $localisation .= $details['region'] . ' - ';
                 }
                 if (isset($details['postal'])) {
                     $localisation .= ' (' . $details['postal'] . ') ';
                 }
                 if (isset($details['city'])) {
                     $localisation .= $details['city'] . ' - ';
                 }
                 $this->setLocalisation($localisation);
                 if (isset($details['loc'])) {
                     $this->setInformations('coordonate', $details['loc']);
                 }
                 if (isset($details['org'])) {
                     $this->setInformations('org', $details['org']);
                 }
                 if (isset($details['hostname'])) {
                     $this->setInformations('hostname', $details['hostname']);
                 }
             }
         } catch (Exception $e) {
             $this->setLocalisation('Unknow');
         }
     }
 }
Example #3
0
<?php

function netMatch($client_ip, $server_ip, $mask)
{
    $mask1 = 32 - $mask;
    $longip = ip2long($client_ip);
    echo $longip;
    echo "\n";
    $maskip = $longip >> $mask1;
    echo $maskip;
    echo "\n";
    $maskip = $longip >> $mask1;
    $serip = ip2long($server_ip);
    $maskser = $serip >> $mask1;
    echo $serip . "\n" . $maskser;
    if (ip2long($client_ip) >> $mask1 == ip2long($server_ip) >> $mask1) {
        return 1;
    } else {
        return 0;
    }
}
$client_ip = '192.168.41.15';
$server_ip = '192.168.190.0';
$mask = 16;
$res = netMatch($client_ip, $server_ip, $mask);
echo "\n" . $res;