From 4ba9aa5c982320210fd0e9c50510f905baa05444 Mon Sep 17 00:00:00 2001 From: perennate Date: Sat, 28 Sep 2013 17:38:18 -0400 Subject: [PATCH] Add language support. --- .../public_html/config.default.php | 1 + .../public_html/config.sample.php | 3 ++ gpg-mailgate-web/public_html/confirm.php | 5 +- .../public_html/include/common.php | 1 + .../public_html/include/language.php | 25 ++++++++++ gpg-mailgate-web/public_html/include/pgp.php | 21 +++++---- gpg-mailgate-web/public_html/index.php | 5 +- .../public_html/language/english.php | 47 +++++++++++++++++++ .../public_html/language/index.html | 0 gpg-mailgate-web/public_html/theme/home.php | 10 ++-- 10 files changed, 99 insertions(+), 19 deletions(-) create mode 100644 gpg-mailgate-web/public_html/include/language.php create mode 100644 gpg-mailgate-web/public_html/language/english.php create mode 100644 gpg-mailgate-web/public_html/language/index.html diff --git a/gpg-mailgate-web/public_html/config.default.php b/gpg-mailgate-web/public_html/config.default.php index c0865a4..6bba21c 100644 --- a/gpg-mailgate-web/public_html/config.default.php +++ b/gpg-mailgate-web/public_html/config.default.php @@ -31,6 +31,7 @@ $config['email_from'] = 'gpg-mailgate-web@example.com'; $config['email_subject_requestpgp'] = 'Confirm your email address'; $config['site_url'] = 'http://example.com/gpgmw'; $config['site_title'] = 'PGP key management'; +$config['language'] = 'english'; $config['debug'] = false; $config['mail_smtp'] = false; $config['mail_smtp_host'] = 'localhost'; diff --git a/gpg-mailgate-web/public_html/config.sample.php b/gpg-mailgate-web/public_html/config.sample.php index 96ac46b..f1acfbf 100644 --- a/gpg-mailgate-web/public_html/config.sample.php +++ b/gpg-mailgate-web/public_html/config.sample.php @@ -40,6 +40,9 @@ $config['site_url'] = 'http://example.com/gpgmw'; //title of the website (displayed on home page) $config['site_title'] = 'PGP key management'; +//language file to use (see language subdirectory) +$config['language'] = 'english'; + //whether debug mode should be enabled $config['debug'] = false; diff --git a/gpg-mailgate-web/public_html/confirm.php b/gpg-mailgate-web/public_html/confirm.php index bbf1774..33803aa 100644 --- a/gpg-mailgate-web/public_html/confirm.php +++ b/gpg-mailgate-web/public_html/confirm.php @@ -21,6 +21,7 @@ */ require_once("include/config.php"); +require_once("include/language.php"); require_once("include/common.php"); require_once("include/dbconnect.php"); require_once("include/pgp.php"); @@ -29,9 +30,9 @@ if(isset($_REQUEST['email']) && isset($_REQUEST['confirm'])) { $result = confirmPGP($_REQUEST['email'], $_REQUEST['confirm']); if($result === true) { - get_page("home", array('message' => 'Your email address has been confirmed successfully. Within a few minutes, emails from our mail server to you should be encrypted with your PGP public key.')); + get_page("home", array('message' => $lang['confirm_success'])); } else { - get_page("home", array('message' => 'Error: failed to confirm any email address. You may have already confirmed the address, or you may have the wrong confirmation key.')); + get_page("home", array('message' => $lang['confirm_fail_general'])); } } else { get_page("home"); diff --git a/gpg-mailgate-web/public_html/include/common.php b/gpg-mailgate-web/public_html/include/common.php index 7539be5..46ab46e 100644 --- a/gpg-mailgate-web/public_html/include/common.php +++ b/gpg-mailgate-web/public_html/include/common.php @@ -71,6 +71,7 @@ function get_page($page, $args = array()) { //let pages use some variables extract($args); $config = $GLOBALS['config']; + $lang = $GLOBALS['lang']; $basePath = basePath(); diff --git a/gpg-mailgate-web/public_html/include/language.php b/gpg-mailgate-web/public_html/include/language.php new file mode 100644 index 0000000..dec4157 --- /dev/null +++ b/gpg-mailgate-web/public_html/include/language.php @@ -0,0 +1,25 @@ +. + +*/ + +require_once(dirname(__FILE__) . '/../language/' . $config['language'] . '.php'); + +?> diff --git a/gpg-mailgate-web/public_html/include/pgp.php b/gpg-mailgate-web/public_html/include/pgp.php index 3d8749f..2c6626a 100644 --- a/gpg-mailgate-web/public_html/include/pgp.php +++ b/gpg-mailgate-web/public_html/include/pgp.php @@ -23,22 +23,22 @@ //returns true on success or error message on failure function requestPGP($email, $key) { require_once(includePath() . "/lock.php"); - global $config; + global $config, $lang; if(!checkLock('requestpgp')) { - return "please wait a bit before trying again"; + return $lang['submit_error_trylater']; } if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { - return "invalid email address"; + return $lang['submit_error_bademail']; } if(strlen($email) > 256 || strlen($key) > 1024 * 32) { - return "email address or key too long"; + return $lang['submit_error_toolong']; } if(!isAscii($key)) { - return "only keys encoded with ASCII armor are accepted (gpg --armor)"; + return $lang['submit_error_nonascii']; } //housekeeping @@ -50,7 +50,7 @@ function requestPGP($email, $key) { if($row = $result->fetch()) { if($row[0] < 24) { - return "there is already a key in the queue for this email address; please wait twenty-four hours between submitting keys, or confirm the previous key and then resubmit"; + return $lang['submit_error_alreadyqueue']; } else { databaseQuery('DELETE FROM gpgmw_keys WHERE id = ?', array($row[1])); } @@ -61,17 +61,18 @@ function requestPGP($email, $key) { require_once(includePath() . "/gpg.php"); if(!verifyPGPKey($key, $email)) { - return "your key does not appear to be valid (ensure ASCII armor is enabled and that the email address entered matches the email address of the key)"; + return $lang['submit_error_badkey']; } } //well, it looks good, let's submit it lockAction('requestpgp'); $confirm = uid(32); - $result = gpgmw_mail($config['email_subject_requestpgp'], "Please confirm your email address to complete the submission process. You can do so by clicking the link below\n\n{$config['site_url']}/confirm.php?email=" . urlencode($email) . "&confirm=$confirm\n\nThanks,\ngpg-mailgate-web", $email); + $confirm_link = "{$config['site_url']}/confirm.php?email=" . urlencode($email) . "&confirm=$confirm"; + $result = gpgmw_mail($config['email_subject_requestpgp'], sprintf($lang['mail_confirm'], $confirm_link), $email); if(!$result) { - return "failed to send email"; + return $lang['submit_error_emailfail']; } databaseQuery("INSERT INTO gpgmw_keys (email, publickey, confirm) VALUES (?, ?, ?)", array($email, $key, $confirm)); @@ -83,7 +84,7 @@ function confirmPGP($email, $confirm) { require_once(includePath() . "/lock.php"); if(!lockAction('confirmpgp')) { - return "try again later"; + return false; } $result = databaseQuery("SELECT id FROM gpgmw_keys WHERE confirm = ? AND email = ?", array($confirm, $email)); diff --git a/gpg-mailgate-web/public_html/index.php b/gpg-mailgate-web/public_html/index.php index e1e912e..57127fe 100644 --- a/gpg-mailgate-web/public_html/index.php +++ b/gpg-mailgate-web/public_html/index.php @@ -21,6 +21,7 @@ */ require_once("include/config.php"); +require_once("include/language.php"); require_once("include/common.php"); require_once("include/dbconnect.php"); require_once("include/pgp.php"); @@ -29,9 +30,9 @@ if(isset($_POST['email']) && isset($_POST['key'])) { $result = requestPGP($_POST['email'], $_POST['key']); if($result === true) { - get_page("home", array('message' => 'Key submission successful. Please check your email to confirm your email address.')); + get_page("home", array('message' => $lang['submit_success'])); } else { - get_page("home", array('message' => 'Error: ' . $result . '.')); + get_page("home", array('message' => $result)); } } else { get_page("home"); diff --git a/gpg-mailgate-web/public_html/language/english.php b/gpg-mailgate-web/public_html/language/english.php new file mode 100644 index 0000000..9fb852a --- /dev/null +++ b/gpg-mailgate-web/public_html/language/english.php @@ -0,0 +1,47 @@ +. + +*/ + +$lang = array(); + +$lang['home_text'] = 'Use the form below to submit an ASCII-armored PGP public key. After submission, you will receive an email asking you to confirm your email address. Once confirmation is completed, mail sent to your email address via our mail server will be encrypted with your PGP public key.'; +$lang['home_footer'] = 'gpg-mailgate and gpg-mailgate-web are released under the GNU LGPL.'; +$lang['home_emaildesc'] = 'Your email address (must match key)'; +$lang['home_keydesc'] = 'ASCII-armored PGP public key'; +$lang['home_submitkey'] = 'Submit key'; + +$lang['submit_success'] = 'Key submission successful. Please check your email to confirm your email address.'; +$lang['submit_error_trylater'] = 'Error: please wait a bit before trying again.'; +$lang['submit_error_bademail'] = 'Error: invalid email address.'; +$lang['submit_error_toolong'] = 'Error: email address or key too long.'; +$lang['submit_error_nonascii'] = 'Error: only keys encoded with ASCII armor are accepted (gpg --armor).'; +$lang['submit_error_alreadyqueue'] = 'Error: there is already a key in the queue for this email address; please wait twenty-four hours between submitting keys, or confirm the previous key and then resubmit.'; +$lang['submit_error_badkey'] = 'Error: your key does not appear to be valid (ensure ASCII armor is enabled and that the email address entered matches the email address of the key).'; +$lang['submit_error_emailfail'] = 'Error: failed to send email.'; +$lang['submit_error_bademail'] = 'Error: invalid email address.'; +$lang['submit_error_bademail'] = 'Error: invalid email address.'; + +$lang['confirm_success'] = 'Your email address has been confirmed successfully. Within a few minutes, emails from our mail server to you should be encrypted with your PGP public key.'; +$lang['confirm_fail_general'] = 'Error: failed to confirm any email address. You may have already confirmed the address, or you may have the wrong confirmation key.'; + +$lang['mail_confirm'] = "Please confirm your email address to complete the submission process. You can do so by clicking the link below\n\n%s\n\nThanks,\ngpg-mailgate-web"; + +?> diff --git a/gpg-mailgate-web/public_html/language/index.html b/gpg-mailgate-web/public_html/language/index.html new file mode 100644 index 0000000..e69de29 diff --git a/gpg-mailgate-web/public_html/theme/home.php b/gpg-mailgate-web/public_html/theme/home.php index 3f3c383..ebf1fce 100644 --- a/gpg-mailgate-web/public_html/theme/home.php +++ b/gpg-mailgate-web/public_html/theme/home.php @@ -27,20 +27,20 @@

-

Use the form below to submit an ASCII-armored PGP public key. After submission, you will receive an email asking you to confirm your email address. Once confirmation is completed, mail sent to your email address via our mail server will be encrypted with your PGP public key.

+

- + - +
Your email address (must match key)
ASCII-armored PGP public key
- +
-

gpg-mailgate and gpg-mailgate-web are released under the GNU LGPL.

+