Răsfoiți Sursa

Redirect unassigned hosts to default page

The server will return a generic "Success!" page when navigating via IP or an unassigned domain name.
Kristan Kenney 7 ani în urmă
părinte
comite
4c813ddb22

+ 16 - 0
install/deb/apache2/unassigned.conf

@@ -0,0 +1,16 @@
+Listen directIP:8080
+Listen directIP:8443
+
+<VirtualHost directIP:80>
+  
+    DocumentRoot /var/www/html/
+    Alias /error/ /var/www/document_errors/
+
+</VirtualHost>
+
+<VirtualHost directIP:443>
+  
+    DocumentRoot /var/www/html/
+    Alias /error/ /var/www/document_errors/
+
+</VirtualHost>

+ 50 - 0
install/deb/nginx/unassigned.inc

@@ -0,0 +1,50 @@
+server {
+    listen directIP:80 default;
+    server_name _;
+    location / {
+        access_log /dev/null;
+        error_log /dev/null;
+        root /var/www/html;
+
+        location /phpmyadmin/ {
+            alias /var/www/document_errors/;
+            return 404;
+        }
+
+        location /phppgadmin/ {
+            alias /var/www/document_errors/;
+            return 404;
+        }
+
+        location /webmail {
+            alias /var/www/document_errors/;
+            return 404;
+        }
+        
+        location /webmail/ {
+            alias /var/www/document_errors/;
+            return 404;
+        }
+
+        location /error/ {
+            alias /var/www/document_errors/;
+        }
+    }
+}
+
+server {
+    listen directIP:443 ssl http2 default;
+    server_name _;
+    ssl_certificate      /usr/local/hestia/ssl/certificate.crt;
+    ssl_certificate_key  /usr/local/hestia/ssl/certificate.key;
+
+    return 301 http://$host$request_uri;
+
+    location / {
+        root /var/www/document_errors/;
+    }
+
+    location /error/ {
+        alias /var/www/document_errors/;
+    }
+}

+ 22 - 0
install/hst-install-debian.sh

@@ -1072,6 +1072,17 @@ if [ "$nginx" = 'yes' ]; then
         service php$fpm_v-fpm start >> $LOG
         check_result $? "php$fpm_v-fpm start failed"
     fi
+
+    # Redirect unassigned hosts to default "Success" page
+    if [ -f /usr/local/hestia/data/ips/* ]; then
+        for ip in /usr/local/hestia/data/ips/*; do
+            ipaddr=${ip##*/}
+            rm -f /etc/nginx/conf.d/$ip.conf
+            cp -f $HESTIA/install/deb/nginx/unassigned.inc /etc/nginx/conf.d/$ipaddr.conf
+            sed -i 's/directIP/'$ipaddr'/g' /etc/nginx/conf.d/$ipaddr.conf
+        done
+    fi
+
     update-rc.d nginx defaults > /dev/null 2>&1
     service nginx start >> $LOG
     check_result $? "nginx start failed"
@@ -1118,6 +1129,17 @@ if [ "$apache" = 'yes' ]; then
             sed -i 's/#//g' $HESTIA/data/templates/web/apache2/*.stpl
         fi
     fi
+
+    # Add unassigned hosts configuration to apache2
+    if [ -f /usr/local/hestia/data/ips/* ]; then
+        for ip in /usr/local/hestia/data/ips/*; do
+            ipaddr=${ip##*/}
+            rm -f /etc/apache2/conf.d/$ip.conf
+            cp -f $HESTIA/install/deb/apache2/unassigned.conf /etc/apache2/conf.d/$ipaddr.conf
+            sed -i 's/directIP/'$ipaddr'/g' /etc/apache2/conf.d/$ipaddr.conf
+        done
+    fi
+
     update-rc.d apache2 defaults > /dev/null 2>&1
     service apache2 start >> $LOG
     check_result $? "apache2 start failed"

+ 22 - 0
install/hst-install-ubuntu.sh

@@ -1050,6 +1050,17 @@ if [ "$nginx" = 'yes' ]; then
         service php$fpm_v-fpm start >> $LOG
         check_result $? "php$fpm_v-fpm start failed"
     fi
+
+    # Redirect unassigned hosts to default "Success" page
+    if [ -f /usr/local/hestia/data/ips/* ]; then
+        for ip in /usr/local/hestia/data/ips/*; do
+            ipaddr=${ip##*/}
+            rm -f /etc/nginx/conf.d/$ip.conf
+            cp -f $HESTIA/install/deb/nginx/unassigned.inc /etc/nginx/conf.d/$ipaddr.conf
+            sed -i 's/directIP/'$ipaddr'/g' /etc/nginx/conf.d/$ipaddr.conf
+        done
+    fi
+
     update-rc.d nginx defaults > /dev/null 2>&1
     service nginx start >> $LOG
     check_result $? "nginx start failed"
@@ -1092,6 +1103,17 @@ if [ "$apache" = 'yes' ]; then
         done
         chmod a+x $HESTIA/data/templates/web/apache2/*.sh
     fi
+
+    # Add unassigned hosts configuration to apache2
+    if [ -f /usr/local/hestia/data/ips/* ]; then
+        for ip in /usr/local/hestia/data/ips/*; do
+            ipaddr=${ip##*/}
+            rm -f /etc/apache2/conf.d/$ip.conf
+            cp -f $HESTIA/install/deb/apache2/unassigned.conf /etc/apache2/conf.d/$ipaddr.conf
+            sed -i 's/directIP/'$ipaddr'/g' /etc/apache2/conf.d/$ipaddr.conf
+        done
+    fi
+
     update-rc.d apache2 defaults > /dev/null 2>&1
     service apache2 start >> $LOG
     check_result $? "apache2 start failed"

+ 14 - 0
install/upgrade/0.9.8-28.sh

@@ -125,6 +125,20 @@ chmod 751 $HESTIA/data/templates/web/unassigned/css
 chmod 751 $HESTIA/data/templates/web/unassigned/js
 chmod 751 $HESTIA/data/templates/web/unassigned/webfonts
 
+# Add unassigned hosts configuration to nginx and apache2
+if [ -f /usr/local/hestia/data/ips/* ]; then
+    for ip in /usr/local/hestia/data/ips/*; do
+        ipaddr=${ip##*/}
+        rm -f /etc/nginx/conf.d/$ip.conf
+        cp -f $HESTIA/install/deb/nginx/unassigned.inc /etc/nginx/conf.d/$ipaddr.conf
+        sed -i 's/directIP/'$ipaddr'/g' /etc/nginx/conf.d/$ipaddr.conf
+
+        rm -f /etc/apache2/conf.d/$ip.conf
+        cp -f $HESTIA/install/deb/apache2/unassigned.conf /etc/apache2/conf.d/$ipaddr.conf
+        sed -i 's/directIP/'$ipaddr'/g' /etc/apache2/conf.d/$ipaddr.conf
+    done
+fi
+
 # Set Purge to false in roundcube config - https://goo.gl/3Nja3u
 if [ -f /etc/roundcube/config.inc.php ]; then
     sed -i "s/\['flag_for_deletion'] = 'Purge';/\['flag_for_deletion'] = false;/gI" /etc/roundcube/config.inc.php