Troubleshooting page

This commit is contained in:
Elia Zammuto 2021-08-17 20:22:47 +02:00
parent 81317ce672
commit 1f239214a1
5 changed files with 146 additions and 0 deletions

View File

@ -54,6 +54,9 @@
<li class="nav-item">
<a class="nav-link" href="/password">Change Password</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/troubleshooting">Troubleshooting</a>
</li>
</ul>
</div>
</div>

View File

@ -0,0 +1,74 @@
<div id="app" class="container">
<h1 class="my-4">Troubleshooting</h1>
<!--Force Close App-->
<div class="card p-2 my-4">
<div>
<h2>Force Close</h2>
<br />
<p>
If Moonlight complains about an app currently running, force closing the
app should fix the issue
</p>
</div>
<div>
<button
class="btn btn-warning"
:disabled="closeAppPressed"
@click="closeApp"
>
Force Close
</button>
</div>
</div>
<!--Unpair all Clients-->
<div class="card p-2 my-4">
<div>
<h2>Unpair All Clients</h2>
<br />
<p>Remove all your paired devices</p>
</div>
<div>
<button
class="btn btn-danger"
:disabled="unpairAllPressed"
@click="unpairAll"
>
Unpair All
</button>
</div>
</div>
</div>
<script>
new Vue({
el: "#app",
data() {
return {
closeAppPressed: false,
closeAppStatus: null,
unpairAllPressed: false,
unpairAllStatus: null,
};
},
methods: {
closeApp() {
this.closeAppPressed = true;
fetch("/api/apps/close", { method: "POST" })
.then((r) => r.json())
.then((r) => {
this.closeAppPressed = false;
this.closeAppStatus = r.status.toString() === "true";
});
},
unpairAll() {
this.unpairAllPressed = true;
fetch("/api/clients/unpair", { method: "POST" })
.then((r) => r.json())
.then((r) => {
this.unpairAllPressed = false;
this.unpairAllStatus = r.status.toString() === "true";
});
},
},
});
</script>

View File

@ -211,6 +211,16 @@ void getWelcomePage(resp_https_t response, req_https_t request) {
response->write(header + content);
}
void getTroubleshootingPage(resp_https_t response, req_https_t request) {
if(!authenticate(response, request)) return;
print_req(request);
std::string header = read_file(WEB_DIR "header.html");
std::string content = read_file(WEB_DIR "troubleshooting.html");
response->write(header + content);
}
void getApps(resp_https_t response, req_https_t request) {
if(!authenticate(response, request)) return;
@ -481,6 +491,56 @@ void savePin(resp_https_t response, req_https_t request) {
}
}
void unpairAll(resp_https_t response, req_https_t request){
if(!authenticate(response, request)) return;
print_req(request);
pt::ptree outputTree;
auto g = util::fail_guard([&]() {
std::ostringstream data;
pt::write_json(data, outputTree);
response->write(data.str());
});
try {
nvhttp::erase_all_clients();
outputTree.put("status", true);
}
catch(std::exception &e) {
BOOST_LOG(warning) << "unpairAll: "sv << e.what();
outputTree.put("status", false);
outputTree.put("error", e.what());
return;
}
}
void closeApp(resp_https_t response, req_https_t request){
if(!authenticate(response, request)) return;
print_req(request);
pt::ptree outputTree;
auto g = util::fail_guard([&]() {
std::ostringstream data;
pt::write_json(data, outputTree);
response->write(data.str());
});
try {
proc::proc.terminate();
outputTree.put("status", true);
}
catch(std::exception &e) {
BOOST_LOG(warning) << "CloseApp: "sv << e.what();
outputTree.put("status", false);
outputTree.put("error", e.what());
return;
}
}
void start() {
auto shutdown_event = mail::man->event<bool>(mail::shutdown);
@ -498,6 +558,7 @@ void start() {
server.resource["^/config$"]["GET"] = getConfigPage;
server.resource["^/password$"]["GET"] = getPasswordPage;
server.resource["^/welcome$"]["GET"] = getWelcomePage;
server.resource["^/troubleshooting$"]["GET"] = getTroubleshootingPage;
server.resource["^/api/pin"]["POST"] = savePin;
server.resource["^/api/apps$"]["GET"] = getApps;
server.resource["^/api/apps$"]["POST"] = saveApp;
@ -505,6 +566,8 @@ void start() {
server.resource["^/api/config$"]["POST"] = saveConfig;
server.resource["^/api/password$"]["POST"] = savePassword;
server.resource["^/api/apps/([0-9]+)$"]["DELETE"] = deleteApp;
server.resource["^/api/clients/unpair$"]["POST"] = unpairAll;
server.resource["^/api/apps/close"]["POST"] = closeApp;
server.config.reuse_address = true;
server.config.address = "0.0.0.0"s;
server.config.port = port_https;

View File

@ -927,4 +927,9 @@ void start() {
ssl.join();
tcp.join();
}
void erase_all_clients(){
map_id_client.clear();
save_state();
}
} // namespace nvhttp

View File

@ -14,6 +14,7 @@ constexpr auto PORT_HTTPS = -5;
void start();
bool pin(std::string pin);
void erase_all_clients();
} // namespace nvhttp
#endif //SUNSHINE_NVHTTP_H