Spaces:
Paused
Paused
Upload 3 files
Browse files- Dockerfile +39 -0
- index.js +99 -0
- package.json +13 -0
Dockerfile
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:20-slim
|
| 2 |
+
|
| 3 |
+
# Maktaba za mfumo zinazohitajika na Chromium ya Puppeteer
|
| 4 |
+
RUN apt-get update && apt-get install -y \
|
| 5 |
+
ca-certificates \
|
| 6 |
+
fonts-liberation \
|
| 7 |
+
libasound2 \
|
| 8 |
+
libatk-bridge2.0-0 \
|
| 9 |
+
libatk1.0-0 \
|
| 10 |
+
libcups2 \
|
| 11 |
+
libdbus-1-3 \
|
| 12 |
+
libdrm2 \
|
| 13 |
+
libgbm1 \
|
| 14 |
+
libgtk-3-0 \
|
| 15 |
+
libnspr4 \
|
| 16 |
+
libnss3 \
|
| 17 |
+
libxcomposite1 \
|
| 18 |
+
libxdamage1 \
|
| 19 |
+
libxfixes3 \
|
| 20 |
+
libxkbcommon0 \
|
| 21 |
+
libxrandr2 \
|
| 22 |
+
xdg-utils \
|
| 23 |
+
wget \
|
| 24 |
+
--no-install-recommends \
|
| 25 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 26 |
+
|
| 27 |
+
WORKDIR /app
|
| 28 |
+
|
| 29 |
+
COPY package.json ./
|
| 30 |
+
RUN npm install
|
| 31 |
+
|
| 32 |
+
COPY index.js ./
|
| 33 |
+
|
| 34 |
+
# Puppeteer inapakua Chromium yake yenyewe wakati wa npm install
|
| 35 |
+
# (PUPPETEER_SKIP_CHROMIUM_DOWNLOAD haijawekwa, kwa hiyo default
|
| 36 |
+
# inapakua binary sahihi kwa mfumo huu).
|
| 37 |
+
|
| 38 |
+
EXPOSE 7860
|
| 39 |
+
CMD ["node", "index.js"]
|
index.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require('express');
|
| 2 |
+
const puppeteer = require('puppeteer');
|
| 3 |
+
|
| 4 |
+
const app = express();
|
| 5 |
+
const PORT = process.env.PORT || 7860;
|
| 6 |
+
|
| 7 |
+
const CHALLENGE_MARKERS = [
|
| 8 |
+
'checking your browser',
|
| 9 |
+
'cookies are not enabled',
|
| 10 |
+
'captcha',
|
| 11 |
+
'attention required',
|
| 12 |
+
'access denied',
|
| 13 |
+
'just a moment',
|
| 14 |
+
];
|
| 15 |
+
|
| 16 |
+
app.get('/', (req, res) => {
|
| 17 |
+
res.send(`
|
| 18 |
+
<h2>Jaribio la IP β Hugging Face Space vs InfinityFree</h2>
|
| 19 |
+
<p>Bofya link kujaribu:</p>
|
| 20 |
+
<ul>
|
| 21 |
+
<li><a href="/test?url=https://jaynes.freedev.app/api/content/channels">
|
| 22 |
+
/test?url=https://jaynes.freedev.app/api/content/channels
|
| 23 |
+
</a></li>
|
| 24 |
+
</ul>
|
| 25 |
+
<p>Au tumia query yako mwenyewe: <code>/test?url=...</code></p>
|
| 26 |
+
`);
|
| 27 |
+
});
|
| 28 |
+
|
| 29 |
+
app.get('/test', async (req, res) => {
|
| 30 |
+
const targetUrl = req.query.url || 'https://jaynes.freedev.app/api/content/channels';
|
| 31 |
+
|
| 32 |
+
let browser;
|
| 33 |
+
try {
|
| 34 |
+
browser = await puppeteer.launch({
|
| 35 |
+
headless: 'new',
|
| 36 |
+
args: [
|
| 37 |
+
'--no-sandbox',
|
| 38 |
+
'--disable-setuid-sandbox',
|
| 39 |
+
'--disable-dev-shm-usage',
|
| 40 |
+
],
|
| 41 |
+
});
|
| 42 |
+
|
| 43 |
+
const page = await browser.newPage();
|
| 44 |
+
await page.setUserAgent(
|
| 45 |
+
'Mozilla/5.0 (Linux; Android 11; SM-A125F) AppleWebKit/537.36 ' +
|
| 46 |
+
'(KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36'
|
| 47 |
+
);
|
| 48 |
+
|
| 49 |
+
const response = await page.goto(targetUrl, {
|
| 50 |
+
waitUntil: 'networkidle2',
|
| 51 |
+
timeout: 20000,
|
| 52 |
+
});
|
| 53 |
+
|
| 54 |
+
const bodyText = await page.evaluate(() => document.body.innerText);
|
| 55 |
+
const httpStatus = response ? response.status() : null;
|
| 56 |
+
|
| 57 |
+
let isValidJson = false;
|
| 58 |
+
try {
|
| 59 |
+
JSON.parse(bodyText);
|
| 60 |
+
isValidJson = true;
|
| 61 |
+
} catch (e) {
|
| 62 |
+
isValidJson = false;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
const lower = bodyText.toLowerCase();
|
| 66 |
+
const looksLikeChallenge = CHALLENGE_MARKERS.some((m) => lower.includes(m));
|
| 67 |
+
|
| 68 |
+
await browser.close();
|
| 69 |
+
|
| 70 |
+
let verdict;
|
| 71 |
+
if (isValidJson) {
|
| 72 |
+
verdict = 'IMEFANIKIWA β JSON halisi imepatikana. IP ya Space hii HAIJAZUIWA.';
|
| 73 |
+
} else if (looksLikeChallenge) {
|
| 74 |
+
verdict = 'IMEZUIWA β anti-bot challenge imeonekana. IP ya Space hii imezuiwa.';
|
| 75 |
+
} else {
|
| 76 |
+
verdict = 'HAIJULIKANI β si JSON, si challenge inayotambulika. Angalia "preview" hapo chini.';
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
res.json({
|
| 80 |
+
target_url: targetUrl,
|
| 81 |
+
http_status: httpStatus,
|
| 82 |
+
verdict,
|
| 83 |
+
is_valid_json: isValidJson,
|
| 84 |
+
looks_like_challenge: looksLikeChallenge,
|
| 85 |
+
body_preview: bodyText.slice(0, 1500),
|
| 86 |
+
});
|
| 87 |
+
} catch (err) {
|
| 88 |
+
if (browser) await browser.close().catch(() => {});
|
| 89 |
+
res.status(500).json({
|
| 90 |
+
target_url: targetUrl,
|
| 91 |
+
verdict: 'HITILAFU β ' + err.message,
|
| 92 |
+
error: err.message,
|
| 93 |
+
});
|
| 94 |
+
}
|
| 95 |
+
});
|
| 96 |
+
|
| 97 |
+
app.listen(PORT, () => {
|
| 98 |
+
console.log(`Jaribio la IP linaendesha kwenye port ${PORT}`);
|
| 99 |
+
});
|
package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "jaynes-ip-test",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"description": "Jaribio dogo: je IP ya Hugging Face Space inaweza kufikia jaynes.freedev.app bila kuzuiwa na anti-bot?",
|
| 5 |
+
"main": "index.js",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"start": "node index.js"
|
| 8 |
+
},
|
| 9 |
+
"dependencies": {
|
| 10 |
+
"express": "^4.19.2",
|
| 11 |
+
"puppeteer": "^22.15.0"
|
| 12 |
+
}
|
| 13 |
+
}
|