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
e962c8e2
Commit
e962c8e2
authored
Nov 20, 2020
by
Ahmad Nemati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
9bebf2df
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
1 deletion
+50
-1
app.js
app.js
+50
-1
iptable.sh
iptable.sh
+0
-0
No files found.
app.js
View file @
e962c8e2
...
...
@@ -7,7 +7,7 @@ const cronOne = require('node-cron');
const
cronSpeed
=
require
(
'
node-cron
'
);
const
shellExec
=
require
(
'
shell-exec
'
)
var
decimalPointRegex
=
/
\-?\d
+
\.\d
+/g
;
let
fs
=
require
(
'
fs
'
)
let
port
=
5
...
...
@@ -58,6 +58,8 @@ app.listen(3000, () => console.log(`Example app listening on port 3000!`))
async
function
run
()
{
let
whiteIp
=
await
getWhiteIp
()
let
portRes
=
await
getPort
()
if
(
portRes
===
'
0
'
||
portRes
===
'
443
'
)
port
=
randomInt
(
4000
,
60000
)
...
...
@@ -67,6 +69,41 @@ async function run() {
console
.
log
(
'
Reset Proxy
'
)
}
async
function
doIptable
(
whiteIp
)
{
let
command
=
''
for
(
let
i
=
0
;
i
<
whiteIp
.
length
;
i
++
)
{
command
+=
'
iptables -A INPUT -p tcp -s
'
+
whiteIp
[
i
]
+
'
--dport 3000 -j ACCEPT
'
command
+=
'
\n
'
command
+=
'
iptables -A INPUT -p tcp -s
'
+
whiteIp
[
i
]
+
'
--dport 22 -j ACCEPT
'
command
+=
'
\n
'
}
command
+=
'
iptables -A INPUT -p tcp -s 0.0.0.0/0 --dport 3000 -j DROP
'
command
+=
'
\n
'
command
+=
'
iptables -A INPUT -p tcp -s 0.0.0.0/0 --dport 22 -j DROP
'
await
createfile
(
command
)
await
execLast
()
return
true
}
function
createfile
(
command
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
fs
.
writeFile
(
"
iptable.sh
"
,
command
,
'
utf8
'
,
function
(
err
)
{
if
(
err
)
reject
(
err
);
else
resolve
(
command
);
});
});
}
async
function
execLast
()
{
let
d
=
await
shellExec
(
'
sudo ./iptable.sh
'
)
return
true
}
async
function
checkProcessWork
()
{
let
a
=
await
shell
.
exec
(
'
nc -vz 127.0.0.1
'
+
port
).
stderr
;
if
(
a
.
includes
(
'
succeeded
'
))
{
...
...
@@ -147,6 +184,18 @@ function getPort() {
}
function
getWhiteIp
()
{
const
request
=
require
(
'
request
'
);
let
url
=
'
http://admin.fcfglobal.co:3000/getWhiteIp
'
return
new
Promise
(
function
(
resolve
,
reject
)
{
request
(
url
,
{
timeout
:
15000
},
function
(
error
,
res
,
body
)
{
resolve
(
JSON
.
parse
(
body
))
});
});
}
cronSpeed
.
schedule
(
'
*/5 * * * * *
'
,
()
=>
{
...
...
iptable.sh
0 → 100644
View file @
e962c8e2
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