added get_ssh_server and set_ssh_server
This commit is contained in:
1 parent
f7b1d75bab
commit
5a1a3a92a2
10 files changed
+133
-3
No files matched your search
@@ -15,6 +15,8 @@ add_executable(
|
|||||||
src/settings/ssh/status.cpp
|
src/settings/ssh/status.cpp
|
||||||
src/settings/ssh/keys.cpp
|
src/settings/ssh/keys.cpp
|
||||||
src/settings/ssh/port.cpp
|
src/settings/ssh/port.cpp
|
||||||
|
src/settings/ssh/server.cpp
|
||||||
|
|
||||||
|
|
||||||
src/settings/dns/enabled.cpp
|
src/settings/dns/enabled.cpp
|
||||||
src/settings/dns/servers.cpp
|
src/settings/dns/servers.cpp
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ executable(
|
|||||||
'src/settings/ssh/status.cpp',
|
'src/settings/ssh/status.cpp',
|
||||||
'src/settings/ssh/keys.cpp',
|
'src/settings/ssh/keys.cpp',
|
||||||
'src/settings/ssh/port.cpp',
|
'src/settings/ssh/port.cpp',
|
||||||
|
'src/settings/ssh/server.cpp',
|
||||||
|
|
||||||
'src/settings/dns/enabled.cpp',
|
'src/settings/dns/enabled.cpp',
|
||||||
'src/settings/dns/servers.cpp',
|
'src/settings/dns/servers.cpp',
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ OpenRouter::OpenRouter()
|
|||||||
this->srv.Post("/api/settings/ssh/keys/set", api::settings::set_ssh_keys);
|
this->srv.Post("/api/settings/ssh/keys/set", api::settings::set_ssh_keys);
|
||||||
this->srv.Post("/api/settings/ssh/port/get", api::settings::get_ssh_port);
|
this->srv.Post("/api/settings/ssh/port/get", api::settings::get_ssh_port);
|
||||||
this->srv.Post("/api/settings/ssh/port/set", api::settings::set_ssh_port);
|
this->srv.Post("/api/settings/ssh/port/set", api::settings::set_ssh_port);
|
||||||
|
this->srv.Post("/api/settings/ssh/server/get", api::settings::get_ssh_server_http);
|
||||||
|
this->srv.Post("/api/settings/ssh/server/set", api::settings::set_ssh_server_http);
|
||||||
|
|
||||||
this->srv.Post("/api/settings/dns/get", api::settings::get_dns);
|
this->srv.Post("/api/settings/dns/get", api::settings::get_dns);
|
||||||
this->srv.Post("/api/settings/dns/set", api::settings::set_dns);
|
this->srv.Post("/api/settings/dns/set", api::settings::set_dns);
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
#include <settings/ssh/ssh.hpp>
|
||||||
|
#include <fstream>
|
||||||
|
#include <json.hpp>
|
||||||
|
#include <colors.h>
|
||||||
|
#include <helpers.hpp>
|
||||||
|
#include <types.hpp>
|
||||||
|
#include <auth/auth.hpp>
|
||||||
|
|
||||||
|
#define SSH_SERVER_REQUIRED_STRING R"({"required":"[token,server]"})"
|
||||||
|
|
||||||
|
namespace api
|
||||||
|
{
|
||||||
|
namespace settings
|
||||||
|
{
|
||||||
|
std::string get_ssh_server()
|
||||||
|
{
|
||||||
|
std::ifstream serverfile("/etc/openrouter/ssh/server");
|
||||||
|
std::string ssh_server = "";
|
||||||
|
serverfile >> ssh_server;
|
||||||
|
serverfile.close();
|
||||||
|
return ssh_server;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string set_ssh_server(std::string &server)
|
||||||
|
{
|
||||||
|
std::ofstream serverfile("/etc/openrouter/ssh/server");
|
||||||
|
serverfile << server;
|
||||||
|
serverfile.close();
|
||||||
|
return get_ssh_server();
|
||||||
|
}
|
||||||
|
|
||||||
|
void get_ssh_server_http(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 (!check_body(request))
|
||||||
|
{
|
||||||
|
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||||
|
|
||||||
|
if (!authenticate(json_body["token"]))
|
||||||
|
{
|
||||||
|
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::stringstream responsedata;
|
||||||
|
responsedata << R"({"server":")" << get_ssh_server() << R"("})";
|
||||||
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
|
}
|
||||||
|
void set_ssh_server_http(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 (!check_body(request))
|
||||||
|
{
|
||||||
|
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||||
|
|
||||||
|
if (json_body["server"] == nullptr)
|
||||||
|
{
|
||||||
|
response.set_content(SSH_SERVER_REQUIRED_STRING, JSON_TYPE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!authenticate(json_body["token"]))
|
||||||
|
{
|
||||||
|
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::stringstream responsedata;
|
||||||
|
std::string server = json_body["server"];
|
||||||
|
responsedata << R"({"server":")" << set_ssh_server(server) << R"("})";
|
||||||
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,12 @@ namespace api
|
|||||||
{
|
{
|
||||||
namespace settings
|
namespace settings
|
||||||
{
|
{
|
||||||
|
std::string get_ssh_server();
|
||||||
|
std::string set_ssh_server(std::string &server);
|
||||||
|
|
||||||
|
void get_ssh_server_http(const httplib::Request &request, httplib::Response &response);
|
||||||
|
void set_ssh_server_http(const httplib::Request &request, httplib::Response &response);
|
||||||
|
|
||||||
void get_ssh_status(const httplib::Request &request, httplib::Response &response);
|
void get_ssh_status(const httplib::Request &request, httplib::Response &response);
|
||||||
void set_ssh_status(const httplib::Request &request, httplib::Response &response);
|
void set_ssh_status(const httplib::Request &request, httplib::Response &response);
|
||||||
|
|
||||||
|
|||||||
@@ -120,6 +120,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="settingrectbody" id="sshsettingsbody">
|
<div class="settingrectbody" id="sshsettingsbody">
|
||||||
|
<div style="display:flex;align-items:center;justify-content:space-between;">
|
||||||
|
<label for="sshserverinput" class="forminputlabel">Server</label>
|
||||||
|
<select name="selectserver" id="sshserverinput">
|
||||||
|
<option value="dropbear">dropbear</option>
|
||||||
|
<option value="openssh">openssh</option>
|
||||||
|
</select>
|
||||||
|
<!-- <input type="text" id="sshserverinput" class="forminput"> -->
|
||||||
|
</div>
|
||||||
<div style="display:flex;align-items:center;justify-content:space-between;">
|
<div style="display:flex;align-items:center;justify-content:space-between;">
|
||||||
<label for="sshportinput" class="forminputlabel">Port</label>
|
<label for="sshportinput" class="forminputlabel">Port</label>
|
||||||
<input type="text" id="sshportinput" class="forminput">
|
<input type="text" id="sshportinput" class="forminput">
|
||||||
|
|||||||
+12
-1
@@ -6,6 +6,15 @@ const exitbutton = document.querySelector('.exitbutton')
|
|||||||
const adminpanelsection = document.querySelector('.adminpanel')
|
const adminpanelsection = document.querySelector('.adminpanel')
|
||||||
const headerusername = document.querySelector('.headerusername')
|
const headerusername = document.querySelector('.headerusername')
|
||||||
|
|
||||||
|
const hashPassword = async (password) => {
|
||||||
|
const encoder = new TextEncoder()
|
||||||
|
const data = encoder.encode(password)
|
||||||
|
const hashBuffer = await crypto.subtle.digest('SHA-256', data)
|
||||||
|
const hashArray = Array.from(new Uint8Array(hashBuffer))
|
||||||
|
const hashHex = hashArray.map(b=>('00' + b.toString(16)).slice(-2)).join('')
|
||||||
|
return hashHex
|
||||||
|
}
|
||||||
|
|
||||||
if (localStorage.getItem("token") === null) {
|
if (localStorage.getItem("token") === null) {
|
||||||
adminpanelsection.classList.remove('active')
|
adminpanelsection.classList.remove('active')
|
||||||
loginform.classList.add('active')
|
loginform.classList.add('active')
|
||||||
@@ -17,7 +26,9 @@ if (localStorage.getItem("token") === null) {
|
|||||||
|
|
||||||
loginformbody.addEventListener('submit', (e) => {
|
loginformbody.addEventListener('submit', (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
login(loginusername.value, loginpassword.value)
|
hashPassword(loginpassword.value).then(hashedpassword => {
|
||||||
|
login(loginusername.value, hashedpassword)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const login = async (username, password) => {
|
const login = async (username, password) => {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ const host = window.location.origin
|
|||||||
const prefix = 'api'
|
const prefix = 'api'
|
||||||
|
|
||||||
const routes = {
|
const routes = {
|
||||||
login: () => [host, prefix, 'token'].join('/'),
|
login: () => ["http://localhost:43243", prefix, 'token'].join('/'),
|
||||||
user: () => [host, prefix, 'users', 'user'].join('/'),
|
user: () => ["http://localhost:43243", prefix, 'users', 'user'].join('/'),
|
||||||
|
|
||||||
telnet_status: () => [host, prefix, 'settings', 'telnet', 'get'].join('/'),
|
telnet_status: () => [host, prefix, 'settings', 'telnet', 'get'].join('/'),
|
||||||
telnet_status_set: () => [host, prefix, 'settings', 'telnet', 'set'].join('/'),
|
telnet_status_set: () => [host, prefix, 'settings', 'telnet', 'set'].join('/'),
|
||||||
@@ -16,6 +16,7 @@ const routes = {
|
|||||||
ssh_keys_set: () => [host, prefix, 'settings', 'ssh', 'keys', 'set'].join('/'),
|
ssh_keys_set: () => [host, prefix, 'settings', 'ssh', 'keys', 'set'].join('/'),
|
||||||
ssh_port_get: () => [host, prefix, 'settings', 'ssh', 'port', 'get'].join('/'),
|
ssh_port_get: () => [host, prefix, 'settings', 'ssh', 'port', 'get'].join('/'),
|
||||||
ssh_port_set: () => [host, prefix, 'settings', 'ssh', 'port', 'set'].join('/'),
|
ssh_port_set: () => [host, prefix, 'settings', 'ssh', 'port', 'set'].join('/'),
|
||||||
|
ssh_server_get: () => [host, prefix, 'settings', 'ssh', 'server', 'get'].join('/'),
|
||||||
|
|
||||||
dns_status: () => [host, prefix, 'settings', 'dns', 'get'].join('/'),
|
dns_status: () => [host, prefix, 'settings', 'dns', 'get'].join('/'),
|
||||||
dns_status_set: () => [host, prefix, 'settings', 'dns', 'set'].join('/'),
|
dns_status_set: () => [host, prefix, 'settings', 'dns', 'set'].join('/'),
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const get_all_settings = () => {
|
|||||||
get_ssh_status()
|
get_ssh_status()
|
||||||
get_ssh_keys()
|
get_ssh_keys()
|
||||||
get_ssh_port()
|
get_ssh_port()
|
||||||
|
get_ssh_server()
|
||||||
|
|
||||||
get_wifi_status()
|
get_wifi_status()
|
||||||
get_wifi_name()
|
get_wifi_name()
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const sshsettingsbody = document.querySelector('#sshsettingsbody')
|
|||||||
const sshkeystablebody = document.querySelector('#sshkeystablebody')
|
const sshkeystablebody = document.querySelector('#sshkeystablebody')
|
||||||
const sshportinput = document.querySelector('#sshportinput')
|
const sshportinput = document.querySelector('#sshportinput')
|
||||||
const add_ssh_key_button = document.querySelector('#add_ssh_key')
|
const add_ssh_key_button = document.querySelector('#add_ssh_key')
|
||||||
|
const sshserverinput = document.querySelector('#sshserverinput')
|
||||||
|
|
||||||
let sshkeys = []
|
let sshkeys = []
|
||||||
|
|
||||||
@@ -140,3 +141,20 @@ const set_ssh_port = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
// ------------------- end SSH port -------------------
|
// ------------------- end SSH port -------------------
|
||||||
|
|
||||||
|
|
||||||
|
const get_ssh_server = () => {
|
||||||
|
fetch(routes.ssh_server_get(), {
|
||||||
|
method: 'POST',
|
||||||
|
body: `{"token":"${localStorage.getItem("token")}"}`
|
||||||
|
}).then(data => data.json()).then(jsondata => {
|
||||||
|
for (let i = 0; i < sshserverinput.options.length; i++) {
|
||||||
|
if (sshserverinput.options[i].value === jsondata.server) {
|
||||||
|
sshserverinput.selectedIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).catch((error) => {
|
||||||
|
notification(`Ошибка на сервере: ${error}`, "error")
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in new issue
Block a user