Skip to content

Commit

Permalink
修复 UA 可能为空的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-chu committed Oct 7, 2024
1 parent b304ab6 commit 03406b0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public abstract class SparkleController {

public String ua(HttpServletRequest req){
return req.getHeader("User-Agent");
return req.getHeader("User-Agent") != null ? req.getHeader("User-Agent") : "Unknown";
}

public String ip(HttpServletRequest req){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,19 @@ public static List<byte[]> extractInfoHashes(String queryString) {
@Transactional
@Lock(LockModeType.WRITE)
public byte[] announce() {
if (req.getQueryString() == null
|| req.getHeader("User-Agent").contains("Mozilla")
|| req.getHeader("User-Agent").contains("Chrome")
|| req.getHeader("User-Agent").contains("Firefox")
|| req.getHeader("User-Agent").contains("Safari")
|| req.getHeader("User-Agent").contains("Edge")
|| req.getHeader("User-Agent").contains("Opera")) {
if (req.getQueryString() == null) {
return "Sorry, This is a BitTorrent Tracker, and access announce endpoint via Browser is disallowed and useless.".getBytes(StandardCharsets.UTF_8);
}
if (ua(req) != null) {
if (ua(req).contains("Mozilla")
|| ua(req).contains("Chrome")
|| ua(req).contains("Firefox")
|| ua(req).contains("Safari")
|| ua(req).contains("Edge")
|| ua(req).contains("Opera")) {
return "Sorry, This is a BitTorrent Tracker, and access announce endpoint via Browser is disallowed and useless.".getBytes(StandardCharsets.UTF_8);
}
}
var infoHashes = extractInfoHashes(req.getQueryString());
Validate.isTrue(infoHashes.size() == 1);
byte[] infoHash = infoHashes.getFirst();
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
<div class="alert alert-warning" role="alert">
<b>🚧改版装修中</b> BTN 2.0 正在加紧施工中。由于缺乏前端人手,目前前端仅基本功能可用,不影响后端运行和上报收集等功能。
</div>
<div class="alert alert-danger" role="alert">
<b>🛑对 PBH v5 的服务终止</b> BTN Sparkle 现在不再接受任何来自 PeerBanHelper v5.x 的数据,且不再返回 BTN 规则,请尽快升级到 PeerBanHelper v6.x <a href="https://github.com/PBH-BTN/PeerBanHelper/issues/372">了解更多</a>
<div class="alert alert-info" role="alert">
<b>🤯Sparkle Tracker 正在公测</b> 添加 <span>https://btn-prod.ghostchu-services.top/tracker/announce</span> 到种子
Tracker 列表来试用 Sparkle Tracker!
</div>
alert alert-info

<div class="jumbotron">
<h1 class="display-4">Sparkle - BTN Instance</h1>
Expand Down

0 comments on commit 03406b0

Please sign in to comment.