Add branding .env variables and remove hard coded.

New Variables (including matching commandline parameters):
* PSLINK_EMPTY_FORWARD_URL
* PSLINK_BRAND_NAME
This commit is contained in:
Dietrich 2021-03-11 12:54:09 +01:00
parent 23fa296ceb
commit 6c6d8d4d5b
Signed by: dietrich
GPG Key ID: 9F3C20C0F85DF67C
3 changed files with 48 additions and 15 deletions

View File

@ -14,6 +14,7 @@ use crate::{queries, schema};
use slog::{Drain, Logger};
#[allow(clippy::clippy::too_many_lines)]
fn generate_cli() -> App<'static, 'static> {
app_from_crate!()
.arg(
@ -42,6 +43,24 @@ fn generate_cli() -> App<'static, 'static> {
.default_value("localhost:8080")
.global(true),
)
.arg(
Arg::with_name("empty_forward_url")
.long("empty-url")
.short("e")
.help("The the url that / will redirect to. Usually your homepage.")
.env("PSLINK_EMPTY_FORWARD_URL")
.default_value("https://github.com/enaut/pslink")
.global(true),
)
.arg(
Arg::with_name("brand_name")
.long("brand-name")
.short("b")
.help("The Brandname that will apper in various places.")
.env("PSLINK_BRAND_NAME")
.default_value("Pslink")
.global(true),
)
.arg(
Arg::with_name("internal_ip")
.long("hostip")
@ -148,6 +167,14 @@ fn parse_args_to_config(config: &ArgMatches, log: &Logger) -> ServerConfig {
.value_of("public_url")
.expect("Failed to read the host value")
.to_owned();
let empty_forward_url = config
.value_of("empty_forward_url")
.expect("Failed to read the empty_forward_url value")
.to_owned();
let brand_name = config
.value_of("brand_name")
.expect("Failed to read the brand_name value")
.to_owned();
let internal_ip = config
.value_of("internal_ip")
.expect("Failed to read the host value")
@ -173,6 +200,8 @@ fn parse_args_to_config(config: &ArgMatches, log: &Logger) -> ServerConfig {
port,
protocol,
log,
empty_forward_url,
brand_name,
}
}

View File

@ -163,6 +163,8 @@ pub(crate) struct ServerConfig {
port: u32,
protocol: Protocol,
log: slog::Logger,
empty_forward_url: String,
brand_name: String,
}
impl ServerConfig {
@ -171,6 +173,8 @@ impl ServerConfig {
format!("PSLINK_DATABASE=\"{}\"\n", self.db.display()),
format!("PSLINK_PORT={}\n", self.port),
format!("PSLINK_PUBLIC_URL=\"{}\"\n", self.public_url),
format!("PSLINK_EMPTY_FORWARD_URL=\"{}\"\n", self.empty_forward_url),
format!("PSLINK_BRAND_NAME=\"{}\"\n", self.brand_name),
format!("PSLINK_IP=\"{}\"\n", self.internal_ip),
format!("PSLINK_PROTOCOL=\"{}\"\n", self.protocol),
concat!(
@ -262,8 +266,8 @@ async fn webservice(server_config: ServerConfig) -> std::io::Result<()> {
.service(actix_web_static_files::ResourceFiles::new(
"/static", generated,
))
// directly go to the main page of Freie-Hochschule-Stuttgart
.route("/", web::get().to(views::redirect_fhs))
// directly go to the main page set the target with the environment variable.
.route("/", web::get().to(views::redirect_empty))
// admin block
.service(
web::scope("/admin")
@ -283,7 +287,7 @@ async fn webservice(server_config: ServerConfig) -> std::io::Result<()> {
.service(
web::scope("/link")
.route("/{redirect_id}", web::get().to(views::view_link))
.route("/", web::get().to(views::view_link_fhs)),
.route("/", web::get().to(views::view_link_empty)),
)
.service(
web::scope("/profile")

View File

@ -36,7 +36,7 @@ pub(crate) async fn index(
if let Ok(links) = queries::list_all_allowed(&id, &config) {
let mut data = Context::new();
data.insert("user", &links.user);
data.insert("title", "Links der Freien Hochschule Stuttgart");
data.insert("title", &format!("Links der {}", &config.brand_name,));
data.insert("links_per_users", &links.list);
let rendered = tera.render("index.html", &data)?;
Ok(HttpResponse::Ok().body(rendered))
@ -54,7 +54,7 @@ pub(crate) async fn index_users(
if let Ok(users) = queries::list_users(&id, &config) {
let mut data = Context::new();
data.insert("user", &users.user);
data.insert("title", "Benutzer der Freien Hochschule Stuttgart");
data.insert("title", &format!("Benutzer der {}", &config.brand_name,));
data.insert("users", &users.list);
let rendered = tera.render("index_users.html", &data)?;
@ -63,7 +63,7 @@ pub(crate) async fn index_users(
Ok(redirect_builder("/admin/login"))
}
}
pub(crate) async fn view_link_fhs(
pub(crate) async fn view_link_empty(
tera: web::Data<Tera>,
config: web::Data<crate::ServerConfig>,
id: Identity,
@ -96,7 +96,7 @@ pub(crate) async fn view_link(
data.insert("user", &link.user);
data.insert(
"title",
&format!("Links {} der Freien Hochschule Stuttgart", &link.item.code),
&format!("Links {} der {}", &link.item.code, &config.brand_name,),
);
data.insert("link", &link.item);
data.insert("qr", &svg);
@ -123,8 +123,8 @@ pub(crate) async fn view_profile(
data.insert(
"title",
&format!(
"Benutzer {} der Freien Hochschule Stuttgart",
&query.item.username
"Benutzer {} der {}",
&query.item.username, &config.brand_name,
),
);
data.insert("viewed_user", &query.item);
@ -150,8 +150,8 @@ pub(crate) async fn edit_profile(
data.insert(
"title",
&format!(
"Benutzer {} der Freien Hochschule Stuttgart",
&query.user.username
"Benutzer {} der {}",
&query.user.username, &config.brand_name,
),
);
data.insert("user", &query.user);
@ -330,10 +330,10 @@ pub(crate) async fn redirect(
}
}
pub(crate) async fn redirect_fhs() -> Result<HttpResponse, ServerError> {
Ok(redirect_builder(
"https://www.freie-hochschule-stuttgart.de",
))
pub(crate) async fn redirect_empty(
config: web::Data<crate::ServerConfig>,
) -> Result<HttpResponse, ServerError> {
Ok(redirect_builder(&config.empty_forward_url))
}
pub(crate) async fn create_link(