From b3ac00069f9594f6ec0077cbb91516e26e13c3b6 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期六, 01 八月 2020 15:23:26 +0800
Subject: [PATCH] #当前本版十分完美、冻结

---
 version/lib/framework-1.1.1.jar                              |    0 
 src/main/java/com/zy/common/web/AuthController.java          |   51 ++++++
 src/main/java/com/zy/common/properties/SystemProperties.java |   69 +++++++++
 src/main/java/com/zy/common/task/ActivateScheduler.java      |   43 ++++++
 version/lib/cool-framework-install.txt                       |    2 
 src/main/java/com/zy/common/config/AdminInterceptor.java     |    7 +
 src/main/webapp/views/index.html                             |    6 
 src/main/java/com/zy/common/model/enums/SysOsType.java       |   49 +++++++
 src/main/java/com/zy/common/properties/OSinfo.java           |  136 +++++++++++++++++++
 src/main/webapp/static/layuiadmin/lib/admin.js               |   28 +++-
 pom.xml                                                      |    4 
 11 files changed, 376 insertions(+), 19 deletions(-)

diff --git a/pom.xml b/pom.xml
index e497317..d242810 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,12 +10,12 @@
     </parent>
     <groupId>com.zy</groupId>
     <artifactId>asrs</artifactId>
-    <version>1.0.0</version>
+    <version>1.1.1</version>
     <packaging>war</packaging>
 
     <properties>
         <java.version>1.8</java.version>
-        <cool.version>1.0.0</cool.version>
+        <cool.version>1.1.1</cool.version>
         <mysql-driver.version>5.1.47</mysql-driver.version>
         <mybatis-plus.version>2.3.2</mybatis-plus.version>
         <fastjson.version>1.2.58</fastjson.version>
diff --git a/src/main/java/com/zy/common/config/AdminInterceptor.java b/src/main/java/com/zy/common/config/AdminInterceptor.java
index 37a863d..80e61c5 100644
--- a/src/main/java/com/zy/common/config/AdminInterceptor.java
+++ b/src/main/java/com/zy/common/config/AdminInterceptor.java
@@ -5,6 +5,7 @@
 import com.core.annotations.ManagerAuth;
 import com.core.common.BaseRes;
 import com.core.common.Cools;
+import com.zy.common.properties.SystemProperties;
 import com.zy.common.utils.Http;
 import com.zy.system.entity.*;
 import com.zy.system.service.*;
@@ -114,6 +115,12 @@
             userLoginService.updateById(userLogin);
             // 鎿嶄綔鏃ュ織
             if (!Cools.isEmpty(memo)) {
+                // 杩涜婵�娲诲垽鏂�
+                if (!SystemProperties.SYSTEM_ACTIVATION) {
+                    Http.response(response, BaseRes.NO_ACTIVATION);
+                    return false;
+                }
+                // 璁板綍鎿嶄綔鏃ュ織
                 OperateLog operateLog = new OperateLog();
                 operateLog.setAction(Cools.isEmpty(memo)?request.getRequestURI():memo);
                 operateLog.setIp(request.getRemoteAddr());
diff --git a/src/main/java/com/zy/common/model/enums/SysOsType.java b/src/main/java/com/zy/common/model/enums/SysOsType.java
new file mode 100644
index 0000000..26f1051
--- /dev/null
+++ b/src/main/java/com/zy/common/model/enums/SysOsType.java
@@ -0,0 +1,49 @@
+package com.zy.common.model.enums;
+
+public enum SysOsType {
+
+    Any("any", null),
+    Linux("Linux", null),
+    Mac_OS("Mac OS", null),
+    Mac_OS_X("Mac OS X", null),
+    Windows("Windows", "D:\\婵�娲荤爜.txt"),
+    OS2("OS/2", null),
+    Solaris("Solaris", null),
+    SunOS("SunOS", null),
+    MPEiX("MPE/iX", null),
+    HP_UX("HP-UX", null),
+    AIX("AIX", null),
+    OS390("OS/390", null),
+    FreeBSD("FreeBSD", null),
+    Irix("Irix", null),
+    Digital_Unix("Digital Unix", null),
+    NetWare_411("NetWare", null),
+    OSF1("OSF1", null),
+    OpenVMS("OpenVMS", null),
+    Others("Others", null);
+
+    private String description;
+    private String activationCodePath;
+
+    SysOsType(String desc, String activationCodePath) {
+        this.description = desc;
+        this.activationCodePath = activationCodePath;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getActivationCodePath() {
+        return activationCodePath;
+    }
+
+    public void setActivationCodePath(String activationCodePath) {
+        this.activationCodePath = activationCodePath;
+    }
+
+}
diff --git a/src/main/java/com/zy/common/properties/OSinfo.java b/src/main/java/com/zy/common/properties/OSinfo.java
new file mode 100644
index 0000000..c66b5cd
--- /dev/null
+++ b/src/main/java/com/zy/common/properties/OSinfo.java
@@ -0,0 +1,136 @@
+package com.zy.common.properties;
+
+import com.zy.common.model.enums.SysOsType;
+
+/**
+ * Created by vincent on 2020/8/1
+ */
+public class OSinfo {
+
+    private static final String OS = System.getProperty("os.name").toLowerCase();
+
+    private static final OSinfo _instance = new OSinfo();
+
+    private SysOsType sysOsType;
+
+    private OSinfo(){}
+
+    public static boolean isLinux(){
+        return OS.contains("linux");
+    }
+
+    public static boolean isMacOS(){
+        return OS.contains("mac") &&OS.indexOf("os")>0&& !OS.contains("x");
+    }
+
+    public static boolean isMacOSX(){
+        return OS.contains("mac") &&OS.indexOf("os")>0&&OS.indexOf("x")>0;
+    }
+
+    public static boolean isWindows(){
+        return OS.contains("windows");
+    }
+
+    public static boolean isOS2(){
+        return OS.contains("os/2");
+    }
+
+    public static boolean isSolaris(){
+        return OS.contains("solaris");
+    }
+
+    public static boolean isSunOS(){
+        return OS.contains("sunos");
+    }
+
+    public static boolean isMPEiX(){
+        return OS.contains("mpe/ix");
+    }
+
+    public static boolean isHPUX(){
+        return OS.contains("hp-ux");
+    }
+
+    public static boolean isAix(){
+        return OS.contains("aix");
+    }
+
+    public static boolean isOS390(){
+        return OS.contains("os/390");
+    }
+
+    public static boolean isFreeBSD(){
+        return OS.contains("freebsd");
+    }
+
+    public static boolean isIrix(){
+        return OS.contains("irix");
+    }
+
+    public static boolean isDigitalUnix(){
+        return OS.contains("digital") &&OS.indexOf("unix")>0;
+    }
+
+    public static boolean isNetWare(){
+        return OS.contains("netware");
+    }
+
+    public static boolean isOSF1(){
+        return OS.contains("osf1");
+    }
+
+    public static boolean isOpenVMS(){
+        return OS.contains("openvms");
+    }
+
+    /**
+     * 鑾峰彇鎿嶄綔绯荤粺鍚嶅瓧
+     * @return 鎿嶄綔绯荤粺鍚�
+     */
+    public static SysOsType getOSname(){
+        if(isAix()){
+            _instance.sysOsType = SysOsType.AIX;
+        }else if (isDigitalUnix()) {
+            _instance.sysOsType = SysOsType.Digital_Unix;
+        }else if (isFreeBSD()) {
+            _instance.sysOsType = SysOsType.FreeBSD;
+        }else if (isHPUX()) {
+            _instance.sysOsType = SysOsType.HP_UX;
+        }else if (isIrix()) {
+            _instance.sysOsType = SysOsType.Irix;
+        }else if (isLinux()) {
+            _instance.sysOsType = SysOsType.Linux;
+        }else if (isMacOS()) {
+            _instance.sysOsType = SysOsType.Mac_OS;
+        }else if (isMacOSX()) {
+            _instance.sysOsType = SysOsType.Mac_OS_X;
+        }else if (isMPEiX()) {
+            _instance.sysOsType = SysOsType.MPEiX;
+        }else if (isNetWare()) {
+            _instance.sysOsType = SysOsType.NetWare_411;
+        }else if (isOpenVMS()) {
+            _instance.sysOsType = SysOsType.OpenVMS;
+        }else if (isOS2()) {
+            _instance.sysOsType = SysOsType.OS2;
+        }else if (isOS390()) {
+            _instance.sysOsType = SysOsType.OS390;
+        }else if (isOSF1()) {
+            _instance.sysOsType = SysOsType.OSF1;
+        }else if (isSolaris()) {
+            _instance.sysOsType = SysOsType.Solaris;
+        }else if (isSunOS()) {
+            _instance.sysOsType = SysOsType.SunOS;
+        }else if (isWindows()) {
+            _instance.sysOsType = SysOsType.Windows;
+        }else{
+            _instance.sysOsType = SysOsType.Others;
+        }
+        return _instance.sysOsType;
+    }
+
+    public static void main(String[] args) {
+        System.out.println(OSinfo.getOSname());// 鑾峰彇绯荤粺绫诲瀷
+        System.out.println(OSinfo.isWindows());// 鍒ゆ柇鏄惁涓簑indows绯荤粺
+    }
+
+}
diff --git a/src/main/java/com/zy/common/properties/SystemProperties.java b/src/main/java/com/zy/common/properties/SystemProperties.java
new file mode 100644
index 0000000..37d8e1c
--- /dev/null
+++ b/src/main/java/com/zy/common/properties/SystemProperties.java
@@ -0,0 +1,69 @@
+package com.zy.common.properties;
+
+import com.core.common.AesUtils;
+
+import java.io.*;
+
+/**
+ * Created by vincent on 2020/8/1
+ */
+public class SystemProperties {
+
+    // 婵�娲荤爜鍔犲瘑鐩� -- 16浣�
+    public static final String SALT = "123456789qwertyu";
+
+    // 绯荤粺婵�娲荤姸鎬� (榛樿鏈縺娲�)
+    public static boolean SYSTEM_ACTIVATION = Boolean.FALSE;
+
+    public static String getActivationCode(String fileName){
+        StringBuilder activationCode = new StringBuilder();
+        try {
+            FileReader f = new FileReader(fileName);
+            BufferedReader buf = new BufferedReader(f);
+            String s;
+            while ((s = buf.readLine()) != null) {
+                activationCode.append(s);
+            }
+            f.close();
+            buf.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+            throw new RuntimeException("璇诲彇WMS绯荤粺婵�娲荤爜澶辫触锛侊紒锛乗n璇诲彇璺緞 " + fileName);
+        }
+        return activationCode.toString();
+    }
+
+    public static boolean saveActivationCode(String filePath, String code){
+        try {
+            // 闃叉鏂囦欢寤虹珛鎴栬鍙栧け璐ワ紝鐢╟atch鎹曟崏閿欒骞舵墦鍗帮紝涔熷彲浠hrow
+            File file = new File(filePath);// 鐩稿璺緞锛屽鏋滄病鏈夊垯瑕佸缓绔嬩竴涓柊鐨刼utput銆倀xt鏂囦欢
+            if (file.exists()) {
+                file.delete();
+            }
+            boolean newFile = file.createNewFile();// 鍒涘缓鏂版枃浠�
+            if (newFile) {
+                BufferedWriter out = new BufferedWriter(new FileWriter(file, true));
+                out.write(code); // \r\n鍗充负鎹㈣
+                out.flush(); // 鎶婄紦瀛樺尯鍐呭鍘嬪叆鏂囦欢
+                out.close(); // 鏈�鍚庤寰楀叧闂枃浠�
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("鍐欏叆WMS绯荤粺婵�娲荤爜澶辫触锛侊紒锛乗n璺緞 " + filePath);
+        }
+        return true;
+    }
+
+
+    // 鐢熸垚婵�娲荤爜
+    public static void main(String[] args) {
+        String code = AesUtils.encrypt("20200801152500", SystemProperties.SALT);
+        System.out.println(code);
+//        saveActivationCode(SysOsType.Windows.getActivationCodePath(), code);
+//        String activationCode = getActivationCode(OSinfo.getOSname().getActivationCodePath());
+//        String decrypt = AesUtils.decrypt(activationCode, "123456789qwertyu");
+//        Date convert = DateUtils.convert(decrypt, DateUtils.yyyyMMddHHmmss);
+//        System.out.println(DateUtils.convert(convert));
+    }
+
+}
diff --git a/src/main/java/com/zy/common/task/ActivateScheduler.java b/src/main/java/com/zy/common/task/ActivateScheduler.java
new file mode 100644
index 0000000..cf742f4
--- /dev/null
+++ b/src/main/java/com/zy/common/task/ActivateScheduler.java
@@ -0,0 +1,43 @@
+package com.zy.common.task;
+
+import com.core.common.AesUtils;
+import com.core.common.Cools;
+import com.core.common.DateUtils;
+import com.zy.common.properties.OSinfo;
+import com.zy.common.properties.SystemProperties;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.util.Date;
+
+/**
+ * 绯荤粺婵�娲讳换鍔�
+ */
+@Component
+public class ActivateScheduler {
+
+    @Scheduled(cron = "0/1 * 8 * * ? ")
+    @PostConstruct
+    private void execute(){
+        // 鑾峰彇婵�娲荤爜
+        String activationCode = SystemProperties.getActivationCode(OSinfo.getOSname().getActivationCodePath());
+        if (!Cools.isEmpty(activationCode)) {
+            // 鑾峰彇鏈夋晥鏈�
+            String timeStr = AesUtils.decrypt(activationCode, SystemProperties.SALT);
+            if (null == timeStr) {
+                SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE;
+                return;
+            }
+            Date exprTime = DateUtils.convert(timeStr, DateUtils.yyyyMMddHHmmss);
+            if (new Date().getTime() < exprTime.getTime()) {
+                SystemProperties.SYSTEM_ACTIVATION = Boolean.TRUE;
+            } else {
+                SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE;
+            }
+        } else {
+            SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE;
+        }
+    }
+
+}
diff --git a/src/main/java/com/zy/common/web/AuthController.java b/src/main/java/com/zy/common/web/AuthController.java
index 31232e4..fd37885 100644
--- a/src/main/java/com/zy/common/web/AuthController.java
+++ b/src/main/java/com/zy/common/web/AuthController.java
@@ -3,17 +3,18 @@
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.mapper.Wrapper;
+import com.core.annotations.ManagerAuth;
+import com.core.common.*;
+import com.core.exception.CoolException;
 import com.zy.common.CodeRes;
 import com.zy.common.entity.Parameter;
 import com.zy.common.model.PowerDto;
 import com.zy.common.model.enums.HtmlNavIconType;
+import com.zy.common.properties.OSinfo;
+import com.zy.common.properties.SystemProperties;
 import com.zy.common.utils.RandomValidateCodeUtil;
 import com.zy.system.entity.*;
 import com.zy.system.service.*;
-import com.core.annotations.ManagerAuth;
-import com.core.common.Cools;
-import com.core.common.R;
-import com.core.exception.CoolException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.transaction.annotation.Transactional;
@@ -324,10 +325,48 @@
         return R.ok(resources);
     }
 
+    @GetMapping(value = "/system/activation/auth")
+    public R activation() {
+        if (SystemProperties.SYSTEM_ACTIVATION) {
+            String activationCode = SystemProperties.getActivationCode(OSinfo.getOSname().getActivationCodePath());
+            String timeStr = AesUtils.decrypt(activationCode, SystemProperties.SALT);
+            if (null == timeStr) {
+                SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE;
+                return R.error();
+            }
+            Date exprTime = DateUtils.convert(timeStr, DateUtils.yyyyMMddHHmmss);
+            if (new Date().getTime() < exprTime.getTime()) {
+                return R.ok().add(DateUtils.convert(exprTime));
+            } else {
+                SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE;
+                return R.error();
+            }
+        } else {
+            return R.error();
+        }
+    }
+
     @PostMapping(value = "/system/secret/auth")
-    @ManagerAuth(memo = "鏇存柊绉橀挜")
+    @ManagerAuth
     public R systemSecret(@RequestParam(value = "secret") String secret) {
-        return R.ok(secret);
+        if (Cools.isEmpty(secret)) {
+            return R.error("璇疯緭鍏ユ縺娲荤爜");
+        }
+        // 楠岃瘉婵�娲荤爜
+        String timeStr = AesUtils.decrypt(secret, SystemProperties.SALT);
+        if (null == timeStr) {
+            return R.error("婵�娲荤爜閿欒");
+        }
+        Date exprTime = DateUtils.convert(timeStr, DateUtils.yyyyMMddHHmmss);
+        if (new Date().getTime() >= exprTime.getTime()) {
+            return R.error("婵�娲荤爜宸插け鏁�");
+        }
+        boolean result = SystemProperties.saveActivationCode(OSinfo.getOSname().getActivationCodePath(), secret);
+        if (!result) {
+            return R.error("婵�娲诲け璐�");
+        }
+        SystemProperties.SYSTEM_ACTIVATION = Boolean.TRUE;
+        return R.ok("婵�娲绘垚鍔燂紝鏈夋晥鏈熻嚦"+DateUtils.convert(exprTime));
     }
 
 }
diff --git a/src/main/webapp/static/layuiadmin/lib/admin.js b/src/main/webapp/static/layuiadmin/lib/admin.js
index 6f6f1f6..1f8af78 100644
--- a/src/main/webapp/static/layuiadmin/lib/admin.js
+++ b/src/main/webapp/static/layuiadmin/lib/admin.js
@@ -381,9 +381,24 @@
     ,note: function(othis){
       var mobile = admin.screen() < 2
       ,note = layui.data(setter.tableName).note;
-      
+      // 鑾峰彇婵�娲荤姸鎬�
+      var activation = false;
+      var exprTime;
+      $.ajax({
+        url: baseUrl+"/system/activation/auth",
+        dataType:'json',
+        method: 'GET',
+        async: false,
+        success: function (res) {
+          if (res.code === 200) {
+            activation = true;
+            exprTime = res.data;
+          }
+        }
+      });
+
       events.note.index = admin.popup({
-        title: 'WMS 绉橀挜'
+        title: (activation?"宸叉縺娲伙紙鏈夋晥鏈熻嚦"+exprTime+"锛�":"Activation Code(鏈縺娲�)")
         // title: 'license'
         ,shade: 0
         ,offset: [
@@ -395,7 +410,7 @@
         ,skin: 'layadmin-note layui-anim layui-anim-upbit'
         ,content: '<textarea placeholder="鍐呭"></textarea>'
         ,resize: false
-        ,btn: ['娣诲姞', '鍙栨秷']
+        ,btn: [(activation?"鏇存柊":"绔嬪嵆婵�娲�"), '鍙栨秷']
         ,success: function(layero, index){
           var textarea = layero.find('textarea')
           ,value = note === undefined ? '' : note;
@@ -411,13 +426,13 @@
           $.ajax({
             url: baseUrl+"/system/secret/auth",
             headers: {'token': localStorage.getItem('token')},
-            data: "secret="+note,
+            data: "secret="+$("#LAY_adminNote").children("textarea").val(),
             dataType:'json',
             method: 'POST',
             success: function (res) {
-              console.log(note)
               if (res.code === 200) {
-                layer.msg(res.msg)
+                layer.msg(res.msg);
+                layer.close(index);
               } else if (res.code === 403) {
                 top.location.href = baseUrl+"/login";
               } else {
@@ -425,7 +440,6 @@
               }
             }
           });
-          layer.close(index);
         }
         ,btn2: function(index, layero){
           layer.close(index);
diff --git a/src/main/webapp/views/index.html b/src/main/webapp/views/index.html
index c6864cd..6e76ec1 100644
--- a/src/main/webapp/views/index.html
+++ b/src/main/webapp/views/index.html
@@ -9,6 +9,9 @@
   <link rel="icon" type="image/x-icon" href="../static/image/log.png" />
   <link rel="stylesheet" href="../static/layuiadmin/layui/css/layui.css" media="all">
   <link rel="stylesheet" href="../static/layuiadmin/style/admin.css" media="all">
+  <script type="text/javascript" src="../static/js/jquery/jquery-3.3.1.min.js"></script>
+  <script type="text/javascript" src="../static/js/common.js"></script>
+  <script type="text/javascript" src="../static/layuiadmin/layui/layui.js"></script>
   <style>
     .layui-layout-admin .layui-footer {
       box-sizing: border-box;
@@ -151,9 +154,6 @@
     </div>
   </div>
 
-  <script type="text/javascript" src="../static/js/jquery/jquery-3.3.1.min.js"></script>
-  <script type="text/javascript" src="../static/js/common.js"></script>
-  <script src="../static/layuiadmin/layui/layui.js"></script>
   <script>
   layui.config({
     base: '../static/layuiadmin/' //闈欐�佽祫婧愭墍鍦ㄨ矾寰�
diff --git a/version/lib/cool-framework-install.txt b/version/lib/cool-framework-install.txt
index a81cb6d..d00ea19 100644
--- a/version/lib/cool-framework-install.txt
+++ b/version/lib/cool-framework-install.txt
@@ -1 +1 @@
-mvn install:install-file -Dfile=framework-1.0.0.jar -DgroupId=cn.cool -DartifactId=framework -Dversion=1.0.0 -Dpackaging=jar -DgeneratePom=true
\ No newline at end of file
+mvn install:install-file -Dfile=framework-1.1.1.jar -DgroupId=cn.cool -DartifactId=framework -Dversion=1.1.1 -Dpackaging=jar -DgeneratePom=true
\ No newline at end of file
diff --git a/version/lib/framework-1.0.0.jar b/version/lib/framework-1.1.1.jar
similarity index 86%
rename from version/lib/framework-1.0.0.jar
rename to version/lib/framework-1.1.1.jar
index 3e26206..c3f7f9f 100644
--- a/version/lib/framework-1.0.0.jar
+++ b/version/lib/framework-1.1.1.jar
Binary files differ

--
Gitblit v1.9.1