mirror of
https://github.com/LizardByte/Sunshine.git
synced 2025-08-10 00:52:16 +00:00
Show a Welcome Page if credentials are created the first time Sunshine is started
This commit is contained in:
@@ -87,7 +87,8 @@ sunshine needs access to uinput to create mouse and gamepad events:
|
||||
- When Moonlight request you insert the correct pin on sunshine:
|
||||
- Type in the URL bar of your browser: `https://xxx.xxx.xxx.xxx:47990` where `xxx.xxx.xxx.xxx` is the IP address of your computer
|
||||
- Ignore any warning given by your browser about "insecure website"
|
||||
- Type in the username and password shown the first time you run Sunshine
|
||||
- You should see a page containing both a new username and a password, needed to login into the next step
|
||||
- Press "login" and log in using the credentials given above
|
||||
- Go to "PIN" in the Header
|
||||
- Type in your PIN and press Enter, you should get a Success Message
|
||||
- Click on one of the Applications listed
|
||||
|
||||
17
assets/web/header-no-nav.html
Normal file
17
assets/web/header-no-nav.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Sunshine</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||
integrity="sha384-wEmeIV1mKuiNpC+IOBjI7aAzPcEZeedi5yW5f2yOq55WWLwNGmvvx4Um1vskeMj0" crossorigin="anonymous">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js"
|
||||
integrity="sha384-p34f1UUtsS3wqzfto5wAAmdvj+osOnFyQFpp4Ua3gs/ZVWx6oOypYoCJhGGScy+8" crossorigin="anonymous">
|
||||
</script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
30
assets/web/welcome.html
Normal file
30
assets/web/welcome.html
Normal file
@@ -0,0 +1,30 @@
|
||||
<main role="main" id="app" style="max-width: 600px;margin: 0 auto;">
|
||||
<div class="container-parent">
|
||||
<div class="container py-3">
|
||||
<h1 class="mb-0">Welcome to Sunshine!</h1>
|
||||
<p class="mb-0 align-self-start">Before Getting Started, write down below these credentials</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="alert alert-warning">These Credentials down below are needed to access the rest of the application.<br> Keep them safe, since <b>you will never see them again!</b></div>
|
||||
<div class="card p-4" style="width: 100%;">
|
||||
<div class="mb-2">
|
||||
<label for="" class="form-label">Username: </label>
|
||||
<input type="text" class="form-control" disabled id="username">
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<label for="" class="form-label">Password: </label>
|
||||
<input type="text" class="form-control" disabled id="password">
|
||||
</div>
|
||||
<a href="/" class="mb-2 btn btn-primary" style="margin: 1em auto;">Login</a>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
fetch("/api/setup/password").then(r => r.json()).then(r => {
|
||||
if(r.status === "true"){
|
||||
document.querySelector("#username").value = r.username;
|
||||
document.querySelector("#password").value = r.password;
|
||||
}
|
||||
})
|
||||
</script>
|
||||
@@ -230,6 +230,8 @@ sunshine_t sunshine {
|
||||
SUNSHINE_CONFIG_DIR "/sunshine.conf", // config file
|
||||
{}, // cmd args
|
||||
47989,
|
||||
false, // show credentials,
|
||||
""
|
||||
};
|
||||
|
||||
bool endline(char ch) {
|
||||
|
||||
@@ -109,6 +109,9 @@ struct sunshine_t {
|
||||
} cmd;
|
||||
|
||||
std::uint16_t port;
|
||||
|
||||
bool showCredentials;
|
||||
std::string plainPassword;
|
||||
};
|
||||
|
||||
extern video_t video;
|
||||
|
||||
@@ -73,6 +73,15 @@ void send_unauthorized(resp_https_t response, req_https_t request) {
|
||||
response->write(SimpleWeb::StatusCode::client_error_unauthorized, headers);
|
||||
}
|
||||
|
||||
void send_redirect(resp_https_t response, req_https_t request, const char *path) {
|
||||
auto address = request->remote_endpoint_address();
|
||||
BOOST_LOG(info) << "Web UI: ["sv << address << "] -- not authorized"sv;
|
||||
const SimpleWeb::CaseInsensitiveMultimap headers {
|
||||
{ "Location", path }
|
||||
};
|
||||
response->write(SimpleWeb::StatusCode::redirection_temporary_redirect, headers);
|
||||
}
|
||||
|
||||
bool authenticate(resp_https_t response, req_https_t request) {
|
||||
auto address = request->remote_endpoint_address();
|
||||
auto ip_type = net::from_address(address);
|
||||
@@ -87,6 +96,13 @@ bool authenticate(resp_https_t response, req_https_t request) {
|
||||
send_unauthorized(response, request);
|
||||
});
|
||||
|
||||
//If credentials are shown, redirect the user to a /welcome page
|
||||
if(config::sunshine.showCredentials){
|
||||
send_redirect(response,request,"/welcome");
|
||||
fg.disable();
|
||||
return false;
|
||||
}
|
||||
|
||||
auto auth = request->header.find("authorization");
|
||||
if(auth == request->header.end()) {
|
||||
return false;
|
||||
@@ -185,6 +201,17 @@ void getPasswordPage(resp_https_t response, req_https_t request) {
|
||||
response->write(header + content);
|
||||
}
|
||||
|
||||
void getWelcomePage(resp_https_t response, req_https_t request) {
|
||||
print_req(request);
|
||||
if(!config::sunshine.showCredentials){
|
||||
send_redirect(response,request,"/");
|
||||
return;
|
||||
}
|
||||
std::string header = read_file(WEB_DIR "header-no-nav.html");
|
||||
std::string content = read_file(WEB_DIR "welcome.html");
|
||||
response->write(header + content);
|
||||
}
|
||||
|
||||
void getApps(resp_https_t response, req_https_t request) {
|
||||
if(!authenticate(response, request)) return;
|
||||
|
||||
@@ -335,6 +362,29 @@ void getConfig(resp_https_t response, req_https_t request) {
|
||||
}
|
||||
}
|
||||
|
||||
void getPlainPassword(resp_https_t response, req_https_t request) {
|
||||
|
||||
print_req(request);
|
||||
|
||||
pt::ptree outputTree;
|
||||
auto g = util::fail_guard([&]() {
|
||||
std::ostringstream data;
|
||||
|
||||
pt::write_json(data, outputTree);
|
||||
response->write(data.str());
|
||||
});
|
||||
|
||||
if(config::sunshine.showCredentials){
|
||||
outputTree.put("status", "true");
|
||||
outputTree.put("username", config::sunshine.username);
|
||||
outputTree.put("password", config::sunshine.plainPassword);
|
||||
config::sunshine.showCredentials = false;
|
||||
config::sunshine.plainPassword = "";
|
||||
} else {
|
||||
outputTree.put("status", "false");
|
||||
}
|
||||
}
|
||||
|
||||
void saveConfig(resp_https_t response, req_https_t request) {
|
||||
if(!authenticate(response, request)) return;
|
||||
|
||||
@@ -467,6 +517,7 @@ void start() {
|
||||
server.resource["^/clients$"]["GET"] = getClientsPage;
|
||||
server.resource["^/config$"]["GET"] = getConfigPage;
|
||||
server.resource["^/password$"]["GET"] = getPasswordPage;
|
||||
server.resource["^/welcome$"]["GET"] = getWelcomePage;
|
||||
server.resource["^/api/pin"]["POST"] = savePin;
|
||||
server.resource["^/api/apps$"]["GET"] = getApps;
|
||||
server.resource["^/api/apps$"]["POST"] = saveApp;
|
||||
@@ -474,6 +525,7 @@ 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/setup/password$"]["GET"] = getPlainPassword;
|
||||
server.config.reuse_address = true;
|
||||
server.config.address = "0.0.0.0"s;
|
||||
server.config.port = port_https;
|
||||
|
||||
@@ -94,8 +94,12 @@ int save_user_creds(const std::string &file, const std::string &username, const
|
||||
BOOST_LOG(info) << "New credentials have been created"sv;
|
||||
|
||||
if(run_our_mouth) {
|
||||
BOOST_LOG(info) << "Username: "sv << username;
|
||||
BOOST_LOG(info) << "Password: "sv << password;
|
||||
//BOOST_LOG(info) << "Username: "sv << username;
|
||||
//BOOST_LOG(info) << "Password: "sv << password;
|
||||
BOOST_LOG(info) << "Open the Web UI to see your new username and password";
|
||||
//Save these two in memory to show user and password the first time Sunshine is started
|
||||
config::sunshine.showCredentials = true;
|
||||
config::sunshine.plainPassword = password;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user