Commit 2e919a0b authored by nanahira's avatar nanahira

implant of ladder

parent 43df9b4e
......@@ -107,6 +107,9 @@ dist
.vscode-test
/data/
/result/
/lists/chnroutes*
/lists/gfwiplist*
/lists/result.yaml
*.retry
*-setconf.conf.j2
......
......@@ -46,40 +46,26 @@ protocol kernel {
{% endif %}
{% endfor %}
ipv4 table gfwiplist;
ipv4 table chnroute_reverse;
{% for net in gfwiplist %}
protocol static {
ipv4 {
table gfwiplist;
};
igp table master4;
route {{net}} recursive 10.199.0.12;
}
{% endfor %}
{% for net in chnroute_reverse %}
{% for plan in route_tables %}
ipv4 table {{plan.name}};
{% for net in plan.list %}
protocol static {
ipv4 {
table chnroute_reverse;
table {{plan.name}};
};
igp table master4;
route {{net}} recursive 10.199.0.12;
route {{net}} recursive {{plan.gatewayAddress}};
}
{% endfor %}
protocol kernel {
ipv4 {
table gfwiplist;
table {{plan.name}};
export all;
};
kernel table 401;
}
protocol kernel {
ipv4 {
table chnroute_reverse;
export all;
};
kernel table 402;
kernel table {{plan.table}};
}
{% endfor %}
protocol ospf v2 {
ipv4 {
......
#!/usr/bin/env python3
from netaddr import *
universe = IPSet(['0.0.0.0/0'])
special = IPSet([line.strip() for line in open('special.txt')])
chnroutes = IPSet([line.strip() for line in open('chnroutes.txt') if not line.startswith('#')])
result = universe - special - chnroutes
for network in result.iter_cidrs():
print(network)
#!/usr/bin/env python3
from netaddr import *
import yaml
def read_yaml_file(name):
file = open(name, 'r', encoding="utf-8")
data = yaml.load(file, Loader=yaml.SafeLoader)
file.close()
return data
def write_yaml_file(name, data):
file = open(name, 'w', encoding="utf-8")
yaml.dump(data, file)
file.close()
universe = IPSet(['0.0.0.0/0'])
special = IPSet([line.strip() for line in open('special.txt')])
chnroutes = IPSet([line.strip() for line in open('chnroutes.txt') if not line.startswith('#')])
gfwiplist = IPSet([line.strip() for line in open('gfwiplist.txt') if not line.startswith('#')])
result = {'chnroute_reverse': [], 'gfwiplist': []}
chnroute_reverse = universe - special - chnroutes
for route in chnroute_reverse.iter_cidrs():
result['chnroute_reverse'].append(str(route))
gfwiplist_patches = read_yaml_file('patch-gfwiplist.yaml')
gfwiplist_add = IPSet(gfwiplist_patches['add'])
gfwiplist_remove = IPSet(gfwiplist_patches['remove'])
gfwiplist_patched = (gfwiplist | gfwiplist_add) - gfwiplist_remove - special
for route in gfwiplist_patched.iter_cidrs():
result['gfwiplist'].append(str(route))
write_yaml_file("result.yaml", result)
......@@ -5,7 +5,12 @@ if [ -d "chnroutes2" ]; then
else
git clone https://github.com/misakaio/chnroutes2.git
fi
ln -sf chnroutes2/chnroutes.txt chnroutes.txt
if [ -d "gfwiplist" ]; then
(cd gfwiplist && git pull)
else
git clone https://github.com/SteamedFish/gfwiplist.git
fi
ln -sf gfwiplist/gfwiplist.txt gfwiplist.txt
#pip3 install -r requirements.txt
python3 reverse.py
python3 route_helper.py
......@@ -40,18 +40,26 @@ class InventoryBuilder {
// console.log(Object.values(this.hosts));
const hosts = Object.fromEntries(Object.values(this.hosts).map(h => [h.host, this.host_vars(h)]));
// console.log(hosts);
const vars = await this.loadUtilities();
const vars = await this.loadUtilities(hosts);
const result = YAML.stringify({ wg: { hosts, vars } });
return fs.promises.writeFile('result/inventory.yaml', result);
}
async loadUtilities() {
const raw_data = _.keyBy(await this.load('configurations'), 'key');
async loadUtilities(hosts) {
const raw_utility = _.keyBy(await this.load('configurations'), 'key');
let route_tables = await this.load('route tables')
const route_lists = YAML.parse(fs.readFileSync(path.join('lists', 'result.yaml'), "utf8"));
for (let plan of route_tables) {
plan.name = plan.list + "_" + plan.gateway.replace(/-/g, "_").split(".")[0]
plan.list = JSON.parse(JSON.stringify(route_lists[plan.list]));
plan.gatewayAddress = hosts[plan.gateway].address;
}
const vars = {
all_subnets: JSON.parse(JSON.stringify(this.all_subnets))
all_subnets: this.all_subnets,
route_tables
};
for (let col in raw_data) {
vars[col] = raw_data[col].value;
for (let col in raw_utility) {
vars[col] = raw_utility[col].value;
}
return vars;
......@@ -59,7 +67,7 @@ class InventoryBuilder {
host_vars(host) {
const connections = [];
const null_connection = "10000,null";
const lan_interfaces = host.lan_interfaces.split(",");
const lan_interfaces = host.lan_interfaces.length > 0 ? host.lan_interfaces.split(",") : [];
for (const h of this.connections) {
if (h != host.name) {
const to = host[h];
......
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