added wifi password ssid status get
This commit is contained in:
1 parent
eb97beecac
commit
d5cbaa8d38
15 files changed
+268
-13
No files matched your search
Vendored
+2
-1
@@ -74,6 +74,7 @@
|
|||||||
"cinttypes": "cpp",
|
"cinttypes": "cpp",
|
||||||
"typeinfo": "cpp",
|
"typeinfo": "cpp",
|
||||||
"valarray": "cpp",
|
"valarray": "cpp",
|
||||||
"variant": "cpp"
|
"variant": "cpp",
|
||||||
|
"stdfloat": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,10 @@ add_executable(
|
|||||||
src/settings/dns/servers.cpp
|
src/settings/dns/servers.cpp
|
||||||
src/settings/dns/local_domains.cpp
|
src/settings/dns/local_domains.cpp
|
||||||
|
|
||||||
|
src/settings/wifi/status.cpp
|
||||||
|
src/settings/wifi/name.cpp
|
||||||
|
src/settings/wifi/password.cpp
|
||||||
|
|
||||||
src/settings/ftp/ftp.cpp
|
src/settings/ftp/ftp.cpp
|
||||||
|
|
||||||
src/reboot/reboot.cpp
|
src/reboot/reboot.cpp
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "settings/ssh/ssh.hpp"
|
#include "settings/ssh/ssh.hpp"
|
||||||
#include "settings/dns/dns.hpp"
|
#include "settings/dns/dns.hpp"
|
||||||
#include "settings/ftp/ftp.hpp"
|
#include "settings/ftp/ftp.hpp"
|
||||||
|
#include "settings/wifi/wifi.hpp"
|
||||||
#include "reboot/reboot.hpp"
|
#include "reboot/reboot.hpp"
|
||||||
#include "syslog/syslog.hpp"
|
#include "syslog/syslog.hpp"
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
@@ -37,6 +38,10 @@ int main() {
|
|||||||
srv.Post("/api/settings/ftp/get", get_ftp);
|
srv.Post("/api/settings/ftp/get", get_ftp);
|
||||||
srv.Post("/api/settings/ftp/set", set_ftp);
|
srv.Post("/api/settings/ftp/set", set_ftp);
|
||||||
|
|
||||||
|
srv.Post("/api/settings/wifi/status/get", get_wifi_status);
|
||||||
|
srv.Post("/api/settings/wifi/name/get", get_wifi_name);
|
||||||
|
srv.Post("/api/settings/wifi/password/get", get_wifi_password);
|
||||||
|
|
||||||
srv.Post("/api/reboot", reboot);
|
srv.Post("/api/reboot", reboot);
|
||||||
|
|
||||||
srv.Get("/api/syslog", get_syslog);
|
srv.Get("/api/syslog", get_syslog);
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
#include "wifi.hpp"
|
||||||
|
#include <colors.h>
|
||||||
|
#include "../../types.hpp"
|
||||||
|
#include "../../routes.hpp"
|
||||||
|
#include <json.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
|
#define WIFI_SETTINGS_PATH "/etc/hostapd/hostapd.conf"
|
||||||
|
|
||||||
|
void get_wifi_name(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 wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||||
|
std::string wifi_name;
|
||||||
|
std::string wifisettingsbuffer;
|
||||||
|
while (std::getline(wifisettingsfile, wifisettingsbuffer)) {
|
||||||
|
if (wifisettingsbuffer.find("ssid=") == 0) {
|
||||||
|
wifi_name = wifisettingsbuffer;
|
||||||
|
wifi_name.erase(0, 5);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wifisettingsfile.close();
|
||||||
|
std::stringstream responsedata;
|
||||||
|
responsedata << R"({"name":")" << wifi_name << R"("})";
|
||||||
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
#include "wifi.hpp"
|
||||||
|
#include <colors.h>
|
||||||
|
#include "../../types.hpp"
|
||||||
|
#include "../../routes.hpp"
|
||||||
|
#include <json.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
|
#define WIFI_SETTINGS_PATH "/etc/hostapd/hostapd.conf"
|
||||||
|
|
||||||
|
void get_wifi_password(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 wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||||
|
std::string wifi_password;
|
||||||
|
std::string wifisettingsbuffer;
|
||||||
|
while (std::getline(wifisettingsfile, wifisettingsbuffer)) {
|
||||||
|
if (wifisettingsbuffer.find("wpa_passphrase=") == 0) {
|
||||||
|
wifi_password = wifisettingsbuffer;
|
||||||
|
wifi_password.erase(0, 15);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wifisettingsfile.close();
|
||||||
|
std::stringstream responsedata;
|
||||||
|
responsedata << R"({"password":")" << wifi_password << R"("})";
|
||||||
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#include "wifi.hpp"
|
||||||
|
#include <colors.h>
|
||||||
|
#include <json.hpp>
|
||||||
|
#include "../../routes.hpp"
|
||||||
|
#include "../../types.hpp"
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
|
void get_wifi_status(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 wifistatusfile("/etc/openrouter/wifi/status");
|
||||||
|
int wifi_status;
|
||||||
|
wifistatusfile >> wifi_status;
|
||||||
|
wifistatusfile.close();
|
||||||
|
std::stringstream responsedata;
|
||||||
|
responsedata << R"({"status":")" << wifi_status << R"("})";
|
||||||
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef WIFI_HPP
|
||||||
|
#define WIFI_HPP
|
||||||
|
|
||||||
|
#include <httplib.h>
|
||||||
|
|
||||||
|
void get_wifi_status(const httplib::Request &request, httplib::Response &response);
|
||||||
|
|
||||||
|
void get_wifi_name(const httplib::Request &request, httplib::Response &response);
|
||||||
|
|
||||||
|
void get_wifi_password(const httplib::Request &request, httplib::Response &response);
|
||||||
|
|
||||||
|
#endif // WIFI_HPP
|
||||||
@@ -112,6 +112,9 @@
|
|||||||
max-height: 0;
|
max-height: 0;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
transition: 0.3s;
|
transition: 0.3s;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.settingrectbody.active {
|
.settingrectbody.active {
|
||||||
|
|||||||
@@ -32,9 +32,9 @@
|
|||||||
<!-- header -->
|
<!-- header -->
|
||||||
<!-- settings block -->
|
<!-- settings block -->
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<section class="settingssection grid" data-masonry='{ "itemSelector": ".grid-item", "columnWidth": 24% }'>
|
<section class="settingssection">
|
||||||
<!-- telnet settings -->
|
<!-- telnet settings -->
|
||||||
<div class="settingrect grid-item">
|
<div class="settingrect ">
|
||||||
<div class="settingrectheader">
|
<div class="settingrectheader">
|
||||||
<h2>Telnet</h2>
|
<h2>Telnet</h2>
|
||||||
<div class="checkbox-wrapper-2">
|
<div class="checkbox-wrapper-2">
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- telnet settings -->
|
<!-- telnet settings -->
|
||||||
<!-- DNS settings -->
|
<!-- DNS settings -->
|
||||||
<div class="settingrect grid-item">
|
<div class="settingrect ">
|
||||||
<div class="settingrectheader">
|
<div class="settingrectheader">
|
||||||
<h2>DNS</h2>
|
<h2>DNS</h2>
|
||||||
<div class="checkbox-wrapper-2">
|
<div class="checkbox-wrapper-2">
|
||||||
@@ -90,7 +90,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- DNS settings -->
|
<!-- DNS settings -->
|
||||||
<!-- ftp settings -->
|
<!-- ftp settings -->
|
||||||
<div class="settingrect grid-item">
|
<div class="settingrect ">
|
||||||
<div class="settingrectheader">
|
<div class="settingrectheader">
|
||||||
<h2>Ftp</h2>
|
<h2>Ftp</h2>
|
||||||
<div class="checkbox-wrapper-2">
|
<div class="checkbox-wrapper-2">
|
||||||
@@ -104,7 +104,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- ftp settings -->
|
<!-- ftp settings -->
|
||||||
<!-- ssh settings -->
|
<!-- ssh settings -->
|
||||||
<div class="settingrect grid-item">
|
<div class="settingrect ">
|
||||||
<div class="settingrectheader">
|
<div class="settingrectheader">
|
||||||
<h2>SSH</h2>
|
<h2>SSH</h2>
|
||||||
<div class="checkbox-wrapper-2">
|
<div class="checkbox-wrapper-2">
|
||||||
@@ -131,11 +131,21 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- ssh settings -->
|
<!-- ssh settings -->
|
||||||
<!-- wifi settings -->
|
<!-- wifi settings -->
|
||||||
<div class="settingrect grid-item">
|
<div class="settingrect ">
|
||||||
<div class="settingrectheader">
|
<div class="settingrectheader">
|
||||||
<h2>WIFI</h2>
|
<h2>WIFI</h2>
|
||||||
<div class="checkbox-wrapper-2">
|
<div class="checkbox-wrapper-2">
|
||||||
<input type="checkbox" class="sc-gJwTLC ikxBAC" id="sshenable">
|
<input type="checkbox" class="sc-gJwTLC ikxBAC" id="wifistatus">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="settingrectbody" id="wifisettingsbody">
|
||||||
|
<div style="display:flex;align-items:center;justify-content:space-between;">
|
||||||
|
<label for="SSID" class="forminputlabel">SSID</label>
|
||||||
|
<input type="text" id="SSID" class="forminput">
|
||||||
|
</div>
|
||||||
|
<div style="display:flex;align-items:center;justify-content:space-between;">
|
||||||
|
<label for="wifipassword" class="forminputlabel">Password</label>
|
||||||
|
<input type="text" id="wifipassword" class="forminput">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="settingrectfooter onebutton">
|
<div class="settingrectfooter onebutton">
|
||||||
@@ -244,6 +254,7 @@
|
|||||||
<script src="js/settings/dns.js"></script>
|
<script src="js/settings/dns.js"></script>
|
||||||
<script src="js/settings/ftp.js"></script>
|
<script src="js/settings/ftp.js"></script>
|
||||||
<script src="js/settings/ssh.js"></script>
|
<script src="js/settings/ssh.js"></script>
|
||||||
|
<script src="js/settings/wifi.js"></script>
|
||||||
<script src="js/settings/settings.js"></script>
|
<script src="js/settings/settings.js"></script>
|
||||||
|
|
||||||
<script src="js/reboot.js"></script>
|
<script src="js/reboot.js"></script>
|
||||||
|
|||||||
@@ -27,6 +27,13 @@ const routes = {
|
|||||||
ftp_status: () => [host, prefix, 'settings', 'ftp', 'get'].join('/'),
|
ftp_status: () => [host, prefix, 'settings', 'ftp', 'get'].join('/'),
|
||||||
ftp_status_set: () => [host, prefix, 'settings', 'ftp', 'set'].join('/'),
|
ftp_status_set: () => [host, prefix, 'settings', 'ftp', 'set'].join('/'),
|
||||||
|
|
||||||
|
wifi_status_get: () => [host, prefix, 'settings', 'wifi', 'status', 'get'].join('/'),
|
||||||
|
wifi_status_set: () => [host, prefix, 'settings', 'wifi', 'status', 'set'].join('/'),
|
||||||
|
wifi_name_get: () => [host, prefix, 'settings', 'wifi', 'name', 'get'].join('/'),
|
||||||
|
wifi_name_set: () => [host, prefix, 'settings', 'wifi', 'name', 'set'].join('/'),
|
||||||
|
wifi_password_get: () => [host, prefix, 'settings', 'wifi', 'password', 'get'].join('/'),
|
||||||
|
wifi_password_set: () => [host, prefix, 'settings', 'wifi', 'password', 'set'].join('/'),
|
||||||
|
|
||||||
reboot: () => [host, prefix, 'reboot'].join('/'),
|
reboot: () => [host, prefix, 'reboot'].join('/'),
|
||||||
syslog: () => [host, prefix, 'syslog'].join('/'),
|
syslog: () => [host, prefix, 'syslog'].join('/'),
|
||||||
// all_users: () => [host, prefix, 'users', 'all'].join('/'),
|
// all_users: () => [host, prefix, 'users', 'all'].join('/'),
|
||||||
|
|||||||
@@ -11,4 +11,8 @@ const get_all_settings = () => {
|
|||||||
get_ssh_status()
|
get_ssh_status()
|
||||||
get_ssh_keys()
|
get_ssh_keys()
|
||||||
get_ssh_port()
|
get_ssh_port()
|
||||||
|
|
||||||
|
get_wifi_status()
|
||||||
|
get_wifi_name()
|
||||||
|
get_wifi_password()
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
const wifistatus = document.querySelector('#wifistatus')
|
||||||
|
const wifisettingsbody = document.querySelector('#wifisettingsbody')
|
||||||
|
const wifissid = document.querySelector('#SSID')
|
||||||
|
const wifipassword = document.querySelector('#wifipassword')
|
||||||
|
|
||||||
|
const get_wifi_status = () => {
|
||||||
|
fetch(routes.wifi_status_get(), {
|
||||||
|
method: 'POST',
|
||||||
|
body: `{"token":"${localStorage.getItem('token')}"}`
|
||||||
|
}).then(data => data.json()).then(jsondata => {
|
||||||
|
console.log(jsondata)
|
||||||
|
if (jsondata.status == "1") {
|
||||||
|
wifistatus.checked = true
|
||||||
|
wifisettingsbody.classList.add('active')
|
||||||
|
} else {
|
||||||
|
wifistatus.checked = false
|
||||||
|
}
|
||||||
|
}).catch((error) => {
|
||||||
|
notification(`Ошибка на сервере: ${error}`, "error")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const get_wifi_name = () => {
|
||||||
|
fetch(routes.wifi_name_get(), {
|
||||||
|
method: 'POST',
|
||||||
|
body: `{"token":"${localStorage.getItem('token')}"}`
|
||||||
|
}).then(data => data.json()).then(jsondata => {
|
||||||
|
console.log(jsondata)
|
||||||
|
wifissid.value = jsondata.name
|
||||||
|
}).catch((error) => {
|
||||||
|
notification(`Ошибка на сервере: ${error}`, "error")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const get_wifi_password = () => {
|
||||||
|
fetch(routes.wifi_password_get(), {
|
||||||
|
method: 'POST',
|
||||||
|
body: `{"token":"${localStorage.getItem('token')}"}`
|
||||||
|
}).then(data => data.json()).then(jsondata => {
|
||||||
|
console.log(jsondata)
|
||||||
|
wifipassword.value = jsondata.password
|
||||||
|
}).catch((error) => {
|
||||||
|
notification(`Ошибка на сервере: ${error}`, "error")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
wifistatus.addEventListener('click', () => {
|
||||||
|
if (wifistatus.checked) {
|
||||||
|
wifisettingsbody.classList.add('active')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
wifisettingsbody.classList.remove('active')
|
||||||
|
})
|
||||||
@@ -7,16 +7,18 @@ init () {
|
|||||||
test -f $DAEMON || exit 0
|
test -f $DAEMON || exit 0
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
echo "Starting $DESC..."
|
notify $NOTIFY_START
|
||||||
if [ $LOG ] ; then
|
if [ $LOG ] ; then
|
||||||
$DAEMON $PARAMS 2>>/var/log/$LOG &
|
$start_command $start_params 2>>/var/log/$LOG &
|
||||||
|
check $?
|
||||||
else
|
else
|
||||||
$DAEMON $PARAMS &>/dev/null &
|
$start_command $start_params &>/dev/null &
|
||||||
|
check $?
|
||||||
fi
|
fi
|
||||||
echo $! > $PIDFILE
|
echo $! > $PIDFILE
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
printf "\nStopping $DESC..."
|
notify $NOTIFY_STOP
|
||||||
if [ $STOP ] ; then
|
if [ $STOP ] ; then
|
||||||
$STOP $PARAMS
|
$STOP $PARAMS
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ Red='\033[0;31m'
|
|||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
notify "Starting telnet "
|
notify "Starting telnet "
|
||||||
telnetd -p $(cat /etc/openrouter/telnet/port)
|
telnetd -S -p $(cat /etc/openrouter/telnet/port)
|
||||||
check $?
|
check $?
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
0
|
||||||
Reference in new issue
Block a user