|
#!/bin/bash |
|
# |
|
# INSTALL |
|
# @@@@@@@ |
|
# git clone https://gist.github.com/1602c3b520d4595a41df59f8673d019c.git pve-fp |
|
# cd pve-fp; |
|
# chmod+x proxmox-frontpage.sh |
|
# ./proxmox-frontpage.sh |
|
|
|
# @@@@@@@@@@@@@@@ |
|
# https://gist.github.com/pacmac |
|
# I created this for my own use but decided to share it, use entirely at your own risk. |
|
# If your server is public facing or you don't trust any of your nodes then don't do it. |
|
# CORS policies have been circumvented in the add_header X-Frame-Options for the iframe to load the frontpages. |
|
# After each change please test thye configuration with "nginx -t" |
|
# and restart the nginx service: systemctl restart nginx |
|
# It would be nice to see this as an enhancement properly built into proxmox. |
|
# @@@@@@@@@@@@@@@ |
|
|
|
function _help { |
|
echo " ##################### |
|
## Example node entry |
|
##################### |
|
> For Each CT/VM node, add a new entry into the /etc/nginx/conf.d folder: |
|
> The listen port needs to be the Node ID + 8000 |
|
|
|
> So in this example, the node id is 101 so the listen port is 8101 |
|
> either use the local dns host name or the ip address and port. |
|
|
|
nano /etc/nginx/conf.d/8101_plex.conf |
|
|
|
server { |
|
include snippets/pveprox.conf; |
|
listen 8101 ssl; |
|
location / { |
|
proxy_pass http://plex.local:32400/; |
|
} |
|
} |
|
|
|
> Then test & restart nginx |
|
|
|
nginx -t |
|
systemctl restart nginx; |
|
##################### |
|
" |
|
} |
|
|
|
### Check for previous install & backup |
|
function _check { |
|
if [ -f "/usr/share/pve-manager/index.html.tpl.bak" ];then |
|
echo "@@@ This installer has already been run once." |
|
echo "@@@ Quitting." |
|
exit 0; |
|
else |
|
echo "OK First Run, proceeding with install..." |
|
cp -p /usr/share/pve-manager/index.html.tpl /usr/share/pve-manager/index.html.tpl.bak |
|
fi |
|
} |
|
|
|
### Install nginx |
|
function _install { |
|
echo "Updaing repos & installing nginx..." |
|
apt update && apt -y install nginx; |
|
} |
|
|
|
### Remove existing nginx defaults |
|
function _ngclean { |
|
rm -f /etc/nginx/sites-enabled/default |
|
rm -f /etc/nginx/sites-available/default |
|
rm -f /etc/nginx/snippets/*.conf |
|
rm -f /etc/nginx/conf.d/*.conf |
|
} |
|
|
|
|
|
### insert proxmox.conf into /etc/nginx/conf.d |
|
function _pmproxy { |
|
pmox="upstream proxmox { |
|
server "proxmox.local"; |
|
} |
|
|
|
server { |
|
listen 80 default_server; |
|
rewrite ^(.*) https://\$host\$1 permanent; |
|
} |
|
|
|
server { |
|
listen 443 ssl; |
|
server_name _; |
|
ssl_certificate /etc/pve/local/pve-ssl.pem; |
|
ssl_certificate_key /etc/pve/local/pve-ssl.key; |
|
proxy_redirect off; |
|
location / { |
|
proxy_http_version 1.1; |
|
proxy_set_header Upgrade \$http_upgrade; |
|
proxy_set_header Connection "upgrade"; |
|
proxy_pass https://localhost:8006; |
|
proxy_buffering off; |
|
client_max_body_size 0; |
|
proxy_connect_timeout 3600s; |
|
proxy_read_timeout 3600s; |
|
proxy_send_timeout 3600s; |
|
send_timeout 3600s; |
|
} |
|
} |
|
" |
|
echo "$pmox" > /etc/nginx/conf.d/proxmox.conf |
|
} |
|
|
|
|
|
## insert pveprox.conf include file into /etc/nginx/snippets |
|
function _snippets { |
|
echo "server_name _; |
|
ssl_certificate /etc/pve/local/pve-ssl.pem; |
|
ssl_certificate_key /etc/pve/local/pve-ssl.key; |
|
proxy_redirect off; |
|
proxy_http_version 1.1; |
|
proxy_set_header Upgrade \$http_upgrade; |
|
proxy_set_header Connection "upgrade"; |
|
proxy_set_header Host \$host; |
|
proxy_set_header X-Real-IP \$remote_addr; |
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; |
|
proxy_set_header X-Forwarded-Host \$server_name; |
|
proxy_set_header X-Forwarded-Proto https; |
|
proxy_hide_header X-Frame-Options; |
|
add_header X-Frame-Options \"ALLOWALL\";" > /etc/nginx/snippets/pveprox.conf |
|
} |
|
|
|
|
|
### append <script> to index.html.tpl |
|
function _index { |
|
FN="/usr/share/pve-manager/index.html.tpl" |
|
|
|
## Backup the file |
|
if [ ! -f "$FN.bak" ];then |
|
cp -rp $FN "$FN.bak"; |
|
fi |
|
|
|
if [ ! "$(cat $FN | grep frontpage.js)" ];then |
|
echo "Inserting into $FN"; |
|
sed -i '/<\/head>/i <script type="text/javascript" src='\''/pve2/js/frontpage.js'\''></script>' $FN; |
|
fi; |
|
} |
|
|
|
### Copy frontpage.js to pve folder |
|
function _cpjs { |
|
cp -rp ./frontpage.js /usr/share/pve-manager/js/frontpage.js |
|
} |
|
|
|
## restart nginx |
|
function _restart { |
|
nginx -t |
|
systemctl restart nginx; |
|
} |
|
|
|
## MAIN |
|
_check; |
|
_install; |
|
_ngclean; |
|
_pmproxy; |
|
_snippets; |
|
_index; |
|
_cpjs; |
|
_restart; |
|
_help; |
|
|