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
e7ba2ed7
Commit
e7ba2ed7
authored
Aug 13, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.mycard.moe:mycard/network
parents
8bc7c4f8
026fb8f2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
7 deletions
+21
-7
package-lock.json
package-lock.json
+10
-0
package.json
package.json
+2
-0
src/inventory.ts
src/inventory.ts
+9
-7
No files found.
package-lock.json
View file @
e7ba2ed7
...
...
@@ -17,6 +17,11 @@
"resolved"
:
"https://registry.npmjs.org/@types/lodash/-/lodash-4.14.149.tgz"
,
"integrity"
:
"sha512-ijGqzZt/b7BfzcK9vTrS6MFljQRPn5BFWOx8oE0GYxribu6uV+aA9zZuXI1zc/etK9E8nrgdoF2+LgUw7+9tJQ=="
},
"@types/mustache"
:
{
"version"
:
"4.1.1"
,
"resolved"
:
"https://registry.npmjs.org/@types/mustache/-/mustache-4.1.1.tgz"
,
"integrity"
:
"sha512-Sm0NWeLhS2QL7NNGsXvO+Fgp7e3JLHCO6RS3RCnfjAnkw6Y1bsji/AGfISdQZDIR/AeOyzkrxRk9jBkl55zdJw=="
},
"@types/node"
:
{
"version"
:
"13.7.0"
,
"resolved"
:
"https://registry.npmjs.org/@types/node/-/node-13.7.0.tgz"
,
...
...
@@ -61,6 +66,11 @@
"integrity"
:
"sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g=="
,
"dev"
:
true
},
"mustache"
:
{
"version"
:
"4.2.0"
,
"resolved"
:
"https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz"
,
"integrity"
:
"sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ=="
},
"source-map"
:
{
"version"
:
"0.6.1"
,
"resolved"
:
"https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz"
,
...
...
package.json
View file @
e7ba2ed7
...
...
@@ -10,9 +10,11 @@
"dependencies"
:
{
"
@types/ip
"
:
"
^1.1.0
"
,
"
@types/lodash
"
:
"
^4.14.149
"
,
"
@types/mustache
"
:
"
^4.1.1
"
,
"
csv-parse
"
:
"
^4.8.5
"
,
"
ip
"
:
"
^1.1.5
"
,
"
lodash
"
:
"
^4.17.15
"
,
"
mustache
"
:
"
^4.2.0
"
,
"
yaml
"
:
"
^1.10.0
"
},
"devDependencies"
:
{
...
...
src/inventory.ts
View file @
e7ba2ed7
...
...
@@ -17,7 +17,7 @@ async function generateOcpasswdLine(username: string, password: string) {
return
res
;
}
interface
GatewayGroup
{
interface
GatewayGroup
extends
Record
<
string
,
any
>
{
id
:
number
;
name
:
string
;
locationPrefix
:
string
;
...
...
@@ -27,15 +27,17 @@ interface GatewayGroup {
destMark
:
number
;
}
type
CommonEntry
=
Record
<
string
,
any
>
;
class
InventoryBuilder
{
hosts
:
{
[
key
:
string
]:
an
y
};
gateways
:
any
;
hosts
:
{
[
key
:
string
]:
CommonEntr
y
};
gateways
:
Record
<
string
,
CommonEntry
>
;
gatewayGroups
:
GatewayGroup
[];
connections
:
string
[];
routeLists
:
any
;
routeLists
:
Record
<
string
,
string
[]
>
;
resolveCache
:
Map
<
string
,
string
>
;
resolver
:
dns
.
Resolver
;
vars
:
an
y
;
vars
:
CommonEntr
y
;
linksOnly
:
string
[];
linksLimit
:
string
[];
...
...
@@ -78,7 +80,7 @@ class InventoryBuilder {
return
resolvedIP
;
}
async
load
(
sheetName
:
string
)
{
async
load
(
sheetName
:
string
)
:
Promise
<
Record
<
string
,
any
>
[]
>
{
const
data
=
await
fs
.
promises
.
readFile
(
path
.
join
(
'
data
'
,
`内网互联计划 -
${
sheetName
}
.csv`
));
// @ts-ignore
return
(
await
util
.
promisify
(
parse
)(
data
,
{
columns
:
true
,
cast
:
true
})).
filter
(
h
=>
h
.
id
);
...
...
@@ -101,7 +103,7 @@ class InventoryBuilder {
async
main
()
{
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
'
);
this
.
gatewayGroups
=
await
this
.
load
(
'
gateway groups
'
)
as
GatewayGroup
[]
;
//console.log(this.gateways);
this
.
connections
=
_
.
intersection
(
Object
.
keys
(
this
.
hosts
),
Object
.
keys
(
_
.
find
(
this
.
hosts
)));
...
...
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