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
22cc6e7c
Commit
22cc6e7c
authored
Mar 03, 2022
by
Ahmad Nemati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
c19ed73f
Pipeline
#140
canceled with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
37 deletions
+25
-37
app.js
app.js
+25
-37
No files found.
app.js
View file @
22cc6e7c
...
...
@@ -9,21 +9,19 @@ const shellExec = require('shell-exec')
var
decimalPointRegex
=
/
\-?\d
+
\.\d
+/g
;
let
fs
=
require
(
'
fs
'
)
let
port
=
5
let
routeIp
=
5
let
countReboot
=
4
let
tryFail
=
0
run
()
app
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
res
.
send
(
'
Hello World!
'
)
run
()
})
app
.
get
(
'
/ip/:ip/
'
,
(
req
,
res
)
=>
{
// console.log(req.params.acc)
return
addNewIp
(
req
,
res
)
})
app
.
get
(
'
/rst2
'
,
(
req
,
res
)
=>
{
...
...
@@ -31,26 +29,15 @@ app.get('/rst2', (req, res) => {
})
app
.
get
(
'
/test
'
,
(
req
,
res
)
=>
{
// console.log(req.params.acc)
res
.
sendfile
(
'
jetmtp.png
'
)
})
async
function
addNewIp
(
req
,
res
)
{
res
.
send
(
'
Hello World!
'
)
console
.
log
(
req
.
params
.
ip
)
addBaship
(
req
.
params
.
ip
)
}
async
function
addBaship
(
ip
)
{
return
await
shell
.
exec
(
'
ip addr add
'
+
ip
+
'
dev eth0
'
).
stderr
;
}
async
function
reboot
()
{
//
return await shell.exec(' sudo reboot ').stderr;
return
await
shell
.
exec
(
'
sudo reboot
'
).
stderr
;
}
...
...
@@ -59,19 +46,34 @@ app.listen(3000, () => console.log(`Example app listening on port 3000!`))
async
function
run
()
{
let
whiteIp
=
await
getWhiteIp
()
doIptable
(
whiteIp
)
//
doIptable(whiteIp)
let
portRes
=
await
getPort
()
portRes
=
parseInt
(
portRes
)
if
(
portRes
.
route
===
'
0
'
)
{
await
sleep
(
1500
)
return
run
()
}
routeIp
=
portRes
.
route
portRes
=
parseInt
(
portRes
.
port
)
console
.
log
(
portRes
)
if
(
portRes
===
0
||
portRes
===
443
||
portRes
===
5
)
if
(
portRes
===
0
||
portRes
===
443
||
portRes
===
5
)
port
=
randomInt
(
4000
,
60000
)
else
port
=
parseInt
(
portRes
)
let
a
=
await
shell
.
exec
(
'
cd .. && cd mt && sudo ./server1.sh
'
+
port
,
{
silent
:
true
}).
stdout
;
let
command
=
'
sysctl net.ipv4.ip_forward=1 &&
'
command
=
command
+
'
iptables -t nat -A PREROUTING -p tcp --dport
'
+
portRes
+
'
-j DNAT --to-destination
'
+
routeIp
+
'
:443 &&
'
command
=
command
+
'
iptables -t nat -A POSTROUTING -j MASQUERADE
'
let
a
=
await
shell
.
exec
(
command
,
{
silent
:
true
}).
stdout
;
console
.
log
(
'
Reset Proxy
'
)
}
async
function
sleep
(
millis
)
{
return
new
Promise
(
resolve
=>
setTimeout
(
resolve
,
millis
));
}
async
function
doIptable
(
whiteIp
)
{
let
command
=
''
for
(
let
i
=
0
;
i
<
whiteIp
.
length
;
i
++
)
{
...
...
@@ -103,22 +105,8 @@ async function execLast() {
return
true
}
async
function
checkProcessWork
()
{
let
a
=
await
shell
.
exec
(
'
nc -vz 127.0.0.1
'
+
port
).
stderr
;
if
(
a
.
includes
(
'
succeeded
'
)
||
a
.
includes
(
'
Connected
'
))
{
tryFail
=
0
return
true
}
tryFail
++
if
(
tryFail
>=
countReboot
)
reboot
()
run
()
}
function
randomInt
(
low
,
high
)
{
return
Math
.
floor
(
Math
.
random
()
*
(
high
-
low
)
+
low
)
}
...
...
@@ -175,10 +163,10 @@ function sendRate(rx, tx) {
function
getPort
()
{
const
request
=
require
(
'
request
'
);
let
url
=
'
http://23.88.33.146:3000/getPort
'
let
url
=
'
http://23.88.33.146:3000/getPort
Adv
'
return
new
Promise
(
function
(
resolve
,
reject
)
{
request
(
url
,
{
timeout
:
15000
},
function
(
error
,
res
,
body
)
{
resolve
(
body
)
resolve
(
JSON
.
parse
(
body
)
)
});
});
...
...
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