diff --git a/Base/Database.cpp b/Base/Database.cpp index 16812d3..c0dc89d 100644 --- a/Base/Database.cpp +++ b/Base/Database.cpp @@ -4,6 +4,13 @@ #include 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); diff --git a/Base/Database.h b/Base/Database.h index cee6e29..68127e6 100644 --- a/Base/Database.h +++ b/Base/Database.h @@ -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); diff --git a/Readme.md b/Readme.md index 40fae36..74d7219 100644 --- a/Readme.md +++ b/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 模型添加 diff --git a/Tools/UrlCheck.cpp b/Tools/UrlCheck.cpp index 17877f0..d064b65 100644 --- a/Tools/UrlCheck.cpp +++ b/Tools/UrlCheck.cpp @@ -17,6 +17,9 @@ #include 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(),"set database path") + ("docroot,r", boost::program_options::value(),"set docroot path") + ("delete", boost::program_options::value>(),"set docroot path") ("delete-invalid", boost::program_options::value()->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 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(); } + if (values.count("docroot")) { + docRoot = values.at("docroot").as(); + } + + if (values.count("delete")) { + removeItems = values.at("delete").as>(); + } 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 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()) { + + 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; diff --git a/resources/conf/server.conf b/resources/conf/server.conf index 9305581..3fe78fb 100644 --- a/resources/conf/server.conf +++ b/resources/conf/server.conf @@ -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; diff --git a/resources/older.service b/resources/older.service index 954c291..c3a521a 100644 --- a/resources/older.service +++ b/resources/older.service @@ -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