Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
server-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NoCloud
server-utils
Commits
f0cb3b4b
Commit
f0cb3b4b
authored
11 months ago
by
Elian Loraux
Browse files
Options
Downloads
Patches
Plain Diff
Script de bascule réseau automatique
parent
ffc34c1a
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
net-switch.sh
+54
-0
54 additions, 0 deletions
net-switch.sh
reverseSSHproxy.sh
+10
-0
10 additions, 0 deletions
reverseSSHproxy.sh
with
64 additions
and
0 deletions
net-switch.sh
0 → 100644
+
54
−
0
View file @
f0cb3b4b
#!/usr/bin/env bash
IPPubliqueTetrixChezOVH
=
"109.190.180.230"
IPPubliqueAquilaChezOVH
=
"5.135.140.89"
APIKEY
=
"PUT YOUT PERSONAL TOKEN"
# Jeton sur passbotl
stateFile
=
"/opt/net-state"
currentIP
=
`
curl api.ipify.org
`
reverseSSHProxyPath
=
"/opt/reverseSSHproxy.sh"
# check if file exist
if
[[
-f
"
$stateFile
"
]]
;
then
$state
=
`
cat
$stateFile
`
# Check if current ip is different of normal ip
if
[[
$IPPubliqueTetrixChezOVH
==
$currentIP
]]
;
then
if
[[
$state
!=
"normal"
]]
;
then
# Switch on normal mode
# ssh dockerweb@aquila.tetras-libre.fr 'cd reverse-ssh-proxy && docker-compose down'
pid
=
`
ps aux |
grep
test.sh |
grep
-v
grep
|
awk
'{print $2}'
`
kill
$pid
change_dns
$APIKEY
$IPPubliqueTetrixChezOVH
echo
"normal"
>
"
$stateFile
"
fi
else
if
[[
$state
=
"normal"
]]
;
then
# Switch on back up mode
# ssh dockerweb@aquila.tetras-libre.fr 'cd reverse-ssh-proxy && docker-compose up'
bash
$reverseSSHProxyPath
&
change_dns
$APIKEY
$IPPubliqueAquilaChezOVH
echo
"backup"
>
"
$stateFile
"
fi
fi
else
echo
"normal"
>
"
$stateFile
"
fi
change_dns
()
{
APIKEY
=
$1
CURRENTIP
=
$2
curl
-s
-X
PUT
--header
"Authorization: Bearer
${
APIKEY
}
"
\
--header
"Content-Type: application/json"
\
-d
"{
\"
rrset_values
\"
: [
\"
${
CURRENTIP
}
\"
],
\"
rrset_ttl
\"
: "
300
"}"
\
https://api.gandi.net/v5/livedns/domains/tetras-libre.fr/records/tetrixx/A
}
This diff is collapsed.
Click to expand it.
reverseSSHproxy.sh
0 → 100644
+
10
−
0
View file @
f0cb3b4b
#!/bin/bash
HTTPS_PORT
=
8080
SSHPORT_INT
=
2223
SSHPORT
=
2222
PROXY_HOST
=
aquila.tetras-libre.fr
while
true
;
do
/usr/bin/ssh
-i
/root/.ssh/id_rsa
-N
-R
${
HTTPS_PORT
}
:localhost:443
-R
${
SSHPORT_INT
}
:localhost:22
-o
"ExitOnForwardFailure yes"
-o
"StrictHostKeyChecking no"
-o
"ServerAliveInterval 60"
sshuser@
${
PROXY_HOST
}
-p
${
SSHPORT
}
echo
"Ssh failed
$?
"
sleep
5
done
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment