574 lines
22 KiB
PHP
574 lines
22 KiB
PHP
<?php
|
||
|
||
namespace app\admin\controller;
|
||
|
||
use think\Db;
|
||
use think\Request;
|
||
|
||
class Log extends Common
|
||
{
|
||
// 代理操作日志
|
||
public function index()
|
||
{
|
||
// 接收分页的条件
|
||
$get = Request::instance()->get();
|
||
$query = http_build_query($get);
|
||
$this->assign('get',$get);
|
||
$this->assign('query',$query);
|
||
|
||
// 接收搜索参数
|
||
$username = Request::instance()->get('username');
|
||
$startDate = Request::instance()->get('startDate');
|
||
$endDate = Request::instance()->get('endDate');
|
||
$export = Request::instance()->get('export');
|
||
$startTime = 0;
|
||
$endTime = time();
|
||
|
||
// 拼装搜索条件
|
||
$where = array();
|
||
if(!empty($username)) $where['username'] = array('like',"%".$username."%");
|
||
if($startDate) $startTime = strtotime($startDate);
|
||
if($endDate) $endTime = strtotime($endDate);
|
||
$where['control_time'] = array('between',[$startTime,$endTime]);
|
||
|
||
if($export == 1){
|
||
$log_list = Db::name('agent_log')->where($where)->order('control_time desc')->select();
|
||
}else{
|
||
// 查询所有的日志信息
|
||
$log_list = Db::name('agent_log')->where($where)->order('control_time desc')->paginate(15,false,array('query'=>$get));
|
||
}
|
||
$log_sum = Db::name('agent_log')->count();
|
||
foreach($log_list as $k => $v){
|
||
$v['control_time'] = date('Y-m-d H:i:s',$v['control_time']);
|
||
if(empty($v['ip_location'])) $v['ip_location'] = "无";
|
||
$log_list[$k] = $v;
|
||
}
|
||
|
||
//导出excel列表
|
||
if($export == 1){
|
||
if($log_list){
|
||
//重新组合
|
||
$excelData = array();
|
||
foreach($log_list AS $k => $v){
|
||
$excelData[$k][0] = $v['username'];
|
||
$excelData[$k][1] = $v['control'];
|
||
$excelData[$k][2] = $v['remake'];
|
||
$excelData[$k][3] = $v['control_time'];
|
||
}
|
||
$title = array('操作人','操作类型','操作描述','操作时间');
|
||
if($startDate && $endDate){
|
||
$this->exportExcelCore($excelData, '操作日志-'.$startDate."-".$endDate, $title);
|
||
}else{
|
||
$this->exportExcelCore($excelData, '操作日志', $title);
|
||
}
|
||
exit('已导出支持列表,请不要重复刷新该页面!');
|
||
}else{
|
||
exit('没有可以导出的列表!');
|
||
}
|
||
}
|
||
|
||
// 渲染参数和模板
|
||
$this->assign('log_list',$log_list);
|
||
$this->assign('log_sum',$log_sum);
|
||
return $this->fetch();
|
||
}
|
||
|
||
// 代理操作日志
|
||
public function admin()
|
||
{
|
||
// 接收分页的条件
|
||
$get = Request::instance()->get();
|
||
$query = http_build_query($get);
|
||
$this->assign('get',$get);
|
||
$this->assign('query',$query);
|
||
|
||
// 接收搜索参数
|
||
$username = Request::instance()->get('username');
|
||
$startDate = Request::instance()->get('startDate');
|
||
$endDate = Request::instance()->get('endDate');
|
||
$export = Request::instance()->get('export');
|
||
$startTime = 0;
|
||
$endTime = time();
|
||
|
||
// 拼装搜索条件
|
||
$where = array();
|
||
if(!empty($username)) $where['space_admin'] = array('like',"%".$username."%");
|
||
if($startDate) $startTime = strtotime($startDate);
|
||
if($endDate) $endTime = strtotime($endDate);
|
||
$where['control_time'] = array('between',[$startTime,$endTime]);
|
||
|
||
if($export == 1){
|
||
$log_list = Db::name('space_system_log')->where($where)->order('control_time desc')->select();
|
||
}else{
|
||
// 查询所有的日志信息
|
||
$log_list = Db::name('space_system_log')->where($where)->order('control_time desc')->paginate(10,false,array('query'=>$get));
|
||
}
|
||
$log_sum = Db::name('agent_log')->count();
|
||
foreach($log_list as $k => $v){
|
||
$v['control_time'] = date('Y-m-d H:i:s',$v['control_time']);
|
||
if(empty($v['ip_location'])) $v['ip_location'] = "无";
|
||
$log_list[$k] = $v;
|
||
}
|
||
|
||
//导出excel列表
|
||
if($export == 1){
|
||
if($log_list){
|
||
//重新组合
|
||
$excelData = array();
|
||
foreach($log_list AS $k => $v){
|
||
$excelData[$k][0] = $v['space_admin'];
|
||
$excelData[$k][1] = $v['control'];
|
||
$excelData[$k][2] = $v['remake'];
|
||
$excelData[$k][3] = $v['control_time'];
|
||
}
|
||
$title = array('操作人','操作类型','操作描述','操作时间');
|
||
if($startDate && $endDate){
|
||
$this->exportExcelCore($excelData, '操作日志-'.$startDate."-".$endDate, $title);
|
||
}else{
|
||
$this->exportExcelCore($excelData, '操作日志', $title);
|
||
}
|
||
exit('已导出支持列表,请不要重复刷新该页面!');
|
||
}else{
|
||
exit('没有可以导出的列表!');
|
||
}
|
||
}
|
||
|
||
// 渲染参数和模板
|
||
$this->assign('log_list',$log_list);
|
||
$this->assign('log_sum',$log_sum);
|
||
return $this->fetch();
|
||
}
|
||
public function admin_print(){
|
||
$get = Request::instance()->get();
|
||
$query = http_build_query($get);
|
||
$username = Request::instance()->get('username');
|
||
$startDate = Request::instance()->get('startDate');
|
||
$endDate = Request::instance()->get('endDate');
|
||
$startTime = 0;
|
||
$endTime = time();
|
||
$where = array();
|
||
if(!empty($username)) $where['space_admin'] = array('like',"%".$username."%");
|
||
if($startDate) $startTime = strtotime($startDate);
|
||
if($endDate) $endTime = strtotime($endDate);
|
||
$where['control_time'] = array('between',[$startTime,$endTime]);
|
||
$log_list = Db::name('space_system_log')->where($where)->order('control_time desc')->select();
|
||
$log_sum = Db::name('agent_log')->count();
|
||
foreach($log_list as $k => $v){
|
||
$v['control_time'] = date('Y-m-d H:i:s',$v['control_time']);
|
||
if(empty($v['ip_location'])) $v['ip_location'] = "无";
|
||
$log_list[$k] = $v;
|
||
}
|
||
$this->assign('log_list',$log_list);
|
||
$this->assign('log_sum',$log_sum);
|
||
return $this->fetch();
|
||
}
|
||
public function user_print(){
|
||
$get = Request::instance()->get();
|
||
$query = http_build_query($get);
|
||
$username = Request::instance()->get('username');
|
||
$startDate = Request::instance()->get('startDate');
|
||
$endDate = Request::instance()->get('endDate');
|
||
$startTime = 0;
|
||
$endTime = time();
|
||
$where = array();
|
||
if(!empty($username)) $where['username'] = array('like',"%".$username."%");
|
||
if($startDate) $startTime = strtotime($startDate);
|
||
if($endDate) $endTime = strtotime($endDate);
|
||
$where['control_time'] = array('between',[$startTime,$endTime]);
|
||
$log_list = Db::name('agent_log')->where($where)->order('control_time desc')->select();
|
||
$log_sum = Db::name('agent_log')->count();
|
||
foreach($log_list as $k => $v){
|
||
$v['control_time'] = date('Y-m-d H:i:s',$v['control_time']);
|
||
if(empty($v['ip_location'])) $v['ip_location'] = "无";
|
||
$log_list[$k] = $v;
|
||
}
|
||
$this->assign('log_list',$log_list);
|
||
$this->assign('log_sum',$log_sum);
|
||
return $this->fetch();
|
||
}
|
||
|
||
// 用户登录日志
|
||
public function user_login()
|
||
{
|
||
// 接收分页的条件
|
||
$get = Request::instance()->get();
|
||
$query = http_build_query($get);
|
||
$this->assign('get',$get);
|
||
$this->assign('query',$query);
|
||
|
||
// 接收搜索参数
|
||
$username = Request::instance()->get('username');
|
||
$remark = Request::instance()->get('remark');
|
||
$startDate = Request::instance()->get('startDate');
|
||
$endDate = Request::instance()->get('endDate');
|
||
$export = Request::instance()->get('export');
|
||
$startTime = 0;
|
||
$endTime = time();
|
||
|
||
// 拼装搜索条件
|
||
$where = array();
|
||
if(!empty($username)) $where['username'] = array('like',"%".$username."%");
|
||
if(!empty($remark)) $where['remark'] = $remark;
|
||
if($startDate) $startTime = strtotime($startDate);
|
||
if($endDate) $endTime = strtotime($endDate);
|
||
$where['create_time'] = array('between',[$startTime,$endTime]);
|
||
|
||
if($export == 1){
|
||
$log_list = Db::name('user_log')->where($where)->order('create_time desc')->select();
|
||
}else{
|
||
// 查询所有的日志信息
|
||
$log_list = Db::name('user_log')->where($where)->order('create_time desc')->paginate(10,false,array('query'=>$get));
|
||
}
|
||
$log_sum = Db::name('user_log')->count();
|
||
foreach($log_list as $k => $v){
|
||
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
|
||
$log_list[$k] = $v;
|
||
}
|
||
|
||
//导出excel列表
|
||
if($export == 1){
|
||
if($log_list){
|
||
//重新组合
|
||
$excelData = array();
|
||
foreach($log_list AS $k => $v){
|
||
$excelData[$k][0] = $v['username'];
|
||
$excelData[$k][1] = $v['nickname'];
|
||
$excelData[$k][2] = $v['ip'];
|
||
$excelData[$k][3] = $v['ip_location'];
|
||
$excelData[$k][4] = $v['client'];
|
||
$excelData[$k][5] = $v['remark'];
|
||
$excelData[$k][6] = $v['create_time'];
|
||
}
|
||
$title = array('账号','姓名','IP','IP所属地区','登录客户端','备注','操作时间');
|
||
if($startDate && $endDate){
|
||
$this->exportExcelCore($excelData, '用户登录日志-'.$startDate."-".$endDate, $title);
|
||
}else{
|
||
$this->exportExcelCore($excelData, '用户登录日志', $title);
|
||
}
|
||
exit('已导出支持列表,请不要重复刷新该页面!');
|
||
}else{
|
||
exit('没有可以导出的列表!');
|
||
}
|
||
}
|
||
|
||
// 渲染参数和模板
|
||
$this->assign('log_list',$log_list);
|
||
$this->assign('log_sum',$log_sum);
|
||
return $this->fetch();
|
||
}
|
||
public function user_login_print(){
|
||
$get = Request::instance()->get();
|
||
$query = http_build_query($get);
|
||
$username = Request::instance()->get('username');
|
||
$remark = Request::instance()->get('remark');
|
||
$startDate = Request::instance()->get('startDate');
|
||
$endDate = Request::instance()->get('endDate');
|
||
$startTime = 0;
|
||
$endTime = time();
|
||
$where = array();
|
||
if(!empty($username)) $where['username'] = array('like',"%".$username."%");
|
||
if(!empty($remark)) $where['remark'] = $remark;
|
||
if($startDate) $startTime = strtotime($startDate);
|
||
if($endDate) $endTime = strtotime($endDate);
|
||
$where['create_time'] = array('between',[$startTime,$endTime]);
|
||
$log_list = Db::name('user_log')->where($where)->order('create_time desc')->select();
|
||
$log_sum = Db::name('user_log')->count();
|
||
foreach($log_list as $k => $v){
|
||
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
|
||
$log_list[$k] = $v;
|
||
}
|
||
$this->assign('log_list',$log_list);
|
||
$this->assign('log_sum',$log_sum);
|
||
return $this->fetch();
|
||
}
|
||
// 扫描用户
|
||
public function scan_admin(){
|
||
// 接收分页的条件
|
||
$get = Request::instance()->get();
|
||
$query = http_build_query($get);
|
||
$this->assign('get',$get);
|
||
$this->assign('query',$query);
|
||
$admin_list = Db::name('scan_account')->order('id desc')->paginate(10,false,array('query'=>$get));
|
||
// 渲染参数和模板
|
||
$this->assign('admin_list',$admin_list);
|
||
return $this->fetch();
|
||
}
|
||
// 接口用户
|
||
public function api_admin(){
|
||
// 接收分页的条件
|
||
$get = Request::instance()->get();
|
||
$query = http_build_query($get);
|
||
$this->assign('get',$get);
|
||
$this->assign('query',$query);
|
||
$admin_list = Db::name('api_account')->order('id desc')->paginate(10,false,array('query'=>$get));
|
||
// 渲染参数和模板
|
||
$this->assign('admin_list',$admin_list);
|
||
return $this->fetch();
|
||
}
|
||
|
||
// 扫描用户添加页面
|
||
public function scan_admin_add(){
|
||
// 渲染参数和模板
|
||
return $this->fetch();
|
||
}
|
||
// API用户添加页面
|
||
public function api_admin_add(){
|
||
// 渲染参数和模板
|
||
return $this->fetch();
|
||
}
|
||
|
||
// 处理扫描用户添加
|
||
public function do_scan_admin_add(){
|
||
// 接收提交过来的数据
|
||
$appid = Request::instance()->post('appid');
|
||
$pass = Request::instance()->post('pass');
|
||
$repass = Request::instance()->post('repass');
|
||
$name = Request::instance()->post('name');
|
||
$remake = Request::instance()->post('remake');
|
||
|
||
// 数据验证
|
||
if( !isset($appid) && empty($appid) ){
|
||
return json(['code'=>0,'msg'=>'用户名不能为空!']);
|
||
}
|
||
if( !isset($pass) && empty($pass) ){
|
||
return json(['code'=>0,'msg'=>'密码不能为空!']);
|
||
}
|
||
if( !isset($repass) && empty($repass) ){
|
||
return json(['code'=>0,'msg'=>'确认密码不能为空!']);
|
||
}
|
||
if( $repass != $pass ){
|
||
return json(['code'=>0,'msg'=>'两次密码不一致!']);
|
||
}
|
||
if( !isset($name) && empty($name) ){
|
||
return json(['code'=>0,'msg'=>'名称不能为空!']);
|
||
}
|
||
|
||
// 检测用户名是否已经被注册
|
||
$user = Db::name('scan_account')->where('appid',$appid)->find();
|
||
if($user){
|
||
return json(['code'=>0,'msg'=>'用户已存在!']);
|
||
}
|
||
|
||
// 拼装数据
|
||
$data = array();
|
||
$data['appid'] = $appid;
|
||
$data['appsecret'] = think_ucenter_md5($pass, UC_AUTH_KEY);
|
||
$data['name'] = $name;
|
||
$data['remake'] = $remake;
|
||
$insert_id = Db::name('scan_account')->insertGetId($data);
|
||
if($insert_id){
|
||
// 写入管理员日志
|
||
insertAdminLog('添加扫描用户','添加扫描用户:| ID: '.$insert_id.' | appid: '.$appid);
|
||
return json(['code'=>1,'msg'=>'添加成功!']);
|
||
}else{
|
||
return json(['code'=>0,'msg'=>'添加失败!']);
|
||
}
|
||
}
|
||
|
||
// 处理API用户添加
|
||
public function do_api_admin_add(){
|
||
// 接收提交过来的数据
|
||
$appid = Request::instance()->post('appid');
|
||
$pass = Request::instance()->post('pass');
|
||
$repass = Request::instance()->post('repass');
|
||
$name = Request::instance()->post('name');
|
||
|
||
// 数据验证
|
||
if( !isset($appid) && empty($appid) ){
|
||
return json(['code'=>0,'msg'=>'APPID不能为空']);
|
||
}
|
||
if( !isset($pass) && empty($pass) ){
|
||
return json(['code'=>0,'msg'=>'秘钥不能为空']);
|
||
}
|
||
if( !isset($repass) && empty($repass) ){
|
||
return json(['code'=>0,'msg'=>'确认秘钥不能为空']);
|
||
}
|
||
if( $repass != $pass ){
|
||
return json(['code'=>0,'msg'=>'两次秘钥不一致']);
|
||
}
|
||
if( !isset($name) && empty($name) ){
|
||
return json(['code'=>0,'msg'=>'名称不能为空!']);
|
||
}
|
||
|
||
// 检测用户名是否已经被注册
|
||
$user = Db::name('api_account')->where('appid',$appid)->find();
|
||
if($user){
|
||
return json(['code'=>0,'msg'=>'APPID已存在']);
|
||
}
|
||
|
||
// 拼装数据
|
||
$data = array();
|
||
$data['appid'] = $appid;
|
||
$data['appsecret'] = $pass;
|
||
$data['name'] = $name;
|
||
$insert_id = Db::name('api_account')->insertGetId($data);
|
||
if($insert_id){
|
||
// 写入管理员日志
|
||
insertAdminLog('添加扫描用户','添加API用户:| ID: '.$insert_id.' | appid: '.$appid);
|
||
return json(['code'=>1,'msg'=>'添加成功!']);
|
||
}else{
|
||
return json(['code'=>0,'msg'=>'添加失败!']);
|
||
}
|
||
}
|
||
|
||
// 扫描用户编辑页面
|
||
public function scan_admin_edit(){
|
||
// 扫描用户
|
||
$id = Request::instance()->get('id');
|
||
$admin = Db::name('scan_account')->find($id);
|
||
|
||
// 渲染参数和模板
|
||
$this->assign('admin',$admin);
|
||
return $this->fetch();
|
||
}
|
||
|
||
// API用户编辑页面
|
||
public function api_admin_edit(){
|
||
// API用户
|
||
$id = Request::instance()->get('id');
|
||
$admin = Db::name('api_account')->find($id);
|
||
|
||
// 渲染参数和模板
|
||
$this->assign('admin',$admin);
|
||
return $this->fetch();
|
||
}
|
||
|
||
// 处理扫描用户编辑
|
||
public function do_scan_admin_edit(){
|
||
if(Request::instance()->post()){
|
||
// 接收传过来的数据
|
||
$scan_admin_id = Request::instance()->post('scan_admin_id');
|
||
$appid = Request::instance()->post('appid');
|
||
$pass = Request::instance()->post('pass');
|
||
$repass = Request::instance()->post('repass');
|
||
$name = Request::instance()->post('name');
|
||
$remake = Request::instance()->post('remake');
|
||
|
||
//数据验证
|
||
if(empty($appid)){
|
||
return json(['code'=>0,'msg'=>'appid不能为空!']);
|
||
}
|
||
if(!empty($pass) && strlen($pass) < 6){
|
||
return json(['code'=>0,'msg'=>'密码长度不能少于6位!']);
|
||
}
|
||
if(!empty($pass) && $pass != $repass){
|
||
return json(['code'=>0,'msg'=>'两次密码输入不一致!']);
|
||
}
|
||
|
||
// 拼装数据
|
||
$data = array();
|
||
if(!empty($pass)) $data['appsecret'] = think_ucenter_md5($pass, UC_AUTH_KEY);
|
||
$data['name'] = $name;
|
||
$data['remake'] = $remake;
|
||
|
||
// 修改管理员资料
|
||
$result = Db::name('scan_account')->where('id',$scan_admin_id)->update($data);
|
||
if($result){
|
||
insertAdminLog('修改扫描用户','修改扫描用户:| ID: '.$scan_admin_id.' | appid:'.$appid);
|
||
return json(['code'=>1,'msg'=>'修改成功!']);
|
||
}else{
|
||
return json(['code'=>0,'msg'=>'修改失败!']);
|
||
}
|
||
}else{
|
||
return json(['code'=>0,'msg'=>'操作错误!']);
|
||
}
|
||
}
|
||
|
||
// 处理API用户编辑
|
||
public function do_api_admin_edit(){
|
||
if(Request::instance()->post()){
|
||
// 接收传过来的数据
|
||
$id = Request::instance()->post('id');
|
||
$appid = Request::instance()->post('appid');
|
||
$pass = Request::instance()->post('pass');
|
||
$repass = Request::instance()->post('repass');
|
||
$name = Request::instance()->post('name');
|
||
|
||
//数据验证
|
||
if(empty($appid)){
|
||
return json(['code'=>0,'msg'=>'appid不能为空!']);
|
||
}
|
||
if(!empty($pass) && strlen($pass) < 6){
|
||
return json(['code'=>0,'msg'=>'密码长度不能少于6位!']);
|
||
}
|
||
if(!empty($pass) && $pass != $repass){
|
||
return json(['code'=>0,'msg'=>'两次密码输入不一致!']);
|
||
}
|
||
|
||
// 拼装数据
|
||
$data = array();
|
||
$data['appsecret'] = $pass;
|
||
$data['name'] = $name;
|
||
|
||
// 修改管理员资料
|
||
$result = Db::name('api_account')->where('id',$id)->update($data);
|
||
if($result){
|
||
insertAdminLog('修改API用户','修改API用户:| ID: '.$id.' | appid:'.$appid);
|
||
return json(['code'=>1,'msg'=>'修改成功!']);
|
||
}else{
|
||
return json(['code'=>0,'msg'=>'修改失败!']);
|
||
}
|
||
}
|
||
}
|
||
|
||
// 删除扫描用户
|
||
public function scan_admin_del()
|
||
{
|
||
if(Request::instance()->post()){
|
||
// 接收数据
|
||
$scan_admin_id = Request::instance()->post('scan_admin_id');
|
||
$scan_admin = Db::name('scan_account')->where('id',$scan_admin_id)->find();
|
||
// 数据验证
|
||
if(!$scan_admin){
|
||
return json(['code'=>0,'msg'=>'用户不存在']);
|
||
}
|
||
|
||
// 删除用户
|
||
$result = Db::name('scan_account')->where('id',$scan_admin_id)->delete();
|
||
if($result){
|
||
insertAdminLog('删除扫描用户',"删除扫描用户: | appid: ".$scan_admin['appid']);
|
||
return json(['code'=>1,'msg'=>'删除成功!']);
|
||
}else{
|
||
return json(['code'=>1,'msg'=>'删除失败!']);
|
||
}
|
||
}else{
|
||
return json(['code'=>0,'msg'=>'操作错误!']);
|
||
}
|
||
}
|
||
// 删除API用户
|
||
public function api_admin_del(){
|
||
if(Request::instance()->post()){
|
||
// 接收数据
|
||
$id = Request::instance()->post('id');
|
||
// 删除用户
|
||
$result = Db::name('api_account')->where('id',$id)->delete();
|
||
if($result){
|
||
insertAdminLog('删除API用户',"删除API用户: | id: ".$id);
|
||
return json(['code'=>1,'msg'=>'删除成功!']);
|
||
}else{
|
||
return json(['code'=>1,'msg'=>'删除失败!']);
|
||
}
|
||
}
|
||
}
|
||
// 更改APIStatus
|
||
public function api_admin_status(){
|
||
if(Request::instance()->post()){
|
||
// 接收数据
|
||
$id = Request::instance()->post('id');
|
||
// 删除用户
|
||
$find = Db::name('api_account')->where('id',$id)->find();
|
||
if($find['status'] == 1){
|
||
$status = 0;
|
||
}else{
|
||
$status = 1;
|
||
}
|
||
$result = Db::name('api_account')->where('id',$id)->update(array('status' => $status));
|
||
if($result){
|
||
insertAdminLog('更改API用户状态',"更改API用户状态: | id: ".$id);
|
||
return json(['code'=>1,'msg'=>'更改状态成功!']);
|
||
}else{
|
||
return json(['code'=>1,'msg'=>'更改状态失败!']);
|
||
}
|
||
}
|
||
}
|
||
} |