#!/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 ""

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..."
yum install dnf-plugins-core -y

yum config-manager --set-enabled powertools


yum -y install perl perl-Net-SSLeay openssl perl-IO-Tty perl-Encode-Detect

cd /tmp
wget http://prdownloads.sourceforge.net/webadmin/webmin-1.994-1.noarch.rpm
rpm -U webmin-1.994-1.noarch.rpm
rm -f webmin-1.994-1.noarch.rpm


#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


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"


