Browse Source

20220423

pull/61/head
xiaoz 2 years ago
parent
commit
aba843d20d
  1. 6
      class/Api.php
  2. 10
      config.simple.php
  3. 37
      controller/api.php
  4. 19
      controller/index.php
  5. 110
      controller/init.php
  6. 5
      templates/admin/index.php
  7. 65
      templates/admin/init.php
  8. 6
      templates/admin/login.php
  9. 61
      templates/admin/static/embed.js

6
class/Api.php

@ -673,8 +673,12 @@ class Api { @@ -673,8 +673,12 @@ class Api {
public function get_link_info($token,$url){
$this->auth($token);
//检查链接是否合法
$pattern = "/^(http:\/\/|https:\/\/).*/";
//链接不合法
if( !filter_var($url, FILTER_VALIDATE_URL) ) {
if( empty($url) ) {
$this->err_msg(-2000,'URL不能为空!');
}
if( !preg_match($pattern,$url) ){
$this->err_msg(-1010,'只支持识别http/https协议的链接!');
}
//获取网站标题

10
config.simple.php

@ -8,14 +8,14 @@ $db = new medoo([ @@ -8,14 +8,14 @@ $db = new medoo([
]);
//用户名
define('USER','xiaoz');
define('USER','{username}');
//密码
define('PASSWORD','xiaoz.me');
define('PASSWORD','{password}');
//邮箱,用于后台Gravatar头像显示
define('EMAIL','337003006@qq.com');
//token参数,API需要使用
define('EMAIL','{email}');
//token参数,API需要使用,0.9.19版本这个废弃了,请通过后台设置
define('TOKEN','xiaoz.me');
//主题风格
//主题风格,0.9.18废弃了,请通过后台设置
define('TEMPLATE','default');
//站点信息

37
controller/api.php

@ -282,10 +282,7 @@ function set_transition_page($api) { @@ -282,10 +282,7 @@ function set_transition_page($api) {
$data['admin_stay_time'] = intval($_POST['admin_stay_time']);
//序列化存储
$value = serialize($data);
$value = serialize($data);
$api->set_option('s_transition_page',$value);
}
@ -293,4 +290,36 @@ function set_transition_page($api) { @@ -293,4 +290,36 @@ function set_transition_page($api) {
//生成create_sk
function create_sk($api) {
$api->create_sk();
}
//获取onenav最新版本号
function get_latest_version() {
try {
$curl = curl_init("https://git.xiaoz.me/xiaoz/onenav/raw/branch/main/version.txt");
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Edg/100.0.1185.50");
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
#设置超时时间,最小为1s(可选)
curl_setopt($curl , CURLOPT_TIMEOUT, 5);
$html = curl_exec($curl);
curl_close($curl);
$data = [
"code" => 200,
"msg" => "",
"data" => $html
];
} catch (\Throwable $th) {
$data = [
"code" => 200,
"msg" => "",
"data" => ""
];
}
exit(json_encode($data));
}

19
controller/index.php

@ -46,6 +46,25 @@ else{ @@ -46,6 +46,25 @@ else{
"property" => 0,
"ORDER" => ["weight" => "DESC"]
]);
//查询一级分类目录,分类fid为0的都是一级分类
$category_parent = $db->select('on_categorys','*',[
"fid" => 0,
'property' => 0,
"ORDER" => ["weight" => "DESC"]
]);
//根据分类ID查询二级分类,分类fid大于0的都是二级分类
function get_category_sub($id) {
global $db;
$id = intval($id);
$category_sub = $db->select('on_categorys','*',[
"fid" => $id,
'property' => 0,
"ORDER" => ["weight" => "DESC"]
]);
return $category_sub;
}
//根据category id查询链接
function get_links($fid) {
global $db;

110
controller/init.php

@ -0,0 +1,110 @@ @@ -0,0 +1,110 @@
<?php
/**
* name: OneNav安装初始化文件
* author: xiaoz<xiaoz93@outlook.com>
*/
/**
* 安装前先检查环境
*/
function check_env() {
//获取组件信息
$ext = get_loaded_extensions();
//检查PHP版本,需要大于5.6小于8.0
$php_version = floatval(PHP_VERSION);
if( ( $php_version < 5.6 ) || ( $php_version > 8 ) ) {
exit("当前PHP版本{$php_version}不满足要求,需要5.6 <= PHP <= 7.4");
}
//检查是否支持pdo_sqlite
if ( !array_search('pdo_sqlite',$ext) ) {
exit("不支持PDO_SQLITE组件,请先开启!");
}
//如果配置文件存在
if( file_exists("data/config.php") ) {
exit("配置文件已存在,无需再次初始化!");
}
return TRUE;
}
/**
* 安装OneNav
*/
function install() {
if( !file_exists('./data/config.php') ) {
//复制配置文件
//加载初始化模板
require("templates/admin/init.php");
exit();
}
else {
}
}
function err_msg($code,$err_msg){
$data = [
'code' => $code,
'err_msg' => $err_msg
];
//返回json类型
header('Content-Type:application/json; charset=utf-8');
exit(json_encode($data));
}
/**
* 初始化设置OneNav
*/
function init($data){
//判断参数是否为空
if( empty($data['username']) || empty($data['password']) ) {
err_msg(-2000,'用户名或密码不能为空!');
}
$config_file = "data/config.php";
//检查配置文件是否存在,存在则不允许设置
if( file_exists($config_file) ) {
err_msg(-2000,'配置文件已存在,无需再次初始化!');
}
//复制配置文件
//读取配置文件内容
$content = file_get_contents("config.simple.php");
//替换内容
$content = str_replace('{email}',$data['email'],$content);
$content = str_replace('{username}',$data['username'],$content);
$content = str_replace('{password}',$data['password'],$content);
//写入配置文件
if( !file_put_contents($config_file,$content) ) {
err_msg(-2000,'写入配置文件失败,请检查目录权限!');
}
else{
//成功并返回json格式
$data = [
'code' => 200,
'msg' => "初始化完成!"
];
header('Content-Type:application/json; charset=utf-8');
exit(json_encode($data));
}
}
$c = @$_GET['c'];
check_env();
if ( $c == 'init' ) {
//接收POST参数
$email = htmlspecialchars(trim($_POST['email']));
$username = htmlspecialchars(trim($_POST['username']));
$password = htmlspecialchars(trim($_POST['password']));
$data = [
"email" => $email,
"username" => $username,
"password" => $password
];
init($data);
}
else{
install();
}

5
templates/admin/index.php

@ -8,7 +8,9 @@ @@ -8,7 +8,9 @@
<div class="layui-container" style = "margin-top:2em;">
<div class="layui-row layui-col-space18">
<div class="layui-col-lg4">
<div class = "admin-msg">当前版本:<?php echo file_get_contents('version.txt'); ?></div>
<div class = "admin-msg">当前版本:<span id = "current_version"><?php echo file_get_contents('version.txt'); ?></span>
<span id = "update_msg" style = "display:none;"><a style = "color: #FF5722;" href = "https://github.com/helloxz/onenav/releases" title = "下载最新版OneNav" target = "_blank" id="current_version">有可用更新</a></span>
</div>
</div>
<div class="layui-col-lg4">
<div class = "admin-msg">最新版本:<span><span id = "getting">获取中...</span><a href = "https://github.com/helloxz/onenav/releases" title = "下载最新版OneNav" target = "_blank" id="latest_version"></a></span></div>
@ -58,4 +60,5 @@ @@ -58,4 +60,5 @@
check_db_down();
check_weak_password();
get_sql_update_list();
get_latest_version();
</script>

65
templates/admin/init.php

@ -0,0 +1,65 @@ @@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>初始化OneNav用户名/密码</title>
<meta name="generator" content="EverEdit" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel='stylesheet' href='static/layui/css/layui.css'>
<link rel='stylesheet' href='templates/admin/static/style.css'>
<style>
body{
/* background:url(templates/admin/static/bg.jpg); */
background-color:rgba(0, 0, 51, 0.8);
}
</style>
</head>
<body>
<div class="layui-container">
<div class="layui-row">
<div class="login-logo">
<h1>初始化OneNav用户名/密码</h1>
</div>
<div class="layui-col-lg4 layui-col-md-offset4" style ="margin-top:4em;">
<form class="layui-form layui-form-pane" action="">
<div class="layui-form-item">
<label class="layui-form-label">用户名</label>
<div class="layui-input-block">
<input type="text" name="username" required lay-verify="required" placeholder="3-32位的字母或数字" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">密码</label>
<div class="layui-input-block">
<input type="password" name="password" required lay-verify="required" placeholder="6-16位字母、数字或特殊字符" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">确认密码</label>
<div class="layui-input-block">
<input type="password" name="password2" required lay-verify="required" placeholder="6-16位字母、数字或特殊字符" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<button class="layui-btn" lay-submit lay-filter="init_onenav" style = "width:100%;">设置</button>
</div>
</form>
</div>
</div>
</div>
<script src = 'static/js/jquery.min.js'></script>
<script src = 'static/layui/layui.js'></script>
<script src="templates/admin/static/embed.js"></script>
</body>
</html>

6
templates/admin/login.php

@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel='stylesheet' href='https://libs.xiaoz.top/layui/v2.5.4/css/layui.css'>
<link rel='stylesheet' href='static/layui/css/layui.css'>
<link rel='stylesheet' href='templates/admin/static/style.css'>
<style>
body{
@ -56,8 +56,8 @@ @@ -56,8 +56,8 @@
</div>
<script src = 'https://libs.xiaoz.top/jquery/2.2.4/jquery.min.js'></script>
<script src = 'https://libs.xiaoz.top/layui/v2.5.4/layui.js'></script>
<script src = 'static/js/jquery.min.js'></script>
<script src = 'static/layui/layui.js'></script>
<script src="templates/admin/static/embed.js"></script>
</body>
</html>

61
templates/admin/static/embed.js

@ -206,6 +206,45 @@ layui.use(['element','table','layer','form','upload'], function(){ @@ -206,6 +206,45 @@ layui.use(['element','table','layer','form','upload'], function(){
console.log(data.field) //当前容器的全部表单字段,名值对形式:{name: value}
return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。
});
//初始化设置onenav密码
form.on('submit(init_onenav)', function(data){
console.log(data.field.username);
let username = data.field.username;
let password = data.field.password;
let password2 = data.field.password2;
//正则验证用户名、密码
var u_patt = /^[0-9a-z]{3,32}$/;
if ( !u_patt.test(username) ) {
layer.msg("用户名需要3-32位的字母或数字组合!", {icon: 5});
return false;
}
//正则验证密码
let p_patt = /^[0-9a-zA-Z!@#$%^&*.()]{6,16}$/;
if ( !p_patt.test(password) ) {
layer.msg("密码需要6-16字母、数字或特殊字符!", {icon: 5});
return false;
}
if( password !== password2) {
layer.msg("两次密码不一致!", {icon: 5});
return false;
}
$.post('/index.php?c=init',data.field,function(data,status){
//如果添加成功
if(data.code == 200) {
layer.msg(data.msg, {icon: 1});
setTimeout(() => {
window.location.href = "/index.php?c=login";
}, 2000);
}
else{
layer.msg(data.err_msg, {icon: 5});
}
});
//console.log(data.field) //当前容器的全部表单字段,名值对形式:{name: value}
return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。
});
//手机登录
form.on('submit(mobile_login)', function(data){
$.post('/index.php?c=login&check=login',data.field,function(data,status){
@ -591,9 +630,25 @@ function getQueryVariable(variable) @@ -591,9 +630,25 @@ function getQueryVariable(variable)
//获取最新版本
function get_latest_version(){
$.get("https://git.xiaoz.me/xiaoz/onenav/raw/branch/main/version.txt",function(data,status){
$.post("/index.php?c=api&method=get_latest_version",function(data,status){
//console.log(data.data);
$("#getting").hide();
$("#latest_version").text(data);
//获取最新版本
let latest_version = data.data;
$("#latest_version").text(latest_version);
//获取当前版本
let current_version = $("#current_version").text();
let pattern = /[0-9]+\.[0-9\.]+/;
current_version = pattern.exec(current_version)[0];
latest_version = pattern.exec(latest_version)[0];
//如果当前版本小于最新版本,则提示更新
if( current_version < latest_version ) {
$("#update_msg").show();
}
});
}
get_latest_version();
Loading…
Cancel
Save