Skip to content

Commit

Permalink
Added script file
Browse files Browse the repository at this point in the history
Script file, which is why this repository is existing
  • Loading branch information
developerfromjokela authored Nov 13, 2018
1 parent 9e8f2ac commit 50882b6
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions ngrokmailer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 &

This comment has been minimized.

Copy link
@martin-paul

martin-paul Nov 7, 2021

it somehow crashes the console for me ... this can be fixed by the following modification:

./$ngrok_path $forwarding_connectiontype $forwarding_ip:$forwarding_port > /dev/null &

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

0 comments on commit 50882b6

Please sign in to comment.