Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rt2-main
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
rt2-main
Commits
3eed624c
Commit
3eed624c
authored
Nov 10, 2020
by
Ahmad Nemati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
648edd5f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
4 deletions
+10
-4
app.js
app.js
+10
-4
No files found.
app.js
View file @
3eed624c
const
express
=
require
(
'
express
'
)
const
express
=
require
(
'
express
'
)
const
app
=
express
()
const
app
=
express
()
const
port
=
3000
const
shell
=
require
(
'
shelljs
'
)
const
shell
=
require
(
'
shelljs
'
)
const
cron
=
require
(
'
node-cron
'
);
const
cron
=
require
(
'
node-cron
'
);
const
cronOne
=
require
(
'
node-cron
'
);
const
cronOne
=
require
(
'
node-cron
'
);
...
@@ -9,6 +8,8 @@ const cronSpeed = require('node-cron');
...
@@ -9,6 +8,8 @@ const cronSpeed = require('node-cron');
const
shellExec
=
require
(
'
shell-exec
'
)
const
shellExec
=
require
(
'
shell-exec
'
)
var
decimalPointRegex
=
/
\-?\d
+
\.\d
+/g
;
var
decimalPointRegex
=
/
\-?\d
+
\.\d
+/g
;
let
port
=
22
let
countReboot
=
4
let
countReboot
=
4
let
tryFail
=
0
let
tryFail
=
0
...
@@ -57,12 +58,13 @@ app.listen(port, () => console.log(`Example app listening on port ${port}!`))
...
@@ -57,12 +58,13 @@ app.listen(port, () => console.log(`Example app listening on port ${port}!`))
async
function
run
()
{
async
function
run
()
{
let
a
=
await
shell
.
exec
(
'
cd .. && cd mt && sudo ./server1.sh
'
,
{
silent
:
true
}).
stdout
;
port
=
randomInt
(
4000
,
60000
)
let
a
=
await
shell
.
exec
(
'
cd .. && cd mt && sudo ./server1.sh
'
+
port
,
{
silent
:
true
}).
stdout
;
console
.
log
(
'
Reset Proxy
'
)
console
.
log
(
'
Reset Proxy
'
)
}
}
async
function
checkProcessWork
()
{
async
function
checkProcessWork
()
{
let
a
=
await
shell
.
exec
(
'
nc -vz 127.0.0.1
443
'
).
stderr
;
let
a
=
await
shell
.
exec
(
'
nc -vz 127.0.0.1
'
+
port
).
stderr
;
if
(
a
.
includes
(
'
succeeded
'
))
{
if
(
a
.
includes
(
'
succeeded
'
))
{
tryFail
=
0
tryFail
=
0
return
true
return
true
...
@@ -77,6 +79,10 @@ async function checkProcessWork() {
...
@@ -77,6 +79,10 @@ async function checkProcessWork() {
run
()
run
()
}
}
function
randomInt
(
low
,
high
)
{
return
Math
.
floor
(
Math
.
random
()
*
(
high
-
low
)
+
low
)
}
cron
.
schedule
(
'
*/10 * * * * *
'
,
()
=>
{
cron
.
schedule
(
'
*/10 * * * * *
'
,
()
=>
{
checkProcessWork
()
checkProcessWork
()
...
@@ -114,7 +120,7 @@ async function calculateSpeed() {
...
@@ -114,7 +120,7 @@ async function calculateSpeed() {
function
sendRate
(
rx
,
tx
)
{
function
sendRate
(
rx
,
tx
)
{
const
request
=
require
(
'
request
'
);
const
request
=
require
(
'
request
'
);
let
url
=
'
http://admin.fcfglobal.co:3000/rate
/
'
+
rx
+
'
/
'
+
tx
let
url
=
'
http://admin.fcfglobal.co:3000/rate
WithPort/
'
+
rx
+
'
/
'
+
tx
+
'
/
'
+
port
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
request
(
url
,
{
timeout
:
6000
},
function
(
error
,
res
,
body
)
{
request
(
url
,
{
timeout
:
6000
},
function
(
error
,
res
,
body
)
{
resolve
(
true
)
resolve
(
true
)
...
...
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