2023-01-29 10:26:52 +08:00

237 lines
7.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | 小说系统 [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\common\controller\Admin;
class Index extends Admin {
public function index() {
$data['is_administrator'] = is_administrator();
$data['new'] = db('notice')->where('status=1')->order('id DESC')->limit(1)->find();
$list = db('notice')->where('status=1')->order('id desc')->paginate(config('list_rows'));
$data['list'] = $list;
$data['page'] = $list->render();
$this->assign($data);
$this->setMeta('后台首页');
return $this->fetch();
}
public function api_get_notice() {
$data = array(
"id"=>"3",
"title"=>"本周热门推荐榜单",
"content"=>"一、新品漫画:\n《暧昧公寓》-----数据不错,可上量尝试!\n\n二、热门轻小说推荐:\n1、《留住有情人》\n2、《那天我们爱了》\n3、《非你不嫁》",
"created_at"=>"1511493100",
"created_by_id"=>"635",
"target_user_type"=>"all"
);
header('Content-type: text/json');
echo json_encode($data);
exit();
}
public function login($username = '', $password = '', $verify = '') {
if (IS_POST) {
if (!$username || !$password) {
return $this->error('用户名或者密码不能为空!', '');
}
//验证码验证
//$this->checkVerify($verify);
$user = model('User');
$uid = $user->login($username, $password);
if ($uid > 0) {
return $this->success('登录成功!', '/');
} else {
switch ($uid) {
case -1:$error = '用户不存在或被禁用!';
break; //系统级别禁用
case -2:$error = '密码错误!';
break;
default:$error = '未知错误!';
break; // 0-接口参数错误(调试阶段使用)
}
return $this->error($error, '');
}
} else {
return $this->fetch();
}
}
public function logout() {
$user = model('User');
$user->logout();
$this->redirect('admin/index/login');
}
public function clear() {
if (IS_POST) {
$clear = input('post.clear/a', array());
foreach ($clear as $key => $value) {
if ($value == 'cache') {
\think\Cache::clear(); // 清空缓存数据
} elseif ($value == 'log') {
\think\Log::clear();
}
}
//opcache_reset();//清空opcache缓存
return $this->success("更新成功!", url('admin/index/index'));
} else {
$keylist = array(
array('name' => 'clear', 'title' => '更新缓存', 'type' => 'checkbox', 'help' => '', 'option' => array(
'cache' => '缓存数据',
'log' => '日志数据',
),
),
);
$data = array(
'keyList' => $keylist,
);
$this->assign($data);
$this->setMeta("更新缓存");
return $this->fetch('public/edit');
}
}
public function sys_tz() {
//服务器标识
$php_uname = @php_uname();
//服务器操作系统
$os = explode(" ", php_uname());
$oss = $os[0];
//内核版本
if('/'==DIRECTORY_SEPARATOR){
$Kernelversion = $os[2];
}else{
$Kernelversion = $os[1];
}
$sysInfo = $this->sys_linux();
}
//linux系统探测
public function sys_linux()
{
// CPU
if (false === ($str = @file("/proc/cpuinfo"))) return false;
$str = implode("", $str);
@preg_match_all("/model\s+name\s{0,}\:+\s{0,}([\w\s\)\(\@.-]+)([\r\n]+)/s", $str, $model);
@preg_match_all("/cpu\s+MHz\s{0,}\:+\s{0,}([\d\.]+)[\r\n]+/", $str, $mhz);
@preg_match_all("/cache\s+size\s{0,}\:+\s{0,}([\d\.]+\s{0,}[A-Z]+[\r\n]+)/", $str, $cache);
@preg_match_all("/bogomips\s{0,}\:+\s{0,}([\d\.]+)[\r\n]+/", $str, $bogomips);
var_dump($model[1]);
exit();
if (false !== is_array($model[1]))
{
$res['cpu']['num'] = sizeof($model[1]);
/*
for($i = 0; $i < $res['cpu']['num']; $i++)
{
$res['cpu']['model'][] = $model[1][$i].'&nbsp;('.$mhz[1][$i].')';
$res['cpu']['mhz'][] = $mhz[1][$i];
$res['cpu']['cache'][] = $cache[1][$i];
$res['cpu']['bogomips'][] = $bogomips[1][$i];
}*/
if($res['cpu']['num']==1)
$x1 = '';
else
$x1 = ' ×'.$res['cpu']['num'];
$mhz[1][0] = ' | 频率:'.$mhz[1][0];
$cache[1][0] = ' | 二级缓存:'.$cache[1][0];
$bogomips[1][0] = ' | Bogomips:'.$bogomips[1][0];
$res['cpu']['model'][] = $model[1][0].$mhz[1][0].$cache[1][0].$bogomips[1][0].$x1;
if (false !== is_array($res['cpu']['model'])) $res['cpu']['model'] = implode("<br />", $res['cpu']['model']);
var_dump($res);
exit();
if (false !== is_array($res['cpu']['mhz'])) $res['cpu']['mhz'] = implode("<br />", $res['cpu']['mhz']);
if (false !== is_array($res['cpu']['cache'])) $res['cpu']['cache'] = implode("<br />", $res['cpu']['cache']);
if (false !== is_array($res['cpu']['bogomips'])) $res['cpu']['bogomips'] = implode("<br />", $res['cpu']['bogomips']);
}
// NETWORK
// UPTIME
if (false === ($str = @file("/proc/uptime"))) return false;
$str = explode(" ", implode("", $str));
$str = trim($str[0]);
$min = $str / 60;
$hours = $min / 60;
$days = floor($hours / 24);
$hours = floor($hours - ($days * 24));
$min = floor($min - ($days * 60 * 24) - ($hours * 60));
if ($days !== 0) $res['uptime'] = $days."";
if ($hours !== 0) $res['uptime'] .= $hours."小时";
$res['uptime'] .= $min."分钟";
// MEMORY
if (false === ($str = @file("/proc/meminfo"))) return false;
$str = implode("", $str);
preg_match_all("/MemTotal\s{0,}\:+\s{0,}([\d\.]+).+?MemFree\s{0,}\:+\s{0,}([\d\.]+).+?Cached\s{0,}\:+\s{0,}([\d\.]+).+?SwapTotal\s{0,}\:+\s{0,}([\d\.]+).+?SwapFree\s{0,}\:+\s{0,}([\d\.]+)/s", $str, $buf);
preg_match_all("/Buffers\s{0,}\:+\s{0,}([\d\.]+)/s", $str, $buffers);
$res['memTotal'] = round($buf[1][0]/1024, 2);
$res['memFree'] = round($buf[2][0]/1024, 2);
$res['memBuffers'] = round($buffers[1][0]/1024, 2);
$res['memCached'] = round($buf[3][0]/1024, 2);
$res['memUsed'] = $res['memTotal']-$res['memFree'];
$res['memPercent'] = (floatval($res['memTotal'])!=0)?round($res['memUsed']/$res['memTotal']*100,2):0;
$res['memRealUsed'] = $res['memTotal'] - $res['memFree'] - $res['memCached'] - $res['memBuffers']; //真实内存使用
$res['memRealFree'] = $res['memTotal'] - $res['memRealUsed']; //真实空闲
$res['memRealPercent'] = (floatval($res['memTotal'])!=0)?round($res['memRealUsed']/$res['memTotal']*100,2):0; //真实内存使用率
$res['memCachedPercent'] = (floatval($res['memCached'])!=0)?round($res['memCached']/$res['memTotal']*100,2):0; //Cached内存使用率
$res['swapTotal'] = round($buf[4][0]/1024, 2);
$res['swapFree'] = round($buf[5][0]/1024, 2);
$res['swapUsed'] = round($res['swapTotal']-$res['swapFree'], 2);
$res['swapPercent'] = (floatval($res['swapTotal'])!=0)?round($res['swapUsed']/$res['swapTotal']*100,2):0;
// LOAD AVG
if (false === ($str = @file("/proc/loadavg"))) return false;
$str = explode(" ", implode("", $str));
$str = array_chunk($str, 4);
$res['loadAvg'] = implode(" ", $str[0]);
return $res;
}
/******切换公众号*****/
public function switch() {
$wxmpid = input('wxmpid');
$wxmp = db('wxmp')->where('id ='.$wxmpid." and status =1")->field('id,webname')->find();
if($wxmp){
/* 更新SESSION */
session('wxmpid', $wxmp['id']);
session('webname',$wxmp['webname']);
echo json_encode(array("code"=>200));
}else{
echo json_encode(array("code"=>0));
}
exit();
}
//在线人数统计
public function usercount(){
$uid = session('user_auth.uid');
$mp=array();
$time = time() - 60*10;
$mp['update_time'] = ['>',$time];
$user_count = db('history')->field('count(DISTINCT uid) as user')->where($mp)->count('id');
return $user_count;
}
}