parent
692c5e796f
commit
eada97b43f
3 changed files with 916 additions and 0 deletions
@ -0,0 +1,198 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
include 'functions.php'; |
||||||
|
|
||||||
|
$type = $_GET['type']; |
||||||
|
|
||||||
|
$o = ''; |
||||||
|
|
||||||
|
|
||||||
|
/* header */ |
||||||
|
|
||||||
|
$o .= ' '.date('Y-m-d').' Ushio Report |
||||||
|
'; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$conn = db__connect("log"); |
||||||
|
$connAuth = db__connect("auth"); |
||||||
|
|
||||||
|
$data = db__getData($conn, "log_iis", "", "", "", "", "WHERE timestamp BETWEEN '".date('Y-m-d H:i:s', strtotime("-1 day"))."' AND '".date('Y-m-d H:i:s')."'"); |
||||||
|
$dataApi = db__getData($conn, "log_api", "", "", "", "", "WHERE timestamp BETWEEN '".date('Y-m-d H:i:s', strtotime("-1 day"))."' AND '".date('Y-m-d H:i:s')."'"); |
||||||
|
|
||||||
|
$o .= 'Domain Statistic |
||||||
|
'; |
||||||
|
$domain = Array(); |
||||||
|
|
||||||
|
foreach($data as $index=>$val){ |
||||||
|
if(!array_key_exists($val['domain'], $domain)){ |
||||||
|
$domain[$val['domain']] = Array(); |
||||||
|
} |
||||||
|
array_push($domain[$val['domain']], $val); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
foreach($domain as $index=>$val){ |
||||||
|
$o .= $index.': |
||||||
|
'; |
||||||
|
|
||||||
|
$totalSession = 0; |
||||||
|
$usrs = Array(); |
||||||
|
foreach($val as $item){ |
||||||
|
if($item['sessiontime']){ |
||||||
|
$totalSession += $item['sessiontime']; |
||||||
|
} |
||||||
|
if(!in_array($item['fp'], $usrs)){ |
||||||
|
array_push($usrs, $item['fp']); |
||||||
|
} |
||||||
|
} |
||||||
|
$o .= 'Visitors: '.count($usrs).' '; |
||||||
|
$o .= 'TSession: '.$totalSession; |
||||||
|
$o .= ' |
||||||
|
'; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$o .= ' |
||||||
|
Visitor Statistic |
||||||
|
|
||||||
|
'; |
||||||
|
$fp = Array(); |
||||||
|
|
||||||
|
foreach($data as $index=>$val){ |
||||||
|
if(!array_key_exists($val['fp'], $fp)){ |
||||||
|
$fp[$val['fp']] = Array(); |
||||||
|
} |
||||||
|
array_push($fp[$val['fp']], $val); |
||||||
|
} |
||||||
|
|
||||||
|
foreach($fp as $index=>$val){ |
||||||
|
|
||||||
|
|
||||||
|
$usrInfo = ''; |
||||||
|
if(db__rowNum($connAuth, "fip", "fp", $index)){ |
||||||
|
$res = db__getData($connAuth, 'fip', 'fp', $index); |
||||||
|
$token = $res[count($res)-1]['token']; |
||||||
|
$res = db__getData($connAuth, 'token', 'token', $token); |
||||||
|
if($res != 404 && $res[count($res)-1]['state']){ |
||||||
|
$hash = $res[count($res)-1]['hash']; |
||||||
|
$res = db__getData($connAuth, 'account', 'hash', $hash); |
||||||
|
$usrInfo .= 'U'.$res[0]['uid'].' N: '.$res[0]['nickname'].' C: '.$res[0]['comments'].' |
||||||
|
'; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
$web = Array(); |
||||||
|
$eeedog = array(); |
||||||
|
$totalSession = 0; |
||||||
|
foreach($val as $item){ |
||||||
|
if(!in_array($item['domain'], $web)){ |
||||||
|
$web[$item['domain']] = 0; |
||||||
|
} |
||||||
|
if($item['domain'] == 'www.eee.dog'){ |
||||||
|
$s = substr($item['url'], 19); |
||||||
|
$pos = strpos($s, '#'); |
||||||
|
if($pos){ |
||||||
|
$s = substr($s, 0, $pos); |
||||||
|
} |
||||||
|
$pos = strpos($s, '?'); |
||||||
|
if($pos){ |
||||||
|
$s = substr($s, 0, $pos); |
||||||
|
} |
||||||
|
if(!in_array($s, $eeedog)){ |
||||||
|
array_push($eeedog, $s); |
||||||
|
} |
||||||
|
} |
||||||
|
if($item['sessiontime']){ |
||||||
|
$web[$item['domain']] += $item['sessiontime']; |
||||||
|
$totalSession += $item['sessiontime']; |
||||||
|
} |
||||||
|
} |
||||||
|
if($usrInfo != "" || count($web) > 1 || $totalSession > 20){ |
||||||
|
|
||||||
|
$o .= $index.': |
||||||
|
'; |
||||||
|
$o .= $usrInfo; |
||||||
|
$o .= $val[0]['platform'].' '; |
||||||
|
$o .= $val[0]['language'].' '; |
||||||
|
$o .= $val[0]['timezone'].' |
||||||
|
'; |
||||||
|
$o .= 'web:'; |
||||||
|
foreach($web as $d=>$session){ |
||||||
|
$o .= $d.'('.$session.') '; |
||||||
|
} |
||||||
|
|
||||||
|
if(count($eeedog)){ |
||||||
|
$o .= ' |
||||||
|
eeedog: '; |
||||||
|
foreach($eeedog as $url){ |
||||||
|
$o .= $url .' '; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
$o .= ' |
||||||
|
'; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$o .= ' |
||||||
|
API Statistic |
||||||
|
'; |
||||||
|
$api = Array(); |
||||||
|
|
||||||
|
foreach($dataApi as $index=>$val){ |
||||||
|
if(!array_key_exists($val['api'], $api)){ |
||||||
|
$api[$val['api']] = Array(); |
||||||
|
} |
||||||
|
array_push($api[$val['api']], $val); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
foreach($api as $index=>$val){ |
||||||
|
$o .= $index.': |
||||||
|
'; |
||||||
|
$f = array(); |
||||||
|
foreach($val as $item){ |
||||||
|
$s = parse_url($item['_from'])['host']; |
||||||
|
if(!array_key_exists($s, $f)){ |
||||||
|
$f[$s] = 0; |
||||||
|
} |
||||||
|
$f[$s] ++; |
||||||
|
} |
||||||
|
$ip = array(); |
||||||
|
foreach($val as $item){ |
||||||
|
$s = $item['ip']; |
||||||
|
if(!array_key_exists($s, $ip)){ |
||||||
|
$ip[$s] = 0; |
||||||
|
} |
||||||
|
$ip[$s] ++; |
||||||
|
} |
||||||
|
$o .= 'Num:'.count($val).' Host:'.count($f).' Usr:'.count($ip).' |
||||||
|
'; |
||||||
|
foreach($f as $usr=>$n){ |
||||||
|
if($n>20){ |
||||||
|
$o .= $usr.'('.$n.')'; |
||||||
|
} |
||||||
|
} |
||||||
|
$o .= ' |
||||||
|
'; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$o .= '------------------'; |
||||||
|
|
||||||
|
if($type == 'memobird') yimian__gugu($o); |
||||||
|
elseif($type == 'email') yimian__mail('i@iotcat.me', date('Y-m-d').' Ushio Report', str_replace(PHP_EOL, '<br>', $o), 'Ushio-Report'); |
||||||
|
else echo str_replace(PHP_EOL, '<br>', $o); |
@ -0,0 +1,122 @@ |
|||||||
|
<?php |
||||||
|
class memobird{ |
||||||
|
private $ak = ''; //access key |
||||||
|
private $url=array( |
||||||
|
'getUserId' => 'http://open.memobird.cn/home/setuserbind/', |
||||||
|
'printPaper' => 'http://open.memobird.cn/home/printpaper/', |
||||||
|
'getPrintStatus' => 'http://open.memobird.cn/home/getprintstatus/' |
||||||
|
); |
||||||
|
|
||||||
|
|
||||||
|
function __construct($ak){ |
||||||
|
$this->ak = $ak; |
||||||
|
date_default_timezone_set('PRC'); |
||||||
|
} |
||||||
|
|
||||||
|
public function getUserId($memobirdID,$useridentifying){ |
||||||
|
$params=array( |
||||||
|
'ak'=> $this->ak, |
||||||
|
'timestamp'=>date('Y-m-d h:m:s',time()), |
||||||
|
'memobirdID'=>$memobirdID, |
||||||
|
'useridentifying'=>$useridentifying |
||||||
|
); |
||||||
|
$paramsString = http_build_query($params); |
||||||
|
return $this->curl($this->url['getUserId'],$paramsString); |
||||||
|
} |
||||||
|
|
||||||
|
public function printPaper($printcontent,$memobirdID,$userID){ |
||||||
|
$params=array( |
||||||
|
'ak'=> $this->ak, |
||||||
|
'timestamp'=>date('Y-m-d h:m:s',time()), |
||||||
|
'printcontent'=>$printcontent, |
||||||
|
'memobirdID'=>$memobirdID, |
||||||
|
'userID'=>$userID |
||||||
|
); |
||||||
|
$paramsString = http_build_query($params); |
||||||
|
return $this->curl($this->url['printPaper'],$paramsString); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
//构造printPaper方法中$printcontent格式,多个可以循环并用|拼接 |
||||||
|
public function contentSet($type,$content){ |
||||||
|
switch($type){ |
||||||
|
case 'T': |
||||||
|
$ret = $type.':'.base64_encode($this->charsetToGBK($content)."\n");break; |
||||||
|
case 'P': |
||||||
|
$ret = 'P:'.base64_encode($content); |
||||||
|
default: |
||||||
|
} |
||||||
|
return $ret; |
||||||
|
} |
||||||
|
|
||||||
|
public function getPaperStatus($printcontentID){ |
||||||
|
$params=array( |
||||||
|
'ak'=> $this->ak, |
||||||
|
'timestamp'=>date('Y-m-d h:m:s',time()), |
||||||
|
'printcontentID'=>$printcontentID |
||||||
|
); |
||||||
|
$paramsString = http_build_query($params); |
||||||
|
return $this->curl($this->url['getPrintStatus'],$paramsString); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 创建http header参数 |
||||||
|
* @param array $data |
||||||
|
* @return bool |
||||||
|
*/ |
||||||
|
private function createHttpHeader() { |
||||||
|
// |
||||||
|
} |
||||||
|
/** |
||||||
|
* 发起 server 请求 |
||||||
|
* @param $action |
||||||
|
* @param $params |
||||||
|
* @param $httpHeader |
||||||
|
* @return mixed |
||||||
|
*/ |
||||||
|
public function curl($action,$params) { |
||||||
|
//$action = self::SERVERAPIURL.$action.'.'.$this->format; |
||||||
|
//$httpHeader = $this->createHttpHeader(); |
||||||
|
$ch = curl_init(); |
||||||
|
curl_setopt($ch, CURLOPT_URL, $action); |
||||||
|
curl_setopt($ch, CURLOPT_POST, 1); |
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $params); |
||||||
|
//curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader); |
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false); //处理http证书问题 |
||||||
|
curl_setopt($ch, CURLOPT_HEADER, false); |
||||||
|
curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
||||||
|
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false); |
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||||||
|
$ret = curl_exec($ch); |
||||||
|
if (false === $ret) { |
||||||
|
$ret = curl_errno($ch); |
||||||
|
} |
||||||
|
curl_close($ch); |
||||||
|
return $ret; |
||||||
|
} |
||||||
|
|
||||||
|
public function charsetToGBK($mixed){ |
||||||
|
if (is_array($mixed)) { |
||||||
|
foreach ($mixed as $k => $v) { |
||||||
|
if (is_array($v)) { |
||||||
|
$mixed[$k] = charsetToGBK($v); |
||||||
|
} else { |
||||||
|
$encode = mb_detect_encoding($v, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5')); |
||||||
|
if ($encode == 'UTF-8') { |
||||||
|
$mixed[$k] = iconv('UTF-8', 'GBK', $v); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} else { |
||||||
|
$encode = mb_detect_encoding($mixed, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5')); |
||||||
|
//var_dump($encode); |
||||||
|
if ($encode == 'UTF-8') { |
||||||
|
$mixed = iconv('UTF-8', 'GBK', $mixed); |
||||||
|
} |
||||||
|
} |
||||||
|
return $mixed; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue