Skip to content
This repository was archived by the owner on Nov 21, 2019. It is now read-only.

Commit fc2ceba

Browse files
author
icymind
committed
format firewall rules
1 parent c913ddb commit fc2ceba

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/renderer/lib/generator.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const os = require('os')
99
* 根据rule, 生成PREROUTING和OUTPUT两条iptables规则
1010
*/
1111
function genFWRulesHelper (rule) {
12-
return `iptables -t nat -A PREROUTING ${rule}\niptables -t nat -A OUTPUT ${rule}\n`
12+
return `iptables -t nat -A PREROUTING ${rule}\niptables -t nat -A OUTPUT ${rule}`
1313
}
1414

1515
async function genIPsetFileHelper (fPath, ipsetName) {
@@ -371,14 +371,14 @@ class Generator {
371371

372372
// if kcp protocol: speedup ssh
373373
if (/kt/ig.test(proxies) && profile.speedupServerSSH) {
374-
contents.push('# speedup server ssh connection')
374+
contents.push('\n# speedup server ssh connection')
375375
const rule = `-d ${profile.kcptun.server} -p tcp --dport ${profile.serverSSHPort} -j REDIRECT --to-port ${redirPort}`
376376
contents.push(genFWRulesHelper(rule))
377377
}
378378

379379
// bypass serverIPs
380380
// bypass shadowsocks server_ip
381-
contents.push('# bypass server ip')
381+
contents.push('\n# bypass server ip')
382382
const ips = []
383383
;/kt/ig.test(proxies) && ips.push(profile.kcptun.server)
384384
;/ssr/ig.test(proxies) && ips.push(profile.shadowsocksr.server)
@@ -395,7 +395,7 @@ class Generator {
395395
}
396396

397397
// bypass lan_networks. 如果不想绕过lan, 生成一个空的lan ipset集合即可
398-
contents.push('# bypass lan networks')
398+
contents.push('\n# bypass lan networks')
399399
const rule = `-m set --match-set ${firewallInfo.ipset.lanSetName} dst -j RETURN`
400400
contents.push(genFWRulesHelper(rule))
401401
// bypass udp too
@@ -404,7 +404,7 @@ class Generator {
404404
// whitelist mode: bypass whitelist and route others
405405
if (profile.mode === 'whitelist') {
406406
// "绕过白名单"模式下, 先将黑名单导向代理(如果自定义黑名单中存在白名单相同项, 先处理黑名单符合预期)
407-
contents.push('# route all blacklist traffic')
407+
contents.push('\n# route all blacklist traffic')
408408
let rule = `-p tcp -m set --match-set ${firewallInfo.ipset.blackSetName} dst -j REDIRECT --to-port ${redirPort}`
409409
contents.push(genFWRulesHelper(rule))
410410

@@ -414,11 +414,11 @@ class Generator {
414414
contents.push(`iptables -t mangle -A PREROUTING -p udp -m set --match-set ${firewallInfo.ipset.blackSetName} dst -j TPROXY --on-port ${udpRedirPort} --tproxy-mark 0x01/0x01`)
415415
}
416416

417-
contents.push('# bypass whitelist')
417+
contents.push('\n# bypass whitelist')
418418
rule = `-m set --match-set ${firewallInfo.ipset.whiteSetName} dst -j RETURN`
419419
contents.push(genFWRulesHelper(rule))
420420

421-
contents.push('# route all other traffic')
421+
contents.push('\n# route all other traffic')
422422
rule = `-p tcp -j REDIRECT --to-port ${redirPort}`
423423
contents.push(genFWRulesHelper(rule))
424424

@@ -427,11 +427,11 @@ class Generator {
427427
}
428428
} else if (profile.mode === 'blacklist') {
429429
// 仅代理黑名单模式下, 先将白名单返回(如果自定义白名单中存在黑名单相同项, 先处理白名单符合预期)
430-
contents.push('# bypass whitelist')
430+
contents.push('\n# bypass whitelist')
431431
let rule = `-m set --match-set ${firewallInfo.ipset.whiteSetName} dst -j RETURN`
432432
contents.push(genFWRulesHelper(rule))
433433

434-
contents.push('# route all blacklist traffic')
434+
contents.push('\n# route all blacklist traffic')
435435
rule = `-p tcp -m set --match-set ${firewallInfo.ipset.blackSetName} dst -j REDIRECT --to-port ${redirPort}`
436436
contents.push(genFWRulesHelper(rule))
437437

@@ -441,7 +441,7 @@ class Generator {
441441
contents.push(`iptables -t mangle -A PREROUTING -p udp -m set --match-set ${firewallInfo.ipset.blackSetName} dst -j TPROXY --on-port ${udpRedirPort} --tproxy-mark 0x01/0x01`)
442442
}
443443
} else if (profile.mode === 'global') {
444-
contents.push('# route all traffic')
444+
contents.push('\n# route all traffic')
445445
let rule = `-p tcp -j REDIRECT --to-port ${redirPort}`
446446
contents.push(genFWRulesHelper(rule))
447447

0 commit comments

Comments
 (0)