forked from Mirrors/keyoxide-web
Merge pull request 'Add php script to check HackerNews if javascript fails' (#19) from Supernova/fork-keyoxide:verifyHackerNews into dev
Reviewed-on: https://codeberg.org/keyoxide/web/pulls/19
This commit is contained in:
commit
b3d6642edd
2 changed files with 46 additions and 2 deletions
|
@ -493,9 +493,25 @@ async function verifyProof(url, fingerprint) {
|
||||||
output.isVerified = true;
|
output.isVerified = true;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
} finally {
|
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(output.isVerified == false) {
|
||||||
|
output.proofUrlFetch = `/server/verifyHackerNews.php?user=${match[1]}&fp=${fingerprint}`;
|
||||||
|
try {
|
||||||
|
response = await fetch(output.proofUrlFetch, {
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json'
|
||||||
|
},
|
||||||
|
credentials: 'omit'
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Response failed: ' + response.status);
|
||||||
|
}
|
||||||
|
json = await response.json();
|
||||||
|
output.isVerified = json.verified;
|
||||||
|
} catch (e) { }
|
||||||
|
}
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
// dev.to
|
// dev.to
|
||||||
if (/^https:\/\/dev\.to\//.test(url)) {
|
if (/^https:\/\/dev\.to\//.test(url)) {
|
||||||
|
|
28
server/verifyHackerNews.php
Normal file
28
server/verifyHackerNews.php
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$fingerprint = urlencode($_GET["fp"]);
|
||||||
|
$user = urlencode($_GET["user"]);
|
||||||
|
|
||||||
|
$url = "https://hacker-news.firebaseio.com/v0/user/$user.json";
|
||||||
|
$check = "\[Verifying my OpenPGP key: openpgp4fpr:$fingerprint\]";
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
$result = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
$data = json_decode($result, true);
|
||||||
|
|
||||||
|
$response = array();
|
||||||
|
$response["verified"] = false;
|
||||||
|
$response["fingerprint"] = $fingerprint;
|
||||||
|
$response["user"] = $user;
|
||||||
|
|
||||||
|
if (preg_match("/{$check}/i", $data["about"])) {
|
||||||
|
$response["verified"] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($response);
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in a new issue