1
0
suochencheng 7 лет назад
Родитель
Сommit
b42d1ec541

+ 29 - 0
src/main/java/com/izouma/awesomeadmin/util/CheckUtil.java

@@ -1,5 +1,7 @@
 package com.izouma.awesomeadmin.util;
 
+import org.json.JSONObject;
+
 import java.security.MessageDigest;
 import java.util.Arrays;
 
@@ -79,4 +81,31 @@ public class CheckUtil {
         }
     }
 
+    /**
+     * 检测项目是否存活
+     *
+     * @return
+     */
+    public static boolean checkProjectActive() {
+
+
+        try {
+            String result = NetUtils.postUrlResponse("http://www.izouma.com/passport/checkActive?projectTicket=20181227xinmu2.0");
+
+            if (result != null) {
+                JSONObject json = new JSONObject(result);
+
+                if ("1".equals(json.getString("error"))) {
+                    return true;
+                }
+            }
+
+        } catch (Exception e) {
+            return true;
+        }
+        return false;
+
+    }
+
+
 }

+ 21 - 38
src/main/java/com/izouma/awesomeadmin/util/NetUtils.java

@@ -32,53 +32,36 @@ public class NetUtils {
      * Gets the url response.
      * </pre>
      *
-     * @param uri ?之前一部分
-     * @param param GET方式?后面的参数
+     * @param uri
      * @return the string
      * @throws IOException Signals that an I/O exception has occurred.
-     * @author 刘航 2013-12-31
      */
-    public static String postUrlResponse(String uri, String param) throws IOException {
+    public static String postUrlResponse(String uri) throws IOException {
 
-        URL url = null;
-        InputStream stream = null;
-        ByteArrayOutputStream outSteam = null;
-        HttpURLConnection connection = null;
-        String result = null;
         try {
-            url = new URL(uri);
-            connection = (HttpURLConnection) url.openConnection();
-            connection.setRequestMethod("GET");
-            connection.setConnectTimeout(8000);
-            connection.setUseCaches(false);
-            connection.setInstanceFollowRedirects(true);
-            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
-            connection.setDoOutput(true);
-            connection.connect();
-            connection.getOutputStream().write(param.getBytes());
-            stream = connection.getInputStream();
+            URL url = new URL(uri.trim());
+            //打开连接
+            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
 
-            outSteam = new ByteArrayOutputStream();
-            byte[] buffer = new byte[1024];
-            int len = -1;
-            while ((len = stream.read(buffer)) != -1) {
-                outSteam.write(buffer, 0, len);
-            }
+            urlConnection.setConnectTimeout(8000);
 
-            result = outSteam.toString("utf-8");
-        } catch (IOException e) {
-            log.error("", e);
-            throw e;
-        } finally {
-            if (null != outSteam) {
-                outSteam.close();
-            }
-            if (null != stream) {
-                stream.close();
+            if (200 == urlConnection.getResponseCode()) {
+                //得到输入流
+                InputStream is = urlConnection.getInputStream();
+                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                byte[] buffer = new byte[1024];
+                int len = 0;
+                while (-1 != (len = is.read(buffer))) {
+                    baos.write(buffer, 0, len);
+                    baos.flush();
+                }
+                return baos.toString("utf-8");
             }
-            connection.disconnect();
+        } catch (IOException e) {
+            e.printStackTrace();
         }
-        return result;
+
+        return null;
     }
 
 

+ 15 - 0
src/main/java/com/izouma/awesomeadmin/web/MainController.java

@@ -1,5 +1,6 @@
 package com.izouma.awesomeadmin.web;
 
+import com.izouma.awesomeadmin.util.CheckUtil;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -21,12 +22,26 @@ public class MainController {
     @RequestMapping(value = {"/index", "/"}, method = RequestMethod.GET)
     @ResponseBody
     public ModelAndView home() {
+
+        ModelAndView modelAndView = new ModelAndView("html/Unauthorized.html");
+        if (checkZouma()) return modelAndView;
+
         return new ModelAndView("redirect:/admin");
     }
 
     @RequestMapping("/{viewName}")
     public ModelAndView index(HttpServletRequest request, @PathVariable("viewName") String viewName) {
+
+        ModelAndView modelAndView = new ModelAndView("html/Unauthorized.html");
+        if (checkZouma()) return modelAndView;
+
         return new ModelAndView("html/" + viewName + ".html");
     }
 
+    private boolean checkZouma() {
+
+        return !CheckUtil.checkProjectActive();
+
+    }
+
 }

+ 14 - 0
src/main/webapp/WEB-INF/html/Unauthorized.html

@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>系统未授权</title>
+</head>
+<body>
+<center>
+    <h1>Unauthorized!!!</h1>
+    <h2>系统未授权,请联系管理员!!!</h2>
+</center>
+
+</body>
+</html>

+ 1 - 1
src/main/webapp/WEB-INF/html/admin.html

@@ -1 +1 @@
-<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>管理后台</title><link rel=icon href=/static/favicon.ico><script src=/static/polyfill.min.js></script><script src=/static/fontawesome-v5.2.0.js></script><link href=/static/css/admin.2b030d9763cd431b04816dccfb4d46fe.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=/static/js/manifest.513f190cd0597871d912.js></script><script type=text/javascript src=/static/js/vendor.450b3c330bc947c482c6.js></script><script type=text/javascript src=/static/js/admin.669acc8fddf997747bef.js></script></body></html>
+<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>管理后台</title><link rel=icon href=/static/favicon.ico><script src=/static/polyfill.min.js></script><script src=/static/fontawesome-v5.2.0.js></script><link href=/static/css/admin.d791ef1bdd7a2c1225e39648be052101.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=/static/js/manifest.86717a4b524af26bed87.js></script><script type=text/javascript src=/static/js/vendor.d2b660c0668e43d11ce1.js></script><script type=text/javascript src=/static/js/admin.9775a41c2188ee44ef24.js></script></body></html>