Kenqt commited on
Commit
76513f3
·
verified ·
1 Parent(s): 911595c

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +33 -0
  2. api_test.py +26 -0
  3. index.js +179 -0
  4. package.json +22 -0
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
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())
index.js ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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://kenqt-pay.hf.space`;
10
+
11
+ global.browserLimit = Number(process.env.browserLimit) || 20;
12
+ global.timeOut = Number(process.env.timeOut) || 60000;
13
+
14
+ const CACHE_DIR = path.join(__dirname, "cache");
15
+ const CACHE_FILE = path.join(CACHE_DIR, "cache.json");
16
+ const CACHE_TTL = 5 * 60 * 1000;
17
+
18
+ function loadCache() {
19
+ if (!fs.existsSync(CACHE_FILE)) return {};
20
+ try {
21
+ return JSON.parse(fs.readFileSync(CACHE_FILE, 'utf-8'));
22
+ } catch {
23
+ return {};
24
+ }
25
+ }
26
+
27
+ function saveCache(cache) {
28
+ if (!fs.existsSync(CACHE_DIR)) {
29
+ fs.mkdirSync(CACHE_DIR, { recursive: true });
30
+ }
31
+ fs.writeFileSync(CACHE_FILE, JSON.stringify(cache, null, 2), 'utf-8');
32
+ }
33
+
34
+ function readCache(key) {
35
+ const cache = loadCache();
36
+ const entry = cache[key];
37
+ if (entry && Date.now() - entry.timestamp < CACHE_TTL) {
38
+ return entry.value;
39
+ }
40
+ return null;
41
+ }
42
+
43
+ function writeCache(key, value) {
44
+ const cache = loadCache();
45
+ cache[key] = { timestamp: Date.now(), value };
46
+ saveCache(cache);
47
+ }
48
+
49
+ app.use(express.json({ limit: "50mb" }));
50
+ app.use(express.urlencoded({ extended: true, limit: "50mb" }));
51
+
52
+ app.get("/", (req, res) => {
53
+ res.json({
54
+ message: "Server is running!",
55
+ domain: domain,
56
+ endpoints: {
57
+ cloudflare: `${domain}/cloudflare`,
58
+ antibot: `${domain}/antibot`
59
+ },
60
+ status: {
61
+ browserLimit: global.browserLimit,
62
+ timeOut: global.timeOut,
63
+ authRequired: authToken !== null
64
+ }
65
+ });
66
+ });
67
+
68
+ if (process.env.NODE_ENV !== 'development') {
69
+ let server = app.listen(port, () => {
70
+ console.log(`Server running on port ${port}`);
71
+ console.log(`Domain: ${domain}`);
72
+ console.log(`Auth required: ${authToken !== null}`);
73
+ });
74
+ try {
75
+ server.timeout = global.timeOut;
76
+ } catch {}
77
+ }
78
+
79
+ async function createBrowser(proxyServer = null) {
80
+ const connectOptions = {
81
+ headless: false,
82
+ turnstile: true,
83
+ connectOption: { defaultViewport: null },
84
+ disableXvfb: false,
85
+ };
86
+ if (proxyServer) connectOptions.args = [`--proxy-server=${proxyServer}`];
87
+
88
+ const { browser } = await connect(connectOptions);
89
+ const [page] = await browser.pages();
90
+
91
+ await page.goto('about:blank');
92
+ await page.setRequestInterception(true);
93
+ page.on('request', (req) => {
94
+ const type = req.resourceType();
95
+ if (["image", "stylesheet", "font", "media"].includes(type)) req.abort();
96
+ else req.continue();
97
+ });
98
+
99
+ return { browser, page };
100
+ }
101
+
102
+ const turnstile = require('./endpoints/turnstile');
103
+ const cloudflare = require('./endpoints/cloudflare');
104
+ const antibot = require('./endpoints/antibot');
105
+
106
+ app.post('/cloudflare', async (req, res) => {
107
+ const data = req.body;
108
+ if (!data || typeof data.mode !== 'string')
109
+ return res.status(400).json({ message: 'Bad Request: missing or invalid mode' });
110
+
111
+ if (global.browserLimit <= 0)
112
+ return res.status(429).json({ message: 'Too Many Requests' });
113
+
114
+ let cacheKey, cached;
115
+ if (data.mode === "iuam") {
116
+ cacheKey = JSON.stringify(data);
117
+ cached = readCache(cacheKey);
118
+ if (cached) return res.status(200).json({ ...cached, cached: true });
119
+ }
120
+
121
+ global.browserLimit--;
122
+ let result, browser;
123
+
124
+ try {
125
+ const proxyServer = data.proxy ? `${data.proxy.hostname}:${data.proxy.port}` : null;
126
+ const ctx = await createBrowser(proxyServer);
127
+ browser = ctx.browser;
128
+ const page = ctx.page;
129
+
130
+ await page.goto('about:blank');
131
+
132
+ switch (data.mode) {
133
+ case "turnstile":
134
+ result = await turnstile(data, page).then(t => ({ token: t }));
135
+ break;
136
+
137
+ case "iuam":
138
+ result = await cloudflare(data, page).then(r => ({ ...r }));
139
+ writeCache(cacheKey, result);
140
+ break;
141
+
142
+ case "antibot":
143
+ result = await antibot(data);
144
+ break;
145
+
146
+ default:
147
+ result = { code: 400, message: 'Invalid mode' };
148
+ }
149
+ } catch (err) {
150
+ result = { code: 500, message: err.message };
151
+ } finally {
152
+ if (browser) try { await browser.close(); } catch {}
153
+ global.browserLimit++;
154
+ }
155
+
156
+ res.status(result.code ?? 200).json(result);
157
+ });
158
+
159
+ app.post("/antibot", async (req, res) => {
160
+ const data = req.body;
161
+
162
+ if (!data || !data.main || !Array.isArray(data.bots))
163
+ return res.status(400).json({ message: "Invalid body" });
164
+
165
+ try {
166
+ const result = await antibot(data);
167
+ res.json(result);
168
+ } catch (err) {
169
+ res.status(500).json({ message: err.message });
170
+ }
171
+ });
172
+
173
+ app.use((req, res) => {
174
+ res.status(404).json({ message: 'Not Found' });
175
+ });
176
+
177
+ if (process.env.NODE_ENV === 'development') {
178
+ module.exports = app;
179
+ }
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
+ }