Spaces:
Paused
Paused
File size: 6,232 Bytes
5340f1e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | /**
* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
* ู
ุซุงู ุงูุชุญูู ู
ู ุงูุชููู ูู ุงูุฎุงุฏู
ุงูุฎููู (Node.js)
* SkyGuard CAPTCHA โ Server-Side Token Verification
* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
*
* ุชุซุจูุช ุงูู
ุชุทูุจุงุช:
* npm install express axios
*
* ุชุดุบูู:
* node server-verify-example.js
*/
const express = require("express");
const axios = require("axios");
const app = express();
app.use(express.json());
// โโ ุงูุฅุนุฏุงุฏุงุช โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
const SKYGUARD_SPACE_URL = "https://YOUR_USERNAME-skyguard-captcha.hf.space";
// โโ ุงูุชุญูู ู
ู captchaToken ุงููุงุฏู
ู
ู ุงููุงุฌูุฉ ุงูุฃู
ุงู
ูุฉ โโ
async function verifyCaptchaToken(token) {
try {
const url = `${SKYGUARD_SPACE_URL}/api/verify?token=${encodeURIComponent(token)}`;
const res = await axios.get(url, { timeout: 5000 });
return res.data.valid === true;
} catch (err) {
console.error("[SkyGuard] Verification error:", err.message);
return false; // ูู ุญุงูุฉ ุงููุดูุ ุงุฑูุถ ุงูุทูุจ
}
}
// โโ ู
ุซุงู: ุญู
ุงูุฉ ููุทุฉ ููุงูุฉ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ
app.post("/api/submit-form", async (req, res) => {
const { captchaToken, name, email, message } = req.body;
// 1) ุชุญูู ู
ู ูุฌูุฏ ุงูุชููู
if (!captchaToken) {
return res.status(400).json({ error: "captcha_required" });
}
// 2) ุชุญูู ู
ู ุตุญุฉ ุงูุชููู ุนุจุฑ SkyGuard API
const valid = await verifyCaptchaToken(captchaToken);
if (!valid) {
return res.status(403).json({ error: "captcha_invalid_or_expired" });
}
// 3) ุงูุชููู ุตุญูุญ โ ูููุฐ ุงูู
ูุทู ุงูุฃุตูู
console.log("โ
CAPTCHA verified! Processing form:", { name, email });
res.json({ success: true, message: "ุชู
ุฅุฑุณุงู ุงููู
ูุฐุฌ ุจูุฌุงุญ" });
});
// โโ ู
ุซุงู: ุญู
ุงูุฉ ููุทุฉ ุชุณุฌูู ุงูุฏุฎูู โโโโโโโโโโโโโโโโโโโ
app.post("/api/login", async (req, res) => {
const { username, password, captchaToken } = req.body;
if (!captchaToken) {
return res.status(400).json({ error: "captcha_required" });
}
const valid = await verifyCaptchaToken(captchaToken);
if (!valid) {
return res.status(403).json({ error: "captcha_failed" });
}
// โ ููุง ู
ูุทู ุชุณุฌูู ุงูุฏุฎูู ุงูุฎุงุต ุจู
console.log("Login attempt by:", username);
res.json({ success: true });
});
// โโ ู
ุซุงู: Middleware ูุงุจู ูุฅุนุงุฏุฉ ุงูุงุณุชุฎุฏุงู
โโโโโโโโโโโโ
async function requireCaptcha(req, res, next) {
const token =
req.body?.captchaToken ||
req.query?.captchaToken ||
req.headers["x-captcha-token"];
if (!token) {
return res.status(400).json({ error: "captcha_token_missing" });
}
const valid = await verifyCaptchaToken(token);
if (!valid) {
return res.status(403).json({ error: "captcha_verification_failed" });
}
next();
}
// ุงุณุชุฎุฏุงู
ุงูู middleware
app.post("/api/register", requireCaptcha, (req, res) => {
res.json({ success: true, message: "ุชู
ุชุณุฌูู ุงูุญุณุงุจ ุจูุฌุงุญ" });
});
app.post("/api/contact", requireCaptcha, (req, res) => {
res.json({ success: true, message: "ุชู
ุฅุฑุณุงู ุฑุณุงูุชู" });
});
// โโ ุชุดุบูู ุงูุฎุงุฏู
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
app.listen(3000, () => {
console.log("โ
Server running at http://localhost:3000");
console.log("๐ SkyGuard Space:", SKYGUARD_SPACE_URL);
});
/**
* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
* ู
ุซุงู PHP (ุฅุฐุง ููุช ุชุณุชุฎุฏู
PHP)
* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
<?php
function verifySkyGuard(string $token): bool {
$url = "https://YOUR_USERNAME-skyguard-captcha.hf.space/api/verify?token=" . urlencode($token);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$body = curl_exec($ch);
curl_close($ch);
if (!$body) return false;
$data = json_decode($body, true);
return ($data['valid'] ?? false) === true;
}
// ุงูุงุณุชุฎุฏุงู
:
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$token = $_POST['captchaToken'] ?? '';
if (!verifySkyGuard($token)) {
http_response_code(403);
die(json_encode(['error' => 'captcha_failed']));
}
// โ
ู
ุชุงุจุนุฉ ุงูู
ูุทู ุงูุฃุตูู...
}
?>
*/
/**
* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
* ู
ุซุงู Python (Flask/Django)
* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
import requests
SKYGUARD_URL = "https://YOUR_USERNAME-skyguard-captcha.hf.space"
def verify_skyguard(token: str) -> bool:
try:
r = requests.get(
f"{SKYGUARD_URL}/api/verify",
params={"token": token},
timeout=5
)
return r.json().get("valid") is True
except Exception:
return False
# Flask ู
ุซุงู:
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route("/submit", methods=["POST"])
def submit():
token = request.json.get("captchaToken", "")
if not verify_skyguard(token):
return jsonify({"error": "captcha_failed"}), 403
# โ
ู
ุชุงุจุนุฉ...
return jsonify({"success": True})
*/
|