Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rt2-route
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-route
Commits
5fa82229
Commit
5fa82229
authored
Dec 03, 2019
by
Ahmad Nemati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
86bb64cc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
4 deletions
+59
-4
app.js
app.js
+55
-2
package.json
package.json
+4
-2
No files found.
app.js
View file @
5fa82229
...
...
@@ -3,6 +3,9 @@ const app = express()
const
port
=
3000
const
shell
=
require
(
'
shelljs
'
)
const
cron
=
require
(
'
node-cron
'
);
const
cronSpeed
=
require
(
'
node-cron
'
);
const
shellExec
=
require
(
'
shell-exec
'
)
var
decimalPointRegex
=
/
\-?\d
+
\.\d
+/g
;
app
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
...
...
@@ -29,7 +32,7 @@ async function addNewIp(req, res) {
}
async
function
addBaship
(
ip
)
{
return
await
shell
.
exec
(
'
ip addr add
'
+
ip
+
'
dev eth0
'
).
stderr
;
return
await
shell
.
exec
(
'
ip addr add
'
+
ip
+
'
dev eth0
'
).
stderr
;
}
...
...
@@ -38,7 +41,6 @@ app.listen(port, () => console.log(`Example app listening on port ${port}!`))
async
function
run
()
{
let
a
=
await
shell
.
exec
(
'
cd .. && cd mt && sudo ./server1.sh
'
,
{
silent
:
true
}).
stdout
;
// await shell.exec('iptables -A INPUT -s 95.156.255.148 -p ICMP --icmp-type 8 -j ACCEPT && iptables -A INPUT -p ICMP --icmp-type 8 -j DROP', {silent: true}).stdout;
console
.
log
(
'
Reset Proxy
'
)
}
...
...
@@ -53,3 +55,54 @@ cron.schedule('*/10 * * * * *', () => {
checkProcessWork
()
});
async
function
calculateSpeed
()
{
let
d
=
await
shellExec
(
'
vnstat -tr
'
)
d
=
d
.
stdout
d
=
d
.
match
(
decimalPointRegex
)[
0
]
if
(
d
.
includes
(
'
kbit/s
'
))
{
d
[
0
]
=
1
d
[
1
]
=
1
}
else
if
(
d
.
includes
(
'
Mbit/s
'
))
{
}
else
if
(
d
.
includes
(
'
Gbit/s
'
))
{
d
[
0
]
=
d
[
0
]
*
1000
d
[
1
]
=
d
[
1
]
*
1000
}
else
if
(
d
.
includes
(
'
bit/s
'
))
{
d
[
0
]
=
1
d
[
1
]
=
1
}
await
sendRate
(
d
[
0
],
d
[
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 * * * * *
'
,
()
=>
{
return
calculateSpeed
()
});
package.json
View file @
5fa82229
...
...
@@ -7,7 +7,9 @@
},
"dependencies"
:
{
"
express
"
:
"
~4.16.0
"
,
"
shelljs
"
:
"
^0.8.3
"
,
"
node-cron
"
:
"
^2.0.3
"
"
node-cron
"
:
"
^2.0.3
"
,
"
request
"
:
"
^2.88.0
"
,
"
shell-exec
"
:
"
^1.0.2
"
,
"
shelljs
"
:
"
^0.8.3
"
}
}
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