#!/bin/bash

echo "Welcome to the Discord-Linux Webmin Automated installer"
echo "This installer will automatically select a port on your container."
echo "I will let you know how to access your Webmin installation when installation is complete."
echo ""
echo ""
echo ""
echo ""

apt update
echo "downloading the Notification Bot"
wget -q -O /usr/bin/notif https://ssh.surf/debian/notif && chmod +x /usr/bin/notif
echo "Done"

#notif "Welcome to the Webmin Automated installer for Discord-Linux, We are preparing your installation..."



apk add perl perl-net-ssleay


cd /opt
wget -O - https://github.com/webmin/webmin/archive/refs/tags/1.991.tar.gz | tar -xzf -

mv webmin-1.991 webmin

cd webmin
./setup.sh /usr/local/webmin



#notif "Finding a port and configuring webmin"

hostname=$(hostname)

echo "Grabbing a port from your container from our API"
port=$(curl -s  https://findport.ssh.surf/?id=$hostname)

echo "Disabling SSL in webmin for proxy support"
sed -i 's/ssl=1/ssl=0/g' /etc/webmin/miniserv.conf
echo "disabling refer checks to allow for vhost usage"
sed -i 's/referers_none=1/referers_none=0/g' /etc/webmin/config
sed -i 's/referer=1/referer=0/g' /etc/webmin/config
echo "Setting Webmin Port"
sed -i "s/10000/${port}/g" /etc/webmin/miniserv.conf

rm -f /tmp/webmin_1.984_all.deb 

service webmin start

sed -i "s/#webmin/service webmin start/g" /start.sh

#notif "Your webmin installation has completed, you may access your installation at: http://ssh.surf:$port"

echo "Your installation has completed, you may access your installation at: http://ssh.surf:$port"


