diff --git a/controller/admin.php b/controller/admin.php index 1ec6fdb..0afc081 100755 --- a/controller/admin.php +++ b/controller/admin.php @@ -23,6 +23,12 @@ check_auth($site_setting['user'],$site_setting['password']); $version = new_get_version(); $page = empty($_GET['page']) ? 'index' : $_GET['page']; +// 正则判断page,只能允许字符+数字和下划线组合 +$pattern = "/^[a-zA-Z0-9_\/]+$/"; +if ( !preg_match($pattern,$page) ) { + exit('非法请求!'); +} + //如果是后台首页,则判断是否是手机访问,并决定是否跳转到手机版页面 if( $page == 'index' ) { @@ -323,6 +329,11 @@ function check_auth($user,$password){ } } +// 判断$page文件是否存在,不存在,则终止执行 +$full_page_path = 'templates/admin/'.$page; +if( !file_exists($full_page_path) ) { + exit("file does not exist!"); +} // 载入前台首页模板 require('templates/admin/'.$page); \ No newline at end of file diff --git a/controller/api.php b/controller/api.php index 058e554..1dbbf18 100755 --- a/controller/api.php +++ b/controller/api.php @@ -667,4 +667,4 @@ function global_search() { function upload_backup(){ global $api; $api->general_upload('data/backup/',['db3']); -} \ No newline at end of file +} diff --git a/controller/index.php b/controller/index.php index d733e93..f78470e 100755 --- a/controller/index.php +++ b/controller/index.php @@ -9,6 +9,8 @@ $site = unserialize($site); // 获取链接数量,默认为30 $link_num = empty( $site['link_num'] ) ? 30 : intval($site['link_num']); + + //如果已经登录,获取所有分类和链接 // 载入辅助函数 require('functions/helper.php'); @@ -77,6 +79,8 @@ if( is_login() ){ } //如果没有登录,只获取公有链接 else{ + // 检查分类是否全私有,如果是,则跳转到登录界面 + check_all_cat(); //查询分类目录 $categorys = []; //查询一级分类目录,分类fid为0的都是一级分类 diff --git a/controller/init.php b/controller/init.php index b1395ce..893c48b 100644 --- a/controller/init.php +++ b/controller/init.php @@ -66,6 +66,16 @@ function init($data){ if( empty($data['username']) || empty($data['password']) ) { err_msg(-2000,'用户名或密码不能为空!'); } + // 正则验证用户名 + $u_patt = '/^[0-9a-z]{3,32}$/'; + if( !preg_match($u_patt,$data['username']) ) { + err_msg(-2000,'用户名格式不正确!'); + } + // 正则验证密码 + $p_patt = '/^[0-9a-zA-Z!@#%^*.()]{6,16}$/'; + if( !preg_match($p_patt,$data['password']) ) { + err_msg(-2000,'密码格式不正确!'); + } $config_file = "data/config.php"; //检查配置文件是否存在,存在则不允许设置 if( file_exists($config_file) ) {