Merge pull request #185 from TheElixZammuto/web-ui-troubleshooting

Web UI - Troubleshooting Page
This commit is contained in:
loki-47-6F-64
2021-09-01 21:48:34 +02:00
committed by GitHub
5 changed files with 147 additions and 0 deletions

View File

@@ -45,6 +45,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,92 @@
<div id="app" class="container">
<h1 class="my-4">Troubleshooting</h1>
<!--Force Close App-->
<div class="card p-2 my-4">
<div class="card-body">
<h2>Force Close</h2>
<br />
<p>
If Moonlight complains about an app currently running, force closing the
app should fix the issue
</p>
<div class="alert alert-success" v-if="closeAppStatus === true">
Application Closed Successfuly!
</div>
<div class="alert alert-danger" v-if="closeAppStatus === false">
Error while closing Appplication
</div>
<div>
<button
class="btn btn-warning"
:disabled="closeAppPressed"
@click="closeApp"
>
Force Close
</button>
</div>
</div>
</div>
<!--Unpair all Clients-->
<div class="card p-2 my-4">
<div class="card-body">
<h2>Unpair All Clients</h2>
<br />
<p>Remove all your paired devices</p>
<div class="alert alert-success" v-if="unpairAllStatus === true">
Unpair Successful!
</div>
<div class="alert alert-danger" v-if="unpairAllStatus === false">
Error while unpairing
</div>
<div>
<button
class="btn btn-danger"
:disabled="unpairAllPressed"
@click="unpairAll"
>
Unpair All
</button>
</div>
</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";
setTimeout(() => {
this.closeAppStatus = null;
}, 5000);
});
},
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";
setTimeout(() => {
this.unpairAllStatus = null;
}, 5000);
});
},
},
});
</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 getBootstrapCss(resp_https_t response, req_https_t request) {
print_req(request);
@@ -502,6 +512,39 @@ 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());
});
nvhttp::erase_all_clients();
outputTree.put("status", true);
}
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());
});
proc::proc.terminate();
outputTree.put("status", true);
}
void start() {
auto shutdown_event = mail::man->event<bool>(mail::shutdown);
@@ -519,6 +562,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;
@@ -526,6 +570,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.resource["^/third_party/bootstrap.min.css$"]["GET"] = getBootstrapCss;
server.resource["^/third_party/bootstrap.bundle.min.js$"]["GET"] = getBootstrapJs;
server.resource["^/third_party/vue.js$"]["GET"] = getVueJs;

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