import { Document, parseDocument } from "yaml" import fs from "fs" import axios from "axios" import * as randomstring from "randomstring" import { bridges } from "./bridges.js" const country = "US" const groupSize = 1 const proxyNumEachGroup = 2 const nets = [ { router: "192.168.6.1", subnets: ["192.168.10"] }, { router: "192.168.7.1", subnets: ["192.168.11", "192.168.12"] }, { router: "192.168.8.1", subnets: ["192.168.13", "192.168.14"] } ] const { data: template, config } = await axios.get( "http://192.168.50.47:25500/sub", { params: { target: "clash", url: "http://192.168.50.46:3000/download/collection/all?target=ClashMeta", insert: false, config: "https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_NoAuto.ini", emoji: true, list: false, xudp: false, udp: false, tfo: false, expand: true, scv: true, fdn: false, new_name: true } } ) 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("unified-delay", true) const proxies = doc.get("proxies") const proxyGroups = doc.get("proxy-groups") 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: "gate1.ipweb.cc", port: 7778, username: `B_37678_${country}___5_${randomstring.generate( { length: 8, charset: "alphanumeric" } )}`, password: "123456", "dialer-proxy": bridge.name }, { 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.add(group) } rules.unshift( `SRC-IP-CIDR,${ip}/32,${proxyGroups .get(proxyGroups.items.length - 1) .get("name")}` ) }) rules = [ "DOMAIN-SUFFIX,izouma.com,DIRECT", "IP-CIDR,47.98.225.28/32,DIRECT", "IP-CIDR,8.149.128.251/32,DIRECT", "DOMAIN-SUFFIX,baidu.com,DIRECT", "DOMAIN-SUFFIX,aliyuncs.com,DIRECT" ].concat(rules) doc.set("rules", rules) fs.writeFileSync( `dist/${net.router}-${country}-IPWEB-${bridge.name}.yaml`, doc.toString({ lineWidth: 0 }) ) } }