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
ece0e1f1
Commit
ece0e1f1
authored
Aug 18, 2024
by
Ahmad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inikt
parent
11fa3ab9
Pipeline
#219
canceled with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
2 deletions
+39
-2
app.js
app.js
+38
-2
package.json
package.json
+1
-0
No files found.
app.js
View file @
ece0e1f1
const
fs
=
require
(
'
fs
'
);
const
path
=
require
(
'
path
'
);
const
AWS
=
require
(
'
aws-sdk
'
);
const
{
NodeSSH
}
=
require
(
'
node-ssh
'
);
const
ssh
=
new
NodeSSH
();
const
downloadsPath
=
path
.
join
(
process
.
env
.
HOME
||
process
.
env
.
USERPROFILE
,
'
Downloads
'
);
const
rootKeyFilePath
=
path
.
join
(
downloadsPath
,
'
rootkey.csv
'
);
...
...
@@ -108,7 +110,39 @@ async function disableIpv6(lightsail, instanceName) {
});
}
async
function
processRegion
(
region
,
credentials
)
{
async
function
runCommandOnInstance
(
instanceIp
,
username
,
privateKeyPath
)
{
try
{
// Connect to the instance via SSH using the provided PEM file
await
ssh
.
connect
({
host
:
instanceIp
,
username
:
username
,
privateKey
:
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
)
{
const
instanceIp
=
instance
.
publicIpAddress
;
// Replace with your method to get the IP
const
username
=
'
ubuntu
'
;
// Replace with the appropriate username for your instances
console
.
log
(
`Running command on instance:
${
instance
.
name
}
(
${
instanceIp
}
)`
);
await
runCommandOnInstance
(
instanceIp
,
username
,
pemFilePath
);
}
async
function
processRegion
(
region
,
credentials
,
pemFilePath
)
{
const
lightsail
=
new
AWS
.
Lightsail
({
region
,
accessKeyId
:
credentials
.
accessKeyId
,
...
...
@@ -125,6 +159,7 @@ async function processRegion(region, credentials) {
console
.
log
(
`Processing instance:
${
instance
.
name
}
in region:
${
region
}
`
);
await
openAllPorts
(
lightsail
,
instance
.
name
);
await
disableIpv6
(
lightsail
,
instance
.
name
);
await
processInstance
(
instance
,
pemFilePath
);
// Pass the PEM file path
}
}
}
...
...
@@ -141,7 +176,8 @@ async function main() {
}
for
(
const
region
of
regions
)
{
await
processRegion
(
region
,
credentials
);
const
pemFilePath
=
path
.
join
(
downloadsPath
,
`LightsailDefaultKey-
${
region
}
.pem`
);
await
processRegion
(
region
,
credentials
,
pemFilePath
);
}
}
catch
(
error
)
{
console
.
error
(
'
Error:
'
,
error
.
message
);
...
...
package.json
View file @
ece0e1f1
...
...
@@ -12,6 +12,7 @@
"dependencies"
:
{
"
aws-sdk
"
:
"
^2.1677.0
"
,
"
csv-parser
"
:
"
^3.0.0
"
,
"
node-ssh
"
:
"
^13.2.0
"
,
"
ssh2
"
:
"
^1.15.0
"
}
}
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