mirror of
https://codeberg.org/keyoxide/keyoxide-web.git
synced 2024-12-22 14:59:29 -07:00
Fix Reddit proof
This commit is contained in:
parent
d144a6d372
commit
8622953905
2 changed files with 40 additions and 8 deletions
|
@ -333,7 +333,7 @@ async function verifyProof(url, fingerprint) {
|
|||
match = url.match(/https:\/\/www.reddit.com\/user\/(.*)\/comments\/(.*)\/(.*)\//);
|
||||
output.display = match[1];
|
||||
output.url = `https://www.reddit.com/user/${match[1]}`;
|
||||
output.proofUrlFetch = url.replace(/\/[a-zA-Z0-9_]*\/$/, ".json");
|
||||
output.proofUrlFetch = `/server/verifyReddit.php?user=${match[1]}&comment=${match[2]}&fp=${fingerprint}`;
|
||||
try {
|
||||
response = await fetch(output.proofUrlFetch, {
|
||||
headers: {
|
||||
|
@ -345,13 +345,7 @@ async function verifyProof(url, fingerprint) {
|
|||
throw new Error('Response failed: ' + response.status);
|
||||
}
|
||||
json = await response.json();
|
||||
console.log(json);
|
||||
reVerify = new RegExp(`Verifying my OpenPGP key: openpgp4fpr:${fingerprint}`);
|
||||
json.Answer.forEach((item, i) => {
|
||||
if (reVerify.test(item.data)) {
|
||||
output.isVerified = true;
|
||||
}
|
||||
});
|
||||
output.isVerified = json.verified;
|
||||
} catch (e) {
|
||||
} finally {
|
||||
return output;
|
||||
|
|
38
server/verifyReddit.php
Normal file
38
server/verifyReddit.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
include 'secrets.php';
|
||||
|
||||
$fingerprint = htmlspecialchars($_GET["fp"]);
|
||||
$user = htmlspecialchars($_GET["user"]);
|
||||
$comment = htmlspecialchars($_GET["comment"]);
|
||||
|
||||
$url = "https://www.reddit.com/user/$user/comments/$comment.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;
|
||||
$response["comment"] = $comment;
|
||||
|
||||
foreach ($data as $entry) {
|
||||
$entryData = $entry["data"]["children"];
|
||||
|
||||
foreach ($entryData as $subEntry) {
|
||||
if (preg_match("/{$check}/i", $subEntry["data"]["selftext"])) {
|
||||
$response["verified"] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
|
||||
?>
|
Loading…
Reference in a new issue