mirror of
https://codeberg.org/keyoxide/keyoxide-web.git
synced 2024-12-22 23:09:29 -07:00
Add php script to check HackerNews if javascript fails
This commit is contained in:
parent
e97fb27c0e
commit
b7c2b05214
2 changed files with 46 additions and 2 deletions
|
@ -464,9 +464,25 @@ async function verifyProof(url, fingerprint) {
|
|||
output.isVerified = true;
|
||||
}
|
||||
} 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
|
||||
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