-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f3fa24
commit c2ad56d
Showing
7 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/var/pids/* | ||
!/var/pids/.gitkeep | ||
/conf.d/* | ||
!/conf.d/config-example.sh.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,28 @@ | ||
# private-networking | ||
Networking solution written in Bash, based on reverse proxy | ||
Allows to create multiple reverse tunnels from inside of NAT to the external server. | ||
|
||
## Setup | ||
|
||
- Put your configuration files into `conf.d` | ||
|
||
``` | ||
1. File must be with ".sh" extension | ||
2. File must be executable (eg. chmod +x "webserver.sh") | ||
3. File must be in a proper syntax and implement proper configuration variables | ||
described as an example in the "config-example.sh.md" | ||
``` | ||
|
||
Send public key to all servers described in your configuration | ||
so the communication could be without a password using a ssh key. | ||
|
||
Run: `./bin/send-public-key.sh` | ||
|
||
- Bind your ports to the external server | ||
|
||
Run: `./bin/bind-network.sh` | ||
|
||
That's all! | ||
Your local services should be exposed to the remote server and be | ||
visible on eg. http://localhost:1234, so you need an internal proxy or | ||
a load balancer like nginx to forward the traffic to the internet. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
#-------------------------------------------- | ||
# Bind network ports to the remote server | ||
# using a reverse proxy strategy | ||
# | ||
# @author Wolnościowiec Team | ||
# @see https://wolnosciowiec.net | ||
#-------------------------------------------- | ||
|
||
cd "$( dirname "${BASH_SOURCE[0]}" )" | ||
DIR=$(pwd) | ||
|
||
./kill-previous-sessions.sh | ||
|
||
for config_file_name in ../conf.d/*.sh | ||
do | ||
echo " >> Reading $config_file_name" | ||
source "$config_file_name" | ||
|
||
for forward_ports in ${PORTS[*]} | ||
do | ||
IFS='>' read -r -a parts <<< "$forward_ports" | ||
source_port=${parts[0]} | ||
dest_port=${parts[1]} | ||
|
||
echo " --> Forwarding $source_port:$PN_HOST:$dest_port" | ||
autossh -M 0 -N -f -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -R "$source_port:$PN_HOST:$dest_port" "$PN_USER@$PN_HOST" -p $PN_PORT | ||
echo $! >> ../var/pids/ssh-servers.pid | ||
|
||
if [[ $? != 0 ]]; then | ||
echo " ~ The port forwarding failed, please verify if your SSH keys are well installed" | ||
exit 1 | ||
fi | ||
done | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
#-------------------------------------------- | ||
# Kill all previously opened ssh sessions | ||
# | ||
# @author Wolnościowiec Team | ||
# @see https://wolnosciowiec.net | ||
#-------------------------------------------- | ||
|
||
cd "$( dirname "${BASH_SOURCE[0]}" )" | ||
DIR=$(pwd) | ||
|
||
for config_file_name in ../conf.d/*.sh | ||
do | ||
source "$config_file_name" | ||
|
||
for forward_ports in ${PORTS[*]} | ||
do | ||
pid=$(ps aux |grep autossh|grep "$source_port:$PN_HOST:$dest_port"|grep -v "grep"|awk '{print $2}') | ||
|
||
if [[ $pid ]]; then | ||
echo " >> Killing $pid" | ||
kill $pid | ||
fi | ||
done | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
cd "$( dirname "${BASH_SOURCE[0]}" )" | ||
DIR=$(pwd) | ||
|
||
if [[ ! -f ~/.ssh/id_rsa.pub ]]; then | ||
echo " >> RSA key not found, generating" | ||
ssh-keygen -t rsa -f ~/.ssh/id_rsa | ||
fi | ||
|
||
for config_file_name in ../conf.d/*.sh | ||
do | ||
echo " >> Reading $config_file_name" | ||
source "$config_file_name" | ||
|
||
echo " >> Copying your ID to the $PN_USER@$PN_HOST:$PN_PORT, please log in" | ||
ssh-copy-id -i ~/.ssh/id_rsa "$PN_USER@$PN_HOST" -p $PN_PORT | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
``` | ||
PN_USER=xxx | ||
PN_PORT=22 | ||
PN_HOST=mydomain.org | ||
# local port => destination port | ||
PORTS[0]="8000>80" | ||
PORTS[1]="22>2222" | ||
``` |
Empty file.