azizniiby commited on
Commit
56c4cfe
·
verified ·
1 Parent(s): bfb943b

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. Dockerfile +26 -0
  2. api_test.py +26 -0
  3. index.js +178 -0
  4. package.json +16 -0
Dockerfile ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM node:20-slim
2
+
3
+ RUN apt update && apt install -y \
4
+ wget gnupg ca-certificates xvfb \
5
+ fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 \
6
+ libatk1.0-0 libxss1 libnss3 libxcomposite1 libxdamage1 libxrandr2 libgbm1 \
7
+ && wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
8
+ && apt install -y ./google-chrome-stable_current_amd64.deb \
9
+ && rm google-chrome-stable_current_amd64.deb
10
+
11
+ WORKDIR /app
12
+
13
+ RUN mkdir -p /app/endpoints && \
14
+ mkdir -p /app/cache
15
+
16
+ COPY package*.json ./
17
+ RUN npm install
18
+
19
+ COPY . .
20
+
21
+ EXPOSE 7860
22
+
23
+ CMD rm -f /tmp/.X99-lock && \
24
+ Xvfb :99 -screen 0 1024x768x24 & \
25
+ export DISPLAY=:99 && \
26
+ 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,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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; // Set null biar gak perlu auth
9
+ const domain = process.env.DOMAIN || `https://azizniiby-cf.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());
50
+ app.use(express.urlencoded({ extended: true }));
51
+
52
+ // ROUTE UTAMA APP.GET("/")
53
+ app.get("/", (req, res) => {
54
+ res.json({
55
+ message: "Server is running!",
56
+ domain: domain,
57
+ endpoints: {
58
+ cloudflare: `${domain}/cloudflare`,
59
+ turnstile: `${domain}/cloudflare`,
60
+ recaptcha: `${domain}/cloudflare`
61
+ },
62
+ status: {
63
+ browserLimit: global.browserLimit,
64
+ timeOut: global.timeOut,
65
+ authRequired: authToken !== null
66
+ }
67
+ });
68
+ });
69
+
70
+ if (process.env.NODE_ENV !== 'development') {
71
+ let server = app.listen(port, () => {
72
+ console.log(`Server running on port ${port}`);
73
+ console.log(`Domain: ${domain}`);
74
+ console.log(`Auth required: ${authToken !== null}`);
75
+ });
76
+ try {
77
+ server.timeout = global.timeOut;
78
+ } catch {}
79
+ }
80
+
81
+ async function createBrowser(proxyServer = null) {
82
+ const connectOptions = {
83
+ headless: false,
84
+ turnstile: true,
85
+ connectOption: { defaultViewport: null },
86
+ disableXvfb: false,
87
+ };
88
+ if (proxyServer) connectOptions.args = [`--proxy-server=${proxyServer}`];
89
+
90
+ const { browser } = await connect(connectOptions);
91
+ const [page] = await browser.pages();
92
+
93
+ await page.goto('about:blank');
94
+ await page.setRequestInterception(true);
95
+ page.on('request', (req) => {
96
+ const type = req.resourceType();
97
+ if (["image", "stylesheet", "font", "media"].includes(type)) req.abort();
98
+ else req.continue();
99
+ });
100
+
101
+ return { browser, page };
102
+ }
103
+
104
+ const turnstile = require('./endpoints/turnstile');
105
+ const cloudflare = require('./endpoints/cloudflare');
106
+ const recaptchaV2 = require('./endpoints/recaptchav2');
107
+
108
+ app.post('/cloudflare', async (req, res) => {
109
+ const data = req.body;
110
+ if (!data || typeof data.mode !== 'string')
111
+ return res.status(400).json({ message: 'Bad Request: missing or invalid mode' });
112
+
113
+ // COMMENT/HAPUS pengecekan auth token biar gak perlu auth
114
+ // if (authToken && data.authToken !== authToken)
115
+ // return res.status(401).json({ message: 'Unauthorized' });
116
+
117
+ if (global.browserLimit <= 0)
118
+ return res.status(429).json({ message: 'Too Many Requests' });
119
+
120
+ let cacheKey, cached;
121
+ if (data.mode === "iuam" || data.mode === "recaptcha") {
122
+ cacheKey = JSON.stringify(data);
123
+ cached = readCache(cacheKey);
124
+ if (cached) return res.status(200).json({ ...cached, cached: true });
125
+ }
126
+
127
+ global.browserLimit--;
128
+ let result, browser;
129
+
130
+ try {
131
+ const proxyServer = data.proxy ? `${data.proxy.hostname}:${data.proxy.port}` : null;
132
+ const ctx = await createBrowser(proxyServer);
133
+ browser = ctx.browser;
134
+ const page = ctx.page;
135
+
136
+ await page.goto('about:blank');
137
+
138
+ switch (data.mode) {
139
+ case "turnstile":
140
+ result = await turnstile(data, page)
141
+ .then(token => ({ token }))
142
+ .catch(err => ({ code: 500, message: err.message }));
143
+ break;
144
+
145
+ case "iuam":
146
+ result = await cloudflare(data, page)
147
+ .then(r => ({ ...r }))
148
+ .catch(err => ({ code: 500, message: err.message }));
149
+ if (!result.code || result.code === 200) writeCache(cacheKey, result);
150
+ break;
151
+
152
+ case "recaptcha":
153
+ result = await recaptchaV2(data, page)
154
+ .then(r => ({ ...r }))
155
+ .catch(err => ({ code: 500, message: err.message }));
156
+ if (!result.code || result.code === 200) writeCache(cacheKey, result);
157
+ break;
158
+
159
+ default:
160
+ result = { code: 400, message: 'Invalid mode' };
161
+ }
162
+ } catch (err) {
163
+ result = { code: 500, message: err.message };
164
+ } finally {
165
+ if (browser) try { await browser.close(); } catch {}
166
+ global.browserLimit++;
167
+ }
168
+
169
+ res.status(result.code ?? 200).json(result);
170
+ });
171
+
172
+ app.use((req, res) => {
173
+ res.status(404).json({ message: 'Not Found' });
174
+ });
175
+
176
+ if (process.env.NODE_ENV === 'development') {
177
+ module.exports = app;
178
+ }
package.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "puppeteer-real-browser": "^1.4.0"
12
+ },
13
+ "devDependencies": {
14
+ "nodemon": "^3.1.10"
15
+ }
16
+ }