Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
Hetzner-NewGeneration
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Hetzner-NewGeneration
Commits
aeac12d1
Commit
aeac12d1
authored
Apr 28, 2020
by
Ahmad Nemati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
79fcb898
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
147 additions
and
0 deletions
+147
-0
app2.js
app2.js
+147
-0
No files found.
app2.js
0 → 100644
View file @
aeac12d1
let
groups
=
0
let
generation
=
1
const
express
=
require
(
'
express
'
)
const
app
=
express
()
const
port
=
3000
const
shell
=
require
(
'
shelljs
'
)
const
cron
=
require
(
'
node-cron
'
);
let
Hetzner
=
require
(
'
./Hetzner
'
)
const
cronRemover
=
require
(
'
node-cron
'
);
const
cronRemover2
=
require
(
'
node-cron
'
);
let
_
=
require
(
'
lodash
'
)
const
request
=
require
(
'
request
'
);
const
fs
=
require
(
'
fs
'
)
const
cronSpeed
=
require
(
'
node-cron
'
);
const
shellExec
=
require
(
'
shell-exec
'
)
var
decimalPointRegex
=
/
\-?\d
+
\.\d
+/g
;
let
het
app
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
res
.
send
(
'
Hello World!
'
)
run
()
})
const
cryptLib
=
require
(
'
@skavinvarnan/cryptlib
'
);
const
key
=
"
6*sN_rZxHD4!X$=T
"
;
app
.
get
(
'
/ip/:ip/
'
,
(
req
,
res
)
=>
{
// console.log(req.params.acc)
return
addNewIp
(
req
,
res
)
})
app
.
get
(
'
/test
'
,
(
req
,
res
)
=>
{
// console.log(req.params.acc)
res
.
sendfile
(
'
jetmtp.png
'
)
})
app
.
listen
(
port
,
()
=>
console
.
log
(
`Example app listening on port
${
port
}
!`
))
postRequest
()
cronRemover
.
schedule
(
'
*/1 * * * *
'
,
()
=>
{
init
()
});
async
function
init
()
{
await
addIp
()
}
function
postRequest
()
{
let
data
=
{
generation
:
generation
,
groups
:
groups
}
data
=
JSON
.
stringify
(
data
)
data
=
cryptLib
.
encryptPlainTextWithRandomIV
(
data
,
key
)
var
options
=
{
method
:
'
POST
'
,
url
:
'
http://admin.fcfglobal.co:3000/addIp
'
,
headers
:
{
'
content-type
'
:
'
application/x-www-form-urlencoded
'
},
body
:
'
data=
'
+
Buffer
.
from
(
data
).
toString
(
'
base64
'
)
};
return
new
Promise
(
function
(
resolve
,
reject
)
{
request
(
options
,
function
(
error
,
response
,
body
)
{
if
(
error
)
console
.
log
(
error
)
resolve
(
true
)
});
});
}
function
addIp
()
{
const
request
=
require
(
'
request
'
);
let
url
=
'
http://admin.fcfglobal.co:3000/add/
'
return
new
Promise
(
function
(
resolve
,
reject
)
{
request
(
url
,
{
timeout
:
15000
},
function
(
error
,
res
,
body
)
{
resolve
(
body
)
});
});
}
async
function
calculateSpeed
()
{
let
d
=
await
shellExec
(
'
vnstat -i ens3 -tr
'
)
d
=
d
.
stdout
let
arr
=
d
.
match
(
decimalPointRegex
)
if
(
d
.
includes
(
'
kbit/s
'
))
{
arr
[
0
]
=
1
arr
[
1
]
=
1
}
else
if
(
d
.
includes
(
'
Mbit/s
'
))
{
}
else
if
(
d
.
includes
(
'
Gbit/s
'
))
{
arr
[
0
]
=
arr
[
0
]
*
1000
arr
[
1
]
=
arr
[
1
]
*
1000
}
else
if
(
d
.
includes
(
'
bit/s
'
))
{
arr
[
0
]
=
1
arr
[
1
]
=
1
}
await
sendRate
(
arr
[
0
],
arr
[
1
])
}
function
sendRate
(
rx
,
tx
)
{
const
request
=
require
(
'
request
'
);
let
url
=
'
http://admin.fcfglobal.co:3000/rate/
'
+
rx
+
'
/
'
+
tx
return
new
Promise
(
function
(
resolve
,
reject
)
{
request
(
url
,
{
timeout
:
6000
},
function
(
error
,
res
,
body
)
{
resolve
(
true
)
});
});
}
cronSpeed
.
schedule
(
'
*/5 * * * * *
'
,
()
=>
{
calculateSpeed
()
});
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