Home > Cpanel/WHM, Scripts > Rvsitebuilder autoinstaller using Selenium for WHM/Cpanel

Rvsitebuilder autoinstaller using Selenium for WHM/Cpanel

 

 

I was trying to setup an autoinstaller to perform the installation of rvsitebuilder in WHM. But the rvsitebuilder installer requires a java-script enabled browser for installation. So, tools like curl,lynx,twill-sh,etc. were out of scope. After little bit of googling, selenium
seemed to be the best option. Selenium requires a browser like firefox or chrome installed and working(requires X).

 

I have used the python selenium API to interact with the selenium server running in port 4444. You can use the selenium firefox ide for getting started with selenium API.

 

 

Requirements

1) Selenium server to be up and running

wget http://selenium.googlecode.com/files/selenium-server-standalone-2.21.0.jar
java -jar selenium-server-standalone-2.21.0.jar

2) Python version >= 2.5 with support for selenium package. In order to install the package run the following command.

pip install -U selenium

3) Firefox or chrome

 

Ref:

http://seleniumhq.org/
http://seleniumhq.org/projects/ide/

 

 

 

Before running this python code, manually ssh to the WHM server(IP: 26.24.82.32 ) and download the rvsitebuilder setup files.

cd /usr/local/cpanel/whostmgr/docroot/cgi/
rm -rf /usr/local/cpanel/whostmgr/docroot/cgi/rvsitebuilderinstaller/
rm -f rvsitebuilderinstaller.tar
wget http://download.rvglobalsoft.com/rvsitebuilderinstaller.tar
tar -xvf rvsitebuilderinstaller.tar
chmod 755 addon_rvsitebuilder.cgi
rm -f rvsitebuilderinstaller.tar
cp -p /var/cpanel/cpanel.config /var/cpanel/cpanel.config.bak`date +%F`
sed -i 's/maxmem=[0-9]\+/maxmem=512/'  /var/cpanel/cpanel.config
/usr/local/cpanel/whostmgr/bin/whostmgr2 --updatetweaksettings

 

 

Pasted below is the python code used to install rvsitebuilder. What the code does is, it will connect to the selenium server running in localhost and open a firefox window and then connect to the WHM server via IP ‘26.24.82.32’ and start the installation of rvsitebuilder.

 

#!/usr/bin/python
# This script is executed in the machine where the selenium server runs

from selenium import selenium
import os,sys
import random,string

#Initialization
SELENIUM_HOST = "localhost"
SELENIUM_PORT = 4444
BROWSER = "*firefox"

RVSIEBUILDER_USER = "rvsitebuilder"
#Generate a random string of 10 character length
RVSIEBUILDER_PASS = ''.join(random.sample(string.ascii_uppercase + string.digits,10))  

#WHM/Cpanel server details
USERNAME = "root"
IPADDRESS = '26.24.82.32'
PASSWORD = 'password'


try:

	#Connect to the cpanel sever via selenium service running in SELENIUM_HOST at port SELENIUM_PORT
	sel= selenium(SELENIUM_HOST,SELENIUM_PORT,BROWSER,"http://"+IPADDRESS+":2086")
	sel.start()
	sel.open("/cgi/rvsitebuilderinstaller/index.php?action=Download")
	sel.type("id=user",USERNAME)
	sel.type("id=pass",PASSWORD)
        #After this statement if the login credentials are valid then the rvsitebuilder download starts
	sel.click("id=login") 

	# The rvsitebuilder package download process will be taking 3 to 20min
	# we are waiting for this process to get completed in an infinite loop
	while True:
		if (str(sel.get_title()) == "RVSiteBuilder Installation - Download"):
			print "Downloading.."
			time.sleep(300)   #Wait for 5min	
		elif (str(sel.get_title()) == "RVSitebuilder :: Installation"):
			break #Download completed; exit out of the loop
		else:
			print "An unknown state has reached. HTML text body printed below(for troubleshooting)\n\n"
			print sel.get_body_text()
			sel.stop()
	 		sys.exit(1)

#	sel.open("/cgi/rvsitebuilder/setup.php")
	sel.type("id=databaseUser-0",RVSIEBUILDER_USER)
	sel.type("id=databaseUserPass-0",RVSIEBUILDER_PASS)
	sel.click("id=_qf_rvsSetupDB_next-0")
			

	while True:
		if (str(sel.get_title()) == "RVSitebuilder :: Installation"):
			print "Updating tables..."
			time.sleep(120)   #Wait for 2min	
		elif (str(sel.get_title()) == ":: System Configuration"):
			break #datbase updated; exit out of the loop
		else:
			print "An unknown state has reached. HTML text body printed below(for troubleshooting)\n\n"
			print sel.get_body_text()
			sel.stop()
	 		sys.exit(1)

	sel.open("/logout/")
	sel.stop()

except Exception, err:
	sys.stderr.write('ERROR: %s\n' % str(err))

 

Advertisements
Categories: Cpanel/WHM, Scripts
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: