Add language support.
This commit is contained in:
parent
c9f2e2f721
commit
4ba9aa5c98
10 changed files with 99 additions and 19 deletions
|
@ -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';
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
25
gpg-mailgate-web/public_html/include/language.php
Normal file
25
gpg-mailgate-web/public_html/include/language.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
/*
|
||||
|
||||
gpg-mailgate
|
||||
|
||||
This file is part of the gpg-mailgate source code.
|
||||
|
||||
gpg-mailgate is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
gpg-mailgate source code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with gpg-mailgate source code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/../language/' . $config['language'] . '.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));
|
||||
|
|
|
@ -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");
|
||||
|
|
47
gpg-mailgate-web/public_html/language/english.php
Normal file
47
gpg-mailgate-web/public_html/language/english.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/*
|
||||
|
||||
gpg-mailgate
|
||||
|
||||
This file is part of the gpg-mailgate source code.
|
||||
|
||||
gpg-mailgate is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
gpg-mailgate source code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with gpg-mailgate source code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
$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'] = '<a href="https://github.com/uakfdotb/gpg-mailgate">gpg-mailgate and gpg-mailgate-web</a> are released under the <a href="https://www.gnu.org/licenses/lgpl-3.0.txt">GNU LGPL</a>.';
|
||||
$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";
|
||||
|
||||
?>
|
0
gpg-mailgate-web/public_html/language/index.html
Normal file
0
gpg-mailgate-web/public_html/language/index.html
Normal file
|
@ -27,20 +27,20 @@
|
|||
<p><b><i><?= htmlspecialchars($message) ?></i></b></p>
|
||||
<? } ?>
|
||||
|
||||
<p>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.</p>
|
||||
<p><?= $lang['home_text'] ?></p>
|
||||
|
||||
<form method="POST">
|
||||
<table>
|
||||
<tr>
|
||||
<td>Your email address (must match key)</td>
|
||||
<td><?= $lang['home_emaildesc'] ?></td>
|
||||
<td><input type="text" name="email" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>ASCII-armored PGP public key</td>
|
||||
<td><?= $lang['home_keydesc'] ?></td>
|
||||
<td><textarea name="key" rows="10" cols="80"></textarea></td>
|
||||
</tr>
|
||||
</table>
|
||||
<input type="submit" value="Submit key" />
|
||||
<input type="submit" value="<?= $lang['home_submitkey'] ?>" />
|
||||
</form>
|
||||
|
||||
<p><a href="https://github.com/uakfdotb/gpg-mailgate">gpg-mailgate and gpg-mailgate-web</a> are released under the <a href="https://www.gnu.org/licenses/lgpl-3.0.txt">GNU LGPL</a>.</p>
|
||||
<p><?= $lang['home_footer'] ?></p>
|
||||
|
|
Loading…
Reference in a new issue