File size: 4,068 Bytes
ce7ec8e | 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 | import express from "express";
import { request as httpRequest } from "http";
import { request as httpsRequest } from "https";
import { writeFileSync, readFileSync, existsSync, mkdirSync } from "fs";
const app = express();
app.use(express.json({ limit: "10mb" }));
app.use(express.urlencoded({ extended: true }));
const PORT = 7860;
const AUTH_TOKEN = process.env.MCP_AUTH_TOKEN || "chimera-secret-key-2026";
app.get("/", (req, res) => res.json({ status: "CHIMERA MCP SERVER ONLINE", version: "1.0.0", uptime: process.uptime() }));
app.get("/health", (req, res) => res.json({ status: "healthy", uptime: process.uptime() }));
app.get("/proxy", async (req, res) => {
try {
const { url, method, data, auth: a, ctype } = req.query;
if (!url) return res.status(400).json({ error: "Missing ?url=" });
const parsed = new URL(url);
const mod = parsed.protocol === "https:" ? httpsRequest : httpRequest;
const b = data || null;
const req2 = mod({ hostname: parsed.hostname, port: parsed.port || (parsed.protocol === "https:" ? 443 : 80), path: parsed.pathname + parsed.search, method: method || "POST", headers: { "Content-Type": ctype || "application/x-www-form-urlencoded", "Content-Length": b ? Buffer.byteLength(b) : undefined, ...(a ? { Authorization: "Bearer " + a } : {}) }, timeout: 30000 }, (r) => { let d = ""; r.on("data", c => d += c); r.on("end", () => { try { res.json({ status: r.statusCode, data: JSON.parse(d) }); } catch { res.json({ status: r.statusCode, data: d }); } }); });
req2.on("error", e => res.status(502).json({ error: e.message }));
req2.on("timeout", () => { req2.destroy(); res.status(504).json({ error: "timeout" }); });
if (b) req2.write(b);
req2.end();
} catch (err) { res.status(502).json({ error: "Proxy failed: " + err }); }
});
app.get("/5sim/buy", async (req, res) => {
try {
if (!req.query.token) return res.status(400).json({ error: "Missing ?token=" });
const parsed = new URL(`https://5sim.net/v1/user/buy/activation/${req.query.country||"usa"}/${req.query.operator||"any"}/${req.query.product||"7eleven"}`);
httpsRequest({ hostname: parsed.hostname, path: parsed.pathname, headers: { Authorization: "Bearer " + req.query.token } }, r => { let d = ""; r.on("data", c => d += c); r.on("end", () => { try { res.json(JSON.parse(d)); } catch { res.json({ raw: d }); } }); }).end();
} catch (err) { res.status(502).json({ error: "5sim failed: " + err }); }
});
app.get("/5sim/check", async (req, res) => {
try {
if (!req.query.token || !req.query.orderid) return res.status(400).json({ error: "Missing ?token= and ?orderid=" });
httpsRequest({ hostname: "5sim.net", path: "/v1/user/check/" + req.query.orderid, headers: { Authorization: "Bearer " + req.query.token } }, r => { let d = ""; r.on("data", c => d += c); r.on("end", () => { try { res.json(JSON.parse(d)); } catch { res.json({ raw: d }); } }); }).end();
} catch (err) { res.status(502).json({ error: "5sim check failed: " + err }); }
});
app.get("/apkx/download", async (req, res) => {
try {
if (!req.query.package) return res.status(400).json({ error: "Missing ?package=" });
const pkg = req.query.package;
const parsed = new URL("http://srv1497266.hstgr.cloud:9090/download");
const body = "package=" + encodeURIComponent(pkg) + "&source=apk-pure&apply_mitm=true&generate_report=true";
const req2 = httpRequest({ hostname: parsed.hostname, port: 9090, path: "/download", method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded", "Content-Length": Buffer.byteLength(body) }, timeout: 60000 }, r => { let d = ""; r.on("data", c => d += c); r.on("end", () => { try { res.json({ status: r.statusCode, data: JSON.parse(d) }); } catch { res.json({ status: r.statusCode, raw: d }); } }); });
req2.on("error", e => res.status(502).json({ error: e.message }));
req2.write(body);
req2.end();
} catch (err) { res.status(502).json({ error: "apkX failed: " + err }); }
});
app.listen(PORT, "0.0.0.0", () => console.log("Chimera MCP Server v1.0 | :" + PORT)); |