Skip to content

Commit

Permalink
In local installation by default use the EFI locale
Browse files Browse the repository at this point in the history
When connecting remotely it still prefers the browser language
  • Loading branch information
lslezak committed Jan 20, 2025
1 parent 88d1f1e commit a29e86b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
18 changes: 17 additions & 1 deletion live/root/root/.icewm/startup
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,21 @@ TOKEN_FILE=/run/agama/token
TOKEN=$(cat $TOKEN_FILE)
PREFS=$HOME/.mozilla/firefox/profile/user.js

sed -e "s/__HOMEPAGE__/http:\/\/localhost\/login?token=$TOKEN/" $PREFS.template > $PREFS
# read the system locale from EFI if present
LANG_FILE=/sys/firmware/efi/efivars/PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c

# file exists and is not empty
if [ -s "$LANG_FILE" ]; then
# skip the first 4 bytes (the EFI attributes), keep only the characters allowed in a language code,
# especially remove the trailing null byte
EFI_LANG=$(cat "$LANG_FILE" | tail -c +5 | tr -cd "[_a-zA-Z-]")

if [ -n "$EFI_LANG" ]; then
# escape & because it has a special meaning in sed replacement
LANG_QUERY="\\&lang=$EFI_LANG"
fi
fi

sed -e "s/__HOMEPAGE__/http:\/\/localhost\/login?token=$TOKEN$LANG_QUERY/" $PREFS.template > $PREFS

firefox --kiosk --profile $HOME/.mozilla/firefox/profile
20 changes: 18 additions & 2 deletions rust/agama-server/src/web/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ pub async fn login(
pub struct LoginFromQueryParams {
/// Token to use for authentication.
token: String,
/// Requested locale
lang: String,
}

#[utoipa::path(get, path = "/login", responses(
(status = 301, description = "Injects the authentication cookie if correct and redirects to the web UI")
(status = 307, description = "Injects the authentication cookie if correct and redirects to the web UI")
))]
pub async fn login_from_query(
State(state): State<ServiceState>,
Expand All @@ -120,7 +122,21 @@ pub async fn login_from_query(
);
}

headers.insert(header::LOCATION, HeaderValue::from_static("/"));
// the redirection path
let mut target = String::from("/");

// keep the "lang" URL query if it was present in the original request
if !&params.lang.is_empty() {
target.push_str(format!("?lang={}", params.lang).as_str());
}

let location = HeaderValue::from_str(target.as_str());

headers.insert(
header::LOCATION,
location.unwrap_or(HeaderValue::from_static("/")),
);

(StatusCode::TEMPORARY_REDIRECT, headers)
}

Expand Down

0 comments on commit a29e86b

Please sign in to comment.