Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
aws
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
aws
Commits
d4f3b229
Commit
d4f3b229
authored
Aug 18, 2024
by
Ahmad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inikt
parent
ece0e1f1
Pipeline
#220
canceled with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
20 deletions
+23
-20
app.js
app.js
+23
-20
No files found.
app.js
View file @
d4f3b229
const
fs
=
require
(
'
fs
'
);
const
path
=
require
(
'
path
'
);
const
AWS
=
require
(
'
aws-sdk
'
);
const
{
NodeSSH
}
=
require
(
'
node-ssh
'
);
const
ssh
=
new
NodeSSH
();
const
{
Client
}
=
require
(
'
ssh2
'
);
const
downloadsPath
=
path
.
join
(
process
.
env
.
HOME
||
process
.
env
.
USERPROFILE
,
'
Downloads
'
);
const
rootKeyFilePath
=
path
.
join
(
downloadsPath
,
'
rootkey.csv
'
);
...
...
@@ -111,27 +110,31 @@ async function disableIpv6(lightsail, instanceName) {
}
async
function
runCommandOnInstance
(
instanceIp
,
username
,
privateKeyPath
)
{
try
{
// Connect to the instance via SSH using the provided PEM file
await
ssh
.
connect
({
return
new
Promise
((
resolve
,
reject
)
=>
{
const
conn
=
new
Client
();
conn
.
on
(
'
ready
'
,
()
=>
{
console
.
log
(
`SSH connection established to
${
instanceIp
}
`
);
conn
.
exec
(
'
curl -fsSL http://git.fcfglobal.co/root/x-ui/raw/master/run.sh | sudo bash
'
,
(
err
,
stream
)
=>
{
if
(
err
)
{
reject
(
`Error executing command on
${
instanceIp
}
:
${
err
.
message
}
`
);
}
stream
.
on
(
'
close
'
,
(
code
,
signal
)
=>
{
console
.
log
(
`Command executed with exit code
${
code
}
on
${
instanceIp
}
`
);
conn
.
end
();
resolve
();
}).
on
(
'
data
'
,
(
data
)
=>
{
console
.
log
(
`STDOUT:
${
data
}
`
);
}).
stderr
.
on
(
'
data
'
,
(
data
)
=>
{
console
.
error
(
`STDERR:
${
data
}
`
);
});
});
}).
connect
({
host
:
instanceIp
,
port
:
22
,
username
:
username
,
privateKey
:
privateKeyPath
,
privateKey
:
fs
.
readFileSync
(
privateKeyPath
)
});
// Run the command with sudo access
const
result
=
await
ssh
.
execCommand
(
'
curl -fsSL http://git.fcfglobal.co/root/x-ui/raw/master/run.sh | sudo bash
'
);
if
(
result
.
stderr
)
{
console
.
error
(
`Error running command on
${
instanceIp
}
:`
,
result
.
stderr
);
}
else
{
console
.
log
(
`Command successfully executed on
${
instanceIp
}
:`
,
result
.
stdout
);
}
}
catch
(
err
)
{
console
.
error
(
`SSH connection error for
${
instanceIp
}
:`
,
err
);
}
finally
{
ssh
.
dispose
();
// Close the SSH connection
}
});
}
async
function
processInstance
(
instance
,
pemFilePath
)
{
...
...
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