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})
 */