Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pengjinning committed Jan 15, 2025
1 parent e20a2b8 commit a8f2052
Show file tree
Hide file tree
Showing 18 changed files with 343 additions and 203 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2024-06-05 09:43:27
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2025-01-14 17:35:33
* @LastEditTime: 2025-01-15 13:51:23
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
Expand All @@ -27,8 +27,7 @@ Team Cooperation with AI powered Omnichannel customer service
- Multi-level organizational structure
- Role management
- Permission management
- Chat record management
- Group chat
- ...

### AI Chat

Expand All @@ -41,7 +40,6 @@ Team Cooperation with AI powered Omnichannel customer service
- Support multiple channels
- multiple routing strategies, and detailed assessment indicators
- Seating workbench
- Seat management
- ...

### Ticket
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public abstract class BaseEntity implements Serializable {
// private static final String timezone = "GMT+8";

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

// @NotBlank 在应用层(业务逻辑或表单验证)确保uid字段在提交时必须是非空且去除空格后有实际内容的。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public abstract class BaseEntityNoOrg implements Serializable {
// private static final String timezone = "GMT+8";

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

// @NotBlank 在应用层(业务逻辑或表单验证)确保uid字段在提交时必须是非空且去除空格后有实际内容的。
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.bytedesk.core.black.access;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

@Component
public class VisitorAccessInterceptor implements HandlerInterceptor {

@Autowired
private VisitorAccessService visitorAccessService;

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 从请求中获取visitor ID
String visitorId = request.getHeader("X-Visitor-ID");
if (visitorId == null) {
visitorId = request.getParameter("visitorId");
}

// 检查访问权限
if (visitorId != null && !visitorAccessService.isAllowed(visitorId)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Access denied for visitor: " + visitorId);
return false;
}

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* @Author: jackning 270580156@qq.com
* @Date: 2025-01-15 14:08:50
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2025-01-15 14:14:26
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
* contact: 270580156@qq.com
*
* Copyright (c) 2025 by bytedesk.com, All Rights Reserved.
*/
package com.bytedesk.core.black.access;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class VisitorAccessService {

private static final String BLOCKED_VISITOR_KEY = "bytedesk:blocked:visitor:";

@Autowired
private RedisTemplate<String, String> redisTemplate;

public boolean isAllowed(String visitorId) {
return !Boolean.TRUE.equals(redisTemplate.hasKey(BLOCKED_VISITOR_KEY + visitorId));
}

public void blockVisitor(String visitorId) {
redisTemplate.opsForValue().set(BLOCKED_VISITOR_KEY + visitorId, "blocked");
}

public void unblockVisitor(String visitorId) {
redisTemplate.delete(BLOCKED_VISITOR_KEY + visitorId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2024-01-26 15:28:57
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2024-12-24 17:57:12
* @LastEditTime: 2025-01-15 14:13:05
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
Expand All @@ -22,6 +22,7 @@
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.bytedesk.core.black.access.VisitorAccessInterceptor;
import com.bytedesk.core.ip.access.IpAccessInterceptor;

// import com.bytedesk.core.config.BytedeskProperties;
Expand All @@ -41,18 +42,24 @@ public class WebMvcConfig implements WebMvcConfigurer {
"classpath:/public/",
};

// @Autowired
// private IpInterceptor ipInterceptor;

@Autowired
private IpAccessInterceptor ipAccessInterceptor;

@Autowired
private VisitorAccessInterceptor visitorAccessInterceptor;

/**
* @{VisitorAnonymousController}
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry
// .addInterceptor(ipInterceptor)
.addInterceptor(ipAccessInterceptor)
.addPathPatterns("/visitor/api/v1/init", "/visitor/api/v1/thread");
// 注册IP访问拦截器
registry.addInterceptor(ipAccessInterceptor)
.addPathPatterns("/**");

// 注册Visitor访问拦截器,只拦截visitor相关接口
registry.addInterceptor(visitorAccessInterceptor)
.addPathPatterns("/visitor/**");
}

/**
Expand Down
98 changes: 48 additions & 50 deletions modules/core/src/main/java/com/bytedesk/core/ip/IpEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2024-05-17 13:03:15
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2024-12-24 22:03:12
* @LastEditTime: 2025-01-15 14:30:16
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
Expand All @@ -13,52 +13,50 @@
*/
package com.bytedesk.core.ip;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import com.bytedesk.core.base.BaseEntity;
import com.bytedesk.core.constant.TypeConsts;
import com.bytedesk.core.utils.StringSetConverter;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Entity
@Data
@Builder
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "bytedesk_core_ip")
public class IpEntity extends BaseEntity {
//
@Builder.Default
@Column(columnDefinition = TypeConsts.COLUMN_TYPE_TEXT)
@Convert(converter = StringSetConverter.class)
private Set<String> ips = new HashSet<>();
// private String ip;
// private String ipLocation;

private String ipRangeStart;

private String ipRangeEnd;

@Builder.Default
@Column(name = "ip_type")
private String type = IpTypeEnum.BLACKLIST.toString();

private String reason;

// time duration
private Date untilDate;
}
// import java.util.Date;
// import java.util.HashSet;
// import java.util.Set;

// import com.bytedesk.core.base.BaseEntity;
// import com.bytedesk.core.constant.TypeConsts;
// import com.bytedesk.core.utils.StringSetConverter;

// import jakarta.persistence.Column;
// import jakarta.persistence.Convert;
// import jakarta.persistence.Entity;
// import jakarta.persistence.Table;
// import lombok.AllArgsConstructor;
// import lombok.Builder;
// import lombok.Data;
// import lombok.EqualsAndHashCode;
// import lombok.NoArgsConstructor;
// import lombok.experimental.Accessors;

// @Entity
// @Data
// @Builder
// @Accessors(chain = true)
// @EqualsAndHashCode(callSuper = true)
// @AllArgsConstructor
// @NoArgsConstructor
// @Table(name = "bytedesk_core_ip")
// public class IpEntity extends BaseEntity {
// //
// @Builder.Default
// @Column(columnDefinition = TypeConsts.COLUMN_TYPE_TEXT)
// @Convert(converter = StringSetConverter.class)
// private Set<String> ips = new HashSet<>();

// private String ipRangeStart;

// private String ipRangeEnd;

// @Builder.Default
// @Column(name = "ip_type")
// private String type = IpTypeEnum.BLACKLIST.toString();

// private String reason;

// // time duration
// private Date untilDate;
// }
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2024-06-27 11:34:19
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2024-06-27 11:34:22
* @LastEditTime: 2025-01-15 14:30:42
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
Expand All @@ -13,14 +13,14 @@
*/
package com.bytedesk.core.ip;

import java.util.Optional;
// import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
// import org.springframework.data.jpa.repository.JpaRepository;
// import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

public interface IpRepository extends JpaRepository<IpEntity, Long>, JpaSpecificationExecutor<IpEntity> {
// public interface IpRepository extends JpaRepository<IpEntity, Long>, JpaSpecificationExecutor<IpEntity> {

Optional<IpEntity> findByUid(String uid);
// Optional<IpEntity> findByUid(String uid);

Optional<IpEntity> findFirstByOrgUid(String orgUid);
}
// Optional<IpEntity> findFirstByOrgUid(String orgUid);
// }
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2024-04-05 14:15:17
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2024-10-30 15:53:08
* @LastEditTime: 2025-01-15 14:31:28
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
Expand All @@ -13,10 +13,7 @@
*/
package com.bytedesk.core.ip;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -38,26 +35,26 @@ public class IpRestController {

private final IpService ipService;

@PostMapping("/block")
public ResponseEntity<?> blockIp(@RequestBody IpRequest request) {
ipService.blockIp(request);
return ResponseEntity.ok(JsonResult.success());
}
// @PostMapping("/block")
// public ResponseEntity<?> blockIp(@RequestBody IpRequest request) {
// ipService.blockIp(request);
// return ResponseEntity.ok(JsonResult.success());
// }

@PostMapping("/unblock")
public ResponseEntity<?> unblockIp(@RequestBody IpRequest request) {
return ResponseEntity.ok(JsonResult.success());
}
// @PostMapping("/unblock")
// public ResponseEntity<?> unblockIp(@RequestBody IpRequest request) {
// return ResponseEntity.ok(JsonResult.success());
// }

@PostMapping("/white")
public ResponseEntity<?> whiteIp(@RequestBody IpRequest request) {
return ResponseEntity.ok(JsonResult.success());
}
// @PostMapping("/white")
// public ResponseEntity<?> whiteIp(@RequestBody IpRequest request) {
// return ResponseEntity.ok(JsonResult.success());
// }

@PostMapping("/unwhite")
public ResponseEntity<?> unwhiteIp(@RequestBody IpRequest request) {
return ResponseEntity.ok(JsonResult.success());
}
// @PostMapping("/unwhite")
// public ResponseEntity<?> unwhiteIp(@RequestBody IpRequest request) {
// return ResponseEntity.ok(JsonResult.success());
// }

/**
* http://127.0.0.1:9003/ip/api/v1/
Expand Down
Loading

0 comments on commit a8f2052

Please sign in to comment.