CREATE TABLE IF NOT EXISTS `modx_visitors_log` ( `index` int(10) NOT NULL AUTO_INCREMENT, `ip` varchar(15) COLLATE utf8_unicode_ci NOT NULL, `host` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `url` text COLLATE utf8_unicode_ci NOT NULL, `datetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `referer` text COLLATE utf8_unicode_ci NOT NULL, `browser` varchar(255) NOT NULL, PRIMARY KEY (`index`), KEY `ip` (`ip`,`host`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
-> ->->
/* */ // modx_visitors_log $db = '`modx_visitors_log`'; // IP. - $not_log_ip = array('192.168.100.1', '192.168.100.2'); $not_log_user = array('bezumkin'); /* */ // $login = $_SESSION['webShortname']; // . - . $ip = $_SERVER['REMOTE_ADDR']; // IP . . $host = ''; // , IP . . $url = $_SERVER['REQUEST_URI']; // . $referer = urlencode($_SERVER['HTTP_REFERER']); // , . $browser = mysql_real_escape_string($_SERVER['HTTP_USER_AGENT']); // . browscap, . . // if (!in_array($ip, $not_log_ip) and !in_array($login, $not_log_login)) { $modx->db->query("INSERT INTO $db (`login`, `ip`, `host`, `url`, `referer`,`browser`) VALUES ('$login','$ip','$host', '$url','$referer','$browser')"); }
<?php $db = '`modx_visitors_log`'; // , host $sql = $modx->db->query("SELECT `ip` FROM $db WHERE `host` = '' GROUP BY `ip`"); $arr = $modx->db->makeArray($sql); // foreach ($arr as $v) { $ip = $v['ip']; // nslookup. Windows, -, , - - - . $host = `nslookup "$ip" | grep 'name =' | awk '{print $4}'`; // - , , . if (empty($host)) {$host = 'unknown';} // . $modx->db->query("UPDATE $db SET `host` = '$host' WHERE `ip` = '$ip' AND `host` = '';"); } ?>
[!Ip2Host!]
10 2 * * * * user wget localhost/secret_page.html
<?php /* */ if (empty($db)) {$db = '`modx_visitors_log`';} // if (empty($days)) {$days = 14;} // - if (empty($daysText)) {$daysText = '';} // - , if (empty($tpl)) {$tpl = 'visitStat.tpl';} // if (empty($act)) {$act = 'graph';} // , , graph & table if (empty($dateFormat)) {$dateFormat = '%d.%m';} // , strftime() if (empty($int)) {$int = 2;} // graph. - . /* */ // , $cur = time(); $end = date("Ymd"); $start = strftime("%Y-%m-%d", ($cur - ($days * 86400))); // $sql = $modx->db->query("SELECT DATE(`datetime`) as `date`, COUNT(distinct `ip`) as `host`, COUNT(`ip`) as `hit` FROM $db WHERE DATE(`datetime`) BETWEEN '$start' AND '$end' GROUP BY DATE(`datetime`) ORDER BY `datetime` ASC"); $result = $modx->db->makeArray($sql); // 3 , , foreach($result as $v) { $date[] = $v['date']; $host[] = $v['host']; $hit[] = $v['hit']; } // graph $int , - $i = 1; foreach ($date as $v) { if ($act == 'graph') { if ($i == $int) { $i = 0; $date2 .= '<th></th>'; } else { $date2 .= '<th>'.strftime($dateFormat, strtotime($v)).'</th>'; } $i++; } else if ($act == 'table') { $date2 .= '<th>'.strftime($dateFormat, strtotime($v)).'</th>'; } } foreach ($host as $v) { $host2 .= '<td>'.$v.'</td>'; } foreach ($hit as $v) { $hit2 .= '<td>'.$v.'</td>'; } $placeholders = array('[+stat.days+]','[+stat.days.text+]','[+stat.date+]','[+stat.host+]','[+stat.hit+]'); $values = array($days, $daysText, $date2, $host2, $hit2); $html = $modx->getChunk($tpl); echo str_replace($placeholders, $values, $html); ?>
<div style='margin: auto;text-align: center;'> <table id='chart_table'> <caption> [+stat.days+] [+stat.days.text+]</caption> <thead> <tr><td></td>[+stat.date+]</tr> </thead> <tbody> <tr><th></th>[+stat.host+]</tr> <tr><th></th>[+stat.hit+]</tr> </tbody> </table> </div>
<link type='text/css' rel='stylesheet' href='[(site_url)]inc/css/visualize.css' /> <script type='text/javascript' src='[(site_url)]inc/js/visualize.jquery.js'></script> <script type='text/javascript'> $(document).ready(function(){ $('#chart').visualize({ type: 'area', width: '570', height: '300' }); }); </script> <div style='margin: auto;'> <table id='chart' style='display: none;'> <caption> [+stat.days+] [+stat.days.text+]</caption> <thead> <tr><td></td>[+stat.date+]</tr> </thead> <tbody> <tr><th></th>[+stat.host+]</tr> <tr><th></th>[+stat.hit+]</tr> </tbody> </table> </div>
$(document).ready(function(){ $('#chart').visualize({ type: 'area', width: '570', height: '300' }); });
[!generateStatGraph? &days=`20` &tpl=`tpl.StatTable` &act=`table` &dateFormat=`%d <i>%b</i>` !] [!generateStatGraph? &days=`20` &daysText=`` &tpl=`tpl.StatGraph` &act=`graph` &dateFormat=`%d` !]
: `modx_visitors_log`
: [string]
: , (`modx`.`modx_log`).
: '%d %b %Y %H:%M'
: strftime()
: .
: 14
: [int]
: .
: ''
: [string]
: - , , .
: 'tpl.StatGraph'
: modx
: .
: 'graph'
: graph, table
: . graph .
: 2
: [int]
: &act=`graph`, &int , . - .
.
.
().
().
Source: https://habr.com/ru/post/111203/
All Articles