diff --git a/class/Api.php b/class/Api.php index 8c306ac..783606d 100755 --- a/class/Api.php +++ b/class/Api.php @@ -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协议的链接!'); } //获取网站标题 diff --git a/config.simple.php b/config.simple.php index e72ee02..19684a0 100755 --- a/config.simple.php +++ b/config.simple.php @@ -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'); //站点信息 diff --git a/controller/api.php b/controller/api.php index adcf8d3..7e62aee 100755 --- a/controller/api.php +++ b/controller/api.php @@ -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) { //生成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)); } \ No newline at end of file diff --git a/controller/index.php b/controller/index.php index 2decb9c..375195f 100755 --- a/controller/index.php +++ b/controller/index.php @@ -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; diff --git a/controller/init.php b/controller/init.php new file mode 100644 index 0000000..73a9cbf --- /dev/null +++ b/controller/init.php @@ -0,0 +1,110 @@ + + */ + + /** + * 安装前先检查环境 + */ +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(); +} diff --git a/templates/admin/index.php b/templates/admin/index.php index f59e49b..e8c224f 100755 --- a/templates/admin/index.php +++ b/templates/admin/index.php @@ -8,7 +8,9 @@
-
当前版本:
+
当前版本: + +
最新版本:获取中...
@@ -58,4 +60,5 @@ check_db_down(); check_weak_password(); get_sql_update_list(); + get_latest_version(); diff --git a/templates/admin/init.php b/templates/admin/init.php new file mode 100755 index 0000000..7db4e26 --- /dev/null +++ b/templates/admin/init.php @@ -0,0 +1,65 @@ + + + + + 初始化OneNav用户名/密码 + + + + + + + + + + + +
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+
+
+ + + + + + + \ No newline at end of file diff --git a/templates/admin/login.php b/templates/admin/login.php index ab60719..9156465 100755 --- a/templates/admin/login.php +++ b/templates/admin/login.php @@ -8,7 +8,7 @@ - +