mirror of
https://codeberg.org/keyoxide/keyoxide-web.git
synced 2024-12-23 07:19:28 -07:00
Fix handling of hkp or wkd depending on input
This commit is contained in:
parent
747cec0bb1
commit
2ab91d7659
6 changed files with 64 additions and 11 deletions
|
@ -585,9 +585,8 @@ if (elProfileUid) {
|
||||||
let match, opts, profileUid = elProfileUid.innerHTML;
|
let match, opts, profileUid = elProfileUid.innerHTML;
|
||||||
if (/.*@.*/.test(profileUid)) {
|
if (/.*@.*/.test(profileUid)) {
|
||||||
// Match email for wkd
|
// Match email for wkd
|
||||||
match = profileUid.match(/(.*)@(.*)_([a-zA-Z0-9]+)$/);
|
|
||||||
opts = {
|
opts = {
|
||||||
input: `${match[1]}@${match[2]}.${match[3]}`,
|
input: profileUid,
|
||||||
mode: "wkd"
|
mode: "wkd"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
48
index.php
48
index.php
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
include_once __DIR__ . '/vendor/autoload.php';
|
include_once __DIR__ . '/vendor/autoload.php';
|
||||||
use Pagerange\Markdown\MetaParsedown;
|
use Pagerange\Markdown\MetaParsedown;
|
||||||
|
include_once 'server/functions.php';
|
||||||
|
|
||||||
// Init router
|
// Init router
|
||||||
$router = new AltoRouter();
|
$router = new AltoRouter();
|
||||||
|
@ -14,6 +15,12 @@ $router->map('GET', '/proofs', function() {}, 'proofs');
|
||||||
$router->map('GET', '/verify/[:uid]', function() {}, 'verifyUid');
|
$router->map('GET', '/verify/[:uid]', function() {}, 'verifyUid');
|
||||||
$router->map('GET', '/encrypt/[:uid]', function() {}, 'encryptUid');
|
$router->map('GET', '/encrypt/[:uid]', function() {}, 'encryptUid');
|
||||||
$router->map('GET', '/proofs/[:uid]', function() {}, 'proofsUid');
|
$router->map('GET', '/proofs/[:uid]', function() {}, 'proofsUid');
|
||||||
|
$router->map('GET', '/verify/hkp/[:uid]', function() {}, 'verifyHKP');
|
||||||
|
$router->map('GET', '/encrypt/hkp/[:uid]', function() {}, 'encryptHKP');
|
||||||
|
$router->map('GET', '/proofs/hkp/[:uid]', function() {}, 'proofsHKP');
|
||||||
|
$router->map('GET', '/verify/wkd/[:uid]', function() {}, 'verifyWKD');
|
||||||
|
$router->map('GET', '/encrypt/wkd/[:uid]', function() {}, 'encryptWKD');
|
||||||
|
$router->map('GET', '/proofs/wkd/[:uid]', function() {}, 'proofsWKD');
|
||||||
$router->map('GET', '/guides', function() {}, 'guides');
|
$router->map('GET', '/guides', function() {}, 'guides');
|
||||||
$router->map('GET', '/guides/[:id]', function() {}, 'guideId');
|
$router->map('GET', '/guides/[:id]', function() {}, 'guideId');
|
||||||
$router->map('GET', '/faq', function() {}, 'faq');
|
$router->map('GET', '/faq', function() {}, 'faq');
|
||||||
|
@ -22,6 +29,11 @@ $router->map('GET', '/[:uid]', function() {}, 'profile');
|
||||||
// Router matching
|
// Router matching
|
||||||
$match = $router->match();
|
$match = $router->match();
|
||||||
|
|
||||||
|
// Fix "escaped" email address
|
||||||
|
if (array_key_exists('uid', $match['params'])) {
|
||||||
|
$match['params']['uid'] = str_lreplace('_', '.', $match['params']['uid']);
|
||||||
|
}
|
||||||
|
|
||||||
// Render the appropriate route
|
// Render the appropriate route
|
||||||
if(is_array($match) && is_callable($match['target'])) {
|
if(is_array($match) && is_callable($match['target'])) {
|
||||||
switch ($match['name']) {
|
switch ($match['name']) {
|
||||||
|
@ -31,24 +43,54 @@ if(is_array($match) && is_callable($match['target'])) {
|
||||||
|
|
||||||
case 'verify':
|
case 'verify':
|
||||||
case 'verifyUid':
|
case 'verifyUid':
|
||||||
|
case 'verifyHKP':
|
||||||
$content = file_get_contents('pages/verify.html');
|
$content = file_get_contents('pages/verify.html');
|
||||||
$content = str_replace('%UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ""), $content);
|
$content = str_replace('%HKP_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
|
||||||
|
$content = str_replace('%WKD_UID%', '', $content);
|
||||||
|
header('Content-Type: text/html; charset=utf-8');
|
||||||
|
echo($content);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'verifyWKD':
|
||||||
|
$content = file_get_contents('pages/verify.html');
|
||||||
|
$content = str_replace('%HKP_UID%', '', $content);
|
||||||
|
$content = str_replace('%WKD_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
|
||||||
header('Content-Type: text/html; charset=utf-8');
|
header('Content-Type: text/html; charset=utf-8');
|
||||||
echo($content);
|
echo($content);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'encrypt':
|
case 'encrypt':
|
||||||
case 'encryptUid':
|
case 'encryptUid':
|
||||||
|
case 'encryptHKP':
|
||||||
$content = file_get_contents('pages/encrypt.html');
|
$content = file_get_contents('pages/encrypt.html');
|
||||||
$content = str_replace('%UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ""), $content);
|
$content = str_replace('%HKP_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
|
||||||
|
$content = str_replace('%WKD_UID%', '', $content);
|
||||||
|
header('Content-Type: text/html; charset=utf-8');
|
||||||
|
echo($content);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'encryptWKD':
|
||||||
|
$content = file_get_contents('pages/encrypt.html');
|
||||||
|
$content = str_replace('%HKP_UID%', '', $content);
|
||||||
|
$content = str_replace('%WKD_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
|
||||||
header('Content-Type: text/html; charset=utf-8');
|
header('Content-Type: text/html; charset=utf-8');
|
||||||
echo($content);
|
echo($content);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'proofs':
|
case 'proofs':
|
||||||
case 'proofsUid':
|
case 'proofsUid':
|
||||||
|
case 'proofsHKP':
|
||||||
$content = file_get_contents('pages/proofs.html');
|
$content = file_get_contents('pages/proofs.html');
|
||||||
$content = str_replace('%UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ""), $content);
|
$content = str_replace('%HKP_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
|
||||||
|
$content = str_replace('%WKD_UID%', '', $content);
|
||||||
|
header('Content-Type: text/html; charset=utf-8');
|
||||||
|
echo($content);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'proofsWKD':
|
||||||
|
$content = file_get_contents('pages/proofs.html');
|
||||||
|
$content = str_replace('%HKP_UID%', '', $content);
|
||||||
|
$content = str_replace('%WKD_UID%', (array_key_exists('uid', $match['params']) ? $match['params']['uid'] : ''), $content);
|
||||||
header('Content-Type: text/html; charset=utf-8');
|
header('Content-Type: text/html; charset=utf-8');
|
||||||
echo($content);
|
echo($content);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -29,10 +29,10 @@
|
||||||
<h3>Public Key (1: plaintext)</h3>
|
<h3>Public Key (1: plaintext)</h3>
|
||||||
<textarea name="publicKey" id="publicKey"></textarea>
|
<textarea name="publicKey" id="publicKey"></textarea>
|
||||||
<h3>Public Key (2: web key directory)</h3>
|
<h3>Public Key (2: web key directory)</h3>
|
||||||
<input type="text" name="wkd" id="wkd" placeholder="name@domain.com">
|
<input type="text" name="wkd" id="wkd" placeholder="name@domain.com" value="%WKD_UID%">
|
||||||
<h3>Public Key (3: HKP server)</h3>
|
<h3>Public Key (3: HKP server)</h3>
|
||||||
<input type="text" name="hkp_server" id="hkp_server" placeholder="https://keys.openpgp.org/">
|
<input type="text" name="hkp_server" id="hkp_server" placeholder="https://keys.openpgp.org/">
|
||||||
<input type="text" name="hkp_input" id="hkp_input" placeholder="Email / key id / fingerprint" value="%UID%">
|
<input type="text" name="hkp_input" id="hkp_input" placeholder="Email / key id / fingerprint" value="%HKP_UID%">
|
||||||
<h3>Result</h3>
|
<h3>Result</h3>
|
||||||
<textarea name="messageEncrypted" id="messageEncrypted" readonly></textarea>
|
<textarea name="messageEncrypted" id="messageEncrypted" readonly></textarea>
|
||||||
<p id="result"></p>
|
<p id="result"></p>
|
||||||
|
|
|
@ -27,10 +27,10 @@
|
||||||
<h3>Public Key (1: plaintext)</h3>
|
<h3>Public Key (1: plaintext)</h3>
|
||||||
<textarea name="publicKey" id="publicKey"></textarea>
|
<textarea name="publicKey" id="publicKey"></textarea>
|
||||||
<h3>Public Key (2: web key directory)</h3>
|
<h3>Public Key (2: web key directory)</h3>
|
||||||
<input type="text" name="wkd" id="wkd" placeholder="name@domain.com">
|
<input type="text" name="wkd" id="wkd" placeholder="name@domain.com" value="%WKD_UID%">
|
||||||
<h3>Public Key (3: HKP server)</h3>
|
<h3>Public Key (3: HKP server)</h3>
|
||||||
<input type="text" name="hkp_server" id="hkp_server" placeholder="https://keys.openpgp.org/">
|
<input type="text" name="hkp_server" id="hkp_server" placeholder="https://keys.openpgp.org/">
|
||||||
<input type="text" name="hkp_input" id="hkp_input" placeholder="Email / key id / fingerprint" value="%UID%">
|
<input type="text" name="hkp_input" id="hkp_input" placeholder="Email / key id / fingerprint" value="%HKP_UID%">
|
||||||
<h3>Result</h3>
|
<h3>Result</h3>
|
||||||
<p id="result">Click on the button below.</p>
|
<p id="result">Click on the button below.</p>
|
||||||
<p id="resultContent"></p>
|
<p id="resultContent"></p>
|
||||||
|
|
|
@ -29,10 +29,10 @@
|
||||||
<h3>Public Key (1: plaintext)</h3>
|
<h3>Public Key (1: plaintext)</h3>
|
||||||
<textarea name="publicKey" id="publicKey"></textarea>
|
<textarea name="publicKey" id="publicKey"></textarea>
|
||||||
<h3>Public Key (2: web key directory)</h3>
|
<h3>Public Key (2: web key directory)</h3>
|
||||||
<input type="text" name="wkd" id="wkd" placeholder="name@domain.com">
|
<input type="text" name="wkd" id="wkd" placeholder="name@domain.com" value="%WKD_UID%">
|
||||||
<h3>Public Key (3: HKP server)</h3>
|
<h3>Public Key (3: HKP server)</h3>
|
||||||
<input type="text" name="hkp_server" id="hkp_server" placeholder="https://keys.openpgp.org/">
|
<input type="text" name="hkp_server" id="hkp_server" placeholder="https://keys.openpgp.org/">
|
||||||
<input type="text" name="hkp_input" id="hkp_input" placeholder="Email / key id / fingerprint" value="%UID%">
|
<input type="text" name="hkp_input" id="hkp_input" placeholder="Email / key id / fingerprint" value="%HKP_UID%">
|
||||||
<h3>Result</h3>
|
<h3>Result</h3>
|
||||||
<p id="result">Click on the button below.</p>
|
<p id="result">Click on the button below.</p>
|
||||||
<p id="resultContent"></p>
|
<p id="resultContent"></p>
|
||||||
|
|
12
server/functions.php
Normal file
12
server/functions.php
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
function str_lreplace($search, $replace, $subject) {
|
||||||
|
$pos = strrpos($subject, $search);
|
||||||
|
|
||||||
|
if($pos !== false) {
|
||||||
|
$subject = substr_replace($subject, $replace, $pos, strlen($search));
|
||||||
|
}
|
||||||
|
return $subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in a new issue