Skip to content
This repository was archived by the owner on Aug 2, 2020. It is now read-only.

Commit 1a8bad6

Browse files
committed
Remove ca_cert_downloader plugin, move the functionality to websocket_reverse
1 parent 8f3908d commit 1a8bad6

File tree

5 files changed

+31
-55
lines changed

5 files changed

+31
-55
lines changed

src/cqhttp/core/common.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#pragma once
22

3-
#include <ciso646>
4-
53
#include <nlohmann/json.hpp>
64
using json = nlohmann::json;
75

src/cqhttp/plugins/ca_cert_downloader/ca_cert_downloader.cpp

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/cqhttp/plugins/ca_cert_downloader/ca_cert_downloader.h

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/cqhttp/plugins/web/websocket_reverse.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,46 @@
11
#include "./websocket_reverse.h"
22

3+
#include <filesystem>
4+
#include <regex>
5+
6+
#include "cqhttp/core/core.h"
7+
#include "cqhttp/core/helpers.h"
8+
#include "cqhttp/utils/http.h"
9+
310
using namespace std;
11+
namespace fs = std::filesystem;
412

513
namespace cqhttp::plugins {
614
static const auto TAG = "反向WS";
715

16+
using utils::http::download_file;
17+
using helpers::get_asset_url;
18+
819
static string check_ws_url(const string &url) {
9-
if (!url.empty() && !regex_search(url, regex("^wss?://"))) {
20+
if (!url.empty() && !regex_search(url, regex("^wss?://", regex::icase))) {
1021
// bad websocket url, we warn the user, and ignore the url
1122
logging::warning(TAG, u8"反向 WebSocket 服务端地址 " + url + u8" 不是合法地址,将被忽略");
1223
return "";
1324
}
25+
if (boost::istarts_with(url, "wss://")) {
26+
const auto cacert_file = cq::dir::app("tmp") + "cacert.pem";
27+
auto ok = true;
28+
29+
if (!fs::exists(ansi(cacert_file))) {
30+
logging::info(
31+
TAG, u8"正在下载 CA 证书文件,这只会在第一次启动时进行,如果耗时较长,请在配置文件中更换更新源");
32+
if (download_file(get_asset_url("cacert.pem"), cacert_file, true)) {
33+
logging::info_success(TAG, u8"下载 CA 证书文件成功");
34+
} else {
35+
logging::warning(TAG, u8"下载 CA 证书文件失败,可能导致无法 WSS");
36+
ok = false;
37+
}
38+
}
39+
40+
if (ok) {
41+
app.store().put("cacert_file", cacert_file);
42+
}
43+
}
1444
return url;
1545
}
1646

src/main.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "cqhttp/plugins/config_loader/ini_config_loader.h"
77
#include "cqhttp/plugins/config_loader/json_config_loader.h"
88

9-
#include "cqhttp/plugins/ca_cert_downloader/ca_cert_downloader.h"
109
#include "cqhttp/plugins/heartbeat_generator/heartbeat_generator.h"
1110
#include "cqhttp/plugins/loggers/loggers.h"
1211
#include "cqhttp/plugins/worker_pool_resizer/worker_pool_resizer.h"
@@ -42,7 +41,6 @@ CQ_MAIN {
4241
// config global things
4342
use(plugins::loggers);
4443
use(plugins::worker_pool_resizer);
45-
use(plugins::ca_cert_downloader);
4644
use(plugins::heartbeat_generator);
4745

4846
// extend the Context object

0 commit comments

Comments
 (0)