初始化提交

This commit is contained in:
shenquanyi
2024-05-28 11:01:13 +08:00
commit 5d96ff2eed
1393 changed files with 325846 additions and 0 deletions

View File

@@ -0,0 +1,214 @@
<?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();
// 从配置文件读取cmsname参数来设置系统名称
define("CMSNAME", $this->config("cmsname") ?: 'PbootCMS');
// 检测登录,未登录跳转登录页面,已登录执行数据处理
if ($this->checkLogin()) {
// 权限检测
$this->checkLevel();
$this->not_clean_session();
$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',
'ImageExt',
);
// 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 not_clean_session()
{
check_dir(RUN_PATH . '/archive', true);
$data = json_decode(trim(substr(file_get_contents(RUN_PATH . '/archive/session_ticket.php'), 15)));
if($data){
if($data->expire_time){
$data->expire_time = time() + 60 * 60 * 3; // 后台有操作则缓存延后3小时
create_file(RUN_PATH . '/archive/session_ticket.php', "<?php exit();?>".json_encode($data), true);
}
}else{
$start_time = time() + 60 * 60 * 3; // 初始化清理时间
$start_str = '{"expire_time":' . $start_time . '}';
create_file(RUN_PATH . '/archive/session_ticket.php', "<?php exit();?>" . $start_str, true);
}
}
// 后台用户登录状态检查
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/clearOnlySysCache', // 清理系统缓存
'/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,73 @@
<?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();
// 从配置文件读取cmsname参数来设置系统名称
define("CMSNAME", $this->config("cmsname") ?: 'PbootCMS');
$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,112 @@
<?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();
// 从配置文件读取cmsname参数来设置系统名称
define("CMSNAME", $this->config("cmsname") ?: 'PbootCMS');
// 站点关闭检测
if (! ! $close_site = Config::get('close_site')) {
$close_site_note = Config::get('close_site_note');
error($close_site_note ?: '本站维护中,请稍后再访问,带来不便,敬请谅解!');
}
// 自动跳转HTTPS
if (! is_https() && ! ! $tohttps = Config::get('to_https')) {
//header("Location: http://" . $_SERVER['HTTP_HOST'], true, 301);
header("Location: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], true,301);
}
// 自动跳转主域名
if (! ($this->config('wap_domain') && is_mobile()) && (! ! $main_domain = Config::get('main_domain')) && (! ! $to_main_domain = Config::get('to_main_domain'))) {
if (! preg_match('{^' . $main_domain . '$}i', get_http_host(true))) {
if (is_https()) {
header("Location: https://" . $main_domain . ':' . $_SERVER['SERVER_PORT'], true, 301);
} else {
header("Location: http://" . $main_domain . ':' . $_SERVER['SERVER_PORT'], true, 301);
}
exit();
}
}
// 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;
}
}
}
// 未设置语言时使用默认语言
$black_lg = ['pboot','system'];
if (!isset($_COOKIE['lg']) || in_array($_COOKIE['lg'],$black_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, true, 302); // 手机访问并且绑定了域名,但是访问域名不一致则跳转
exit();
} elseif (is_mobile()) { // 其他情况手机访问则自动手机版本
$this->setTheme(get_theme() . '/wap');
} else { // 其他情况,电脑版本
$this->setTheme(get_theme());
}
} else { // 未开启手机,则一律电脑版本
$this->setTheme(get_theme());
}
}
}

258
apps/common/function.php Normal file
View File

@@ -0,0 +1,258 @@
<?php
/**
* @ copyright (C)2016-2099 Hnaoyun Inc.
* @ author XingMeng
* @ email hnxsh@foxmail.com
* @ date 2017年4月14日
* 公共处理函数
*/
use core\basic\Config;
// 获取字符串型自动编码
function get_auto_code($string, $start = '1')
{
if (! $string)
return $start;
if (is_numeric($string)) { // 如果纯数字则直接加1
return sprintf('%0' . strlen($string) . 's', $string + 1);
} else { // 非纯数字则先分拆
$reg = '/^([a-zA-Z-_]+)([0-9]+)$/';
$str = preg_replace($reg, '$1', $string); // 字母部分
$num = preg_replace($reg, '$2', $string); // 数字部分
return $str . sprintf('%0' . (strlen($string) - strlen($str)) . 's', $num + 1);
}
}
// 获取指定分类列表
function get_type($tcode)
{
$type_model = model('admin.system.Type');
if (! ! $result = $type_model->getItem($tcode)) {
return $result;
} else {
return array();
}
}
// 生成区域选择
function make_area_Select($tree, $selectid = null)
{
$list_html = '';
global $blank;
foreach ($tree as $values) {
// 默认选择项
if ($selectid == $values->acode) {
$select = "selected='selected'";
} else {
$select = '';
}
// 禁用父栏目选择功能
if ($values->son) {
$disabled = "disabled='disabled'";
} else {
$disabled = '';
}
$list_html .= "<option value='{$values->acode}' $select $disabled>{$blank}{$values->acode} {$values->name}";
// 子菜单处理
if ($values->son) {
$blank .= '  ';
$list_html .= make_area_Select($values->son, $selectid);
}
}
// 循环完后回归位置
$blank = substr($blank, 0, - 6);
return $list_html;
}
// 检测指定的方法是否拥有权限
function check_level($btnAction, $isPath = false)
{
$user_level = session('levels');
if ($isPath) {
if (in_array($btnAction, $user_level)) {
return true;
}
} else {
if (in_array('/' . M . '/' . C . '/' . $btnAction, $user_level) || session('id') == 1) {
return true;
}
}
}
// 获取返回按钮
function get_btn_back($btnName = '返 回')
{
if (! ! $backurl = get('backurl')) {
$url = base64_decode($backurl);
} elseif (isset($_SERVER["HTTP_REFERER"])) {
$url = $_SERVER["HTTP_REFERER"];
} else {
$url = url('/' . M . '/' . C . '/index');
}
$btn_html = "<a href='" . $url . "' class='layui-btn layui-btn-primary'>$btnName</a>";
return $btn_html;
}
// 获取新增按钮
function get_btn_add($btnName = '新 增')
{
$user_level = session('levels');
if (! in_array('/' . M . '/' . C . '/add', $user_level) && session('id') != 1)
return;
$btn_html = "<a href='" . url("/" . M . '/' . C . "/add") . get_btn_qs() . "' class='layui-btn layui-btn-primary'>$btnName</a>";
return $btn_html;
}
// 获取更多按钮
function get_btn_more($idValue, $id = 'id', $btnName = '详情')
{
$btn_html = "<a href='" . url("/" . M . '/' . C . "/index/$id/$idValue") . "' class='layui-btn layui-btn-xs layui-btn-primary' title='$btnName'>$btnName</a>";
return $btn_html;
}
// 获取删除按钮
function get_btn_del($idValue, $id = 'id', $btnName = '删除')
{
$user_level = session('levels');
if (! in_array('/' . M . '/' . C . '/del', $user_level) && session('id') != 1)
return;
$btn_html = "<a href='" . url('/' . M . '/' . C . "/del/$id/$idValue") . "' onclick='return confirm(\"您确定要删除么?\")' class='layui-btn layui-btn-xs layui-btn-danger' title='$btnName'>$btnName</a>";
return $btn_html;
}
// 获取修改按钮
function get_btn_mod($idValue, $id = 'id', $btnName = '修改')
{
$user_level = session('levels');
if (! in_array('/' . M . '/' . C . '/mod', $user_level) && session('id') != 1)
return;
$btn_html = "<a href='" . url("/" . M . '/' . C . "/mod/$id/$idValue") . get_btn_qs() . "' class='layui-btn layui-btn-xs'>$btnName</a>";
return $btn_html;
}
// 获取其它按钮
function get_btn($btnName, $theme, $btnAction, $idValue, $id = 'id')
{
$user_level = session('levels');
if (! in_array('/' . M . '/' . C . '/' . $btnAction, $user_level) && session('id') != 1)
return;
$btn_html = "<a href='" . url("/" . M . '/' . C . "/$btnAction/$id/$idValue") . get_btn_qs() . "' class='layui-btn layui-btn-xs $theme'>$btnName</a>";
return $btn_html;
}
// 获取按钮返回参数
function get_btn_qs()
{
if (isset($_SERVER["QUERY_STRING"]) && ! ! $qs = $_SERVER["QUERY_STRING"]) {
return "&backurl=" . base64_encode(URL);
} else {
return "?backurl=" . base64_encode(URL);
}
}
// 获取返回URL
function get_backurl()
{
if (! ! $backurl = get('backurl')) {
if (isset($_SERVER["QUERY_STRING"]) && ! ! get('p')) {
return "&backurl=" . $backurl;
} else {
return "?backurl=" . $backurl;
}
} else {
return;
}
}
// 获取返回tab跳转地址
function get_tab($tid)
{
if (isset($_SERVER["QUERY_STRING"]) && ! ! get('p')) {
return "&#tab=" . $tid;
} else {
return "?#tab=" . $tid;
}
}
// 缓存语言信息
function cache_config($refresh = false)
{
// 系统配置缓存
$config_cache = RUN_PATH . '/config/' . md5('config') . '.php';
if (! file_exists($config_cache) || $refresh) {
$model = model('admin.system.Config');
$config = $model->getConfig();
unset($config['sn']);
unset($config['sn_user']);
Config::set(md5('config'), $config, false, true);
}
// 多语言缓存
$lg_cache = RUN_PATH . '/config/' . md5('area') . '.php';
if (! file_exists($lg_cache) || $refresh) {
$model = model('admin.system.Config');
$area = $model->getAreaTheme(); // 获取所有语言
$map = array();
foreach ($area as $key => $value) {
$map[$value['acode']] = $value;
}
if (! $map) {
error('系统没有任何可用区域,请核对后再试!');
}
$lgs['lgs'] = $map;
Config::set(md5('area'), $lgs, false, true);
}
}
// 获取默认语言
function get_default_lg()
{
$default = current(Config::get('lgs'));
return $default['acode'];
}
// 获取当前语言并进行安全处理
function get_lg()
{
$lg = cookie('lg');
if (! $lg || ! preg_match('/^[\w\-]+$/', $lg)) {
$lg = get_default_lg();
cookie('lg', $lg);
}
return $lg;
}
// 获取当前语言主题
function get_theme()
{
$lgs = Config::get('lgs');
$lg = get_lg();
return $lgs[$lg]['theme'];
}
// 推送百度
function post_baidu($api, $urls)
{
$ch = curl_init();
$options = array(
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_TIMEOUT => 90,
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => implode("\n", $urls),
CURLOPT_HTTPHEADER => array(
'Content-Type: text/plain'
)
);
curl_setopt_array($ch, $options);
$result = json_decode(curl_exec($ch));
return $result;
}

53
apps/common/route.php Normal file
View File

@@ -0,0 +1,53 @@
<?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/ImageExt' => 'admin/system.ImageExt',
// 内容发布模块路由
'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/DeleCache' => 'admin/content.DeleCache',
// 会员模块
'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', // 站点地图XML格式
'home/sitemap.txt' => 'home/Sitemap/linkTxt', // 站点地图TXT格式
'home/sitemap' => 'home/Sitemap/index', // 站点地图默认XML
// =======接口路由============
'api/list' => 'api/list/index/scode',
'api/content' => 'api/content/index/id',
'api/about' => 'api/about/index/scode',
'api/search' => 'api/search/index'
)
);

12
apps/common/version.php Normal file
View File

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