diff --git a/databases/v1.2/update.sql b/databases/v1.2/update.sql
index e16119b6..06e52f81 100644
--- a/databases/v1.2/update.sql
+++ b/databases/v1.2/update.sql
@@ -139,4 +139,116 @@ CREATE TABLE `user_tunnel` (
`create_time` datetime NULL COMMENT '创建时间',
`update_time` datetime NULL COMMENT '更新时间',
PRIMARY KEY (`id`)
-) COMMENT = '用户的通道';
\ No newline at end of file
+) COMMENT = '用户的通道';
+
+
+
+
+
+
+CREATE TABLE `orders` (
+ `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '订单id',
+ `order_no` varchar(22) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '订单号',
+ `user_id` bigint(20) NULL DEFAULT NULL COMMENT '用户id',
+ `resource_type` int(2) NULL DEFAULT NULL COMMENT '资源类型 1域名 2端口 3流量 4 充值',
+ `domain_id` bigint(22) NULL DEFAULT NULL COMMENT '资源id',
+ `amount` bigint(22) NULL DEFAULT NULL COMMENT '购买量 单位:秒、MB',
+ `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '资源名称',
+ `price_amount` decimal(12, 2) NULL DEFAULT NULL COMMENT '原价',
+ `discount_amount` decimal(12, 2) NULL DEFAULT NULL COMMENT '优惠金额',
+ `pay_amount` decimal(12, 2) NULL DEFAULT NULL COMMENT '支付价格',
+ `pay_type` int(1) NULL DEFAULT NULL COMMENT '支付方式 1余额 2支付宝',
+ `status` tinyint(2) NULL DEFAULT NULL COMMENT '订单状态 0待支付 1已支付 2 取消 3退款中 4已退款',
+ `trade_no` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '三方交易号',
+ `pay_time` datetime(0) NULL DEFAULT NULL COMMENT '支付时间',
+ `refund_time` datetime(0) NULL DEFAULT NULL COMMENT '退款时间',
+ `cancel_time` datetime(0) NULL DEFAULT NULL COMMENT '取消时间',
+ `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
+ `update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
+ PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
+
+
+ALTER TABLE `t_domain`
+ MODIFY COLUMN `sales_price` decimal(10, 2) NULL DEFAULT NULL COMMENT '销售价格(元/天)' AFTER `create_time`,
+ MODIFY COLUMN `original_price` decimal(10, 2) NULL DEFAULT NULL COMMENT '原价(元/天)' AFTER `sales_price`;
+
+
+
+ALTER TABLE `t_sys_users`
+ ADD COLUMN `user_admin` tinyint(1) NULL DEFAULT 0 COMMENT '是否后台用户 1是 0否' AFTER `activate_code`;
+
+update t_sys_users set user_admin = 0 ;
+
+-- 2022-07-31 忘记密码增加索引
+ALTER TABLE `t_user_forget`
+ ADD INDEX `idx_code`(`code`),
+ ADD INDEX `idx_email`(`email`);
+
+-- 2022-08-03 设备任意门文件服务器
+CREATE TABLE `t_device_door` (
+ `id` bigint(22) NOT NULL AUTO_INCREMENT COMMENT 'id',
+ `device_id` bigint(20) NULL DEFAULT NULL COMMENT '设备id',
+ `local_path` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '本地服务路径',
+ `server_path` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '服务端路径',
+ `enable` int(1) NULL DEFAULT 0 COMMENT '启用状态 1启用 0停用',
+ `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
+ `update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
+ PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '设备任意门' ROW_FORMAT = Dynamic;
+
+
+
+CREATE TABLE `device_peers` (
+ `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
+ `user_id` bigint(20) NULL DEFAULT NULL COMMENT '用户id',
+ `server_device_id` bigint(11) NULL DEFAULT NULL COMMENT '服务侧设备id',
+ `client_device_id` bigint(11) NULL DEFAULT NULL COMMENT '客户侧设备id',
+ `server_local_port` int(11) NULL DEFAULT NULL COMMENT '服务侧本地端口',
+ `client_proxy_port` int(11) NULL DEFAULT NULL COMMENT '客户侧代理端口',
+ `status` tinyint(1) NULL DEFAULT NULL COMMENT '状态 1启用 0禁用',
+ `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
+ `update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
+ PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
+
+
+ALTER TABLE `device_peers`
+ ADD COLUMN `app_name` varchar(200) NULL COMMENT 'p2pAppName' AFTER `user_id`;
+
+-- 2022-08-12 marker 新增特定IP
+ALTER TABLE `device_peers`
+ ADD COLUMN `server_local_host` varchar(20) NULL COMMENT '服务侧本地host' AFTER `server_local_port`,
+ ADD COLUMN `client_proxy_host` varchar(20) NULL COMMENT '客户侧代理host' AFTER `client_proxy_port`,
+ ADD COLUMN `remark` varchar(220) NULL COMMENT '备注' AFTER `client_proxy_host`;
+
+
+ALTER TABLE `device_peers` COMMENT = 'P2P映射';
+
+
+-- 2022-08-21 marker 设备socks5代理
+CREATE TABLE `device_proxy` (
+ `id` bigint(22) NOT NULL AUTO_INCREMENT COMMENT 'id',
+ `device_id` bigint(22) NULL DEFAULT NULL COMMENT '设备id',
+ `device_proxy_port` int(11) NULL DEFAULT NULL COMMENT '设备代理服务端口',
+ `domain_id` int(11) NULL DEFAULT NULL COMMENT '端口id',
+ `type` varchar(20) NULL DEFAULT NULL COMMENT '代理协议:http/https/socks5',
+ `status` tinyint(1) NULL DEFAULT NULL COMMENT '状态 1启用 0禁用',
+ `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
+ `update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
+ PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '设备代理' ROW_FORMAT = Dynamic;
+
+-- 2022-08-30 marker 数据收集的扩展字段
+ALTER TABLE `data_metrics`
+ ADD COLUMN `duration` int(11) NULL COMMENT '链接占用时长' AFTER `bytes_out`,
+ ADD COLUMN `open_time` datetime NULL COMMENT '打开链接时间' AFTER `duration`,
+ ADD COLUMN `close_time` datetime NULL COMMENT '关闭链接时间' AFTER `open_time`,
+ ADD COLUMN `remote_addr` varchar(24) NULL COMMENT '远端地址' AFTER `close_time`;
+-- 历史数据处理
+update data_metrics set duration = 0, open_time = create_time, close_time = create_time;
+
+
+-- 2022-08-31 marker 任意门新增domainid字段
+ALTER TABLE `t_device_door`
+ ADD COLUMN `domain_id` bigint(22) NULL COMMENT '域名id' AFTER `device_id`;
\ No newline at end of file
diff --git a/databases/v1.3/update.sql b/databases/v1.3/update.sql
index 9a9bb0c6..14916615 100644
--- a/databases/v1.3/update.sql
+++ b/databases/v1.3/update.sql
@@ -1,107 +1,18 @@
-CREATE TABLE `orders` (
- `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '订单id',
- `order_no` varchar(22) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '订单号',
- `user_id` bigint(20) NULL DEFAULT NULL COMMENT '用户id',
- `resource_type` int(2) NULL DEFAULT NULL COMMENT '资源类型 1域名 2端口 3流量 4 充值',
- `domain_id` bigint(22) NULL DEFAULT NULL COMMENT '资源id',
- `amount` bigint(22) NULL DEFAULT NULL COMMENT '购买量 单位:秒、MB',
- `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '资源名称',
- `price_amount` decimal(12, 2) NULL DEFAULT NULL COMMENT '原价',
- `discount_amount` decimal(12, 2) NULL DEFAULT NULL COMMENT '优惠金额',
- `pay_amount` decimal(12, 2) NULL DEFAULT NULL COMMENT '支付价格',
- `pay_type` int(1) NULL DEFAULT NULL COMMENT '支付方式 1余额 2支付宝',
- `status` tinyint(2) NULL DEFAULT NULL COMMENT '订单状态 0待支付 1已支付 2 取消 3退款中 4已退款',
- `trade_no` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '三方交易号',
- `pay_time` datetime(0) NULL DEFAULT NULL COMMENT '支付时间',
- `refund_time` datetime(0) NULL DEFAULT NULL COMMENT '退款时间',
- `cancel_time` datetime(0) NULL DEFAULT NULL COMMENT '取消时间',
- `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
- `update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
- PRIMARY KEY (`id`) USING BTREE
-) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
+-- 2022-09-05 marker 在线设备新增通道id
+ALTER TABLE `t_device_online`
+ ADD COLUMN `server_tunnel_id` int(11) NULL COMMENT '通道id' AFTER `client_version`,
+ MODIFY COLUMN `updateTime` datetime(0) NULL DEFAULT NULL COMMENT '更新时间' AFTER `client_version`;
-ALTER TABLE `t_domain`
- MODIFY COLUMN `sales_price` decimal(10, 2) NULL DEFAULT NULL COMMENT '销售价格(元/天)' AFTER `create_time`,
- MODIFY COLUMN `original_price` decimal(10, 2) NULL DEFAULT NULL COMMENT '原价(元/天)' AFTER `sales_price`;
+update t_device_online set server_tunnel_id =1;
+-- 2022-09-05 marker 在线设备新增设备信息
+ALTER TABLE `t_device_online`
+ ADD COLUMN `os` varchar(20) NULL COMMENT '操作系统' AFTER `server_tunnel_id`,
+ ADD COLUMN `arch` varchar(20) NULL COMMENT 'CPU架构' AFTER `os`;
-ALTER TABLE `t_sys_users`
- ADD COLUMN `user_admin` tinyint(1) NULL DEFAULT 0 COMMENT '是否后台用户 1是 0否' AFTER `activate_code`;
-update t_sys_users set user_admin = 0 ;
-
--- 2022-07-31 忘记密码增加索引
-ALTER TABLE `t_user_forget`
- ADD INDEX `idx_code`(`code`),
-ADD INDEX `idx_email`(`email`);
-
--- 2022-08-03 设备任意门文件服务器
-CREATE TABLE `t_device_door` (
- `id` bigint(22) NOT NULL AUTO_INCREMENT COMMENT 'id',
- `device_id` bigint(20) NULL DEFAULT NULL COMMENT '设备id',
- `local_path` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '本地服务路径',
- `server_path` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '服务端路径',
- `enable` int(1) NULL DEFAULT 0 COMMENT '启用状态 1启用 0停用',
- `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
- `update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
- PRIMARY KEY (`id`) USING BTREE
-) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '设备任意门' ROW_FORMAT = Dynamic;
-
-
-
-CREATE TABLE `device_peers` (
- `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
- `user_id` bigint(20) NULL DEFAULT NULL COMMENT '用户id',
- `server_device_id` bigint(11) NULL DEFAULT NULL COMMENT '服务侧设备id',
- `client_device_id` bigint(11) NULL DEFAULT NULL COMMENT '客户侧设备id',
- `server_local_port` int(11) NULL DEFAULT NULL COMMENT '服务侧本地端口',
- `client_proxy_port` int(11) NULL DEFAULT NULL COMMENT '客户侧代理端口',
- `status` tinyint(1) NULL DEFAULT NULL COMMENT '状态 1启用 0禁用',
- `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
- `update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
- PRIMARY KEY (`id`) USING BTREE
-) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-
-
-ALTER TABLE `device_peers`
- ADD COLUMN `app_name` varchar(200) NULL COMMENT 'p2pAppName' AFTER `user_id`;
-
--- 2022-08-12 marker 新增特定IP
-ALTER TABLE `device_peers`
- ADD COLUMN `server_local_host` varchar(20) NULL COMMENT '服务侧本地host' AFTER `server_local_port`,
- ADD COLUMN `client_proxy_host` varchar(20) NULL COMMENT '客户侧代理host' AFTER `client_proxy_port`,
- ADD COLUMN `remark` varchar(220) NULL COMMENT '备注' AFTER `client_proxy_host`;
-
-
-ALTER TABLE `device_peers` COMMENT = 'P2P映射';
-
-
--- 2022-08-21 marker 设备socks5代理
-CREATE TABLE `device_proxy` (
- `id` bigint(22) NOT NULL AUTO_INCREMENT COMMENT 'id',
- `device_id` bigint(22) NULL DEFAULT NULL COMMENT '设备id',
- `device_proxy_port` int(11) NULL DEFAULT NULL COMMENT '设备代理服务端口',
- `domain_id` int(11) NULL DEFAULT NULL COMMENT '端口id',
- `type` varchar(20) NULL DEFAULT NULL COMMENT '代理协议:http/https/socks5',
- `status` tinyint(1) NULL DEFAULT NULL COMMENT '状态 1启用 0禁用',
- `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
- `update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
- PRIMARY KEY (`id`) USING BTREE
-) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '设备代理' ROW_FORMAT = Dynamic;
-
--- 2022-08-30 marker 数据收集的扩展字段
-ALTER TABLE `data_metrics`
- ADD COLUMN `duration` int(11) NULL COMMENT '链接占用时长' AFTER `bytes_out`,
- ADD COLUMN `open_time` datetime NULL COMMENT '打开链接时间' AFTER `duration`,
- ADD COLUMN `close_time` datetime NULL COMMENT '关闭链接时间' AFTER `open_time`,
- ADD COLUMN `remote_addr` varchar(24) NULL COMMENT '远端地址' AFTER `close_time`;
--- 历史数据处理
-update data_metrics set duration = 0, open_time = create_time, close_time = create_time;
-
-
--- 2022-08-31 marker 任意门新增domainid字段
-ALTER TABLE `t_device_door`
- ADD COLUMN `domain_id` bigint(22) NULL COMMENT '域名id' AFTER `device_id`;
\ No newline at end of file
+ALTER TABLE `t_server_tunnel`
+ ADD COLUMN `status` int(2) NULL COMMENT '在线状态 1在线 0不在线' AFTER `buy_status`;
\ No newline at end of file
diff --git a/joggle-common/src/main/java/com/wuweibi/bullet/protocol/Message.java b/joggle-common/src/main/java/com/wuweibi/bullet/protocol/Message.java
index 2e2cb46d..030160fa 100644
--- a/joggle-common/src/main/java/com/wuweibi/bullet/protocol/Message.java
+++ b/joggle-common/src/main/java/com/wuweibi/bullet/protocol/Message.java
@@ -21,6 +21,9 @@ public abstract class Message {
public static final int DELIVER_RESP = 0x80000004;
public static final int REPORT = 0x5;
public static final int REPORT_RESP = 0x80000005;
+ public static final int GET_DEVICE_STATUS = 0x11;
+ public static final int GET_DEVICE_STATUS_RESP = 0x12;
+ public static final int DEVICE_DOWN = 0x13;
public static final int DEVICE_SECRET = 0x10000001;// 设备秘钥
public static final int LOG_MAPPING_STATUS = 0x10000010; // 日志开关消息
@@ -39,6 +42,11 @@ public abstract class Message {
public static final int AUTH_RESP = 0xa000001; //
+
+ //** 服务器管理端与服务端的消息
+ public static final int CONTROL_SERVER_WRAPPER = 1; // 管理端与服务器之间的消息
+ public static final int CONTROL_CLIENT_WRAPPER = 2; // 管理端与客户端之间的消息
+
//消息头
private MsgHead head;
diff --git a/joggle-common/src/main/java/com/wuweibi/bullet/protocol/MsgAuthResp.java b/joggle-common/src/main/java/com/wuweibi/bullet/protocol/MsgAuthResp.java
index 34c07c65..aa7f9787 100644
--- a/joggle-common/src/main/java/com/wuweibi/bullet/protocol/MsgAuthResp.java
+++ b/joggle-common/src/main/java/com/wuweibi/bullet/protocol/MsgAuthResp.java
@@ -12,7 +12,7 @@
/**
*
- * 客户端认证结果消息
+ * 客户端认证消息
*
* @author marker
* @create 2021-03-28 下午1:13
@@ -22,18 +22,18 @@ public class MsgAuthResp extends Message {
/**
- * error
+ * authToken
*/
- private String error;
+ private String clientNo;
/**
* 构造
*/
- public MsgAuthResp(String error) {
+ public MsgAuthResp(String clientNo) {
super(Message.AUTH_RESP);
- getHead().setLength(super.getLength() + error.length());
- this.error = error;
+ getHead().setLength(super.getLength() + clientNo.length());
+ this.clientNo = clientNo;
}
public MsgAuthResp() {
@@ -51,10 +51,10 @@ public void write(OutputStream out) throws IOException {
log.debug("send {}",this.toString());
// 写入authToken
- int len = error.getBytes().length;
+ int len = clientNo.getBytes().length;
byte bs[] = new byte[len];
- System.arraycopy(error.getBytes(), 0, bs, 0, len);
+ System.arraycopy(clientNo.getBytes(), 0, bs, 0, len);
out.write(bs);
out.flush();
}
@@ -65,12 +65,11 @@ public void read(InputStream in) throws IOException {
// 读取ip
byte bs[] = new byte[len];
in.read(bs);
- this.error = Utils.getString(bs, 0, len);
+ this.clientNo = Utils.getString(bs, 0, len);
}
- public String getError() {
- return error;
+ public String getClientNo() {
+ return clientNo;
}
-
}
diff --git a/joggle-common/src/main/java/com/wuweibi/bullet/protocol/MsgDeviceDown.java b/joggle-common/src/main/java/com/wuweibi/bullet/protocol/MsgDeviceDown.java
new file mode 100644
index 00000000..d0e65e86
--- /dev/null
+++ b/joggle-common/src/main/java/com/wuweibi/bullet/protocol/MsgDeviceDown.java
@@ -0,0 +1,73 @@
+package com.wuweibi.bullet.protocol;
+/**
+ * Created by marker on 2017/12/7.
+ */
+
+import com.wuweibi.bullet.utils.Utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * 设备下线消息
+ * @author marker
+ * @create 2017-12-07 下午1:13
+ **/
+public class MsgDeviceDown extends Message {
+
+
+ // deviceNo
+ private String deviceNo;
+
+
+
+ /**
+ * 构造
+ */
+ public MsgDeviceDown(String deviceNo) {
+ super(Message.DEVICE_DOWN);
+ this.deviceNo = deviceNo;
+ getHead().setLength(super.getLength() + deviceNo.length());
+ }
+
+ public MsgDeviceDown() {
+ super(Message.DEVICE_DOWN);
+ }
+
+ public MsgDeviceDown(MsgHead head) {
+ super(Message.DEVICE_DOWN, head);
+ }
+
+
+ @Override
+ public void write(OutputStream out) throws IOException {
+ getHead().write(out);
+ int len = deviceNo.getBytes().length;
+ // 写入IP地址
+ byte bs[] = new byte[len];
+ System.arraycopy(deviceNo.getBytes(), 0, bs, 0, len);
+ out.write(bs);
+ out.flush();
+ }
+
+ @Override
+ public void read(InputStream in) throws IOException {
+ // 读取deviceNo
+ int len = getHead().getLength() - 24;
+
+ byte bs[] = new byte[len];
+ in.read(bs);
+ this.deviceNo = Utils.getString(bs, 0, len);
+
+ }
+
+ public String getDeviceNo() {
+ return deviceNo;
+ }
+
+ public void setDeviceNo(String deviceNo) {
+ this.deviceNo = deviceNo;
+ getHead().setLength(super.getLength() + deviceNo.length());
+ }
+}
diff --git a/joggle-common/src/main/java/com/wuweibi/bullet/protocol/MsgGetDeviceStatus.java b/joggle-common/src/main/java/com/wuweibi/bullet/protocol/MsgGetDeviceStatus.java
new file mode 100644
index 00000000..9aab51fd
--- /dev/null
+++ b/joggle-common/src/main/java/com/wuweibi/bullet/protocol/MsgGetDeviceStatus.java
@@ -0,0 +1,39 @@
+package com.wuweibi.bullet.protocol;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * 获取设备状态消息
+ * 用于服务器与控制端的消息
+ *
+ * @author marker
+ **/
+public class MsgGetDeviceStatus extends Message {
+
+
+
+ /**
+ * 构造
+ */
+ public MsgGetDeviceStatus() {
+ super(Message.GET_DEVICE_STATUS);
+ }
+
+ public MsgGetDeviceStatus(MsgHead head) {
+ super(Message.GET_DEVICE_STATUS, head);
+ }
+
+
+ @Override
+ public void write(OutputStream out) throws IOException {
+ getHead().write(out);
+ out.flush();
+ }
+
+ @Override
+ public void read(InputStream in) throws IOException {
+
+ }
+}
diff --git a/joggle-common/src/main/java/com/wuweibi/bullet/protocol/MsgGetDeviceStatusResp.java b/joggle-common/src/main/java/com/wuweibi/bullet/protocol/MsgGetDeviceStatusResp.java
new file mode 100644
index 00000000..bb142a45
--- /dev/null
+++ b/joggle-common/src/main/java/com/wuweibi/bullet/protocol/MsgGetDeviceStatusResp.java
@@ -0,0 +1,50 @@
+package com.wuweibi.bullet.protocol;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * 获取设备状态消息
+ * 用于服务器与控制端的消息
+ *
+ * @author marker
+ **/
+public class MsgGetDeviceStatusResp extends Message {
+
+ private JSONObject data;
+
+ /**
+ * 构造
+ */
+ public MsgGetDeviceStatusResp() {
+ super(Message.GET_DEVICE_STATUS_RESP);
+ }
+
+ public MsgGetDeviceStatusResp(MsgHead head) {
+ super(Message.GET_DEVICE_STATUS_RESP, head);
+ }
+
+
+ @Override
+ public void write(OutputStream out) throws IOException {
+ getHead().write(out);
+ out.flush();
+ }
+
+ @Override
+ public void read(InputStream in) throws IOException {
+ int len = this.getLength() - MsgHead.HEAD_LENGTH;
+ byte bs[] = new byte[len];
+ in.read(bs);
+ this.data = JSON.parseObject(new String(bs));
+ }
+
+
+ public JSONObject getData() {
+ return data;
+ }
+}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/business/impl/OrderPayBizImpl.java b/joggle-server/src/main/java/com/wuweibi/bullet/business/impl/OrderPayBizImpl.java
index 4dacf56c..98c9e0ec 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/business/impl/OrderPayBizImpl.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/business/impl/OrderPayBizImpl.java
@@ -3,6 +3,7 @@
import com.wuweibi.bullet.business.OrderPayBiz;
import com.wuweibi.bullet.business.domain.OrderPayInfo;
+import com.wuweibi.bullet.domain2.domain.DomainDetail;
import com.wuweibi.bullet.domain2.entity.Domain;
import com.wuweibi.bullet.entity.api.R;
import com.wuweibi.bullet.exception.BaseException;
@@ -73,7 +74,7 @@ public R calculate(OrdersDTO ordersDTO) {
switch (resourceType){
case 1: // 域名
case 2: // 端口
- Domain domain = domainService.getById(resId);
+ DomainDetail domain = domainService.getDetail(resId);
// 校验域名是否存在
if(domain == null){
return R.fail(SystemErrorType.DOMAIN_NOT_FOUND);
@@ -95,7 +96,7 @@ public R calculate(OrdersDTO ordersDTO) {
String name = ResourceTypeEnum.toName(resourceType);
- orderPayInfo.setName(String.format("%s%s:%s", text, name ,domain.getDomain()));
+ orderPayInfo.setName(String.format("%s%s:%s", text, name , domain.getDomainFull()));
// 计算到期
Calendar calendar = Calendar.getInstance();
@@ -117,7 +118,7 @@ public R calculate(OrdersDTO ordersDTO) {
BigDecimal priceAmount = BigDecimal.valueOf(1.6);
payAmount = priceAmount.multiply(BigDecimal.valueOf(amount));
- orderPayInfo.setName(String.format("流量套餐:%dMB", amount));
+ orderPayInfo.setName(String.format("购买流量:%dMB", amount));
orderPayInfo.setPriceAmount(payAmount);
orderPayInfo.setPayAmount(payAmount);
orderPayInfo.setDiscountAmount(BigDecimal.ZERO);
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/client/service/impl/ClientVersionServiceImpl.java b/joggle-server/src/main/java/com/wuweibi/bullet/client/service/impl/ClientVersionServiceImpl.java
index 1d8d32af..8c4306aa 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/client/service/impl/ClientVersionServiceImpl.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/client/service/impl/ClientVersionServiceImpl.java
@@ -46,10 +46,11 @@ public int updateChecksumByOsArch(String version, String os, String arch, String
if (clientVersion == null) return 0;
// 生产环境才做URL更新
- if (SpringUtils.isProduction()) {
- String downloadURL = String.format("%s/client/%s/%s", aliOssProperties.getPublicServerUrl(), version, binFilePath);
- clientVersion.setDownloadUrl(downloadURL);
+ String downloadURL = String.format("%s/client/%s/%s", aliOssProperties.getPublicServerUrl(), version, binFilePath);
+ if (!SpringUtils.isProduction()) {
+ downloadURL = String.format("%s/client/%s/%s", "http://192.168.1.6:30974", version, binFilePath);
}
+ clientVersion.setDownloadUrl(downloadURL);
clientVersion.setChecksum(checksum);
clientVersion.setTitle(String.format("JoggleClient-v%s", version));
clientVersion.setVersion(version);
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/config/BeanConfig.java b/joggle-server/src/main/java/com/wuweibi/bullet/config/BeanConfig.java
index 261e4c40..0bbfe764 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/config/BeanConfig.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/config/BeanConfig.java
@@ -3,6 +3,7 @@
import com.alipay.easysdk.kernel.Config;
import com.wuweibi.bullet.config.properties.AlipayProperties;
import com.wuweibi.bullet.conn.CoonPool;
+import com.wuweibi.bullet.conn.WebsocketPool;
import com.wuweibi.bullet.utils.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
@@ -48,6 +49,11 @@ public CoonPool beanCoonPool() {
return new CoonPool();
}
+ @Bean
+ public WebsocketPool beanC2oonPool() {
+ return new WebsocketPool();
+ }
+
@Bean
public TaskExecutor beanTaskExecutor() {
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/config/WebSocketConfig.java b/joggle-server/src/main/java/com/wuweibi/bullet/config/WebSocketConfig.java
index 203544c5..8a21fbc3 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/config/WebSocketConfig.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/config/WebSocketConfig.java
@@ -1,5 +1,7 @@
package com.wuweibi.bullet.config;
+import com.wuweibi.bullet.config.properties.BulletConfig;
+import com.wuweibi.bullet.websocket.Bullet3Annotation;
import com.wuweibi.bullet.websocket.BulletAnnotation;
import com.wuweibi.bullet.websocket.LogAnnotation;
import com.wuweibi.bullet.websocket.VideoAnnotation;
@@ -8,6 +10,8 @@
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
+import javax.annotation.Resource;
+
/**
* WebSocket 配置
*
@@ -18,6 +22,8 @@
@EnableWebSocket
public class WebSocketConfig {
+ @Resource
+ private BulletConfig config;
@Bean
public ServerEndpointExporter serverEndpointExporter() {
@@ -35,6 +41,12 @@ public BulletAnnotation serverEndpointBulletAnnotation() {
}
+ @Bean
+ public Bullet3Annotation serverEndpointBullet3Annotation() {
+ return new Bullet3Annotation();
+ }
+
+
/**
* Video WebSocket接口
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/conn/CoonPool.java b/joggle-server/src/main/java/com/wuweibi/bullet/conn/CoonPool.java
index 25027290..55ec5e89 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/conn/CoonPool.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/conn/CoonPool.java
@@ -1,4 +1,5 @@
package com.wuweibi.bullet.conn;
+
import com.wuweibi.bullet.protocol.Message;
import com.wuweibi.bullet.websocket.BulletAnnotation;
import lombok.extern.slf4j.Slf4j;
@@ -143,16 +144,15 @@ public boolean exists(String deviceNo) {
* @param msg
*/
public void boradcast(String deviceNo, Message msg) {
-
- BulletAnnotation bulletAnnotation = this.getByDeviceNo(deviceNo);
- if(bulletAnnotation == null){
- return;
- }
- if(!bulletAnnotation.getSession().isOpen()){
- return;
- }
-
- bulletAnnotation.sendMessage(msg);
+// Bullet3Annotation bulletAnnotation = this.getByDeviceNo("1");
+// if(bulletAnnotation == null){
+// return;
+// }
+// if(!bulletAnnotation.getSession().isOpen()){
+// return;
+// }
+//
+// bulletAnnotation.sendMessage(msg);
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/conn/WebsocketPool.java b/joggle-server/src/main/java/com/wuweibi/bullet/conn/WebsocketPool.java
new file mode 100644
index 00000000..fc8c1dc5
--- /dev/null
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/conn/WebsocketPool.java
@@ -0,0 +1,151 @@
+package com.wuweibi.bullet.conn;
+
+import com.wuweibi.bullet.protocol.Message;
+import com.wuweibi.bullet.websocket.Bullet3Annotation;
+import lombok.extern.slf4j.Slf4j;
+
+import javax.websocket.Session;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ *
+ *
+ * @author marker
+ * 2018-01-10 下午9:12
+ **/
+@Slf4j
+public final class WebsocketPool {
+
+ /** 根据客户端缓存链接 */
+ public final Map clientConnections = new ConcurrentHashMap<>();
+
+
+ /**
+ * 新增一个链接
+ * @param conn 链接对象
+ */
+ public void addConnection(Bullet3Annotation conn){
+ String tunnelId = conn.getTunnelId().toString();
+ Bullet3Annotation bulletAnnotation = clientConnections.get(tunnelId);
+// if (bulletAnnotation != null) {
+// conn.stop(String.format("通道服务%s已注册,请修改配置", tunnelId));
+// return;
+// }
+ clientConnections.put(tunnelId, conn);
+ }
+
+
+ /**
+ * 移除一个链接
+ * @param conn 链接对象
+ * @param message
+ */
+ public void removeConnection(Bullet3Annotation conn, String message) {
+ if (conn == null) {
+ return;
+ }
+ String tunnelId = conn.getTunnelId().toString();
+ clientConnections.remove(tunnelId); // 直接全部移除
+ conn.stop(message);
+ }
+
+
+
+
+
+ /**
+ * 根据客户端ID获取一个可用的链接
+ * @param deviceNo 设备编号
+ * @return
+ */
+ @Deprecated
+ public Bullet3Annotation getByDeviceNo(String deviceNo) {
+ Bullet3Annotation bulletAnnotation = clientConnections.get(deviceNo);
+ return bulletAnnotation;
+ }
+
+ /**
+ * 根据通道id获取设备
+ * @param tunnelId 通道id
+ * @return
+ */
+ public Bullet3Annotation getByTunnelId(Integer tunnelId) {
+ Bullet3Annotation bulletAnnotation = clientConnections.get(tunnelId.toString());
+ return bulletAnnotation;
+ }
+
+
+
+
+
+ public DeviceStatus getDeviceStatusEnum(String deviceNo) {
+ Bullet3Annotation bulletAnnotation = this.clientConnections.get(deviceNo);
+ if(bulletAnnotation == null){
+ return DeviceStatus.OUTLINE;
+ }
+ Session session = bulletAnnotation.getSession();
+ return session.isOpen()? DeviceStatus.ONLINE:DeviceStatus.OUTLINE;
+ }
+
+
+ /**
+ * websoket链接数量
+ * @return
+ */
+ public Integer count() {
+ return clientConnections.size();
+ }
+
+
+ /**
+ * 全局
+ */
+ public void stop() {
+ Set sets = clientConnections.keySet();
+ for(String key : sets){
+ Bullet3Annotation bulletAnnotation = clientConnections.get(key);
+ bulletAnnotation.stop("批量下线");
+ }
+ }
+
+
+ /**
+ * 判断是否存在
+ * @param deviceNo
+ * @return
+ */
+ public boolean exists(String deviceNo) {
+ return clientConnections.containsKey(deviceNo);
+ }
+
+
+ /**
+ * 广播所有客户端 TODO
+ * @param deviceNo
+ * @param msg
+ */
+ public void boradcast(String deviceNo, Message msg) {
+ Bullet3Annotation bulletAnnotation = this.getByTunnelId( 1);
+ if (bulletAnnotation == null) {
+ return;
+ }
+ bulletAnnotation.sendMessage(deviceNo, msg);
+ }
+
+
+ /**
+ * 打印连接池信息
+ */
+ public void printDetailInfo(){
+ log.info("============= clientConnections size {} ============= ", this.clientConnections.size());
+ Set sets = this.clientConnections.keySet();
+ for(String key:sets){
+ Bullet3Annotation ba = this.clientConnections.get(key);
+ log.info("deviceNo={}, session[{}]", 1, ba.getSession().isOpen());
+ }
+ log.info("============= clientConnections size {} ============= ", this.clientConnections.size());
+ }
+
+}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/controller/BaseController.java b/joggle-server/src/main/java/com/wuweibi/bullet/controller/BaseController.java
deleted file mode 100644
index 50a6470c..00000000
--- a/joggle-server/src/main/java/com/wuweibi/bullet/controller/BaseController.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.wuweibi.bullet.controller;/**
- * Created by marker on 2017/12/9.
- */
-
-/**
- * @author marker
- * @create 2017-12-09 下午3:11
- **/
-public class BaseController {
-
-
-}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/controller/HomeController.java b/joggle-server/src/main/java/com/wuweibi/bullet/controller/HomeController.java
index ceb7c979..f4bc3d43 100755
--- a/joggle-server/src/main/java/com/wuweibi/bullet/controller/HomeController.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/controller/HomeController.java
@@ -1,10 +1,10 @@
package com.wuweibi.bullet.controller;
+import com.wuweibi.bullet.config.properties.BulletConfig;
import com.wuweibi.bullet.domain.vo.CountVO;
import com.wuweibi.bullet.entity.api.R;
import com.wuweibi.bullet.oauth2.manager.ResourceManager;
import com.wuweibi.bullet.service.CountService;
-import com.wuweibi.bullet.utils.ConfigUtils;
import com.wuweibi.bullet.utils.HttpUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@@ -44,6 +44,8 @@ public String home(HttpServletRequest request){
return "index";
}
+ @Resource
+ private BulletConfig bulletConfig;
/**
@@ -53,13 +55,16 @@ public String home(HttpServletRequest request){
@GetMapping("/api/open/init")
@ResponseBody
public R init(){
- String domain = ConfigUtils.getBulletDomain();
+ String websiteUrl = bulletConfig.getServerUrl();
+ String website = websiteUrl.substring(websiteUrl.indexOf("://")+3);
+
Map map = new HashMap(6);
- map.put("domain", domain);
- map.put("clientVersion", "v1.2.14");
+ map.put("website", website);
+ map.put("websiteUrl", websiteUrl);
+ map.put("clientVersion", "v1.3.0");
map.put("serverVersion", "v1.2.0");
map.put("dockerClientVersion", "0.0.7");
- map.put("apkClientVersion", "0.0.1");
+ map.put("apkClientVersion", "0.0.2");
resourceManager.loadResource();
return R.success(map);
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/controller/OpenController.java b/joggle-server/src/main/java/com/wuweibi/bullet/controller/OpenController.java
index 0e3cdc88..ca385ae3 100755
--- a/joggle-server/src/main/java/com/wuweibi/bullet/controller/OpenController.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/controller/OpenController.java
@@ -12,7 +12,7 @@
import com.wuweibi.bullet.domain.dto.ClientInfoDTO;
import com.wuweibi.bullet.domain.vo.ReleaseDetail;
import com.wuweibi.bullet.domain.vo.ReleaseInfo;
-import com.wuweibi.bullet.entity.Device;
+import com.wuweibi.bullet.device.entity.Device;
import com.wuweibi.bullet.domain2.entity.Domain;
import com.wuweibi.bullet.entity.User;
import com.wuweibi.bullet.entity.api.R;
@@ -208,6 +208,7 @@ public R activate(
*
* @return
*/
+ @Deprecated
@ApiOperation("设备秘钥校验【服务端调用校验】")
@RequestMapping(value = "/device/secret", method = RequestMethod.POST)
public R devicesecret(@RequestParam String clientNo,
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceController.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceController.java
index 750c7bcf..d4bb3e17 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceController.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceController.java
@@ -7,6 +7,7 @@
import com.wuweibi.bullet.annotation.JwtUser;
import com.wuweibi.bullet.config.swagger.annotation.WebApi;
import com.wuweibi.bullet.conn.CoonPool;
+import com.wuweibi.bullet.conn.WebsocketPool;
import com.wuweibi.bullet.core.builder.MapBuilder;
import com.wuweibi.bullet.device.domain.dto.DeviceDelDTO;
import com.wuweibi.bullet.device.domain.dto.DeviceSwitchLineDTO;
@@ -17,8 +18,7 @@
import com.wuweibi.bullet.device.service.ServerTunnelService;
import com.wuweibi.bullet.domain.domain.session.Session;
import com.wuweibi.bullet.domain.dto.DeviceDto;
-import com.wuweibi.bullet.domain.message.MessageFactory;
-import com.wuweibi.bullet.entity.Device;
+import com.wuweibi.bullet.device.entity.Device;
import com.wuweibi.bullet.entity.DeviceOnline;
import com.wuweibi.bullet.entity.api.R;
import com.wuweibi.bullet.exception.type.AuthErrorType;
@@ -32,22 +32,21 @@
import com.wuweibi.bullet.service.DeviceService;
import com.wuweibi.bullet.utils.HttpUtils;
import com.wuweibi.bullet.utils.StringUtil;
-import com.wuweibi.bullet.websocket.BulletAnnotation;
+import com.wuweibi.bullet.websocket.Bullet3Annotation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.Md5Crypt;
-import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.*;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
import java.util.stream.Collectors;
import static com.wuweibi.bullet.core.builder.MapBuilder.newMap;
@@ -68,6 +67,8 @@ public class DeviceController {
@Resource
private CoonPool coonPool;
+ @Resource
+ private WebsocketPool websocketPool;
/**
@@ -90,7 +91,7 @@ public class DeviceController {
*/
@ApiOperation("设备下拉列表")
@GetMapping("/options")
- public R> deviceOptions( ) {
+ public R> deviceOptions() {
Long userId = SecurityUtils.getUserId();
List list = deviceService.getOptionListByUserId(userId);
return R.ok(list);
@@ -103,47 +104,13 @@ public R> deviceOptions( ) {
*/
@ApiOperation("用户的设备列表")
@GetMapping
- public Object device( ) {
-
+ public R> device() {
Long userId = SecurityUtils.getUserId();
-
- List list = deviceService.listByMap(newMap(1)
- .setParam("userId", userId)
- .build());
-
- Iterator it = list.iterator();
-
- List deviceList = new ArrayList<>();
-
- while (it.hasNext()) {
- Device device = it.next();
-
- DeviceDto deviceDto = new DeviceDto(device);
- String deviceNo = device.getDeviceNo();
-
- int status = getStatus(deviceNo);
- deviceDto.setStatus(status);
- // TODO 性能问题
- DeviceOnline deviceOnline = deviceOnlineService.selectByDeviceNo(deviceNo);
- if (deviceOnline != null) {
- deviceDto.setIntranetIp(deviceOnline.getIntranetIp());
- deviceDto.setOnlineTime(deviceOnline.getUpdateTime());
- }
- deviceList.add(deviceDto);
- }
- return MessageFactory.get(deviceList);
+ List list = deviceService.getWebListByUserId(userId);
+ return R.ok(list);
}
- /**
- * 获取设备状态
- *
- * @param deviceCode
- * @return
- */
- private int getStatus(String deviceCode) {
- return coonPool.getDeviceStatus(deviceCode);
- }
/**
@@ -168,12 +135,12 @@ public R save(@RequestBody @Valid DeviceUpdateDTO dto) {
/**
- * 删除设备
+ * 删除设备 解绑
* @return
*/
@ApiOperation("删除设备")
@DeleteMapping(value = "")
- public Object delete(@JwtUser Session session,
+ public R delete(@JwtUser Session session,
@RequestBody @Valid DeviceDelDTO dto,
HttpServletRequest request) {
Long userId = session.getUserId();
@@ -182,29 +149,24 @@ public Object delete(@JwtUser Session session,
// 校验设备是否是他的
boolean status = deviceService.exists(userId, deviceId);
if (status) {
+ // 验证是否存在
Device device = deviceService.getById(deviceId);
+ DeviceOnline deviceOnline = deviceOnlineService.getByDeviceNo(device.getDeviceNo());
+ if (deviceOnline == null) {
+ return R.fail(SystemErrorType.DEVICE_NOT_ONLINE);
+ }
+ Bullet3Annotation bulletAnnotation = websocketPool.getByTunnelId(deviceOnline.getServerTunnelId());
+ if(bulletAnnotation != null){
+ MsgUnBind msg = new MsgUnBind();
+ bulletAnnotation.sendMessage(device.getDeviceNo(), msg);
+ }
// 删除映射
deviceMappingService.deleteByDeviceId(deviceId);
- deviceService.removeUserId(deviceId);
-
- try {
- BulletAnnotation bulletAnnotation = coonPool.getByDeviceNo(device.getDeviceNo());
- MsgUnBind msg = new MsgUnBind();
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- msg.write(outputStream);
- // 包装了Bullet协议的
- byte[] resultBytes = outputStream.toByteArray();
- ByteBuffer buf = ByteBuffer.wrap(resultBytes);
- bulletAnnotation.getSession().getBasicRemote().sendBinary(buf);
- // 停止ws链接
-// bulletAnnotation.stop("设备删除");
- } catch (Exception e) {
- log.error("{}", e.getMessage());
- }
+ deviceService.removeUserId(deviceId);
}
- return MessageFactory.getOperationSuccess();
+ return R.ok();
}
@@ -233,6 +195,12 @@ public R validate(String deviceId, HttpServletRequest request) {
if (device!= null && device.getUserId() != null) {
return R.fail(SystemErrorType.DEVICE_OTHER_BIND);
}
+
+ Bullet3Annotation annotation = websocketPool.getByTunnelId(deviceOnline.getServerTunnelId());
+ if (annotation == null) {
+ return R.fail("ngrokd实例不在线, 请联系管理员");
+ }
+
if (device == null) {
// 给当前用户存储最新的设备数据
device = new Device();
@@ -240,8 +208,6 @@ public R validate(String deviceId, HttpServletRequest request) {
device.setUserId(userId);
device.setCreateTime(new Date());
device.setName(deviceId);
- device.setMacAddr(deviceOnline.getMacAddr());
- device.setIntranetIp(deviceOnline.getIntranetIp());
}
// 限制普通用户绑定设备的数量10 排除自己的账号判断
@@ -254,29 +220,13 @@ public R validate(String deviceId, HttpServletRequest request) {
String deviceSecret = Md5Crypt.md5Crypt(deviceId.getBytes(), null, "");
device.setDeviceSecret(deviceSecret);
device.setUserId(userId);
-
deviceService.saveOrUpdate(device);
+
// 发送消息通知设备秘钥
+ MsgDeviceSecret msg = new MsgDeviceSecret();
+ msg.setSecret(deviceSecret);
+ annotation.sendMessage(deviceNo, msg);
- BulletAnnotation annotation = coonPool.getByDeviceNo(deviceNo);
- if (annotation != null) {
- MsgDeviceSecret msg = new MsgDeviceSecret();
- msg.setSecret(deviceSecret);
-
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- try {
- msg.write(outputStream);
- // 包装了Bullet协议的
- byte[] resultBytes = outputStream.toByteArray();
- ByteBuffer buf = ByteBuffer.wrap(resultBytes);
- annotation.getSession().getBasicRemote().sendBinary(buf);
-
- } catch (IOException e) {
- log.error("", e);
- } finally {
- IOUtils.closeQuietly(outputStream);
- }
- }
return R.success();
}
@@ -318,8 +268,10 @@ public R device(HttpServletRequest request, @RequestParam Long deviceId,
Long deviceUserId = deviceInfo.getLong("userId");
String deviceNo = deviceInfo.getString("deviceNo");
String serverAddr = deviceInfo.getString("serverAddr"); // 通道顶级地址
-
- if (!deviceUserId.equals(userId)) {
+ if(deviceNo == null){
+ return R.fail("设备不存在");
+ }
+ if (!userId.equals(deviceUserId)) {
return R.fail("设备不存在");
}
@@ -328,9 +280,8 @@ public R device(HttpServletRequest request, @RequestParam Long deviceId,
if (deviceOnline != null) {
deviceInfo.put("intranetIp", deviceOnline.getIntranetIp());
deviceInfo.put("clientVersion", deviceOnline.getClientVersion());
-
- int status = getStatus(deviceNo);
- deviceInfo.put("status", status);
+ deviceInfo.put("macAddr", deviceOnline.getMacAddr());
+ deviceInfo.put("status", deviceOnline.getStatus());
} else {
deviceInfo.put("clientVersion", "");
deviceInfo.put("status", -1);
@@ -346,22 +297,11 @@ public R device(HttpServletRequest request, @RequestParam Long deviceId,
.collect(Collectors.toList());
// 端口
-// QueryWrapper wrapper = new QueryWrapper();
-// wrapper.eq("userId", userId);
-// wrapper.eq("device_id", deviceId);
-// wrapper.in("protocol", 2, 5);
-// List portList = deviceMappingService.list(wrapper);
portList.forEach(item->{
item.setDomain(serverAddr + ":" + item.getRemotePort());
});
// 域名
-// QueryWrapper wrapper2 = new QueryWrapper();
-// wrapper2.eq("userId", userId);
-// wrapper2.eq("device_id", deviceId);
-// wrapper2.in("protocol", Arrays.asList(1, 3, 4));
-//
-// List domainList = deviceMappingService.list(wrapper2);
domainList.forEach(item -> {
if (StringUtil.isNotBlank(item.getHostname())) {
item.setDomain(item.getHostname());
@@ -408,11 +348,6 @@ public R WOL(@JwtUser Session session, String mac) {
public R discovery(HttpServletRequest request) {
String ip = HttpUtils.getRemoteIP(request);
List list = deviceService.getDiscoveryDevice(ip);
-
- // 筛选在线设备
- list = list.stream().filter(item-> coonPool.exists(item.getDeviceNo()))
- .collect(Collectors.toList());
-
return R.success(list);
}
@@ -452,28 +387,20 @@ public R switchLine(@JwtUser Session session,
Device device = deviceService.getById(deviceId);
String deviceNo = device.getDeviceNo();
- device.setServerTunnelId(dto.getServerTunnelId());
deviceService.updateById(device);
+ DeviceOnline deviceOnline = deviceOnlineService.getByDeviceNo(deviceNo);
+ if (deviceOnline == null) {
+ return R.fail(SystemErrorType.DEVICE_NOT_ONLINE);
+ }
+
// 发送切换消息给设备
- BulletAnnotation annotation = coonPool.getByDeviceNo(deviceNo);
+ Bullet3Annotation annotation = websocketPool.getByTunnelId(deviceOnline.getServerTunnelId());
if (annotation != null) {
MsgSwitchLine msg = new MsgSwitchLine();
msg.setDeviceNo(deviceNo);
msg.setServerAddr(serverTunnel.getServerAddr());
-
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- try {
- msg.write(outputStream);
- // 包装了Bullet协议的
- byte[] resultBytes = outputStream.toByteArray();
- ByteBuffer buf = ByteBuffer.wrap(resultBytes);
- annotation.getSession().getBasicRemote().sendBinary(buf);
- } catch (IOException e) {
- log.error("", e);
- } finally {
- IOUtils.closeQuietly(outputStream);
- }
+ annotation.sendMessage(deviceNo, msg);
}
return R.success();
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceDoorController.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceDoorController.java
index d766fefc..b0f8045e 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceDoorController.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceDoorController.java
@@ -3,14 +3,15 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
-import com.wuweibi.bullet.conn.CoonPool;
+import com.wuweibi.bullet.conn.WebsocketPool;
+import com.wuweibi.bullet.device.domain.DeviceDetail;
import com.wuweibi.bullet.device.domain.dto.DeviceDoorDTO;
import com.wuweibi.bullet.device.domain.vo.DeviceDoorVO;
import com.wuweibi.bullet.device.entity.DeviceDoor;
import com.wuweibi.bullet.device.service.DeviceDoorService;
import com.wuweibi.bullet.domain2.controller.DomainController;
import com.wuweibi.bullet.domain2.domain.DomainDetail;
-import com.wuweibi.bullet.entity.Device;
+import com.wuweibi.bullet.device.entity.Device;
import com.wuweibi.bullet.entity.DeviceMapping;
import com.wuweibi.bullet.entity.api.R;
import com.wuweibi.bullet.oauth2.utils.SecurityUtils;
@@ -19,7 +20,7 @@
import com.wuweibi.bullet.service.DeviceMappingService;
import com.wuweibi.bullet.service.DeviceService;
import com.wuweibi.bullet.service.DomainService;
-import com.wuweibi.bullet.websocket.BulletAnnotation;
+import com.wuweibi.bullet.websocket.Bullet3Annotation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@@ -55,7 +56,7 @@ public class DeviceDoorController {
private DomainService domainService;
@Resource
- private CoonPool coonPool;
+ private WebsocketPool coonPool;
@Resource
private DeviceMappingService deviceMappingService;
@@ -72,11 +73,12 @@ public class DeviceDoorController {
public R save(@RequestBody @Valid DeviceDoorDTO dto) {
Long userId = SecurityUtils.getUserId();
Long domainId = dto.getDomainId();
- Device device = deviceService.getById(dto.getDeviceId());
- if (device == null) {
+ DeviceDetail deviceDetail = deviceService.getDetail(dto.getDeviceId());
+ if (deviceDetail == null) {
return R.fail("设备不存在");
}
- if (!device.getUserId().equals(userId)) {
+ String deviceNo = deviceDetail.getDeviceNo();
+ if (!deviceDetail.getUserId().equals(userId)) {
return R.fail("设备不存在");
}
@@ -103,24 +105,20 @@ public R save(@RequestBody @Valid DeviceDoorDTO dto) {
return R.fail("域名已绑定");
}
-
-
-
boolean status = this.deviceDoorService.saveOrUpdate(deviceDoor);
// 设备发送消息开启任意门
- String deviceNo = device.getDeviceNo();
- BulletAnnotation annotation = coonPool.getByDeviceNo(deviceNo);
+ Bullet3Annotation annotation = coonPool.getByTunnelId(deviceDetail.getServerTunnelId());
if (annotation != null) {
DoorConfig doorConfig = new DoorConfig();
- doorConfig.setDeviceId(device.getId());
+ doorConfig.setDeviceId(deviceDetail.getId());
doorConfig.setLocalPath(deviceDoor.getLocalPath());
doorConfig.setServerPath(deviceDoor.getServerPath());
doorConfig.setEnable(deviceDoor.getEnable());
JSONObject data = (JSONObject) JSON.toJSON(doorConfig);
MsgDeviceDoor msg = new MsgDeviceDoor(data.toJSONString());
- annotation.sendMessage(msg);
+ annotation.sendMessage(deviceNo, msg);
}
// 调用绑定映射关系
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceMappingController.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceMappingController.java
index adbae93e..94797162 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceMappingController.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceMappingController.java
@@ -5,7 +5,8 @@
import com.alibaba.fastjson.JSONObject;
import com.wuweibi.bullet.annotation.JwtUser;
import com.wuweibi.bullet.config.swagger.annotation.WebApi;
-import com.wuweibi.bullet.conn.CoonPool;
+import com.wuweibi.bullet.conn.WebsocketPool;
+import com.wuweibi.bullet.device.domain.DeviceDetail;
import com.wuweibi.bullet.device.domain.dto.DeviceMappingDelDTO;
import com.wuweibi.bullet.domain.domain.session.Session;
import com.wuweibi.bullet.domain.message.MessageFactory;
@@ -19,16 +20,14 @@
import com.wuweibi.bullet.protocol.MsgMapping;
import com.wuweibi.bullet.protocol.MsgUnMapping;
import com.wuweibi.bullet.service.DeviceMappingService;
-import com.wuweibi.bullet.websocket.BulletAnnotation;
+import com.wuweibi.bullet.service.DeviceOnlineService;
+import com.wuweibi.bullet.service.DeviceService;
+import com.wuweibi.bullet.websocket.Bullet3Annotation;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.io.IOUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.nio.ByteBuffer;
import java.util.List;
import static com.wuweibi.bullet.core.builder.MapBuilder.newMap;
@@ -55,7 +54,7 @@ public class DeviceMappingController {
@Resource
- private CoonPool coonPool;
+ private WebsocketPool coonPool;
/**
@@ -72,32 +71,24 @@ public Object delete(@JwtUser Session session, @RequestBody DeviceMappingDelDTO
DeviceMapping entity = deviceMappingService.getById(dmId);
deviceMappingService.removeById(dmId);
- String deviceNo = deviceMappingService.getDeviceNo(entity.getDeviceId());
- if(!org.apache.commons.lang3.StringUtils.isBlank(deviceNo)){
- BulletAnnotation annotation = coonPool.getByDeviceNo(deviceNo);
- if(annotation != null){
- JSONObject data = (JSONObject)JSON.toJSON(entity);
- MsgUnMapping msg = new MsgUnMapping(data.toJSONString());
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- try {
- msg.write(outputStream);
- // 包装了Bullet协议的
- byte[] resultBytes = outputStream.toByteArray();
- ByteBuffer buf = ByteBuffer.wrap(resultBytes);
-
- annotation.getSession().getBasicRemote().sendBinary(buf);
-
- } catch (IOException e) {
- log.error("", e);
- } finally {
- IOUtils.closeQuietly(outputStream);
- }
- }
+ DeviceDetail deviceDetail = deviceService.getDetail(entity.getDeviceId());
+ if (deviceDetail == null) {
+ return R.fail("设备不存在");
+ }
+ String deviceNo = deviceDetail.getDeviceNo();
+ Bullet3Annotation annotation = coonPool.getByTunnelId(deviceDetail.getServerTunnelId());
+ if (annotation != null) {
+ JSONObject data = (JSONObject) JSON.toJSON(entity);
+ MsgUnMapping msg = new MsgUnMapping(data.toJSONString());
+ annotation.sendMessage(deviceNo, msg);
}
}
return MessageFactory.getOperationSuccess();
}
+ @Resource
+ private DeviceOnlineService deviceOnlineService;
+
/**
* 获取映射详情
@@ -162,43 +153,33 @@ public R save(DeviceMapping entity ){
deviceMappingService.save(entity);
}
+ DeviceDetail deviceDetail = deviceService.getDetail(entity.getDeviceId());
+ if (deviceDetail == null) {
+ return R.fail("设备不存在");
+ }
+ String deviceNo = deviceDetail.getDeviceNo();
- String deviceNo = deviceMappingService.getDeviceNo(entity.getDeviceId());
- if(!org.apache.commons.lang3.StringUtils.isBlank(deviceNo)){
- BulletAnnotation annotation = coonPool.getByDeviceNo(deviceNo);
- if(annotation == null){// 设备不在线
- return R.fail(SystemErrorType.DEVICE_NOT_ONLINE);
- }
-
- JSONObject data = (JSONObject)JSON.toJSON(entity);
-
- Message msg;
-
- if(entity.getStatus() == 1) { // 启用映射
- msg = new MsgMapping(data.toJSONString());
- } else {
- log.debug("设备 {} 停用 {} 映射", entity.getDeviceId(), entity.getId());
- msg = new MsgUnMapping(data.toJSONString());
- }
+ Bullet3Annotation annotation = coonPool.getByTunnelId(deviceDetail.getServerTunnelId());
+ if (annotation == null) {// 设备不在线
+ return R.fail(SystemErrorType.DEVICE_NOT_ONLINE);
+ }
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- try {
- msg.write(outputStream);
- // 包装了Bullet协议的
- byte[] resultBytes = outputStream.toByteArray();
- ByteBuffer buf = ByteBuffer.wrap(resultBytes);
-
- annotation.sendBinary(buf);
- } catch (IOException e) {
- log.error("", e);
- } finally {
- IOUtils.closeQuietly(outputStream);
- }
- return R.success();
+ JSONObject data = (JSONObject)JSON.toJSON(entity);
+ Message msg;
+ if (entity.getStatus() == 1) { // 启用映射
+ msg = new MsgMapping(data.toJSONString());
+ } else {
+ log.debug("设备 {} 停用 {} 映射", entity.getDeviceId(), entity.getId());
+ msg = new MsgUnMapping(data.toJSONString());
}
- return R.fail("服务器错误");
+ annotation.sendMessage(deviceNo, msg);
+
+ return R.success();
}
+ @Resource
+ private DeviceService deviceService;
+
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceOpenInnerController.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceOpenInnerController.java
new file mode 100644
index 00000000..2c2f25cd
--- /dev/null
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceOpenInnerController.java
@@ -0,0 +1,104 @@
+package com.wuweibi.bullet.device.controller;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.wuweibi.bullet.business.DeviceBiz;
+import com.wuweibi.bullet.config.properties.BulletConfig;
+import com.wuweibi.bullet.config.swagger.annotation.WebApi;
+import com.wuweibi.bullet.device.domain.dto.DeviceAuthDTO;
+import com.wuweibi.bullet.device.domain.dto.DeviceAuthVO;
+import com.wuweibi.bullet.device.domain.dto.DeviceOnlineInfoDTO;
+import com.wuweibi.bullet.device.entity.Device;
+import com.wuweibi.bullet.entity.api.R;
+import com.wuweibi.bullet.exception.type.SystemErrorType;
+import com.wuweibi.bullet.flow.service.UserFlowService;
+import com.wuweibi.bullet.metrics.service.DataMetricsService;
+import com.wuweibi.bullet.service.DeviceOnlineService;
+import com.wuweibi.bullet.service.DeviceService;
+import com.wuweibi.bullet.utils.CodeHelper;
+import com.wuweibi.bullet.utils.StringUtil;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import javax.validation.Valid;
+
+/**
+ * 数据收集(DataMetrics)表控制层
+ *
+ * @author marker
+ * @since 2021-11-07 14:17:51
+ */
+@Slf4j
+@WebApi
+@Api(tags = "设备认证")
+@RestController
+@RequestMapping("/inner/open/device")
+public class DeviceOpenInnerController {
+ /**
+ * 服务对象
+ */
+ @Resource
+ private DataMetricsService dataMetricsService;
+
+ @Resource
+ private DeviceService deviceService;
+
+ @Resource
+ private UserFlowService userFlowService;
+
+ @Resource
+ private BulletConfig bulletConfig;
+
+
+
+
+ @Resource
+ private DeviceBiz deviceBiz;
+
+
+
+ @ApiOperation("设备秘钥校验【服务端调用校验】")
+ @PostMapping(value = "/auth")
+ public R deviceSecret(@RequestBody @Valid DeviceAuthDTO deviceAuthDTO) {
+ String deviceNo = deviceAuthDTO.getDeviceNo();
+ QueryWrapper queryWrapper = new QueryWrapper();
+ queryWrapper.eq("deviceId", deviceNo);
+ Device device = deviceService.getOne(queryWrapper);
+ if (device != null && device.getUserId() != null) { // 设备存在且设备被绑定 强制校验秘钥
+ String deviceSecret = device.getDeviceSecret();
+ if (!deviceSecret.equals(deviceAuthDTO.getSecret())) { // 校验秘钥一致性
+ return R.fail(SystemErrorType.DEVICE_SECRET_ERROR);
+ }
+ }
+ // 其他情况认为设备是等待绑定状态
+ DeviceAuthVO authVO = new DeviceAuthVO();
+ if (StringUtil.isBlank(deviceNo)) {
+ deviceNo = CodeHelper.makeNewCode();
+ }
+ authVO.setDeviceNo(deviceNo);
+ // 设备在线
+ DeviceOnlineInfoDTO deviceOnlineInfoDTO = new DeviceOnlineInfoDTO();
+ deviceOnlineInfoDTO.setDeviceNo(deviceNo);
+ deviceOnlineInfoDTO.setPublicIp(deviceAuthDTO.getRemoteIpAddr());
+ deviceOnlineInfoDTO.setIntranetIp(deviceAuthDTO.getIpAddr());
+ deviceOnlineInfoDTO.setMacAddr(deviceAuthDTO.getMac());
+ deviceOnlineInfoDTO.setClientVersion(deviceAuthDTO.getVersion());
+ deviceOnlineInfoDTO.setOs(deviceAuthDTO.getOs());
+ deviceOnlineInfoDTO.setArch(deviceAuthDTO.getArch());
+ deviceOnlineInfoDTO.setServerTunnelId(deviceAuthDTO.getServerTunnelId());
+ deviceOnlineService.saveOrUpdate(deviceOnlineInfoDTO);
+
+ return R.ok(authVO);
+ }
+
+ @Resource
+ private DeviceOnlineService deviceOnlineService;
+
+
+}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DevicePeersController.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DevicePeersController.java
index 6fec156d..4d86ffb9 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DevicePeersController.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DevicePeersController.java
@@ -108,10 +108,12 @@ public R save(@RequestBody @Valid DevicePeersDTO dto) {
DevicePeers peers = this.devicePeersService.savePeers(userId, dto);
- DevicePeersConfigDTO devicePeersConfigDTO = this.devicePeersService.getPeersConfig(peers.getId());
-
+ DevicePeersConfigDTO dtoPeer = this.devicePeersService.getPeersConfig(peers.getId());
+ if (dtoPeer.getClientDeviceTunnelId() == null || dtoPeer.getServerDeviceTunnelId() == null) {
+ return R.fail("设备通道id错误,请确定设备状态");
+ }
// 发送peer消息
- devicePeersService.sendMsgPeerConfig(devicePeersConfigDTO);
+ devicePeersService.sendMsgPeerConfig(dtoPeer);
return R.ok();
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceProxyController.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceProxyController.java
index 81d9a2ce..5b80a7e3 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceProxyController.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/DeviceProxyController.java
@@ -9,7 +9,7 @@
import com.wuweibi.bullet.device.domain.DeviceProxyVO;
import com.wuweibi.bullet.device.entity.DeviceProxy;
import com.wuweibi.bullet.device.service.DeviceProxyService;
-import com.wuweibi.bullet.entity.Device;
+import com.wuweibi.bullet.device.entity.Device;
import com.wuweibi.bullet.entity.api.R;
import com.wuweibi.bullet.protocol.MsgProxy;
import com.wuweibi.bullet.protocol.domain.ProxyConfig;
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/ServerTunnelController.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/ServerTunnelController.java
index 8d1d3289..ad6a47a6 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/ServerTunnelController.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/controller/ServerTunnelController.java
@@ -1,13 +1,14 @@
package com.wuweibi.bullet.device.controller;
-import com.baomidou.mybatisplus.extension.api.ApiController;
import com.wuweibi.bullet.config.swagger.annotation.WebApi;
import com.wuweibi.bullet.device.domain.vo.ServerTunnelVO;
+import com.wuweibi.bullet.device.domain.vo.TunnelOption;
import com.wuweibi.bullet.device.entity.ServerTunnel;
import com.wuweibi.bullet.device.service.ServerTunnelService;
import com.wuweibi.bullet.entity.api.R;
import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -27,21 +28,35 @@
@Api(tags = "通道管理")
@RestController
@RequestMapping("/api/server/tunnel")
-public class ServerTunnelController extends ApiController {
+public class ServerTunnelController {
/**
* 服务对象
*/
@Resource
private ServerTunnelService serverTunnelService;
+
+ /**
+ * 设备列表
+ *
+ * @return
+ */
+ @ApiOperation("通道区域下拉列表")
+ @GetMapping("/options")
+ public R> deviceOptions() {
+ List list = serverTunnelService.getOptionList();
+ return R.ok(list);
+ }
+
/**
* 获取所有数据
+ *
* @return 所有数据
*/
@GetMapping("/list")
public R> selectAll() {
List list = this.serverTunnelService.list();
- return R.success(list.stream().map(item->{
+ return R.success(list.stream().map(item -> {
ServerTunnelVO vo = new ServerTunnelVO();
BeanUtils.copyProperties(item, vo);
return vo;
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/DeviceDetail.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/DeviceDetail.java
new file mode 100644
index 00000000..35315d87
--- /dev/null
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/DeviceDetail.java
@@ -0,0 +1,75 @@
+package com.wuweibi.bullet.device.domain;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ *
+ *
+ *
+ *
+ * @author marker
+ * @since 2017-12-09
+ */
+@Data
+public class DeviceDetail extends Model {
+
+ private static final long serialVersionUID = 1L;
+
+ private Long id;
+ private String name;
+ private String deviceNo;
+
+
+ @TableField(value = "createTime")
+ private Date createTime;
+ @TableField(value = "userId")
+ private Long userId;
+
+ @ApiModelProperty("设备秘钥")
+ @TableField("device_secret")
+ private String deviceSecret;
+
+
+ @ApiModelProperty("在线状态 -1离线 1在线")
+ private Integer status;
+
+ /**
+ * 内网IP
+ */
+ @TableField(value="intranet_ip" )
+ private String intranetIp;
+ /**
+ * 公网IP
+ */
+ @TableField()
+ private String publicIp;
+
+ @ApiModelProperty("客户端版本")
+ private String clientVersion;
+
+ @ApiModelProperty("通道id")
+ private Integer serverTunnelId;
+
+ @ApiModelProperty("操作系统")
+ private String os;
+
+ @ApiModelProperty("CPU架构")
+ private String arch;
+
+
+ @Override
+ public String toString() {
+ return "Device{" +
+ ", id=" + id +
+ ", name=" + name +
+ ", deviceNo=" + deviceNo +
+ ", createTime=" + createTime +
+ ", userId=" + userId +
+ "}";
+ }
+}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/DevicePeersConfigDTO.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/DevicePeersConfigDTO.java
index 64bf4645..fca349b8 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/DevicePeersConfigDTO.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/DevicePeersConfigDTO.java
@@ -38,6 +38,7 @@ public class DevicePeersConfigDTO {
@ApiModelProperty("服务侧设备No")
private String serverDeviceNo;
+ private Integer serverDeviceTunnelId;
/**
* 客户侧设备id
@@ -47,6 +48,7 @@ public class DevicePeersConfigDTO {
@ApiModelProperty("客户侧设备No")
private String clientDeviceNo;
+ private Integer clientDeviceTunnelId;
/**
* 服务侧本地端口
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/dto/DeviceAuthDTO.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/dto/DeviceAuthDTO.java
new file mode 100644
index 00000000..1d0f319a
--- /dev/null
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/dto/DeviceAuthDTO.java
@@ -0,0 +1,32 @@
+package com.wuweibi.bullet.device.domain.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+@Data
+public class DeviceAuthDTO {
+
+
+ @NotNull(message = "{com.wuweibi.bullet.device.id.NotNull}")
+ private String deviceNo;
+
+ private String ipAddr;
+
+ private String mac;
+
+ private String secret;
+
+ private String os;
+
+ private String arch;
+
+ private String remoteIpAddr;
+
+ private String version;
+
+ @ApiModelProperty("通道id")
+ private Integer serverTunnelId;
+
+}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/dto/DeviceAuthVO.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/dto/DeviceAuthVO.java
new file mode 100644
index 00000000..892eeba3
--- /dev/null
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/dto/DeviceAuthVO.java
@@ -0,0 +1,15 @@
+package com.wuweibi.bullet.device.domain.dto;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+@Data
+public class DeviceAuthVO {
+
+
+ @NotNull(message = "{com.wuweibi.bullet.device.id.NotNull}")
+ private String deviceNo;
+
+
+}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/dto/DeviceOnlineInfoDTO.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/dto/DeviceOnlineInfoDTO.java
index 5628485d..22d196a6 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/dto/DeviceOnlineInfoDTO.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/dto/DeviceOnlineInfoDTO.java
@@ -1,6 +1,7 @@
package com.wuweibi.bullet.device.domain.dto;
+import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@@ -14,5 +15,21 @@ public class DeviceOnlineInfoDTO {
/**
* 公网IP地址
*/
+ @ApiModelProperty("公网IP地址")
private String publicIp;
+
+ private String intranetIp;
+
+ private String clientVersion;
+
+ private String macAddr;
+
+ @ApiModelProperty("操作系统")
+ private String os;
+
+ @ApiModelProperty("cpu架构")
+ private String arch;
+
+ @ApiModelProperty("通道id")
+ private Integer serverTunnelId;
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/vo/TunnelOption.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/vo/TunnelOption.java
new file mode 100644
index 00000000..3f391cbc
--- /dev/null
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/domain/vo/TunnelOption.java
@@ -0,0 +1,34 @@
+package com.wuweibi.bullet.device.domain.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ *
+ * 设备下拉列表
+ *
+ *
+ * @author marker
+ * @since 2017-12-09
+ */
+@Data
+public class TunnelOption {
+
+ @ApiModelProperty("通道id")
+ private Long id;
+
+ @ApiModelProperty("通道名称")
+ private String name;
+
+
+
+
+
+ @Override
+ public String toString() {
+ return "TunnelOption{" +
+ ", id=" + id +
+ ", name=" + name +
+ "}";
+ }
+}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/entity/Device.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/entity/Device.java
similarity index 81%
rename from joggle-server/src/main/java/com/wuweibi/bullet/entity/Device.java
rename to joggle-server/src/main/java/com/wuweibi/bullet/device/entity/Device.java
index c70fd625..c07b7d01 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/entity/Device.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/entity/Device.java
@@ -1,4 +1,4 @@
-package com.wuweibi.bullet.entity;
+package com.wuweibi.bullet.device.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
@@ -36,18 +36,6 @@ public class Device extends Model {
@TableField(value = "userId")
private Long userId;
- @TableField(value = "intranet_ip")
- private String intranetIp;
- @TableField(value = "mac_addr")
- private String macAddr;
-
-
- /**
- * 服务通道ID
- */
- @TableField("server_tunnel_id")
- private Integer serverTunnelId;
-
@ApiModelProperty("设备秘钥")
@TableField("device_secret")
private String deviceSecret;
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/entity/ServerTunnel.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/entity/ServerTunnel.java
index f7575f7e..1462c295 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/device/entity/ServerTunnel.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/entity/ServerTunnel.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
+import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
@@ -41,5 +42,8 @@ public class ServerTunnel extends Model {
// 是否可购买 1可 0不可
private Integer buyStatus;
+
+ @ApiModelProperty("在线状态 1在线 0不在线")
+ private Integer status;
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/mapper/ServerTunnelMapper.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/mapper/ServerTunnelMapper.java
index b1bf7ca4..156a807e 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/device/mapper/ServerTunnelMapper.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/mapper/ServerTunnelMapper.java
@@ -1,8 +1,11 @@
package com.wuweibi.bullet.device.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.wuweibi.bullet.device.domain.vo.TunnelOption;
import com.wuweibi.bullet.device.entity.ServerTunnel;
+import java.util.List;
+
/**
* 通道(ServerTunnel)表数据库访问层
*
@@ -11,5 +14,7 @@
*/
public interface ServerTunnelMapper extends BaseMapper {
+ List selectOptionList();
+
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/service/ServerTunnelService.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/service/ServerTunnelService.java
index c034ac40..8c509fe4 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/device/service/ServerTunnelService.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/service/ServerTunnelService.java
@@ -1,8 +1,11 @@
package com.wuweibi.bullet.device.service;
import com.baomidou.mybatisplus.extension.service.IService;
+import com.wuweibi.bullet.device.domain.vo.TunnelOption;
import com.wuweibi.bullet.device.entity.ServerTunnel;
+import java.util.List;
+
/**
* 通道(ServerTunnel)表服务接口
*
@@ -11,5 +14,22 @@
*/
public interface ServerTunnelService extends IService {
+ List getOptionList();
+
+
+ /**
+ * 获取所有可用区域清单
+ * @return
+ */
+ List getListEnable();
+
+
+ /**
+ * 更新通道的在线状态
+ * @param tunnelId 通道id
+ * @param status 状态 1在线 0 不在线
+ * @return
+ */
+ boolean updateStatus(Integer tunnelId, int status);
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/service/impl/DevicePeersServiceImpl.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/service/impl/DevicePeersServiceImpl.java
index 0c2c34ee..5a5970ac 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/device/service/impl/DevicePeersServiceImpl.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/service/impl/DevicePeersServiceImpl.java
@@ -6,7 +6,7 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.wuweibi.bullet.conn.CoonPool;
+import com.wuweibi.bullet.conn.WebsocketPool;
import com.wuweibi.bullet.device.contrast.DevicePeerStatusEnum;
import com.wuweibi.bullet.device.domain.DevicePeersConfigDTO;
import com.wuweibi.bullet.device.domain.DevicePeersDTO;
@@ -18,7 +18,7 @@
import com.wuweibi.bullet.protocol.MsgPeer;
import com.wuweibi.bullet.protocol.domain.PeerConfig;
import com.wuweibi.bullet.utils.StringUtil;
-import com.wuweibi.bullet.websocket.BulletAnnotation;
+import com.wuweibi.bullet.websocket.Bullet3Annotation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.BeanUtils;
@@ -81,7 +81,7 @@ public DevicePeersConfigDTO getPeersConfig(Long id) {
@Resource
- private CoonPool coonPool;
+ private WebsocketPool coonPool;
public void sendMsgPeerConfig(DevicePeersConfigDTO dto) {
@@ -89,33 +89,37 @@ public void sendMsgPeerConfig(DevicePeersConfigDTO dto) {
log.debug("P2P Conf Error AppName={}, ClientDeviceNo={}, ServerDeviceNo={}", dto.getAppName(), dto.getClientDeviceNo(), dto.getServerDeviceNo() );
return;
}
+ if (dto.getClientDeviceTunnelId() == null || dto.getServerDeviceTunnelId() == null) {
+ return;
+ }
String clientDeviceNo = dto.getClientDeviceNo();
String serverDeviceNo = dto.getServerDeviceNo();
- BulletAnnotation annotation = coonPool.getByDeviceNo(clientDeviceNo);
+ Bullet3Annotation annotation = coonPool.getByTunnelId(dto.getServerDeviceTunnelId());
if (annotation != null) {
PeerConfig doorConfig = new PeerConfig();
doorConfig.setAppName(dto.getAppName());
- doorConfig.setPort(dto.getClientProxyPort());
- doorConfig.setHost(dto.getClientProxyHost());
- doorConfig.setType(PeerConfig.CLIENT);
+ doorConfig.setPort(dto.getServerLocalPort());
+ doorConfig.setHost(dto.getServerLocalHost());
+ doorConfig.setType(PeerConfig.SERVER);
doorConfig.setEnable(dto.getStatus());
JSONObject data = (JSONObject) JSON.toJSON(doorConfig);
MsgPeer msg = new MsgPeer(data.toJSONString());
- annotation.sendMessage(msg);
+ annotation.sendMessage(serverDeviceNo, msg);
}
- annotation = coonPool.getByDeviceNo(serverDeviceNo);
+
+ annotation = coonPool.getByTunnelId(dto.getClientDeviceTunnelId());
if (annotation != null) {
PeerConfig doorConfig = new PeerConfig();
doorConfig.setAppName(dto.getAppName());
- doorConfig.setPort(dto.getServerLocalPort());
- doorConfig.setHost(dto.getServerLocalHost());
- doorConfig.setType(PeerConfig.SERVER);
+ doorConfig.setPort(dto.getClientProxyPort());
+ doorConfig.setHost(dto.getClientProxyHost());
+ doorConfig.setType(PeerConfig.CLIENT);
doorConfig.setEnable(dto.getStatus());
JSONObject data = (JSONObject) JSON.toJSON(doorConfig);
MsgPeer msg = new MsgPeer(data.toJSONString());
- annotation.sendMessage(msg);
+ annotation.sendMessage(clientDeviceNo, msg);
}
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/device/service/impl/ServerTunnelServiceImpl.java b/joggle-server/src/main/java/com/wuweibi/bullet/device/service/impl/ServerTunnelServiceImpl.java
index 274e2ddb..1e134ad0 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/device/service/impl/ServerTunnelServiceImpl.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/device/service/impl/ServerTunnelServiceImpl.java
@@ -1,11 +1,15 @@
package com.wuweibi.bullet.device.service.impl;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.wuweibi.bullet.device.domain.vo.TunnelOption;
import com.wuweibi.bullet.device.mapper.ServerTunnelMapper;
import com.wuweibi.bullet.device.entity.ServerTunnel;
import com.wuweibi.bullet.device.service.ServerTunnelService;
import org.springframework.stereotype.Service;
+import java.util.List;
+
/**
* 通道(ServerTunnel)表服务实现类
*
@@ -15,5 +19,22 @@
@Service("serverTunnelService")
public class ServerTunnelServiceImpl extends ServiceImpl implements ServerTunnelService {
+ @Override
+ public List getOptionList() {
+ return this.baseMapper.selectOptionList();
+ }
+
+ @Override
+ public List getListEnable() {
+ return this.baseMapper.selectList(Wrappers.emptyWrapper());
+ }
+
+ @Override
+ public boolean updateStatus(Integer tunnelId, int status) {
+ return this.update(Wrappers.lambdaUpdate()
+ .eq(ServerTunnel::getId, tunnelId)
+ .set(ServerTunnel::getStatus, status)
+ );
+ }
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/domain/dto/DeviceDto.java b/joggle-server/src/main/java/com/wuweibi/bullet/domain/dto/DeviceDto.java
index 1cc30bda..dcf92b87 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/domain/dto/DeviceDto.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/domain/dto/DeviceDto.java
@@ -2,7 +2,7 @@
* Created by marker on 2017/12/10.
*/
-import com.wuweibi.bullet.entity.Device;
+import com.wuweibi.bullet.device.entity.Device;
import lombok.Data;
import java.util.Date;
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/domain/vo/DomainVO.java b/joggle-server/src/main/java/com/wuweibi/bullet/domain/vo/DomainVO.java
index 2f255772..73f90d4c 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/domain/vo/DomainVO.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/domain/vo/DomainVO.java
@@ -9,6 +9,7 @@ public class DomainVO {
private Long id;
private String domain;
+ private String domainFull;
private Integer type;
private Integer status;
private Date dueDateTime;
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/domain2/controller/DomainController.java b/joggle-server/src/main/java/com/wuweibi/bullet/domain2/controller/DomainController.java
index 7a065854..4fce841e 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/domain2/controller/DomainController.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/domain2/controller/DomainController.java
@@ -7,15 +7,18 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wuweibi.bullet.annotation.JwtUser;
import com.wuweibi.bullet.config.swagger.annotation.WebApi;
-import com.wuweibi.bullet.conn.CoonPool;
+import com.wuweibi.bullet.device.domain.DeviceDetail;
+import com.wuweibi.bullet.device.entity.ServerTunnel;
+import com.wuweibi.bullet.device.service.ServerTunnelService;
import com.wuweibi.bullet.domain.domain.session.Session;
import com.wuweibi.bullet.domain.message.MessageFactory;
import com.wuweibi.bullet.domain.vo.DomainVO;
import com.wuweibi.bullet.domain2.domain.DomainBuyListVO;
import com.wuweibi.bullet.domain2.domain.DomainSearchParam;
-import com.wuweibi.bullet.entity.Device;
-import com.wuweibi.bullet.entity.DeviceMapping;
+import com.wuweibi.bullet.domain2.domain.vo.DomainDetailVO;
import com.wuweibi.bullet.domain2.entity.Domain;
+import com.wuweibi.bullet.domain2.enums.DomainTypeEnum;
+import com.wuweibi.bullet.entity.DeviceMapping;
import com.wuweibi.bullet.entity.api.R;
import com.wuweibi.bullet.exception.type.AuthErrorType;
import com.wuweibi.bullet.exception.type.SystemErrorType;
@@ -27,6 +30,7 @@
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@@ -47,8 +51,6 @@
public class DomainController {
- @Resource
- private CoonPool coonPool;
/**
@@ -85,20 +87,17 @@ public Object device(@JwtUser Session session) {
return MessageFactory.get(list);
}
+ @Resource
+ private ServerTunnelService serverTunnelService;
/**
* 获取我的域名信息
*/
@ApiModelProperty("获取域名信息")
@GetMapping(value = "/info")
- public Object getInfo(@JwtUser Session session, @RequestParam Long domainId) {
-
+ public R getInfo(@JwtUser Session session, @RequestParam Long domainId) {
Long userId = session.getUserId();
- // 检查是否该用户的域名
-// if(!domainService.checkDomain(userId, domainId)){
-// return R.fail(SystemErrorType.DOMAIN_NOT_FOUND);
-// }
Domain domain = domainService.getById(domainId);
if (domain == null) {
return R.fail(SystemErrorType.DOMAIN_NOT_FOUND);
@@ -107,7 +106,19 @@ public Object getInfo(@JwtUser Session session, @RequestParam Long domainId) {
if (domain.getUserId() != null && !domain.getUserId().equals(userId)) {
return R.fail(SystemErrorType.DOMAIN_NOT_FOUND);
}
- return R.success(domain);
+ ServerTunnel serverTunnel = serverTunnelService.getById(domain.getServerTunnelId());
+ if (serverTunnel == null) {
+ return R.fail("域名/端口信息有误");
+ }
+ DomainDetailVO domainDetailVO = new DomainDetailVO();
+ BeanUtils.copyProperties(domain, domainDetailVO);
+ domainDetailVO.setDomainFull(domain.getDomain());
+ if (domain.getType().equals(DomainTypeEnum.DOMAIN.getType())) {
+ domainDetailVO.setDomainFull(String.format("%s.%s", domain.getDomain(), serverTunnel.getServerAddr()));
+ } else {
+ domainDetailVO.setDomainFull(String.format("%s:%s", serverTunnel.getServerAddr(), domain.getDomain()));
+ }
+ return R.success(domainDetailVO);
}
/**
@@ -148,7 +159,8 @@ public R bind(@RequestParam Long domainId, @RequestParam Long deviceId) {
}
// 检查设备是否该用户的
- if (!deviceService.exists(userId, deviceId)) {
+ DeviceDetail deviceDetail = deviceService.getDetail(deviceId);
+ if (deviceDetail == null) {
return R.fail(SystemErrorType.DEVICE_NOT_EXIST);
}
// 检查域名是否已经绑定
@@ -159,13 +171,12 @@ public R bind(@RequestParam Long domainId, @RequestParam Long deviceId) {
// 执行绑定
Domain domainInfo = domainService.getById(domainId);
- Device deviceInfo = deviceService.getById(deviceId);
DeviceMapping mapping = new DeviceMapping();
mapping.setDomain(domainInfo.getDomain());
mapping.setUserId(userId);
mapping.setDeviceId(deviceId);
- mapping.setServerTunnelId(deviceInfo.getServerTunnelId());
+ mapping.setServerTunnelId(deviceDetail.getServerTunnelId());
mapping.setDomainId(domainId);
mapping.setCreateTime(new Date());
if (domainInfo.getType() == 1) {
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/domain2/domain/DomainBuyListVO.java b/joggle-server/src/main/java/com/wuweibi/bullet/domain2/domain/DomainBuyListVO.java
index ce517063..36aeffa0 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/domain2/domain/DomainBuyListVO.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/domain2/domain/DomainBuyListVO.java
@@ -22,4 +22,13 @@ public class DomainBuyListVO {
private BigDecimal originalPrice;
@ApiModelProperty("销售价格")
private BigDecimal salesPrice;
+
+ @ApiModelProperty("通道区域")
+ private String tunnelName;
+ @ApiModelProperty("通道地区")
+ private String tunnelArea;
+ @ApiModelProperty("通道国家")
+ private String tunnelCountry;
+ @ApiModelProperty("通道宽带")
+ private Integer tunnelBroadband;
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/domain2/domain/DomainSearchParam.java b/joggle-server/src/main/java/com/wuweibi/bullet/domain2/domain/DomainSearchParam.java
index 4d52aae3..6e30f0e2 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/domain2/domain/DomainSearchParam.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/domain2/domain/DomainSearchParam.java
@@ -13,4 +13,7 @@ public class DomainSearchParam {
@ApiModelProperty("类型:1 端口 2域名")
private Integer type;
+ @ApiModelProperty("通道id")
+ private Integer serverTunnelId;
+
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/domain2/domain/vo/DomainDetailVO.java b/joggle-server/src/main/java/com/wuweibi/bullet/domain2/domain/vo/DomainDetailVO.java
new file mode 100644
index 00000000..fe7cd40d
--- /dev/null
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/domain2/domain/vo/DomainDetailVO.java
@@ -0,0 +1,22 @@
+
+package com.wuweibi.bullet.domain2.domain.vo;
+
+import com.wuweibi.bullet.domain2.entity.Domain;
+import lombok.Data;
+
+/**
+ *
+ * 域名与端口
+ *
+ *
+ * @author marker
+ */
+@Data
+public class DomainDetailVO extends Domain {
+
+ /**
+ * 全名称域名
+ */
+ private String domainFull;
+
+}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/entity/DeviceOnline.java b/joggle-server/src/main/java/com/wuweibi/bullet/entity/DeviceOnline.java
index cf6490a1..77633371 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/entity/DeviceOnline.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/entity/DeviceOnline.java
@@ -62,6 +62,15 @@ public class DeviceOnline extends Model {
@ApiModelProperty("客户端版本")
private String clientVersion;
+ @ApiModelProperty("通道id")
+ private Integer serverTunnelId;
+
+ @ApiModelProperty("操作系统")
+ private String os;
+
+ @ApiModelProperty("CPU架构")
+ private String arch;
+
/**
* 默认构造
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/exception/CustomWebResponseExceptionTranslator.java b/joggle-server/src/main/java/com/wuweibi/bullet/exception/CustomWebResponseExceptionTranslator.java
index 9db2d8b2..a4cba2a4 100755
--- a/joggle-server/src/main/java/com/wuweibi/bullet/exception/CustomWebResponseExceptionTranslator.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/exception/CustomWebResponseExceptionTranslator.java
@@ -34,19 +34,13 @@ public class CustomWebResponseExceptionTranslator implements WebResponseExceptio
@Override
public ResponseEntity translate(Exception e) {
-
-
// Try to extract a SpringSecurityException from the stacktrace
Throwable[] causeChain = throwableAnalyzer.determineCauseChain(e);
Exception ase = (AuthenticationException) throwableAnalyzer
.getFirstThrowableOfType(AuthenticationException.class, causeChain);
-
-
-
if (e instanceof OAuth2Exception) {
- log.warn("", e);
OAuth2Exception oAuth2Exception = (OAuth2Exception) e;
if (oAuth2Exception instanceof InvalidGrantException) {
if ("User is disabled".equals(oAuth2Exception.getMessage())) {
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/listener/CloseServerListener.java b/joggle-server/src/main/java/com/wuweibi/bullet/listener/CloseServerListener.java
index 7db19a27..85db4a26 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/listener/CloseServerListener.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/listener/CloseServerListener.java
@@ -1,16 +1,14 @@
-package com.wuweibi.bullet.listener;/**
+package com.wuweibi.bullet.listener;
+/**
* Created by marker on 2019/5/31.
*/
-import com.wuweibi.bullet.service.DeviceOnlineService;
-import com.wuweibi.bullet.utils.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
/**
* 应用停止监听
- *
* @author marker
* @create 2019-05-31 11:23
**/
@@ -21,13 +19,6 @@ public CloseServerListener( ) { }
@Override
public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
-
- log.warn("SpringBoot 停止运行中...");
-
- DeviceOnlineService deviceOnlineService = SpringUtils.getBean(DeviceOnlineService.class);
-
- log.warn("SpringBoot 准备下线所有设备...");
- deviceOnlineService.allDownNow();
-
+ log.warn("SpringBoot 停止中...");
}
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/listener/BulletSpringApplicationRunListener.java b/joggle-server/src/main/java/com/wuweibi/bullet/listener/SpringApplicationRunListener.java
similarity index 72%
rename from joggle-server/src/main/java/com/wuweibi/bullet/listener/BulletSpringApplicationRunListener.java
rename to joggle-server/src/main/java/com/wuweibi/bullet/listener/SpringApplicationRunListener.java
index 94c90662..3afb0496 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/listener/BulletSpringApplicationRunListener.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/listener/SpringApplicationRunListener.java
@@ -4,7 +4,6 @@
import com.wuweibi.bullet.utils.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
-import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;
import java.time.Duration;
@@ -16,10 +15,10 @@
* @author marker
*/
@Slf4j
-public class BulletSpringApplicationRunListener implements SpringApplicationRunListener {
+public class SpringApplicationRunListener implements org.springframework.boot.SpringApplicationRunListener {
//必须有的构造器
- public BulletSpringApplicationRunListener(SpringApplication application, String[] args) {
+ public SpringApplicationRunListener(SpringApplication application, String[] args) {
}
@@ -31,12 +30,12 @@ public void contextLoaded(ConfigurableApplicationContext context) {
@Override
public void started(ConfigurableApplicationContext context, Duration timeTaken) {
- SpringApplicationRunListener.super.started(context, timeTaken);
+ org.springframework.boot.SpringApplicationRunListener.super.started(context, timeTaken);
log.info("SpringBoot 启动完成...");
+
DeviceOnlineService deviceOnlineService = SpringUtils.getBean(DeviceOnlineService.class);
log.info("SpringBoot 初始化设备状态...");
- deviceOnlineService.allDownNow();
- log.info("SpringBoot 数据库记录设备已经下线...");
+ deviceOnlineService.checkDeviceStatus();
// CoonPool coonPool = SpringUtils.getBean(CoonPool.class);
// coonPool.stop();
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/mapper/DeviceMapper.java b/joggle-server/src/main/java/com/wuweibi/bullet/mapper/DeviceMapper.java
index e9a7d398..661e7459 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/mapper/DeviceMapper.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/mapper/DeviceMapper.java
@@ -2,8 +2,10 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.wuweibi.bullet.device.domain.DeviceDetail;
import com.wuweibi.bullet.device.domain.vo.DeviceOption;
-import com.wuweibi.bullet.entity.Device;
+import com.wuweibi.bullet.domain.dto.DeviceDto;
+import com.wuweibi.bullet.device.entity.Device;
import io.lettuce.core.dynamic.annotation.Param;
import java.util.List;
@@ -56,4 +58,13 @@ public interface DeviceMapper extends BaseMapper {
* @return
*/
List selectOptionListByUserId(@Param("userId") Long userId);
+
+ List selectWebListByUserId(@Param("userId")Long userId);
+
+ /**
+ * 获取设备详情
+ * @param deviceId 设备id
+ * @return
+ */
+ DeviceDetail selectDetail(@Param("deviceId") Long deviceId);
}
\ No newline at end of file
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/mapper/DeviceOnlineMapper.java b/joggle-server/src/main/java/com/wuweibi/bullet/mapper/DeviceOnlineMapper.java
index 690cc520..2535205e 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/mapper/DeviceOnlineMapper.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/mapper/DeviceOnlineMapper.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wuweibi.bullet.entity.DeviceOnline;
+import org.apache.ibatis.annotations.Param;
import java.util.List;
@@ -27,4 +28,30 @@ public interface DeviceOnlineMapper extends BaseMapper {
void updateStatus(String deviceOnline);
List selectDiscoveryDevice(String ip);
+
+
+ /**
+ * 更新设备在线状态
+ * @param deviceNo 设备编码
+ * @param status 状态
+ * @return
+ */
+ boolean updateDeviceStatus(@Param("deviceNo") String deviceNo,@Param("status") int status);
+
+ /**
+ * 批量更新设备状态
+ * @param deviceNoList 设备清单
+ * @param status 设备状态
+ * @return
+ */
+ int batchUpdateStatus(@Param("list") List deviceNoList,@Param("status") int status);
+
+ /**
+ * 根据通道id批量更新设备状态为下线
+ *
+ * @param tunnelId 通道id
+ * @return
+ */
+ int updateOutLineByTunnelId(@Param("tunnelId") Integer tunnelId);
+
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/mapper/DomainMapper.java b/joggle-server/src/main/java/com/wuweibi/bullet/mapper/DomainMapper.java
index cd7ca163..69397898 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/mapper/DomainMapper.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/mapper/DomainMapper.java
@@ -8,6 +8,7 @@
import com.wuweibi.bullet.domain2.domain.DomainDetail;
import com.wuweibi.bullet.domain2.domain.DomainSearchParam;
import com.wuweibi.bullet.domain2.entity.Domain;
+import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
@@ -23,6 +24,7 @@
* @author marker
* @since 2017-12-09
*/
+@Mapper
public interface DomainMapper extends BaseMapper {
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/metrics/controller/DataMetricsOpenController.java b/joggle-server/src/main/java/com/wuweibi/bullet/metrics/controller/DataMetricsOpenController.java
index 420bbeb3..8e016fa8 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/metrics/controller/DataMetricsOpenController.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/metrics/controller/DataMetricsOpenController.java
@@ -3,7 +3,7 @@
import com.wuweibi.bullet.business.DeviceBiz;
import com.wuweibi.bullet.config.swagger.annotation.WebApi;
-import com.wuweibi.bullet.entity.Device;
+import com.wuweibi.bullet.device.entity.Device;
import com.wuweibi.bullet.entity.api.R;
import com.wuweibi.bullet.exception.type.SystemErrorType;
import com.wuweibi.bullet.flow.entity.UserFlow;
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/metrics/controller/DataMetricsOpenInnerController.java b/joggle-server/src/main/java/com/wuweibi/bullet/metrics/controller/DataMetricsOpenInnerController.java
index cf541387..2d9bea2e 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/metrics/controller/DataMetricsOpenInnerController.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/metrics/controller/DataMetricsOpenInnerController.java
@@ -4,7 +4,7 @@
import com.wuweibi.bullet.business.DeviceBiz;
import com.wuweibi.bullet.config.properties.BulletConfig;
import com.wuweibi.bullet.config.swagger.annotation.WebApi;
-import com.wuweibi.bullet.entity.Device;
+import com.wuweibi.bullet.device.entity.Device;
import com.wuweibi.bullet.entity.api.R;
import com.wuweibi.bullet.exception.type.SystemErrorType;
import com.wuweibi.bullet.flow.entity.UserFlow;
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/oauth2/handler/event/AuthenticationSuccessEventListener.java b/joggle-server/src/main/java/com/wuweibi/bullet/oauth2/handler/event/AuthenticationSuccessEventListener.java
index aa6143f4..4ec429a3 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/oauth2/handler/event/AuthenticationSuccessEventListener.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/oauth2/handler/event/AuthenticationSuccessEventListener.java
@@ -7,12 +7,8 @@
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
/**
@@ -31,18 +27,18 @@ public class AuthenticationSuccessEventListener implements ApplicationListener
* 服务类
@@ -58,4 +60,28 @@ public interface DeviceOnlineService extends IService {
*/
DeviceOnline getByDeviceNo(String deviceId);
+ /**
+ * 检查设备状态
+ * @return
+ */
+ boolean checkDeviceStatus();
+
+
+ boolean updateDeviceStatus(String deviceNo, int status);
+
+
+ /**
+ * 批量更新设备状态
+ * @param deviceNoList 设备清单
+ * @param status 设备状态
+ * @return
+ */
+ int batchUpdateStatus(List deviceNoList, int status);
+
+ /**
+ * 下线通道的所有设备
+ * @param tunnelId 通道id
+ * @return
+ */
+ int updateOutLineByTunnelId(Integer tunnelId);
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/service/DeviceService.java b/joggle-server/src/main/java/com/wuweibi/bullet/service/DeviceService.java
index e8aee498..6e080709 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/service/DeviceService.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/service/DeviceService.java
@@ -2,8 +2,10 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
+import com.wuweibi.bullet.device.domain.DeviceDetail;
import com.wuweibi.bullet.device.domain.vo.DeviceOption;
-import com.wuweibi.bullet.entity.Device;
+import com.wuweibi.bullet.domain.dto.DeviceDto;
+import com.wuweibi.bullet.device.entity.Device;
import com.wuweibi.bullet.entity.DeviceOnline;
import java.util.List;
@@ -97,4 +99,12 @@ public interface DeviceService extends IService {
boolean removeUserId(Long deviceId);
+ List getWebListByUserId(Long userId);
+
+ /**
+ * 设备详情
+ * @param deviceId 设备Id
+ * @return
+ */
+ DeviceDetail getDetail(Long deviceId);
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/service/impl/DeviceMappingServiceImpl.java b/joggle-server/src/main/java/com/wuweibi/bullet/service/impl/DeviceMappingServiceImpl.java
index eae845cf..886a00d9 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/service/impl/DeviceMappingServiceImpl.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/service/impl/DeviceMappingServiceImpl.java
@@ -7,7 +7,7 @@
import com.wuweibi.bullet.device.domain.vo.MappingDeviceVO;
import com.wuweibi.bullet.domain.DeviceMappingDTO;
import com.wuweibi.bullet.domain.dto.DeviceMappingDto;
-import com.wuweibi.bullet.entity.Device;
+import com.wuweibi.bullet.device.entity.Device;
import com.wuweibi.bullet.entity.DeviceMapping;
import com.wuweibi.bullet.mapper.DeviceMappingMapper;
import com.wuweibi.bullet.service.DeviceMappingService;
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/service/impl/DeviceOnlineServiceImpl.java b/joggle-server/src/main/java/com/wuweibi/bullet/service/impl/DeviceOnlineServiceImpl.java
index 06bfed9f..24f440bf 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/service/impl/DeviceOnlineServiceImpl.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/service/impl/DeviceOnlineServiceImpl.java
@@ -3,13 +3,19 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.wuweibi.bullet.conn.WebsocketPool;
import com.wuweibi.bullet.device.contrast.DeviceOnlineStatus;
import com.wuweibi.bullet.device.domain.dto.DeviceOnlineInfoDTO;
-import com.wuweibi.bullet.entity.Device;
+import com.wuweibi.bullet.device.entity.ServerTunnel;
+import com.wuweibi.bullet.device.service.ServerTunnelService;
import com.wuweibi.bullet.entity.DeviceOnline;
import com.wuweibi.bullet.mapper.DeviceMapper;
import com.wuweibi.bullet.mapper.DeviceOnlineMapper;
+import com.wuweibi.bullet.protocol.MsgGetDeviceStatus;
import com.wuweibi.bullet.service.DeviceOnlineService;
+import com.wuweibi.bullet.service.DeviceService;
+import com.wuweibi.bullet.websocket.Bullet3Annotation;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -25,6 +31,7 @@
* @author marker
* @since 2017-12-09
*/
+@Slf4j
@Service
public class DeviceOnlineServiceImpl extends ServiceImpl implements DeviceOnlineService {
@@ -59,18 +66,6 @@ public void saveOrUpdateOnline(String deviceNo, String ip, String mac, String cl
this.baseMapper.updateById(deviceOnline);
}
- // 更新已绑定的设备
- QueryWrapper ew2 = new QueryWrapper();
- ew2.eq("deviceId", deviceNo);
- List deviceList = deviceMapper.selectList(ew2);
- if (deviceList.size() == 0) return;
-
- for (Device device : deviceList) {
- device.setIntranetIp(ip);
- device.setMacAddr(mac);
- deviceMapper.updateById(device);
- }
-
}
@Override
@@ -109,6 +104,7 @@ public void allDownNow() {
}
@Override
+ @Transactional
public boolean saveOrUpdate(DeviceOnlineInfoDTO deviceInfo) {
String deviceNo = deviceInfo.getDeviceNo();
DeviceOnline deviceOnline = this.baseMapper.selectOne(Wrappers.lambdaQuery()
@@ -118,7 +114,13 @@ public boolean saveOrUpdate(DeviceOnlineInfoDTO deviceInfo) {
deviceOnline.setDeviceNo(deviceNo);
deviceOnline.setStatus(1);// 等待被绑定(在线)
}
+ deviceOnline.setServerTunnelId(deviceInfo.getServerTunnelId());
deviceOnline.setPublicIp(deviceInfo.getPublicIp());
+ deviceOnline.setIntranetIp(deviceInfo.getPublicIp());
+ deviceOnline.setMacAddr(deviceInfo.getMacAddr());
+ deviceOnline.setClientVersion(deviceInfo.getClientVersion());
+ deviceOnline.setOs(deviceInfo.getOs());
+ deviceOnline.setArch(deviceInfo.getArch());
deviceOnline.setUpdateTime(new Date());
if (deviceOnline.getId() != null) {
@@ -130,6 +132,9 @@ public boolean saveOrUpdate(DeviceOnlineInfoDTO deviceInfo) {
return true;
}
+ @Resource
+ private DeviceService deviceService;
+
@Override
public DeviceOnline getByDeviceNo(String deviceId) {
return this.baseMapper.selectOne(Wrappers.lambdaQuery()
@@ -137,4 +142,46 @@ public DeviceOnline getByDeviceNo(String deviceId) {
.eq(DeviceOnline::getStatus, DeviceOnlineStatus.ONLINE.status)
.orderByDesc(DeviceOnline::getUpdateTime));
}
+
+ @Resource
+ private WebsocketPool websocketPool;
+
+ @Resource
+ private ServerTunnelService serverTunnelService;
+
+ @Override
+ public boolean checkDeviceStatus() {
+
+ List list = serverTunnelService.getListEnable();
+
+ list.forEach(item -> {
+ log.debug("[init] check server[{}] {}[{}]", item.getId(), item.getName(), item.getServerAddr());
+ Bullet3Annotation annotation = websocketPool.getByTunnelId(item.getId());
+ if (annotation == null) {
+ log.debug("[init] check server[{}] not online", item.getId());
+ }
+ if (annotation != null) {
+ MsgGetDeviceStatus msg = new MsgGetDeviceStatus();
+ annotation.sendMessageToServer(msg);
+ log.debug("[init] check server[{}] ok [GetDeviceStatus]", item.getId());
+ }
+ });
+ return true;
+ }
+
+ @Override
+ public boolean updateDeviceStatus(String deviceNo, int status) {
+ return this.baseMapper.updateDeviceStatus(deviceNo, status);
+ }
+
+ @Override
+ public int batchUpdateStatus(List deviceNoList, int status) {
+ if (deviceNoList.size() == 0) return 0;
+ return this.baseMapper.batchUpdateStatus(deviceNoList, status);
+ }
+
+ @Override
+ public int updateOutLineByTunnelId(Integer tunnelId) {
+ return this.baseMapper.updateOutLineByTunnelId(tunnelId);
+ }
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/service/impl/DeviceServiceImpl.java b/joggle-server/src/main/java/com/wuweibi/bullet/service/impl/DeviceServiceImpl.java
index 9a350e2a..dce7b9e0 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/service/impl/DeviceServiceImpl.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/service/impl/DeviceServiceImpl.java
@@ -3,9 +3,11 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.wuweibi.bullet.conn.CoonPool;
+import com.wuweibi.bullet.conn.WebsocketPool;
+import com.wuweibi.bullet.device.domain.DeviceDetail;
import com.wuweibi.bullet.device.domain.vo.DeviceOption;
-import com.wuweibi.bullet.entity.Device;
+import com.wuweibi.bullet.domain.dto.DeviceDto;
+import com.wuweibi.bullet.device.entity.Device;
import com.wuweibi.bullet.entity.DeviceOnline;
import com.wuweibi.bullet.mapper.DeviceMapper;
import com.wuweibi.bullet.mapper.DeviceOnlineMapper;
@@ -31,7 +33,7 @@ public class DeviceServiceImpl extends ServiceImpl impleme
@Resource
- private CoonPool coonPool;
+ private WebsocketPool coonPool;
@Override
@@ -118,6 +120,16 @@ public boolean removeUserId(Long deviceId) {
);
}
+ @Override
+ public List getWebListByUserId(Long userId) {
+ return this.baseMapper.selectWebListByUserId(userId);
+ }
+
+ @Override
+ public DeviceDetail getDetail(Long deviceId) {
+ return this.baseMapper.selectDetail(deviceId);
+ }
+
private List getListByUserId(Long userId){
return this.baseMapper.selectList(Wrappers.lambdaQuery().eq(Device::getUserId, userId));
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/web/filter/CrossDomainFilter.java b/joggle-server/src/main/java/com/wuweibi/bullet/web/filter/CrossDomainFilter.java
index 8c6d0855..8734e954 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/web/filter/CrossDomainFilter.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/web/filter/CrossDomainFilter.java
@@ -54,10 +54,9 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
response.setHeader("Access-Control-Allow-Methods", "POST,GET,PUT,DELETE");
response.setHeader("Access-Control-Allow-Headers", "sign_key,authorization,content-type");
response.setHeader("Access-Control-Max-Age", "0"); // 单位秒
- logger.debug("response add cross-domain headers");
+// logger.debug("response add cross-domain headers");
-
- if(method.equals("OPTIONS")){
+ if (method.equals("OPTIONS")) {
response.setStatus(200);
return;
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/web/filter/WebsocketIPFilter.java b/joggle-server/src/main/java/com/wuweibi/bullet/web/filter/WebsocketIPFilter.java
index 5c5d92df..da1e384e 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/web/filter/WebsocketIPFilter.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/web/filter/WebsocketIPFilter.java
@@ -1,5 +1,7 @@
package com.wuweibi.bullet.web.filter;
+import com.wuweibi.bullet.utils.HttpUtils;
+
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
@@ -11,7 +13,9 @@ public class WebsocketIPFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest req= (HttpServletRequest) servletRequest;
- req.getSession().setAttribute("ip", req.getRemoteHost());
+
+ req.setAttribute("ip", HttpUtils.getRemoteIP(req));
+ req.getSession().setAttribute("ip", HttpUtils.getRemoteIP(req));
filterChain.doFilter(servletRequest,servletResponse);
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/websocket/Bullet3Annotation.java b/joggle-server/src/main/java/com/wuweibi/bullet/websocket/Bullet3Annotation.java
new file mode 100644
index 00000000..b2bcdf76
--- /dev/null
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/websocket/Bullet3Annotation.java
@@ -0,0 +1,342 @@
+package com.wuweibi.bullet.websocket;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.wuweibi.bullet.config.properties.BulletConfig;
+import com.wuweibi.bullet.conn.WebsocketPool;
+import com.wuweibi.bullet.device.contrast.DeviceOnlineStatus;
+import com.wuweibi.bullet.device.contrast.DevicePeerStatusEnum;
+import com.wuweibi.bullet.device.domain.DevicePeersConfigDTO;
+import com.wuweibi.bullet.device.service.DevicePeersService;
+import com.wuweibi.bullet.device.service.ServerTunnelService;
+import com.wuweibi.bullet.entity.DeviceMapping;
+import com.wuweibi.bullet.protocol.*;
+import com.wuweibi.bullet.service.DeviceMappingService;
+import com.wuweibi.bullet.service.DeviceOnlineService;
+import com.wuweibi.bullet.utils.SpringUtils;
+import com.wuweibi.bullet.utils.Utils;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import javax.websocket.*;
+import javax.websocket.server.PathParam;
+import javax.websocket.server.ServerEndpoint;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+
+import static com.wuweibi.bullet.protocol.Message.CONTROL_CLIENT_WRAPPER;
+import static com.wuweibi.bullet.protocol.Message.CONTROL_SERVER_WRAPPER;
+
+
+/**
+ * 基于Ngrokd的Websocket链接
+ *
+ * @author marker
+ * @version 1.0
+ */
+@Slf4j
+@ServerEndpoint(value = "/inner/open/ws/{tunnelId}", configurator = WebSocketConfigurator.class)
+public class Bullet3Annotation {
+
+
+ /**
+ * session
+ */
+ private Session session;
+
+ /**
+ * 设备ID
+ */
+ private Integer tunnelId;
+
+
+ public Bullet3Annotation() { }
+
+
+
+ /**
+ * 客户端打开连接
+ *
+ * @param session session
+ * @param tunnelId 通道id
+ */
+ @OnOpen
+ public void open(Session session, @PathParam("tunnelId") Integer tunnelId) {
+ session.setMaxIdleTimeout(10000l); // 超时时间10s
+ this.session = session;
+ this.tunnelId = tunnelId;
+
+ String authorization = (String) session.getUserProperties().get("authorization");
+ BulletConfig config = SpringUtils.getBean(BulletConfig.class);
+ // 校验Token
+ if(!config.getAdminApiToken().equals(authorization)){
+ log.error("websocket api token error session[{}]", session.getId());
+ this.stop(CloseReason.CloseCodes.CANNOT_ACCEPT ,"Auth Token Error...");
+ return;
+ }
+
+ WebsocketPool pool = SpringUtils.getBean(WebsocketPool.class);
+ pool.addConnection(this);
+
+// DeviceOnlineService deviceOnlineService = SpringUtils.getBean(DeviceOnlineService.class);
+// deviceOnlineService.checkDeviceStatus();
+
+ // 更新服务通道得在线状态
+
+ ServerTunnelService serverTunnelService = SpringUtils.getBean(ServerTunnelService.class);
+ serverTunnelService.updateStatus(tunnelId, 1);
+ }
+
+
+ @OnClose
+ public void end(CloseReason closeReason) {
+ log.debug("websocket close [{}]", closeReason.toString());
+ ServerTunnelService serverTunnelService = SpringUtils.getBean(ServerTunnelService.class);
+ serverTunnelService.updateStatus(tunnelId, 0);
+ }
+
+
+ @OnMessage
+ public void incoming(byte[] bytes) {
+ ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
+ MsgHead head = new MsgHead();
+ try {
+ head.read(bis);//读取消息头
+ switch (head.getCommand()) {
+ case Message.PROXY:// Bind响应命令
+ MsgProxy msgProxy = new MsgProxy(head);
+ msgProxy.read(bis);
+ break;
+ case Message.AUTH_RESP:// 设备认证成功
+ MsgAuthResp msgAuthResp = new MsgAuthResp(head);
+ msgAuthResp.read(bis);
+
+ String clientNo = msgAuthResp.getClientNo();
+
+ this.sendMappingInfo(clientNo);
+
+ break;
+ case Message.AUTH:// 认证
+ MsgAuth msgAuth = new MsgAuth(head);
+ msgAuth.read(bis);
+ break;
+ case Message.Heart:// 心跳消息
+ MsgHeart msgHeart = new MsgHeart(head);
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ try {
+ msgHeart.write(outputStream);
+ // 包装了Bullet协议的
+ byte[] resultBytes = outputStream.toByteArray();
+ ByteBuffer buf = ByteBuffer.wrap(resultBytes);
+ this.getSession().getBasicRemote().sendPong(buf);
+ } catch (IOException e) {
+ log.error("", e);
+ } finally {
+ IOUtils.closeQuietly(outputStream);
+ }
+
+ return;
+ case Message.NEW_BINDIP:// 绑定IP
+ MsgBindIP msg2 = new MsgBindIP(head);
+ msg2.read(bis);
+
+ // 更新设备状态
+ DeviceOnlineService deviceOnlineService = SpringUtils.getBean(DeviceOnlineService.class);
+// deviceOnlineService.saveOrUpdateOnline(this.deviceNo, msg2.getIp(), msg2.getMac(), msg2.getVersion());
+
+ return;
+ case Message.GET_DEVICE_STATUS_RESP:// 获取设备状态响应所有设备状态
+ MsgGetDeviceStatusResp msgGetDeviceStatusResp = new MsgGetDeviceStatusResp(head);
+ msgGetDeviceStatusResp.read(bis);
+ JSONObject jsonObject = msgGetDeviceStatusResp.getData();
+ // 更新在线状态
+ deviceOnlineService = SpringUtils.getBean(DeviceOnlineService.class);
+ List deviceNoList = new ArrayList<>(jsonObject.size());
+ jsonObject.forEach((item, v)->{
+ deviceNoList.add(item);
+ });
+
+ deviceOnlineService.updateOutLineByTunnelId(this.tunnelId);
+ deviceOnlineService.batchUpdateStatus(deviceNoList, DeviceOnlineStatus.ONLINE.status);
+
+ return;
+ case Message.DEVICE_DOWN: // 设备下线
+ MsgDeviceDown msgDeviceDown = new MsgDeviceDown(head);
+ msgDeviceDown.read(bis);
+ String deviceNo = msgDeviceDown.getDeviceNo();
+ deviceOnlineService = SpringUtils.getBean(DeviceOnlineService.class);
+ deviceOnlineService.updateDeviceStatus(deviceNo, DeviceOnlineStatus.OUTLINE.status);
+ return;
+// case Message.LOG_MAPPING_LOG:// 日志消息
+// MsgCommandLog msgCommandLog = new MsgCommandLog(head);
+// msgCommandLog.read(bis);
+// // 转移消息到另外一个通道
+//
+// LogAnnotation.broadcast(this.deviceId, msgCommandLog.getLine());
+ }
+ } catch (IOException e) {
+ log.error("", e);
+ } finally {
+ IOUtils.closeQuietly(bis);
+ }
+
+ }
+
+
+
+ /**
+ * 发送映射信息
+ */
+ public void sendMappingInfo(String deviceNo) {
+ // 获取设备的配置数据,并将映射配置发送到客户端
+ DeviceMappingService deviceMappingService = SpringUtils.getBean(DeviceMappingService.class);
+ List list = deviceMappingService.getDeviceAll(deviceNo);
+
+ for (DeviceMapping entity : list) {
+ if (!StringUtils.isBlank(deviceNo)) {
+ JSONObject data = (JSONObject) JSON.toJSON(entity);
+ MsgMapping msg = new MsgMapping(data.toJSONString());
+ this.sendMessage(deviceNo, msg);
+ }
+ }
+
+ // P2P 设备通道
+ DevicePeersService devicePeersService = SpringUtils.getBean(DevicePeersService.class);
+ List peersList = devicePeersService.getListByDeviceNo(deviceNo);
+ for (DevicePeersConfigDTO configDTO : peersList){
+ if (configDTO.getStatus() == DevicePeerStatusEnum.DISABLE.getStatus()) {
+ continue;
+ }
+ devicePeersService.sendMsgPeerConfig(configDTO);
+ }
+
+ }
+
+ @OnError
+ public void onError(Throwable t) throws Throwable {
+// log.error("Bullet Client[{}] Error: {}", this.deviceNo, t.toString());
+//// if (!(t instanceof EOFException)) {
+//// log.error("", t);
+//// }
+// log.error("", t);
+ WebsocketPool pool = SpringUtils.getBean(WebsocketPool.class);
+// if (this.deviceStatus) { // 正常设备才能移除
+ pool.removeConnection(this, String.format("异常-%s",t.getMessage()));
+//
+// }
+// this.deviceStatus = false;
+
+
+ ServerTunnelService serverTunnelService = SpringUtils.getBean(ServerTunnelService.class);
+ serverTunnelService.updateStatus(tunnelId, 0);
+ }
+
+
+
+
+ /**
+ * 获取会话信息
+ *
+ * @return
+ */
+ public Session getSession() {
+ return this.session;
+ }
+
+
+
+ /**
+ * 服务器端主动关闭连接
+ */
+ public void stop(CloseReason.CloseCode closeCode, String message) {
+ CloseReason closeReason = new CloseReason(closeCode, message);
+ try {
+ if (this.session.isOpen()) {
+ this.session.close(closeReason);
+ }
+ } catch (IOException e) {
+ log.error("", e);
+ }
+ }
+
+
+
+
+ /**
+ * 发送数据到客户端
+ *
+ * @param message 消息
+ * @throws IOException
+ */
+ public void sendObject(Object message) throws IOException {
+ Message message1 = (Message) message;
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ message1.write(outputStream);
+ // 包装了Bullet协议的
+ byte[] resultBytes = outputStream.toByteArray();
+ ByteBuffer buf = ByteBuffer.wrap(resultBytes);
+ this.session.getBasicRemote().sendBinary(buf, true);
+ }
+
+
+ /**
+ * 发送消息
+ *
+ * @param msg
+ */
+ @SneakyThrows
+ public void sendMessage(String clientNo, Message msg) {
+ log.info("Control -> Server -> Client: {} {}", msg.getCommand(),msg.getSequence());
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ try {
+ outputStream.write(Utils.IntToBytes4(CONTROL_CLIENT_WRAPPER));
+ outputStream.write(Utils.IntToBytes4(clientNo.length()));
+ outputStream.write(clientNo.getBytes(StandardCharsets.UTF_8));
+ msg.write(outputStream);
+ // 包装了Bullet协议的
+ byte[] resultBytes = outputStream.toByteArray();
+ ByteBuffer buf = ByteBuffer.wrap(resultBytes);
+ this.session.getBasicRemote().sendBinary(buf, true);
+ } catch (Exception e) {
+ log.error("", e);
+ } finally {
+ IOUtils.closeQuietly(outputStream);
+ }
+ }
+
+
+
+ public void sendMessageToServer(MsgGetDeviceStatus msg) {
+ log.info("Control -> Server: {} {}", msg.getCommand(),msg.getSequence());
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ try {
+ outputStream.write(Utils.IntToBytes4(CONTROL_SERVER_WRAPPER));
+ msg.write(outputStream);
+ // 包装了Bullet协议的
+ byte[] resultBytes = outputStream.toByteArray();
+ ByteBuffer buf = ByteBuffer.wrap(resultBytes);
+ this.session.getBasicRemote().sendBinary(buf, true);
+ } catch (Exception e) {
+ log.error("", e);
+ } finally {
+ IOUtils.closeQuietly(outputStream);
+ }
+
+ }
+
+ public void stop(String message) {
+ this.stop(CloseReason.CloseCodes.NORMAL_CLOSURE, message);
+ }
+
+ public Integer getTunnelId() {
+ return this.tunnelId;
+ }
+}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/websocket/BulletAnnotation.java b/joggle-server/src/main/java/com/wuweibi/bullet/websocket/BulletAnnotation.java
index 18b467b6..c20e67bf 100755
--- a/joggle-server/src/main/java/com/wuweibi/bullet/websocket/BulletAnnotation.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/websocket/BulletAnnotation.java
@@ -24,7 +24,7 @@
import com.wuweibi.bullet.device.domain.DevicePeersConfigDTO;
import com.wuweibi.bullet.device.domain.dto.DeviceOnlineInfoDTO;
import com.wuweibi.bullet.device.service.DevicePeersService;
-import com.wuweibi.bullet.entity.Device;
+import com.wuweibi.bullet.device.entity.Device;
import com.wuweibi.bullet.entity.DeviceMapping;
import com.wuweibi.bullet.exception.BaseException;
import com.wuweibi.bullet.protocol.*;
@@ -428,6 +428,7 @@ public void sendObject(Object message) throws IOException {
* @param msg
*/
@SneakyThrows
+ @Deprecated
public void sendMessage(Message msg) {
log.info("websocket send: {} {}", msg.getCommand(),msg.getSequence());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/websocket/LogAnnotation.java b/joggle-server/src/main/java/com/wuweibi/bullet/websocket/LogAnnotation.java
index 6a14b252..13b8ceb6 100755
--- a/joggle-server/src/main/java/com/wuweibi/bullet/websocket/LogAnnotation.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/websocket/LogAnnotation.java
@@ -17,7 +17,7 @@
package com.wuweibi.bullet.websocket;
import com.wuweibi.bullet.conn.CoonPool;
-import com.wuweibi.bullet.entity.Device;
+import com.wuweibi.bullet.device.entity.Device;
import com.wuweibi.bullet.protocol.MsgLogOpen;
import com.wuweibi.bullet.service.DeviceService;
import com.wuweibi.bullet.utils.SpringUtils;
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/websocket/WebSocketConfigurator.java b/joggle-server/src/main/java/com/wuweibi/bullet/websocket/WebSocketConfigurator.java
index 7385c60f..60a9f677 100644
--- a/joggle-server/src/main/java/com/wuweibi/bullet/websocket/WebSocketConfigurator.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/websocket/WebSocketConfigurator.java
@@ -1,10 +1,10 @@
package com.wuweibi.bullet.websocket;
-import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
-import java.util.Enumeration;
+import javax.ws.rs.core.HttpHeaders;
+import java.util.List;
import java.util.Map;
public class WebSocketConfigurator extends ServerEndpointConfig.Configurator {
@@ -15,15 +15,16 @@ public class WebSocketConfigurator extends ServerEndpointConfig.Configurator {
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
Map attributes = sec.getUserProperties();
- HttpSession session = (HttpSession) request.getHttpSession();
+ List values = request.getHeaders().get(HttpHeaders.AUTHORIZATION);
- if (session != null) {
- attributes.put(IP_ADDR, session.getAttribute("ip"));
- Enumeration names = session.getAttributeNames();
- while (names.hasMoreElements()) {
- String name = names.nextElement();
- attributes.put(name, session.getAttribute(name));
- }
- }
+ attributes.put("authorization", null != values?values.get(0): "");
+// if (session != null) {
+// attributes.put(IP_ADDR, session.getAttribute("ip"));
+// Enumeration names = session.getAttributeNames();
+// while (names.hasMoreElements()) {
+// String name = names.nextElement();
+// attributes.put(name, session.getAttribute(name));
+// }
+// }
}
}
diff --git a/joggle-server/src/main/java/com/wuweibi/bullet/weixin/WXBizDataCrypt.java b/joggle-server/src/main/java/com/wuweibi/bullet/weixin/WXBizDataCrypt.java
index d5744b9a..7643bc15 100755
--- a/joggle-server/src/main/java/com/wuweibi/bullet/weixin/WXBizDataCrypt.java
+++ b/joggle-server/src/main/java/com/wuweibi/bullet/weixin/WXBizDataCrypt.java
@@ -4,12 +4,12 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import sun.misc.BASE64Decoder;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.Security;
+import java.util.Base64;
/**
* 微信小程序
@@ -43,7 +43,7 @@ public JSONObject decrypt(String encryptedData, String iv) throws Exception {
String jsonStr = new String("");
try {
- BASE64Decoder base64Decoder = new BASE64Decoder();
+ Base64.Decoder base64Decoder = Base64.getDecoder();
/**
* 小程序加密数据解密算法
* https://developers.weixin.qq.com/miniprogram/dev/api/signature.html#wxchecksessionobject
@@ -51,9 +51,9 @@ public JSONObject decrypt(String encryptedData, String iv) throws Exception {
* 2.对称解密秘钥 aeskey = Base64_Decode(session_key), aeskey 是16字节。
* 3.对称解密算法初始向量 为Base64_Decode(iv),其中iv由数据接口返回。
*/
- byte[] encryptedByte = base64Decoder.decodeBuffer(encryptedData);
- byte[] sessionKeyByte = base64Decoder.decodeBuffer(this.sessionKey);
- byte[] ivByte = base64Decoder.decodeBuffer(iv);
+ byte[] encryptedByte = base64Decoder.decode(encryptedData);
+ byte[] sessionKeyByte = base64Decoder.decode(this.sessionKey);
+ byte[] ivByte = base64Decoder.decode(iv);
/**
* 以下为AES-128-CBC解密算法
*/
diff --git a/joggle-server/src/main/resources/META-INF/spring.factories b/joggle-server/src/main/resources/META-INF/spring.factories
index d989563a..ee1c5495 100644
--- a/joggle-server/src/main/resources/META-INF/spring.factories
+++ b/joggle-server/src/main/resources/META-INF/spring.factories
@@ -1,2 +1,2 @@
org.springframework.boot.SpringApplicationRunListener=\
-com.wuweibi.bullet.listener.BulletSpringApplicationRunListener
+com.wuweibi.bullet.listener.SpringApplicationRunListener
diff --git a/joggle-server/src/main/resources/logback-common.xml b/joggle-server/src/main/resources/logback-common.xml
index 6e8db815..795a2abb 100644
--- a/joggle-server/src/main/resources/logback-common.xml
+++ b/joggle-server/src/main/resources/logback-common.xml
@@ -80,6 +80,7 @@
+
diff --git a/joggle-server/src/main/resources/mapper/Device.xml b/joggle-server/src/main/resources/mapper/Device.xml
index 43da88c5..23656c1e 100644
--- a/joggle-server/src/main/resources/mapper/Device.xml
+++ b/joggle-server/src/main/resources/mapper/Device.xml
@@ -32,10 +32,36 @@
+
+
+
+
+
+
+
diff --git a/joggle-server/src/main/resources/mapper/DeviceOnline.xml b/joggle-server/src/main/resources/mapper/DeviceOnline.xml
index 0b90109a..9e57f2ae 100644
--- a/joggle-server/src/main/resources/mapper/DeviceOnline.xml
+++ b/joggle-server/src/main/resources/mapper/DeviceOnline.xml
@@ -15,6 +15,23 @@
+
+ update t_device_online set status=#{status}, updateTime=sysdate() where deviceNo=#{deviceNo}
+
+
+
+
+ update t_device_online set status=#{status}, updateTime=sysdate() where deviceNo in
+
+ #{item}
+
+
+
+
+ update t_device_online set status=-1, updateTime=sysdate() where server_tunnel_id=#{tunnelId}
+
+
+
- Copyright © 2014 - 2022 www.{{config.domain}} All rights reserved.
蜀ICP备14017469号-2
+ Copyright © 2014 - 2022 {{config.website}} All rights reserved.
蜀ICP备14017469号-2
diff --git a/joggle-server/src/main/resources/static/js/faceinner.ajax.js b/joggle-server/src/main/resources/static/js/faceinner.ajax.js
index b09d2c30..3df17a57 100644
--- a/joggle-server/src/main/resources/static/js/faceinner.ajax.js
+++ b/joggle-server/src/main/resources/static/js/faceinner.ajax.js
@@ -7,7 +7,7 @@
*/
// 读取服务器地址
-let server = 'http://localhost:8081';
+let server = 'http://192.168.1.20:8081';
if(window.SERVER_URL && window.SERVER_URL != '${url}'){ // 如果配置了
server = window.SERVER_URL;
}
diff --git a/joggle-server/src/main/resources/static/view/device/bind.js b/joggle-server/src/main/resources/static/view/device/bind.js
index e8be756a..375e8af7 100644
--- a/joggle-server/src/main/resources/static/view/device/bind.js
+++ b/joggle-server/src/main/resources/static/view/device/bind.js
@@ -28,12 +28,12 @@ define(['app','jquery'], function (app, $) {//加载依赖js,
$("#progress-bar .progress-bar").removeClass("progress-bar-danger");
$("#progress-bar .progress-bar").addClass("progress-bar-success");
$("#progress-bar .progress-bar").css({width:"100%"});
- $scope.info = "绑定完成! 等待3秒跳转到 > 我的设备。";
+ $scope.info = "绑定完成! 等待1秒跳转到 > 我的设备。";
})
// 准备跳转
- $scope.time = 2;
+ $scope.time = 1;
let timer = $interval(function(){
let num = $scope.time - 1;
if (num >= 0) {
@@ -45,7 +45,7 @@ define(['app','jquery'], function (app, $) {//加载依赖js,
$location.path("/user/device");
$interval.cancel(timer);
}
- }, 1000);
+ }, 500);
} else {
$scope.$apply(function(){
diff --git a/joggle-server/src/main/resources/static/view/device/device.htm b/joggle-server/src/main/resources/static/view/device/device.htm
index 261d9b61..2eb6d4cc 100644
--- a/joggle-server/src/main/resources/static/view/device/device.htm
+++ b/joggle-server/src/main/resources/static/view/device/device.htm
@@ -18,7 +18,7 @@
- 您还没有绑定设备,赶紧去
下载客户端程序运行并绑定吧!
+ 您还没有绑定设备,赶紧去
下载客户端程序运行并绑定吧!
@@ -34,7 +34,7 @@
别名:{{item.name}}
-
编码:{{item.deviceId}}
+
编码:{{item.deviceNo}}
地址:{{item.intranetIp}}
diff --git a/joggle-server/src/main/resources/static/view/device/device.js b/joggle-server/src/main/resources/static/view/device/device.js
index 62f76625..d657a742 100644
--- a/joggle-server/src/main/resources/static/view/device/device.js
+++ b/joggle-server/src/main/resources/static/view/device/device.js
@@ -17,13 +17,10 @@ define(['app','jquery', 'css!./device.css'], function (app, $) {//加载依赖js
function render(){
faceinner.get(api['user.device'], function(res){
- if (res.status == 0) {
+ if (res.code == "S00") {
$scope.$apply(function() {
- // res.data = res.data.concat(res.data);
-
$scope.list = res.data;
$.each($scope.list, function(i,item){
-
item.onlineTimeStr = (new Date(item.onlineTime))
.format("yyyy-MM-dd hh:mm:ss");
});
@@ -62,10 +59,12 @@ define(['app','jquery', 'css!./device.css'], function (app, $) {//加载依赖js
*/
$scope.confirmDeleteDevice = function(){
faceinner.delete(api['user.device'], $scope.item , function(res) {
- if (res.status == 0) {
+ if (res.code == "S00") {
$("#delDevice").modal('hide');
render();
+ return
}
+ layer.msg(res.msg)
});
};
diff --git a/joggle-server/src/main/resources/static/view/device/mapping.css b/joggle-server/src/main/resources/static/view/device/mapping.css
new file mode 100644
index 00000000..e38b4e36
--- /dev/null
+++ b/joggle-server/src/main/resources/static/view/device/mapping.css
@@ -0,0 +1,68 @@
+
+.mapping .item-text{
+ margin-bottom: 4px;
+ white-space: nowrap;
+}
+.mapping .item-wrap{
+ border: 1px #ccc solid;
+ padding: 10px 20px;
+ overflow: hidden;
+ height: 90px;
+ margin-bottom: 20px;
+ display: block;
+ color:#000;
+}
+
+.mapping .item-wrap:hover{
+ cursor: pointer;
+ background: #efefef;
+ border: 1px #4CAF50 solid;
+}
+.mapping .item-server{
+ position: relative;
+ margin: 0 auto;
+ height: 66px;
+ width: 80px;
+}
+.mapping .item-icon {
+ font-size: 80px; color:#383838;
+ position: absolute;
+ top: -3px;
+}
+.mapping .item-status.label-success{
+ background: #0de216;
+}
+.mapping .item-status{
+ display: block;
+ background: #ffe300;
+ width: 7px;
+ height: 7px;
+ z-index: 999;
+ position: absolute;
+ right: 5px;
+ top: 8px;
+ border-radius: 4px;
+}
+
+
+
+
+.mapping .mapping-feature-item{
+ border:1px #ccc solid;
+ text-align: center;
+ padding: 10px 0;
+}
+
+.mapping .mapping-feature-item p{
+ color: #929292;
+}
+.mapping .no-device-info{
+ text-align: center;
+ margin-top: 7rem;
+}
+.mapping .bind-device{
+ float: right;
+}
+.mapping .bind-device:before{
+ content: '';
+}
\ No newline at end of file
diff --git a/joggle-server/src/main/resources/static/view/device/mapping.htm b/joggle-server/src/main/resources/static/view/device/mapping.htm
index 5dd272fe..e6626c89 100644
--- a/joggle-server/src/main/resources/static/view/device/mapping.htm
+++ b/joggle-server/src/main/resources/static/view/device/mapping.htm
@@ -1,5 +1,5 @@
-
+
@@ -50,25 +50,25 @@
-
-
+
宽带
{{deviceInfo.broadband}}MB
-
+
域名
{{features.domainCount}}个
-
+
端口
{{features.portCount}}个
@@ -314,10 +314,12 @@
绑定域名/端口
-
+
+
diff --git a/joggle-server/src/main/resources/static/view/device/mapping.js b/joggle-server/src/main/resources/static/view/device/mapping.js
index 39387bdb..abbf293f 100644
--- a/joggle-server/src/main/resources/static/view/device/mapping.js
+++ b/joggle-server/src/main/resources/static/view/device/mapping.js
@@ -5,7 +5,7 @@
* @author marker
* @date 2016-06-05
*/
-define(['app','jquery', 'layer','bootstrap-switch', 'css!./device.css'], function (app, $, layer) {//加载依赖js,
+define(['app','jquery', 'layer','bootstrap-switch', 'css!./mapping.css'], function (app, $, layer) {//加载依赖js,
let callback = ["$scope","$routeParams","$location","$rootScope", function ($scope, $routeParams,$location,$rootScope) {
$scope.active = 'device';
@@ -56,19 +56,19 @@ define(['app','jquery', 'layer','bootstrap-switch', 'css!./device.css'], functio
flushData();
- /**
- * 展示域名
- * @param item
- * @returns {*|string}
- */
- $scope.showDomain = function (item) {
- if (item.domain) {// 子域名
- return item.domain + '.' + $rootScope.config.domain;
- }
- if (item.hostname) {// 自定义域名 CNAME指向
- return item.hostname;
- }
- }
+ // /**
+ // * 展示域名
+ // * @param item
+ // * @returns {*|string}
+ // */
+ // $scope.showDomain = function (item) {
+ // if (item.domain) {// 子域名
+ // return item.domain + '.' + $rootScope.config.domain;
+ // }
+ // if (item.hostname) {// 自定义域名 CNAME指向
+ // return item.hostname;
+ // }
+ // }
/**
* 展示映射状态
@@ -449,7 +449,7 @@ define(['app','jquery', 'layer','bootstrap-switch', 'css!./device.css'], functio
*/
$scope.confirmDeleteDevice = function(){
faceinner.delete(api['user.device'], $scope.deviceInfo , function(res) {
- if (res.status == 0) {
+ if (res.code == 'S00') {
$("#delDevice").modal('hide');
window.history.back();
}
diff --git a/joggle-server/src/main/resources/static/view/domain/domain.htm b/joggle-server/src/main/resources/static/view/domain/domain.htm
index bccb8464..d268cfbb 100644
--- a/joggle-server/src/main/resources/static/view/domain/domain.htm
+++ b/joggle-server/src/main/resources/static/view/domain/domain.htm
@@ -18,15 +18,11 @@
-
+
-
+
- {{item.domain +'.' + config.domain}}
-
-
-
- {{item.domain}}
+ {{item.domainFull}}
{{item.dueTime}}
diff --git a/joggle-server/src/main/resources/static/view/download/download.htm b/joggle-server/src/main/resources/static/view/download/download.htm
index 9bc560ac..6bae3ae2 100644
--- a/joggle-server/src/main/resources/static/view/download/download.htm
+++ b/joggle-server/src/main/resources/static/view/download/download.htm
@@ -14,7 +14,7 @@
下载中心
Joggle Client [客户端]
-
Joggle Client 是一个内网服务器的代理程序。
+
Joggle Client 是一个内网服务器的Agent程序。
diff --git a/joggle-server/src/main/resources/static/view/home/index.htm b/joggle-server/src/main/resources/static/view/home/index.htm
index 529b8c0c..6b0bb744 100644
--- a/joggle-server/src/main/resources/static/view/home/index.htm
+++ b/joggle-server/src/main/resources/static/view/home/index.htm
@@ -90,7 +90,7 @@
什么是Joggle?
免费、开源
-
github/gitee下载最新的源代码
+
github下载最新的源代码
@@ -111,7 +111,7 @@
多平台支持
多协议支持
-
支持TCP、UDP、HTTP、HTTPS等协议
+
支持TCP、UDP、HTTP、HTTPS、P2P等协议
diff --git a/joggle-server/src/main/resources/static/view/login/login.htm b/joggle-server/src/main/resources/static/view/login/login.htm
index 5da70ff4..c00c9967 100644
--- a/joggle-server/src/main/resources/static/view/login/login.htm
+++ b/joggle-server/src/main/resources/static/view/login/login.htm
@@ -37,6 +37,7 @@
diff --git a/joggle-server/src/main/resources/static/view/login/login.js b/joggle-server/src/main/resources/static/view/login/login.js
index 5038a6b4..f933e953 100644
--- a/joggle-server/src/main/resources/static/view/login/login.js
+++ b/joggle-server/src/main/resources/static/view/login/login.js
@@ -11,6 +11,9 @@ define(['app','layer','css!./login.css'], function (app, layer) {// 加载依赖
function ($rootScope, $scope, $location, userService, $AjaxService, $session) {
// 登录操作
$scope.login = function(){
+
+ $scope.loginBtnDisable = true;
+
let params = {
username: $scope.user.name,
password: $scope.user.pass,
@@ -32,12 +35,19 @@ define(['app','layer','css!./login.css'], function (app, layer) {// 加载依赖
$rootScope.user = res.data;
$rootScope.islogin = true;
$location.path('/index').replace();
+
+ $scope.loginBtnDisable = false;
});
}
});
}else{
layer.msg(res.msg);
+ $scope.$apply(function() {
+ $scope.loginBtnDisable = false;
+ });
}
+
+
// faceinner.handleFieldError($scope, res);
});
};
diff --git a/joggle-server/src/main/resources/static/view/p2p/mapping/mapping.htm b/joggle-server/src/main/resources/static/view/p2p/mapping/mapping.htm
index 49648a62..2afeb1dd 100644
--- a/joggle-server/src/main/resources/static/view/p2p/mapping/mapping.htm
+++ b/joggle-server/src/main/resources/static/view/p2p/mapping/mapping.htm
@@ -5,6 +5,7 @@
- 首页
+ - 我的设备
- P2P映射管理
-
diff --git a/joggle-server/src/main/resources/static/view/pay/pay.htm b/joggle-server/src/main/resources/static/view/pay/pay.htm
index ebe87200..252d33c5 100644
--- a/joggle-server/src/main/resources/static/view/pay/pay.htm
+++ b/joggle-server/src/main/resources/static/view/pay/pay.htm
@@ -20,7 +20,7 @@
- {{data.type == 2? data.domain +'.' + config.domain: data.domain}}
+ {{data.domainFull}}
diff --git a/joggle-server/src/main/resources/static/view/service/domain-buy/domain-buy.css b/joggle-server/src/main/resources/static/view/service/domain-buy/domain-buy.css
index 760b6e2b..3ca15984 100644
--- a/joggle-server/src/main/resources/static/view/service/domain-buy/domain-buy.css
+++ b/joggle-server/src/main/resources/static/view/service/domain-buy/domain-buy.css
@@ -36,4 +36,8 @@
margin-top: 4px;
margin-left: 10px;
display: inline-block;
+}
+.domain-buy .item-domain{
+ background: #e7e7e7;
+ color: black;
}
\ No newline at end of file
diff --git a/joggle-server/src/main/resources/static/view/service/domain-buy/domain-buy.htm b/joggle-server/src/main/resources/static/view/service/domain-buy/domain-buy.htm
index 45b14509..464bc791 100644
--- a/joggle-server/src/main/resources/static/view/service/domain-buy/domain-buy.htm
+++ b/joggle-server/src/main/resources/static/view/service/domain-buy/domain-buy.htm
@@ -15,9 +15,15 @@