|
|
@@ -1,226 +0,0 @@
|
|
|
-#!/bin/bash
|
|
|
-# info: add system ipv6 address
|
|
|
-# options: IPV6 [PREFIXLEN] [INTERFACE] [USER] [IP_STATUS] [IP_NAME]
|
|
|
-#
|
|
|
-# example: v-add-sys-ipv6 1234:55:66::1 /64
|
|
|
-#
|
|
|
-# This function adds ipv6 address into a system. It also creates rc scripts. You
|
|
|
-# can specify ipv6 name which will be used as root domain for temporary aliases.
|
|
|
-# For example, if you set a1.myhosting.com as name, each new domain created on
|
|
|
-# this ipv6 will automatically receive alias $domain.a1.myhosting.com. Of course
|
|
|
-# you must have wildcard record *.a1.myhosting.com pointed to ipv6. This feature
|
|
|
-# is very handy when customer wants to test domain before dns migration.
|
|
|
-
|
|
|
-#----------------------------------------------------------#
|
|
|
-# Variables & Functions #
|
|
|
-#----------------------------------------------------------#
|
|
|
-
|
|
|
-# Get interface name
|
|
|
-iface=$(/bin/ip token | awk -F 'dev ' '{print $2}')
|
|
|
-
|
|
|
-# Argument definition
|
|
|
-ipv6=${1// /}
|
|
|
-prefix_length="${2-/64}"
|
|
|
-iface="${3-$iface}"
|
|
|
-user="${4-admin}"
|
|
|
-ip_status="${5-shared}"
|
|
|
-ip_name=$6
|
|
|
-
|
|
|
-# Includes
|
|
|
-# shellcheck source=/etc/hestiacp/hestia.conf
|
|
|
-source /etc/hestiacp/hestia.conf
|
|
|
-# shellcheck source=/usr/local/hestia/func/main.sh
|
|
|
-source $HESTIA/func/main.sh
|
|
|
-# shellcheck source=/usr/local/hestia/func/ip.sh
|
|
|
-source $HESTIA/func/ip.sh
|
|
|
-# shellcheck source=/usr/local/hestia/func/domain.sh
|
|
|
-source $HESTIA/func/domain.sh
|
|
|
-# load config file
|
|
|
-source_conf "$HESTIA/conf/hestia.conf"
|
|
|
-
|
|
|
-#----------------------------------------------------------#
|
|
|
-# Verifications #
|
|
|
-#----------------------------------------------------------#
|
|
|
-
|
|
|
-check_args '1' "$#" 'IPV6 [PREFIXLEN] [INTERFACE] [USER] [STATUS] [NAME]'
|
|
|
-is_format_valid 'ipv6' 'prefix_length' 'iface' 'user' 'ip_status'
|
|
|
-is_ipv6_free
|
|
|
-is_object_valid 'user' 'USER' "$user"
|
|
|
-is_object_unsuspended 'user' 'USER' "$user"
|
|
|
-if [ -n "$ip_name" ] ; then
|
|
|
- is_format_valid 'ip_name'
|
|
|
-fi
|
|
|
-if [ "$user" != "admin" ]; then
|
|
|
- ip_status="dedicated"
|
|
|
-fi
|
|
|
-
|
|
|
-# Perform verification if read-only mode is enabled
|
|
|
-check_hestia_demo_mode
|
|
|
-
|
|
|
-#----------------------------------------------------------#
|
|
|
-# Action #
|
|
|
-#----------------------------------------------------------#
|
|
|
-
|
|
|
-sys_ip_check=$(/sbin/ip -6 addr | grep "$ipv6")
|
|
|
-if [ -z "$sys_ip_check" ]; then
|
|
|
- # Adding sys ip
|
|
|
- /sbin/ip addr add $ipv6$prefix_length dev ${iface%:*} label ${iface}
|
|
|
- sleep 2 # wait to avoid issues with apache and nginx port binding
|
|
|
-
|
|
|
- # Check if netplan is in use and generate configuration file
|
|
|
- if [ ! -z $(which netplan) ]; then
|
|
|
- if [ ! -z "$(netplan generate --mapping "$iface" | grep networkd)" ]; then
|
|
|
- netplan=1
|
|
|
- else
|
|
|
- netplan=0
|
|
|
- fi
|
|
|
- else
|
|
|
- netplan=0
|
|
|
- fi
|
|
|
-
|
|
|
- if [ "$netplan" == "1" ]; then
|
|
|
- if [ -f "/etc/netplan/60-hestia.yaml" ]; then
|
|
|
- sys_ip=" - $ipv6$prefix_length"
|
|
|
- else
|
|
|
- sys_ip="# Added by hestia, please do not edit the file manually!"
|
|
|
- sys_ip="$sys_ip\nnetwork:"
|
|
|
- sys_ip="$sys_ip\n version: 2"
|
|
|
- sys_ip="$sys_ip\n renderer: networkd"
|
|
|
- sys_ip="$sys_ip\n ethernets:"
|
|
|
- sys_ip="$sys_ip\n $iface:"
|
|
|
- sys_ip="$sys_ip\n addresses:"
|
|
|
- sys_ip="$sys_ip\n - $ipv6$prefix_length"
|
|
|
- fi
|
|
|
- IFS='%'
|
|
|
- echo -e $sys_ip >> /etc/netplan/60-hestia.yaml
|
|
|
- unset IFS
|
|
|
- else
|
|
|
- sys_ip="\n# Added by Hestia Control Panel"
|
|
|
- sys_ip="$sys_ip\nauto ${iface}"
|
|
|
- sys_ip="$sys_ip\niface ${iface} inet6 static"
|
|
|
- sys_ip="$sys_ip\naddress $ipv6$prefix_length"
|
|
|
- echo -e $sys_ip >> /etc/network/interfaces
|
|
|
- fi
|
|
|
-fi
|
|
|
-
|
|
|
-# Generating timestamp
|
|
|
-time_n_date=$(date +'%T %F')
|
|
|
-time=$(echo "$time_n_date" |cut -f 1 -d \ )
|
|
|
-date=$(echo "$time_n_date" |cut -f 2 -d \ )
|
|
|
-
|
|
|
-# Adding hestia ip
|
|
|
-echo "OWNER='$user'
|
|
|
-STATUS='$ip_status'
|
|
|
-NAME='$ip_name'
|
|
|
-U_SYS_USERS=''
|
|
|
-U_WEB_DOMAINS='0'
|
|
|
-INTERFACE='$iface'
|
|
|
-NETMASK='$prefix_length'
|
|
|
-NAT=''
|
|
|
-TIME='$time'
|
|
|
-DATE='$date'
|
|
|
-VERSION='6'" > $HESTIA/data/ips/$ipv6
|
|
|
-chmod 660 $HESTIA/data/ips/$ipv6
|
|
|
-
|
|
|
-# WEB support
|
|
|
-if [ ! -z "$WEB_SYSTEM" ]; then
|
|
|
- web_conf="/etc/$WEB_SYSTEM/conf.d/$ipv6.conf"
|
|
|
- rm -f $web_conf
|
|
|
-
|
|
|
- if [ "$WEB_SYSTEM" = 'httpd' ] || [ "$WEB_SYSTEM" = 'apache2' ]; then
|
|
|
- if [ -z "$(/usr/sbin/apachectl -v | grep Apache/2.4)" ]; then
|
|
|
- echo "NameVirtualHost [$ipv6]:$WEB_PORT" > $web_conf
|
|
|
- fi
|
|
|
- echo "Listen [$ipv6]:$WEB_PORT" >> $web_conf
|
|
|
- cat $HESTIA_INSTALL_DIR/apache2/unassigned.conf >> $web_conf
|
|
|
- sed -i 's/\(VirtualHost \)directIP/\1['$ipv6']/g' $web_conf
|
|
|
- sed -i 's/directIP/'$ipv6'/g' $web_conf
|
|
|
- sed -i 's/directPORT/'$WEB_PORT'/g' $web_conf
|
|
|
-
|
|
|
- elif [ "$WEB_SYSTEM" = 'nginx' ]; then
|
|
|
- cp -f $HESTIA_INSTALL_DIR/nginx/unassigned.inc $web_conf
|
|
|
- sed -i 's/directIP/['$ipv6']/g' $web_conf
|
|
|
- fi
|
|
|
-
|
|
|
- if [ "$WEB_SSL" = 'mod_ssl' ]; then
|
|
|
- if [ -z "$(/usr/sbin/apachectl -v | grep Apache/2.4)" ]; then
|
|
|
- sed -i "1s/^/NameVirtualHost [$ipv6]:$WEB_SSL_PORT\n/" $web_conf
|
|
|
- fi
|
|
|
- sed -i "1s/^/Listen [$ipv6]:$WEB_SSL_PORT\n/" $web_conf
|
|
|
- sed -i 's/directSSLPORT/'$WEB_SSL_PORT'/g' $web_conf
|
|
|
- fi
|
|
|
-fi
|
|
|
-
|
|
|
-# Proxy support
|
|
|
-if [ -n "$PROXY_SYSTEM" ]; then
|
|
|
- cat $WEBTPL/$PROXY_SYSTEM/proxy_ip.tpl |\
|
|
|
- sed -e "s/%ip%/[$ipv6]/g" \
|
|
|
- -e "s/%web_port%/$WEB_PORT/g" \
|
|
|
- -e "s/%proxy_port%/$PROXY_PORT/g" \
|
|
|
- -e "s/%proxy_ssl_port%/$PROXY_SSL_PORT/g" \
|
|
|
- > /etc/$PROXY_SYSTEM/conf.d/$ipv6.conf
|
|
|
-
|
|
|
- # mod_extract_forwarded
|
|
|
- fw_conf="/etc/$WEB_SYSTEM/conf.d/mod_extract_forwarded.conf"
|
|
|
- if [ -e "$fw_conf" ]; then
|
|
|
- ips=$(grep 'MEFaccept ' $fw_conf | grep -v '#' | head -n1)
|
|
|
- sed -i "s/$ips/$ips $ipv6/g" $fw_conf
|
|
|
- fi
|
|
|
-
|
|
|
- # mod_rpaf
|
|
|
- rpaf_conf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
|
|
|
- if [ -e "$rpaf_conf" ]; then
|
|
|
- rpaf_str=$(grep RPAFproxy_ips $rpaf_conf)
|
|
|
- [ -z "$rpaf_str" ] && sed -i 's|</IfModule>|RPAFproxy_ips\n</IfModule>|' $rpaf_conf && rpaf_str='RPAFproxy_ips'
|
|
|
- rpaf_str="$rpaf_str $ipv6"
|
|
|
- sed -i "s/.*RPAFproxy_ips.*/$rpaf_str/" $rpaf_conf
|
|
|
- fi
|
|
|
-
|
|
|
- #mod_remoteip
|
|
|
- remoteip_conf="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
|
|
|
- if [ -e "$remoteip_conf" ]; then
|
|
|
- if [ $( grep -ic "$ipv6" $remoteip_conf ) -eq 0 ]; then
|
|
|
- sed -i "s/<\/IfModule>/RemoteIPInternalProxy $ipv6\n<\/IfModule>/g" $remoteip_conf
|
|
|
- fi
|
|
|
- fi
|
|
|
-fi
|
|
|
-
|
|
|
-#----------------------------------------------------------#
|
|
|
-# Hestia #
|
|
|
-#----------------------------------------------------------#
|
|
|
-
|
|
|
-# Updating user counters
|
|
|
-increase_user_value "$user" '$IPV6_OWNED'
|
|
|
-if [ "$user" = 'admin' ]; then
|
|
|
- if [ "$ip_status" = 'shared' ]; then
|
|
|
- for hestia_user in $($HESTIA/bin/v-list-sys-users plain); do
|
|
|
- increase_user_value "$user" '$IPV6_AVAIL'
|
|
|
- done
|
|
|
- else
|
|
|
- increase_user_value 'admin' '$IPV6_AVAIL'
|
|
|
- fi
|
|
|
-else
|
|
|
- increase_user_value "$user" '$IPV6_AVAIL'
|
|
|
- increase_user_value 'admin' '$IPV6_AVAIL'
|
|
|
-fi
|
|
|
-
|
|
|
-# Restarting web server
|
|
|
-$BIN/v-restart-web
|
|
|
-check_result $? "Web restart failed" >/dev/null
|
|
|
-
|
|
|
-# Restarting proxy server
|
|
|
-if [ -n "$PROXY_SYSTEM" ]; then
|
|
|
- $BIN/v-restart-proxy
|
|
|
- check_result $? "Proxy restart failed" >/dev/null
|
|
|
-fi
|
|
|
-
|
|
|
-# Restarting firewall
|
|
|
-if [ -n "$FIREWALL_SYSTEM" ]; then
|
|
|
- $BIN/v-update-firewall
|
|
|
-fi
|
|
|
-
|
|
|
-# Logging
|
|
|
-$BIN/v-log-action "system" "Info" "Network" "Added new IPV6 address to the system (IPV6: $ipv6)."
|
|
|
-log_event "$OK" "$ARGUMENTS"
|
|
|
-
|
|
|
-exit
|