forked from arakasi72/rtinst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtwebmin
95 lines (80 loc) · 3.47 KB
/
rtwebmin
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
#!/bin/bash
######################################################################
#
# Copyright (c) 2015 arakasi72 (https://github.com/arakasi72)
#
# --> Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
#
######################################################################
PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/bin:/sbin
SERVERIP=$(ip route get 8.8.8.8 | awk 'NR==1 {print $NF}')
relno=$(lsb_release -sr | cut -d. -f1)
if ! [ "$LOGNAME" = "root" ]; then
echo "Must be run as root, directly or with sudo"
exit 1
fi
if [ $(dpkg-query -W -f='${Status}' webmin 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
echo "Installing Webmin"
echo "deb http://download.webmin.com/download/repository sarge contrib" > /etc/apt/sources.list.d/webmin.list
wget -qO - http://www.webmin.com/jcameron-key.asc | apt-key add -
apt-get update >> /dev/null 2>&1
apt-get -y install webmin >> /dev/null 2>&1
else
echo 'Webmin is already installed'
fi
#changes to the webmin config file
if [ -z "$(grep ^referers_none= /etc/webmin/config)" ]; then
echo "referers_none=1" >> /etc/webmin/config
else
sed -i '/^referers_none=/ c\referers_none=1' /etc/webmin/config
fi
if [ -z "$(grep ^referers= /etc/webmin/config)" ]; then
echo "referers=localhost" >> /etc/webmin/config
else
sed -i '/^referers=/ c\referers=localhost' /etc/webmin/config
fi
if [ -z "$(grep ^webprefix= /etc/webmin/config)" ]; then
echo "webprefix=/webmin" >> /etc/webmin/config
else
sed -i '/^webprefix=/ c\webprefix=\/webmin' /etc/webmin/config
fi
if [ -z "$(grep ^webprefixnoredir= /etc/webmin/config)" ]; then
echo "webprefixnoredir=1" >> /etc/webmin/config
else
sed -i '/^webprefixnoredir=/ c\webprefixnoredir=1' /etc/webmin/config
fi
if [ -z "$(grep ^referer= /etc/webmin/config)" ]; then
echo "referer=1" >> /etc/webmin/config
else
sed -i '/^referer=/ c\referer=1' /etc/webmin/config
fi
if [ -z "$(grep ^ssl= /etc/webmin/miniserv.conf)" ]; then
echo "ssl=0" >> /etc/webmin/miniserv.conf
else
sed -i '/^ssl=/ c\ssl=0' /etc/webmin/miniserv.conf
fi
echo "Setting up Nginx Reverse Proxy"
#set up default proxy settings
echo 'proxy_redirect off;' > /etc/nginx/conf.d/proxy.conf
echo 'proxy_set_header Host $host;' >> /etc/nginx/conf.d/proxy.conf
echo 'proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/conf.d/proxy.conf
echo 'proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/conf.d/proxy.conf
echo 'proxy_cache off;' >> /etc/nginx/conf.d/proxy.conf
echo 'proxy_buffering off;' >> /etc/nginx/conf.d/proxy.conf
#include webmin location in main nginx site file
sed -i '/webmin-loc/d' /etc/nginx/sites-available/default
sed -i '/^$/N;/^\n$/D' /etc/nginx/sites-available/default
lineno=$(grep -Fn 'location ~ /\.ht' /etc/nginx/sites-available/default | cut -d : -f 1 | tail -1)
sed -i $lineno"i\ include \/etc\/nginx\/sites-available\/webmin-loc;\n" /etc/nginx/sites-available/default
#write the webmin nginx location file
echo 'location /webmin/ {' > /etc/nginx/sites-available/webmin-loc
echo ' proxy_pass http://localhost:10000/;' >> /etc/nginx/sites-available/webmin-loc
echo ' proxy_redirect http://$host:10000/ /webmin/;' >> /etc/nginx/sites-available/webmin-loc
echo '}' >> /etc/nginx/sites-available/webmin-loc
#restart services
service webmin restart >> /dev/null 2>&1
service nginx restart >> /dev/null 2>&1
echo "Completed"
echo
echo "Webmin can be accessed at https://$SERVERIP/webmin"
echo "login using root, or sudo user credentials"