* [pbs-devel] [PATCH backup 0/2] implement GUI translation support @ 2020-09-07 12:56 Thomas Lamprecht 2020-09-07 12:56 ` [pbs-devel] [PATCH backup 1/2] tools: rename extract_auth_cookie to extract_cookie Thomas Lamprecht ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: Thomas Lamprecht @ 2020-09-07 12:56 UTC (permalink / raw) To: pbs-devel Modelled after the PVE/PMG approach. We already set the "PBSLangCookie" correctly, so I only had to add parsing and sourcing the language JS file, if it exists, Thomas Lamprecht (2): tools: rename extract_auth_cookie to extract_cookie ui: add translation support debian/control | 1 + debian/control.in | 1 + src/bin/proxmox-backup-proxy.rs | 1 + src/server/rest.rs | 34 ++++++++++++++++++++++++--------- src/tools.rs | 4 ++-- www/index.hbs | 4 ++++ 6 files changed, 34 insertions(+), 11 deletions(-) -- 2.27.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [pbs-devel] [PATCH backup 1/2] tools: rename extract_auth_cookie to extract_cookie 2020-09-07 12:56 [pbs-devel] [PATCH backup 0/2] implement GUI translation support Thomas Lamprecht @ 2020-09-07 12:56 ` Thomas Lamprecht 2020-09-07 12:56 ` [pbs-devel] [PATCH backup 2/2] ui: add translation support Thomas Lamprecht 2020-09-08 7:03 ` [pbs-devel] applied-series: [PATCH backup 0/2] implement GUI " Thomas Lamprecht 2 siblings, 0 replies; 6+ messages in thread From: Thomas Lamprecht @ 2020-09-07 12:56 UTC (permalink / raw) To: pbs-devel It does nothing specific to authentication.. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com> --- will be re-used for parsing the PBSLangCookie, it felt wrong having "auth" in the name. src/server/rest.rs | 2 +- src/tools.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/server/rest.rs b/src/server/rest.rs index 5ee788d2..70c8b2c1 100644 --- a/src/server/rest.rs +++ b/src/server/rest.rs @@ -446,7 +446,7 @@ fn extract_auth_data(headers: &http::HeaderMap) -> (Option<String>, Option<Strin let mut ticket = None; if let Some(raw_cookie) = headers.get("COOKIE") { if let Ok(cookie) = raw_cookie.to_str() { - ticket = tools::extract_auth_cookie(cookie, "PBSAuthCookie"); + ticket = tools::extract_cookie(cookie, "PBSAuthCookie"); } } diff --git a/src/tools.rs b/src/tools.rs index 1b9d35a8..a3fbe007 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -326,9 +326,9 @@ pub fn assert_if_modified(digest1: &str, digest2: &str) -> Result<(), Error> { Ok(()) } -/// Extract authentication cookie from cookie header. +/// Extract a specific cookie from cookie header. /// We assume cookie_name is already url encoded. -pub fn extract_auth_cookie(cookie: &str, cookie_name: &str) -> Option<String> { +pub fn extract_cookie(cookie: &str, cookie_name: &str) -> Option<String> { for pair in cookie.split(';') { let (name, value) = match pair.find('=') { Some(i) => (pair[..i].trim(), pair[(i + 1)..].trim()), -- 2.27.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [pbs-devel] [PATCH backup 2/2] ui: add translation support 2020-09-07 12:56 [pbs-devel] [PATCH backup 0/2] implement GUI translation support Thomas Lamprecht 2020-09-07 12:56 ` [pbs-devel] [PATCH backup 1/2] tools: rename extract_auth_cookie to extract_cookie Thomas Lamprecht @ 2020-09-07 12:56 ` Thomas Lamprecht 2020-09-08 4:56 ` Dietmar Maurer 2020-09-08 7:03 ` [pbs-devel] applied-series: [PATCH backup 0/2] implement GUI " Thomas Lamprecht 2 siblings, 1 reply; 6+ messages in thread From: Thomas Lamprecht @ 2020-09-07 12:56 UTC (permalink / raw) To: pbs-devel Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com> --- debian/control | 1 + debian/control.in | 1 + src/bin/proxmox-backup-proxy.rs | 1 + src/server/rest.rs | 32 ++++++++++++++++++++++++-------- www/index.hbs | 4 ++++ 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/debian/control b/debian/control index e523d4d2..460cac6e 100644 --- a/debian/control +++ b/debian/control @@ -103,6 +103,7 @@ Depends: fonts-font-awesome, libjs-extjs (>= 6.0.1), libzstd1 (>= 1.3.8), lvm2, + pbs-i18n, proxmox-backup-docs, proxmox-mini-journalreader, proxmox-widget-toolkit (>= 2.2-4), diff --git a/debian/control.in b/debian/control.in index 31641a3b..8e2312d3 100644 --- a/debian/control.in +++ b/debian/control.in @@ -4,6 +4,7 @@ Depends: fonts-font-awesome, libjs-extjs (>= 6.0.1), libzstd1 (>= 1.3.8), lvm2, + pbs-i18n, proxmox-backup-docs, proxmox-mini-journalreader, proxmox-widget-toolkit (>= 2.2-4), diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index 2b43c5ac..75065e6f 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -53,6 +53,7 @@ async fn run() -> Result<(), Error> { config.add_alias("extjs", "/usr/share/javascript/extjs"); config.add_alias("fontawesome", "/usr/share/fonts-font-awesome"); config.add_alias("xtermjs", "/usr/share/pve-xtermjs"); + config.add_alias("locale", "/usr/share/pbs-i18n"); config.add_alias("widgettoolkit", "/usr/share/javascript/proxmox-widget-toolkit"); config.add_alias("css", "/usr/share/javascript/proxmox-backup/css"); config.add_alias("docs", "/usr/share/doc/proxmox-backup/html"); diff --git a/src/server/rest.rs b/src/server/rest.rs index 70c8b2c1..5577116b 100644 --- a/src/server/rest.rs +++ b/src/server/rest.rs @@ -313,7 +313,13 @@ pub async fn handle_api_request<Env: RpcEnvironment, S: 'static + BuildHasher + Ok(resp) } -fn get_index(userid: Option<Userid>, token: Option<String>, api: &Arc<ApiConfig>, parts: Parts) -> Response<Body> { +fn get_index( + userid: Option<Userid>, + token: Option<String>, + language: Option<String>, + api: &Arc<ApiConfig>, + parts: Parts, +) -> Response<Body> { let nodename = proxmox::tools::nodename(); let userid = userid.as_ref().map(|u| u.as_str()).unwrap_or(""); @@ -333,10 +339,18 @@ fn get_index(userid: Option<Userid>, token: Option<String>, api: &Arc<ApiConfig> } } + let mut lang = String::from(""); + if let Some(language) = language { + if Path::new(&format!("/usr/share/pbs-i18n/pbs-lang-{}.js", language)).exists() { + lang = language; + } + } + let data = json!({ "NodeName": nodename, "UserName": userid, "CSRFPreventionToken": token, + "language": lang, "debug": debug, }); @@ -441,12 +455,14 @@ async fn handle_static_file_download(filename: PathBuf) -> Result<Response<Body } } -fn extract_auth_data(headers: &http::HeaderMap) -> (Option<String>, Option<String>) { +fn extract_auth_data(headers: &http::HeaderMap) -> (Option<String>, Option<String>, Option<String>) { let mut ticket = None; + let mut language = None; if let Some(raw_cookie) = headers.get("COOKIE") { if let Ok(cookie) = raw_cookie.to_str() { ticket = tools::extract_cookie(cookie, "PBSAuthCookie"); + language = tools::extract_cookie(cookie, "PBSLangCookie"); } } @@ -455,7 +471,7 @@ fn extract_auth_data(headers: &http::HeaderMap) -> (Option<String>, Option<Strin _ => None, }; - (ticket, token) + (ticket, token, language) } fn check_auth( @@ -526,7 +542,7 @@ pub async fn handle_request(api: Arc<ApiConfig>, req: Request<Body>) -> Result<R ) { // explicitly allow those calls without auth } else { - let (ticket, token) = extract_auth_data(&parts.headers); + let (ticket, token, _) = extract_auth_data(&parts.headers); match check_auth(&method, &ticket, &token, &user_info) { Ok(userid) => rpcenv.set_user(Some(userid.to_string())), Err(err) => { @@ -573,20 +589,20 @@ pub async fn handle_request(api: Arc<ApiConfig>, req: Request<Body>) -> Result<R } if comp_len == 0 { - let (ticket, token) = extract_auth_data(&parts.headers); + let (ticket, token, language) = extract_auth_data(&parts.headers); if ticket != None { match check_auth(&method, &ticket, &token, &user_info) { Ok(userid) => { let new_token = assemble_csrf_prevention_token(csrf_secret(), &userid); - return Ok(get_index(Some(userid), Some(new_token), &api, parts)); + return Ok(get_index(Some(userid), Some(new_token), language, &api, parts)); } _ => { tokio::time::delay_until(Instant::from_std(delay_unauth_time)).await; - return Ok(get_index(None, None, &api, parts)); + return Ok(get_index(None, None, language, &api, parts)); } } } else { - return Ok(get_index(None, None, &api, parts)); + return Ok(get_index(None, None, language, &api, parts)); } } else { let filename = api.find_alias(&components); diff --git a/www/index.hbs b/www/index.hbs index 11e4baa9..fc5afb4a 100644 --- a/www/index.hbs +++ b/www/index.hbs @@ -12,7 +12,11 @@ <link rel="stylesheet" type="text/css" href="/fontawesome/css/font-awesome.css" /> <link rel="stylesheet" type="text/css" href="/widgettoolkit/css/ext6-pmx.css" /> <link rel="stylesheet" type="text/css" href="/css/ext6-pbs.css" /> + {{#if language}} + <script type='text/javascript' src='/locale/pbs-lang-{{ language }}.js'></script> + {{else}} <script type='text/javascript'> function gettext(buf) { return buf; } </script> + {{/if}} {{#if debug}} <script type="text/javascript" src="/extjs/ext-all-debug.js"></script> <script type="text/javascript" src="/extjs/charts-debug.js"></script> -- 2.27.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [pbs-devel] [PATCH backup 2/2] ui: add translation support 2020-09-07 12:56 ` [pbs-devel] [PATCH backup 2/2] ui: add translation support Thomas Lamprecht @ 2020-09-08 4:56 ` Dietmar Maurer 2020-09-08 6:44 ` Thomas Lamprecht 0 siblings, 1 reply; 6+ messages in thread From: Dietmar Maurer @ 2020-09-08 4:56 UTC (permalink / raw) To: Proxmox Backup Server development discussion, Thomas Lamprecht dpkg: dependency problems prevent configuration of proxmox-backup-server: proxmox-backup-server depends on pbs-i18n; however: Package pbs-i18n is not installed. So where is that package? > On 09/07/2020 2:56 PM Thomas Lamprecht <t.lamprecht@proxmox.com> wrote: > > > Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com> > --- > debian/control | 1 + > debian/control.in | 1 + > src/bin/proxmox-backup-proxy.rs | 1 + > src/server/rest.rs | 32 ++++++++++++++++++++++++-------- > www/index.hbs | 4 ++++ > 5 files changed, 31 insertions(+), 8 deletions(-) > > diff --git a/debian/control b/debian/control > index e523d4d2..460cac6e 100644 > --- a/debian/control > +++ b/debian/control > @@ -103,6 +103,7 @@ Depends: fonts-font-awesome, > libjs-extjs (>= 6.0.1), > libzstd1 (>= 1.3.8), > lvm2, > + pbs-i18n, > proxmox-backup-docs, > proxmox-mini-journalreader, > proxmox-widget-toolkit (>= 2.2-4), ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [pbs-devel] [PATCH backup 2/2] ui: add translation support 2020-09-08 4:56 ` Dietmar Maurer @ 2020-09-08 6:44 ` Thomas Lamprecht 0 siblings, 0 replies; 6+ messages in thread From: Thomas Lamprecht @ 2020-09-08 6:44 UTC (permalink / raw) To: Proxmox Backup Server development discussion, Dietmar Maurer On 08.09.20 06:56, Dietmar Maurer wrote: > dpkg: dependency problems prevent configuration of proxmox-backup-server: > proxmox-backup-server depends on pbs-i18n; however: > Package pbs-i18n is not installed. > > So where is that package? We already talked off-list, so just for the record: It's already uploaded in out internal staging repository, and lives in the proxmox-i18n git repository. Commit which added it there is: https://git.proxmox.com/?p=proxmox-i18n.git;a=commitdiff;h=31f04d6ba979f99e8a23b6ff119322e208a10bc7 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [pbs-devel] applied-series: [PATCH backup 0/2] implement GUI translation support 2020-09-07 12:56 [pbs-devel] [PATCH backup 0/2] implement GUI translation support Thomas Lamprecht 2020-09-07 12:56 ` [pbs-devel] [PATCH backup 1/2] tools: rename extract_auth_cookie to extract_cookie Thomas Lamprecht 2020-09-07 12:56 ` [pbs-devel] [PATCH backup 2/2] ui: add translation support Thomas Lamprecht @ 2020-09-08 7:03 ` Thomas Lamprecht 2 siblings, 0 replies; 6+ messages in thread From: Thomas Lamprecht @ 2020-09-08 7:03 UTC (permalink / raw) To: pbs-devel On 07.09.20 14:56, Thomas Lamprecht wrote: > Modelled after the PVE/PMG approach. We already set the "PBSLangCookie" > correctly, so I only had to add parsing and sourcing the language JS file, if > it exists, > > Thomas Lamprecht (2): > tools: rename extract_auth_cookie to extract_cookie > ui: add translation support > > debian/control | 1 + > debian/control.in | 1 + > src/bin/proxmox-backup-proxy.rs | 1 + > src/server/rest.rs | 34 ++++++++++++++++++++++++--------- > src/tools.rs | 4 ++-- > www/index.hbs | 4 ++++ > 6 files changed, 34 insertions(+), 11 deletions(-) > applied. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-09-08 7:03 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-09-07 12:56 [pbs-devel] [PATCH backup 0/2] implement GUI translation support Thomas Lamprecht 2020-09-07 12:56 ` [pbs-devel] [PATCH backup 1/2] tools: rename extract_auth_cookie to extract_cookie Thomas Lamprecht 2020-09-07 12:56 ` [pbs-devel] [PATCH backup 2/2] ui: add translation support Thomas Lamprecht 2020-09-08 4:56 ` Dietmar Maurer 2020-09-08 6:44 ` Thomas Lamprecht 2020-09-08 7:03 ` [pbs-devel] applied-series: [PATCH backup 0/2] implement GUI " Thomas Lamprecht
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox