This commit is contained in:
@ -4,6 +4,13 @@
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Older {
|
||||
|
||||
Database::~Database() {
|
||||
if (m_sqlite != nullptr) {
|
||||
sqlite3_close(m_sqlite);
|
||||
}
|
||||
}
|
||||
|
||||
bool Database::open(const std::string &path) {
|
||||
if (sqlite3_open(path.c_str(), &m_sqlite) != SQLITE_OK) {
|
||||
LOG(error) << "Can't open database: " << sqlite3_errmsg(m_sqlite);
|
||||
|
@ -10,6 +10,7 @@ typedef struct sqlite3 sqlite3;
|
||||
namespace Older {
|
||||
class Database {
|
||||
public:
|
||||
~Database();
|
||||
bool open(const std::string &path);
|
||||
void upsertVisitRecord(const std::string &url, const std::string &visitorUuid, const std::string &userAgent,
|
||||
int64_t viewTime);
|
||||
|
18
Readme.md
18
Readme.md
@ -162,7 +162,25 @@ curl -v -X POST \
|
||||
| salt | BLOB | NOT NULL | |
|
||||
| created_at | INTEGER | NOT NULL | |
|
||||
|
||||
## WebRTC Signal 服务
|
||||
|
||||
```javascript
|
||||
// /api/v1/webrtc/signal/{id}
|
||||
{
|
||||
"id": "server",
|
||||
"type": "request"
|
||||
}
|
||||
{
|
||||
"id": "DDeFJqNHPN",
|
||||
"type": "offer",
|
||||
"sdp": "v=0\r\no=rtc 2294191555 0 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n ......"
|
||||
}
|
||||
{
|
||||
"id": "server",
|
||||
"type": "answer",
|
||||
"sdp": "v=0\r\no=- 7471496884559213660 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n ......"
|
||||
}
|
||||
```
|
||||
|
||||
## Live2D 模型添加
|
||||
|
||||
|
@ -17,6 +17,9 @@
|
||||
#include <iostream>
|
||||
|
||||
bool isUrlValid(boost::asio::io_context &ioContext, const std::string &host, const std::string &port, const std::string &target);
|
||||
bool isPathValid(const std::string &docRoot, const std::string &target);
|
||||
|
||||
// ./UrlCheck -d ./database.sqlite -r ./amass_blog --delete-invalid=true --delete="/" --delete="/login" --delete="/MessageBoard" --delete="/我的博客"
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
boost::program_options::options_description description("Allowed options");
|
||||
@ -24,6 +27,8 @@ int main(int argc, char const *argv[]) {
|
||||
description.add_options()
|
||||
("help,h", "produce help message.")
|
||||
("database,d", boost::program_options::value<std::string>(),"set database path")
|
||||
("docroot,r", boost::program_options::value<std::string>(),"set docroot path")
|
||||
("delete", boost::program_options::value<std::vector <std::string>>(),"set docroot path")
|
||||
("delete-invalid", boost::program_options::value<bool>()->default_value(false),"delete invalid url");
|
||||
// clang-format on
|
||||
boost::program_options::variables_map values;
|
||||
@ -31,13 +36,23 @@ int main(int argc, char const *argv[]) {
|
||||
boost::program_options::notify(values);
|
||||
|
||||
std::string path;
|
||||
std::string docRoot;
|
||||
std::vector<std::string> removeItems;
|
||||
|
||||
if (values.count("help")) {
|
||||
std::cout << description << std::endl;
|
||||
std::exit(0);
|
||||
} else if (values.count("database")) {
|
||||
}
|
||||
if (values.count("database")) {
|
||||
path = values.at("database").as<std::string>();
|
||||
}
|
||||
if (values.count("docroot")) {
|
||||
docRoot = values.at("docroot").as<std::string>();
|
||||
}
|
||||
|
||||
if (values.count("delete")) {
|
||||
removeItems = values.at("delete").as<std::vector<std::string>>();
|
||||
}
|
||||
|
||||
if (path.empty()) {
|
||||
std::cerr << "please specify the database path." << std::endl;
|
||||
@ -48,6 +63,22 @@ int main(int argc, char const *argv[]) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (docRoot.empty()) {
|
||||
std::cerr << "please specify the doc root." << std::endl;
|
||||
std::cout << description << std::endl;
|
||||
return 1;
|
||||
} else if (!std::filesystem::exists(docRoot)) {
|
||||
std::cerr << "doc root " << docRoot << " not existed." << std::endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (!removeItems.empty()) {
|
||||
std::cout << "remove:\r " << std::endl;
|
||||
for (auto &item : removeItems) {
|
||||
std::cout << item << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
Older::Database database;
|
||||
if (!database.open(path)) {
|
||||
return 3;
|
||||
@ -56,10 +87,14 @@ int main(int argc, char const *argv[]) {
|
||||
boost::asio::io_context ioContext;
|
||||
auto items = database.visitRecords();
|
||||
for (auto &item : items) {
|
||||
bool valid = isUrlValid(ioContext, "amass.fun", "443", item.url);
|
||||
bool needDelete = std::find(removeItems.cbegin(), removeItems.cend(), item.url) != removeItems.cend();
|
||||
if (!needDelete) {
|
||||
needDelete = !isPathValid(docRoot, item.url) && values.at("delete-invalid").as<bool>();
|
||||
}
|
||||
// bool valid = isUrlValid(ioContext, "amass.fun", "443", item.url);
|
||||
std::cout << item.url << std::endl;
|
||||
std::cout << "valid: " << valid << std::endl;
|
||||
if (!valid && values.at("delete-invalid").as<bool>()) {
|
||||
|
||||
if (needDelete) {
|
||||
std::cout << "delete: " << database.removeVisitRecord(item.id) << std::endl;
|
||||
}
|
||||
std::cout << "----------" << std::endl;
|
||||
@ -68,6 +103,10 @@ int main(int argc, char const *argv[]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool isPathValid(const std::string &docRoot, const std::string &target) {
|
||||
return std::filesystem::exists(docRoot + target);
|
||||
}
|
||||
|
||||
bool isUrlValid(boost::asio::io_context &ioContext, const std::string &host, const std::string &port, const std::string &target) {
|
||||
using namespace boost;
|
||||
using namespace boost::asio;
|
||||
|
@ -50,6 +50,40 @@ location ^~ /api/v1/freedom {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
|
||||
location /api/v2/freedom {
|
||||
client_max_body_size 0;
|
||||
grpc_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
client_body_timeout 5m;
|
||||
grpc_read_timeout 315;
|
||||
grpc_send_timeout 5m;
|
||||
grpc_pass unix:/dev/shm/Freedom-Vless.socket;
|
||||
}
|
||||
|
||||
location /api/v3/freedom {
|
||||
if ($http_upgrade != "websocket") {
|
||||
return 404;
|
||||
}
|
||||
proxy_pass http://[::1]:1234;
|
||||
proxy_redirect off;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_read_timeout 5d;
|
||||
}
|
||||
|
||||
location /api/v4/freedom {
|
||||
if ($request_method != "POST") {
|
||||
return 404;
|
||||
}
|
||||
client_body_buffer_size 1m;
|
||||
client_body_timeout 1h;
|
||||
client_max_body_size 0;
|
||||
grpc_pass grpc://[::1]:3002;
|
||||
}
|
||||
|
||||
location ^~ /freedom {
|
||||
if ($content_type !~ "^application/grpc") {
|
||||
return 402;
|
||||
|
@ -9,7 +9,6 @@ WorkingDirectory=/root/Server
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
User=root
|
||||
Environment="LD_LIBRARY_PATH=/opt/Libraries/boost_1_87_0/lib:$LD_LIBRARY_PATH"
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
Reference in New Issue
Block a user