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
6d6295ae
Commit
6d6295ae
authored
Feb 12, 2020
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
frp
parent
35f83424
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
4 deletions
+26
-4
ansible/bird.conf.j2
ansible/bird.conf.j2
+1
-1
ansible/protocols/ipip/wg.yaml
ansible/protocols/ipip/wg.yaml
+1
-1
ansible/protocols/wg/wg.yaml
ansible/protocols/wg/wg.yaml
+0
-1
src/inventory.ts
src/inventory.ts
+24
-1
No files found.
ansible/bird.conf.j2
View file @
6d6295ae
...
...
@@ -51,7 +51,7 @@ protocol ospf v2 {
{% if connection.outbound %}
cost {{connection.metric}};
{% else %}
cost
99999
;
cost
65535
;
{% endif %}
hello 5;
};
...
...
ansible/protocols/ipip/wg.yaml
View file @
6d6295ae
...
...
@@ -6,4 +6,4 @@
systemd
:
name
:
'
wg-quick@{{conn.name}}'
state
:
started
enabled
:
yes
\ No newline at end of file
enabled
:
yes
ansible/protocols/wg/wg.yaml
View file @
6d6295ae
...
...
@@ -13,4 +13,3 @@
name
:
'
wg-quick@{{conn.name}}'
state
:
started
enabled
:
yes
src/inventory.ts
View file @
6d6295ae
...
...
@@ -4,7 +4,8 @@ import fs from 'fs';
import
path
from
'
path
'
;
import
YAML
from
'
yaml
'
;
import
_
from
'
lodash
'
;
import
*
as
child_process
from
'
child_process
'
;
import
child_process
from
'
child_process
'
;
import
assert
from
'
assert
'
;
class
InventoryBuilder
{
hosts
:
{
[
key
:
string
]:
any
};
...
...
@@ -53,6 +54,8 @@ class InventoryBuilder {
ansible_ssh_user
:
host
.
user
,
address
:
host
.
address
,
key
:
host
.
wgPrivateKey
,
frpsPort
:
host
.
frpsPort
,
frpToken
:
host
.
frpToken
,
gateways
:
_
.
mapValues
(
this
.
gateways
[
host
.
name
],
gw
=>
_
.
pick
(
gw
,
[
'
mark_gateway
'
])),
connections
};
...
...
@@ -76,9 +79,13 @@ class InventoryBuilder {
const
remoteMark
=
remote
.
mark
;
const
localPort
=
primary
?
remote
.
port
:
remote
.
port2
;
const
remotePort
=
primary
?
local
.
port
:
local
.
port2
;
const
remoteFrpsPort
=
remote
.
frpsPort
;
const
wgPublicKey
=
remote
.
wgPublickey
;
const
localPeerAddress
=
primary
?
`10.200.
${
local
.
id
}
.
${
remote
.
id
}
`
:
`10.201.
${
local
.
id
}
.
${
remote
.
id
}
`
;
const
remotePeerAddress
=
primary
?
`10.200.
${
remote
.
id
}
.
${
local
.
id
}
`
:
`10.201.
${
remote
.
id
}
.
${
local
.
id
}
`
;
const
frpType
=
protocol
===
'
frp
'
?
(
this
.
gatewayCompare
(
local
,
remote
)
?
'
frps
'
:
'
frpc
'
)
:
undefined
;
return
{
name
,
metric
,
...
...
@@ -92,11 +99,27 @@ class InventoryBuilder {
wgPublicKey
,
localPeerAddress
,
remotePeerAddress
,
remoteFrpsPort
,
frpType
,
inbound
,
outbound
};
}
// true: 本地做 server,false: 远端做server
// 如果都不能做,抛异常
// 两个参数对调返回的结果必须相反
gatewayCompare
(
localGateway
:
any
,
remoteGateway
:
any
):
boolean
{
// 两边至少一个静态地址才能连
assert
(
localGateway
.
ipv4
===
'
static
'
||
remoteGateway
.
ipv4
===
'
static
'
);
// 如果都static,就让列表中更靠前的做s
if
(
localGateway
.
ipv4
==
remoteGateway
.
ipv4
)
{
return
localGateway
.
id
<
remoteGateway
.
id
;
}
else
{
return
localGateway
.
ipv4
===
'
static
'
;
}
}
async
wgPublickey
(
privateKey
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
child
=
child_process
.
execFile
(
'
wg
'
,
[
'
pubkey
'
],
{
encoding
:
'
utf8
'
},
(
error
,
stdout
,
stderr
)
=>
{
...
...
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