diff --git a/src/main/java/com/rebuild/server/helper/SystemConfiguration.java b/src/main/java/com/rebuild/server/helper/SystemConfiguration.java index f7e3779a4..a3db523db 100644 --- a/src/main/java/com/rebuild/server/helper/SystemConfiguration.java +++ b/src/main/java/com/rebuild/server/helper/SystemConfiguration.java @@ -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() { - return null; + 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() { - return null; - } - - /*- - * 从数据库-配置文件获取 - */ - private static String getItemFromBoth(ItemName name) { - String s = getItem(name); - if (s == null) { - s = Application.getBean(AesPreferencesConfigurer.class).getItem(name.name()); + String user = getItem(SystemItem.SmsUser); + if (user == null) { + return null; } - return s; + String password = getItem(SystemItem.SmsPassword); + if (password == null) { + return null; + } + String sign = getItem(SystemItem.SmsSign); + if (sign == null) { + return null; + } + return new String[] { user, password, sign }; } // -- - private static final Map CACHED = new ConcurrentHashMap<>(); + private static final Map 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()) diff --git a/src/main/java/com/rebuild/server/helper/SystemItem.java b/src/main/java/com/rebuild/server/helper/SystemItem.java new file mode 100644 index 000000000..ae16ce357 --- /dev/null +++ b/src/main/java/com/rebuild/server/helper/SystemItem.java @@ -0,0 +1,47 @@ +/* +rebuild - Building your system freely. +Copyright (C) 2018 devezhao + +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 . +*/ + +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 + +} diff --git a/src/main/java/com/rebuild/utils/AES.java b/src/main/java/com/rebuild/utils/AES.java index ec21ebcf3..4cdd7e288 100644 --- a/src/main/java/com/rebuild/utils/AES.java +++ b/src/main/java/com/rebuild/utils/AES.java @@ -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")); } } \ No newline at end of file diff --git a/src/main/java/com/rebuild/utils/StringsUtils.java b/src/main/java/com/rebuild/utils/StringsUtils.java new file mode 100644 index 000000000..4c6f4efa1 --- /dev/null +++ b/src/main/java/com/rebuild/utils/StringsUtils.java @@ -0,0 +1,55 @@ +/* +rebuild - Building your system freely. +Copyright (C) 2018 devezhao + +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 . +*/ + +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); + } + } + +} diff --git a/src/main/java/com/rebuild/web/admin/SystemConfigurerContoll.java b/src/main/java/com/rebuild/web/admin/SystemConfigurerContoll.java index 430a929d8..af84f89bf 100644 --- a/src/main/java/com/rebuild/web/admin/SystemConfigurerContoll.java +++ b/src/main/java/com/rebuild/web/admin/SystemConfigurerContoll.java @@ -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"); } } diff --git a/src/main/resources/cloud-3rd.properties b/src/main/resources/cloud-3rd.properties index 64c6ce929..925791c24 100644 --- a/src/main/resources/cloud-3rd.properties +++ b/src/main/resources/cloud-3rd.properties @@ -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 diff --git a/src/main/webapp/_include/NavLeftAdmin.jsp b/src/main/webapp/_include/NavLeftAdmin.jsp index f39ece5f0..4b6c12682 100644 --- a/src/main/webapp/_include/NavLeftAdmin.jsp +++ b/src/main/webapp/_include/NavLeftAdmin.jsp @@ -9,17 +9,16 @@
  • 系统
  • - 第三方服务集成 + 三方服务集成 -
    ${param['pageTitle']}
    +
    ${param['pageTitle']}