tightening up naming conventions and template content - beefing up home page

master
lalanza808 4 years ago
parent c91c37538e
commit 1b57a64fc2

@ -36,7 +36,7 @@ From there set environment variables:
```
export WGAS_ENDPOINT=127.0.0.1
export WGAS_SUDO=false
export WGAS_SUDO=false # set to true if deploying on live VPN instance
export WGAS_DNS=1.1.1.1 # set to dns you control if possible
export WGAS_ROUTE=0.0.0.0/0
export WGAS_PORT=51820
@ -47,5 +47,5 @@ and use `cargo` to run the dev server or build production release binaries:
```
cargo run
cargo build --release # outputs to ./target/release/<package_nae>
cargo build --release # outputs to ./target/release/<package_name>
```

@ -11,3 +11,15 @@ pub fn wg_cmd(arg: String) -> String {
output_str
}
pub fn sh_cmd(cmd: String) -> String {
let output = Command::new("sh")
.arg("-c")
.arg(cmd)
.output()
.expect("failed to execute process");
let output_str = String::from_utf8(output.stdout)
.unwrap();
output_str
}

@ -21,7 +21,7 @@ fn main() {
println!("{:#?}", wg_opts);
rocket::ignite()
.mount("/", routes![
routes::index, routes::generate
routes::home, routes::add_peer
])
.mount("/static", StaticFiles::from("./static"))
.register(catchers![not_found])

@ -4,23 +4,36 @@ mod data;
mod helpers;
use data::WireGuardOptions;
use helpers::wg_cmd;
use helpers::{wg_cmd, sh_cmd};
use rocket_contrib::templates::Template;
use rocket_contrib::json::JsonValue;
use qrcode_generator::QrCodeEcc;
#[get("/")]
pub fn index() -> Template {
let current_config = wg_cmd("show".to_string());
pub fn home() -> Template {
let show_config = wg_cmd("show".to_string());
let whoami = sh_cmd("whoami".to_string());
let uptime = sh_cmd("uptime".to_string());
let hostname = sh_cmd("hostname".to_string());
let netstat_info = sh_cmd("netstat -tan | grep \"ESTABLISHED\\|CLOSE_WAIT\"".to_string());
let shell_ps1 = format!(
"{}@{} $",
whoami.trim_end(),
hostname.trim_end()
);
let context: JsonValue = json!({
"show_config": current_config
"show_config": show_config.trim_end(),
"uptime": uptime.trim_end(),
"netstat_info": netstat_info,
"shell_ps1": shell_ps1,
});
Template::render("index", context)
Template::render("home", context)
}
#[get("/generate")]
pub fn generate() -> Template {
#[get("/add-peer")]
pub fn add_peer() -> Template {
let new_key = wg_cmd("genkey".to_string());
let state = WireGuardOptions { ..Default::default() };
let full_config = format!("[Interface]
@ -48,5 +61,5 @@ PersistentKeepalive = 21",
"qr_code": qr_code,
"full_config": full_config
});
Template::render("generate", context)
Template::render("add_peer", context)
}

@ -4,26 +4,15 @@
<section id="contact" class="">
<div class="container">
<header>
<h2>Add New Peers</h2>
<h2>Add A Peer</h2>
</header>
<p>The following configuration has been generated by the server. Refresh for new keys.</br>The keys and peer info will not be configured on the interface until you confirm with the buttons below.</p>
<div class="code">{{ full_config }}</div>
<img src="data:image/svg+xml;base64,{{ qr_code }}" width=200 class="center">
<hr>
<button type="submit">Configure (wip)</button>
</div>
</section>
{% endblock content %}

@ -29,7 +29,7 @@
<nav id="nav">
<ul>
<li><a href="/" id="top-link"><span class="icon solid fa-home">Home</span></a></li>
<li><a href="/generate" id="about-link"><span class="icon solid fa-user">Add New Peers</span></a></li>
<li><a href="/add-peer" id="about-link"><span class="icon solid fa-user">Add A Peer</span></a></li>
<!-- <li><a href="#portfolio" id="portfolio-link"><span class="icon solid fa-th">wip</span></a></li>
<li><a href="#contact" id="contact-link"><span class="icon solid fa-envelope">wip</span></a></li> -->
</ul>
@ -73,9 +73,7 @@
<!-- Scripts -->
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/jquery.scrolly.min.js"></script>
<script src="/static/js/jquery.scrollex.min.js"></script>
<script src="/static/js/browser.min.js"></script>
<!-- <script src="/static/js/browser.min.js"></script> -->
<script src="/static/js/breakpoints.min.js"></script>
<script src="/static/js/util.js"></script>
<script src="/static/js/main.js"></script>

@ -0,0 +1,24 @@
{% extends "base" %}
{% block content %}
<section id="top" class="">
<div class="container">
<header>
<h2 class="alt">Home</h2>
<p>The current tunnel configuration and stats are shown below.</p>
</header>
<div class="code">
{{ shell_ps1 }} <strong>uptime</strong>
{{ uptime }}
{{ shell_ps1 }} <strong>netstat -tan | grep "ESTABLISHED\|CLOSE_WAIT"</strong>
{{ netstat_info }}
{{ shell_ps1 }} <strong>wg show</strong>
{% if show_config %}{{ show_config }}{% else %}It doesn't look like the tunnel interface is up yet.{% endif %}
</div>
</div>
</section>
{% endblock content %}

@ -1,19 +0,0 @@
{% extends "base" %}
{% block content %}
<section id="top" class="">
<div class="container">
<header>
<h2 class="alt">Welcome</h2>
<p>The current tunnel configuration and stats are shown below.</p>
</header>
<div class="code">{% if show_config %}{{ show_config }}{% else %}It doesn't look like the tunnel interface is up yet.{% endif %}</div>
</div>
</section>
{% endblock content %}
Loading…
Cancel
Save