some review
This commit is contained in:
1 parent
00ce07f8f5
commit
726b8807e0
20 files changed
+15
-34
No files matched your search
@@ -1,4 +1,9 @@
|
|||||||
#include "OpenRouter.hpp"
|
#include "OpenRouter.hpp"
|
||||||
|
#include <colors.h>
|
||||||
|
#include "../settings/settings.hpp"
|
||||||
|
#include "../system/system.hpp"
|
||||||
|
#include <syslog.h>
|
||||||
|
#include "../security/cors.hpp"
|
||||||
|
|
||||||
OpenRouter::OpenRouter() {
|
OpenRouter::OpenRouter() {
|
||||||
this->srv.Post("/api/settings/telnet/get", settings::get_telnet);
|
this->srv.Post("/api/settings/telnet/get", settings::get_telnet);
|
||||||
@@ -45,11 +50,9 @@ OpenRouter::OpenRouter() {
|
|||||||
this->srv.set_mount_point("/css", "../src/web/css");
|
this->srv.set_mount_point("/css", "../src/web/css");
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenRouter::~OpenRouter() {
|
OpenRouter::~OpenRouter() = default;
|
||||||
|
|
||||||
}
|
int OpenRouter::serve(const std::string *ip, int port, int socket_flags) {
|
||||||
|
|
||||||
int OpenRouter::serve(const std::string ip, int port, int socket_flags) {
|
|
||||||
std::cout << GREEN << "Starting" << RESET << " server on [ " << YELLOW
|
std::cout << GREEN << "Starting" << RESET << " server on [ " << YELLOW
|
||||||
<< "0.0.0.0" << RESET << ":" << CYAN << "43244" << RESET << " ]" << std::endl;
|
<< "0.0.0.0" << RESET << ":" << CYAN << "43244" << RESET << " ]" << std::endl;
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,8 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <httplib.h>
|
#include <httplib.h>
|
||||||
#include <colors.h>
|
|
||||||
#include "../settings/settings.hpp"
|
|
||||||
#include "../system/system.hpp"
|
|
||||||
#include <syslog.h>
|
|
||||||
|
|
||||||
#define CORS_ENABLE
|
#define CORS_ENABLE
|
||||||
#include "../security/cors.hpp"
|
|
||||||
|
|
||||||
class OpenRouter {
|
class OpenRouter {
|
||||||
private:
|
private:
|
||||||
@@ -18,7 +13,7 @@ class OpenRouter {
|
|||||||
public:
|
public:
|
||||||
OpenRouter();
|
OpenRouter();
|
||||||
~OpenRouter();
|
~OpenRouter();
|
||||||
int serve(const std::string ip, int port, int socket_flags = 0);
|
int serve(const std::string *ip, int port, int socket_flags = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // OPENROUTER_HPP
|
#endif // OPENROUTER_HPP
|
||||||
@@ -5,12 +5,12 @@
|
|||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
#include "../types.hpp"
|
#include "../types.hpp"
|
||||||
|
|
||||||
bool authenticate(std::string token) {
|
bool authenticate(const std::string &token) {
|
||||||
httplib::Client cli(AUTH_SERVICE);
|
httplib::Client cli(AUTH_SERVICE);
|
||||||
|
|
||||||
std::stringstream body;
|
std::stringstream body;
|
||||||
body << R"({"token":")" << token << R"("})";
|
body << R"({"token":")" << token << R"("})";
|
||||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
httplib::Result res = cli.Post("/api/access", body.str(), JSON_TYPE);
|
||||||
if (res->status == httplib::OK_200) {
|
if (res->status == httplib::OK_200) {
|
||||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||||
if (resjson["access"] == "reject") {
|
if (resjson["access"] == "reject") {
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
bool authenticate(std::string token);
|
bool authenticate(const std::string token);
|
||||||
|
|
||||||
#endif // AUTH_HPP
|
#endif // AUTH_HPP
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "dns.hpp"
|
#include "dns.hpp"
|
||||||
#include <colors.h>
|
#include <colors.h>
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
#include "../../routes.hpp"
|
|
||||||
#include "../../types.hpp"
|
#include "../../types.hpp"
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include "../../auth/auth.hpp"
|
#include "../../auth/auth.hpp"
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "dns.hpp"
|
#include "dns.hpp"
|
||||||
#include <colors.h>
|
#include <colors.h>
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
#include "../../routes.hpp"
|
|
||||||
#include "../../types.hpp"
|
#include "../../types.hpp"
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include "../../auth/auth.hpp"
|
#include "../../auth/auth.hpp"
|
||||||
@@ -31,7 +30,7 @@ namespace settings {
|
|||||||
while (!domainsfile.eof()) {
|
while (!domainsfile.eof()) {
|
||||||
domainsfile >> ip_string;
|
domainsfile >> ip_string;
|
||||||
domainsfile >> domain_string;
|
domainsfile >> domain_string;
|
||||||
if (domain_string == "") {
|
if (domain_string.empty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
responsedata << R"({"ip":")" << ip_string << R"(","domain":")" << domain_string << R"("},)";
|
responsedata << R"({"ip":")" << ip_string << R"(","domain":")" << domain_string << R"("},)";
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "dns.hpp"
|
#include "dns.hpp"
|
||||||
#include <colors.h>
|
#include <colors.h>
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
#include "../../routes.hpp"
|
|
||||||
#include "../../types.hpp"
|
#include "../../types.hpp"
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include "../../auth/auth.hpp"
|
#include "../../auth/auth.hpp"
|
||||||
@@ -62,9 +61,9 @@ namespace settings {
|
|||||||
if (authenticate(json_body["token"])) {
|
if (authenticate(json_body["token"])) {
|
||||||
std::ofstream dnsserversfile("/etc/dnsmasq.conf.d/resolv.conf");
|
std::ofstream dnsserversfile("/etc/dnsmasq.conf.d/resolv.conf");
|
||||||
nlohmann::json servers = json_body["servers"];
|
nlohmann::json servers = json_body["servers"];
|
||||||
for (nlohmann::json_abi_v3_11_3::json server : servers) {
|
for (const nlohmann::json_abi_v3_11_3::json server : servers) {
|
||||||
std::string srv = server;
|
std::string srv = server;
|
||||||
if (server == "") {
|
if (server.empty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
dnsserversfile << "nameserver " << srv << "\n";
|
dnsserversfile << "nameserver " << srv << "\n";
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "ftp.hpp"
|
#include "ftp.hpp"
|
||||||
#include <colors.h>
|
#include <colors.h>
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
#include "../../routes.hpp"
|
|
||||||
#include "../../types.hpp"
|
#include "../../types.hpp"
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include "../../auth/auth.hpp"
|
#include "../../auth/auth.hpp"
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "ssh.hpp"
|
#include "ssh.hpp"
|
||||||
#include <colors.h>
|
#include <colors.h>
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
#include "../../routes.hpp"
|
|
||||||
#include "../../types.hpp"
|
#include "../../types.hpp"
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include "../../auth/auth.hpp"
|
#include "../../auth/auth.hpp"
|
||||||
@@ -30,7 +29,7 @@ namespace settings {
|
|||||||
std::string key_string = "";
|
std::string key_string = "";
|
||||||
int iter = 0;
|
int iter = 0;
|
||||||
while (std::getline(keysfile, key_string)) {
|
while (std::getline(keysfile, key_string)) {
|
||||||
if (key_string == "") {
|
if (key_string.empty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
responsedata << R"(")" << key_string << R"(",)";
|
responsedata << R"(")" << key_string << R"(",)";
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "ssh.hpp"
|
#include "ssh.hpp"
|
||||||
#include <colors.h>
|
#include <colors.h>
|
||||||
#include "../../types.hpp"
|
#include "../../types.hpp"
|
||||||
#include "../../routes.hpp"
|
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "ssh.hpp"
|
#include "ssh.hpp"
|
||||||
#include <colors.h>
|
#include <colors.h>
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
#include "../../routes.hpp"
|
|
||||||
#include "../../types.hpp"
|
#include "../../types.hpp"
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include "../../auth/auth.hpp"
|
#include "../../auth/auth.hpp"
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "telnet.hpp"
|
#include "telnet.hpp"
|
||||||
#include <colors.h>
|
#include <colors.h>
|
||||||
#include "../../types.hpp"
|
#include "../../types.hpp"
|
||||||
#include "../../routes.hpp"
|
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "telnet.hpp"
|
#include "telnet.hpp"
|
||||||
#include <colors.h>
|
#include <colors.h>
|
||||||
#include "../../types.hpp"
|
#include "../../types.hpp"
|
||||||
#include "../../routes.hpp"
|
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "wifi.hpp"
|
#include "wifi.hpp"
|
||||||
#include <colors.h>
|
#include <colors.h>
|
||||||
#include "../../types.hpp"
|
#include "../../types.hpp"
|
||||||
#include "../../routes.hpp"
|
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "wifi.hpp"
|
#include "wifi.hpp"
|
||||||
#include <colors.h>
|
#include <colors.h>
|
||||||
#include "../../types.hpp"
|
#include "../../types.hpp"
|
||||||
#include "../../routes.hpp"
|
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "wifi.hpp"
|
#include "wifi.hpp"
|
||||||
#include <colors.h>
|
#include <colors.h>
|
||||||
#include "../../types.hpp"
|
#include "../../types.hpp"
|
||||||
#include "../../routes.hpp"
|
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "wifi.hpp"
|
#include "wifi.hpp"
|
||||||
#include <colors.h>
|
#include <colors.h>
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
#include "../../routes.hpp"
|
|
||||||
#include "../../types.hpp"
|
#include "../../types.hpp"
|
||||||
#include <QR-Code-generator/qrcodegen.hpp>
|
#include <QR-Code-generator/qrcodegen.hpp>
|
||||||
#include <QR-Code-generator/qrtosvg.hpp>
|
#include <QR-Code-generator/qrtosvg.hpp>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "wifi.hpp"
|
#include "wifi.hpp"
|
||||||
#include <colors.h>
|
#include <colors.h>
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
#include "../../routes.hpp"
|
|
||||||
#include "../../types.hpp"
|
#include "../../types.hpp"
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include "../../auth/auth.hpp"
|
#include "../../auth/auth.hpp"
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#include "reboot.hpp"
|
#include "reboot.hpp"
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
#include "../routes.hpp"
|
|
||||||
#include <colors.h>
|
#include <colors.h>
|
||||||
#include "../types.hpp"
|
#include "../types.hpp"
|
||||||
#include "../../auth/auth.hpp"
|
#include "../../auth/auth.hpp"
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#include "syslog.hpp"
|
#include "syslog.hpp"
|
||||||
#include <colors.h>
|
|
||||||
#include "../types.hpp"
|
#include "../types.hpp"
|
||||||
#include "../routes.hpp"
|
|
||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|||||||
Reference in new issue
Block a user