初始化官网代码

This commit is contained in:
wojiaoxiaomage
2025-12-30 10:26:47 +08:00
commit 00f55e8b83
232 changed files with 49856 additions and 0 deletions

View File

@@ -0,0 +1,193 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2016年12月25日
* 应用公共控制类
*/
namespace app\common;
use core\basic\Controller;
class AdminController extends Controller
{
public function __construct()
{
// 自动缓存基础信息
cache_config();
// 检测登录,未登录跳转登录页面,已登录执行数据处理
if ($this->checkLogin()) {
// 权限检测
$this->checkLevel();
$this->getSecondMenu(); // 获取同级菜单
$this->assign('menu_tree', session('menu_tree')); // 注入菜单树
if (session('area_tree')) {
$area_html = make_area_Select(session('area_tree'), session('acode'));
$this->assign('area_html', $area_html);
if (count(session('area_tree')) == 1) {
$this->assign('one_area', true);
}
} else {
session_unset();
error('您账号的区域权限设置有误,无法正常登录!', url('/admin/Index/index'), 10);
}
// 内容模型菜单注入
$models = model('admin.content.Model');
$this->assign('menu_models', $models->getModelMenu());
// 注入编码后的回跳地址
$this->assign('btnqs', get_btn_qs());
$this->assign('backurl', get_backurl());
// 兼容模式form使用get搜索时注入pathinfo隐藏域
if ($_GET['p'] && $this->config('app_url_type') == 3) {
$this->assign('pathinfo', '<input name="p" type="hidden" value="' . get('p') . '">');
}
}
// 不进行表单检验的控制器
$nocheck = array(
'Upgrade'
);
// POST表单提交校验
if ($_POST && ! in_array(C, $nocheck) && session('formcheck') != post('formcheck')) {
// 检查会话目录权限问题
if (session_save_path()) {
preg_match('/^((\s+)?([0-9]+)(\s+)?;)?(.*)/', session_save_path(), $matches);
// 自动创建会话主目录
if (! check_dir($matches[5], true)) {
error('会话目录创建失败!' . $matches[5]);
}
// 检查会话目录写入权限
if (! is_writable($matches[5])) {
error('会话目录权限不足!' . $matches[5]);
}
// 自动创建层级会话目录
if ($matches[3]) {
create_session_dir($matches[5], $matches[3]);
}
} elseif (isset($_SERVER['TMP']) && ! file_exists($_SERVER['TMP'] . '/sess_' . session_id())) {
error(' 操作系统缓存目录写入权限不足!' . $_SERVER['TMP']);
}
alert_back('表单提交校验失败,请刷新后重试!');
}
// 首次加载时,生成页面验证码
if (! issetSession('formcheck')) {
session('formcheck', get_uniqid());
}
$this->assign('formcheck', session('formcheck')); // 注入formcheck模板变量
}
// 后台用户登录状态检查
private function checkLogin()
{
// 免登录可访问页面
$public_path = array(
'/admin/Index/index', // 登录页面
'/admin/Index/login' // 执行登录
);
if (session('sid') && $this->checkSid()) { // 如果已经登录直接true
return true;
} elseif (in_array('/' . M . '/' . C . '/' . F, $public_path)) { // 免登录可访问页面
return false;
} else { // 未登录跳转到登录页面
location(url('/admin/Index/index'));
}
}
// 检查会话id
private function checkSid()
{
$sid = encrypt_string(session_id() . session('id'));
if ($sid != session('sid') || session('M') != M) {
session_destroy();
return false;
} else {
return true;
}
}
// 访问权限检查
private function checkLevel()
{
// 免权限等级认证页面,即所有登录用户都可以访问
$public_path = array(
'/admin/Index/index', // 登录页
'/admin/Index/home', // 主页
'/admin/Index/loginOut', // 退出登录
'/admin/Index/ucenter', // 用户中心
'/admin/Index/area', // 区域选择
'/admin/Index/clearCache', // 清理缓存
'/admin/Index/upload' // 上传文件
);
$levals = session('levels');
$path1 = '/' . M . '/' . C;
$path2 = '/' . M . '/' . C . '/' . F;
if (session('id') == 1 || in_array(URL, $levals) || in_array($path2, $levals) || in_array($path1, $public_path) || in_array($path2, $public_path)) {
return true;
} else {
error('您的账号权限不足,您无法执行该操作!');
}
}
// 当前菜单的父类的子菜单,即同级菜单二级菜单
private function getSecondMenu()
{
$menu_tree = session('menu_tree');
$url = '/' . M . '/' . C . '/' . F;
$len = 0;
$primary_menu_url = '';
$second_menu = array();
// 直接比对找出最长匹配URL
foreach ($menu_tree as $key => $value) {
if (is_array($value->son)) {
foreach ($value->son as $key2 => $value2) {
if (! $value2->url) // 如果为空,则跳过
continue;
$pos = strpos($url, $value2->url);
if ($pos !== false) {
$templen = strlen($value2->url);
if ($templen > $len) {
$len = $templen;
$primary_menu_url = $value->url;
$second_menu = $value->son;
}
break; // 如果匹配到已经找到父类,则结束
}
}
}
}
// 前面第一种无法匹配,则选择子菜单匹配,只需控制器通过即可,如翻页、增、改、删操作
if (! $second_menu) {
foreach ($menu_tree as $key => $value) {
if (is_array($value->son)) {
foreach ($value->son as $key2 => $value2) {
if (strpos($value2->url, '/' . M . '/' . C . '/') === 0) {
$primary_menu_url = $value->url;
$second_menu = $value->son;
break;
}
}
}
if ($second_menu) { // 已经获取二级菜单到后退出
break;
}
}
}
$this->assign('primary_menu_url', $primary_menu_url);
$this->assign('second_menu', $second_menu);
}
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2018年4月22日
* API公共控制类
*/
namespace app\common;
use core\basic\Controller;
use core\basic\Config;
class ApiController extends Controller
{
public function __construct()
{
// 自动缓存基础信息
cache_config();
$this->checkAccess($this->config());
}
/**
* 客户端发起请求必须包含appid、timestamp、signature三个参数;
* signature通过appid、secret、timestamp连接为一个字符串,然后进行双层md5加密生成;
*/
public static function checkAccess($config)
{
if (! isset($config['api_open']) || ! $config['api_open']) {
json(0, '系统尚未开启API功能请到后台配置');
}
// 验证总开关
if ($config['api_auth']) {
// 判断用户
if (! $config['api_appid']) {
json(0, '请求失败:管理后台接口认证用户配置有误');
}
// 判断密钥
if (! $config['api_secret']) {
json(0, '请求失败:管理后台接口认证密钥配置有误');
}
// 获取参数
if (! $appid = request('appid')) {
json(0, '请求失败未检查到appid参数');
}
if (! $timestamp = request('timestamp')) {
json(0, '请求失败未检查到timestamp参数');
}
if (! $signature = request('signature')) {
json(0, '请求失败未检查到signature参数');
}
// 验证时间戳
if (strpos($_SERVER['HTTP_REFERER'], get_http_url()) === false && time() - $timestamp > 15) { // 请求时间戳认证不得超过15秒
json(0, '请求失败:接口时间戳验证失败!');
}
// 验证签名
if ($signature != md5(md5($config['api_appid'] . $config['api_secret'] . $timestamp))) {
error('请求失败:接口签名信息错误!');
}
}
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2018年04月12日
* 前台公共控制类
*/
namespace app\common;
use core\basic\Controller;
use core\basic\Config;
class HomeController extends Controller
{
public function __construct()
{
// 自动缓存基础信息
cache_config();
// 站点关闭检测
if (! ! $close_site = Config::get('close_site')) {
$close_site_note = Config::get('close_site_note');
error($close_site_note ?: '本站维护中,请稍后再访问,带来不便,敬请谅解!');
}
// IP访问黑白名单检测
$user_ip = get_user_ip(); // 获取用户IP
if (filter_var($user_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
// ip黑名单
$ip_deny = Config::get('ip_deny', true);
foreach ($ip_deny as $key => $value) {
if (network_match($user_ip, $value)) {
error('本站启用了黑名单功能您的IP(' . $user_ip . ')不允许访问!');
}
}
// ip白名单
$ip_allow = Config::get('ip_allow', true);
foreach ($ip_allow as $key => $value) {
if (network_match($user_ip, $value)) {
$allow = true;
}
}
// 如果设置了白名单IP不在白名单内则阻止访问
if ($ip_allow && ! isset($allow)) {
error('本站启用了白名单功能您的IP(' . $user_ip . ')不在允许范围!');
}
}
// 语言绑定域名检测, 如果匹配到多语言绑定则自动设置当前语言
$lgs = Config::get('lgs');
if (count($lgs) > 1) {
$domain = get_http_host();
foreach ($lgs as $value) {
if ($value['domain'] == $domain) {
cookie('lg', $value['acode']);
break;
}
}
}
// 未设置语言时使用默认语言
if (! isset($_COOKIE['lg'])) {
cookie('lg', get_default_lg());
}
// 手机自适应主题
if ($this->config('open_wap')) {
if ($this->config('wap_domain') && $this->config('wap_domain') == get_http_host()) {
$this->setTheme(get_theme() . '/wap'); // 已绑域名并且一致则自动手机版本
} elseif (is_mobile() && $this->config('wap_domain') && $this->config('wap_domain') != get_http_host()) {
if (is_https()) {
$pre = 'https://';
} else {
$pre = 'http://';
}
header('Location:' . $pre . $this->config('wap_domain') . URL); // 手机访问并且绑定了域名,但是访问域名不一致则跳转
} elseif (is_mobile()) { // 其他情况手机访问则自动手机版本
$this->setTheme(get_theme() . '/wap');
} else { // 其他情况,电脑版本
$this->setTheme(get_theme());
}
} else { // 未开启手机,则一律电脑版本
$this->setTheme(get_theme());
}
}
}

View File

@@ -0,0 +1,50 @@
<?php
return array(
// URL地址路由// 'home/index' => 'home/index/index'
'url_route' => array(
// =======管理端路由============
// 系统模块路由
'admin/Area' => 'admin/system.Area',
'admin/Menu' => 'admin/system.Menu',
'admin/Role' => 'admin/system.Role',
'admin/User' => 'admin/system.User',
'admin/Type' => 'admin/system.Type',
'admin/Syslog' => 'admin/system.Syslog',
'admin/Database' => 'admin/system.Database',
'admin/Config' => 'admin/system.Config',
'admin/Upgrade' => 'admin/system.Upgrade',
// 内容发布模块路由
'admin/Site' => 'admin/content.Site',
'admin/Company' => 'admin/content.Company',
'admin/Label' => 'admin/content.Label',
'admin/Model' => 'admin/content.Model',
'admin/ExtField' => 'admin/content.ExtField',
'admin/ContentSort' => 'admin/content.ContentSort',
'admin/Content' => 'admin/content.Content',
'admin/Single' => 'admin/content.Single',
'admin/Message' => 'admin/content.Message',
'admin/Slide' => 'admin/content.Slide',
'admin/Link' => 'admin/content.Link',
'admin/Form' => 'admin/content.Form',
'admin/Tags' => 'admin/content.Tags',
// 会员模块
'admin/MemberGroup' => 'admin/member.MemberGroup',
'admin/MemberField' => 'admin/member.MemberField',
'admin/Member' => 'admin/member.Member',
'admin/MemberComment' => 'admin/member.MemberComment',
// 前台及接口路径统一小写URL
// =======前台路由============
'home/sitemap.xml' => 'home/Sitemap/index', // 站点地图1
'home/sitemap' => 'home/Sitemap/index', // 站点地图2
// =======接口路由============
'api/list' => 'api/list/index/scode',
'api/content' => 'api/content/index/id',
'api/about' => 'api/about/index/scode',
'api/search' => 'api/search/index'
)
);

View File

@@ -0,0 +1,12 @@
<?php
return array(
// 应用版本
'app_version' => '3.0.3',
// 发布时间
'release_time' => '20201007',
// 修订版本
'revise_version' => '0'
);