Current File : //scripts/change_IP_only.sh |
#!/bin/bash
oldip=$1
newip=$2
if [ -z "$oldip" -o -z "$newip" ]
then
echo "oldip and newip is missing";
echo "/scripts/change_IP_only.sh Old_IPaddress New_IPaddress";
exit;
fi
if [ -f /etc/centos-release ]; then
OSNAME="CentOs"
OSVERSION_FULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)
VERSION=${OSVERSION_FULL:0:1} # return 6 or 7
elif [ -f /etc/lsb-release ]; then
OSNAME=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')
VERSION=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')
else
OSNAME=$(uname -s)
VERSION=$(uname -r)
fi
/etc/sentora/panel/bin/setso --set server_ip $newip
mysql -e "Use sentora_core; UPDATE x_dns SET dn_target_vc = REPLACE(dn_target_vc,'$oldip','$newip');"
mysql -e "Use sentora_core; UPDATE x_changeip SET ci_ip = REPLACE(ci_ip,'$oldip','$newip');"
output=$(mysql -e "Use sentora_core; select GROUP_CONCAT(vh_id_pk) from x_vhosts where vh_deleted_ts IS NULL")
IP=$(echo $output | awk '{print $2}')
echo $IP
/etc/sentora/panel/bin/setso --set dns_hasupdates "$IP"
cd /etc/sentora/configs/apache/domains/
rm -rf ./*
cd /etc/sentora/configs/apache/sentora/
rm -rf ./*
cd /root
sed -i 's/'$oldip'/'$newip'/g' passwords.txt
sed -i 's/'$oldip'/'$newip'/g' /etc/postfix/main.cf
################################# SELF SIGNED SSL CERTIFICATE #############################
mkdir /etc/httpd/httpscertificate
cd /etc/httpd/httpscertificate
if [[ "$OSNAME" == "CentOs" && ("$VERSION" == "8") ]] ; then
openssl req -new -newkey rsa:2048 -nodes -keyout $newip.key -out $newip.csr -subj "/C=IN/ST=karnataka/L=bangalore/O=ovipanel/OU=software/CN=$newip"
openssl x509 -req -days 365 -in /etc/httpd/httpscertificate/$newip.csr -signkey /etc/httpd/httpscertificate/$newip.key -out /etc/httpd/httpscertificate/$newip.crt
else
openssl genrsa -des3 -passout pass:x -out keypair.key 2048
openssl rsa -passin pass:x -in keypair.key -out /etc/httpd/httpscertificate/$newip.key
openssl req -new -key /etc/httpd/httpscertificate/$newip.key -subj "/C=IN/ST=karnataka/L=bangalore/O=ovipanel/OU=software/CN=$newip" -keyout /etc/httpd/httpscertificate/$newip.key -out /etc/httpd/httpscertificate/$newip.csr
openssl x509 -req -days 365 -in /etc/httpd/httpscertificate/$newip.csr -signkey /etc/httpd/httpscertificate/$newip.key -out /etc/httpd/httpscertificate/$newip.crt
fi
if [[ "$OSNAME" == "Ubuntu" ]] ; then
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/httpd/httpscertificate/$newip.key -subj "/C=IN/ST=karnataka/L=bangalore/O=ovipanel/OU=software/CN=$newip" -out /etc/httpd/httpscertificate/$newip.crt
fi
sed -i 's/^SSLCertificateFile.*/SSLCertificateFile \/etc\/httpd\/httpscertificate\/'$newip'.crt/' /etc/httpd/conf.d/ssl.conf
sed -i 's/^SSLCertificateKeyFile.*/SSLCertificateKeyFile \/etc\/httpd\/httpscertificate\/'$newip'.key/' /etc/httpd/conf.d/ssl.conf
cd ~
cp /etc/proftpd.conf /etc/proftpd.conf_hold_bak
sed -i '/MasqueradeAddress/d' /etc/proftpd.conf
echo "MasqueradeAddress $newip" >> /etc/proftpd.conf
service proftpd restart
service httpd restart
################################# SELF SIGNED SSL CERTIFICATE #############################
/etc/sentora/panel/bin/setso --set apache_changed true
php /etc/sentora/panel/bin/daemon.php