NAME commited on
Commit
d6a77a6
·
1 Parent(s): 9e29eca
Dockerfile ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM node:20-bullseye
2
+
3
+ # Install ALL dependencies untuk OpenCV + Chrome
4
+ RUN apt update && apt install -y \
5
+ wget gnupg ca-certificates xvfb \
6
+ fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 \
7
+ libatk1.0-0 libxss1 libnss3 libxcomposite1 libxdamage1 libxrandr2 libgbm1 \
8
+ python3 make g++ pkg-config cmake \
9
+ libcairo2-dev libjpeg-dev libpng-dev libgif-dev librsvg2-dev \
10
+ libopencv-dev \
11
+ && wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
12
+ && apt install -y ./google-chrome-stable_current_amd64.deb \
13
+ && rm google-chrome-stable_current_amd64.deb \
14
+ && apt clean
15
+
16
+ WORKDIR /app
17
+
18
+ RUN mkdir -p /app/endpoints && \
19
+ mkdir -p /app/cache
20
+
21
+ COPY package*.json ./
22
+
23
+ # Install OpenCV dengan build from source
24
+ RUN npm install
25
+
26
+ COPY . .
27
+
28
+ EXPOSE 7860
29
+
30
+ CMD rm -f /tmp/.X99-lock && \
31
+ Xvfb :99 -screen 0 1024x768x24 & \
32
+ export DISPLAY=:99 && \
33
+ npm start
README.md CHANGED
@@ -1,12 +1,12 @@
1
  ---
2
- title: '1'
3
- emoji: 🐨
4
  colorFrom: blue
5
- colorTo: red
6
- sdk: gradio
7
- sdk_version: 6.13.0
8
- app_file: app.py
9
- pinned: false
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Khususan Indra
3
+ emoji: 🤣
4
  colorFrom: blue
5
+ colorTo: yellow
6
+ sdk: docker
7
+ sdk_version: 6.0.0
8
+ license: apache-2.0
9
+ short_description: antibot ai
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
api_test.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ import httpx
3
+
4
+ async def main():
5
+ async with httpx.AsyncClient(timeout=30.0) as client:
6
+ resp1 = await client.post(
7
+ "http://localhost:8080/cloudflare",
8
+ json={
9
+ "domain": "https://olamovies.watch/generate",
10
+ "mode": "iuam",
11
+ },
12
+ )
13
+ print(resp1.json())
14
+
15
+ resp2 = await client.post(
16
+ "http://localhost:8080/cloudflare",
17
+ json={
18
+ "domain": "https://lksfy.com/",
19
+ "siteKey": "0x4AAAAAAA49NnPZwQijgRoi",
20
+ "mode": "turnstile",
21
+ },
22
+ )
23
+ print(resp2.json())
24
+
25
+ if __name__ == "__main__":
26
+ asyncio.run(main())
cache/cache.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "{\"domain\":\"https://v2links.org\",\"mode\":\"iuam\"}": {
3
+ "timestamp": 1758616160392,
4
+ "value": {
5
+ "cf_clearance": "qqs5f4MpFMgA0v78Qmh_HYDWoKhbwqlQ57bTW5KeIr8-1758616161-1.2.1.1-D5PdpmheHl.26ssIRKQBsXzPtPPkSXntEZ_H9FUJVt7MMTS_BEE8iH.E48MDzKtFBLwZqRYxE_1GLo1gj3ChXrwatOGEJcmGRUwavy2qvGgUPizn7qufd.sW0ULfhaRO7Gz_H_eO1TU3iEqCzltEUDNk0SviKRFkF8ozbvJ91MW_qmO.qrjQorbu_jxcgJv5BHs6rTNOitWtVDAmYMDukASq0viHXIUAIvTM.LIfQ88",
6
+ "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36",
7
+ "elapsed_time": 5.028
8
+ }
9
+ }
10
+ }
endpoints/antibot.js ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ // Pastikeun file imageProcessor.js aya dina folder anu sarua
4
+ const { extractTextFromImage } = require('./imageProcessor');
5
+
6
+ // --- KONFIGURASI & MAPPING ---
7
+ const NUMBER_WORDS = {
8
+ 'nol': '0', 'satu': '1', 'dua': '2', 'tiga': '3', 'empat': '4', 'lima': '5',
9
+ 'enam': '6', 'tujuh': '7', 'delapan': '8', 'sembilan': '9', 'sepuluh': '10',
10
+ 'sebelas': '11', 'one': '1', 'two': '2', 'three': '3', 'four': '4', 'five': '5',
11
+ 'six': '6', 'seven': '7', 'eight': '8', 'nine': '9', 'ten': '10',
12
+ 'zero': '0', 'eleven': '11', 'twelve': '12'
13
+ };
14
+
15
+ const LEET_MAP = {
16
+ '4': 'a', '@': 'a', '8': 'b', '3': 'e', '6': 'g', '1': 'i', '!': 'i', '0': 'o',
17
+ '5': 's', '$': 's', '7': 't', '+': 't', '2': 'z'
18
+ };
19
+
20
+ // --- FUNGSI HELPER ---
21
+ function safeString(s) { return (s || '').toString(); }
22
+
23
+ function normalizeText(text) {
24
+ let normalized = safeString(text).normalize('NFD').replace(/[\u0300-\u036f]/g, '');
25
+ normalized = normalized.toLowerCase();
26
+
27
+ // Apply Leet Map (anti-deteksi karakter anéh)
28
+ let leetOut = '';
29
+ for (const ch of normalized) { leetOut += (LEET_MAP[ch] !== undefined) ? LEET_MAP[ch] : ch; }
30
+ normalized = leetOut;
31
+
32
+ // Beberesih karakter non-alfanumerik
33
+ normalized = normalized.replace(/[^a-z0-9\s]/g, ' ').replace(/\s+/g, ' ').trim();
34
+
35
+ // Mapping kecap angka jadi digit
36
+ const tokens = normalized.split(/\s+/);
37
+ return tokens.map(t => NUMBER_WORDS[t] !== undefined ? NUMBER_WORDS[t] : t).join(' ');
38
+ }
39
+
40
+ function levenshtein(a = '', b = '') {
41
+ const alen = a.length, blen = b.length;
42
+ if (alen === 0) return blen;
43
+ if (blen === 0) return alen;
44
+ const matrix = Array.from({ length: alen + 1 }, () => new Array(blen + 1));
45
+ for (let i = 0; i <= alen; i++) matrix[i][0] = i;
46
+ for (let j = 0; j <= blen; j++) matrix[0][j] = j;
47
+ for (let i = 1; i <= alen; i++) {
48
+ for (let j = 1; j <= blen; j++) {
49
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
50
+ matrix[i][j] = Math.min(matrix[i - 1][j] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j - 1] + cost);
51
+ }
52
+ }
53
+ return matrix[alen][blen];
54
+ }
55
+
56
+ function similarity(a, b) {
57
+ a = normalizeText(a); b = normalizeText(b);
58
+ if (a === b || a.includes(b) || b.includes(a)) return 1;
59
+ const dist = levenshtein(a, b);
60
+ const maxLen = Math.max(a.length, b.length);
61
+ return maxLen === 0 ? 1 : 1 - (dist / maxLen);
62
+ }
63
+
64
+ // --- LOGIKA UTAMA SOLVER ---
65
+ async function solve(data) {
66
+ try {
67
+ console.log("🛠️ Processing Antibot Challenge...");
68
+
69
+ const mainBuffer = Buffer.from(data.main, 'base64');
70
+ const botsBuffers = data.bots.map(b => Buffer.from(b, 'base64'));
71
+
72
+ // OCR Gambar Instruksi Utama
73
+ const mainOCR = await extractTextFromImage(mainBuffer);
74
+ let rawMain = (mainOCR.response || "").toLowerCase();
75
+ console.log("🎯 Raw Instruction:", rawMain);
76
+
77
+ // --- BAGIAN TARGET NU DIUBAH (LEMBUT TAPI TEGAS) ---
78
+ const targets = rawMain
79
+ .replace(/please\s*click\s*on\s*the\s*anti-bot\s*links\s*in\s*the\s*following\s*order/gi, '')
80
+ .replace(/[:.,|+&-]/g, ' ') // Ganti karakter separator ku spasi
81
+ .split(/\s+/)
82
+ .filter(t => t.length > 0 && t !== 'and');
83
+
84
+ console.log("🔍 Cleaned Targets:", targets);
85
+
86
+ // OCR Kabéh Gambar Pilihan (Bots)
87
+ const botResults = [];
88
+ for (let i = 0; i < botsBuffers.length; i++) {
89
+ const res = await extractTextFromImage(botsBuffers[i]);
90
+ botResults.push({
91
+ index: (i + 1).toString(),
92
+ text: normalizeText(res.response || "")
93
+ });
94
+ console.log(`🖼️ Bot ${i+1} OCR: "${res.response}"`);
95
+ }
96
+
97
+ // Matching Strategy
98
+ let finalOrder = [];
99
+ let usedIndices = new Set();
100
+
101
+ for (const target of targets) {
102
+ let bestMatch = { index: null, score: -1 };
103
+
104
+ for (const bot of botResults) {
105
+ if (usedIndices.has(bot.index)) continue;
106
+
107
+ const score = similarity(bot.text, target);
108
+ if (score > bestMatch.score) {
109
+ bestMatch = { index: bot.index, score: score };
110
+ }
111
+ }
112
+
113
+ // Skor minimal 0.3 (30%) bisi OCR-na rada burem
114
+ if (bestMatch.index && bestMatch.score > 0.3) {
115
+ finalOrder.push(bestMatch.index);
116
+ usedIndices.add(bestMatch.index);
117
+ }
118
+ }
119
+
120
+ // Fallback: Mun aya bot nu can kapaéh, asupkeun dumasar urutan
121
+ if (finalOrder.length < botsBuffers.length) {
122
+ botResults.forEach(b => {
123
+ if(!usedIndices.has(b.index)) finalOrder.push(b.index);
124
+ });
125
+ }
126
+
127
+ // Pastikeun ngan ngirim jumlah nu sarua jeung bot nu aya
128
+ finalOrder = finalOrder.slice(0, botsBuffers.length);
129
+
130
+ console.log("✅ Final Solution:", finalOrder.join(", "));
131
+ return { status: "Success", result: finalOrder };
132
+
133
+ } catch (error) {
134
+ console.error("❌ Solver Error:", error.message);
135
+ return { status: "Error", message: error.message, result: ["1", "2", "3"] };
136
+ }
137
+ }
138
+
139
+ module.exports = solve;
endpoints/cloudflare.js ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ async function cloudflare(data, page) {
2
+ return new Promise(async (resolve, reject) => {
3
+ if (!data.domain) return reject(new Error("Missing domain parameter"))
4
+
5
+ const startTime = Date.now()
6
+ let isResolved = false
7
+ let userAgent = null
8
+
9
+ const cl = setTimeout(() => {
10
+ if (!isResolved) {
11
+ isResolved = true
12
+ const elapsedTime = (Date.now() - startTime) / 1000
13
+ resolve({
14
+ cf_clearance: null,
15
+ user_agent: userAgent,
16
+ elapsed_time: elapsedTime,
17
+ })
18
+ }
19
+ }, 20000)
20
+
21
+ try {
22
+ if (data.proxy?.username && data.proxy?.password) {
23
+ await page.authenticate({
24
+ username: data.proxy.username,
25
+ password: data.proxy.password,
26
+ })
27
+ }
28
+
29
+ page.removeAllListeners("request")
30
+ page.removeAllListeners("response")
31
+ await page.setRequestInterception(true)
32
+
33
+ page.on("request", async (req) => {
34
+ try {
35
+ await req.continue()
36
+ } catch (_) {}
37
+ })
38
+
39
+ page.on("response", async (res) => {
40
+ try {
41
+ const url = res.url()
42
+ if (url.includes("/cdn-cgi/challenge-platform/")) {
43
+ const headers = res.headers()
44
+ if (headers["set-cookie"]) {
45
+ const match = headers["set-cookie"].match(/cf_clearance=([^;]+)/)
46
+ if (match) {
47
+ const cf_clearance = match[1]
48
+ const userAgent = (await res.request().headers())["user-agent"]
49
+ const elapsedTime = (Date.now() - startTime) / 1000
50
+
51
+ if (!isResolved) {
52
+ isResolved = true
53
+ clearTimeout(cl)
54
+
55
+ resolve({
56
+ cf_clearance,
57
+ user_agent: userAgent,
58
+ elapsed_time: elapsedTime,
59
+ })
60
+ }
61
+ }
62
+ }
63
+ }
64
+ } catch (_) {}
65
+ })
66
+
67
+ await page.goto(data.domain, { waitUntil: "domcontentloaded" })
68
+ userAgent = await page.evaluate(() => navigator.userAgent)
69
+ } catch (err) {
70
+ if (!isResolved) {
71
+ isResolved = true
72
+ clearTimeout(cl)
73
+ reject(err)
74
+ }
75
+ }
76
+ })
77
+ }
78
+
79
+ module.exports = cloudflare
endpoints/imageProcessor ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const fs = require('fs');
2
+ const https = require('https');
3
+
4
+ async function extractTextFromImage(imageBuffer) {
5
+ console.log('[DEBUG] extractTextFromImage: Starting image text extraction');
6
+ console.log('[DEBUG] Image buffer size:', imageBuffer.length, 'bytes');
7
+
8
+ return new Promise((resolve, reject) => {
9
+ const base64Image = imageBuffer.toString('base64');
10
+ console.log('[DEBUG] Base64 image length:', base64Image.length);
11
+
12
+ const requestData = JSON.stringify({
13
+ "contents": [
14
+ {
15
+ "parts": [
16
+ {
17
+ "inline_data": {
18
+ "mime_type": "image/png",
19
+ "data": base64Image
20
+ }
21
+ },
22
+ {
23
+ "text": "Berikan text yang ada di gambar ini saja, tidak ada informasi lain cukup yang ada di gambar saja, jangan ada text lain kalo bukan dari gambar nya."
24
+ }
25
+ ]
26
+ }
27
+ ]
28
+ });
29
+
30
+ console.log('[DEBUG] Request data prepared, length:', requestData.length);
31
+
32
+ const options = {
33
+ hostname: 'generativelanguage.googleapis.com',
34
+ path: '/v1beta/models/gemini-2.5-flash-lite:generateContent',
35
+ method: 'POST',
36
+ headers: {
37
+ 'x-goog-api-key': 'AIzaSyB3-2egs0udKCDX_F7I58uVRAwv7OUX1G8',
38
+ 'Content-Type': 'application/json',
39
+ 'Content-Length': Buffer.byteLength(requestData)
40
+ }
41
+ };
42
+
43
+ console.log('[DEBUG] Making request to Gemini API...');
44
+
45
+ const req = https.request(options, (res) => {
46
+ console.log('[DEBUG] API Response status:', res.statusCode);
47
+ console.log('[DEBUG] API Response headers:', res.headers);
48
+
49
+ let data = '';
50
+
51
+ res.on('data', (chunk) => {
52
+ data += chunk;
53
+ });
54
+
55
+ res.on('end', () => {
56
+ console.log('[DEBUG] Received all response data');
57
+ console.log('[DEBUG] Response data length:', data.length);
58
+
59
+ try {
60
+ const response = JSON.parse(data);
61
+ console.log('[DEBUG] Response parsed successfully');
62
+
63
+ if (response.candidates && response.candidates[0] && response.candidates[0].content) {
64
+ const text = response.candidates[0].content.parts[0].text;
65
+ console.log('[DEBUG] ✅ Text extracted:', text);
66
+ resolve({ status: true, response: text });
67
+ } else {
68
+ console.log('[DEBUG] ❌ No text found in response');
69
+ console.log('[DEBUG] Response structure:', JSON.stringify(response, null, 2));
70
+
71
+ if (response.error) {
72
+ console.log('[DEBUG] API Error:', response.error);
73
+ }
74
+
75
+ resolve({ status: false, response: 'Tidak ada teks yang ditemukan' });
76
+ }
77
+ } catch (error) {
78
+ console.error('[DEBUG] ❌ JSON parse error:', error);
79
+ console.log('[DEBUG] Raw response data:', data);
80
+ reject(error);
81
+ }
82
+ });
83
+ });
84
+
85
+ req.on('error', (error) => {
86
+ console.error('[DEBUG] ❌ Request error:', error);
87
+ reject(error);
88
+ });
89
+
90
+ req.on('timeout', () => {
91
+ console.error('[DEBUG] ❌ Request timeout');
92
+ req.destroy();
93
+ reject(new Error('Request timeout'));
94
+ });
95
+
96
+ req.setTimeout(30000); // 30 second timeout
97
+
98
+ console.log('[DEBUG] Sending request...');
99
+ req.write(requestData);
100
+ req.end();
101
+ console.log('[DEBUG] Request sent');
102
+ });
103
+ }
104
+
105
+ module.exports = { extractTextFromImage };
endpoints/turnstile.js ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ async function turnstile({ domain, proxy, siteKey }, page) {
2
+ if (!domain) throw new Error("Missing domain parameter");
3
+ if (!siteKey) throw new Error("Missing siteKey parameter");
4
+
5
+ const timeout = global.timeOut || 60000;
6
+ let isResolved = false;
7
+
8
+ const cl = setTimeout(async () => {
9
+ if (!isResolved) {
10
+ throw new Error("Timeout Error");
11
+ }
12
+ }, timeout);
13
+
14
+ try {
15
+ if (proxy?.username && proxy?.password) {
16
+ await page.authenticate({
17
+ username: proxy.username,
18
+ password: proxy.password,
19
+ });
20
+ }
21
+
22
+ const htmlContent = `
23
+ <!DOCTYPE html>
24
+ <html lang="en">
25
+ <body>
26
+ <div class="turnstile"></div>
27
+ <script src="https://challenges.cloudflare.com/turnstile/v0/api.js?onload=onloadTurnstileCallback" defer></script>
28
+ <script>
29
+ window.onloadTurnstileCallback = function () {
30
+ turnstile.render('.turnstile', {
31
+ sitekey: '${siteKey}',
32
+ callback: function (token) {
33
+ var c = document.createElement('input');
34
+ c.type = 'hidden';
35
+ c.name = 'cf-response';
36
+ c.value = token;
37
+ document.body.appendChild(c);
38
+ },
39
+ });
40
+ };
41
+ </script>
42
+ </body>
43
+ </html>
44
+ `;
45
+
46
+ await page.setRequestInterception(true);
47
+ page.removeAllListeners("request");
48
+ page.on("request", async (request) => {
49
+ if ([domain, domain + "/"].includes(request.url()) && request.resourceType() === "document") {
50
+ await request.respond({
51
+ status: 200,
52
+ contentType: "text/html",
53
+ body: htmlContent,
54
+ });
55
+ } else {
56
+ await request.continue();
57
+ }
58
+ });
59
+
60
+ await page.goto(domain, { waitUntil: "domcontentloaded" });
61
+
62
+ await page.waitForSelector('[name="cf-response"]', { timeout });
63
+
64
+ const token = await page.evaluate(() => {
65
+ try {
66
+ return document.querySelector('[name="cf-response"]').value;
67
+ } catch {
68
+ return null;
69
+ }
70
+ });
71
+
72
+ isResolved = true;
73
+ clearTimeout(cl);
74
+
75
+ if (!token || token.length < 10) throw new Error("Failed to get token");
76
+ return token;
77
+
78
+ } catch (e) {
79
+ clearTimeout(cl);
80
+ throw e;
81
+ }
82
+ }
83
+
84
+ module.exports = turnstile;
index.js ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const { connect } = require("puppeteer-real-browser");
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ const app = express();
7
+ const port = process.env.PORT || 7860;
8
+ const authToken = process.env.authToken || null;
9
+ const domain = process.env.DOMAIN || `https://forgets-Public.hf.space`;
10
+
11
+ // Konfigurasi Global
12
+ global.browserLimit = Number(process.env.browserLimit) || 30;
13
+ global.timeOut = Number(process.env.timeOut) || 120000;
14
+
15
+ // Cache System (Pikeun Cloudflare/Turnstile)
16
+ const CACHE_DIR = path.join(__dirname, "cache");
17
+ const CACHE_FILE = path.join(CACHE_DIR, "cache.json");
18
+ const CACHE_TTL = 5 * 60 * 1000;
19
+
20
+ function loadCache() {
21
+ if (!fs.existsSync(CACHE_FILE)) return {};
22
+ try { return JSON.parse(fs.readFileSync(CACHE_FILE, 'utf-8')); } catch { return {}; }
23
+ }
24
+
25
+ function saveCache(cache) {
26
+ if (!fs.existsSync(CACHE_DIR)) fs.mkdirSync(CACHE_DIR, { recursive: true });
27
+ fs.writeFileSync(CACHE_FILE, JSON.stringify(cache, null, 2), 'utf-8');
28
+ }
29
+
30
+ // Middleware
31
+ app.use(express.json({ limit: "50mb" }));
32
+ app.use(express.urlencoded({ extended: true, limit: "50mb" }));
33
+
34
+ // --- IMPORT ENDPOINTS ---
35
+ // Ngaran variabel dijieun béda (solveAntibot) meh teu bentrok jeung route /antibot
36
+ const solveTurnstile = require('./endpoints/turnstile');
37
+ const solveCloudflare = require('./endpoints/cloudflare');
38
+ const solveAntibot = require('./endpoints/antibot');
39
+
40
+ // Dashboard Status
41
+ app.get("/", (req, res) => {
42
+ res.json({
43
+ message: "Server is running!",
44
+ endpoints: {
45
+ cloudflare: `${domain}/cloudflare`,
46
+ antibot: `${domain}/antibot`
47
+ },
48
+ status: {
49
+ browserLimit: global.browserLimit,
50
+ authRequired: authToken !== null
51
+ }
52
+ });
53
+ });
54
+
55
+ // Browser Creator Utility
56
+ async function createBrowser(proxyServer = null) {
57
+ const connectOptions = {
58
+ headless: false,
59
+ turnstile: true,
60
+ connectOption: { defaultViewport: null },
61
+ disableXvfb: false,
62
+ };
63
+ if (proxyServer) connectOptions.args = [`--proxy-server=${proxyServer}`];
64
+
65
+ const { browser } = await connect(connectOptions);
66
+ const [page] = await browser.pages();
67
+
68
+ await page.goto('about:blank');
69
+ await page.setRequestInterception(true);
70
+ page.on('request', (req) => {
71
+ if (["image", "stylesheet", "font", "media"].includes(req.resourceType())) req.abort();
72
+ else req.continue();
73
+ });
74
+
75
+ return { browser, page };
76
+ }
77
+
78
+ // --- ROUTE: ANTIBOT (KHUSUS PHP BOT) ---
79
+ app.post("/antibot", async (req, res) => {
80
+ const data = req.body;
81
+
82
+ // Validasi data ti PHP
83
+ if (!data || !data.main || !Array.isArray(data.bots)) {
84
+ return res.status(400).json({ message: "Body format salah (kudu aya main & bots array)" });
85
+ }
86
+
87
+ try {
88
+ console.log("Menerima tantangan Antibot...");
89
+ // Manggil fungsi solveAntibot tina folder endpoints/
90
+ const result = await solveAntibot(data);
91
+
92
+ // Kirim hasilna balik ka PHP
93
+ res.json(result);
94
+ } catch (err) {
95
+ console.error("Error Antibot:", err.message);
96
+ res.status(500).json({ message: err.message });
97
+ }
98
+ });
99
+
100
+ // --- ROUTE: CLOUDFLARE/TURNSTILE ---
101
+ app.post('/cloudflare', async (req, res) => {
102
+ const data = req.body;
103
+ if (!data || !data.mode) return res.status(400).json({ message: 'Missing mode' });
104
+
105
+ if (global.browserLimit <= 0) return res.status(429).json({ message: 'Server Busy' });
106
+
107
+ global.browserLimit--;
108
+ let result, browser;
109
+
110
+ try {
111
+ const proxyServer = data.proxy ? `${data.proxy.hostname}:${data.proxy.port}` : null;
112
+ const ctx = await createBrowser(proxyServer);
113
+ browser = ctx.browser;
114
+ const page = ctx.page;
115
+
116
+ switch (data.mode) {
117
+ case "turnstile":
118
+ const token = await solveTurnstile(data, page);
119
+ result = { token };
120
+ break;
121
+ case "iuam":
122
+ result = await solveCloudflare(data, page);
123
+ break;
124
+ default:
125
+ result = { code: 400, message: 'Invalid mode' };
126
+ }
127
+ } catch (err) {
128
+ result = { code: 500, message: err.message };
129
+ } finally {
130
+ if (browser) await browser.close();
131
+ global.browserLimit++;
132
+ }
133
+
134
+ res.status(result.code ?? 200).json(result);
135
+ });
136
+
137
+ // Start Server
138
+ const server = app.listen(port, () => {
139
+ console.log(`API Server jalan dina port ${port}`);
140
+ });
141
+ server.timeout = global.timeOut;
package.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "cf-bypass",
3
+ "version": "1.0",
4
+ "description": "get the cf_clearance cookie from any website",
5
+ "scripts": {
6
+ "start": "node index.js",
7
+ "dev": "nodemon index.js"
8
+ },
9
+ "dependencies": {
10
+ "express": "^5.1.0",
11
+ "canvas": "^2.11.2",
12
+ "sharp": "^0.32.0",
13
+ "puppeteer-real-browser": "^1.4.0",
14
+ "axios": "^1.9.0",
15
+ "child_process": "*",
16
+ "tesseract.js": "^5.0.3",
17
+ "jimp": "^0.22.10"
18
+ },
19
+ "devDependencies": {
20
+ "nodemon": "^3.1.10"
21
+ }
22
+ }