Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
tun
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
tun
Commits
e517a144
Commit
e517a144
authored
Aug 13, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update redirect
parent
aaee2431
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
10 deletions
+19
-10
ansible/scripts/switch-rules-up.sh.j2
ansible/scripts/switch-rules-up.sh.j2
+1
-1
ansible/scripts/utility.sh.j2
ansible/scripts/utility.sh.j2
+4
-3
src/inventory.ts
src/inventory.ts
+14
-6
No files found.
ansible/scripts/switch-rules-up.sh.j2
View file @
e517a144
...
...
@@ -18,7 +18,7 @@ interface_switch_china -A u_{{gw.isp}}_china {{gw.selectionMark}}
interface_switch_oversea
-A
u_
{{
gw.isp
}}
_oversea
{{
gw.selectionMark
}}
restore_mark_switch
-A
{{
gw.selectionMark
}}
{
% endif %
}
interface_switch_redirect
-A
{{
gw.selectionMark
}}
{{
gw.redirectPort
}}
interface_switch_redirect
-A
{{
gw.selectionMark
}}
{{
gw.redirect
Server
Port
}}
{
% endif %
}
{
% endfor %
}
...
...
ansible/scripts/utility.sh.j2
View file @
e517a144
...
...
@@ -71,7 +71,8 @@ interface_switch_oversea() {
interface_switch_redirect() {
OPTION=$1
MARK=$2
REDIR_PORT=$3
$IPTABLES_EXEC -t nat "$OPTION" NEXTGEN_SWITCH -m mark --mark $MARK -i mc+ -m set --match-set mycard src -m set ! --match-set mycard dst -p tcp -m multiport --dports 80,443,21,22,23,8080,8443 -j DNAT --to-destination {{address}}:$REDIR_PORT
$IPTABLES_EXEC -t nat "$OPTION" NEXTGEN_SWITCH -m mark --mark $MARK -i ocs+ -m set --match-set mycard src -m set ! --match-set mycard dst -p tcp -m multiport --dports 80,443,21,22,23,8080,8443 -j DNAT --to-destination {{address}}:$REDIR_PORT
REDIR_SERVER_PORT=$3
REDIR_TARGET_PORTS=$4
$IPTABLES_EXEC -t nat "$OPTION" NEXTGEN_SWITCH -m mark --mark $MARK -i mc+ -m set --match-set mycard src -m set ! --match-set mycard dst -p tcp -m multiport --dports $REDIR_TARGET_PORTS -m multiport ! --dports {{allRedirectServerPorts}} -j DNAT --to-destination {{address}}:$REDIR_PORT
$IPTABLES_EXEC -t nat "$OPTION" NEXTGEN_SWITCH -m mark --mark $MARK -i ocs+ -m set --match-set mycard src -m set ! --match-set mycard dst -p tcp -m multiport --dports $REDIR_TARGET_PORTS -m multiport ! --dports {{allRedirectServerPorts}} -j DNAT --to-destination {{address}}:$REDIR_PORT
}
src/inventory.ts
View file @
e517a144
...
...
@@ -102,19 +102,23 @@ class InventoryBuilder {
const
gateways
=
await
this
.
load
(
'
gateways2
'
);
for
(
let
gateway
of
gateways
)
{
gateway
.
isCN
=
this
.
hosts
[
gateway
.
router
]
&&
this
.
hosts
[
gateway
.
router
].
location
.
startsWith
(
'
CN
'
);
gateway
.
hidden
=
!!
gateway
.
hidden
;
for
(
const
boolField
of
[
'
hidden
'
,
'
redirectAllPorts
'
])
{
gateway
[
boolField
]
=
!!
gateway
[
boolField
]
}
if
(
gateway
.
mark
)
{
gateway
.
selectionMark
=
gateway
.
mark
+
50
;
gateway
.
redirectPort
=
gateway
.
mark
+
60000
;
gateway
.
redirect
Server
Port
=
gateway
.
mark
+
60000
;
}
else
{
gateway
.
selectionMark
=
0
;
gateway
.
redirectPort
=
60100
;
gateway
.
redirect
Server
Port
=
60100
;
}
gateway
.
redirectTargetPorts
=
gateway
.
redirectAllPorts
?
'
1:65535
'
:
this
.
vars
.
redirectTargetPorts
.
replace
(
/-/g
,
'
:
'
);
}
return
gateways
;
}
async
main
()
{
this
.
vars
=
await
this
.
loadUtilities
();
this
.
hosts
=
_
.
keyBy
(
await
this
.
load
(
'
nextgen2
'
),
'
name
'
);
this
.
gateways
=
_
.
mapValues
(
_
.
groupBy
(
await
this
.
loadGateways
(),
'
router
'
),
g
=>
_
.
keyBy
(
g
,
'
isp
'
));
this
.
gatewayGroups
=
await
this
.
load
(
'
gateway groups
'
)
as
GatewayGroup
[];
...
...
@@ -139,7 +143,6 @@ class InventoryBuilder {
if
(
process
.
env
.
LIMIT_LINKS
)
{
this
.
linksLimit
=
process
.
env
.
LIMIT_LINKS
.
split
(
"
,
"
);
}
this
.
vars
=
await
this
.
loadUtilities
();
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));
...
...
@@ -263,13 +266,17 @@ class InventoryBuilder {
};
}
const
redirectAvailableGateways
=
Object
.
values
(
this
.
gateways
[
host
.
name
]).
filter
(
gateway
=>
!
gateway
.
hidden
);
const
gostConfig
:
GostConfig
=
{
Routes
:
Object
.
values
(
this
.
gateways
[
host
.
name
]).
filter
(
gateway
=>
!
gateway
.
hidden
)
.
map
(
gateway
=>
({
ServeNodes
:
[
`red://
${
host
.
address
}
:
${
gateway
.
redirectPort
}
`
],
Routes
:
redirectAvailableGateways
.
map
(
gateway
=>
({
ServeNodes
:
[
`red://
${
host
.
address
}
:
${
gateway
.
redirect
Server
Port
}
`
],
Mark
:
gateway
.
selectionMark
as
number
,
}))
};
const
allRedirectServerPorts
=
redirectAvailableGateways
.
map
(
gateway
=>
gateway
.
redirectServerPort
).
join
(
'
,
'
);
if
(
gostConfig
.
Routes
.
length
)
{
host
.
gostConfig
=
gostConfig
;
host
.
dockerServices
.
services
.
gost
=
{
...
...
@@ -355,6 +362,7 @@ class InventoryBuilder {
iptables_type
:
host
.
iptables
||
'
auto
'
,
gostConfig
,
installGost
:
!!
gostConfig
,
allRedirectServerPorts
,
};
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment