-
Notifications
You must be signed in to change notification settings - Fork 5
/
ngrokmailer.sh
105 lines (98 loc) · 3.61 KB
/
ngrokmailer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/sh
# Made By Developer From Jokela 2018
#
# Remember to setup sSMTP for first time by editing file 'sudo nano /etc/ssmtp/ssmtp.conf' manually, or script does it for you.
# Script Depends on: sSMTP, ngrok, unzip and wget
# Run Script as root (using sudo if not loged in as root), if ssmtp command is not found, and if you enable for dependencies check
forwarding_ip="192.168.100.69" # IP of device, server or whatever, which NGROK will forward, leave blank for localhost
forwarding_port="80" # Port to forward
forwarding_connectiontype="http" # Forwarding type http or tcp (See more in ngrok documentation)
email_addr="[email protected]" #Email address for sending Ngrok address in case server or device rebooted
ssmtp_root="[email protected]" #Email address which be used to sent emails
ssmtp_mailhub="smtp.gmail.com:587" #SMTP address of mail server
ssmtp_authuser="[email protected]" #Authentication for SMTP server
ssmtp_authpass="passwordforgmail" #Authentication for SMTP server
ssmtp_usestarttls="YES" # Set YES or NO to enable or disable STARTTLS
ssmtp_autoconfig=true #true or false to disable overwriting ssmtp.conf
logging=false #Enables logging to same folder where is script
ngrok_path="ngrok" # Custom path for Ngrok, leave ngrok if file is in same directory as script. BONUS! NgrokMailer will download file if it is missing
checkfordependencies=true # Checking for all dependencies on startup
if [ "$logging" = true ]; then
rm -f ngrokmailer.log
echo "Starting Ngrok Mailer" >> "ngrokmailer.log"
fi
if [ "$checkfordependencies" = true ]; then
if [ "$logging" = true ]; then
echo "Start Checking for dependencies" >> "ngrokmailer.log"
fi
apt-get install wget
apt-get install unzip
apt-get install ssmtp
if [ "$logging" = true ]; then
echo "Check complete! Continuing..." >> "ngrokmailer.log"
fi
fi
if [ "$logging" = true ]; then
echo "Checking for ngrok file" >> "ngrokmailer.log"
fi
if [ -f "$ngrok_path" ]
then
if [ "$logging" = true ]; then
echo "Ngrok file found $ngrok_path" >> "ngrokmailer.log"
fi
else
if [ "$logging" = true ]; then
echo "Ngrok file not found $ngrok_path, so Downloading it." >> "ngrokmailer.log"
fi
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
unzip ngrok-stable-linux-amd64.zip
fi
if [ "$ssmtp_autoconfig" = true ]; then
if [ "$logging" = true ]; then
echo "Rewriting sSMTP file" >> "ngrokmailer.log"
fi
rm -f /etc/ssmtp/ssmtp.conf
cat > /etc/ssmtp/ssmtp.conf <<EOF
# Generated by NgrokMailer
root=$ssmtp_root
mailhub=$ssmtp_mailhub
AuthUser=$ssmtp_authuser
AuthPass=$ssmtp_authpass
UseSTARTTLS=$ssmtp_usestarttls
EOF
fi
if [ "$logging" = true ]; then
echo "Starting Ngrok" >> "ngrokmailer.log"
fi
if [ "$forwarding_ip" == "" ]
then
./ngrok $forwarding_connectiontype $forwarding_port &
if [ "$logging" = true ]; then
echo "Ngrok Started for Localhost" >> "ngrokmailer.log"
fi
else
./$ngrok_path $forwarding_connectiontype $forwarding_ip:$forwarding_port &
if [ "$logging" = true ]; then
echo "Ngrok Started for Device with IP: $forwarding_ip" >> "ngrokmailer.log"
fi
fi
sleep 5
ngrok_url=$(curl --silent --show-error http://127.0.0.1:4040/api/tunnels | sed -nE 's/.*public_url":"https:..([^"]*).*/\1/p')
if [ "$logging" = true ]; then
echo "Get Ngrok Public URL: $ngrok_url" >> "ngrokmailer.log"
fi
rm -f msg.txt
cat > msg.txt <<EOF
To: $email_addr
From: $ssmtp_root
Subject: Ngrok Mailer got url!
Hello! Here is your server's URL from Ngrok
$ngrok_url
Ngrok Mailer by Developer From Jokela
EOF
ssmtp $email_addr < msg.txt
if [ "$logging" = true ]; then
echo "Email sent to: $email_addr" >> "ngrokmailer.log"
else
rm msg.txt
fi