added get_telnet_port
This commit is contained in:
1 parent
77fb7b0816
commit
df32a84f7e
9 files changed
+74
-4
No files matched your search
@@ -36,7 +36,7 @@ void get_telnet(const httplib::Request &request, httplib::Response &response) {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ifstream telnetfile("/etc/openrouter/telnet");
|
||||
std::ifstream telnetfile("/etc/openrouter/telnet/enabled");
|
||||
int telnet_enabled;
|
||||
telnetfile >> telnet_enabled;
|
||||
telnetfile.close();
|
||||
@@ -77,7 +77,7 @@ void set_telnet(const httplib::Request &request, httplib::Response &response) {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ofstream telnetfileout("/etc/openrouter/telnet");
|
||||
std::ofstream telnetfileout("/etc/openrouter/telnet/enabled");
|
||||
std::string new_telnet_enabled = json_body["enabled"];
|
||||
if (new_telnet_enabled == "0") {
|
||||
system("/etc/init.d/telnet stop");
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "telnet.hpp"
|
||||
#include <colors.h>
|
||||
#include "../../types.hpp"
|
||||
#include "../../routes.hpp"
|
||||
#include <json.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
void get_telnet_port(const httplib::Request &request, httplib::Response &response) {
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ifstream telnetportfile("/etc/openrouter/telnet/port");
|
||||
int telnet_port;
|
||||
telnetportfile >> telnet_port;
|
||||
telnetportfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"port":")" << telnet_port << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,6 @@
|
||||
void get_telnet(const httplib::Request &request, httplib::Response &response);
|
||||
void set_telnet(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
void get_telnet_port(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
#endif // SETTINGS_TELNET_HPP
|
||||
Reference in new issue
Block a user