You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
3.2 KiB
PHP
89 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
use App\Models\EmailLog;
|
|
use App\Services\AdminDataMasker;
|
|
use App\Controllers\AdminController;
|
|
use App\Utils\QQWry;
|
|
use App\Utils\SafeDatatables as Datatables;
|
|
use App\Utils\DatatablesHelper;
|
|
|
|
class LogController extends AdminController
|
|
{
|
|
|
|
private static function emailLogStatusFilter($request)
|
|
{
|
|
$query = $request->getQueryParams();
|
|
$status = $query['status'] ?? '';
|
|
|
|
return is_string($status) && in_array($status, ['success', 'failed', 'unknown'], true)
|
|
? $status
|
|
: '';
|
|
}
|
|
|
|
public function emailLog($request, $response, $args)
|
|
{
|
|
$status = self::emailLogStatusFilter($request);
|
|
$ajaxUrl = '/admin/email/ajax' . ($status === '' ? '' : '?status=' . $status);
|
|
$table_config['total_column'] = array("id" => "ID", "email" => "邮箱", "email_type" => "邮件类型", "status" => "状态", "ip" => "IP", "location" => "归属地", "request_domain" => "访问域名", "log_time" => "记录时间");
|
|
$table_config['default_show_column'] = array("id", "email", "email_type", "status", "ip", "request_domain", "log_time");
|
|
$table_config['ajax_url'] = $ajaxUrl;
|
|
|
|
return $this->view()
|
|
->assign('table_config', $table_config)
|
|
->assign('email_status_filter', $status)
|
|
->assign('email_log_ajax_url', $ajaxUrl)
|
|
->display('admin/log/emaillog.tpl');
|
|
}
|
|
|
|
public function ajax_emailLog($request, $response, $args)
|
|
{
|
|
$datatables = new Datatables(new DatatablesHelper('log'));
|
|
$statusWhere = [
|
|
'success' => ' WHERE log.status = 1',
|
|
'failed' => ' WHERE log.status = 0',
|
|
'unknown' => ' WHERE log.status IS NULL',
|
|
];
|
|
$status = self::emailLogStatusFilter($request);
|
|
$datatables->query('Select log.id,log.email,log.email_type,log.status,log.ip,ip as location, log.request_domain, log.date as log_time from user_email_log as log' . ($statusWhere[$status] ?? ''));
|
|
|
|
$datatables->edit('status', static function ($data) {
|
|
if ($data['status'] === null) {
|
|
return '历史未知';
|
|
}
|
|
|
|
if ((int) $data['status'] === 1) {
|
|
return '成功';
|
|
}
|
|
|
|
return (int) $data['status'] === 0 ? '失败' : '未知';
|
|
});
|
|
|
|
$iplocation = new QQWry();
|
|
$datatables->edit('location', static function ($data) use ($iplocation) {
|
|
$location = $iplocation->getlocation($data['location']);
|
|
return iconv('gbk', 'utf-8//IGNORE', $location['country'] . $location['area']);
|
|
});
|
|
|
|
$datatables->edit('email', function ($data) {
|
|
return AdminDataMasker::email($data['email']);
|
|
});
|
|
|
|
$datatables->edit('ip', function ($data) {
|
|
return AdminDataMasker::ip($data['ip']);
|
|
});
|
|
|
|
$datatables->edit('request_domain', function ($data) {
|
|
return AdminDataMasker::sensitiveText($data['request_domain']);
|
|
});
|
|
|
|
$datatables->edit('log_time', function ($data) {
|
|
return date('Y-m-d H:i:s', $data['log_time']);
|
|
});
|
|
|
|
$body = $response->getBody();
|
|
$body->write($datatables->generate());
|
|
}
|
|
}
|