#!/bin/bash # info: add system ip address # options: IP MASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME] [NAT_IP] # # The function adds ip address into a system. It also creates rc scripts. You # can specify ip 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 ip will automaticaly receive alias $domain.a1.myhosting.com. Of course # you must have wildcard record *.a1.myhosting.com pointed to ip. This feature # is very handy when customer wants to test domain before dns migration. #----------------------------------------------------------# # Variable&Function # #----------------------------------------------------------# # Argument defenition ip=${1// /} mask=$2 interface="${3-eth0}" user="${4-admin}" ip_status="${5-shared}" ip_name=$6 nat_ip=$7 # Includes source $VESTA/func/main.sh source $VESTA/func/ip.sh source $VESTA/func/domain.sh source $VESTA/conf/vesta.conf #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# check_args '2' "$#" 'IP MASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME] [NAT_IP]' validate_format 'ip' 'mask' 'interface' 'user' 'ip_status' is_ip_free is_object_valid 'user' 'USER' "$user" is_object_unsuspended 'user' 'USER' "$user" if [ ! -z "$ip_name" ] ; then validate_format 'ip_name' fi if [ ! -z "$nat_ip" ] ; then validate_format 'nat_ip' fi #----------------------------------------------------------# # Action # #----------------------------------------------------------# get_ip_iface sys_ip_check=$(/sbin/ifconfig | grep "addr:$ip ") if [ -z "$sys_ip_check" ]; then # Adding sys ip /sbin/ifconfig "$iface" "$ip" netmask "$mask" # Adding RHEL/CentOS/Fedora startup script if [ -e "/etc/redhat-release" ]; then sys_ip="# Added by vesta" sys_ip="$sys_ip\nDEVICE=$iface" sys_ip="$sys_ip\nBOOTPROTO=static" sys_ip="$sys_ip\nONBOOT=yes" sys_ip="$sys_ip\nIPADDR=$ip" sys_ip="$sys_ip\nNETMASK=$mask" echo -e $sys_ip > /etc/sysconfig/network-scripts/ifcfg-$iface fi # Adding Debian/Ubuntu startup script if [ -e "/etc/debian_version" ]; then sys_ip="\n# Added by vesta" sys_ip="$sys_ip\nauto $iface" sys_ip="$sys_ip\niface $iface inet static" sys_ip="$sys_ip\naddress $ip" sys_ip="$sys_ip\nnetmask $mask" echo -e $sys_ip >> /etc/network/interfaces fi fi # Adding vesta ip echo "OWNER='$user' STATUS='$ip_status' NAME='$ip_name' U_SYS_USERS='' U_WEB_DOMAINS='0' INTERFACE='$interface' NETMASK='$mask' NAT='$nat_ip' TIME='$TIME' DATE='$DATE'" > $VESTA/data/ips/$ip chmod 660 $VESTA/data/ips/$ip # WEB support if [ ! -z "$WEB_SYSTEM" ]; then web_conf="/etc/$WEB_SYSTEM/conf.d/$ip.conf" if [ "$WEB_SYSTEM" = 'httpd' ] || [ "$WEB_SYSTEM" = 'apache2' ]; then echo "NameVirtualHost $ip:$WEB_PORT" > $web_conf echo "Listen $ip:$WEB_PORT" >> $web_conf fi if [ "$WEB_SSL" = 'mod_ssl' ]; then echo "NameVirtualHost $ip:$WEB_SSL_PORT" >> $web_conf echo "Listen $ip:$WEB_SSL_PORT" >> $web_conf fi fi # Proxy support if [ ! -z "$PROXY_SYSTEM" ]; then cat $WEBTPL/$PROXY_SYSTEM/proxy_ip.tpl |\ sed -e "s/%ip%/$ip/g" \ -e "s/%web_port%/$WEB_PORT/g" \ -e "s/%proxy_port%/$PROXY_PORT/g" \ > /etc/$PROXY_SYSTEM/conf.d/$ip.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 $ip/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) rpaf_str="$rpaf_str $ip" sed -i "s/.*RPAFproxy_ips.*/$rpaf_str/" $rpaf_conf fi fi #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# # Updating user counters increase_user_value "$user" '$IP_OWNED' if [ "$user" = 'admin' ]; then if [ "$ip_status" = 'shared' ]; then for user in $(ls $VESTA/data/users); do increase_user_value "$user" '$IP_AVAIL' done else increase_user_value 'admin' '$IP_AVAIL' fi else increase_user_value "$user" '$IP_AVAIL' increase_user_value 'admin' '$IP_AVAIL' fi # Restart web server $BIN/v-restart-web if [ $? -ne 0 ]; then exit E_RESTART fi $BIN/v-restart-proxy if [ $? -ne 0 ]; then exit E_RESTART fi # Logging log_history "added system ip address $ip" '' 'admin' log_event "$OK" "$EVENT" exit