Fred808 commited on
Commit
407e06e
·
verified ·
1 Parent(s): 49bf3a4

Upload entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +34 -8
entrypoint.sh CHANGED
@@ -1,25 +1,51 @@
1
  #!/bin/bash
 
2
  set -e
3
 
4
- if [ "$(id -u)" -ne 0 ]; then
5
- echo "⚠️ Not running as root. Cannot start sshd."
 
 
 
 
 
 
 
6
  exit 1
7
  fi
 
8
 
9
- echo "Starting SSH/SOCKS5 Gateway..."
 
 
10
 
11
- # Ensure SSH host keys exist
12
  if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
13
  ssh-keygen -A
14
  fi
15
 
16
- # Start SSH
17
- /usr/sbin/sshd -D -e -f /etc/ssh/sshd_config &
 
18
  echo "SSH server started."
19
 
20
- # Start Dante
 
 
 
 
21
  /usr/sbin/danted -D &
 
22
  echo "Dante SOCKS5 server started."
23
 
24
- # Stay alive
 
 
 
 
 
 
 
25
  exec tail -f /dev/null
 
 
 
1
  #!/bin/bash
2
+
3
  set -e
4
 
5
+ echo "Starting SSH/SOCKS5 NAT Gateway setup..."
6
+
7
+ # Enable IP forwarding
8
+ # echo 1 > /proc/sys/net/ipv4/ip_forward
9
+
10
+ # Fetch public IP
11
+ PUBLIC_IP=$(curl -s ifconfig.me)
12
+ if [ -z "$PUBLIC_IP" ]; then
13
+ echo "Error: Could not fetch public IP. Exiting."
14
  exit 1
15
  fi
16
+ echo "Detected public IP: $PUBLIC_IP"
17
 
18
+ # Configure SSH server
19
+ cp /app/ssh-config/sshd_config /etc/ssh/sshd_config
20
+ chmod 600 /etc/ssh/sshd_config
21
 
22
+ # Generate SSH host keys if they don't exist
23
  if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
24
  ssh-keygen -A
25
  fi
26
 
27
+ # Start SSH service in debug mode and redirect output to a file
28
+ /usr/sbin/sshd -D -e -f /etc/ssh/sshd_config > /var/log/sshd_debug.log 2>&1 &
29
+
30
  echo "SSH server started."
31
 
32
+ # Configure Dante SOCKS5 server
33
+ cp /app/socks5-config/danted.conf /etc/danted.conf
34
+ chmod 644 /etc/danted.conf
35
+
36
+ # Start Dante SOCKS5 server
37
  /usr/sbin/danted -D &
38
+
39
  echo "Dante SOCKS5 server started."
40
 
41
+ # Apply iptables rules for NAT using iptables-legacy
42
+ iptables-legacy -t nat -A POSTROUTING -o eth0 -j MASQUERADE
43
+ iptables-legacy -A FORWARD -i eth0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
44
+ iptables-legacy -A FORWARD -i eth0 -o eth0 -j ACCEPT
45
+
46
+ echo "iptables NAT rules set."
47
+
48
+ # Keep the container running
49
  exec tail -f /dev/null
50
+
51
+