added get_dns_servers_table and fix some errors
This commit is contained in:
1 parent
0a87be4d59
commit
defd2f551d
12 files changed
+107
-10
No files matched your search
@@ -10,7 +10,10 @@ add_executable(
|
||||
src/security/cors.cpp
|
||||
|
||||
src/settings/telnet/telnet.cpp
|
||||
|
||||
src/settings/dns/dns.cpp
|
||||
src/settings/dns/dns_servers.cpp
|
||||
|
||||
src/settings/ftp/ftp.cpp
|
||||
|
||||
src/reboot/reboot.cpp
|
||||
|
||||
@@ -14,8 +14,11 @@ int main() {
|
||||
|
||||
srv.Post("/api/settings/telnet/get", get_telnet);
|
||||
srv.Post("/api/settings/telnet/set", set_telnet);
|
||||
|
||||
srv.Post("/api/settings/dns/get", get_dns);
|
||||
srv.Post("/api/settings/dns/set", set_dns);
|
||||
srv.Post("/api/settings/dns/servers/get", get_dns_servers);
|
||||
|
||||
srv.Post("/api/settings/ftp/get", get_ftp);
|
||||
srv.Post("/api/settings/ftp/set", set_ftp);
|
||||
|
||||
|
||||
@@ -5,5 +5,6 @@
|
||||
|
||||
void get_dns(const httplib::Request &request, httplib::Response &response);
|
||||
void set_dns(const httplib::Request &request, httplib::Response &response);
|
||||
void get_dns_servers(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
#endif // DNS_HPP
|
||||
@@ -0,0 +1,48 @@
|
||||
#include "dns.hpp"
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include "../../routes.hpp"
|
||||
#include "../../types.hpp"
|
||||
|
||||
// #define DNS_REQUIRED_STRING R"({"required":"[token,enabled]"})"
|
||||
|
||||
void get_dns_servers(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 dnsserversfile("/etc/dnsmasq.conf.d/resolv.conf");
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"servers":[")";
|
||||
std::string dns_server_string = "";
|
||||
while (std::getline(dnsserversfile, dns_server_string)) {
|
||||
dns_server_string.erase(0, 11);
|
||||
responsedata << dns_server_string << R"(",")";
|
||||
dns_server_string = "";
|
||||
}
|
||||
responsedata.str(responsedata.str().erase(responsedata.str().size()-2, 2) + "]}");
|
||||
dnsserversfile.close();
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,7 @@
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border: 2px solid ;
|
||||
border-radius: 10px;
|
||||
}
|
||||
@@ -125,6 +126,7 @@ table {
|
||||
thead>tr>th {
|
||||
border-bottom: 2px solid;
|
||||
padding: 10px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
tbody>tr>th {
|
||||
|
||||
+11
-1
@@ -68,6 +68,15 @@
|
||||
<input type="checkbox" class="sc-gJwTLC ikxBAC" id="dnsenable">
|
||||
</div>
|
||||
</div>
|
||||
<div class="settingrectbody active" id="dnssettingsbody">
|
||||
<table class="dnsservers">
|
||||
<thead>
|
||||
<tr><th>dns servers</th></tr>
|
||||
</thead>
|
||||
<tbody id="dnsserverstablebody">
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="settingrectfooter">
|
||||
<button>Add dns server</button>
|
||||
<button id="set_dns_settings">Confirm</button>
|
||||
@@ -138,13 +147,14 @@
|
||||
<!-- loader -->
|
||||
<script src="js/routes.js"></script>
|
||||
<script src="js/notification.js"></script>
|
||||
<script src="js/login.js"></script>
|
||||
|
||||
<script src="js/settings/confirm.js"></script>
|
||||
<script src="js/settings/telnet.js"></script>
|
||||
<script src="js/settings/dns.js"></script>
|
||||
<script src="js/settings/ftp.js"></script>
|
||||
<script src="js/settings/settings.js"></script>
|
||||
|
||||
<script src="js/reboot.js"></script>
|
||||
<script src="js/login.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -10,6 +10,7 @@ if (localStorage.getItem("token") === null) {
|
||||
adminpanelsection.classList.remove('active')
|
||||
loginform.classList.add('active')
|
||||
} else {
|
||||
get_all_settings()
|
||||
adminpanelsection.classList.add('active')
|
||||
headerusername.innerHTML = JSON.parse(localStorage.getItem('userdata')).username
|
||||
}
|
||||
@@ -40,6 +41,7 @@ const login = async (username, password) => {
|
||||
notification("Успешно", "success")
|
||||
loginform.classList.remove("active")
|
||||
localStorage.setItem("token", response.token)
|
||||
get_all_settings()
|
||||
adminpanelsection.classList.add('active')
|
||||
await get_user_data()
|
||||
loginusername.value = ""
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const authhost = 'http://192.168.122.76:43243'
|
||||
const authhost = 'http://192.168.0.110:43243'
|
||||
const host = window.location.origin
|
||||
const prefix = 'api'
|
||||
|
||||
@@ -7,8 +7,11 @@ const routes = {
|
||||
user: () => [authhost, prefix, 'users', 'user'].join('/'),
|
||||
telnet_status: () => [host, prefix, 'settings', 'telnet', 'get'].join('/'),
|
||||
telnet_status_set: () => [host, prefix, 'settings', 'telnet', 'set'].join('/'),
|
||||
|
||||
dns_status: () => [host, prefix, 'settings', 'dns', 'get'].join('/'),
|
||||
dns_status_set: () => [host, prefix, 'settings', 'dns', 'set'].join('/'),
|
||||
dns_servers_get: () => [host, prefix, 'settings', 'dns', 'servers', 'get'].join('/'),
|
||||
|
||||
ftp_status: () => [host, prefix, 'settings', 'ftp', 'get'].join('/'),
|
||||
ftp_status_set: () => [host, prefix, 'settings', 'ftp', 'set'].join('/'),
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
const dnsenabled = document.querySelector('#dnsenable')
|
||||
const setdnssettingsbutton = document.querySelector('#set_dns_settings')
|
||||
const dnssettingbody = document.querySelector('#dnssettingsbody')
|
||||
const dnsserverstablebody = document.querySelector('#dnsserverstablebody')
|
||||
|
||||
const get_dns_enabled_status = () => {
|
||||
fetch(routes.dns_status(), {
|
||||
@@ -9,7 +11,7 @@ const get_dns_enabled_status = () => {
|
||||
console.log(jsondata)
|
||||
if (jsondata.enabled === '1') {
|
||||
dnsenabled.checked = true
|
||||
// dnssettingbody.classList.add('active')
|
||||
dnssettingbody.classList.add('active')
|
||||
return;
|
||||
}
|
||||
}).catch((error) => {
|
||||
@@ -17,8 +19,6 @@ const get_dns_enabled_status = () => {
|
||||
})
|
||||
}
|
||||
|
||||
get_dns_enabled_status()
|
||||
|
||||
const set_dns_enabled_status = () => {
|
||||
fetch(routes.dns_status_set(), {
|
||||
method: 'POST',
|
||||
@@ -26,7 +26,7 @@ const set_dns_enabled_status = () => {
|
||||
}).then(res => res.json()).then(jsondata => {
|
||||
if (jsondata.enabled === '1') {
|
||||
dnsenabled.checked = true
|
||||
// dnssettingbody.classList.add('active')
|
||||
dnssettingbody.classList.add('active')
|
||||
}
|
||||
notification("Настройки dns сохранены", "success")
|
||||
}).catch((error) => {
|
||||
@@ -37,3 +37,26 @@ const set_dns_enabled_status = () => {
|
||||
setdnssettingsbutton.addEventListener('click', () =>{
|
||||
get_confirm_form("Confirm dns settings?", set_dns_enabled_status)
|
||||
})
|
||||
|
||||
dnsenabled.addEventListener('click', () => {
|
||||
if (dnsenabled.checked) {
|
||||
dnssettingbody.classList.add('active')
|
||||
get_dns_server()
|
||||
} else {
|
||||
dnssettingbody.classList.remove('active')
|
||||
}
|
||||
})
|
||||
|
||||
const get_dns_server = () => {
|
||||
fetch(routes.dns_servers_get(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem("token")}"}`
|
||||
}).then(res => res.json()).then(jsondata => {
|
||||
console.log(jsondata)
|
||||
for (const server in jsondata.servers) {
|
||||
dnsserverstablebody.innerHTML += `<tr><th>${jsondata.servers[server]}</th></tr>`
|
||||
}
|
||||
}).catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error")
|
||||
})
|
||||
}
|
||||
@@ -17,8 +17,6 @@ const get_ftp_enabled_status = () => {
|
||||
})
|
||||
}
|
||||
|
||||
get_ftp_enabled_status()
|
||||
|
||||
const set_ftp_enabled_status = () => {
|
||||
fetch(routes.ftp_status_set(), {
|
||||
method: 'POST',
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
const get_all_settings = () => {
|
||||
get_dns_enabled_status()
|
||||
get_dns_server()
|
||||
get_ftp_enabled_status()
|
||||
get_telnet_enabled_status()
|
||||
}
|
||||
@@ -18,8 +18,6 @@ const get_telnet_enabled_status = () => {
|
||||
})
|
||||
}
|
||||
|
||||
get_telnet_enabled_status()
|
||||
|
||||
const set_telnet_enabled_status = () => {
|
||||
fetch(routes.telnet_status_set(), {
|
||||
method: 'POST',
|
||||
|
||||
Reference in new issue
Block a user