├── .gitignore ├── README.md ├── Sunny-Ngrok启动工具.bat ├── data-analysis ├── pom.xml └── src │ ├── main │ └── scala │ │ └── com │ │ └── gizwits │ │ └── App.scala │ └── test │ └── java │ └── com │ └── gizwits │ └── AppTest.java ├── docker-compose.yml.example ├── images ├── background.png ├── log.png ├── pic01.png └── pic02.png ├── log-collection ├── Dockerfile ├── compile.sh ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── gizwits │ │ ├── analyse │ │ ├── HttpSemantic.java │ │ └── IContent.java │ │ ├── bean │ │ ├── Contants.java │ │ ├── DeviceInfo.java │ │ ├── ParticipantRepository.java │ │ ├── PayloadBody.java │ │ ├── RequestVoiceText.java │ │ └── ResponseMessage.java │ │ ├── config │ │ ├── BeanConfig.java │ │ ├── SwaggerConfig.java │ │ ├── WebSecurityConfig.java │ │ ├── WebSocketConfig.java │ │ ├── WechatMpConfiguration.java │ │ └── WechatMpProperties.java │ │ ├── controller │ │ ├── IndexController.java │ │ ├── WeixinController.java │ │ └── WsController.java │ │ ├── handle │ │ ├── AbstractBuilder.java │ │ ├── AbstractHandler.java │ │ ├── LocationHandler.java │ │ ├── LogHandler.java │ │ ├── MsgHandler.java │ │ └── TextBuilder.java │ │ ├── main │ │ └── App.java │ │ ├── tail │ │ ├── Tailer.java │ │ ├── TailerListener.java │ │ └── TailerListenerAdapter.java │ │ └── util │ │ └── LRUCache.java │ └── resources │ ├── application.properties │ ├── banner.txt │ ├── logback.xml │ ├── static │ ├── css │ │ ├── bootstrap.min.css │ │ └── main.css │ └── js │ │ ├── bootstrap.min.js │ │ ├── html5shiv.js │ │ ├── jquery.min.js │ │ ├── respond.min.js │ │ ├── sockjs.min.js │ │ └── stomp.min.js │ └── templates │ └── index.html ├── ngrok ├── python-ngrok.py ├── smock.sh ├── sunny └── sunny.exe /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml 3 | .DS_Store 4 | log-collection/target 5 | data-analysis/target 6 | owen.md 7 | log/ 8 | docker-compose.yml 9 | data-analysis/src/main/resources/rtdata.json -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### 菜鸟也能也学会基于物联网开发智能家居 2 | 3 | 本教程案例是基于机智云物联网平台开发的智能家居案例 4 | 5 | ### 开发环境 6 | 7 | * 1.macbook/windows/linux 8 | * 2.jdk8/idea 9 | * 3.gokit开发板套件 10 | * 4.微信订阅号 11 | * 5.反向代理工具 12 | 13 | ### 使用的相关技术 14 | * 1.netty/nio 15 | * 2.spring-boot 16 | * 3.webscoket 17 | * 4.docker 18 | * 5.语音识别 19 | 20 | 21 | 22 | 23 | ### docker部署 24 | 25 | docker-compose.yml 26 | 27 | ``` 28 | 29 | log: 30 | container_name: log 31 | image: daocloud.io/gizwits2015/log-collection 32 | working_dir: /data 33 | volumes: 34 | - ./log:/data 35 | ports: 36 | - "8080:8080" 37 | environment: 38 | SECURITY_USER_NAME: "admin" 39 | SECURITY_USER_PASSWORD: "123456" 40 | LOGMONITOR_LOGPATH: "/data/log-collection.log" 41 | APP_PRODUCT_KEY: "xx" 42 | APP_DID: "xx" 43 | APP_MAC: "xx" 44 | APP_AUTH_ID: "xx" 45 | APP_AUTH_SECRET: "xx" 46 | APP_SUBKEY: "client" 47 | APP_PREFETCH_COUNT: 50 48 | WECHAT_MP_APPID: "xx" 49 | WECHAT_MP_SECRET: "xx" 50 | WECHAT_MP_TOKEN: "weixin" 51 | WECHAT_MP_AESKEY: "xx" 52 | SEMANTIC_API: "xx" 53 | 54 | ``` 55 | 56 | ### 日志监控及采集 57 | 58 | ``` 59 | http://localhost:8080/logMonitor 60 | 61 | ``` 62 | 63 | ![image](images/log.png) 64 | 65 | 66 | ### 设备控制API 67 | 68 | ``` 69 | http://localhost:8080/swagger-ui.html 70 | 71 | ``` 72 | 73 | 74 | ``` 75 | curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \ 76 | "mac": "xx", \ 77 | "did": "xx", \ 78 | "cmd": { \ 79 | "LED_OnOff": false, \ 80 | "LED_Color": "紫色", \ 81 | "Motor_Speed": 0 \ 82 | } \ 83 | }' 'http://localhost:8080/dev/control' 84 | ``` 85 | 86 | 87 | 88 | ### 部分语音和文本控制设备 89 | 90 | ![image](images/pic01.png) 91 | 92 | 93 | ![image](images/pic02.png) 94 | 95 | 96 | 97 | ### 视频演示 98 | 99 | [![视频演示](images/background.png)](https://v.qq.com/x/page/w0526jgvvm1.html) 100 | 101 | 102 | * [机智云开发者平台](http://dev.gizwits.com/) 103 | * [Snoti](http://docs.gizwits.com/zh-cn/Cloud/NotificationAPI.html) 104 | * [noti-netty-client](https://github.com/Bestfeel/noti-netty-client) 105 | * [机智云API文档列表](http://swagger.gizwits.com/doc/menu) -------------------------------------------------------------------------------- /Sunny-Ngrok启动工具.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bestfeel/gizwits-iot-course/c9383f955bc9201fc5971ffa4e94c501caa44e7b/Sunny-Ngrok启动工具.bat -------------------------------------------------------------------------------- /data-analysis/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.gizwits 6 | data-analysis 7 | 1.0 8 | jar 9 | 10 | data-analysis 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | UTF-8 16 | UTF-8 17 | 4.12 18 | 1.8 19 | 2.2.0 20 | 21 | 22 | 23 | 24 | junit 25 | junit 26 | 4.4 27 | test 28 | 29 | 30 | org.specs 31 | specs 32 | 1.4.3 33 | test 34 | 35 | 36 | org.apache.spark 37 | spark-core_2.10 38 | ${spark.version} 39 | 40 | 41 | org.apache.spark 42 | spark-sql_2.10 43 | ${spark.version} 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.apache.maven.plugins 52 | maven-compiler-plugin 53 | 3.5.1 54 | 55 | ${java.version} 56 | ${java.version} 57 | 58 | 59 | 60 | org.apache.maven.plugins 61 | maven-resources-plugin 62 | 2.6 63 | 64 | UTF-8 65 | 66 | 67 | 68 | net.alchim31.maven 69 | scala-maven-plugin 70 | 3.2.2 71 | 72 | 73 | 74 | compile 75 | testCompile 76 | 77 | 78 | 79 | 80 | 81 | 82 | org.apache.maven.plugins 83 | maven-eclipse-plugin 84 | 2.10 85 | 86 | 87 | org.scala-ide.sdt.core.scalanature 88 | org.eclipse.jdt.core.javanature 89 | 90 | 91 | org.scala-ide.sdt.core.scalabuilder 92 | 93 | 94 | org.scala-ide.sdt.launching.SCALA_CONTAINER 95 | org.eclipse.jdt.launching.JRE_CONTAINER 96 | 97 | 98 | org.scala-lang:scala-library 99 | org.scala-lang:scala-compiler 100 | 101 | 102 | **/*.scala 103 | **/*.java 104 | 105 | 106 | 107 | 108 | 109 | 110 | org.apache.maven.plugins 111 | maven-shade-plugin 112 | 2.3 113 | 114 | 115 | package 116 | 117 | shade 118 | 119 | 120 | 121 | 122 | 123 | 124 | *:* 125 | 126 | META-INF/*.SF 127 | META-INF/*.DSA 128 | META-INF/*.RSA 129 | 130 | 131 | 132 | ${project.artifactId}_2.10-1.0 133 | 134 | 135 | 136 | org.apache.maven.plugins 137 | maven-assembly-plugin 138 | 139 | 140 | jar-with-dependencies 141 | 142 | 143 | 144 | 145 | assemble-all 146 | package 147 | 148 | single 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /data-analysis/src/main/scala/com/gizwits/App.scala: -------------------------------------------------------------------------------- 1 | package com.gizwits 2 | 3 | import org.apache.spark.rdd.RDD 4 | import org.apache.spark.{SparkConf, SparkContext} 5 | import org.json4s.JsonAST._ 6 | import org.json4s.jackson.JsonMethods._ 7 | 8 | /** 9 | * Created by feel on 2017/7/15. 10 | */ 11 | object App { 12 | 13 | 14 | case class Device(product_key: String, mac: String, `type`: String, ts: Long) 15 | 16 | def main(args: Array[String]): Unit = { 17 | val conf = new SparkConf(true) 18 | .setAppName("StatisticsAnalysis") 19 | .set("spark.scheduler.mode", "FAIR") 20 | .set("spark.default.parallelism", "16") 21 | .setMaster("local[4]") 22 | 23 | 24 | val sc = new SparkContext(conf) 25 | 26 | val localFilePath = "file://data/rtdata.json" 27 | 28 | // 解析字段,提取需要的字段数据 29 | val dataRDD = sc.textFile(localFilePath, 10) 30 | .map(line => parse(line)) 31 | .map(line => Device( 32 | jv2String(line \ "product_key") 33 | , jv2String(line \ "mac") 34 | , jv2String(line \ "type") 35 | , jv2String((line \ "timestamp")).toLong 36 | )) 37 | 38 | val acticeCmd = List("dev2app", "app2dev") 39 | val incrCmd = List("dev_online", "dev_offline", "dev_re_online") 40 | 41 | 42 | // 统计活跃设备 43 | countByDevice(dataRDD.filter(d => acticeCmd.contains(d.`type`)), true).foreach(println _) 44 | // 统计新增(激活)设备 45 | countByDevice(dataRDD.filter(d => incrCmd.contains(d.`type`)), true).foreach(println _) 46 | } 47 | 48 | /** 49 | * 根据pk 指定设备数量 50 | * 51 | * @param device 52 | * @return 53 | */ 54 | def countByDevice(device: RDD[Device], uniq: Boolean = true): RDD[(String, Long)] = { 55 | uniq match { 56 | case true => { 57 | device.map(d => ((d.product_key, d.mac), d.ts)) 58 | .reduceByKey(Math.max) 59 | .map { 60 | case ((pk, mac), ts) => (pk.toString, 1L) 61 | }.repartition(1).reduceByKey(_ + _) 62 | } 63 | case false => { 64 | device.map(d => ((d.product_key, d.mac), d.ts)) 65 | .reduceByKey(Math.min) 66 | .map { 67 | case ((pk, mac), ts) => (pk.toString, 1L) 68 | }.repartition(1).reduceByKey(_ + _) 69 | } 70 | } 71 | 72 | } 73 | 74 | 75 | def jv2String(json: JValue): String = { 76 | import org.json4s._ 77 | implicit lazy val formats = org.json4s.DefaultFormats 78 | json match { 79 | case JBool(value) => value.toString 80 | case JDecimal(value) => value.toString 81 | case JInt(value) => value.toString 82 | case JDouble(value) => value.toLong.toString 83 | case JString(value) => value.toString 84 | case JNull => "" 85 | case JNothing => "" 86 | case jv: JValue => jv.extract[String] 87 | } 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /data-analysis/src/test/java/com/gizwits/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.gizwits; 2 | 3 | import org.junit.Test; 4 | 5 | /** 6 | * Created by feel on 2017/7/15. 7 | */ 8 | public class AppTest { 9 | 10 | @Test 11 | public void test1() throws Exception { 12 | System.out.println("hello world"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /docker-compose.yml.example: -------------------------------------------------------------------------------- 1 | log: 2 | container_name: log 3 | image: daocloud.io/gizwits2015/log-collection 4 | working_dir: /data 5 | volumes: 6 | - ./log:/data 7 | ports: 8 | - "8080:8080" 9 | environment: 10 | SECURITY_USER_NAME: "admin" 11 | SECURITY_USER_PASSWORD: "123456" 12 | LOGMONITOR_LOGPATH: "/data/log-collection.log" 13 | APP_PRODUCT_KEY: "xx" 14 | APP_DID: "xx" 15 | APP_MAC: "xx" 16 | APP_AUTH_ID: "xx" 17 | APP_AUTH_SECRET: "xx" 18 | APP_SUBKEY: "client" 19 | APP_PREFETCH_COUNT: 50 20 | WECHAT_MP_APPID: "xx" 21 | WECHAT_MP_SECRET: "xx" 22 | WECHAT_MP_TOKEN: "weixin" 23 | WECHAT_MP_AESKEY: "xx" 24 | SEMANTIC_API: "xx" 25 | 26 | -------------------------------------------------------------------------------- /images/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bestfeel/gizwits-iot-course/c9383f955bc9201fc5971ffa4e94c501caa44e7b/images/background.png -------------------------------------------------------------------------------- /images/log.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bestfeel/gizwits-iot-course/c9383f955bc9201fc5971ffa4e94c501caa44e7b/images/log.png -------------------------------------------------------------------------------- /images/pic01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bestfeel/gizwits-iot-course/c9383f955bc9201fc5971ffa4e94c501caa44e7b/images/pic01.png -------------------------------------------------------------------------------- /images/pic02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bestfeel/gizwits-iot-course/c9383f955bc9201fc5971ffa4e94c501caa44e7b/images/pic02.png -------------------------------------------------------------------------------- /log-collection/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM daocloud.io/gizwits2015/java8 2 | MAINTAINER feel 3 | RUN mkdir -p /app 4 | ADD target/log-collection-1.0.jar /app/app.jar 5 | EXPOSE 8080 6 | VOLUME /app 7 | WORKDIR /app 8 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app/app.jar"] -------------------------------------------------------------------------------- /log-collection/compile.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | 4 | mvn clean compile package -Dmaven.test.skip=true 5 | 6 | docker build -t daocloud.io/gizwits2015/log-collection . -------------------------------------------------------------------------------- /log-collection/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.gizwits 6 | log-collection 7 | 1.0 8 | jar 9 | 10 | log-collection 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | UTF-8 16 | UTF-8 17 | 4.12 18 | 1.8 19 | 3.5.1 20 | 1.5.0.RELEASE 21 | 1.7.18 22 | 2.7.3.BETA 23 | 2.7.0 24 | daocloud.io/gizwits2015 25 | 26 | 27 | 28 | feel 29 | feel 30 | Gizwits 31 | fye@gizwits.com 32 | 33 | 34 | 35 | 36 | junit 37 | junit 38 | ${junit.version} 39 | test 40 | 41 | 42 | commons-io 43 | commons-io 44 | 2.5 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-thymeleaf 49 | ${spring-boot.version} 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-starter-websocket 54 | ${spring-boot.version} 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-starter-security 59 | ${spring-boot.version} 60 | 61 | 62 | com.gizwits 63 | noti-netty-client 64 | 0.1.1 65 | 66 | 67 | com.github.binarywang 68 | weixin-java-mp 69 | ${weixin-java-mp.version} 70 | 71 | 72 | 73 | com.thoughtworks.xstream 74 | xstream 75 | 1.4.7 76 | 77 | 78 | com.squareup.retrofit2 79 | converter-gson 80 | 2.1.0 81 | 82 | 83 | io.springfox 84 | springfox-swagger2 85 | ${swagger2.version} 86 | 87 | 88 | io.springfox 89 | springfox-swagger-ui 90 | ${swagger2.version} 91 | 92 | 93 | 94 | 95 | 96 | org.apache.maven.plugins 97 | maven-compiler-plugin 98 | 3.5.1 99 | 100 | ${java-version} 101 | ${java-version} 102 | ${java-version} 103 | UTF-8 104 | 105 | 106 | 107 | org.apache.maven.plugins 108 | maven-resources-plugin 109 | 2.6 110 | 111 | UTF-8 112 | 113 | 114 | 115 | org.springframework.boot 116 | spring-boot-maven-plugin 117 | ${spring-boot.version} 118 | 119 | true 120 | 121 | 122 | 123 | 124 | repackage 125 | 126 | 127 | 128 | 129 | 130 | com.spotify 131 | docker-maven-plugin 132 | 0.4.13 133 | 134 | ${docker.image.prefix}/${project.artifactId} 135 | daocloud.io/gizwits2015/java8 136 | src/main/docker 137 | 138 | 139 | / 140 | ${project.build.directory} 141 | ${project.build.finalName}.jar 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/analyse/HttpSemantic.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.analyse; 2 | 3 | import com.gizwits.bean.RequestVoiceText; 4 | import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; 5 | import okhttp3.ResponseBody; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Component; 10 | import retrofit2.Call; 11 | import retrofit2.Retrofit; 12 | 13 | import java.io.IOException; 14 | 15 | /** 16 | * Created by feel on 2017/7/14. 17 | */ 18 | @Component 19 | public class HttpSemantic { 20 | 21 | private final static Logger LOGGER = LoggerFactory.getLogger(HttpSemantic.class); 22 | 23 | @Autowired 24 | private Retrofit newRetrofit; 25 | 26 | public String getVoiceSemantic(RequestVoiceText voiceText) { 27 | 28 | IContent iContent = newRetrofit.create(IContent.class); 29 | 30 | Call content = iContent.getContent(voiceText); 31 | 32 | try { 33 | String semText = content.execute().body().string(); 34 | 35 | return semText; 36 | } catch (IOException e) { 37 | 38 | LOGGER.error("{}", e); 39 | e.printStackTrace(); 40 | return null; 41 | } 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/analyse/IContent.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.analyse; 2 | 3 | import com.gizwits.bean.RequestVoiceText; 4 | import okhttp3.ResponseBody; 5 | import retrofit2.Call; 6 | import retrofit2.http.Body; 7 | import retrofit2.http.Headers; 8 | import retrofit2.http.POST; 9 | 10 | public interface IContent { 11 | @Headers({"Content-Type: application/json", 12 | "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36" 13 | }) 14 | @POST("/semantic_api/analyse") 15 | Call getContent(@Body RequestVoiceText body); 16 | 17 | } -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/bean/Contants.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.bean; 2 | 3 | /** 4 | * Created by feel on 2017/2/1. 5 | */ 6 | public final class Contants { 7 | /** 8 | * 请求失败状态码 9 | */ 10 | public static Integer ERROR_0 = 101; 11 | /** 12 | * 请求成功状态码 13 | */ 14 | public static Integer SUCCESS_0 = 201; 15 | 16 | /** 17 | * 开启日志嗅探合法参数 18 | */ 19 | public static String[] ACTIONS = {"start", "shutdown"}; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/bean/DeviceInfo.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.bean; 2 | 3 | /** 4 | * Created by feel on 2017/7/14. 5 | */ 6 | public class DeviceInfo { 7 | private String pk; 8 | private String pn = "gokit"; 9 | private String pa = "小智"; 10 | private String pt = "normal"; 11 | private String did; 12 | private String alias = "小智"; 13 | private boolean online = true; 14 | 15 | public DeviceInfo() { 16 | } 17 | 18 | public DeviceInfo(String pk, String did) { 19 | this.pk = pk; 20 | this.did = did; 21 | } 22 | 23 | public String getPk() { 24 | return pk; 25 | } 26 | 27 | public void setPk(String pk) { 28 | this.pk = pk; 29 | } 30 | 31 | public String getPn() { 32 | return pn; 33 | } 34 | 35 | public void setPn(String pn) { 36 | this.pn = pn; 37 | } 38 | 39 | public String getPa() { 40 | return pa; 41 | } 42 | 43 | public void setPa(String pa) { 44 | this.pa = pa; 45 | } 46 | 47 | public String getPt() { 48 | return pt; 49 | } 50 | 51 | public void setPt(String pt) { 52 | this.pt = pt; 53 | } 54 | 55 | public String getDid() { 56 | return did; 57 | } 58 | 59 | public void setDid(String did) { 60 | this.did = did; 61 | } 62 | 63 | public String getAlias() { 64 | return alias; 65 | } 66 | 67 | public void setAlias(String alias) { 68 | this.alias = alias; 69 | } 70 | 71 | public boolean isOnline() { 72 | return online; 73 | } 74 | 75 | public void setOnline(boolean online) { 76 | this.online = online; 77 | } 78 | 79 | @Override 80 | public String toString() { 81 | return "DeviceInfo{" + 82 | "pk='" + pk + '\'' + 83 | ", pn='" + pn + '\'' + 84 | ", pa='" + pa + '\'' + 85 | ", pt='" + pt + '\'' + 86 | ", did='" + did + '\'' + 87 | ", alias='" + alias + '\'' + 88 | ", online=" + online + 89 | '}'; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/bean/ParticipantRepository.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.bean; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import java.util.Map; 6 | import java.util.concurrent.ConcurrentHashMap; 7 | 8 | @Component 9 | public class ParticipantRepository { 10 | 11 | private Map activeSessions = new ConcurrentHashMap<>(); 12 | 13 | public void add(String sessionId, String userName) { 14 | activeSessions.putIfAbsent(sessionId, userName); 15 | } 16 | 17 | public String getParticipant(String sessionId) { 18 | return activeSessions.get(sessionId); 19 | } 20 | 21 | public void removeParticipant(String sessionId) { 22 | activeSessions.remove(sessionId); 23 | } 24 | 25 | public Map getActiveSessions() { 26 | return activeSessions; 27 | } 28 | 29 | public void setActiveSessions(Map activeSessions) { 30 | this.activeSessions = activeSessions; 31 | } 32 | } -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/bean/PayloadBody.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.bean; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * Created by feel on 2017/7/13. 7 | */ 8 | public class PayloadBody { 9 | 10 | private String mac; 11 | private String did; 12 | private Map cmd; 13 | 14 | 15 | public PayloadBody() { 16 | } 17 | 18 | public PayloadBody(String mac, String did, Map cmd) { 19 | this.mac = mac; 20 | this.did = did; 21 | this.cmd = cmd; 22 | } 23 | 24 | public boolean isEmpty() { 25 | 26 | if (this.getCmd().isEmpty() || mac == "" || did == "") { 27 | return true; 28 | } else { 29 | return false; 30 | } 31 | } 32 | 33 | public String getMac() { 34 | return mac; 35 | } 36 | 37 | public void setMac(String mac) { 38 | this.mac = mac; 39 | } 40 | 41 | public String getDid() { 42 | return did; 43 | } 44 | 45 | public void setDid(String did) { 46 | this.did = did; 47 | } 48 | 49 | public Map getCmd() { 50 | return cmd; 51 | } 52 | 53 | public void setCmd(Map cmd) { 54 | this.cmd = cmd; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "RequestBody{" + 60 | "mac='" + mac + '\'' + 61 | ", did='" + did + '\'' + 62 | ", cmd=" + cmd + 63 | '}'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/bean/RequestVoiceText.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.bean; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by feel on 2017/7/14. 7 | */ 8 | public class RequestVoiceText { 9 | private String uid = "uid"; 10 | private String text; 11 | private String source = "audio_device"; 12 | private int type = 1; 13 | private String language = "zh_cn"; 14 | private String modes = "modes"; 15 | private List devices; 16 | 17 | public RequestVoiceText() { 18 | } 19 | 20 | public RequestVoiceText(String text, List devices) { 21 | this.text = text; 22 | 23 | this.devices = devices; 24 | } 25 | 26 | public String getUid() { 27 | return uid; 28 | } 29 | 30 | public void setUid(String uid) { 31 | this.uid = uid; 32 | } 33 | 34 | public String getText() { 35 | return text; 36 | } 37 | 38 | public void setText(String text) { 39 | this.text = text; 40 | } 41 | 42 | public String getSource() { 43 | return source; 44 | } 45 | 46 | public void setSource(String source) { 47 | this.source = source; 48 | } 49 | 50 | public int getType() { 51 | return type; 52 | } 53 | 54 | public void setType(int type) { 55 | this.type = type; 56 | } 57 | 58 | public String getLanguage() { 59 | return language; 60 | } 61 | 62 | public void setLanguage(String language) { 63 | this.language = language; 64 | } 65 | 66 | public String getModes() { 67 | return modes; 68 | } 69 | 70 | public void setModes(String modes) { 71 | this.modes = modes; 72 | } 73 | 74 | public List getDevices() { 75 | return devices; 76 | } 77 | 78 | public void setDevices(List devices) { 79 | this.devices = devices; 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | return "RequestVoiceText{" + 85 | "uid='" + uid + '\'' + 86 | ", text='" + text + '\'' + 87 | ", source='" + source + '\'' + 88 | ", type=" + type + 89 | ", language='" + language + '\'' + 90 | ", modes='" + modes + '\'' + 91 | ", devices=" + devices + 92 | '}'; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/bean/ResponseMessage.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.bean; 2 | 3 | /** 4 | * Created by feel on 2017/2/1. 5 | */ 6 | public class ResponseMessage { 7 | 8 | private Integer code; 9 | private String message; 10 | private String ref; 11 | 12 | public ResponseMessage() { 13 | } 14 | 15 | public ResponseMessage(Integer code, String message) { 16 | this.code = code; 17 | this.message = message; 18 | } 19 | 20 | public ResponseMessage(Integer code, String message, String ref) { 21 | this.code = code; 22 | this.message = message; 23 | this.ref = ref; 24 | } 25 | 26 | public Integer getCode() { 27 | return code; 28 | } 29 | 30 | public void setCode(Integer code) { 31 | this.code = code; 32 | } 33 | 34 | public String getMessage() { 35 | return message; 36 | } 37 | 38 | public void setMessage(String message) { 39 | this.message = message; 40 | } 41 | 42 | public String getRef() { 43 | return ref; 44 | } 45 | 46 | public void setRef(String ref) { 47 | this.ref = ref; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "ResponseMessage{" + 53 | "code=" + code + 54 | ", message='" + message + '\'' + 55 | ", ref='" + ref + '\'' + 56 | '}'; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/config/BeanConfig.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.config; 2 | 3 | import com.gizwits.noti2.client.Events; 4 | import com.gizwits.noti2.client.NotiClient; 5 | import com.gizwits.util.LRUCache; 6 | import okhttp3.OkHttpClient; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import retrofit2.Retrofit; 11 | import retrofit2.converter.gson.GsonConverterFactory; 12 | 13 | import java.util.Arrays; 14 | import java.util.concurrent.TimeUnit; 15 | 16 | /** 17 | * Created by feel on 2017/2/2. 18 | */ 19 | @Configuration 20 | public class BeanConfig { 21 | 22 | @Value("${app.product_key}") 23 | private String product_key; 24 | @Value("${app.auth_id}") 25 | private String auth_id; 26 | @Value("${app.auth_secret}") 27 | private String auth_secret; 28 | @Value("${app.subkey}") 29 | private String subkey; 30 | @Value("${app.prefetch_count}") 31 | private int prefetch_count; 32 | @Value("${semantic.api}") 33 | private String analyseUrl; 34 | 35 | @Bean 36 | public LRUCache lruCache() { 37 | return new LRUCache(1000); 38 | } 39 | 40 | @Bean(name = "notiClient") 41 | public NotiClient notiClient() { 42 | 43 | NotiClient notiClient = NotiClient 44 | .build() 45 | .setHost("snoti.gizwits.com") 46 | .setPort(2017) 47 | .login(product_key, auth_id, auth_secret, subkey, prefetch_count, Arrays.asList(Events.ONLINE, Events.OFFLINE, Events.STATUS_KV, Events.STATUS_RAW, Events.ATTR_ALERT, Events.ATTR_FAULT)); 48 | 49 | notiClient.doStart(); 50 | 51 | return notiClient; 52 | } 53 | 54 | 55 | /** 56 | * 获取Retrofit适配器。 57 | * 58 | * @return 网络适配器 59 | */ 60 | @Bean(name = "newRetrofit") 61 | public Retrofit newRetrofit() { 62 | 63 | return new Retrofit.Builder().baseUrl(analyseUrl) 64 | .client(getClient().build()) 65 | .addConverterFactory(GsonConverterFactory.create()) 66 | .build(); 67 | } 68 | 69 | /** 70 | * 获取 OkHttpClient 71 | * 72 | * @return OkHttpClient 73 | */ 74 | private OkHttpClient.Builder getClient() { 75 | 76 | return new OkHttpClient.Builder() 77 | .connectTimeout(5, TimeUnit.SECONDS) 78 | .writeTimeout(5, TimeUnit.SECONDS) 79 | .readTimeout(300, TimeUnit.SECONDS); 80 | 81 | 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.config; 2 | 3 | import com.google.common.base.Predicate; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.context.request.async.DeferredResult; 7 | import springfox.documentation.annotations.ApiIgnore; 8 | import springfox.documentation.service.ApiInfo; 9 | import springfox.documentation.spi.DocumentationType; 10 | import springfox.documentation.spring.web.plugins.Docket; 11 | 12 | import static com.google.common.base.Predicates.not; 13 | import static com.google.common.base.Predicates.or; 14 | import static springfox.documentation.builders.PathSelectors.regex; 15 | import static springfox.documentation.builders.RequestHandlerSelectors.withClassAnnotation; 16 | 17 | /** 18 | * link: http://localhost:8080/swagger-ui.html 19 | * https://springfox.github.io/springfox/docs/snapshot/ 20 | * https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X 21 | */ 22 | @Configuration 23 | public class SwaggerConfig { 24 | @Bean 25 | public Docket merchantStoreApi() { 26 | return new Docket(DocumentationType.SWAGGER_2) 27 | .genericModelSubstitutes(DeferredResult.class) 28 | .useDefaultResponseMessages(false) 29 | .forCodeGeneration(true) 30 | .pathMapping("/")// base,最终调用接口后会和paths拼接在一起 31 | .select() 32 | .apis(not(withClassAnnotation(ApiIgnore.class))) //SwaggerIngore的注解的controller将会被忽略 33 | .paths(paths()) 34 | .paths(not(regex("/error"))) 35 | .build() 36 | .apiInfo(testApiInfo()); 37 | 38 | } 39 | 40 | private Predicate paths() { 41 | return or(regex("/.*")); 42 | } 43 | 44 | private ApiInfo testApiInfo() { 45 | ApiInfo apiInfo = new ApiInfo("设备远程控制",//大标题 46 | "设备远程控制",//小标题 47 | "1.0",//版本 48 | "http://www.gizwits.com/", 49 | "fye@gizwits.com",//作者 50 | "The Apache License, Version 2.0",//链接显示文字 51 | "www.gizwits.com"//网站链接 52 | ); 53 | return apiInfo; 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/config/WebSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.builders.WebSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 9 | 10 | /** 11 | * Created by feel on 2017/2/1. 12 | */ 13 | @Configuration 14 | @EnableWebSecurity 15 | @EnableGlobalMethodSecurity(prePostEnabled = true) 16 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 17 | 18 | /** 19 | * 具体控制权限,角色,url等安全 20 | * 21 | * @param http 22 | * @throws Exception 23 | */ 24 | @Override 25 | protected void configure(HttpSecurity http) throws Exception { 26 | 27 | http.authorizeRequests() 28 | .antMatchers("/logMonitor") //设置拦截规则 29 | .authenticated() 30 | .antMatchers("/logMonitor/*") //设置拦截规则 31 | .authenticated() 32 | .antMatchers("/logMonitor/set/*") //设置拦截规则 33 | .authenticated() 34 | .and() 35 | .httpBasic() 36 | .and() 37 | .csrf().disable(); 38 | 39 | 40 | } 41 | 42 | 43 | @Override 44 | public void configure(WebSecurity web) throws Exception { 45 | //设置不拦截规则 46 | web.ignoring().antMatchers("/resources/static/**"); 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/config/WebSocketConfig.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.messaging.simp.config.MessageBrokerRegistry; 5 | import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer; 6 | import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; 7 | import org.springframework.web.socket.config.annotation.StompEndpointRegistry; 8 | 9 | /** 10 | * Created by feel on 2017/2/1. 11 | * websocket 配置 12 | * 参考官网文档:https://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html 13 | */ 14 | @Configuration 15 | @EnableWebSocketMessageBroker //开启使用STOMP协议来传输基于代理的消息 16 | public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { 17 | /** 18 | * 注册STOMP协议的节点,并指定映射的UR 19 | * 20 | * @param stompEndpointRegistry 21 | */ 22 | @Override 23 | public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) { 24 | stompEndpointRegistry.addEndpoint("/endpointLogMonitor") 25 | .setAllowedOrigins("*") 26 | .withSockJS(); //注册STOMP协议节点,同时指定使用SockJS协议,允许跨域 27 | } 28 | 29 | /** 30 | * 实现推送功能,配置消息代理 31 | * 32 | * @param config 33 | */ 34 | @Override 35 | public void configureMessageBroker(MessageBrokerRegistry config) { 36 | config.enableSimpleBroker("/topic", "/exchange"); // 消息定义主题,可开放多个消息主题 37 | config.setApplicationDestinationPrefixes("/app"); //全局使用的订阅前缀(客户端订阅路径上会体现出来),和@MessageMapping 进行组合 38 | config.setUserDestinationPrefix("/user"); //点对点使用的订阅前缀(客户端订阅路径上会体现出来),不设置的话,默认也是/user/ 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/config/WechatMpConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.config; 2 | 3 | import com.gizwits.handle.AbstractHandler; 4 | import com.gizwits.handle.LocationHandler; 5 | import com.gizwits.handle.LogHandler; 6 | import com.gizwits.handle.MsgHandler; 7 | import me.chanjar.weixin.common.api.WxConsts; 8 | import me.chanjar.weixin.mp.api.WxMpConfigStorage; 9 | import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage; 10 | import me.chanjar.weixin.mp.api.WxMpMessageRouter; 11 | import me.chanjar.weixin.mp.api.WxMpService; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 14 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 15 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 16 | import org.springframework.context.annotation.Bean; 17 | import org.springframework.context.annotation.Configuration; 18 | 19 | @Configuration 20 | @ConditionalOnClass(WxMpService.class) 21 | @EnableConfigurationProperties(WechatMpProperties.class) 22 | public class WechatMpConfiguration { 23 | @Autowired 24 | private WechatMpProperties properties; 25 | 26 | @Autowired 27 | private MsgHandler msgHandler; 28 | 29 | @Autowired 30 | protected LogHandler logHandler; 31 | @Autowired 32 | private LocationHandler locationHandler; 33 | 34 | @Bean 35 | @ConditionalOnMissingBean 36 | public WxMpConfigStorage configStorage() { 37 | WxMpInMemoryConfigStorage configStorage = new WxMpInMemoryConfigStorage(); 38 | configStorage.setAppId(this.properties.getAppId()); 39 | configStorage.setSecret(this.properties.getSecret()); 40 | configStorage.setToken(this.properties.getToken()); 41 | configStorage.setAesKey(this.properties.getAesKey()); 42 | return configStorage; 43 | } 44 | 45 | @Bean 46 | @ConditionalOnMissingBean 47 | public WxMpService wxMpService(WxMpConfigStorage configStorage) { 48 | WxMpService wxMpService = new me.chanjar.weixin.mp.api.impl.WxMpServiceImpl(); 49 | wxMpService.setWxMpConfigStorage(configStorage); 50 | return wxMpService; 51 | } 52 | 53 | @Bean 54 | public WxMpMessageRouter router(WxMpService wxMpService) { 55 | final WxMpMessageRouter newRouter = new WxMpMessageRouter(wxMpService); 56 | 57 | //记录所有事件的日志 (异步执行) 58 | newRouter.rule().handler(this.logHandler).next(); 59 | 60 | // 接收地理位置消息 61 | newRouter.rule().async(false).msgType(WxConsts.XML_MSG_LOCATION) 62 | .handler(this.getLocationHandler()).end(); 63 | 64 | // 默认 65 | newRouter.rule().async(false).handler(this.getMsgHandler()).end(); 66 | 67 | return newRouter; 68 | } 69 | 70 | 71 | protected MsgHandler getMsgHandler() { 72 | return this.msgHandler; 73 | } 74 | 75 | 76 | protected AbstractHandler getLocationHandler() { 77 | return this.locationHandler; 78 | } 79 | } -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/config/WechatMpProperties.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.config; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | 5 | @ConfigurationProperties(prefix = "wechat.mp") 6 | public class WechatMpProperties { 7 | /** 8 | * 设置微信公众号的appid 9 | */ 10 | private String appId; 11 | 12 | /** 13 | * 设置微信公众号的app secret 14 | */ 15 | private String secret; 16 | 17 | /** 18 | * 设置微信公众号的token 19 | */ 20 | private String token; 21 | 22 | /** 23 | * 设置微信公众号的EncodingAESKey 24 | */ 25 | private String aesKey; 26 | 27 | public String getAppId() { 28 | return this.appId; 29 | } 30 | 31 | public void setAppId(String appId) { 32 | this.appId = appId; 33 | } 34 | 35 | public String getSecret() { 36 | return this.secret; 37 | } 38 | 39 | public void setSecret(String secret) { 40 | this.secret = secret; 41 | } 42 | 43 | public String getToken() { 44 | return this.token; 45 | } 46 | 47 | public void setToken(String token) { 48 | this.token = token; 49 | } 50 | 51 | public String getAesKey() { 52 | return this.aesKey; 53 | } 54 | 55 | public void setAesKey(String aesKey) { 56 | this.aesKey = aesKey; 57 | } 58 | 59 | 60 | } -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.controller; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.gizwits.bean.Contants; 5 | import com.gizwits.bean.PayloadBody; 6 | import com.gizwits.bean.ResponseMessage; 7 | import com.gizwits.noti2.client.NotiClient; 8 | import io.swagger.annotations.*; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.beans.factory.annotation.Value; 13 | import org.springframework.http.HttpStatus; 14 | import org.springframework.web.bind.annotation.*; 15 | import springfox.documentation.annotations.ApiIgnore; 16 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 17 | 18 | import javax.annotation.PostConstruct; 19 | import javax.servlet.http.HttpServletRequest; 20 | 21 | /** 22 | * Created by feel on 2017/7/12. 23 | */ 24 | @EnableSwagger2 25 | @RestController 26 | @Api(value = "api", description = "设备远程控制", tags = {"device"}) 27 | @RequestMapping(value = "/") 28 | public class IndexController { 29 | 30 | private static final Logger logger = LoggerFactory.getLogger(IndexController.class); 31 | 32 | @Autowired 33 | private NotiClient notiClient; 34 | @Value("${app.product_key}") 35 | private String product_key; 36 | 37 | @ApiIgnore//使用该注解忽略这个API 38 | @RequestMapping(value = "", method = RequestMethod.GET, produces = "application/json") 39 | @ResponseBody 40 | public ResponseMessage index(HttpServletRequest request) { 41 | 42 | return new ResponseMessage(Contants.SUCCESS_0, "欢迎使用设备日志采集系统,使用如下跳转链接", request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/logMonitor"); 43 | 44 | } 45 | 46 | 47 | /** 48 | * 49 | * { 50 | * "mac": "xxxx", 51 | * "did": "xxx", 52 | * "cmd": { 53 | * "LED_OnOff": false, 54 | * "LED_Color": "紫色", 55 | * "Motor_Speed": 0 56 | * } 57 | * } 58 | * 59 | * 60 | * @param cmd 61 | * @param request 62 | * @return 63 | */ 64 | @CrossOrigin 65 | @ApiOperation(value = "设备远程控制", notes = "测试接口详细描述") 66 | @RequestMapping(value = "/dev/control", method = RequestMethod.POST, produces = "application/json") 67 | @ResponseStatus(HttpStatus.OK) 68 | public ResponseMessage remoteControl(@ApiParam(name = "cmd", required = true, value = "控制设备命令指令 example : {\n" + 69 | " \"mac\": \"xx\",\n" + 70 | " \"did\": \"xx\",\n" + 71 | " \"cmd\": {\n" + 72 | " \"LED_OnOff\": false,\n" + 73 | " \"LED_Color\": \"紫色\",\n" + 74 | " \"Motor_Speed\": 1\n" + 75 | " }\n" + 76 | "} ") @RequestBody String cmd, HttpServletRequest request) { 77 | 78 | 79 | if (cmd != null) { 80 | 81 | PayloadBody map = JSONObject.parseObject(cmd, PayloadBody.class); 82 | 83 | if (!map.isEmpty()) { 84 | notiClient.sendControlMessage(product_key, map.getMac(), map.getDid(), map.getCmd()); 85 | 86 | return new ResponseMessage(Contants.SUCCESS_0, "success", request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/dev/control"); 87 | } 88 | 89 | } 90 | return new ResponseMessage(Contants.ERROR_0, "error", request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/dev/control"); 91 | 92 | 93 | } 94 | 95 | @PostConstruct 96 | public void listenLog() { 97 | 98 | 99 | Thread thread = new Thread(() -> { 100 | //订阅(接收)推送事件消息 101 | String messgae = null; 102 | while ((messgae = notiClient.reveiceMessgae()) != null) { 103 | logger.info("实时接收snoti消息:{}", messgae); 104 | } 105 | }); 106 | thread.setName("--listenLogThread--"); 107 | thread.start(); 108 | 109 | 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/controller/WeixinController.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.controller; 2 | 3 | import me.chanjar.weixin.mp.api.WxMpMessageRouter; 4 | import me.chanjar.weixin.mp.api.WxMpService; 5 | import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; 6 | import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; 7 | import org.apache.commons.lang3.StringUtils; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.web.bind.annotation.*; 12 | import springfox.documentation.annotations.ApiIgnore; 13 | 14 | /** 15 | * Created by feel on 2017/7/14. 16 | */ 17 | @ApiIgnore//使用该注解忽略这个API 18 | @RestController 19 | @RequestMapping(value = "/weixin/portal") 20 | public class WeixinController { 21 | 22 | private static final Logger logger = LoggerFactory.getLogger(WeixinController.class); 23 | 24 | @Autowired 25 | private WxMpService wxService; 26 | 27 | @Autowired 28 | private WxMpMessageRouter router; 29 | 30 | @GetMapping(produces = "text/plain;charset=utf-8") 31 | public String authGet( 32 | @RequestParam(name = "signature", 33 | required = false) String signature, 34 | @RequestParam(name = "timestamp", 35 | required = false) String timestamp, 36 | @RequestParam(name = "nonce", required = false) String nonce, 37 | @RequestParam(name = "echostr", required = false) String echostr) { 38 | 39 | this.logger.debug("\n接收到来自微信服务器的认证消息:[{}, {}, {}, {}]", signature, 40 | timestamp, nonce, echostr); 41 | 42 | if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) { 43 | throw new IllegalArgumentException("请求参数非法,请核实!"); 44 | } 45 | 46 | if (this.wxService.checkSignature(timestamp, nonce, signature)) { 47 | return echostr; 48 | } 49 | 50 | return "非法请求"; 51 | } 52 | 53 | @PostMapping(produces = "application/xml; charset=UTF-8") 54 | public String post(@RequestBody String requestBody, 55 | @RequestParam("signature") String signature, 56 | @RequestParam("timestamp") String timestamp, 57 | @RequestParam("nonce") String nonce, 58 | @RequestParam(name = "encrypt_type", 59 | required = false) String encType, 60 | @RequestParam(name = "msg_signature", 61 | required = false) String msgSignature) { 62 | 63 | 64 | this.logger.debug("\n接收微信请求:[signature=[{}], encType=[{}], msgSignature=[{}]," 65 | + " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ", 66 | signature, encType, msgSignature, timestamp, nonce, requestBody); 67 | 68 | 69 | if (!this.wxService.checkSignature(timestamp, nonce, signature)) { 70 | throw new IllegalArgumentException("非法请求,可能属于伪造的请求!"); 71 | } 72 | 73 | String out = null; 74 | if (encType == null) { 75 | // 明文传输的消息 76 | WxMpXmlMessage inMessage = WxMpXmlMessage.fromXml(requestBody); 77 | WxMpXmlOutMessage outMessage = this.route(inMessage); 78 | if (outMessage == null) { 79 | return ""; 80 | } 81 | 82 | out = outMessage.toXml(); 83 | } else if ("aes".equals(encType)) { 84 | // aes加密的消息 85 | WxMpXmlMessage inMessage = WxMpXmlMessage.fromEncryptedXml( 86 | requestBody, this.wxService.getWxMpConfigStorage(), timestamp, 87 | nonce, msgSignature); 88 | this.logger.debug("\n消息解密后内容为:\n{} ", inMessage.toString()); 89 | WxMpXmlOutMessage outMessage = this.route(inMessage); 90 | if (outMessage == null) { 91 | return ""; 92 | } 93 | 94 | out = outMessage.toEncryptedXml(this.wxService.getWxMpConfigStorage()); 95 | } 96 | 97 | this.logger.debug("\n组装回复信息:{}", out); 98 | 99 | return out; 100 | } 101 | 102 | private WxMpXmlOutMessage route(WxMpXmlMessage message) { 103 | try { 104 | logger.debug("message:{}", message); 105 | return this.router.route(message); 106 | } catch (Exception e) { 107 | this.logger.error(e.getMessage(), e); 108 | } 109 | 110 | return null; 111 | } 112 | 113 | 114 | } 115 | -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/controller/WsController.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.controller; 2 | 3 | import com.gizwits.bean.Contants; 4 | import com.gizwits.bean.ParticipantRepository; 5 | import com.gizwits.bean.ResponseMessage; 6 | import com.gizwits.tail.Tailer; 7 | import com.gizwits.tail.TailerListenerAdapter; 8 | import com.gizwits.util.LRUCache; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.beans.factory.annotation.Value; 13 | import org.springframework.context.event.EventListener; 14 | import org.springframework.messaging.simp.SimpMessageHeaderAccessor; 15 | import org.springframework.messaging.simp.SimpMessagingTemplate; 16 | import org.springframework.stereotype.Controller; 17 | import org.springframework.util.StringUtils; 18 | import org.springframework.web.bind.annotation.PathVariable; 19 | import org.springframework.web.bind.annotation.RequestMapping; 20 | import org.springframework.web.bind.annotation.RequestMethod; 21 | import org.springframework.web.bind.annotation.ResponseBody; 22 | import org.springframework.web.socket.messaging.SessionDisconnectEvent; 23 | import org.springframework.web.socket.messaging.SessionSubscribeEvent; 24 | import springfox.documentation.annotations.ApiIgnore; 25 | 26 | import javax.servlet.http.HttpServletRequest; 27 | import java.io.File; 28 | import java.util.*; 29 | 30 | /** 31 | * Created by feel on 2017/2/1. 32 | */ 33 | @ApiIgnore//使用该注解忽略这个API 34 | @Controller 35 | @RequestMapping(value = "/logMonitor") 36 | public class WsController { 37 | 38 | private static Logger logger = LoggerFactory.getLogger(WsController.class.getName()); 39 | @Value("${logMonitor.logpath}") 40 | private String logpath; 41 | @Autowired 42 | private SimpMessagingTemplate messagingTemplate; //注入SimpMessagingTemplate 用于点对点消息发送 43 | @Autowired 44 | private ParticipantRepository participantRepository; 45 | @Autowired 46 | private LRUCache lruCache; 47 | private Tailer tailer; 48 | private Thread thread; 49 | private static volatile boolean runFlag = true; 50 | 51 | /** 52 | * 参考:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html#websocket-fallback-sockjs-heartbeat 53 | * 相关的事件:SessionConnectEvent,SessionConnectedEvent,SessionSubscribeEvent,SessionUnsubscribeEvent,SessionDisconnectEvent 54 | * 55 | * @param event 56 | */ 57 | @EventListener 58 | private void handleSessionSubscribeEvent(SessionSubscribeEvent event) { 59 | 60 | SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(event.getMessage()); 61 | String username = headers.getUser().getName(); 62 | Map activeSessions = participantRepository.getActiveSessions(); 63 | if (!activeSessions.values().contains(username) || lruCache.isEmpty()) { 64 | tailFile(username); 65 | } else if (!activeSessions.keySet().contains(headers.getSessionId())) { 66 | 67 | lruCache.values().forEach(log -> { 68 | messagingTemplate.convertAndSendToUser(username, "/exchange/logMonitor", (String) log); 69 | }); 70 | } 71 | // We store the session as we need to be idempotent in the disconnect event processing 72 | participantRepository.add(headers.getSessionId(), username); 73 | 74 | } 75 | 76 | private void tailFile(final String userName) { 77 | if (runFlag) { 78 | File file = new File(logpath); 79 | String[] split = this.getClass().getPackage().getName().split("\\."); 80 | String filterName = split[0] + "." + split[1]; 81 | if (file.exists()) { 82 | tailer = new Tailer(file, new TailerListenerAdapter() { 83 | @Override 84 | public void handle(String line) { 85 | if (runFlag) { 86 | messagingTemplate.convertAndSendToUser(userName, "/exchange/logMonitor", line); 87 | } 88 | if (line.contains(filterName)) { 89 | lruCache.put(UUID.randomUUID().toString(), line); 90 | } 91 | } 92 | }, 500, true); 93 | thread = new Thread(tailer); 94 | thread.start(); 95 | } else { 96 | logger.error("file is not exists ,{}", file); 97 | } 98 | 99 | } 100 | } 101 | 102 | @EventListener 103 | private void handleSessionDisconnect(SessionDisconnectEvent event) { 104 | 105 | Optional.ofNullable(participantRepository.getParticipant(event.getSessionId())) 106 | .ifPresent(login -> { 107 | logger.info("连接断开:" + event.getUser().getName() + "。。。" + event.getSessionId()); 108 | 109 | participantRepository.removeParticipant(event.getSessionId()); 110 | 111 | if (participantRepository.getActiveSessions().isEmpty()) { 112 | this.stop(); 113 | } 114 | }); 115 | } 116 | 117 | @RequestMapping(value = "/status", method = RequestMethod.GET) 118 | @ResponseBody 119 | public ResponseMessage status(HttpServletRequest request) { 120 | 121 | String logMonitor = (String) request.getServletContext().getAttribute("logMonitor"); 122 | if (StringUtils.isEmpty(logMonitor)) { 123 | request.getServletContext().setAttribute("logMonitor", Contants.ACTIONS[0]); 124 | logMonitor = Contants.ACTIONS[0]; 125 | } 126 | return new ResponseMessage(Contants.SUCCESS_0, "日志系统嗅探状态:" + logMonitor, request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()); 127 | } 128 | 129 | @RequestMapping(value = "/set/{action}", method = RequestMethod.GET, produces = "application/json") 130 | @ResponseBody 131 | public ResponseMessage set(@PathVariable String action, HttpServletRequest request) { 132 | 133 | if (Arrays.asList(Contants.ACTIONS).contains(action)) { 134 | if (!StringUtils.isEmpty(action)) { 135 | request.getServletContext().setAttribute("logMonitor", action); 136 | } 137 | if (action.equalsIgnoreCase(Contants.ACTIONS[0])) { 138 | runFlag = true; 139 | Collection values = participantRepository.getActiveSessions().values(); 140 | 141 | if (!values.isEmpty()) { 142 | tailFile(values.stream().findFirst().get()); 143 | } 144 | 145 | return new ResponseMessage(Contants.SUCCESS_0, "日志系统嗅探开启成功", request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()); 146 | } else { 147 | runFlag = false; 148 | stop(); 149 | return new ResponseMessage(Contants.SUCCESS_0, "日志系统嗅探关闭成功", request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()); 150 | } 151 | } else { 152 | return new ResponseMessage(Contants.ERROR_0, "日志系统嗅探开启失败,非法参数", request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()); 153 | } 154 | 155 | } 156 | 157 | @RequestMapping("") 158 | public String index() { 159 | return "index"; 160 | } 161 | 162 | /** 163 | * 日志监听关闭 164 | */ 165 | private void stop() { 166 | if (tailer != null && thread.isAlive()) { 167 | tailer.stop(); 168 | thread.interrupt(); 169 | lruCache.clear(); 170 | } 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/handle/AbstractBuilder.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.handle; 2 | 3 | import me.chanjar.weixin.mp.api.WxMpService; 4 | import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; 5 | import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | public abstract class AbstractBuilder { 10 | protected final Logger logger = LoggerFactory.getLogger(getClass()); 11 | 12 | public abstract WxMpXmlOutMessage build(String content, 13 | WxMpXmlMessage wxMessage, WxMpService service); 14 | } -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/handle/AbstractHandler.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.handle; 2 | 3 | import com.gizwits.controller.IndexController; 4 | import me.chanjar.weixin.mp.api.WxMpMessageHandler; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | public abstract class AbstractHandler implements WxMpMessageHandler { 9 | protected Logger logger = LoggerFactory.getLogger(IndexController.class); 10 | } -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/handle/LocationHandler.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.handle; 2 | 3 | import me.chanjar.weixin.common.api.WxConsts; 4 | import me.chanjar.weixin.common.session.WxSessionManager; 5 | import me.chanjar.weixin.mp.api.WxMpService; 6 | import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; 7 | import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; 8 | import org.springframework.stereotype.Component; 9 | 10 | import java.util.Map; 11 | 12 | @Component 13 | public class LocationHandler extends AbstractHandler { 14 | 15 | @Override 16 | public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, 17 | Map context, WxMpService wxMpService, 18 | WxSessionManager sessionManager) { 19 | if (wxMessage.getMsgType().equals(WxConsts.XML_MSG_LOCATION)) { 20 | //TODO 接收处理用户发送的地理位置消息 21 | try { 22 | String content = "感谢反馈,您的的地理位置已收到!"; 23 | return new TextBuilder().build(content, wxMessage, null); 24 | } catch (Exception e) { 25 | this.logger.error("位置消息接收处理失败", e); 26 | return null; 27 | } 28 | } 29 | 30 | //上报地理位置事件 31 | this.logger.info("\n上报地理位置 。。。 "); 32 | this.logger.info("\n纬度 : " + wxMessage.getLatitude()); 33 | this.logger.info("\n经度 : " + wxMessage.getLongitude()); 34 | this.logger.info("\n精度 : " + String.valueOf(wxMessage.getPrecision())); 35 | 36 | //TODO 可以将用户地理位置信息保存到本地数据库,以便以后使用 37 | 38 | return null; 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/handle/LogHandler.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.handle; 2 | 3 | import me.chanjar.weixin.common.session.WxSessionManager; 4 | import me.chanjar.weixin.mp.api.WxMpService; 5 | import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; 6 | import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; 7 | import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; 8 | import org.springframework.stereotype.Component; 9 | 10 | import java.util.Map; 11 | 12 | @Component 13 | public class LogHandler extends AbstractHandler { 14 | @Override 15 | public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, 16 | Map context, WxMpService wxMpService, 17 | WxSessionManager sessionManager) { 18 | this.logger.debug("\n接收到请求消息,内容:{}", WxMpGsonBuilder.create().toJson(wxMessage)); 19 | return null; 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/handle/MsgHandler.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.handle; 2 | 3 | import com.alibaba.fastjson.JSONArray; 4 | import com.alibaba.fastjson.JSONObject; 5 | import com.gizwits.analyse.HttpSemantic; 6 | import com.gizwits.bean.DeviceInfo; 7 | import com.gizwits.bean.RequestVoiceText; 8 | import com.gizwits.noti2.client.NotiClient; 9 | import me.chanjar.weixin.common.api.WxConsts; 10 | import me.chanjar.weixin.common.exception.WxErrorException; 11 | import me.chanjar.weixin.common.session.WxSessionManager; 12 | import me.chanjar.weixin.mp.api.WxMpService; 13 | import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; 14 | import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; 15 | import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; 16 | import org.apache.commons.lang3.StringUtils; 17 | import org.springframework.beans.factory.annotation.Autowired; 18 | import org.springframework.beans.factory.annotation.Value; 19 | import org.springframework.stereotype.Component; 20 | 21 | import java.util.Arrays; 22 | import java.util.Map; 23 | 24 | @Component 25 | public class MsgHandler extends AbstractHandler { 26 | 27 | @Autowired 28 | private HttpSemantic httpSemantic; 29 | @Autowired 30 | private NotiClient notiClient; 31 | @Value("${app.product_key}") 32 | private String product_key; 33 | @Value("${app.did}") 34 | private String did; 35 | @Value("${app.mac}") 36 | private String mac; 37 | 38 | @Override 39 | public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, 40 | Map context, WxMpService weixinService, 41 | WxSessionManager sessionManager) { 42 | 43 | if (!wxMessage.getMsgType().equals(WxConsts.XML_MSG_EVENT)) { 44 | //TODO 可以选择将消息保存到本地 45 | } 46 | 47 | //当用户输入关键词如“你好”,“客服”等,并且有客服在线时,把消息转发给在线客服 48 | try { 49 | if (StringUtils.startsWithAny(wxMessage.getContent(), "你好", "客服") 50 | && weixinService.getKefuService().kfOnlineList() 51 | .getKfOnlineList().size() > 0) { 52 | return WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE() 53 | .fromUser(wxMessage.getToUser()) 54 | .toUser(wxMessage.getFromUser()).build(); 55 | } 56 | } catch (WxErrorException e) { 57 | e.printStackTrace(); 58 | } 59 | 60 | String content = ""; 61 | //TODO 组装回复消息 62 | if (wxMessage.getMsgType().equals(WxConsts.XML_MSG_VOICE)) { 63 | content = wxMessage.getRecognition(); 64 | } else if (wxMessage.getMsgType().equals(WxConsts.XML_MSG_TEXT)) { 65 | content = wxMessage.getContent(); 66 | } else { 67 | 68 | content = WxMpGsonBuilder.create().toJson(wxMessage); 69 | } 70 | 71 | 72 | if (StringUtils.isNotEmpty(content)) { 73 | 74 | 75 | try { 76 | 77 | RequestVoiceText requestVoiceText = new RequestVoiceText(); 78 | 79 | requestVoiceText.setText(content); 80 | DeviceInfo deviceInfo = new DeviceInfo(); 81 | 82 | deviceInfo.setPk(product_key); 83 | deviceInfo.setDid(did); 84 | requestVoiceText.setDevices(Arrays.asList(deviceInfo)); 85 | 86 | 87 | String voiceSemantic = httpSemantic.getVoiceSemantic(requestVoiceText); 88 | 89 | if (StringUtils.isNotEmpty(voiceSemantic)) { 90 | 91 | 92 | JSONObject jsonObject = JSONObject.parseObject(voiceSemantic); 93 | 94 | JSONArray object = jsonObject.getJSONArray("object"); 95 | 96 | if (!object.isEmpty()) { 97 | 98 | Map cmd = object.getJSONObject(0).getObject("attr", Map.class); 99 | 100 | notiClient.sendControlMessage(product_key, mac, did, cmd); 101 | } 102 | 103 | return new TextBuilder().build(jsonObject.getString("reply_text"), wxMessage, weixinService); 104 | } 105 | } catch (Exception e) { 106 | logger.error("{}", e); 107 | } 108 | } 109 | 110 | return new TextBuilder().build("没听懂你说什么", wxMessage, weixinService); 111 | 112 | 113 | } 114 | 115 | } -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/handle/TextBuilder.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.handle; 2 | 3 | import me.chanjar.weixin.mp.api.WxMpService; 4 | import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; 5 | import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; 6 | import me.chanjar.weixin.mp.bean.message.WxMpXmlOutTextMessage; 7 | 8 | public class TextBuilder extends AbstractBuilder { 9 | 10 | @Override 11 | public WxMpXmlOutMessage build(String content, WxMpXmlMessage wxMessage, 12 | WxMpService service) { 13 | WxMpXmlOutTextMessage m = WxMpXmlOutMessage.TEXT().content(content) 14 | .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()) 15 | .build(); 16 | return m; 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/main/App.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.main; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; 8 | import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; 9 | import org.springframework.boot.web.servlet.ErrorPage; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.http.HttpStatus; 12 | 13 | /** 14 | * Created by feel on 2017/2/1. 15 | */ 16 | @SpringBootApplication(scanBasePackages = {"com.gizwits"}) 17 | public class App { 18 | 19 | 20 | private static final Logger logger = LoggerFactory.getLogger(App.class); 21 | 22 | /** 23 | * 错误页面需要放在Spring Boot web应用的static内容目录下, 24 | * 它的默认位置是:src/main/resources/static 25 | * 26 | * @return 27 | */ 28 | @Bean 29 | public EmbeddedServletContainerCustomizer containerCustomizer() { 30 | 31 | return new EmbeddedServletContainerCustomizer() { 32 | @Override 33 | public void customize(ConfigurableEmbeddedServletContainer container) { 34 | 35 | ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/"); 36 | ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/"); 37 | ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/"); 38 | ErrorPage error405Page = new ErrorPage(HttpStatus.METHOD_NOT_ALLOWED, "/"); 39 | 40 | container.addErrorPages(error401Page, error404Page, error500Page, error405Page); 41 | } 42 | }; 43 | } 44 | 45 | public static void main(String[] args) throws InterruptedException { 46 | 47 | SpringApplication.run(App.class, args); 48 | 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/tail/Tailer.java: -------------------------------------------------------------------------------- 1 | 2 | package com.gizwits.tail; 3 | 4 | import org.apache.commons.io.FileUtils; 5 | import org.apache.commons.io.IOUtils; 6 | 7 | import java.io.*; 8 | import java.nio.charset.Charset; 9 | import java.util.ArrayList; 10 | import java.util.Collections; 11 | import java.util.List; 12 | 13 | import static org.apache.commons.io.IOUtils.EOF; 14 | 15 | 16 | public class Tailer implements Runnable { 17 | 18 | private static final int DEFAULT_DELAY_MILLIS = 1000; 19 | 20 | private static final String RAF_MODE = "r"; 21 | 22 | private static final int DEFAULT_BUFSIZE = 4096; 23 | 24 | // The default charset used for reading files 25 | private static final Charset DEFAULT_CHARSET = Charset.defaultCharset(); 26 | 27 | /** 28 | * Buffer on top of RandomAccessFile. 29 | */ 30 | private final byte inbuf[]; 31 | 32 | /** 33 | * The file which will be tailed. 34 | */ 35 | private final File file; 36 | 37 | /** 38 | * The character set that will be used to read the file. 39 | */ 40 | private final Charset cset; 41 | 42 | /** 43 | * The amount of time to wait for the file to be updated. 44 | */ 45 | private final long delayMillis; 46 | 47 | /** 48 | * Whether to tail from the end or start of file,d 49 | */ 50 | private final boolean end; 51 | 52 | /** 53 | * The listener to notify of events when tailing. 54 | */ 55 | private final TailerListener listener; 56 | 57 | /** 58 | * Whether to close and reopen the file whilst waiting for more input. 59 | */ 60 | private final boolean reOpen; 61 | 62 | /** 63 | * The Tailer will run as long as this value is true. 64 | */ 65 | private volatile boolean run = true; 66 | 67 | /** 68 | * 如果 从尾部开始读取文件,默认输出最后200行 69 | */ 70 | private final static int numLine = 200; 71 | 72 | /** 73 | * Creates a Tailer for the given file, starting from the beginning, with the default delay of 1.0s. 74 | * 75 | * @param file The file to follow. 76 | * @param listener the TailerListener to use. 77 | */ 78 | public Tailer(final File file, final TailerListener listener) { 79 | this(file, listener, DEFAULT_DELAY_MILLIS); 80 | } 81 | 82 | /** 83 | * Creates a Tailer for the given file, starting from the beginning. 84 | * 85 | * @param file the file to follow. 86 | * @param listener the TailerListener to use. 87 | * @param delayMillis the delay between checks of the file for new content in milliseconds. 88 | */ 89 | public Tailer(final File file, final TailerListener listener, final long delayMillis) { 90 | this(file, listener, delayMillis, false); 91 | } 92 | 93 | /** 94 | * Creates a Tailer for the given file, with a delay other than the default 1.0s. 95 | * 96 | * @param file the file to follow. 97 | * @param listener the TailerListener to use. 98 | * @param delayMillis the delay between checks of the file for new content in milliseconds. 99 | * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. 100 | */ 101 | public Tailer(final File file, final TailerListener listener, final long delayMillis, final boolean end) { 102 | this(file, listener, delayMillis, end, DEFAULT_BUFSIZE); 103 | } 104 | 105 | /** 106 | * Creates a Tailer for the given file, with a delay other than the default 1.0s. 107 | * 108 | * @param file the file to follow. 109 | * @param listener the TailerListener to use. 110 | * @param delayMillis the delay between checks of the file for new content in milliseconds. 111 | * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. 112 | * @param reOpen if true, close and reopen the file between reading chunks 113 | */ 114 | public Tailer(final File file, final TailerListener listener, final long delayMillis, final boolean end, 115 | final boolean reOpen) { 116 | this(file, listener, delayMillis, end, reOpen, DEFAULT_BUFSIZE); 117 | } 118 | 119 | /** 120 | * Creates a Tailer for the given file, with a specified buffer size. 121 | * 122 | * @param file the file to follow. 123 | * @param listener the TailerListener to use. 124 | * @param delayMillis the delay between checks of the file for new content in milliseconds. 125 | * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. 126 | * @param bufSize Buffer size 127 | */ 128 | public Tailer(final File file, final TailerListener listener, final long delayMillis, final boolean end, 129 | final int bufSize) { 130 | this(file, listener, delayMillis, end, false, bufSize); 131 | } 132 | 133 | /** 134 | * Creates a Tailer for the given file, with a specified buffer size. 135 | * 136 | * @param file the file to follow. 137 | * @param listener the TailerListener to use. 138 | * @param delayMillis the delay between checks of the file for new content in milliseconds. 139 | * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. 140 | * @param reOpen if true, close and reopen the file between reading chunks 141 | * @param bufSize Buffer size 142 | */ 143 | public Tailer(final File file, final TailerListener listener, final long delayMillis, final boolean end, 144 | final boolean reOpen, final int bufSize) { 145 | this(file, DEFAULT_CHARSET, listener, delayMillis, end, reOpen, bufSize); 146 | } 147 | 148 | /** 149 | * Creates a Tailer for the given file, with a specified buffer size. 150 | * 151 | * @param file the file to follow. 152 | * @param cset the Charset to be used for reading the file 153 | * @param listener the TailerListener to use. 154 | * @param delayMillis the delay between checks of the file for new content in milliseconds. 155 | * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. 156 | * @param reOpen if true, close and reopen the file between reading chunks 157 | * @param bufSize Buffer size 158 | */ 159 | public Tailer(final File file, final Charset cset, final TailerListener listener, final long delayMillis, 160 | final boolean end, final boolean reOpen 161 | , final int bufSize) { 162 | this.file = file; 163 | this.delayMillis = delayMillis; 164 | this.end = end; 165 | this.inbuf = new byte[bufSize]; 166 | 167 | // Save and prepare the listener 168 | this.listener = listener; 169 | listener.init(this); 170 | this.reOpen = reOpen; 171 | this.cset = cset; 172 | } 173 | 174 | /** 175 | * Creates and starts a Tailer for the given file. 176 | * 177 | * @param file the file to follow. 178 | * @param listener the TailerListener to use. 179 | * @param delayMillis the delay between checks of the file for new content in milliseconds. 180 | * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. 181 | * @param bufSize buffer size. 182 | * @return The new Tailer 183 | */ 184 | public static Tailer create(final File file, final TailerListener listener, final long delayMillis, 185 | final boolean end, final int bufSize) { 186 | return create(file, listener, delayMillis, end, false, bufSize); 187 | } 188 | 189 | /** 190 | * Creates and starts a Tailer for the given file. 191 | * 192 | * @param file the file to follow. 193 | * @param listener the TailerListener to use. 194 | * @param delayMillis the delay between checks of the file for new content in milliseconds. 195 | * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. 196 | * @param reOpen whether to close/reopen the file between chunks 197 | * @param bufSize buffer size. 198 | * @return The new Tailer 199 | */ 200 | public static Tailer create(final File file, final TailerListener listener, final long delayMillis, 201 | final boolean end, final boolean reOpen, 202 | final int bufSize) { 203 | return create(file, DEFAULT_CHARSET, listener, delayMillis, end, reOpen, bufSize); 204 | } 205 | 206 | /** 207 | * Creates and starts a Tailer for the given file. 208 | * 209 | * @param file the file to follow. 210 | * @param charset the character set to use for reading the file 211 | * @param listener the TailerListener to use. 212 | * @param delayMillis the delay between checks of the file for new content in milliseconds. 213 | * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. 214 | * @param reOpen whether to close/reopen the file between chunks 215 | * @param bufSize buffer size. 216 | * @return The new Tailer 217 | */ 218 | public static Tailer create(final File file, final Charset charset, final TailerListener listener, 219 | final long delayMillis, final boolean end, final boolean reOpen 220 | , final int bufSize) { 221 | final Tailer Tailer = new Tailer(file, charset, listener, delayMillis, end, reOpen, bufSize); 222 | final Thread thread = new Thread(Tailer); 223 | thread.setDaemon(true); 224 | thread.start(); 225 | return Tailer; 226 | } 227 | 228 | /** 229 | * Creates and starts a Tailer for the given file with default buffer size. 230 | * 231 | * @param file the file to follow. 232 | * @param listener the TailerListener to use. 233 | * @param delayMillis the delay between checks of the file for new content in milliseconds. 234 | * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. 235 | * @return The new Tailer 236 | */ 237 | public static Tailer create(final File file, final TailerListener listener, final long delayMillis, 238 | final boolean end) { 239 | return create(file, listener, delayMillis, end, DEFAULT_BUFSIZE); 240 | } 241 | 242 | /** 243 | * Creates and starts a Tailer for the given file with default buffer size. 244 | * 245 | * @param file the file to follow. 246 | * @param listener the TailerListener to use. 247 | * @param delayMillis the delay between checks of the file for new content in milliseconds. 248 | * @param end Set to true to tail from the end of the file, false to tail from the beginning of the file. 249 | * @param reOpen whether to close/reopen the file between chunks 250 | * @return The new Tailer 251 | */ 252 | public static Tailer create(final File file, final TailerListener listener, final long delayMillis, 253 | final boolean end, final boolean reOpen) { 254 | return create(file, listener, delayMillis, end, reOpen, DEFAULT_BUFSIZE); 255 | } 256 | 257 | /** 258 | * Creates and starts a Tailer for the given file, starting at the beginning of the file 259 | * 260 | * @param file the file to follow. 261 | * @param listener the TailerListener to use. 262 | * @param delayMillis the delay between checks of the file for new content in milliseconds. 263 | * @return The new Tailer 264 | */ 265 | public static Tailer create(final File file, final TailerListener listener, final long delayMillis) { 266 | return create(file, listener, delayMillis, false); 267 | } 268 | 269 | /** 270 | * Creates and starts a Tailer for the given file, starting at the beginning of the file 271 | * with the default delay of 1.0s 272 | * 273 | * @param file the file to follow. 274 | * @param listener the TailerListener to use. 275 | * @return The new Tailer 276 | */ 277 | public static Tailer create(final File file, final TailerListener listener) { 278 | return create(file, listener, DEFAULT_DELAY_MILLIS, false); 279 | } 280 | 281 | /** 282 | * Return the file. 283 | * 284 | * @return the file 285 | */ 286 | public File getFile() { 287 | return file; 288 | } 289 | 290 | /** 291 | * Gets whether to keep on running. 292 | * 293 | * @return whether to keep on running. 294 | * @since 2.5 295 | */ 296 | protected boolean getRun() { 297 | return run; 298 | } 299 | 300 | /** 301 | * Return the delay in milliseconds. 302 | * 303 | * @return the delay in milliseconds. 304 | */ 305 | public long getDelay() { 306 | return delayMillis; 307 | } 308 | 309 | /** 310 | * Follows changes in the file, calling the TailerListener's handle method for each new line. 311 | */ 312 | public void run() { 313 | RandomAccessFile reader = null; 314 | try { 315 | 316 | long last = 0; // The last time the file was checked for changes 317 | long position = 0; // position within the file 318 | // 从最后开始监听输出 319 | if (end) { 320 | readLastNLine(numLine).forEach(line -> listener.handle(line)); 321 | } 322 | 323 | while (getRun() && reader == null) { 324 | try { 325 | reader = new RandomAccessFile(file, RAF_MODE); 326 | } catch (final FileNotFoundException e) { 327 | listener.fileNotFound(); 328 | } 329 | if (reader == null) { 330 | Thread.sleep(delayMillis); 331 | } else { 332 | // The current position in the file,判断是否需要重头开始读取 333 | position = end ? file.length() : 0; 334 | last = file.lastModified(); 335 | reader.seek(position); 336 | } 337 | } 338 | while (getRun()) { 339 | final boolean newer = FileUtils.isFileNewer(file, last); // IO-279, must be done first 340 | // Check the file length to see if it was rotated 341 | final long length = file.length(); 342 | if (length < position) { 343 | // File was rotated 344 | listener.fileRotated(); 345 | // Reopen the reader after rotation 346 | try { 347 | // Ensure that the old file is closed iff we re-open it successfully 348 | final RandomAccessFile save = reader; 349 | reader = new RandomAccessFile(file, RAF_MODE); 350 | // At this point, we're sure that the old file is rotated 351 | // Finish scanning the old file and then we'll start with the new one 352 | try { 353 | readLines(save); 354 | } catch (IOException ioe) { 355 | listener.handle(ioe); 356 | } 357 | position = 0; 358 | // close old file explicitly rather than relying on GC picking up previous RAF 359 | IOUtils.closeQuietly(save); 360 | } catch (final FileNotFoundException e) { 361 | // in this case we continue to use the previous reader and position values 362 | listener.fileNotFound(); 363 | } 364 | continue; 365 | } else { 366 | // File was not rotated 367 | // See if the file needs to be read again 368 | if (length > position) { 369 | // The file has more content than it did last time 370 | position = readLines(reader); 371 | last = file.lastModified(); 372 | } else if (newer) { 373 | /* 374 | * This can happen if the file is truncated or overwritten with the exact same length of 375 | * information. In cases like this, the file position needs to be reset 376 | */ 377 | position = 0; 378 | reader.seek(position); // cannot be null here 379 | 380 | // Now we can read new lines 381 | position = readLines(reader); 382 | last = file.lastModified(); 383 | } 384 | } 385 | if (reOpen) { 386 | IOUtils.closeQuietly(reader); 387 | } 388 | Thread.sleep(delayMillis); 389 | if (getRun() && reOpen) { 390 | reader = new RandomAccessFile(file, RAF_MODE); 391 | reader.seek(position); 392 | } 393 | } 394 | } catch (final InterruptedException e) { 395 | Thread.currentThread().interrupt(); 396 | stop(e); 397 | } catch (final Exception e) { 398 | stop(e); 399 | } finally { 400 | IOUtils.closeQuietly(reader); 401 | } 402 | } 403 | 404 | /** 405 | * Stops the Tailer with an exception 406 | * 407 | * @param e The exception to send to listener 408 | */ 409 | private void stop(final Exception e) { 410 | listener.handle(e); 411 | stop(); 412 | } 413 | 414 | /** 415 | * Allows the Tailer to complete its current loop and return. 416 | */ 417 | public void stop() { 418 | this.run = false; 419 | } 420 | 421 | 422 | /** 423 | * Read new lines. 424 | * 425 | * @param reader The file to read 426 | * @return The new position after the lines have been read 427 | * @throws IOException if an I/O error occurs. 428 | */ 429 | private long readLines(final RandomAccessFile reader) throws IOException { 430 | ByteArrayOutputStream lineBuf = new ByteArrayOutputStream(64); 431 | long pos = reader.getFilePointer(); 432 | long rePos = pos; // position to re-read 433 | int num; 434 | boolean seenCR = false; 435 | while (getRun() && ((num = reader.read(inbuf)) != EOF)) { 436 | for (int i = 0; i < num; i++) { 437 | final byte ch = inbuf[i]; 438 | switch (ch) { 439 | case '\n': 440 | seenCR = false; // swallow CR before LF 441 | listener.handle(new String(lineBuf.toByteArray(), cset)); 442 | lineBuf.reset(); 443 | rePos = pos + i + 1; 444 | break; 445 | case '\r': 446 | if (seenCR) { 447 | lineBuf.write('\r'); 448 | } 449 | seenCR = true; 450 | break; 451 | default: 452 | if (seenCR) { 453 | seenCR = false; // swallow final CR 454 | listener.handle(new String(lineBuf.toByteArray(), cset)); 455 | lineBuf.reset(); 456 | rePos = pos + i + 1; 457 | } 458 | lineBuf.write(ch); 459 | } 460 | } 461 | pos = reader.getFilePointer(); 462 | } 463 | IOUtils.closeQuietly(lineBuf); // not strictly necessary 464 | reader.seek(rePos); // Ensure we can re-read if necessary 465 | 466 | if (listener instanceof TailerListenerAdapter) { 467 | ((TailerListenerAdapter) listener).endOfFileReached(); 468 | } 469 | 470 | return rePos; 471 | } 472 | 473 | /** 474 | * 读取文件最后N行 475 | * 476 | * @param numRead 477 | * @return 478 | */ 479 | public List readLastNLine(long numRead) { 480 | // 定义结果集 481 | List result = new ArrayList(); 482 | //行数统计 483 | long count = 0; 484 | // 使用随机读取 485 | RandomAccessFile reader = null; 486 | try { 487 | //使用读模式 488 | reader = new RandomAccessFile(file, RAF_MODE); 489 | //读取文件长度 490 | long length = reader.length(); 491 | //如果是0,代表是空文件,直接返回空结果 492 | if (length == 0L) { 493 | return result; 494 | } else { 495 | //初始化游标 496 | long pos = length - 1; 497 | while (pos > 0) { 498 | pos--; 499 | //开始读取 500 | reader.seek(pos); 501 | //如果读取到\n代表是读取到一行 502 | if (reader.readByte() == '\n') { 503 | //使用readLine获取当前行,ISO-8859-1,解决中文乱码的问题 504 | String line = new String(reader.readLine().getBytes("ISO-8859-1"), cset); 505 | //保存结果 506 | result.add(line); 507 | //行数统计,如果到达了numRead指定的行数,就跳出循环 508 | count++; 509 | if (count == numRead) { 510 | break; 511 | } 512 | } 513 | } 514 | if (pos == 0) { 515 | reader.seek(0); 516 | result.add(reader.readLine()); 517 | } 518 | } 519 | } catch (IOException e) { 520 | IOUtils.closeQuietly(reader); 521 | e.printStackTrace(); 522 | } finally { 523 | IOUtils.closeQuietly(reader); 524 | } 525 | // 倒序 526 | Collections.reverse(result); 527 | return result; 528 | } 529 | 530 | 531 | } 532 | -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/tail/TailerListener.java: -------------------------------------------------------------------------------- 1 | 2 | package com.gizwits.tail; 3 | 4 | public interface TailerListener { 5 | 6 | /** 7 | * The tailer will call this method during construction, 8 | * giving the listener a method of stopping the tailer. 9 | * 10 | * @param tailer the tailer. 11 | */ 12 | void init(Tailer tailer); 13 | 14 | /** 15 | * This method is called if the tailed file is not found. 16 | *

17 | * Note: this is called from the tailer thread. 18 | */ 19 | void fileNotFound(); 20 | 21 | /** 22 | * Called if a file rotation is detected. 23 | *

24 | * This method is called before the file is reopened, and fileNotFound may 25 | * be called if the new file has not yet been created. 26 | *

27 | * Note: this is called from the tailer thread. 28 | */ 29 | void fileRotated(); 30 | 31 | /** 32 | * Handles a line from a Tailer. 33 | *

34 | * Note: this is called from the tailer thread. 35 | * 36 | * @param line the line. 37 | */ 38 | void handle(String line); 39 | 40 | /** 41 | * Handles an Exception . 42 | *

43 | * Note: this is called from the tailer thread. 44 | * 45 | * @param ex the exception. 46 | */ 47 | void handle(Exception ex); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/tail/TailerListenerAdapter.java: -------------------------------------------------------------------------------- 1 | 2 | package com.gizwits.tail; 3 | 4 | 5 | public class TailerListenerAdapter implements TailerListener { 6 | 7 | /** 8 | * The tailer will call this method during construction, 9 | * giving the listener a method of stopping the tailer. 10 | * 11 | * @param tailer the tailer. 12 | */ 13 | public void init(final Tailer tailer) { 14 | } 15 | 16 | /** 17 | * This method is called if the tailed file is not found. 18 | */ 19 | public void fileNotFound() { 20 | } 21 | 22 | /** 23 | * Called if a file rotation is detected. 24 | *

25 | * This method is called before the file is reopened, and fileNotFound may 26 | * be called if the new file has not yet been created. 27 | */ 28 | public void fileRotated() { 29 | } 30 | 31 | /** 32 | * Handles a line from a Tailer. 33 | * 34 | * @param line the line. 35 | */ 36 | public void handle(final String line) { 37 | } 38 | 39 | /** 40 | * Handles an Exception . 41 | * 42 | * @param ex the exception. 43 | */ 44 | public void handle(final Exception ex) { 45 | } 46 | 47 | /** 48 | * Called each time the Tailer reaches the end of the file. 49 | *

50 | * Note: this is called from the tailer thread. 51 | *

52 | * Note: a future version of commons-io will pull this method up to the TailerListener interface, 53 | * for now clients must subclass this class to use this feature. 54 | * 55 | * @since 2.5 56 | */ 57 | public void endOfFileReached() { 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /log-collection/src/main/java/com/gizwits/util/LRUCache.java: -------------------------------------------------------------------------------- 1 | package com.gizwits.util; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * Created by feel on 2017/1/17. 8 | * A cache implementing a least recently used policy. 9 | * 最频繁访问驻留缓存算法 LinkedHashMap,内部已经帮我们实现了该算法 10 | * sun.misc.LRUCache 11 | * py4j.reflection.LRUCache 12 | * org.apache.kafka.common.cache.LRUCache 13 | * ch.qos.logback.classic.turbo.LRUMessageCache 14 | */ 15 | public class LRUCache extends LinkedHashMap { 16 | 17 | private int cacheSize; 18 | 19 | /** 20 | * true代表使用访问顺序 21 | * 22 | * @param cacheSize 23 | */ 24 | public LRUCache(int cacheSize) { 25 | super(16, 0.75f, true); 26 | this.cacheSize = cacheSize; 27 | } 28 | 29 | protected boolean removeEldestEntry(Map.Entry eldest) { 30 | return size() >= cacheSize; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /log-collection/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8080 2 | security.user.name=admin 3 | security.user.password=123 4 | security.user.role=USER 5 | security.basic.authorize-mode=authenticated 6 | security.enable-csrf=false 7 | app.product_key=xx 8 | app.did=xx 9 | app.mac=xx 10 | app.auth_id=xx 11 | app.auth_secret=xx 12 | app.subkey=client 13 | app.prefetch_count=50 14 | wechat.mp.appId=xx 15 | wechat.mp.secret=xx 16 | wechat.mp.token=weixin 17 | wechat.mp.aesKey=xx 18 | semantic.api=http://nlp 19 | logMonitor.logpath=log-collection.log -------------------------------------------------------------------------------- /log-collection/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | _ 2 | _______| | 3 | |_________| 4 | _________ 5 | | _______| 万物互联 6 | | | ____ 7 | | | |__ | 机智云 8 | | |_____| | 9 | |_________| Gizwits 10 | 机智云只为硬件而生的云服务 11 | 12 | -------------------------------------------------------------------------------- /log-collection/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | [%level] %d{yyyy/MM/dd-HH:mm:ss} [%thread] TTL=%r %logger{36} [%c : %line] - %msg%n 11 | 12 | 13 | 14 | 15 | 17 | 18 | log-collection.log 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | log-collection.%i.log.zip 27 | 1 28 | 30 29 | 30 | 31 | 32 | 10MB 33 | 34 | 35 | 36 | [%level] %d{yyyy/MM/dd-HH:mm:ss} [%thread] TTL=%r %logger{36} [%c : %line] - %msg%n 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /log-collection/src/main/resources/static/css/main.css: -------------------------------------------------------------------------------- 1 | 2 | .iconfont { 3 | font-family: "iconfont" !important; 4 | speak: none; 5 | font-style: normal; 6 | font-weight: normal; 7 | font-variant: normal; 8 | text-transform: none; 9 | -webkit-font-smoothing: antialiased; 10 | -moz-osx-font-smoothing: grayscale 11 | } 12 | 13 | html { 14 | height: 100% 15 | } 16 | 17 | body { 18 | height: 100%; 19 | font-family: 'noto-thin' 20 | } 21 | 22 | body #main { 23 | height: 100% 24 | } 25 | 26 | body h2, body h3 { 27 | font-family: 'noto-light' 28 | } 29 | 30 | #lowie-main { 31 | display: none 32 | } 33 | 34 | .lower-ie #main { 35 | display: none 36 | } 37 | 38 | .lower-ie #lowie-main { 39 | display: block; 40 | height: 100%; 41 | width: 100%; 42 | padding: 200px 0 100px; 43 | background-color: #2a3c54 44 | } 45 | 46 | .lower-ie #lowie-main img { 47 | display: block; 48 | width: 60%; 49 | margin: 0 auto 50 | } 51 | 52 | .navbar-default { 53 | border: none; 54 | background-color: #293c55; 55 | z-index: 13; 56 | -webkit-transition: background-color 0.5s linear; 57 | transition: background-color 0.5s linear 58 | } 59 | 60 | .navbar-default .navbar-nav { 61 | margin: 0 -15px; 62 | -webkit-transition: background-color 0.5s linear; 63 | transition: background-color 0.5s linear 64 | } 65 | 66 | .navbar-default .navbar-nav li { 67 | position: relative 68 | } 69 | 70 | .navbar-default .navbar-nav li a { 71 | color: #eee; 72 | background-color: none !important 73 | } 74 | 75 | .navbar-default .navbar-nav li a:hover, .navbar-default .navbar-nav li a:focus { 76 | color: #f9f9f9; 77 | background-color: #162436 78 | } 79 | 80 | .navbar-default .navbar-nav li a .iconfont { 81 | font-size: 12px 82 | } 83 | 84 | .navbar-default .navbar-nav li.open { 85 | background-color: #162436; 86 | color: #fff 87 | } 88 | 89 | .navbar-default .navbar-nav li.open > 90 | a:focus, .navbar-default .navbar-nav li.open > 91 | a:hover { 92 | color: #eee; 93 | background-color: #162436 94 | } 95 | 96 | .navbar-default .navbar-nav li.active > 97 | a { 98 | padding-top: 11px; 99 | border-top: 4px solid #a9334c; 100 | color: #fff; 101 | background-color: transparent; 102 | font-family: noto-light 103 | } 104 | 105 | .navbar-default .navbar-nav li.active > 106 | a:hover, .navbar-default .navbar-nav li.active > 107 | a:focus { 108 | color: #f9f9f9; 109 | background-color: #162436 110 | } 111 | 112 | .navbar-default .navbar-nav li .dropdown-menu { 113 | width: 100%; 114 | padding: 0; 115 | background-color: #162436; 116 | -webkit-box-shadow: none; 117 | box-shadow: none; 118 | border: none 119 | } 120 | 121 | .navbar-default .navbar-nav li .dropdown-menu li { 122 | background-color: #162436; 123 | border-top: none; 124 | padding: 5px 0 125 | } 126 | 127 | .navbar-default .navbar-nav li .dropdown-menu li:hover, .navbar-default .navbar-nav li .dropdown-menu li:focus { 128 | background-color: #a9334c 129 | } 130 | 131 | .navbar-default .navbar-nav li .dropdown-menu li:hover a, .navbar-default .navbar-nav li .dropdown-menu li:focus a { 132 | background-color: #a9334c 133 | } 134 | 135 | .navbar-default .navbar-logo { 136 | height: 32px; 137 | margin-top: -6px; 138 | margin-left: -2px 139 | } 140 | 141 | .navbar-default .navbar-collapse { 142 | border-top: none 143 | } 144 | 145 | .navbar-default .navbar-toggle { 146 | padding: 1px 5px; 147 | margin: 7px 16px 0 0; 148 | border-color: #384E6B; 149 | background-color: #384E6B 150 | } 151 | 152 | .navbar-default .navbar-toggle .icon-bar { 153 | margin: 7px 0 !important; 154 | height: 1px; 155 | background-color: #fff 156 | } 157 | 158 | .navbar-default .navbar-toggle:hover, .navbar-default .navbar-toggle:focus { 159 | border-color: #384E6B; 160 | background-color: #384E6B 161 | } 162 | 163 | #menu-btn { 164 | display: none; 165 | float: right; 166 | height: 45px; 167 | line-height: 45px; 168 | margin: 5px 20px 0 0; 169 | font-size: 30px; 170 | color: #fff; 171 | cursor: pointer 172 | } 173 | 174 | .navbar-bg { 175 | background-color: transparent 176 | } 177 | 178 | .navbar-bg .navbar-nav li a { 179 | color: #fff 180 | } 181 | 182 | .navbar-bg .navbar-nav li.active a { 183 | color: #fff; 184 | background-color: transparent 185 | } 186 | 187 | .navbar-bg .navbar-toggle { 188 | border-color: #517A94; 189 | background-color: #517A94 190 | } 191 | 192 | .navbar-bg .navbar-toggle:hover { 193 | border-color: #384E6B; 194 | background-color: #384E6B 195 | } 196 | 197 | @media (max-width: 768px) { 198 | .navbar-default .navbar-nav { 199 | background-color: #293c55; 200 | -webkit-transition: background-color 0.5s linear; 201 | transition: background-color 0.5s linear 202 | } 203 | 204 | .navbar-default .navbar-nav .open .dropdown-menu { 205 | padding: 0 206 | } 207 | 208 | .navbar-default .navbar-nav .open .dropdown-menu li a { 209 | color: #fff 210 | } 211 | 212 | .navbar-default .navbar-nav li.active > 213 | a { 214 | border-left: 4px solid #a9334c; 215 | border-top: none; 216 | padding: 10px 15px 10px 11px 217 | } 218 | 219 | .navbar-bg .navbar-nav { 220 | background-color: #4B7995 221 | } 222 | 223 | .navbar-bg .navbar-toggle { 224 | background-color: transparent; 225 | border: none 226 | } 227 | 228 | .navbar-bg .navbar-toggle:focus { 229 | border-color: #5A88A2 !important; 230 | background-color: #5A88A2 !important 231 | } 232 | 233 | .navbar-bg .navbar-toggle:hover { 234 | border-color: #5A88A2; 235 | background-color: #5A88A2 236 | } 237 | 238 | #menu-btn { 239 | display: block 240 | } 241 | 242 | #nav-download { 243 | display: none 244 | } 245 | } 246 | 247 | #footer { 248 | padding: 35px 5%; 249 | font-size: 12px; 250 | text-align: left; 251 | background-color: #2a3c54; 252 | color: #fff 253 | } 254 | 255 | #footer .list-wrapper { 256 | *zoom: 1 257 | } 258 | 259 | #footer .list-wrapper:before, #footer .list-wrapper:after { 260 | display: table; 261 | line-height: 0; 262 | content: "" 263 | } 264 | 265 | #footer .list-wrapper:after { 266 | clear: both 267 | } 268 | 269 | #footer ul, #footer li { 270 | list-style: none; 271 | padding: 0; 272 | margin: 0 273 | } 274 | 275 | #footer a { 276 | line-height: 22px; 277 | color: #fff 278 | } 279 | 280 | #footer h2 { 281 | margin-bottom: 10px; 282 | font-size: 13px; 283 | font-weight: 400; 284 | color: #fff 285 | } 286 | 287 | #footer .product-list a { 288 | color: #5b8b95 289 | } 290 | 291 | #footer .copyrights { 292 | margin-top: 30px; 293 | padding-top: 15px; 294 | border-top: 1px solid rgba(255, 255, 255, 0.2); 295 | text-align: center; 296 | clear: left 297 | } 298 | 299 | #footer .product-list, #footer .echarts-product, #footer .contact-list, #footer .more { 300 | float: left; 301 | width: 30% 302 | } 303 | 304 | #footer .more { 305 | width: 10% 306 | } 307 | 308 | @keyframes textAnimation { 309 | 0% { 310 | -webkit-transform: translateX(-300px); 311 | transform: translateX(-300px) 312 | } 313 | 100% { 314 | -webkit-transform: translateX(0); 315 | transform: translateX(0) 316 | } 317 | } 318 | 319 | @-webkit-keyframes textAnimation { 320 | 0% { 321 | -webkit-transform: translateX(-300px); 322 | transform: translateX(-300px) 323 | } 324 | 100% { 325 | -webkit-transform: translateX(0); 326 | transform: translateX(0) 327 | } 328 | } 329 | 330 | @keyframes imgAnimation { 331 | 0% { 332 | -webkit-transform: translateX(500px); 333 | transform: translateX(500px) 334 | } 335 | 100% { 336 | -webkit-transform: translateX(0); 337 | transform: translateX(0) 338 | } 339 | } 340 | 341 | @-webkit-keyframes imgAnimation { 342 | 0% { 343 | -webkit-transform: translateX(500px); 344 | transform: translateX(500px) 345 | } 346 | 100% { 347 | -webkit-transform: translateX(0); 348 | transform: translateX(0) 349 | } 350 | } 351 | 352 | body { 353 | width: 100%; 354 | overflow-x: hidden; 355 | background-color: #fff 356 | } 357 | 358 | .section { 359 | margin-top: 25px; 360 | color: #707d8d 361 | } 362 | 363 | .section h2 { 364 | margin: 110px 0 40px; 365 | font-size: 44px 366 | } 367 | 368 | .section p { 369 | font-size: 19px; 370 | line-height: 28px 371 | } 372 | 373 | #page-index .navbar-default { 374 | margin-bottom: -51px 375 | } 376 | 377 | .section-one { 378 | background-color: #4f7f9b; 379 | background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#4f7f9b), to(#293c55)); 380 | background-image: -webkit-linear-gradient(top, #4f7f9b, #293c55); 381 | background-image: -webkit-gradient(linear, left top, left bottom, from(#4f7f9b), to(#293c55)); 382 | background-image: linear-gradient(to bottom, #4f7f9b, #293c55); 383 | background-repeat: repeat-x 384 | } 385 | 386 | .section-one .container-one { 387 | padding-top: 200px; 388 | } 389 | 390 | .section-one .text, .section-one .shadow, .section-one .line { 391 | display: block; 392 | margin: 0 auto 393 | } 394 | 395 | .section-one #animate-logo { 396 | width: 50%; 397 | margin: 0 auto 398 | } 399 | 400 | .section-one .shadow { 401 | width: 51%; 402 | margin: 10px auto 60px 403 | } 404 | 405 | .section-one .line { 406 | width: 100% 407 | } 408 | 409 | #wave { 410 | width: 100%; 411 | height: 200px 412 | } 413 | 414 | .section-two { 415 | position: relative; 416 | background-color: #293c55; 417 | color: #fff 418 | } 419 | 420 | .section-two .img-bg, .section-two .img-bg-footer, .section-two .header, .section-two .footer { 421 | position: absolute; 422 | left: 0; 423 | width: 100%; 424 | z-index: 1 425 | } 426 | 427 | .section-two .header { 428 | top: 50px; 429 | z-index: 2 430 | } 431 | 432 | .section-two .footer { 433 | bottom: 0 434 | } 435 | 436 | .section-two .earth { 437 | position: relative; 438 | display: block; 439 | width: 460px; 440 | margin: 60px auto 0; 441 | z-index: 11 442 | } 443 | 444 | .section-two .intro-wrap { 445 | position: absolute; 446 | left: 0; 447 | top: 50%; 448 | width: 100%; 449 | text-align: center 450 | } 451 | 452 | .section-two h2 { 453 | position: absolute; 454 | left: 0; 455 | top: 30%; 456 | width: 100%; 457 | text-align: center; 458 | top: 60px 459 | } 460 | 461 | .section-two .intro-source { 462 | width: 70%; 463 | margin: 0 auto; 464 | line-height: 24px; 465 | text-align: left 466 | } 467 | 468 | .section-three { 469 | background-color: #f0f4fa 470 | } 471 | 472 | .section-three .file { 473 | display: block; 474 | width: 80%; 475 | height: 350px; 476 | margin: 0 auto 477 | } 478 | 479 | .section-four .container-four { 480 | text-align: center; 481 | background-color: #fff 482 | } 483 | 484 | .section-four .text-wrap { 485 | padding-left: 10%; 486 | text-align: left 487 | } 488 | 489 | .section-four .text-wrap-animate { 490 | transform: translateZ(0); 491 | -webkit-transform: translateZ(0); 492 | -moz-transform: translateZ(0); 493 | -o-transform: translateZ(0); 494 | animation: textAnimation .7s ease-out; 495 | -moz-animation: textAnimation .7s ease-out; 496 | -webkit-animation: textAnimation .7s ease-out; 497 | -o-animation: textAnimation .7s ease-out 498 | } 499 | 500 | .section-four h2 { 501 | margin-top: 60px 502 | } 503 | 504 | .section-four .device-wrap { 505 | float: right 506 | } 507 | 508 | .section-four .device-wrap-animate { 509 | transform: translateZ(0); 510 | -webkit-transform: translateZ(0); 511 | -moz-transform: translateZ(0); 512 | -o-transform: translateZ(0); 513 | animation: imgAnimation .7s ease-out; 514 | -moz-animation: imgAnimation .7s ease-out; 515 | -webkit-animation: imgAnimation .7s ease-out; 516 | -o-animation: imgAnimation .7s ease-out 517 | } 518 | 519 | .section-four .device { 520 | display: block; 521 | width: 90% 522 | } 523 | 524 | .section-five { 525 | background-color: #f0f4fa 526 | } 527 | 528 | .section-five .container-five { 529 | text-align: center 530 | } 531 | 532 | .section-five .text-wrap { 533 | display: none 534 | } 535 | 536 | .section-five h2 { 537 | margin-bottom: 20px 538 | } 539 | 540 | .section-five p { 541 | width: 80%; 542 | margin: 0 auto 30px 543 | } 544 | 545 | .section-five .list { 546 | height: 300px; 547 | line-height: 300px 548 | } 549 | 550 | .section-five i { 551 | display: inline-block; 552 | width: 8px; 553 | height: 8px; 554 | margin: 0 6px; 555 | -webkit-border-radius: 4px; 556 | border-radius: 4px; 557 | border: 1px solid #b7c4d4 558 | } 559 | 560 | .section-five img { 561 | width: 8%; 562 | -webkit-border-radius: 150px; 563 | border-radius: 150px; 564 | border: 1px solid #b7c4d4; 565 | -webkit-transition: all 0.2s ease-out; 566 | transition: all 0.2s ease-out 567 | } 568 | 569 | .section-five .cur-item { 570 | width: 12%; 571 | margin: 0 6px; 572 | -webkit-border-radius: 200px; 573 | border-radius: 200px; 574 | border-color: #7fccf2; 575 | -webkit-box-shadow: 0 0 10px #b7c4d4; 576 | box-shadow: 0 0 10px #b7c4d4 577 | } 578 | 579 | .section-six .container-six { 580 | padding: 120px 0 60px; 581 | text-align: center; 582 | background-color: #fff 583 | } 584 | 585 | .section-six h2 { 586 | font-size: 19px; 587 | line-height: 30px; 588 | margin: 0 589 | } 590 | 591 | .section-six .start-btn { 592 | display: block; 593 | margin: 40px auto; 594 | width: 210px; 595 | line-height: 46px; 596 | font-size: 21px; 597 | text-decoration: none; 598 | background-color: #5CB6E3; 599 | color: #fff 600 | } 601 | 602 | .section-six .start-btn:hover { 603 | background-color: #91D7F7 604 | } 605 | 606 | .section-one, .section-two { 607 | margin-top: 0 608 | } 609 | 610 | #fp-nav ul li { 611 | width: 14px !important; 612 | height: 14px !important; 613 | margin-bottom: 10px !important 614 | } 615 | 616 | #fp-nav ul li a span { 617 | width: 14px !important; 618 | height: 14px !important; 619 | left: 0 !important; 620 | top: 0 !important; 621 | margin: 0 !important; 622 | border: 1px solid #6090b6 !important; 623 | background: none !important 624 | } 625 | 626 | #fp-nav ul li .active span { 627 | background: #6090b6 !important 628 | } 629 | 630 | .lower-ie #fp-nav { 631 | display: none 632 | } 633 | 634 | @media (max-width: 992px) and (min-width: 768px) { 635 | .section-three h2 { 636 | margin: 20px 0 20px 0 637 | } 638 | 639 | .section-four h2 { 640 | margin: 0 0 20px 0 641 | } 642 | } 643 | 644 | @media (max-width: 768px) { 645 | #wave { 646 | height: 140px 647 | } 648 | 649 | #file-size-chart { 650 | height: 290px 651 | } 652 | 653 | #fp-nav.right { 654 | right: 15px 655 | } 656 | 657 | .section { 658 | text-align: center 659 | } 660 | 661 | .section h2 { 662 | margin: 10px; 663 | font-size: 30px 664 | } 665 | 666 | .section p { 667 | font-size: 15px; 668 | line-height: 28px 669 | } 670 | 671 | .section-six .container-six { 672 | padding: 0 673 | } 674 | 675 | .section-six h2 { 676 | font-size: 19px 677 | } 678 | 679 | #footer h2 { 680 | margin: 0 681 | } 682 | 683 | .section-one #animate-logo { 684 | width: 80% 685 | } 686 | 687 | .section-one .container-one { 688 | padding-top: 100px 689 | } 690 | 691 | .section-one .text { 692 | width: 70% 693 | } 694 | 695 | .section-one .shadow { 696 | width: 78%; 697 | margin: 20px auto 30px 698 | } 699 | 700 | .section-two h2 { 701 | top: 190px; 702 | margin: 0 703 | } 704 | 705 | .section-two .intro-wrap { 706 | top: 250px 707 | } 708 | 709 | .section-two .earth { 710 | width: 300px 711 | } 712 | 713 | .section-three .container-three .file { 714 | margin-bottom: 25px 715 | } 716 | 717 | .section-four .text-wrap { 718 | width: 100%; 719 | padding-left: 0; 720 | margin: 0 0 20px 0; 721 | text-align: center 722 | } 723 | 724 | .section-four .device { 725 | display: block; 726 | margin: 0 auto 40px 727 | } 728 | 729 | .section-five .container-five p { 730 | margin: 0 auto 731 | } 732 | 733 | .section-five .container-five i { 734 | display: none 735 | } 736 | 737 | .section-five .container-five .list { 738 | padding: 20px 12px 30px 20px; 739 | height: auto; 740 | line-height: normal 741 | } 742 | 743 | .section-five .container-five img { 744 | width: 20%; 745 | margin-right: 2% 746 | } 747 | 748 | .section-five .container-five .cur-item { 749 | width: 20%; 750 | margin: 0 2% 0 0; 751 | border-color: #b7c4d4; 752 | -webkit-box-shadow: none; 753 | box-shadow: none 754 | } 755 | 756 | .section-five .container-five .text-wrap { 757 | display: block 758 | } 759 | 760 | .section-five .container-five .text-header-wrap { 761 | display: none 762 | } 763 | } 764 | 765 | @media (max-width: 480px) { 766 | .section { 767 | text-align: center 768 | } 769 | 770 | .section h2 { 771 | font-size: 20px 772 | } 773 | 774 | .section p { 775 | font-size: 13px 776 | } 777 | 778 | .section-three h2, .section-four h2, .section-five h2 { 779 | margin: 10px 780 | } 781 | 782 | .section-three P, .section-four P, .section-five P { 783 | line-height: 28px 784 | } 785 | 786 | .section-two h2 { 787 | top: 140px; 788 | margin: 0 789 | } 790 | 791 | .section-two .intro-wrap { 792 | top: 200px 793 | } 794 | 795 | .section-six h2 { 796 | font-size: 14px 797 | } 798 | 799 | #footer { 800 | display: none 801 | } 802 | } 803 | 804 | @media (max-width: 320px) { 805 | .section-two h2 { 806 | top: 95px; 807 | margin: 0 808 | } 809 | 810 | .section-two .intro-wrap { 811 | top: 130px 812 | } 813 | } 814 | 815 | #left-chart-nav { 816 | position: fixed; 817 | 818 | top: 49px; 819 | bottom: 0; 820 | left: 0; 821 | border-top: 1px solid #0e151f; 822 | width: 155px; 823 | background-color: #293c55; 824 | overflow-y: auto; 825 | z-index: 15 826 | } 827 | 828 | #left-chart-nav:hover { 829 | overflow-y: auto 830 | } 831 | 832 | #left-chart-nav ul { 833 | padding: 0 834 | } 835 | 836 | #left-chart-nav li { 837 | height: 54px; 838 | padding: 10px 15px; 839 | -webkit-transition: 0.5s; 840 | transition: 0.5s; 841 | margin: 0 auto 842 | } 843 | 844 | #left-chart-nav li a { 845 | color: #ccc; 846 | position: relative; 847 | display: block; 848 | -webkit-transition: 0.5s; 849 | transition: 0.5s 850 | } 851 | 852 | #left-chart-nav li a .chart-name { 853 | display: inline-block; 854 | height: 32px; 855 | line-height: 32px; 856 | margin-left: 20px 857 | } 858 | 859 | #left-chart-nav li.active { 860 | background-color: #e43c59 861 | } 862 | 863 | #left-chart-nav li:hover { 864 | background-color: #162436 865 | } 866 | 867 | @media (max-width: 768px) { 868 | #left-chart-nav { 869 | display: none 870 | } 871 | } 872 | 873 | #nav-mask { 874 | display: none; 875 | position: fixed; 876 | top: 50px; 877 | left: 155px; 878 | bottom: 0; 879 | right: 0; 880 | width: 100%; 881 | height: 100%; 882 | background: rgba(0, 0, 0, 0.3); 883 | z-index: 12 884 | } 885 | 886 | #nav-layer { 887 | display: none; 888 | position: fixed; 889 | width: 620px; 890 | max-height: 350px; 891 | left: 155px; 892 | top: 200px; 893 | z-index: 15; 894 | background-color: #fff; 895 | overflow-y: scroll; 896 | -webkit-box-shadow: 0 0 20px rgba(0, 0, 0, 0.5); 897 | box-shadow: 0 0 20px rgba(0, 0, 0, 0.5) 898 | } 899 | 900 | #nav-layer .chart-list { 901 | *zoom: 1; 902 | width: 100%; 903 | clear: both; 904 | padding: 10px; 905 | -webkit-box-sizing: border-box; 906 | box-sizing: border-box 907 | } 908 | 909 | #nav-layer .chart-list:before, #nav-layer .chart-list:after { 910 | display: table; 911 | line-height: 0; 912 | content: "" 913 | } 914 | 915 | #nav-layer .chart-list:after { 916 | clear: both 917 | } 918 | 919 | #nav-layer li { 920 | float: left; 921 | width: 180px; 922 | margin: 10px 10px; 923 | padding: 5px; 924 | -webkit-box-shadow: 0 0 1px rgba(0, 0, 0, 0.3); 925 | box-shadow: 0 0 1px rgba(0, 0, 0, 0.3); 926 | -webkit-transition: -webkit-box-shadow 0.5s ease-out; 927 | transition: -webkit-box-shadow 0.5s ease-out; 928 | transition: box-shadow 0.5s ease-out; 929 | transition: box-shadow 0.5s ease-out, -webkit-box-shadow 0.5s ease-out 930 | } 931 | 932 | #nav-layer li:hover { 933 | -webkit-box-shadow: 0 0 20px rgba(0, 0, 0, 0.3); 934 | box-shadow: 0 0 20px rgba(0, 0, 0, 0.3) 935 | } 936 | 937 | #nav-layer img { 938 | width: 100%; 939 | height: 100% 940 | } 941 | 942 | #left-chart-nav-line .chart-icon { 943 | background-position-x: -1px; 944 | background-position-y: -1px 945 | } 946 | 947 | #left-chart-nav-bar .chart-icon { 948 | background-position-x: -1px; 949 | background-position-y: -33px 950 | } 951 | 952 | #left-chart-nav-scatter .chart-icon { 953 | background-position-x: -1px; 954 | background-position-y: -65px 955 | } 956 | 957 | #left-chart-nav-pie .chart-icon { 958 | background-position-x: -1px; 959 | background-position-y: -129px 960 | } 961 | 962 | #left-chart-nav-radar .chart-icon { 963 | background-position-x: -1px; 964 | background-position-y: -161px 965 | } 966 | 967 | #left-chart-nav-funnel .chart-icon { 968 | background-position-x: -1px; 969 | background-position-y: -321px 970 | } 971 | 972 | #left-chart-nav-gauge .chart-icon { 973 | background-position-x: -1px; 974 | background-position-y: -289px 975 | } 976 | 977 | #left-chart-nav-map .chart-icon { 978 | background-position-x: -1px; 979 | background-position-y: -257px 980 | } 981 | 982 | #left-chart-nav-graph .chart-icon { 983 | background-position-x: -1px; 984 | background-position-y: -225px 985 | } 986 | 987 | #left-chart-nav-treemap .chart-icon { 988 | background-position-x: -1px; 989 | background-position-y: -449px 990 | } 991 | 992 | #left-chart-nav-parallel .chart-icon { 993 | background-position-x: -1px; 994 | background-position-y: -513px 995 | } 996 | 997 | #left-chart-nav-sankey .chart-icon { 998 | background-position-x: -1px; 999 | background-position-y: -545px 1000 | } 1001 | 1002 | #left-chart-nav-candlestick .chart-icon { 1003 | background-position-x: -1px; 1004 | background-position-y: -97px 1005 | } 1006 | 1007 | #left-chart-nav-boxplot .chart-icon { 1008 | background-position-x: -1px; 1009 | background-position-y: -577px 1010 | } 1011 | 1012 | #left-chart-nav-heatmap .chart-icon { 1013 | background-position-x: -1px; 1014 | background-position-y: -353px 1015 | } 1016 | 1017 | #explore-container { 1018 | position: relative; 1019 | /*margin-left: 155px;*/ 1020 | z-index: 10; 1021 | /*background-color: #f9f9f9*/ 1022 | } 1023 | 1024 | .chart-list-panel { 1025 | margin: 75px 15px 30px 15px 1026 | } 1027 | 1028 | .chart-list-panel h3 { 1029 | margin-bottom: 20px; 1030 | border-bottom: 1px solid #ccc; 1031 | padding-bottom: 5px; 1032 | margin-top: 50px 1033 | } 1034 | 1035 | .chart-list-panel .chart .chart-link { 1036 | position: relative; 1037 | display: block 1038 | } 1039 | 1040 | .chart-list-panel .chart .chart-link .chart-area { 1041 | width: 100%; 1042 | height: 100%; 1043 | padding: 8px 1044 | } 1045 | 1046 | .chart-list-panel .chart .chart-link .chart-title { 1047 | color: #293c55; 1048 | overflow: hidden; 1049 | text-overflow: ellipsis; 1050 | white-space: nowrap; 1051 | padding: 10px 10px 2px 10px; 1052 | margin: 0; 1053 | font-weight: normal; 1054 | font-size: 16px 1055 | } 1056 | 1057 | .chart-list-panel .chart .chart-info { 1058 | padding: 5px 0; 1059 | font-weight: bold 1060 | } 1061 | 1062 | .chart-list-panel .chart .chart-info .chart-icon { 1063 | float: right 1064 | } 1065 | 1066 | .chart-list-panel .chart .chart-info .chart-icon .chart-delete { 1067 | display: none; 1068 | -webkit-transition: 1s; 1069 | transition: 1s 1070 | } 1071 | 1072 | .chart-list-panel .chart:hover .chart-info .chart-icon .chart-delete { 1073 | display: block; 1074 | text-decoration: none 1075 | } 1076 | 1077 | @media (max-width: 768px) { 1078 | .chart-list-panel .chart .chart-link .chart-hover { 1079 | opacity: 1; 1080 | position: static; 1081 | color: #666; 1082 | margin-top: 0; 1083 | height: auto 1084 | } 1085 | 1086 | .chart-list-panel .chart .chart-link .chart-hover .chart-title { 1087 | border-top: none; 1088 | color: #e43c59; 1089 | margin-top: 20px; 1090 | margin-bottom: 0 1091 | } 1092 | 1093 | .chart-list-panel .chart .chart-link .chart-hover .chart-subtitle { 1094 | display: none 1095 | } 1096 | 1097 | .chart-list-panel .chart .chart-link .chart-hover .chart-title:before, .chart-list-panel .chart .chart-link .chart-hover .chart-subtitle:after { 1098 | display: none 1099 | } 1100 | 1101 | .chart-list-panel .chart .chart-link:hover .chart-hover-bg { 1102 | display: none 1103 | } 1104 | 1105 | #explore-container { 1106 | margin-left: 0 1107 | } 1108 | 1109 | #chart-demo { 1110 | left: 0 1111 | } 1112 | } 1113 | 1114 | h1, h2, h3, h4, h5, h6, p { 1115 | font-weight: 400; 1116 | margin: 0; 1117 | padding: 0 1118 | } 1119 | 1120 | ul { 1121 | list-style: none; 1122 | padding: 0; 1123 | margin: 0 1124 | } 1125 | 1126 | li { 1127 | list-style: none 1128 | } 1129 | 1130 | ul { 1131 | margin: 0px; 1132 | padding: 0px 1133 | } 1134 | 1135 | #action { 1136 | margin-top: 50px; 1137 | margin-bottom: 100px; 1138 | text-align: center 1139 | } 1140 | 1141 | .clear { 1142 | clear: both 1143 | } 1144 | 1145 | .not-found { 1146 | padding: 150px 0 160px; 1147 | height: 100%; 1148 | background-color: #2a3c54; 1149 | overflow: hidden 1150 | } 1151 | 1152 | .not-found img { 1153 | display: block; 1154 | width: 60%; 1155 | margin: 0 auto 1156 | } 1157 | 1158 | .not-found .text { 1159 | margin-top: 50px; 1160 | text-align: center; 1161 | font-size: 20px; 1162 | color: #fff 1163 | } 1164 | 1165 | .not-found .link { 1166 | margin-left: 10px; 1167 | color: #3183c6 1168 | } 1169 | 1170 | @media (max-width: 768px) { 1171 | .not-found .text { 1172 | padding: 0 15px; 1173 | font-size: 14px 1174 | } 1175 | } 1176 | 1177 | 1178 | 1179 | 1180 | 1181 | 1182 | 1183 | -------------------------------------------------------------------------------- /log-collection/src/main/resources/static/js/bootstrap.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap v3.3.6 (http://getbootstrap.com) 3 | * Copyright 2011-2015 Twitter, Inc. 4 | * Licensed under the MIT license 5 | */ 6 | if("undefined"==typeof jQuery)throw new Error("Bootstrap's JavaScript requires jQuery");+function(a){"use strict";var b=a.fn.jquery.split(" ")[0].split(".");if(b[0]<2&&b[1]<9||1==b[0]&&9==b[1]&&b[2]<1||b[0]>2)throw new Error("Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 3")}(jQuery),+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one("bsTransitionEnd",function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b(),a.support.transition&&(a.event.special.bsTransitionEnd={bindType:a.support.transition.end,delegateType:a.support.transition.end,handle:function(b){return a(b.target).is(this)?b.handleObj.handler.apply(this,arguments):void 0}})})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var c=a(this),e=c.data("bs.alert");e||c.data("bs.alert",e=new d(this)),"string"==typeof b&&e[b].call(c)})}var c='[data-dismiss="alert"]',d=function(b){a(b).on("click",c,this.close)};d.VERSION="3.3.6",d.TRANSITION_DURATION=150,d.prototype.close=function(b){function c(){g.detach().trigger("closed.bs.alert").remove()}var e=a(this),f=e.attr("data-target");f||(f=e.attr("href"),f=f&&f.replace(/.*(?=#[^\s]*$)/,""));var g=a(f);b&&b.preventDefault(),g.length||(g=e.closest(".alert")),g.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(g.removeClass("in"),a.support.transition&&g.hasClass("fade")?g.one("bsTransitionEnd",c).emulateTransitionEnd(d.TRANSITION_DURATION):c())};var e=a.fn.alert;a.fn.alert=b,a.fn.alert.Constructor=d,a.fn.alert.noConflict=function(){return a.fn.alert=e,this},a(document).on("click.bs.alert.data-api",c,d.prototype.close)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof b&&b;e||d.data("bs.button",e=new c(this,f)),"toggle"==b?e.toggle():b&&e.setState(b)})}var c=function(b,d){this.$element=a(b),this.options=a.extend({},c.DEFAULTS,d),this.isLoading=!1};c.VERSION="3.3.6",c.DEFAULTS={loadingText:"loading..."},c.prototype.setState=function(b){var c="disabled",d=this.$element,e=d.is("input")?"val":"html",f=d.data();b+="Text",null==f.resetText&&d.data("resetText",d[e]()),setTimeout(a.proxy(function(){d[e](null==f[b]?this.options[b]:f[b]),"loadingText"==b?(this.isLoading=!0,d.addClass(c).attr(c,c)):this.isLoading&&(this.isLoading=!1,d.removeClass(c).removeAttr(c))},this),0)},c.prototype.toggle=function(){var a=!0,b=this.$element.closest('[data-toggle="buttons"]');if(b.length){var c=this.$element.find("input");"radio"==c.prop("type")?(c.prop("checked")&&(a=!1),b.find(".active").removeClass("active"),this.$element.addClass("active")):"checkbox"==c.prop("type")&&(c.prop("checked")!==this.$element.hasClass("active")&&(a=!1),this.$element.toggleClass("active")),c.prop("checked",this.$element.hasClass("active")),a&&c.trigger("change")}else this.$element.attr("aria-pressed",!this.$element.hasClass("active")),this.$element.toggleClass("active")};var d=a.fn.button;a.fn.button=b,a.fn.button.Constructor=c,a.fn.button.noConflict=function(){return a.fn.button=d,this},a(document).on("click.bs.button.data-api",'[data-toggle^="button"]',function(c){var d=a(c.target);d.hasClass("btn")||(d=d.closest(".btn")),b.call(d,"toggle"),a(c.target).is('input[type="radio"]')||a(c.target).is('input[type="checkbox"]')||c.preventDefault()}).on("focus.bs.button.data-api blur.bs.button.data-api",'[data-toggle^="button"]',function(b){a(b.target).closest(".btn").toggleClass("focus",/^focus(in)?$/.test(b.type))})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},c.DEFAULTS,d.data(),"object"==typeof b&&b),g="string"==typeof b?b:f.slide;e||d.data("bs.carousel",e=new c(this,f)),"number"==typeof b?e.to(b):g?e[g]():f.interval&&e.pause().cycle()})}var c=function(b,c){this.$element=a(b),this.$indicators=this.$element.find(".carousel-indicators"),this.options=c,this.paused=null,this.sliding=null,this.interval=null,this.$active=null,this.$items=null,this.options.keyboard&&this.$element.on("keydown.bs.carousel",a.proxy(this.keydown,this)),"hover"==this.options.pause&&!("ontouchstart"in document.documentElement)&&this.$element.on("mouseenter.bs.carousel",a.proxy(this.pause,this)).on("mouseleave.bs.carousel",a.proxy(this.cycle,this))};c.VERSION="3.3.6",c.TRANSITION_DURATION=600,c.DEFAULTS={interval:5e3,pause:"hover",wrap:!0,keyboard:!0},c.prototype.keydown=function(a){if(!/input|textarea/i.test(a.target.tagName)){switch(a.which){case 37:this.prev();break;case 39:this.next();break;default:return}a.preventDefault()}},c.prototype.cycle=function(b){return b||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(a.proxy(this.next,this),this.options.interval)),this},c.prototype.getItemIndex=function(a){return this.$items=a.parent().children(".item"),this.$items.index(a||this.$active)},c.prototype.getItemForDirection=function(a,b){var c=this.getItemIndex(b),d="prev"==a&&0===c||"next"==a&&c==this.$items.length-1;if(d&&!this.options.wrap)return b;var e="prev"==a?-1:1,f=(c+e)%this.$items.length;return this.$items.eq(f)},c.prototype.to=function(a){var b=this,c=this.getItemIndex(this.$active=this.$element.find(".item.active"));return a>this.$items.length-1||0>a?void 0:this.sliding?this.$element.one("slid.bs.carousel",function(){b.to(a)}):c==a?this.pause().cycle():this.slide(a>c?"next":"prev",this.$items.eq(a))},c.prototype.pause=function(b){return b||(this.paused=!0),this.$element.find(".next, .prev").length&&a.support.transition&&(this.$element.trigger(a.support.transition.end),this.cycle(!0)),this.interval=clearInterval(this.interval),this},c.prototype.next=function(){return this.sliding?void 0:this.slide("next")},c.prototype.prev=function(){return this.sliding?void 0:this.slide("prev")},c.prototype.slide=function(b,d){var e=this.$element.find(".item.active"),f=d||this.getItemForDirection(b,e),g=this.interval,h="next"==b?"left":"right",i=this;if(f.hasClass("active"))return this.sliding=!1;var j=f[0],k=a.Event("slide.bs.carousel",{relatedTarget:j,direction:h});if(this.$element.trigger(k),!k.isDefaultPrevented()){if(this.sliding=!0,g&&this.pause(),this.$indicators.length){this.$indicators.find(".active").removeClass("active");var l=a(this.$indicators.children()[this.getItemIndex(f)]);l&&l.addClass("active")}var m=a.Event("slid.bs.carousel",{relatedTarget:j,direction:h});return a.support.transition&&this.$element.hasClass("slide")?(f.addClass(b),f[0].offsetWidth,e.addClass(h),f.addClass(h),e.one("bsTransitionEnd",function(){f.removeClass([b,h].join(" ")).addClass("active"),e.removeClass(["active",h].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger(m)},0)}).emulateTransitionEnd(c.TRANSITION_DURATION)):(e.removeClass("active"),f.addClass("active"),this.sliding=!1,this.$element.trigger(m)),g&&this.cycle(),this}};var d=a.fn.carousel;a.fn.carousel=b,a.fn.carousel.Constructor=c,a.fn.carousel.noConflict=function(){return a.fn.carousel=d,this};var e=function(c){var d,e=a(this),f=a(e.attr("data-target")||(d=e.attr("href"))&&d.replace(/.*(?=#[^\s]+$)/,""));if(f.hasClass("carousel")){var g=a.extend({},f.data(),e.data()),h=e.attr("data-slide-to");h&&(g.interval=!1),b.call(f,g),h&&f.data("bs.carousel").to(h),c.preventDefault()}};a(document).on("click.bs.carousel.data-api","[data-slide]",e).on("click.bs.carousel.data-api","[data-slide-to]",e),a(window).on("load",function(){a('[data-ride="carousel"]').each(function(){var c=a(this);b.call(c,c.data())})})}(jQuery),+function(a){"use strict";function b(b){var c,d=b.attr("data-target")||(c=b.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,"");return a(d)}function c(b){return this.each(function(){var c=a(this),e=c.data("bs.collapse"),f=a.extend({},d.DEFAULTS,c.data(),"object"==typeof b&&b);!e&&f.toggle&&/show|hide/.test(b)&&(f.toggle=!1),e||c.data("bs.collapse",e=new d(this,f)),"string"==typeof b&&e[b]()})}var d=function(b,c){this.$element=a(b),this.options=a.extend({},d.DEFAULTS,c),this.$trigger=a('[data-toggle="collapse"][href="#'+b.id+'"],[data-toggle="collapse"][data-target="#'+b.id+'"]'),this.transitioning=null,this.options.parent?this.$parent=this.getParent():this.addAriaAndCollapsedClass(this.$element,this.$trigger),this.options.toggle&&this.toggle()};d.VERSION="3.3.6",d.TRANSITION_DURATION=350,d.DEFAULTS={toggle:!0},d.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},d.prototype.show=function(){if(!this.transitioning&&!this.$element.hasClass("in")){var b,e=this.$parent&&this.$parent.children(".panel").children(".in, .collapsing");if(!(e&&e.length&&(b=e.data("bs.collapse"),b&&b.transitioning))){var f=a.Event("show.bs.collapse");if(this.$element.trigger(f),!f.isDefaultPrevented()){e&&e.length&&(c.call(e,"hide"),b||e.data("bs.collapse",null));var g=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[g](0).attr("aria-expanded",!0),this.$trigger.removeClass("collapsed").attr("aria-expanded",!0),this.transitioning=1;var h=function(){this.$element.removeClass("collapsing").addClass("collapse in")[g](""),this.transitioning=0,this.$element.trigger("shown.bs.collapse")};if(!a.support.transition)return h.call(this);var i=a.camelCase(["scroll",g].join("-"));this.$element.one("bsTransitionEnd",a.proxy(h,this)).emulateTransitionEnd(d.TRANSITION_DURATION)[g](this.$element[0][i])}}}},d.prototype.hide=function(){if(!this.transitioning&&this.$element.hasClass("in")){var b=a.Event("hide.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse in").attr("aria-expanded",!1),this.$trigger.addClass("collapsed").attr("aria-expanded",!1),this.transitioning=1;var e=function(){this.transitioning=0,this.$element.removeClass("collapsing").addClass("collapse").trigger("hidden.bs.collapse")};return a.support.transition?void this.$element[c](0).one("bsTransitionEnd",a.proxy(e,this)).emulateTransitionEnd(d.TRANSITION_DURATION):e.call(this)}}},d.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()},d.prototype.getParent=function(){return a(this.options.parent).find('[data-toggle="collapse"][data-parent="'+this.options.parent+'"]').each(a.proxy(function(c,d){var e=a(d);this.addAriaAndCollapsedClass(b(e),e)},this)).end()},d.prototype.addAriaAndCollapsedClass=function(a,b){var c=a.hasClass("in");a.attr("aria-expanded",c),b.toggleClass("collapsed",!c).attr("aria-expanded",c)};var e=a.fn.collapse;a.fn.collapse=c,a.fn.collapse.Constructor=d,a.fn.collapse.noConflict=function(){return a.fn.collapse=e,this},a(document).on("click.bs.collapse.data-api",'[data-toggle="collapse"]',function(d){var e=a(this);e.attr("data-target")||d.preventDefault();var f=b(e),g=f.data("bs.collapse"),h=g?"toggle":e.data();c.call(f,h)})}(jQuery),+function(a){"use strict";function b(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#[A-Za-z]/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}function c(c){c&&3===c.which||(a(e).remove(),a(f).each(function(){var d=a(this),e=b(d),f={relatedTarget:this};e.hasClass("open")&&(c&&"click"==c.type&&/input|textarea/i.test(c.target.tagName)&&a.contains(e[0],c.target)||(e.trigger(c=a.Event("hide.bs.dropdown",f)),c.isDefaultPrevented()||(d.attr("aria-expanded","false"),e.removeClass("open").trigger(a.Event("hidden.bs.dropdown",f)))))}))}function d(b){return this.each(function(){var c=a(this),d=c.data("bs.dropdown");d||c.data("bs.dropdown",d=new g(this)),"string"==typeof b&&d[b].call(c)})}var e=".dropdown-backdrop",f='[data-toggle="dropdown"]',g=function(b){a(b).on("click.bs.dropdown",this.toggle)};g.VERSION="3.3.6",g.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=b(e),g=f.hasClass("open");if(c(),!g){"ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a(document.createElement("div")).addClass("dropdown-backdrop").insertAfter(a(this)).on("click",c);var h={relatedTarget:this};if(f.trigger(d=a.Event("show.bs.dropdown",h)),d.isDefaultPrevented())return;e.trigger("focus").attr("aria-expanded","true"),f.toggleClass("open").trigger(a.Event("shown.bs.dropdown",h))}return!1}},g.prototype.keydown=function(c){if(/(38|40|27|32)/.test(c.which)&&!/input|textarea/i.test(c.target.tagName)){var d=a(this);if(c.preventDefault(),c.stopPropagation(),!d.is(".disabled, :disabled")){var e=b(d),g=e.hasClass("open");if(!g&&27!=c.which||g&&27==c.which)return 27==c.which&&e.find(f).trigger("focus"),d.trigger("click");var h=" li:not(.disabled):visible a",i=e.find(".dropdown-menu"+h);if(i.length){var j=i.index(c.target);38==c.which&&j>0&&j--,40==c.which&&jdocument.documentElement.clientHeight;this.$element.css({paddingLeft:!this.bodyIsOverflowing&&a?this.scrollbarWidth:"",paddingRight:this.bodyIsOverflowing&&!a?this.scrollbarWidth:""})},c.prototype.resetAdjustments=function(){this.$element.css({paddingLeft:"",paddingRight:""})},c.prototype.checkScrollbar=function(){var a=window.innerWidth;if(!a){var b=document.documentElement.getBoundingClientRect();a=b.right-Math.abs(b.left)}this.bodyIsOverflowing=document.body.clientWidth

',trigger:"hover focus",title:"",delay:0,html:!1,container:!1,viewport:{selector:"body",padding:0}},c.prototype.init=function(b,c,d){if(this.enabled=!0,this.type=b,this.$element=a(c),this.options=this.getOptions(d),this.$viewport=this.options.viewport&&a(a.isFunction(this.options.viewport)?this.options.viewport.call(this,this.$element):this.options.viewport.selector||this.options.viewport),this.inState={click:!1,hover:!1,focus:!1},this.$element[0]instanceof document.constructor&&!this.options.selector)throw new Error("`selector` option must be specified when initializing "+this.type+" on the window.document object!");for(var e=this.options.trigger.split(" "),f=e.length;f--;){var g=e[f];if("click"==g)this.$element.on("click."+this.type,this.options.selector,a.proxy(this.toggle,this));else if("manual"!=g){var h="hover"==g?"mouseenter":"focusin",i="hover"==g?"mouseleave":"focusout";this.$element.on(h+"."+this.type,this.options.selector,a.proxy(this.enter,this)),this.$element.on(i+"."+this.type,this.options.selector,a.proxy(this.leave,this))}}this.options.selector?this._options=a.extend({},this.options,{trigger:"manual",selector:""}):this.fixTitle()},c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.getOptions=function(b){return b=a.extend({},this.getDefaults(),this.$element.data(),b),b.delay&&"number"==typeof b.delay&&(b.delay={show:b.delay,hide:b.delay}),b},c.prototype.getDelegateOptions=function(){var b={},c=this.getDefaults();return this._options&&a.each(this._options,function(a,d){c[a]!=d&&(b[a]=d)}),b},c.prototype.enter=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);return c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),b instanceof a.Event&&(c.inState["focusin"==b.type?"focus":"hover"]=!0),c.tip().hasClass("in")||"in"==c.hoverState?void(c.hoverState="in"):(clearTimeout(c.timeout),c.hoverState="in",c.options.delay&&c.options.delay.show?void(c.timeout=setTimeout(function(){"in"==c.hoverState&&c.show()},c.options.delay.show)):c.show())},c.prototype.isInStateTrue=function(){for(var a in this.inState)if(this.inState[a])return!0;return!1},c.prototype.leave=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);return c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),b instanceof a.Event&&(c.inState["focusout"==b.type?"focus":"hover"]=!1),c.isInStateTrue()?void 0:(clearTimeout(c.timeout),c.hoverState="out",c.options.delay&&c.options.delay.hide?void(c.timeout=setTimeout(function(){"out"==c.hoverState&&c.hide()},c.options.delay.hide)):c.hide())},c.prototype.show=function(){var b=a.Event("show.bs."+this.type);if(this.hasContent()&&this.enabled){this.$element.trigger(b);var d=a.contains(this.$element[0].ownerDocument.documentElement,this.$element[0]);if(b.isDefaultPrevented()||!d)return;var e=this,f=this.tip(),g=this.getUID(this.type);this.setContent(),f.attr("id",g),this.$element.attr("aria-describedby",g),this.options.animation&&f.addClass("fade");var h="function"==typeof this.options.placement?this.options.placement.call(this,f[0],this.$element[0]):this.options.placement,i=/\s?auto?\s?/i,j=i.test(h);j&&(h=h.replace(i,"")||"top"),f.detach().css({top:0,left:0,display:"block"}).addClass(h).data("bs."+this.type,this),this.options.container?f.appendTo(this.options.container):f.insertAfter(this.$element),this.$element.trigger("inserted.bs."+this.type);var k=this.getPosition(),l=f[0].offsetWidth,m=f[0].offsetHeight;if(j){var n=h,o=this.getPosition(this.$viewport);h="bottom"==h&&k.bottom+m>o.bottom?"top":"top"==h&&k.top-mo.width?"left":"left"==h&&k.left-lg.top+g.height&&(e.top=g.top+g.height-i)}else{var j=b.left-f,k=b.left+f+c;jg.right&&(e.left=g.left+g.width-k)}return e},c.prototype.getTitle=function(){var a,b=this.$element,c=this.options;return a=b.attr("data-original-title")||("function"==typeof c.title?c.title.call(b[0]):c.title)},c.prototype.getUID=function(a){do a+=~~(1e6*Math.random());while(document.getElementById(a));return a},c.prototype.tip=function(){if(!this.$tip&&(this.$tip=a(this.options.template),1!=this.$tip.length))throw new Error(this.type+" `template` option must consist of exactly 1 top-level element!");return this.$tip},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".tooltip-arrow")},c.prototype.enable=function(){this.enabled=!0},c.prototype.disable=function(){this.enabled=!1},c.prototype.toggleEnabled=function(){this.enabled=!this.enabled},c.prototype.toggle=function(b){var c=this;b&&(c=a(b.currentTarget).data("bs."+this.type),c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c))),b?(c.inState.click=!c.inState.click,c.isInStateTrue()?c.enter(c):c.leave(c)):c.tip().hasClass("in")?c.leave(c):c.enter(c)},c.prototype.destroy=function(){var a=this;clearTimeout(this.timeout),this.hide(function(){a.$element.off("."+a.type).removeData("bs."+a.type),a.$tip&&a.$tip.detach(),a.$tip=null,a.$arrow=null,a.$viewport=null})};var d=a.fn.tooltip;a.fn.tooltip=b,a.fn.tooltip.Constructor=c,a.fn.tooltip.noConflict=function(){return a.fn.tooltip=d,this}}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.popover"),f="object"==typeof b&&b;(e||!/destroy|hide/.test(b))&&(e||d.data("bs.popover",e=new c(this,f)),"string"==typeof b&&e[b]())})}var c=function(a,b){this.init("popover",a,b)};if(!a.fn.tooltip)throw new Error("Popover requires tooltip.js");c.VERSION="3.3.6",c.DEFAULTS=a.extend({},a.fn.tooltip.Constructor.DEFAULTS,{placement:"right",trigger:"click",content:"",template:''}),c.prototype=a.extend({},a.fn.tooltip.Constructor.prototype),c.prototype.constructor=c,c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.setContent=function(){var a=this.tip(),b=this.getTitle(),c=this.getContent();a.find(".popover-title")[this.options.html?"html":"text"](b),a.find(".popover-content").children().detach().end()[this.options.html?"string"==typeof c?"html":"append":"text"](c),a.removeClass("fade top bottom left right in"),a.find(".popover-title").html()||a.find(".popover-title").hide()},c.prototype.hasContent=function(){return this.getTitle()||this.getContent()},c.prototype.getContent=function(){var a=this.$element,b=this.options;return a.attr("data-content")||("function"==typeof b.content?b.content.call(a[0]):b.content)},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")};var d=a.fn.popover;a.fn.popover=b,a.fn.popover.Constructor=c,a.fn.popover.noConflict=function(){return a.fn.popover=d,this}}(jQuery),+function(a){"use strict";function b(c,d){this.$body=a(document.body),this.$scrollElement=a(a(c).is(document.body)?window:c),this.options=a.extend({},b.DEFAULTS,d),this.selector=(this.options.target||"")+" .nav li > a",this.offsets=[],this.targets=[],this.activeTarget=null,this.scrollHeight=0,this.$scrollElement.on("scroll.bs.scrollspy",a.proxy(this.process,this)),this.refresh(),this.process()}function c(c){return this.each(function(){var d=a(this),e=d.data("bs.scrollspy"),f="object"==typeof c&&c;e||d.data("bs.scrollspy",e=new b(this,f)),"string"==typeof c&&e[c]()})}b.VERSION="3.3.6",b.DEFAULTS={offset:10},b.prototype.getScrollHeight=function(){return this.$scrollElement[0].scrollHeight||Math.max(this.$body[0].scrollHeight,document.documentElement.scrollHeight)},b.prototype.refresh=function(){var b=this,c="offset",d=0;this.offsets=[],this.targets=[],this.scrollHeight=this.getScrollHeight(),a.isWindow(this.$scrollElement[0])||(c="position",d=this.$scrollElement.scrollTop()),this.$body.find(this.selector).map(function(){var b=a(this),e=b.data("target")||b.attr("href"),f=/^#./.test(e)&&a(e);return f&&f.length&&f.is(":visible")&&[[f[c]().top+d,e]]||null}).sort(function(a,b){return a[0]-b[0]}).each(function(){b.offsets.push(this[0]),b.targets.push(this[1])})},b.prototype.process=function(){var a,b=this.$scrollElement.scrollTop()+this.options.offset,c=this.getScrollHeight(),d=this.options.offset+c-this.$scrollElement.height(),e=this.offsets,f=this.targets,g=this.activeTarget;if(this.scrollHeight!=c&&this.refresh(),b>=d)return g!=(a=f[f.length-1])&&this.activate(a);if(g&&b=e[a]&&(void 0===e[a+1]||b .dropdown-menu > .active").removeClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!1),b.addClass("active").find('[data-toggle="tab"]').attr("aria-expanded",!0),h?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu").length&&b.closest("li.dropdown").addClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!0),e&&e()}var g=d.find("> .active"),h=e&&a.support.transition&&(g.length&&g.hasClass("fade")||!!d.find("> .fade").length);g.length&&h?g.one("bsTransitionEnd",f).emulateTransitionEnd(c.TRANSITION_DURATION):f(),g.removeClass("in")};var d=a.fn.tab;a.fn.tab=b,a.fn.tab.Constructor=c,a.fn.tab.noConflict=function(){return a.fn.tab=d,this};var e=function(c){c.preventDefault(),b.call(a(this),"show")};a(document).on("click.bs.tab.data-api",'[data-toggle="tab"]',e).on("click.bs.tab.data-api",'[data-toggle="pill"]',e)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof b&&b;e||d.data("bs.affix",e=new c(this,f)),"string"==typeof b&&e[b]()})}var c=function(b,d){this.options=a.extend({},c.DEFAULTS,d),this.$target=a(this.options.target).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(b),this.affixed=null,this.unpin=null,this.pinnedOffset=null,this.checkPosition()};c.VERSION="3.3.6",c.RESET="affix affix-top affix-bottom",c.DEFAULTS={offset:0,target:window},c.prototype.getState=function(a,b,c,d){var e=this.$target.scrollTop(),f=this.$element.offset(),g=this.$target.height();if(null!=c&&"top"==this.affixed)return c>e?"top":!1;if("bottom"==this.affixed)return null!=c?e+this.unpin<=f.top?!1:"bottom":a-d>=e+g?!1:"bottom";var h=null==this.affixed,i=h?e:f.top,j=h?g:b;return null!=c&&c>=e?"top":null!=d&&i+j>=a-d?"bottom":!1},c.prototype.getPinnedOffset=function(){if(this.pinnedOffset)return this.pinnedOffset;this.$element.removeClass(c.RESET).addClass("affix");var a=this.$target.scrollTop(),b=this.$element.offset();return this.pinnedOffset=b.top-a},c.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},c.prototype.checkPosition=function(){if(this.$element.is(":visible")){var b=this.$element.height(),d=this.options.offset,e=d.top,f=d.bottom,g=Math.max(a(document).height(),a(document.body).height());"object"!=typeof d&&(f=e=d),"function"==typeof e&&(e=d.top(this.$element)),"function"==typeof f&&(f=d.bottom(this.$element));var h=this.getState(g,b,e,f);if(this.affixed!=h){null!=this.unpin&&this.$element.css("top","");var i="affix"+(h?"-"+h:""),j=a.Event(i+".bs.affix");if(this.$element.trigger(j),j.isDefaultPrevented())return;this.affixed=h,this.unpin="bottom"==h?this.getPinnedOffset():null,this.$element.removeClass(c.RESET).addClass(i).trigger(i.replace("affix","affixed")+".bs.affix")}"bottom"==h&&this.$element.offset({top:g-b-f})}};var d=a.fn.affix;a.fn.affix=b,a.fn.affix.Constructor=c,a.fn.affix.noConflict=function(){return a.fn.affix=d,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var c=a(this),d=c.data();d.offset=d.offset||{},null!=d.offsetBottom&&(d.offset.bottom=d.offsetBottom),null!=d.offsetTop&&(d.offset.top=d.offsetTop),b.call(c,d)})})}(jQuery); -------------------------------------------------------------------------------- /log-collection/src/main/resources/static/js/html5shiv.js: -------------------------------------------------------------------------------- 1 | /* 2 | HTML5 Shiv v3.7.0 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | (function(l,f){function m(){var a=e.elements;return"string"==typeof a?a.split(" "):a}function i(a){var b=n[a[o]];b||(b={},h++,a[o]=h,n[h]=b);return b}function p(a,b,c){b||(b=f);if(g)return b.createElement(a);c||(c=i(b));b=c.cache[a]?c.cache[a].cloneNode():r.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);return b.canHaveChildren&&!s.test(a)?c.frag.appendChild(b):b}function t(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag(); 5 | a.createElement=function(c){return!e.shivMethods?b.createElem(c):p(c,a,b)};a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/[\w\-]+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");return n}")(e,b.frag)}function q(a){a||(a=f);var b=i(a);if(e.shivCSS&&!j&&!b.hasCSS){var c,d=a;c=d.createElement("p");d=d.getElementsByTagName("head")[0]||d.documentElement;c.innerHTML="x"; 6 | c=d.insertBefore(c.lastChild,d.firstChild);b.hasCSS=!!c}g||t(a,b);return a}var k=l.html5||{},s=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,r=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,j,o="_html5shiv",h=0,n={},g;(function(){try{var a=f.createElement("a");a.innerHTML="";j="hidden"in a;var b;if(!(b=1==a.childNodes.length)){f.createElement("a");var c=f.createDocumentFragment();b="undefined"==typeof c.cloneNode|| 7 | "undefined"==typeof c.createDocumentFragment||"undefined"==typeof c.createElement}g=b}catch(d){g=j=!0}})();var e={elements:k.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output progress section summary template time video",version:"3.7.0",shivCSS:!1!==k.shivCSS,supportsUnknownElements:g,shivMethods:!1!==k.shivMethods,type:"default",shivDocument:q,createElement:p,createDocumentFragment:function(a,b){a||(a=f); 8 | if(g)return a.createDocumentFragment();for(var b=b||i(a),c=b.frag.cloneNode(),d=0,e=m(),h=e.length;d #mq-test-1 { width: 42px; }',c.insertBefore(e,d),b=42===f.offsetWidth,c.removeChild(e),{matches:b,media:a}}}(a.document)}(this),function(a){"use strict";function b(){u(!0)}var c={};a.respond=c,c.update=function(){};var d=[],e=function(){var b=!1;try{b=new a.XMLHttpRequest}catch(c){b=new a.ActiveXObject("Microsoft.XMLHTTP")}return function(){return b}}(),f=function(a,b){var c=e();c&&(c.open("GET",a,!0),c.onreadystatechange=function(){4!==c.readyState||200!==c.status&&304!==c.status||b(c.responseText)},4!==c.readyState&&c.send(null))};if(c.ajax=f,c.queue=d,c.regex={media:/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi,keyframes:/@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi,urls:/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,findStyles:/@media *([^\{]+)\{([\S\s]+?)$/,only:/(only\s+)?([a-zA-Z]+)\s?/,minw:/\([\s]*min\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/,maxw:/\([\s]*max\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/},c.mediaQueriesSupported=a.matchMedia&&null!==a.matchMedia("only all")&&a.matchMedia("only all").matches,!c.mediaQueriesSupported){var g,h,i,j=a.document,k=j.documentElement,l=[],m=[],n=[],o={},p=30,q=j.getElementsByTagName("head")[0]||k,r=j.getElementsByTagName("base")[0],s=q.getElementsByTagName("link"),t=function(){var a,b=j.createElement("div"),c=j.body,d=k.style.fontSize,e=c&&c.style.fontSize,f=!1;return b.style.cssText="position:absolute;font-size:1em;width:1em",c||(c=f=j.createElement("body"),c.style.background="none"),k.style.fontSize="100%",c.style.fontSize="100%",c.appendChild(b),f&&k.insertBefore(c,k.firstChild),a=b.offsetWidth,f?k.removeChild(c):c.removeChild(b),k.style.fontSize=d,e&&(c.style.fontSize=e),a=i=parseFloat(a)},u=function(b){var c="clientWidth",d=k[c],e="CSS1Compat"===j.compatMode&&d||j.body[c]||d,f={},o=s[s.length-1],r=(new Date).getTime();if(b&&g&&p>r-g)return a.clearTimeout(h),h=a.setTimeout(u,p),void 0;g=r;for(var v in l)if(l.hasOwnProperty(v)){var w=l[v],x=w.minw,y=w.maxw,z=null===x,A=null===y,B="em";x&&(x=parseFloat(x)*(x.indexOf(B)>-1?i||t():1)),y&&(y=parseFloat(y)*(y.indexOf(B)>-1?i||t():1)),w.hasquery&&(z&&A||!(z||e>=x)||!(A||y>=e))||(f[w.media]||(f[w.media]=[]),f[w.media].push(m[w.rules]))}for(var C in n)n.hasOwnProperty(C)&&n[C]&&n[C].parentNode===q&&q.removeChild(n[C]);n.length=0;for(var D in f)if(f.hasOwnProperty(D)){var E=j.createElement("style"),F=f[D].join("\n");E.type="text/css",E.media=D,q.insertBefore(E,o.nextSibling),E.styleSheet?E.styleSheet.cssText=F:E.appendChild(j.createTextNode(F)),n.push(E)}},v=function(a,b,d){var e=a.replace(c.regex.keyframes,"").match(c.regex.media),f=e&&e.length||0;b=b.substring(0,b.lastIndexOf("/"));var g=function(a){return a.replace(c.regex.urls,"$1"+b+"$2$3")},h=!f&&d;b.length&&(b+="/"),h&&(f=1);for(var i=0;f>i;i++){var j,k,n,o;h?(j=d,m.push(g(a))):(j=e[i].match(c.regex.findStyles)&&RegExp.$1,m.push(RegExp.$2&&g(RegExp.$2))),n=j.split(","),o=n.length;for(var p=0;o>p;p++)k=n[p],l.push({media:k.split("(")[0].match(c.regex.only)&&RegExp.$2||"all",rules:m.length-1,hasquery:k.indexOf("(")>-1,minw:k.match(c.regex.minw)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:k.match(c.regex.maxw)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}u()},w=function(){if(d.length){var b=d.shift();f(b.href,function(c){v(c,b.href,b.media),o[b.href]=!0,a.setTimeout(function(){w()},0)})}},x=function(){for(var b=0;by;c=p<=y?++b:--b){r=e.charAt(c);if(r===t.NULL){break}i+=r}}return new n(o,a,i)};n.unmarshall=function(n){var i;return function(){var r,o,s,u;s=n.split(RegExp(""+t.NULL+t.LF+"*"));u=[];for(r=0,o=s.length;r0){u.push(e(i))}}return u}()};n.marshall=function(e,i,r){var o;o=new n(e,i,r);return o.toString()+t.NULL};return n}();e=function(){var e;function r(t){this.ws=t;this.ws.binaryType="arraybuffer";this.counter=0;this.connected=false;this.heartbeat={outgoing:1e4,incoming:1e4};this.maxWebSocketFrameSize=16*1024;this.subscriptions={}}r.prototype.debug=function(t){var e;return typeof window!=="undefined"&&window!==null?(e=window.console)!=null?e.log(t):void 0:void 0};e=function(){if(Date.now){return Date.now()}else{return(new Date).valueOf}};r.prototype._transmit=function(t,e,i){var r;r=n.marshall(t,e,i);if(typeof this.debug==="function"){this.debug(">>> "+r)}while(true){if(r.length>this.maxWebSocketFrameSize){this.ws.send(r.substring(0,this.maxWebSocketFrameSize));r=r.substring(this.maxWebSocketFrameSize);if(typeof this.debug==="function"){this.debug("remaining = "+r.length)}}else{return this.ws.send(r)}}};r.prototype._setupHeartbeat=function(n){var r,o,s,u,a,c;if((a=n.version)!==i.VERSIONS.V1_1&&a!==i.VERSIONS.V1_2){return}c=function(){var t,e,i,r;i=n["heart-beat"].split(",");r=[];for(t=0,e=i.length;t>> PING"):void 0}}(this))}if(!(this.heartbeat.incoming===0||o===0)){s=Math.max(this.heartbeat.incoming,o);if(typeof this.debug==="function"){this.debug("check PONG every "+s+"ms")}return this.ponger=i.setInterval(s,function(t){return function(){var n;n=e()-t.serverActivity;if(n>s*2){if(typeof t.debug==="function"){t.debug("did not receive server activity for the last "+n+"ms")}return t.ws.close()}}}(this))}};r.prototype._parseConnect=function(){var t,e,n,i;t=1<=arguments.length?o.call(arguments,0):[];i={};switch(t.length){case 2:i=t[0],e=t[1];break;case 3:if(t[1]instanceof Function){i=t[0],e=t[1],n=t[2]}else{i.login=t[0],i.passcode=t[1],e=t[2]}break;case 4:i.login=t[0],i.passcode=t[1],e=t[2],n=t[3];break;default:i.login=t[0],i.passcode=t[1],e=t[2],n=t[3],i.host=t[4]}return[i,e,n]};r.prototype.connect=function(){var r,s,u,a;r=1<=arguments.length?o.call(arguments,0):[];a=this._parseConnect.apply(this,r);u=a[0],this.connectCallback=a[1],s=a[2];if(typeof this.debug==="function"){this.debug("Opening Web Socket...")}this.ws.onmessage=function(i){return function(r){var o,u,a,c,f,h,l,p,d,g,b,m;c=typeof ArrayBuffer!=="undefined"&&r.data instanceof ArrayBuffer?(o=new Uint8Array(r.data),typeof i.debug==="function"?i.debug("--- got data length: "+o.length):void 0,function(){var t,e,n;n=[];for(t=0,e=o.length;t 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | 18 | 日志采集系统 19 | 20 | 21 | 22 |
23 | 37 | 38 |
39 |
40 |
41 |
42 |

43 |
44 |
45 |
46 |
47 |
48 | 49 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /ngrok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bestfeel/gizwits-iot-course/c9383f955bc9201fc5971ffa4e94c501caa44e7b/ngrok -------------------------------------------------------------------------------- /python-ngrok.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: UTF-8 -*- 3 | # 建议Python 2.7.13 或 Python 3.1 以上运行 4 | # Version: v1.41 5 | import socket 6 | import ssl 7 | import json 8 | import struct 9 | import random 10 | import sys 11 | import time 12 | import logging 13 | import threading 14 | 15 | host = 'server.ngrok.cc' # Ngrok服务器地址 16 | port = 4443 # 端口 17 | bufsize = 1024 # 吞吐量 18 | 19 | Tunnels = list() # 全局渠道赋值 20 | body = dict() #一个隧道 21 | ''' 22 | 参数说明 23 | protocol 协议:tcp、http 24 | hostname 自定义域名,平台上选择自定义域名的时候填写,需要和平台上的一致 25 | subdomain 前置域名,平台上选择前置域名的时候填写,需要和平台上的一致 26 | rport 远程端口,TCP模式使用,需要和平台上的一致 27 | lhost 映射的ip地址,本机使用127.0.0.1,可以是局域网其他ip,如果在自己电脑映射路由器 192.168.1.1 28 | lport 映射端口,修改成自己要映射的端口,例如80,或者22 29 | 30 | 如果需要同时启动多个隧道则 31 | ''' 32 | body['protocol'] = 'http' 33 | body['hostname'] = 'www.baidu.com' 34 | body['subdomain'] = '' 35 | body['rport'] = 0 36 | body['lhost'] = '127.0.0.1' 37 | body['lport'] = 80 38 | 39 | # 启动多个隧道 40 | body1 = dict(); 41 | body1['protocol'] = 'http' 42 | body1['hostname'] = '' 43 | body1['subdomain'] = 'test' 44 | body1['rport'] = 0 45 | body1['lhost'] = '127.0.0.1' 46 | body1['lport'] = 80 47 | Tunnels.append(body) # 加入渠道队列 48 | Tunnels.append(body1) # 加入渠道队列 49 | 50 | 51 | mainsocket = 0 52 | 53 | ClientId = '' 54 | pingtime = 0 55 | 56 | def getloacladdr(Tunnels, Url): 57 | protocol = Url[0:Url.find(':')] 58 | hostname = Url[Url.find('//') + 2:] 59 | subdomain = hostname[0:hostname.find('.')] 60 | rport = Url[Url.rfind(':') + 1:] 61 | 62 | for tunnelinfo in Tunnels: 63 | if tunnelinfo.get('protocol') == protocol: 64 | if tunnelinfo.get('hostname') == hostname: 65 | return tunnelinfo 66 | if tunnelinfo.get('subdomain') == subdomain: 67 | return tunnelinfo 68 | if tunnelinfo.get('protocol') == 'tcp': 69 | if tunnelinfo.get('rport') == int(rport): 70 | return tunnelinfo 71 | 72 | return dict() 73 | 74 | def dnsopen(host): 75 | try: 76 | ip = socket.gethostbyname(host) 77 | except socket.error: 78 | return False 79 | 80 | return ip 81 | 82 | def connectremote(host, port): 83 | try: 84 | host = socket.gethostbyname(host) 85 | client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 86 | ssl_client = ssl.wrap_socket(client, ssl_version=ssl.PROTOCOL_SSLv23) 87 | ssl_client.connect((host, port)) 88 | ssl_client.setblocking(1) 89 | logger = logging.getLogger('%s:%d' % ('Conn', ssl_client.fileno())) 90 | logger.debug('New connection to: %s:%d' % (host, port)) 91 | except socket.error: 92 | return False 93 | 94 | return ssl_client 95 | 96 | def connectlocal(localhost, localport): 97 | try: 98 | localhost = socket.gethostbyname(localhost) 99 | client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 100 | client.connect((localhost, localport)) 101 | client.setblocking(1) 102 | logger = logging.getLogger('%s:%d' % ('Conn', client.fileno())) 103 | logger.debug('New connection to: %s:%d' % (localhost, localport)) 104 | except socket.error: 105 | return False 106 | 107 | return client 108 | 109 | def NgrokAuth(): 110 | Payload = dict() 111 | Payload['ClientId'] = '' 112 | Payload['OS'] = 'darwin' 113 | Payload['Arch'] = 'amd64' 114 | Payload['Version'] = '2' 115 | Payload['MmVersion'] = '1.7' 116 | Payload['User'] = 'user' 117 | Payload['Password'] = '' 118 | body = dict() 119 | body['Type'] = 'Auth' 120 | body['Payload'] = Payload 121 | buffer = json.dumps(body) 122 | return(buffer) 123 | 124 | def ReqTunnel(Protocol, Hostname, Subdomain, RemotePort): 125 | Payload = dict() 126 | Payload['ReqId'] = getRandChar(8) 127 | Payload['Protocol'] = Protocol 128 | Payload['Hostname'] = Hostname 129 | Payload['Subdomain'] = Subdomain 130 | Payload['HttpAuth'] = '' 131 | Payload['RemotePort'] = RemotePort 132 | body = dict() 133 | body['Type'] = 'ReqTunnel' 134 | body['Payload'] = Payload 135 | buffer = json.dumps(body) 136 | return(buffer) 137 | 138 | def RegProxy(ClientId): 139 | Payload = dict() 140 | Payload['ClientId'] = ClientId 141 | body = dict() 142 | body['Type'] = 'RegProxy' 143 | body['Payload'] = Payload 144 | buffer = json.dumps(body) 145 | return(buffer) 146 | 147 | def Ping(): 148 | Payload = dict() 149 | body = dict() 150 | body['Type'] = 'Ping' 151 | body['Payload'] = Payload 152 | buffer = json.dumps(body) 153 | return(buffer) 154 | 155 | def lentobyte(len): 156 | return struct.pack(' 0: 205 | if not recvbuf: 206 | recvbuf = recvbut 207 | else: 208 | recvbuf += recvbut 209 | 210 | if type == 1 or (type == 2 and linkstate == 1): 211 | lenbyte = tolen(recvbuf[0:8]) 212 | if len(recvbuf) >= (8 + lenbyte): 213 | buf = recvbuf[8:lenbyte + 8].decode('utf-8') 214 | logger = logging.getLogger('%s:%d' % ('Recv', sock.fileno())) 215 | logger.debug('Reading message with length: %d' % len(buf)) 216 | logger.debug('Read message: %s' % buf) 217 | js = json.loads(buf) 218 | if type == 1: 219 | if js['Type'] == 'ReqProxy': 220 | newsock = connectremote(host, port) 221 | if newsock: 222 | thread = threading.Thread(target = HKClient, args = (newsock, 0, 2)) 223 | thread.setDaemon(True) 224 | thread.start() 225 | if js['Type'] == 'AuthResp': 226 | ClientId = js['Payload']['ClientId'] 227 | logger = logging.getLogger('%s' % 'client') 228 | logger.info('Authenticated with server, client id: %s' % ClientId) 229 | sendpack(sock, Ping()) 230 | pingtime = time.time() 231 | for tunnelinfo in Tunnels: 232 | # 注册通道 233 | sendpack(sock, ReqTunnel(tunnelinfo['protocol'], tunnelinfo['hostname'], tunnelinfo['subdomain'], tunnelinfo['rport'])) 234 | if js['Type'] == 'NewTunnel': 235 | if js['Payload']['Error'] != '': 236 | logger = logging.getLogger('%s' % 'client') 237 | logger.error('Server failed to allocate tunnel: %s' % js['Payload']['Error']) 238 | time.sleep(30) 239 | else: 240 | logger = logging.getLogger('%s' % 'client') 241 | logger.info('Tunnel established at %s' % js['Payload']['Url']) 242 | if type == 2: 243 | if linkstate == 1: 244 | if js['Type'] == 'StartProxy': 245 | loacladdr = getloacladdr(Tunnels, js['Payload']['Url']) 246 | 247 | newsock = connectlocal(loacladdr['lhost'], loacladdr['lport']) 248 | if newsock: 249 | thread = threading.Thread(target = HKClient, args = (newsock, 0, 3, sock)) 250 | thread.setDaemon(True) 251 | thread.start() 252 | tosock = newsock 253 | linkstate = 2 254 | else: 255 | body = '

Tunnel %s unavailable

Unable to initiate connection to %s. This port is not yet available for web server.

' 256 | html = body % (js['Payload']['Url'], loacladdr['lhost'] + ':' + str(loacladdr['lport'])) 257 | header = "HTTP/1.0 502 Bad Gateway" + "\r\n" 258 | header += "Content-Type: text/html" + "\r\n" 259 | header += "Content-Length: %d" + "\r\n" 260 | header += "\r\n" + "%s" 261 | buf = header % (len(html.encode('utf-8')), html) 262 | sendbuf(sock, buf.encode('utf-8')) 263 | 264 | if len(recvbuf) == (8 + lenbyte): 265 | recvbuf = bytes() 266 | else: 267 | recvbuf = recvbuf[8 + lenbyte:] 268 | 269 | if type == 3 or (type == 2 and linkstate == 2): 270 | sendbuf(tosock, recvbuf) 271 | recvbuf = bytes() 272 | 273 | except socket.error: 274 | break 275 | 276 | if type == 1: 277 | mainsocket = False 278 | if type == 3: 279 | if tosock.fileno() != -1: 280 | tosock.shutdown(socket.SHUT_WR) 281 | 282 | logger = logging.getLogger('%s:%d' % ('Close', sock.fileno())) 283 | logger.debug('Closing') 284 | sock.close() 285 | 286 | # 客户端程序初始化 287 | if __name__ == '__main__': 288 | logging.basicConfig(level=logging.DEBUG, format='[%(asctime)s] [%(levelname)s:%(lineno)d] [%(name)s] %(message)s', datefmt='%Y/%m/%d %H:%M:%S') 289 | while True: 290 | try: 291 | # 检测控制连接是否连接. 292 | if mainsocket == False: 293 | ip = dnsopen(host) 294 | if ip == False: 295 | logging.info('update dns') 296 | time.sleep(10) 297 | continue 298 | mainsocket = connectremote(ip, port) 299 | if mainsocket == False: 300 | logging.info('connect failed...!') 301 | time.sleep(10) 302 | continue 303 | thread = threading.Thread(target = HKClient, args = (mainsocket, 0, 1)) 304 | thread.setDaemon(True) 305 | thread.start() 306 | 307 | # 发送心跳 308 | if pingtime + 20 < time.time() and pingtime != 0: 309 | sendpack(mainsocket, Ping()) 310 | pingtime = time.time() 311 | 312 | time.sleep(1) 313 | 314 | except socket.error: 315 | pingtime = 0 316 | except KeyboardInterrupt: 317 | sys.exit() 318 | -------------------------------------------------------------------------------- /smock.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | ./sunny clientid d8ef1acd4ddfa552 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /sunny: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bestfeel/gizwits-iot-course/c9383f955bc9201fc5971ffa4e94c501caa44e7b/sunny -------------------------------------------------------------------------------- /sunny.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bestfeel/gizwits-iot-course/c9383f955bc9201fc5971ffa4e94c501caa44e7b/sunny.exe --------------------------------------------------------------------------------