add basic styling to about scheme privacy query page

This commit is contained in:
Vincent Sanders 2019-08-07 14:09:37 +01:00
parent 8cec045cb7
commit 1b030bd8de
3 changed files with 129 additions and 58 deletions

View File

@ -80,6 +80,16 @@ struct about_handlers {
bool hidden; /**< If entry should be hidden in listing */
};
/**
* authentication query description if messages fails to retrieve usable text
*/
static const char *authentication_description_fallback = "The site %s is requesting your username and password. The realm is \"%s\"";
/**
* privacy query description if messages fails to retrieve usable text
*/
static const char *privacy_description_fallback = "A privacy error occurred while communicating with %s this may be a site configuration error or an attempt to steal private information (passwords, messages or credit cards)";
/**
* issue fetch callbacks with locking
*/
@ -652,45 +662,15 @@ static bool fetch_about_srverror(struct fetch_about_context *ctx)
}
/**
* generate the description of the privacy query
*/
static nserror
get_privacy_description(struct nsurl *url,
const char *reason,
char **out_str)
{
nserror res;
char *url_s;
size_t url_l;
char *str = NULL;
const char *key = "PrivacyDescription";
res = nsurl_get(url, NSURL_SCHEME | NSURL_HOST, &url_s, &url_l);
if (res != NSERROR_OK) {
return res;
}
str = messages_get_buff(key, url_s, reason);
if ((str != NULL) && (strcmp(key, str) != 0)) {
*out_str = str;
} else {
*out_str = strdup(reason);
}
free(url_s);
return res;
}
/**
* generate the description of the login query
*/
static nserror
get_login_description(struct nsurl *url,
const char *realm,
const char *username,
const char *password,
char **out_str)
get_authentication_description(struct nsurl *url,
const char *realm,
const char *username,
const char *password,
char **out_str)
{
nserror res;
char *url_s;
@ -718,13 +698,14 @@ get_login_description(struct nsurl *url,
*out_str = str;
} else {
/* no message so fallback */
const char *fmt = "The site %s is requesting your username and password. The realm is \"%s\"";
slen = snprintf(str, 0, fmt, url_s, realm) + 1;
slen = snprintf(str, 0, authentication_description_fallback,
url_s, realm) + 1;
str = malloc(slen);
if (str == NULL) {
res = NSERROR_NOMEM;
} else {
snprintf(str, slen, fmt, url_s, realm);
snprintf(str, slen, authentication_description_fallback,
url_s, realm);
*out_str = str;
}
}
@ -736,7 +717,7 @@ get_login_description(struct nsurl *url,
/**
* Handler to generate about scheme authorisation query page
* Handler to generate about scheme authentication query page
*/
static bool fetch_about_query_auth_handler(struct fetch_about_context *ctx)
{
@ -778,8 +759,9 @@ static bool fetch_about_query_auth_handler(struct fetch_about_context *ctx)
fetch_set_http_code(ctx->fetchh, 200);
/* content type */
if (fetch_about_send_header(ctx, "Content-Type: text/html; charset=utf-8"))
if (fetch_about_send_header(ctx, "Content-Type: text/html; charset=utf-8")) {
goto fetch_about_query_auth_handler_aborted;
}
title = messages_get("LoginTitle");
@ -797,7 +779,6 @@ static bool fetch_about_query_auth_handler(struct fetch_about_context *ctx)
goto fetch_about_query_auth_handler_aborted;
}
res = ssenddataf(ctx,
"<form method=\"post\""
" enctype=\"multipart/form-data\">");
@ -805,11 +786,11 @@ static bool fetch_about_query_auth_handler(struct fetch_about_context *ctx)
goto fetch_about_query_auth_handler_aborted;
}
res = get_login_description(siteurl,
realm,
username,
password,
&description);
res = get_authentication_description(siteurl,
realm,
username,
password,
&description);
if (res == NSERROR_OK) {
res = ssenddataf(ctx, "<p>%s</p>", description);
free(description);
@ -891,6 +872,54 @@ fetch_about_query_auth_handler_aborted:
return false;
}
/**
* generate the description of the privacy query
*/
static nserror get_privacy_description(struct nsurl *url, char **out_str)
{
nserror res;
char *url_s;
size_t url_l;
char *str = NULL;
const char *key = "PrivacyDescription";
/* get the host in question */
res = nsurl_get(url, NSURL_HOST, &url_s, &url_l);
if (res != NSERROR_OK) {
return res;
}
/* obtain the description with the url substituted */
str = messages_get_buff(key, url_s);
if ((str != NULL) && (strcmp(key, str) == 0)) {
/* the returned string was simply the key */
free(str);
str = NULL;
}
if (str == NULL) {
/* failed to get suitable translated message text so
* fall back to basic english.
*/
int slen;
slen = snprintf(str, 0, privacy_description_fallback, url_s) + 1;
str = malloc(slen);
if (str != NULL) {
snprintf(str, slen, privacy_description_fallback, url_s);
}
}
if (str == NULL) {
res = NSERROR_NOMEM;
} else {
*out_str = str;
}
free(url_s);
return res;
}
/**
* Handler to generate about scheme privacy query page
*/
@ -946,15 +975,6 @@ static bool fetch_about_query_privacy_handler(struct fetch_about_context *ctx)
goto fetch_about_query_ssl_handler_aborted;
}
res = get_privacy_description(siteurl, reason, &description);
if (res == NSERROR_OK) {
res = ssenddataf(ctx, "<p>%s</p>", description);
free(description);
if (res != NSERROR_OK) {
goto fetch_about_query_ssl_handler_aborted;
}
}
res = ssenddataf(ctx,
"<form method=\"post\""
" enctype=\"multipart/form-data\">");
@ -962,8 +982,21 @@ static bool fetch_about_query_privacy_handler(struct fetch_about_context *ctx)
goto fetch_about_query_ssl_handler_aborted;
}
res = get_privacy_description(siteurl, &description);
if (res == NSERROR_OK) {
res = ssenddataf(ctx, "<div><p>%s</p></div>", description);
free(description);
if (res != NSERROR_OK) {
goto fetch_about_query_ssl_handler_aborted;
}
}
res = ssenddataf(ctx, "<div><p>%s</p></div>", messages_get(reason));
if (res != NSERROR_OK) {
goto fetch_about_query_ssl_handler_aborted;
}
res = ssenddataf(ctx,
"<div>"
"<div id=\"buttons\">"
"<input type=\"submit\" id=\"back\" name=\"back\" "
"value=\"%s\">"
"<input type=\"submit\" id=\"proceed\" name=\"proceed\" "

View File

@ -2784,9 +2784,21 @@ nl.all.Cancel:Annuleer
#
en.all.PrivacyTitle:Privacy error
en.all.PrivacyDescription:Attackers might be trying to steal your information from %s (for example, passwords, messages or credit cards) %s
de.all.PrivacyTitle:Datenschutzfehler
fr.all.PrivacyTitle:Erreur de confidentialité
it.all.PrivacyTitle:Errore di privacy
nl.all.PrivacyTitle:Privacyfout
en.all.PrivacyDescription:A privacy error occurred while communicating with %s this may be a site configuration error or an attempt to steal private information (passwords, messages or credit cards)
en.all.Proceed:Proceed
de.all.Proceed:Vorgehen
fr.all.Proceed:Procéder
it.all.Proceed:Procedere
nl.all.Proceed:Doorgaan
en.all.Backtosafety:Back to safety
de.all.Backtosafety:Zurück zur Sicherheit
fr.all.Backtosafety:Retour a la sécurité
it.all.Backtosafety:Ritorno alla sicurezza
nl.all.Backtosafety:Terug naar veiligheid
# SSL certificate viewer
# ======================

View File

@ -238,7 +238,7 @@ p.imagecachelist span {
}
/*
* authentication styling
* authentication query styling
*/
body#authentication {
@ -278,3 +278,29 @@ body#authentication div#buttons {
text-align: right;
margin-right: 1em;
}
/*
* privacy query styling
*/
body#privacy {
max-width: 34em;
}
body#privacy form {
/* Just to center the form on the page */
margin: 0 auto;
/* To see the outline of the form */
padding: 1em;
border: 1px solid #CCC;
border-radius: 1em;
}
body#privacy form div + div {
margin-top: 1em;
}
body#privacy div#buttons {
text-align: right;
margin-right: 1em;
}