系统配置

This commit is contained in:
FangfangZhao 2018-12-25 17:04:46 +08:00
parent 69629591fa
commit a3e8bfc3a7
15 changed files with 347 additions and 148 deletions

View file

@ -20,8 +20,8 @@ package com.rebuild.server.helper;
import java.io.File;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.collections4.map.CaseInsensitiveMap;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
@ -44,23 +44,6 @@ import cn.devezhao.persist4j.engine.ID;
*/
public class SystemConfiguration {
/**
* 系统配置项名称
*/
public static enum ItemName {
// 通用
AppName, LOGO, LOGOWhite, HomeURL, OpenSignUp,
// 临时目录
TempDirectory,
// 云存储
StorageURL, StorageApiKey, StorageApiSecret, StorageBucket,
// 缓存服务
CacheHost, CachePort, CacheUser, CachePassword,
}
private static final Log LOG = LogFactory.getLog(SystemConfiguration.class);
/**
@ -70,7 +53,7 @@ public class SystemConfiguration {
* @return
*/
public static File getFileOfTemp(String file) {
String tmp = getItemFromBoth(ItemName.TempDirectory);
String tmp = getItem(SystemItem.TempDirectory);
File tmp2 = null;
if (tmp != null) {
tmp2 = new File(tmp);
@ -90,89 +73,107 @@ public class SystemConfiguration {
* @return
*/
public static String getStorageUrl() {
return getItemFromBoth(ItemName.StorageURL);
return getItem(SystemItem.StorageURL);
}
/**
* 云存储账号
*
* @return
* @return returns [StorageApiKey, StorageApiSecret, StorageBucket, StorageURL]
*/
public static String[] getStorageAccount() {
String key = getItemFromBoth(ItemName.StorageApiKey);
String key = getItem(SystemItem.StorageApiKey);
if (key == null) {
return null;
}
String secret = getItemFromBoth(ItemName.StorageApiSecret);
String secret = getItem(SystemItem.StorageApiSecret);
if (secret == null) {
return null;
}
String bucket = getItemFromBoth(ItemName.StorageBucket);
String bucket = getItem(SystemItem.StorageBucket);
if (bucket == null) {
return null;
}
return new String[] { key, secret, bucket };
return new String[] { key, secret, bucket, getStorageUrl() };
}
/**
* TODO 缓存服务账号
* 缓存账号
*
* @return
* @return returns [CacheHost, CachePort, CacheUser, CachePassword]
*/
public static String[] getCacheAccount() {
String host = getItemFromBoth(ItemName.CacheHost);
String host = getItem(SystemItem.CacheHost);
if (host == null) {
return null;
}
String port = getItemFromBoth(ItemName.CachePort);
String port = getItem(SystemItem.CachePort);
if (port == null) {
return null;
}
String user = getItemFromBoth(ItemName.CacheUser);
// if (user == null) {
// return null;
// }
String password = getItemFromBoth(ItemName.CachePassword);
String password = getItem(SystemItem.CachePassword);
if (password == null) {
return null;
}
String user = getItem(SystemItem.CacheUser);
return new String[] { host, port, user, password };
}
/**
* @return
* 邮件账号
*
* @return returns [MailUser, MailPassword, MailAddr, MailName]
*/
public static String[] getEmailAccount() {
String user = getItem(SystemItem.MailUser);
if (user == null) {
return null;
}
String password = getItem(SystemItem.MailPassword);
if (password == null) {
return null;
}
String addr = getItem(SystemItem.MailAddr);
if (addr == null) {
return null;
}
String name = getItem(SystemItem.MailName);
if (name == null) {
return null;
}
return new String[] { user, password, addr, name };
}
/**
* @return
* 短信账号
*
* @return returns [SmsUser, SmsPassword, SmsSign]
*/
public static String[] getSmsAccount() {
String user = getItem(SystemItem.SmsUser);
if (user == null) {
return null;
}
/*-
* 从数据库-配置文件获取
*/
private static String getItemFromBoth(ItemName name) {
String s = getItem(name);
if (s == null) {
s = Application.getBean(AesPreferencesConfigurer.class).getItem(name.name());
String password = getItem(SystemItem.SmsPassword);
if (password == null) {
return null;
}
return s;
String sign = getItem(SystemItem.SmsSign);
if (sign == null) {
return null;
}
return new String[] { user, password, sign };
}
// --
private static final Map<String, String> CACHED = new ConcurrentHashMap<>();
private static final Map<String, String> CACHED = new CaseInsensitiveMap<>();
/**
* @param name
* @return
*/
public static String getItem(ItemName name) {
public static String getItem(SystemItem name) {
return getItem(name, false);
}
@ -180,7 +181,7 @@ public class SystemConfiguration {
* @param name
* @return
*/
public static String getItem(ItemName name, boolean reload) {
public static String getItem(SystemItem name, boolean reload) {
String s = CACHED.get(name.name());
if (s != null && reload == false) {
return s;
@ -191,6 +192,12 @@ public class SystemConfiguration {
.setParameter(1, name.name())
.unique();
s = value == null ? null : StringUtils.defaultIfBlank((String) value[0], null);
// 从配置文件加载
if (s == null) {
s = Application.getBean(AesPreferencesConfigurer.class).getItem(name.name());
}
if (s == null) {
CACHED.remove(name.name());
} else {
@ -204,7 +211,7 @@ public class SystemConfiguration {
* @param defaultValue
* @return
*/
public static long getLongItem(ItemName name, long defaultValue) {
public static long getLongItem(SystemItem name, long defaultValue) {
String s = getItem(name);
return s == null ? defaultValue : NumberUtils.toLong(s);
}
@ -214,7 +221,7 @@ public class SystemConfiguration {
* @param defaultValue
* @return
*/
public static boolean getBoolItem(ItemName name, boolean defaultValue) {
public static boolean getBoolItem(SystemItem name, boolean defaultValue) {
String s = getItem(name);
return s == null ? defaultValue : BooleanUtils.toBoolean(s);
}
@ -224,7 +231,7 @@ public class SystemConfiguration {
* @param value
* @return
*/
public static void setItem(ItemName name, Object value) {
public static void setItem(SystemItem name, Object value) {
Object[] exists = Application.createQueryNoFilter(
"select configId from SystemConfig where item = ?")
.setParameter(1, name.name())

View file

@ -0,0 +1,47 @@
/*
rebuild - Building your system freely.
Copyright (C) 2018 devezhao <zhaofang123@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.rebuild.server.helper;
/**
* 系统配置项
*
* @author devezhao
* @since 12/25/2018
*/
public enum SystemItem {
// 通用
AppName, LOGO, LOGOWhite, HomeURL, OpenSignUp,
// 临时目录
TempDirectory,
// 云存储
StorageURL, StorageApiKey, StorageApiSecret, StorageBucket,
// 缓存服务
CacheHost, CachePort, CacheUser, CachePassword,
// 邮件
MailUser, MailPassword, MailAddr, MailName,
// 短信
SmsUser, SmsPassword, SmsSign
}

View file

@ -93,6 +93,6 @@ public class AES {
// for Encrypt
public static void main(String[] args) {
System.out.println(encrypt("crk2019rb"));
System.out.println(encrypt("428115fbdc40413c43a1e977a83c8a5a"));
}
}

View file

@ -0,0 +1,55 @@
/*
rebuild - Building your system freely.
Copyright (C) 2018 devezhao <zhaofang123@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.rebuild.utils;
import org.apache.commons.lang.StringUtils;
/**
*
* @author devezhao
* @since 12/25/2018
*/
public class StringsUtils {
/**
* 加星号/打码
*
* @param text
* @return
*/
public static String stars(String text) {
if (StringUtils.isBlank(text)) {
return text;
}
int textLen = text.length();
if (textLen <= 3) {
return text.substring(0, 1) + "**";
} else if (textLen <= 20) {
return text.substring(0, 1) + "**" + text.substring(textLen - 1);
} else if (textLen <= 30) {
return text.substring(0, 2) + "****" + text.substring(textLen - 2);
} else if (textLen <= 40) {
return text.substring(0, 4) + "**********" + text.substring(textLen - 4);
} else {
return text.substring(0, 4) + "********************" + text.substring(textLen - 4);
}
}
}

View file

@ -49,13 +49,8 @@ public class SystemConfigurerContoll extends BaseControll {
return createModelAndView("/admin/plugins/cache-redis.jsp");
}
@RequestMapping("plugins/sms")
public ModelAndView pagePluginsSms() {
return createModelAndView("/admin/plugins/sms-submail.jsp");
}
@RequestMapping("plugins/mail")
public ModelAndView pagePluginsMail() {
return createModelAndView("/admin/plugins/mail-submail.jsp");
@RequestMapping("plugins/mails")
public ModelAndView pagePluginsMailSms() {
return createModelAndView("/admin/plugins/mails-submail.jsp");
}
}

View file

@ -18,16 +18,16 @@ CachePassword.aes=vXwBKYUosMpJRO9jeG9+IA==
# SMS - Submail
SmsApiURL=https://api.mysubmail.com/message/xsend
SmsApiKey=
SmsApiSecret=
SmsUser=30912
SmsPassword.aes=w07FOXTgIF5vuU2uWOLHhgeBv2dSExddnQQ8f534GXMKxKZT7YVYoWKjP8gPrEIS
SmsSign=REBUILD
# Mail - Submail
SmtpServer=cloud.mysubmail.com
SmtpPort=25
SmtpUser=
SmtpPassword=
MailUser=14022
MailPassword.aes=vRnLDh4PVen2faMH+itQuFjzwBcWtCTO6qslkF36VAoKxKZT7YVYoWKjP8gPrEIS
MailAddr=hi@smtp.getrebuild.com
MailName=REBUILD
# General

View file

@ -9,17 +9,16 @@
<li class="divider">系统</li>
<li class="${param['activeNav'] == 'systems' ? 'active' : ''}" id="nav_systems"><a href="${baseUrl}/admin/systems"><i class="icon zmdi zmdi-settings"></i><span>通用配置</span></a></li>
<li class="parent">
<a><i class="icon zmdi zmdi-cloud-done"></i><span>三方服务集成</span></a>
<a><i class="icon zmdi zmdi-cloud-done"></i><span>三方服务集成</span></a>
<ul class="sub-menu">
<li class="title">三方服务集成</li>
<li class="title">三方服务集成</li>
<li class="nav-items">
<div class="rb-scroller">
<div class="content">
<ul>
<li class="${param['activeNav'] == 'plugins-storage' ? 'active' : ''}" id="nav_plugins-storage"><a href="${baseUrl}/admin/plugins/storage">云存储</a></li>
<li class="${param['activeNav'] == 'plugins-cache' ? 'active' : ''}" id="nav_plugins-cache"><a href="${baseUrl}/admin/plugins/cache">缓存系统</a></li>
<li class="${param['activeNav'] == 'plugins-sms' ? 'active' : ''}" id="nav_plugins-sms"><a href="${baseUrl}/admin/plugins/sms">短信服务</a></li>
<li class="${param['activeNav'] == 'plugins-mail' ? 'active' : ''}" id="nav_plugins-mail"><a href="${baseUrl}/admin/plugins/mail">邮件服务</a></li>
<li class="${param['activeNav'] == 'plugins-mails' ? 'active' : ''}" id="nav_plugins-mails"><a href="${baseUrl}/admin/plugins/mails">短信/邮件</a></li>
</ul>
</div>
</div>

View file

@ -32,7 +32,7 @@ final User currentUser = Application.getUserStore().getUser(AppUtils.getRequestU
</div>
</li>
</ul>
<div class="page-title"><span>${param['pageTitle']}</span></div>
<div class="page-title hide"><span>${param['pageTitle']}</span></div>
<ul class="nav navbar-nav float-right rb-icons-nav">
<li class="nav-item dropdown J_admin-settings <%=currentUser.isAdmin() ? "" : "hide"%>">
<a class="nav-link" href="${baseUrl}/admin/systems"><i class="icon zmdi zmdi-settings"></i></a>

View file

@ -1,10 +1,14 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.rebuild.utils.StringsUtils"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/_include/Head.jsp"%>
<title>缓存系统配置</title>
<style type="text/css">
.syscfg h5{background-color:#eee;margin:0;padding:10px;}
.syscfg .table td{padding:10px;}
.syscfg .table td p{margin:0;color:#999;font-weight:normal;font-size:12px;}
</style>
</head>
<body>
@ -16,13 +20,37 @@
<jsp:param value="plugins-cache" name="activeNav"/>
</jsp:include>
<div class="rb-content">
<div class="main-content container-fluid">
<h3 class="text-center">暂未支持</h3>
<div class="main-content container-fluid syscfg">
<div class="row">
<div class="col-9">
<div class="card">
<div class="card-header card-header-divider">缓存系统</div>
<div class="card-body">
<h5>Redis</h5>
<%
String account[] = SystemConfiguration.getCacheAccount();
%>
<table class="table">
<tbody>
<tr>
<td width="50%">缓存服务器</td>
<td><%=account == null ? "" : (account[0] + ":" + account[1])%></td>
</tr>
<tr>
<td>访问秘钥</td>
<td><%=account == null ? "" : StringsUtils.stars(account[3])%></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-3">
</div>
</div>
</div>
</div>
</div>
<%@ include file="/_include/Foot.jsp"%>
<script type="text/babel">
</script>
</body>
</html>

View file

@ -1,28 +0,0 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/_include/Head.jsp"%>
<title>邮件服务配置</title>
<style type="text/css">
</style>
</head>
<body>
<div class="rb-wrapper rb-fixed-sidebar rb-collapsible-sidebar rb-collapsible-sidebar-hide-logo rb-color-header">
<jsp:include page="/_include/NavTop.jsp">
<jsp:param value="邮件服务配置" name="pageTitle"/>
</jsp:include>
<jsp:include page="/_include/NavLeftAdmin.jsp">
<jsp:param value="plugins-mail" name="activeNav"/>
</jsp:include>
<div class="rb-content">
<div class="main-content container-fluid">
<h3 class="text-center">暂未支持</h3>
</div>
</div>
</div>
<%@ include file="/_include/Foot.jsp"%>
<script type="text/babel">
</script>
</body>
</html>

View file

@ -0,0 +1,83 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.rebuild.utils.StringsUtils"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/_include/Head.jsp"%>
<title>短信/邮件配置</title>
<style type="text/css">
.syscfg h5{background-color:#eee;margin:0;padding:10px;}
.syscfg .table td{padding:10px;}
.syscfg .table td p{margin:0;color:#999;font-weight:normal;font-size:12px;}
</style>
</head>
<body>
<div class="rb-wrapper rb-fixed-sidebar rb-collapsible-sidebar rb-collapsible-sidebar-hide-logo rb-color-header">
<jsp:include page="/_include/NavTop.jsp">
<jsp:param value="短信/邮件配置" name="pageTitle"/>
</jsp:include>
<jsp:include page="/_include/NavLeftAdmin.jsp">
<jsp:param value="plugins-mails" name="activeNav"/>
</jsp:include>
<div class="rb-content">
<div class="main-content container-fluid syscfg">
<div class="row">
<div class="col-9">
<div class="card">
<div class="card-header card-header-divider">赛邮 SUBMAIL</div>
<div class="card-body">
<%
String smsAccount[] = SystemConfiguration.getSmsAccount();
%>
<h5>短信服务</h5>
<table class="table">
<tbody>
<tr>
<td width="50%">APPID</td>
<td><%=smsAccount == null ? "" : smsAccount[0]%></td>
</tr>
<tr>
<td>APPKEY</td>
<td><%=smsAccount == null ? "" : StringsUtils.stars(smsAccount[1])%></td>
</tr>
<tr>
<td>短信签名</td>
<td><%=smsAccount == null ? "" : smsAccount[2]%></td>
</tr>
</tbody>
</table>
<%
String mailAccount[] = SystemConfiguration.getEmailAccount();
%>
<h5>邮件服务</h5>
<table class="table">
<tbody>
<tr>
<td width="50%">APPID</td>
<td><%=mailAccount == null ? "" : mailAccount[0]%></td>
</tr>
<tr>
<td>APPKEY</td>
<td><%=mailAccount == null ? "" : StringsUtils.stars(mailAccount[1])%></td>
</tr>
<tr>
<td>发件人地址</td>
<td><%=mailAccount == null ? "" : mailAccount[2]%></td>
</tr>
<tr>
<td>发件人名称</td>
<td><%=mailAccount == null ? "" : mailAccount[3]%></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-3">
</div>
</div>
</div>
</div>
<%@ include file="/_include/Foot.jsp"%>
</body>
</html>

View file

@ -1,28 +0,0 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/_include/Head.jsp"%>
<title>短信服务配置</title>
<style type="text/css">
</style>
</head>
<body>
<div class="rb-wrapper rb-fixed-sidebar rb-collapsible-sidebar rb-collapsible-sidebar-hide-logo rb-color-header">
<jsp:include page="/_include/NavTop.jsp">
<jsp:param value="短信服务配置" name="pageTitle"/>
</jsp:include>
<jsp:include page="/_include/NavLeftAdmin.jsp">
<jsp:param value="plugins-sms" name="activeNav"/>
</jsp:include>
<div class="rb-content">
<div class="main-content container-fluid">
<h3 class="text-center">暂未支持</h3>
</div>
</div>
</div>
<%@ include file="/_include/Foot.jsp"%>
<script type="text/babel">
</script>
</body>
</html>

View file

@ -1,10 +1,14 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.rebuild.utils.StringsUtils"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/_include/Head.jsp"%>
<title>云存储配置</title>
<style type="text/css">
.syscfg h5{background-color:#eee;margin:0;padding:10px;}
.syscfg .table td{padding:10px;}
.syscfg .table td p{margin:0;color:#999;font-weight:normal;font-size:12px;}
</style>
</head>
<body>
@ -16,13 +20,46 @@
<jsp:param value="plugins-storage" name="activeNav"/>
</jsp:include>
<div class="rb-content">
<div class="main-content container-fluid">
<h3 class="text-center">暂未支持</h3>
<div class="main-content container-fluid syscfg">
<div class="row">
<div class="col-9">
<div class="card">
<div class="card-header card-header-divider">云存储</div>
<div class="card-body">
<h5>七牛云</h5>
<%
String account[] = SystemConfiguration.getStorageAccount();
String domain = account == null ? "" : account[3];
%>
<table class="table">
<tbody>
<tr>
<td width="50%">访问域名</td>
<td><a href="<%=domain%>" class="link" target="_blank"><%=domain%></a></td>
</tr>
<tr>
<td>存储空间</td>
<td><%=account == null ? "" : account[2]%></td>
</tr>
<tr>
<td>秘钥 AK</td>
<td><%=account == null ? "" : StringsUtils.stars(account[0])%></td>
</tr>
<tr>
<td>秘钥 SK</td>
<td><%=account == null ? "" : StringsUtils.stars(account[1])%></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-3">
</div>
</div>
</div>
</div>
</div>
<%@ include file="/_include/Foot.jsp"%>
<script type="text/babel">
</script>
</body>
</html>

View file

@ -6,11 +6,11 @@
<%@ include file="/_include/Head.jsp"%>
<title>通用配置</title>
<style type="text/css">
a.img-thumbnail{display:inline-block;padding:0.6rem;background-color:#fff;line-height:1;font-size:0;cursor:default;}
a.img-thumbnail img{max-height:20px;}
h5{background-color:#eee;margin:0;padding:10px;}
.table td{padding:10px;}
.table td p{margin:0;color:#999;font-weight:normal;font-size:12px;}
.syscfg a.img-thumbnail{display:inline-block;padding:0.6rem;background-color:#fff;line-height:1;font-size:0;cursor:default;}
.syscfg a.img-thumbnail img{max-height:20px;}
.syscfg h5{background-color:#eee;margin:0;padding:10px;}
.syscfg .table td{padding:10px;}
.syscfg .table td p{margin:0;color:#999;font-weight:normal;font-size:12px;}
</style>
</head>
<body>
@ -22,7 +22,7 @@ h5{background-color:#eee;margin:0;padding:10px;}
<jsp:param value="systems" name="activeNav"/>
</jsp:include>
<div class="rb-content">
<div class="main-content container-fluid">
<div class="main-content container-fluid syscfg">
<div class="row">
<div class="col-9">
<div class="card">
@ -44,7 +44,7 @@ h5{background-color:#eee;margin:0;padding:10px;}
</tr>
<tr>
<td>域名/主页地址</td>
<td><a id="sc-HomeURL" href="http://getrebuild.com/" class="link" target="_blank">http://getrebuild.com/</a></td>
<td><a id="sc-HomeURL" href="https://nightly.getrebuild.com/" class="link" target="_blank">https://nightly.getrebuild.com/</a></td>
</tr>
<tr>
<td>公开注册</td>
@ -88,7 +88,5 @@ h5{background-color:#eee;margin:0;padding:10px;}
</div>
</div>
<%@ include file="/_include/Foot.jsp"%>
<script type="text/babel">
</script>
</body>
</html>

View file

@ -39,7 +39,13 @@ $(function(){
if ($('.rb-notifications').length > 0) {
setTimeout(__checkMessage, 1500)
}
let keydown_times = 0
$(document.body).keydown((e)=>{
if (e.ctrlKey && e.altKey && e.which == 88) command_exec(++keydown_times)
})
})
command_exec = function(t){ }
// 导航菜单
const __initNavs = function(){