File size: 6,493 Bytes
7de2405
64fab1f
 
7de2405
 
 
 
 
 
 
 
 
 
 
 
7b59bef
 
 
 
f334297
 
7b59bef
f334297
7b59bef
f334297
 
 
 
 
 
 
 
 
7de2405
 
 
 
7b59bef
7de2405
f334297
64fab1f
 
7b59bef
 
f334297
7de2405
 
f334297
 
 
7de2405
 
f334297
7b59bef
7de2405
 
 
 
7b59bef
7de2405
 
7b59bef
7de2405
7b59bef
 
f334297
7de2405
 
 
f334297
 
 
7de2405
f334297
7de2405
f334297
 
7de2405
7b59bef
 
 
7de2405
7b59bef
7de2405
 
7b59bef
 
 
 
7de2405
7b59bef
 
 
 
7de2405
 
 
 
 
 
7b59bef
64fab1f
7b59bef
 
931d770
64fab1f
931d770
7b59bef
 
64fab1f
7b59bef
 
 
 
 
 
 
 
f334297
931d770
7b59bef
 
 
 
884596e
931d770
 
 
64fab1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b59bef
 
 
 
 
64fab1f
931d770
 
7b59bef
 
931d770
 
 
64fab1f
f334297
 
884596e
7b59bef
f334297
 
 
 
884596e
f334297
7b59bef
 
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/**
 * API.js - Integrated with rektCaptcha Auto-Config & Docker Path
 * Powered by Forget
 */
const express = require('express');
const { connect } = require("puppeteer-real-browser");
const fs = require('fs');
const path = require('path');

const app = express();
const port = process.env.PORT || 7860;

global.browserLimit = 100;
global.timeOut = 300000;

// Path Ekstensi dari Docker (Absolute Path)
const EXTENSION_PATH = '/A/extensions/rek';

// Cache Configuration
const CACHE_DIR = path.join(__dirname, "cache");
const CACHE_AUTOSAVE = process.env.CACHE_AUTOSAVE === "true";
const CACHE_TTL = 5 * 60 * 1000;

if (!fs.existsSync(CACHE_DIR)) fs.mkdirSync(CACHE_DIR, { recursive: true });

function writeCache(type, taskId, value) {
    const dir = path.join(CACHE_DIR, type);
    if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
    const file = path.join(dir, `${taskId}.json`);
    const data = { timestamp: Date.now(), ...value };
    fs.writeFileSync(file, JSON.stringify(data, null, 2), 'utf-8');
}

app.use(express.json());
app.use(express.urlencoded({ extended: true }));
const tasks = {};

// Root Route
app.get("/", (req, res) => {
    res.json({
        message: "Solver API Running with rektCaptcha Auto-Config",
        version: "7.5.0-DAN",
        extension: fs.existsSync(EXTENSION_PATH) ? "Loaded" : "Not Found",
        uptime: `${Math.floor(process.uptime())}s`
    });
});

app.post('/solve', async (req, res) => {
    const { type, domain, siteKey, taskId, action, proxy, isInvisible } = req.body;

    if (taskId) {
        const task = tasks[taskId];
        if (!task) return res.status(404).json({ status: "error", message: "Task not found" });
        return res.json(task.status === "pending" ? { status: "processing" } : task);
    }

    const newTaskId = Date.now().toString(36);
    tasks[newTaskId] = { status: "pending" };
    console.log(`[NEW] ${newTaskId} | Type: ${type} | Domain: ${domain}`);

    (async () => {
        let browserInstance;
        try {
            const ctx = await init_browser(proxy);
            browserInstance = ctx.browser;
            const page = ctx.page;
            let result;

            switch (type) {
                case "turnstile":
                    result = await turnstile({ domain, siteKey, action, proxy }, page);
                    break;
                case "recaptcha2":
                    result = await recaptchaV2({ domain, siteKey, action, isInvisible, proxy }, page);
                    break;
                case "recaptcha3":
                    result = await recaptchaV3({ domain, siteKey, action, proxy }, page);
                    break;
                case "interstitial":
                    result = await interstitial({ domain, proxy }, page);
                    break;
                default:
                    throw new Error("Invalid type");
            }

            tasks[newTaskId] = { status: "done", ...result };
            if (CACHE_AUTOSAVE) writeCache(type, newTaskId, tasks[newTaskId]);
            console.log(`[DONE] ${newTaskId}`);

        } catch (err) {
            tasks[newTaskId] = { status: "error", message: err.message };
            console.error(`[FAILED] ${newTaskId}:`, err.message);
        } finally {
            if (browserInstance) await browserInstance.close();
        }
    })();

    res.json({ taskId: newTaskId, status: "pending" });
});

/**
 * Optimized init_browser with rektCaptcha Dynamic ID Detection & Config Injection
 */
async function init_browser(proxyData = null) {
    const connectOptions = {
        headless: false, // Wajib false agar ekstensi berjalan
        turnstile: true,
        connectOption: { 
            defaultViewport: null,
            protocolTimeout: 600000, 
            args: [
                '--no-sandbox',
                '--disable-setuid-sandbox',
                '--disable-dev-shm-usage',
                `--disable-extensions-except=${EXTENSION_PATH}`,
                `--load-extension=${EXTENSION_PATH}`
            ]
        },
        disableXvfb: false,
    };

    if (proxyData && proxyData.server) {
        connectOptions.connectOption.args.push(`--proxy-server=${proxyData.server}`);
    }

    const { browser } = await connect(connectOptions);
    const [page] = await browser.pages();

    // --- DAN MODE: AUTO-CONFIG REKTCAPTCHA ---
    try {
        const targets = await browser.targets();
        const extTarget = targets.find(t => t.url().includes('chrome-extension://'));

        if (extTarget) {
            const extId = extTarget.url().split('/')[2];
            console.log(`[RECT] ID Detected: ${extId}`);

            const extBackground = await browser.newPage();
            // Akses manifest untuk masuk ke konteks ID ekstensi tersebut
            await extBackground.goto(`chrome-extension://${extId}/manifest.json`, { waitUntil: 'networkidle2' });

            await extBackground.evaluate(() => {
                const config = {
                    "auto_open": true,
                    "auto_solve": true,
                    "image_click_delay": 0,
                    "solve_delay": 0,
                    "solve_method": "audio" 
                };
                if (typeof chrome !== 'undefined' && chrome.storage && chrome.storage.local) {
                    chrome.storage.local.set(config);
                }
            });
            await extBackground.close();
            console.log(`[RECT] Config Forced: Auto-Solve ON, Delay 0`);
        }
    } catch (e) {
        console.log(`[RECT] Config Injection Bypass: ${e.message}`);
    }

    // Handle Proxy Auth
    if (proxyData && proxyData.auth) {
        const [username, password] = proxyData.auth.split(':');
        await page.authenticate({ username, password });
    }

    // Intercept: Stylesheet JANGAN diblokir agar widget terbaca
    await page.setRequestInterception(true);
    page.on('request', (req) => {
        const resource = req.resourceType();
        if (["image", "font", "media"].includes(resource)) req.abort();
        else req.continue();
    });

    console.log(`[SYSTEM] Browser initialized with rektCaptcha`);
    return { browser, page };
}

// Load Modules
const turnstile = require('./Api/turnstile');
const interstitial = require('./Api/interstitial');
const recaptchaV2 = require('./Api/recaptcha2');
const recaptchaV3 = require('./Api/recaptcha3');

app.listen(port, () => {
    console.log(`Server running on port ${port}`);
});