Commit 62af34a4 authored by nanahira's avatar nanahira

add protosOnly

parent c90f3e56
......@@ -9,6 +9,7 @@ import assert from 'assert';
import { promises as dns } from 'dns';
import os from 'os';
import { getRules } from 'ip-pcc';
import { Rule } from 'ip-pcc/dist/src';
async function generateOcpasswdLine(username: string, password: string) {
const tmpName = os.tmpdir() + '/' + Math.floor(Math.random() * 10000000);
......@@ -45,7 +46,7 @@ type CommonEntry = Record<string, any>;
interface Gateway {
[key: string]: any;
pccWeight?: number;
pccRules?: string[];
pccRules?: Rule[];
noOut: boolean;
hidden: boolean;
redirectAllPorts: boolean;
......@@ -53,7 +54,7 @@ interface Gateway {
class InventoryBuilder {
hosts: { [key: string]: CommonEntry };
gateways: Record<string, Gateway>;
gateways: Record<string, Record<string, Gateway>>;
gatewayGroups: GatewayGroup[];
connections: string[];
routeLists: Record<string, string[]>;
......@@ -62,6 +63,7 @@ class InventoryBuilder {
vars: CommonEntry;
linksOnly: string[];
linksLimit: string[];
protosOnly: string[];
constructor() {
this.resolveCache = new Map();
......@@ -163,6 +165,7 @@ class InventoryBuilder {
router.subnets = subnets.filter((subnet) => subnet.router === name).map((subnet) => subnet.subnet);
}
this.vars = await this.loadUtilities();
// @ts-ignore
this.gateways = _.mapValues(_.groupBy(await this.loadGateways(), 'router'), g => _.keyBy(g, 'isp'));
this.gatewayGroups = await this.load('gateway groups') as GatewayGroup[];
//console.log(this.gateways);
......@@ -178,6 +181,9 @@ class InventoryBuilder {
if (process.env.LIMIT_LINKS) {
this.linksLimit = process.env.LIMIT_LINKS.split(",");
}
if (process.env.ONLY_PROTOS) {
this.protosOnly = process.env.ONLY_PROTOS.split(",");
}
const inventoryValue = { wg: { hosts: Object.fromEntries(Object.values(this.hosts).map(host => [host.name, this.getHostConnectionInfo(host)])) } };
await fs.promises.writeFile('result/inventory.yaml', YAML.stringify(inventoryValue));
// console.log(Object.values(this.hosts));
......@@ -479,7 +485,7 @@ class InventoryBuilder {
const frpType = protocol === 'wgfrp' ? (this.gatewayCompare(localGateway, remoteGateway) ? 'frps' : 'frpc') : undefined;
const ocType = protocol === 'oc' ? (this.gatewayCompareOcserv(local, remote, localGateway, remoteGateway) ? 'server' : 'client') : undefined;
const noUpdate = this.linksOnly && !(this.linksOnly.includes(remote.name) || this.linksOnly.includes(local.name)) || this.linksLimit && !(this.linksLimit.includes(remote.name) && this.linksLimit.includes(local.name));
const noUpdate = this.linksOnly && !(this.linksOnly.includes(remote.name) || this.linksOnly.includes(local.name)) || this.linksLimit && !(this.linksLimit.includes(remote.name) && this.linksLimit.includes(local.name)) || this.protosOnly && !this.protosOnly.includes(protocol);
if (frpType === 'frps' && !local.dockerServices.services.frps) {
local.frpsNeeded = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment