import { Document, parseDocument } from "yaml" import fs from "fs" import axios from "axios" import * as randomstring from "randomstring" import { bridges } from "./bridges.js" import { commonRules } from "./rules.js" const country = "US" const groupSize = 1 const proxyNumEachGroup = 2 const bridge = bridges[0] const nets = [ { router: "10.2.100.1", subnets: ["10.2.100"] }, { router: "10.2.101.1", subnets: ["10.2.101"] }, { router: "10.2.102.1", subnets: ["10.2.102"] } ] const { data: { data: countryList } } = await axios.get("http://admin.uipoxy.com/proxy/web/map/countryList", { params: { page: 1, limit: 1000 } }) const template = fs.readFileSync(`dist/sub-vn.yaml`, "utf-8") let countryId = countryList.find(i => i.abbr === country)?.id for (let bridge of bridges) { for (let net of nets) { const ips = net.subnets.flatMap(subnet => { return Array.from({ length: 200 }, (_, i) => `${subnet}.${i + 50}`) }) const doc = parseDocument(template) doc.set("dns", { nameserver: ["8.8.8.8", "114.114.114.114"], "proxy-server-nameserver": ["8.8.8.8"], "use-hosts": true, "default-nameserver": ["8.8.8.8", "114.114.114.114"] }) doc.set("hosts", { "zipfile.mesgity.top": "154.21.92.47" }) doc.set("unified-delay", true) const proxies = doc.get("proxies") const proxyGroups = [] doc.set("proxy-groups", proxyGroups) let rules = doc.get("rules").items proxies.add(doc.createNode(bridge, { flow: true })) let c = 0, g = 0 ips.forEach((ip, i) => { if (i % groupSize === 0) { const groupProxies = Array.from( { length: proxyNumEachGroup }, (_, j) => { const p = doc.createNode( { name: `${country}-${++c}`, type: "socks5", server: "adv1.uipoxy.com", port: 3000, username: `haoge11_${countryId}_0_0_10_${randomstring.generate({ length: 8, charset: "alphanumeric" })}_5_1`, password: "qaz112211", "dialer-proxy": bridge.name, udp: true }, { flow: true } ) proxies.add(p) return p } ) const group = doc.createNode( { name: `${country}-GROUP-${++g}`, type: "url-test", url: "http://www.gstatic.com/generate_204", interval: 150, tolerance: 50, proxies: groupProxies.map(p => p.get("name")) }, { flow: true } ) proxyGroups.push(group) } rules.unshift( `SRC-IP-CIDR,${ip}/32,${proxyGroups[proxyGroups.length - 1].get("name")}` ) }) rules = commonRules .map(r => r.replace("$bridge", bridge.name)) .concat(rules) doc.set("rules", rules) fs.writeFileSync( `dist/${net.router}-${country}-IPMOYU-${bridge.name}.yaml`, doc.toString({ lineWidth: 0 }) ) } } const doc = parseDocument(template) doc.set("unified-delay", true) const proxies = doc.get("proxies") proxies.add(doc.createNode(bridge, { flow: true })) countryList .filter(country => country.abbr && country.abbr !== "-") .sort((a, b) => a.abbr.localeCompare(b.abbr)) .forEach((country, i) => { const p = doc.createNode( { name: `${country.abbr}-${country.chnName}`, type: "socks5", server: "adv1.uipoxy.com", port: 3000, username: `haoge11_${country.id}_0_0_10_${randomstring.generate({ length: 8, charset: "alphanumeric" })}_5_1`, password: "qaz112211", udp: true }, { flow: true } ) proxies.add(p) }) fs.writeFileSync(`dist/IPMOYU-GLOBAL.yaml`, doc.toString({ lineWidth: 0 }))