Пример #1
0
 /**
  * 获取客户端城市IP地址
  */
 public static function getCityIP($value)
 {
     Yii::import('application.extensions.17mon.*');
     require_once 'IP.class.php';
     //IP::init();
     $ip = IP::find($value);
     //'106.185.24.112'
     return $ip;
 }
Пример #2
0
 /**
  * Set Ip address
  * 
  * @param string $ip ipaddress
  * 
  * @return void
  */
 public function setIp($ip)
 {
     if (!class_exists('IP')) {
         include dirname(__FILE__) . "/../third_party/ipip/IP.class.php";
     }
     $loc = IP::find($ip);
     if ($loc == 'N/A') {
         return;
     }
     if (isset($loc[0]) && $loc[0] != '') {
         $this->country = $loc[0];
     }
     if (isset($loc[1]) && $loc[1] != '') {
         $this->region = $loc[1];
     }
     if (isset($loc[2]) && $loc[2] != '') {
         $this->city = $loc[2];
     }
 }
 public function findOrCreate()
 {
     global $_COOKIE, $_SERVER;
     if (isset($_COOKIE['_webim_visitor_id'])) {
         $id = $_COOKIE['_webim_visitor_id'];
     } else {
         $id = substr(uniqid(), 6);
         setcookie('_webim_visitor_id', $id, time() + 3600 * 24 * 30, "/", "");
     }
     $vid = 'vid:' . $id;
     $visitor = $this->where('name', $vid)->find();
     if (!$visitor) {
         $ipaddr = isset($_SERVER['X-Forwarded-For']) ? $_SERVER['X-Forwarded-For'] : $_SERVER["REMOTE_ADDR"];
         $loc = IP::find($ipaddr);
         if (is_array($loc)) {
             $loc = implode('', $loc);
         }
         $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
         $this->create(array("name" => $vid, "ipaddr" => $ipaddr, "url" => $_SERVER['REQUEST_URI'], "referer" => $referer, "location" => $loc));
         $this->created = date('Y-m-d H:i:s');
         $this->add();
     }
     return (object) array('id' => $vid, 'nick' => "v" . $id, 'group' => "visitor", 'presence' => 'online', 'show' => "available", 'avatar' => WEBIM_IMAGE('male.png'), 'role' => 'visitor', 'url' => "#", 'status' => "");
 }
Пример #4
0
 /**
  * Get visitor
  */
 function visitor()
 {
     global $_COOKIE, $_SERVER;
     if (isset($_COOKIE['_webim_visitor_id'])) {
         $id = $_COOKIE['_webim_visitor_id'];
     } else {
         $id = substr(uniqid(), 6);
         setcookie('_webim_visitor_id', $id, time() + 3600 * 24 * 30, "/", "");
     }
     $vid = 'vid:' . $id;
     $visitor = $this->T('visitors')->where('name', $vid)->findOne();
     if (!$visitor) {
         $ipaddr = isset($_SERVER['X-Forwarded-For']) ? $_SERVER['X-Forwarded-For'] : $_SERVER["REMOTE_ADDR"];
         require_once dirname(__FILE__) . '/../vendor/webim/geoip-php/IP.class.php';
         $loc = \IP::find($ipaddr);
         if (is_array($loc)) {
             $loc = implode('', $loc);
         }
         $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
         $visitor = $this->T('visitors')->create();
         $visitor->set(array("name" => $vid, "ipaddr" => $ipaddr, "url" => $_SERVER['REQUEST_URI'], "referer" => $referer, "location" => $loc))->setExpr('created', 'NOW()');
         $visitor->save();
     }
     return (object) array('id' => $vid, 'nick' => "v" . $id, 'group' => "visitor", 'presence' => 'online', 'show' => "available", 'avatar' => WEBIM_IMAGE('male.png'), 'role' => 'visitor', 'url' => "#", 'status' => "");
 }
Пример #5
0
 /**
  * Save admin login log. 
  * 
  * @param  string $account 
  * @access public
  * @return bool
  */
 public function saveLog($account, $result)
 {
     $this->app->loadClass('IP');
     $ip = helper::getRemoteIP();
     $location = IP::find($ip);
     $extData = new stdclass();
     $extData->userAgent = $this->server->http_user_agent;
     $data = new stdclass();
     $data->account = $account;
     $data->date = helper::now();
     $data->ip = $ip;
     $data->location = is_array($location) ? join(' ', $location) : $location;
     $data->browser = helper::getBrowser() . ' ' . helper::getBrowserVersion();
     $data->type = 'adminlogin';
     $data->desc = $result;
     $data->lang = 'all';
     $data->ext = json_encode($extData);
     $this->dao->insert(TABLE_LOG)->data($data)->exec();
     return !dao::isError();
 }
Пример #6
0
 public function deleteAssets()
 {
     if (Session::has('username') && Session::get('user_type') == "Root") {
         $ip = Input::get("ip_id");
         $hasDeletedAny = false;
         $noOfDeletedAssets = 0;
         foreach ($ip as $s) {
             $ip = IP::find($s);
             if (!$ip) {
                 continue;
             }
             $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has deleted IP asset ( type: " . $ip->type . ") <strong>" . $ip->ip . "</strong>.";
             //Log the changes made
             $newLog = new UserLog();
             $newLog->description = $desc;
             $newLog->user_id = Session::get('user_id');
             $newLog->type = "System";
             $newLog->save();
             $hasDeletedAny = true;
             $noOfDeletedAssets += 1;
             $ip->delete();
         }
         if ($hasDeletedAny) {
             $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has deleted <strong>" . $noOfDeletedAssets . "</strong> IP asset(s).";
             //Log the changes made
             $newLog = new UserLog();
             $newLog->description = $desc;
             $newLog->user_id = Session::get('user_id');
             $newLog->type = "System";
             $newLog->save();
         }
         return Redirect::to(Session::get("page"));
     } else {
         return Redirect::to("/");
     }
 }
Пример #7
0
<?php

header('Content-Type: text/html; charset=utf-8');
require 'IP.class.php';
$ip_list = array('8.8.8.8', '192.168.0.1', '211.144.86.221', '121.201.7.36');
foreach ($ip_list as $ip) {
    echo $ip . ": " . implode('', IP::find($ip)) . '<br>';
}
Пример #8
0
//$panel = '<div class="btn-group" role="group">'.
//    Html::a("普通访客", ['index'], ['class' => 'btn btn-default'.($type != 'regUser' ? ' active': '')]).
//    Html::a("注册用户", ['index','type'=>'regUser'], ['class' => 'btn btn-default'.($type == 'regUser' ? ' active': '')]).
//'</div>';
//&filter_offset=40&filter_limit=20
$panel = "";
$columns = [['class' => 'yii\\grid\\SerialColumn'], ['value' => function ($data) {
    return $data['serverDatePrettyFirstAction'] . '-' . $data['serverTimePrettyFirstAction'];
}, 'header' => '访问时间'], ['value' => 'visitorId', 'header' => '唯一标识'], ['value' => function ($data) {
    if ($data['visitorType'] == 'new') {
        return '新访客';
    } else {
        return '老访客-第' . $data['visitCount'] . '次访问';
    }
}, 'header' => '访客类别'], ['value' => 'visitIp', 'header' => '访客Ip'], ['value' => function ($data) {
    return implode(" ", IP::find($data["visitIp"]));
}, 'header' => 'ip归属地'], ['value' => 'referrerTypeName', 'header' => '来源'], ['format' => 'raw', 'value' => function ($data) {
    return \kartik\helpers\Html::a($data["referrerName"], $data["referrerSearchEngineUrl"]);
}, 'header' => '搜索引擎名称'], ['format' => 'raw', 'value' => function ($data) {
    return Html::a($data["referrerKeyword"], $data["referrerUrl"]);
}, 'header' => '关键词']];
?>


<div class="brand-index">
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => \app\helpers\StatColumns::getRegUserColumns(), 'pjax' => true, 'headerRowOptions' => ['class' => 'kartik-sheet-style'], 'filterRowOptions' => ['class' => 'kartik-sheet-style'], 'export' => false, 'condensed' => true, 'hover' => true, 'panel' => ['heading' => '', 'type' => GridView::TYPE_SUCCESS, 'before' => $panel, 'after' => \app\helpers\Page::preNext()]]);
?>

</div>
Пример #9
0
 private static function parse($string)
 {
     $string = trim($string);
     $int = intval($string);
     if ($int == 0) {
         $tmp = preg_match('/^traceroute.*?\\((.*?)\\)/', $string, $match);
         if ($tmp > 0 && isset($match[1])) {
             $ip = $match[1];
             echo "<script>parent.resp_ip('" . $ip . ")</script>";
             ob_flush();
             flush();
             return [];
         }
     }
     $route = [];
     $string = str_replace('[*]', '[_]', $string);
     $string = str_replace('!X', '', $string);
     $string = str_replace('!N ', '', $string);
     $string = str_replace('!H ', '', $string);
     $array = preg_split('/(\\s+ms\\s*)|(\\*)/', preg_replace('/^\\d+\\s/', '', $string), -1);
     $array = array_map('trim', $array);
     foreach (array_slice($array, 0, 3) as $value) {
         $match = [];
         if (preg_match('/^(?:(.+?)\\s+)?\\((\\d+\\.\\d+\\.\\d+\\.\\d+)\\)\\s+(?:\\[(.*?)\\]\\s+)?([\\.|\\d]+?)$/', trim($value), $match) > 0) {
             $last = $match;
         } elseif (isset($last)) {
             $last[4] = $value;
             $match = $last;
         }
         array_shift($match);
         if (count($match) == 4) {
             $match = array_combine(['host', 'ip', 'as', 'time'], $match);
             if (empty($match['host'])) {
                 $match['host'] = '*';
             }
             $route[] = array_map(function ($v) {
                 return trim($v);
             }, $match);
         } else {
             $route[] = ['host' => '*', 'ip' => '*', 'as' => '*', 'time' => '*'];
         }
     }
     foreach ($route as $k => $v) {
         if ($v['as'] === '_') {
             $route[$k]['as'] = '*';
         } else {
             if (is_array($route[$k]['as'])) {
                 //
             } elseif (stripos($route[$k]['as'], '/') !== FALSE) {
                 $route[$k]['as'] = explode('/', strtr($route[$k]['as'], ['>' => '*', '<' => '*']));
             }
             $route[$k]['as'] = implode(' / ', (array) $route[$k]['as']);
         }
         if (empty($v['time']) === TRUE) {
             $route[$k] = array('host' => '*', 'ip' => '*', 'as' => '*', 'time' => '*');
         } else {
             //
         }
     }
     foreach ($route as $k => $v) {
         if ($v['time'] != '*' && empty($v['time']) === FALSE) {
             $v['time'] = round($v['time'], 1);
             $route[$k] = $v;
         }
         if ($v['ip'] == '*') {
             $v['as'] = '*';
             $v['area'] = '';
         } else {
             $v['area'] = implode(' ', \IP::find($v['ip']));
         }
         $route[$k] = $v;
     }
     /*
             if (count($route) == 3 && $route[0]['host'] === $route[1]['host'] && $route[1]['host'] === $route[2]['host'])
             {
                 if ($route[0]['host'] !== '*')
                 {
                     $route[0]['time'] = $route[0]['time'] . " / " . $route[1]['time']. " / " . $route[2]['time'];
                 }
                 unset($route[1], $route[2]);
             }
     */
     if (count($route) == 3) {
         $_hosts = [];
         for ($i = 0; $i < count($route); $i++) {
             $_hosts[] = $route[$i]['host'];
         }
         if (count(array_unique($_hosts)) == 1) {
             if ($route[0]['host'] !== '*') {
                 $route[0]['time'] = $route[0]['time'] . " / " . $route[1]['time'] . " / " . $route[2]['time'];
             }
             unset($route[1], $route[2]);
         }
     }
     return $route;
 }
Пример #10
0
    $response['Content-Type'] = 'application/javascript';
    $response['Cache-Control'] = 'no-cache';
    $app->render('webim/load.js', array('json' => $json));
})->name('load');
$trackVisitor = function () use($app) {
    if (isset($_SESSION['uid'])) {
        return;
        //user, nothing to do
    }
    $vid = $app->getCookie('webim.vid');
    if ($vid) {
        $req = $app->request();
        $visitor = ORM::forTable('visitors')->findOne($vid);
        if ($visitor) {
            //update visitor
            $loc = IP::find($_SERVER['REMOTE_ADDR']);
            if (is_array($loc)) {
                $loc = implode('', $loc);
            }
            $visitor->set(array('name' => 'v' . $vid, 'ipaddr' => $_SERVER['REMOTE_ADDR'], 'url' => $req->params('siteurl'), 'referer' => $req->params('sitereferer'), 'location' => $loc, 'status' => 1))->set_expr('updated_at', 'NOW()');
            $visitor->save();
            //insert track
            $track = ORM::forTable('tracks')->create();
            $track->set(array('vid' => $vid, 'referer' => $visitor->referer, 'url' => $visitor->url))->set_expr('created_at', 'NOW()');
            $track->save();
        }
    }
};
/**
 * Webim chatbox
 */
Пример #11
0
<?php

include 'IP.class.php';
foreach (array('8.8.8.8', '8.8.4.4', '202.106.195.68', '123.118.91.246', '202.115.128.64', '110.106.46.151', '11.106.46.151', '20.106.46.151', '1.106.46.151', '99.106.46.151', '10.106.46.151') as $ip) {
    $a = IP::find($ip);
    echo "\"{$ip}\": \"{$a['0']}" . '\\t' . $a[1] . '\\t' . $a[2] . "\",\n";
}
Пример #12
0
require "IP.class.php";
$api_key = "YOUR_DB_IP_KEY(https://db-ip.com/api/)";
if (isset($_POST['geo'])) {
    $ip_addr = $_POST['geo'];
} else {
    $ip_addr = null;
}
$ip = $_SERVER['REMOTE_ADDR'];
if (empty($ip_addr)) {
    echo $ip;
} else {
    $dbip = new DBIP_Client($api_key);
    foreach ($dbip->Get_Address_Info($ip_addr) as $k => $v) {
        #            echo "$k:$v,";
        if ($k == "country" && $v == "CN") {
            $finds = IP::find($ip_addr);
            $result = "";
            foreach ($finds as $res) {
                if (!empty($res)) {
                    if ($result != $res) {
                        $result = empty($result) ? $res : "{$result}," . "{$res}";
                    }
                }
            }
            echo $result;
            break;
        }
        if ($k == "address") {
            echo "";
        } else {
            if ($k == "city") {