Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <meta charset="utf-8">
- @if( App::environment('local') )
- <title>local</title>
- @else
- <title>Bunlong Heng</title>
- @endif
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <meta name="author" content="Bunlong Heng">
- <meta name="csrf-token" value="{{ csrf_token() }}">
- <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
- <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
- <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
- <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
- <!-- HTML5 shiv and Respond.js IE8 support of HTML5 elements and media queries -->
- <!--[if lt IE 9]>
- <script src="js/plugins/html5shiv.js"></script>
- <script src="js/plugins/respond.min.js"></script>
- <![endif]-->
- <?php
- use AppVisitor, AppCURLexec;
- if (!function_exists('getallheaders'))
- {
- function getallheaders()
- {
- $headers = '';
- foreach ($_SERVER as $name => $value)
- {
- if (substr($name, 0, 5) == 'HTTP_')
- {
- $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
- }
- }
- return $headers;
- }
- }
- $ip = trim(shell_exec("dig +short myip.opendns.com @resolver1.opendns.com")); Debug::console($ip);
- $ip = $_SERVER['REMOTE_ADDR'];
- $info = shell_exec('curl ipinfo.io/'.$ip );
- $ip_info_array = json_decode($info,true);
- $header_info = getallheaders();
- $loc = isset($ip_info_array['loc'])? $ip_info_array['loc'] : '';
- $url = 'https://maps.google.com/maps/api/geocode/json?latlng='. $loc .'&sensor=false';
- $geocode_array = CURLexec::get($url);
- $formatted_address = isset($geocode_array['results']['0']['formatted_address'])? $geocode_array['results']['0']['formatted_address'] : '';
- $place_id = isset($geocode_array['results']['0']['place_id'])? $geocode_array['results']['0']['place_id'] :'';
- $formatted_address = isset($geocode_array['results']['0']['formatted_address'])? $geocode_array['results']['0']['formatted_address'] : '';
- $place_id = isset($geocode_array['results']['0']['place_id'])? $geocode_array['results']['0']['place_id'] : '';
- //Mac Address + Inet
- $env = Request::server ("HTTP_HOST"); //localhost:8888
- if ($env == 'localhost:8888'){
- //Local
- $inet = trim(shell_exec("ifconfig en0 | grep 'netmask' | awk '{print $2}'"),"n");
- $grab_bssid_command = 'arp '.$inet.' | awk '{print $4}'';
- $bssid = trim(shell_exec($grab_bssid_command), "n");
- }else{
- //Other Machine/Server
- $inet = $ip;
- $grab_bssid_command = 'arp '.$inet.' | awk '{print $4}'';
- // dd($grab_bssid_command);
- $bssid = trim(shell_exec($grab_bssid_command), "n");
- }
- // LatLong Map http://maps.google.com/?q=-27.0000,133.0000
- // Static Map = http://maps.google.com/maps/api/staticmap?center=40.7421,-74.0018&zoom=13&size=500x300
- $static_map_url = 'https://maps.google.com/maps/api/staticmap?center='. $loc.'&zoom=13&size=500x300&maptype=roadmap&scale=2
- &markers=size:mid|color:red|'. $loc .'|size:small';
- $map_url = 'https://maps.google.com/?q='. $loc;
- $ip = isset($ip_info_array['ip'])? $ip_info_array['ip'] : '';
- $host_name = isset($ip_info_array['hostname'])? $ip_info_array['hostname'] : '';
- $city = isset($ip_info_array['city'])? $ip_info_array['city'] : '';
- $region = isset($ip_info_array['region'])? $ip_info_array['region'] : '';
- $country = isset($ip_info_array['country'])? $ip_info_array['country'] : '';
- $org = isset($ip_info_array['org'])? $ip_info_array['org'] : '';
- $postal = isset($ip_info_array['postal'])? $ip_info_array['postal'] : '';
- //User Agent
- $user_agent_info = isset($header_info['User-Agent'])? $header_info['User-Agent'] : '';
- $user_agent_array = ( explode(";",$user_agent_info));
- //OS
- $os_array = explode(")",$user_agent_array[1]);
- $os = str_replace('_','.',$os_array[0]); //
- $os_version = preg_replace("/[^d.]/", '', $os); //10.10.5
- if(array_key_exists(1,$os_array)){
- if($os_array[1] !== ''){
- $webkit_array = explode(" ",$os_array[1]);
- }else{
- $webkit_array = '';
- }
- }else{
- $webkit_array = '';
- }
- if($webkit_array == ''){
- $web_kit = '';
- }else{
- $web_kit = $webkit_array[1];
- }
- /*================================
- = Browsers =
- ================================*/
- if(array_key_exists(2,$os_array)){
- if($os_array[2] !== ''){
- $browsers = explode(")",$os_array[2]);
- }else{
- $browsers = '';
- }
- }else{
- $browsers = '';
- }
- if($browsers == ''){
- $browser_array = '';
- $chrome = '';
- $safari = '';
- }else{
- $browser_array = explode(" ",$browsers[0]);
- $chrome = $browser_array[1];
- if(array_key_exists(2,$browser_array)){
- $safari = $browser_array[2]; //bug
- }else{
- $safari = '';
- }
- }
- //Agent
- $agent_os_array = explode("(",$user_agent_array[0]);
- $agent = $agent_os_array[0]; // Mozilla/5.0
- $device = $agent_os_array[1]; // Macintosh
- // Check for existing
- $validator = Visitor::validator($ip);
- if ($validator->fails()) {
- $ip = Visitor::where('ip', '=', $ip)->firstOrFail();
- $id = $ip['attributes']['id'];
- if($ip){
- $visitor = Visitor::findOrFail($id);
- $visitor->visit_count = $visitor->visit_count + 1 ;
- $visitor->save();
- }
- } else {
- $visitor = new Visitor;
- $visitor->ip = $ip;
- $visitor->host_name = $host_name;
- $visitor->city = $city;
- $visitor->region = $region;
- $visitor->country = $country;
- $visitor->loc = $loc;
- $visitor->org = $org;
- $visitor->postal = $postal;
- $visitor->static_map_url = $static_map_url ;
- $visitor->map_url = $map_url ;
- $visitor->address = $formatted_address ;
- $visitor->details = $place_id;
- $visitor->user_agent = $agent;
- $visitor->visit_count = $visitor->visit_count + 1 ;
- $visitor->device = $device;
- $visitor->os = $os;
- $visitor->os_version = $os_version;
- $visitor->browser_type = $agent;
- $visitor->chrome = $chrome;
- $visitor->safari = $safari;
- $visitor->web_kit = $web_kit;
- $visitor->inet = $inet;
- $visitor->bssid = $bssid;
- $visitor->save();
- }
- //dd($visitor);
- Debug::console($loc);
- if(
- $visitor->country == 'US' AND
- $visitor->ip != '76.119.248.198'
- // $visitor->ip != '72.22.171.98'
- // AND substr($visitor->host_name) != 'crawl-'
- // AND substr($visitor->host_name) != 'spider'
- ){
- //Send Email to me
- $mail = Mail::send('layouts.share.emails.site_visit',
- array(
- 'ip_info_array' => $ip_info_array,
- 'header_info' => $header_info,
- 'formatted_address' => $formatted_address,
- 'static_map_url' => $static_map_url
- ) ,
- function ($ip_info_array) {
- $ip_info_array->from(env('MAIL_USERNAME') , 'bheng gmail');
- $ip_info_array->to(env('MAIL_TO') , 'Bunlong's Site ')
- ->subject( ' Visit Alert : ' . Request::server ("HTTP_HOST"));
- });
- //Send Text Message to me, use the forward from the mail client, so we don't put weigh on the application index
- }
- ?>
- use AppVisitor;
- use AppCURLexec;
Add Comment
Please, Sign In to add comment