Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Dev Section 3rd Party Software
  • Search

Auto IP Changer for VestaCP

Section with additional software for Vesta
Post Reply
  • Print view
Advanced search
3 posts • Page 1 of 1
mingu2001
Posts: 2
Joined: Fri Mar 10, 2017 7:19 pm

Auto IP Changer for VestaCP
  • Quote

Post by mingu2001 » Tue Aug 01, 2017 2:37 am

I made this little script that auto updates the server IP of VestaCP.
This script does not need any arguments, so it can be run on cron.
Also, this only works on configurations that have the the server IP as the public IP.

Disclaimer: I am not responsible for any damages done to your server using this program. Please use in your own risks. Also, backup before using this as this script may have bugs present.

Instructions:
First, do

Code: Select all

sudo -i
or login as ROOT on your server.

Second, do

Code: Select all

touch /usr/local/vesta/bin/v-update-ip
to create the file.

Third, do

Code: Select all

nano /usr/loca/vesta/bin/v-update-ip
and paste the code below.

Code: Select all

#!/bin/bash
# info: updates server IP
# options: NONE
#
# The function updates the server IP
# Created by mingu2001

LOG=/var/log/vesta/system.log

getUID=`/usr/bin/id -u`

if [ "$getUID" != 0 ]; then
        log "Attempted without ROOT Access. Halting operation!";
        exit 0
fi

log() {
	echo -e "$1"
	echo -e "$1" >> $LOG
}

replaceIP() {
	sed -i -e "s/${oldIP}/${newIP}/g" $1
}

oldIP=$(ls /etc/nginx/conf.d/ | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])')

log "Old IP: $oldIP"

newIP=$(curl -sL http://checkip.dyndns.com/ | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])')

failsafeIP=$(curl -sL http://api.ipaddress.com/myip?format=txt | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])')

log "New IP: $newIP"

log "Failsafe IP: $failsafeIP"

if [ $failsafeIP != $newIP ]
then
	log "Results from servers differ. Halting operation!"
	exit 0
fi

if [ $oldIP == $newIP ]
then
	log "No need to change IP!"
	exit 0
fi

replaceIP /etc/nginx/conf.d/$oldIP.conf
mv -f /etc/nginx/conf.d/$oldIP.conf /etc/nginx/conf.d/$newIP.conf

replaceIP /etc/apache2/conf.d/$oldIP.conf
mv -f /etc/apache2/conf.d/$oldIP.conf /etc/apache2/conf.d/$newIP.conf

find /home/ -name "*.conf" -not -path "/home/timeshift/*" -print | xargs sed -i "s/${oldIP}/${newIP}/g"

for i in `ls /usr/local/vesta/data/users`
do
{
    replaceIP /usr/local/vesta/data/users/$i/web.conf
    replaceIP /usr/local/vesta/data/users/$i/dns.conf
	replaceIP /home/$i/conf/web/apache2.conf
    replaceIP /home/$i/conf/web/nginx.conf
	
    for j in `ls /usr/local/vesta/data/users/$i/dns/*.conf`
	do
    {
        replaceIP $j
    }
    done

    for j in `ls /home/$i/conf/dns/*.db`
	do
    {
		replaceIP $j
    }
    done

}
done

service nginx restart
service apache2 restart

log "Changed IP from $oldIP to $newIP"
Then press Ctrl+X to end, and press y to confirm.

Lastly,

Code: Select all

chmod +x /usr/local/vesta/bin/v-update-ip
to make the program executable.

Optionally, you can head over to your vesta panel to add a cron job running

Code: Select all

sudo /usr/local/vesta/bin/v-update-ip
.

Feel free to report any bugs, and DO BACKUP BEFORE USING! Thanks!
Top

skurudo
VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:
Contact skurudo
Website Facebook Google+ Skype
Twitter

Re: Auto IP Changer for VestaCP
  • Quote

Post by skurudo » Tue Aug 08, 2017 8:54 am

Nice!

PS: Moved to 3rd Party Software
Top

arafatx
Posts: 25
Joined: Tue Aug 11, 2015 4:51 pm

Re: Auto IP Changer for VestaCP
  • Quote

Post by arafatx » Sun Apr 22, 2018 4:29 am

I think should list out operating system compatibility and the software without having to go through the script. I thought the script works with httpd centos7. My bad.
Top


Post Reply
  • Print view

3 posts • Page 1 of 1

Return to “3rd Party Software”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

Login  •  Register

I forgot my password