Skip to content

Commit

Permalink
Merge pull request #162 from getrebuild/hotfix-1.9.1
Browse files Browse the repository at this point in the history
fix: install
  • Loading branch information
devezhao authored Apr 29, 2020
2 parents 6ea6f6d + d5bca26 commit 487f265
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 65 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.rebuild</groupId>
<artifactId>rebuild</artifactId>
<packaging>war</packaging>
<version>1.9.0</version>
<version>1.9.1</version>
<name>rebuild</name>
<description>Building your business-systems free!</description>
<url>https://getrebuild.com/</url>
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/rebuild/server/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.alibaba.fastjson.serializer.ToStringSerializer;
import com.rebuild.api.ApiGateway;
import com.rebuild.api.BaseApi;
import com.rebuild.server.helper.AesPreferencesConfigurer;
import com.rebuild.server.helper.ConfigurableItem;
import com.rebuild.server.helper.SysConfiguration;
import com.rebuild.server.helper.cache.CommonCache;
Expand Down Expand Up @@ -64,10 +65,10 @@ public final class Application {

/** Rebuild Version
*/
public static final String VER = "1.9.0";
public static final String VER = "1.9.1";
/** Rebuild Build
*/
public static final int BUILD = 1090;
public static final int BUILD = 1091;

/** Logging for Global
*/
Expand Down Expand Up @@ -193,7 +194,8 @@ protected static ApplicationContext debug() throws Exception {
if (APPLICATION_CTX == null) {
debugMode = true;
LOG.info("Rebuild Booting in DEBUG mode ...");


AesPreferencesConfigurer.initApplicationProperties();
long at = System.currentTimeMillis();
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "application-ctx.xml" });
new Application(ctx).init(at);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/rebuild/server/ServerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.rebuild.server;

import cn.devezhao.commons.CalendarUtils;
import com.rebuild.server.helper.AesPreferencesConfigurer;
import com.rebuild.server.helper.ConfigurableItem;
import com.rebuild.server.helper.SysConfiguration;
import com.rebuild.server.helper.setup.InstallState;
Expand Down Expand Up @@ -54,6 +55,8 @@ public void contextInitialized(ServletContextEvent event) {
event.getServletContext().setAttribute("baseUrl", CONTEXT_PATH);

try {
AesPreferencesConfigurer.initApplicationProperties();

if (!checkInstalled()) {
eventHold = event;
LOG.warn(Application.formatFailure("REBUILD IS WAITING FOR INSTALL ..."));
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/rebuild/server/ServerStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,11 @@ protected static Status checkDatabase() {
return Status.success(name);
}

AesPreferencesConfigurer configurer = Application.getBean(AesPreferencesConfigurer.class);
try {
Connection c = DriverManager.getConnection(
configurer.getItem("db.url"),
configurer.getItem("db.user"),
configurer.getItem("db.passwd"));
AesPreferencesConfigurer.getItem("db.url"),
AesPreferencesConfigurer.getItem("db.user"),
AesPreferencesConfigurer.getItem("db.passwd"));
SqlHelper.close(c);
} catch (Exception ex) {
return Status.error(name, ThrowableUtils.getRootCause(ex).getLocalizedMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@

package com.rebuild.server.helper;

import com.rebuild.server.Application;
import com.rebuild.server.helper.setup.InstallState;
import com.rebuild.server.helper.setup.SetupException;
import com.rebuild.utils.AES;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.util.Assert;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
Expand All @@ -39,21 +44,25 @@
*/
public class AesPreferencesConfigurer extends PreferencesPlaceholderConfigurer implements InstallState {

private Properties propsHold = null;
private static final Log LOG = LogFactory.getLog(AesPreferencesConfigurer.class);

private static Properties propsHold = null;

@Override
protected void loadProperties(Properties props) throws IOException {
super.loadProperties(props);

props.putAll(fromInstallFile());
this.afterLoad(props);
LOG.info("Application properties : " + props);

setNullValue(StringUtils.EMPTY);
}

/**
* @param props
*/
private void afterLoad(Properties props) {
props.putAll(fromInstallFile());

final Object[] keys = props.keySet().toArray(new Object[0]);
for (Object key : keys) {
String cleanKey = key.toString();
Expand Down Expand Up @@ -87,13 +96,6 @@ private void afterLoad(Properties props) {
setIfEmpty(props, ConfigurableItem.CachePort, "6379");

propsHold = (Properties) props.clone();

if (propsHold.getProperty("db.url").contains("jdbc:h2:")) {
Application.LOG.warn("Using QuickMode with H2 database!");
}
if (Application.devMode()) {
Application.LOG.info("System properties : " + propsHold);
}
}

/**
Expand Down Expand Up @@ -125,13 +127,29 @@ private void setIfEmpty(Properties props, ConfigurableItem item, String defaultV
}
}

// --

/**
* @throws IOException
*/
public static void initApplicationProperties() throws IOException {
if (propsHold != null) return;
File file = ResourceUtils.getFile("classpath:application.properties");
try (InputStream is = new FileInputStream(file)) {
Properties props = new Properties();
props.load(is);
new AesPreferencesConfigurer().afterLoad(props);
}
}

/**
* 获取配置项
*
* @param name
* @return
*/
public String getItem(String name) {
public static String getItem(String name) {
Assert.notNull(propsHold, "Rebuild unstarted");
return StringUtils.defaultIfBlank(propsHold.getProperty(name), null);
}
}
50 changes: 25 additions & 25 deletions src/main/java/com/rebuild/server/helper/KVStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import cn.devezhao.persist4j.Record;
import cn.devezhao.persist4j.engine.ID;
import com.rebuild.server.Application;
import com.rebuild.server.helper.cache.CommonCache;
import com.rebuild.server.metadata.EntityHelper;
import com.rebuild.server.service.bizz.UserService;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -88,37 +87,38 @@ record = EntityHelper.forUpdate((ID) exists[0], UserService.SYSTEM_USER);
* @return
*/
protected static String getValue(final String key, boolean reload, Object defaultValue) {
if (!Application.serversReady()) {
return defaultValue == null ? null : defaultValue.toString();
String value = null;
if (Application.serversReady()) {
value = Application.getCommonCache().get(key);
if (value != null && !reload) {
return value;
}

// 1. 首先从数据库
Object[] fromDb = Application.createQueryNoFilter(
"select value from SystemConfig where item = ?")
.setParameter(1, key)
.unique();
value = fromDb == null ? null : StringUtils.defaultIfBlank((String) fromDb[0], null);
}

String cached = Application.getCommonCache().get(key);
if (cached != null && !reload) {
return cached;
}

// 1. 首先从数据库
Object[] fromDb = Application.createQueryNoFilter(
"select value from SystemConfig where item = ?")
.setParameter(1, key)
.unique();
cached = fromDb == null ? null : StringUtils.defaultIfBlank((String) fromDb[0], null);

// 2. 从配置文件加载
if (cached == null) {
cached = Application.getBean(AesPreferencesConfigurer.class).getItem(key);
// 2. 从配置文件/命令行加载
if (value == null) {
value = AesPreferencesConfigurer.getItem(key);
}

// 3. 默认值
if (cached == null && defaultValue != null) {
cached = defaultValue.toString();
if (value == null && defaultValue != null) {
value = defaultValue.toString();
}

if (cached == null) {
Application.getCommonCache().evict(key);
} else {
Application.getCommonCache().put(key, cached);
if (Application.serversReady()) {
if (value == null) {
Application.getCommonCache().evict(key);
} else {
Application.getCommonCache().put(key, value);
}
}
return cached;
return value;
}
}
10 changes: 6 additions & 4 deletions src/main/java/com/rebuild/server/helper/License.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ public static String SN() {

if (SN == null) {
try {
String result = CommonsUtils.get(
String.format("https://getrebuild.com/api/authority/new?k=%s&ver=%s", OSA_KEY, Application.VER));
String apiUrl = String.format("https://getrebuild.com/api/authority/new?ver=%s&k=%s", Application.VER, OSA_KEY);
String result = CommonsUtils.get(apiUrl);

if (JSONUtils.wellFormat(result)) {
JSONObject data = JSON.parseObject(result);
SN = data.getString("sn");
JSONObject o = JSON.parseObject(result);
SN = o.getString("sn");
SysConfiguration.set(ConfigurableItem.SN, SN);
}

} catch (Exception ignored) {
// UNCATCHABLE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package com.rebuild.server.helper.setup;

import cn.devezhao.commons.CalendarUtils;
import com.rebuild.server.Application;
import com.rebuild.server.helper.AesPreferencesConfigurer;
import com.rebuild.server.helper.ConfigurableItem;
import com.rebuild.server.helper.SysConfiguration;
Expand Down Expand Up @@ -41,9 +40,9 @@ public class DatabaseBackup {
* @throws IOException
*/
public File backup() throws IOException {
String url = Application.getBean(AesPreferencesConfigurer.class).getItem("db.url");
String user = Application.getBean(AesPreferencesConfigurer.class).getItem("db.user");
String passwd = Application.getBean(AesPreferencesConfigurer.class).getItem("db.passwd");
String url = AesPreferencesConfigurer.getItem("db.url");
String user = AesPreferencesConfigurer.getItem("db.user");
String passwd = AesPreferencesConfigurer.getItem("db.passwd");

url = url.split("\\?")[0].split("//")[1];
String host = url.split(":")[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public interface InstallState {

/**
* 状态文件位置 ~/.rebuild/.rebuild
* 安装文件位置 ~/.rebuild/.rebuild
*/
String INSTALL_FILE = ".rebuild";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private void executeSql(String sql) {
* @return
*/
public static boolean isUseH2() {
String dbUrl = Application.getBean(AesPreferencesConfigurer.class).getItem("db.url");
String dbUrl = AesPreferencesConfigurer.getItem("db.url");
return dbUrl.startsWith("jdbc:h2:");
}
}
19 changes: 11 additions & 8 deletions src/main/java/com/rebuild/utils/AES.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

package com.rebuild.utils;

import com.rebuild.server.Application;
import com.rebuild.server.RebuildException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
Expand All @@ -33,7 +34,9 @@
* @since 2017-1-2
*/
public class AES {


private static final Log LOG = LogFactory.getLog(AES.class);

/**
* @param input
* @return
Expand All @@ -51,14 +54,14 @@ public static String encrypt(String input) throws RebuildException {
*/
public static String encrypt(String input, String key) throws RebuildException {
key = StringUtils.leftPad(key, 16, "0").substring(0, 16);
byte[] crypted = null;
byte[] crypted;
try {
SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skey);
crypted = cipher.doFinal(input.getBytes());
} catch (Exception ex) {
throw new RebuildException("加密失败", ex);
throw new RebuildException("Encrypting error : " + input, ex);
}
return new String(Base64.encodeBase64(crypted));
}
Expand All @@ -80,14 +83,14 @@ public static String decrypt(String input) throws RebuildException {
*/
public static String decrypt(String input, String key) throws RebuildException {
key = StringUtils.leftPad(key, 16, "0").substring(0, 16);
byte[] output = null;
byte[] output;
try {
SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, skey);
output = cipher.doFinal(Base64.decodeBase64(input));
} catch (Exception ex) {
throw new RebuildException("Decrypting Error", ex);
throw new RebuildException("Decrypting error : " + input, ex);
}
return new String(output);
}
Expand All @@ -100,8 +103,8 @@ public static String decryptNothrow(String input) {
try {
return decrypt(input);
} catch (RebuildException ex) {
Application.LOG.warn("Decrypting Error! Use input: " + input);
return input;
LOG.warn("Decrypting error (Use blank input) : " + input);
return StringUtils.EMPTY;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/admin/system-general.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<td data-id="MarkWatermark" data-options="true:是;false:否">${MarkWatermark ? "" : ""}</td>
</tr>
<tr>
<td>数据库自动备份<p>每日0点备份到数据目录,请预留足够磁盘空间</p></td>
<td>数据库自动备份<p>每日 0 点备份到数据目录,请预留足够磁盘空间</p></td>
<td data-id="DBBackupsEnable" data-options="true:是;false:否">${DBBackupsEnable ? "" : ""}</td>
</tr>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/user/login.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<button class="btn btn-primary btn-xl" type="submit" data-spinner>${bundle.lang('Login')}</button>
<div class="mt-4 text-center">${bundle.lang('NoAccountYet')}&nbsp;<a href="signup">${bundle.lang('SignupNow')}</a></div>
</div>
<div class="select-lang text-center mb-2">
<div class="select-lang text-center mb-2 dev-show">
<a href="?locale=zh_CN" title="中文"><img src="${baseUrl}/assets/img/flag/zh-CN.png" /></a>
<a href="?locale=en" title="English"><img src="${baseUrl}/assets/img/flag/en-US.png" /></a>
<a href="?locale=ja" title="日本語"><img src="${baseUrl}/assets/img/flag/ja-JP.png" /></a>
Expand Down

0 comments on commit 487f265

Please sign in to comment.