#!/usr/bin/python # VPS Post install script # Michael Watters - wattersm@example.com # 11/26/2006 - Rewrite using python import commands import os import string import sys if len(sys.argv) <= 5: print "Usage: xen-post-install.py \n" sys.exit(1) #print "WHM configurator\n" #hostname = raw_input("What is the hostname of the box: ") #hostname = hostname.strip() hostname = sys.argv[1] #rootpw = raw_input("Root Password: ") #rootpw = rootpw.strip() rootpw = sys.argv[2] #contact_mail = raw_input("Contact E-mail: ") #contact_mail = contact_mail.strip() contact_mail = sys.argv[3] #main_ip = raw_input("What is the ip address: ") #main_ip = main_ip.strip() main_ip = sys.argv[4] #netmask = raw_input("What is the netmask: ") #netmask = netmask.strip() netmask = sys.argv[5] # Name servers should be set up from WHM domain = hostname.split('.', 1)[1] #update the cpanel, download and uncompress xcontroller #if os.system("/scripts/upcp") == 1: # print "Cpanel update failed!!!\n" # sys.exit(1) # Disable for now # Install Fantastico Add-on #os.chdir("/usr/local/cpanel/whostmgr/docroot/cgi") #os.system("wget http://files.betaservant.com/files/free/fantastico_whm_admin.tgz") #os.system("tar xzpf fantastico_whm_admin.tgz") #os.system("rm -f fantastico_whm_admin.tgz") # Xcontroller Install #os.chdir("/usr/local/cpanel/base/frontend") #os.system("rm -rf xcontroller") #os.system("rm -f xcontroller.tgz") #if os.system("wget -N http://files.betaservant.com/files/xcontroller/xcontroller.tgz") == 1: # print "Could not download xcontroller! Check your licence!\n" # sys.exit(1) #os.system("tar xzpf xcontroller.tgz") #os.system("chown -R root.root xcontoller/") #os.system("rm -f xcontroller.tgz") #os.system("/usr/local/cpanel/bin/cachelangfiles") #os.chdir("/usr/local/cpanel/lang") #os.system("touch catalan french indonesian polish romanian spanish german italian portugues russian turkish") #done!, setup server settings (server setup tab) f = open('/etc/wwwacct.conf', 'w') f.write("""ADDR %s CONTACTEMAIL %s CONTACTPAGER %s DEFMOD x ETHDEV eth0 FTPTYPE proftpd HOMEDIR /home HOMEMATCH home HOST %s LOGSTYLE combined NS ns1.%s NS2 ns2.%s SCRIPTALIAS y """ %(main_ip, contact_mail, contact_mail, hostname, domain, domain) ) f.close() #update cpanel sslcert os.system("/scripts/rebuildcpanelsslcrt") #install newest chroot version of bind, then disable chrooting!??? #system("yum install bind-chroot.i386") f = open('/etc/chkserv.d/bind', 'w') f.write("#SERVICE = PORT, SEND, RESPONSE, RESTART COMMAND\n\n service[bind]=x,x,x,/scripts/restartsrv bind,named,named|root|bind\n") f.close() f = open('/etc/sysconfig/named', 'w') f.close() #install exim4, since cpanel hasnt ben doing that recently os.system("/scripts/exim4") os.system("/etc/init.d/chkservd restart") #add vps ips(only 2 now) octets = main_ip.split('.') f = open("/etc/ips", 'w') nextnum = int(octets[3]) + 1 f.write("%s.%s.%s.%s\n" % (octets[0], octets[1], octets[2], octets[3]) ) f.write("%s.%s.%s.%s\n" % (octets[0], octets[1], octets[2], nextnum) ) f.close() #quick and dirty write of named.conf os.system("/scripts/rebuildnamedconf") os.system("rndc reload") #enable quotas os.system("/scripts/fixquotas") #do apache stuff os.system("mv -f /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak") f = open('/usr/local/apache/conf/httpd.conf.bak', 'r') lines = f.readlines() f.close() f = open('/usr/local/apache/conf/httpd.conf', 'w') for x in lines: if x.startswith("ServerAdmin"): f.write("ServerAdmin %s\n" %contact_mail) elif x.startswith("ServerName"): f.write("ServerName %s\n" %hostname) else: f.write(x) f.close() f = open('/etc/nameserverips', 'w') f.write("%s.%s.%s.%s=ns1.%s\n" % (octets[0], octets[1], octets[2], octets[3], domain) ) f.write("%s.%s.%s.%s=ns2.%s\n" % (octets[0], octets[1], octets[2], nextnum, domain) ) f.close() os.system("/etc/init.d/named restart") os.system("/scripts/fixndc") os.system("/scripts/fixndc") os.system("rndc reload") os.system("mysqladmin password \"$root\"") #setsourceguardian f = open('/var/cpanel/cpanel.config', 'w') f.write("#config ---------------------------------------=\nRS=default\nVALIASDIR=/etc/valiases\nVFILTERDIR=/etc/vfilters\naccess_log=/usr/local/cpanel/logs/access_log\nadminuser=cpanel\nallowcpsslinstall=0\nallowparkonothers=0\nallowperlupdates=0\nallowremotedomains=0\nallowunregistereddomains=0\nalwaysredirecttossl=1\nawstatsbrowserupdate=0\nawstatsreversedns=0\nbasename=cpanel\nblockcommondomains=0\ncpredirecthostname=0\ncycle=1\ndefaultmailaction=localuser\ndisablequotacache=0\ndiscardformmailbccsubject=0\ndnslookuponconnect=0\ndocroot=/usr/local/cpanel/base\ndumplogs=0\nemailusersbandwidthexceed=0\nengine=cpanel\nenginepl=cpanel.pl\nengineroot=/usr/local/cpanel\nerrorstostdout=0\nexim-retrytime=60\neximmailtrap=0\nextracpus=0\nftppasslogs=0\nignoredepreciated=0\ninterchangever=disable\njaildefaultshell=0\nkeepftplogs=0\nkeeplogs=0\nkeepstatslog=0\nloadthreshold=\nlogchmod=\nmaxemailsperhour=0\nmyname=cpaneld\nmysql-version=4.1\nmysqldebug=0\nnobodyspam=0\nnouserbackupwarn=0\nnumacctlist=\nphploader=sourceguardian\npopbeforesmtpsenders=0\npopchecktimes=0\npopfloodcheck=0\nport=2082\nproduct=cPanel\nresetpass=1\nroot=/usr/local/cpanel\nshowwhmbwusageinmegs=0\nskipanalog=0\nskipawstats=0\nskipboxcheck=0\nskipbwlimitcheck=0\nskipdiskcheck=0\nskipeximstats=0\nskipformmail=0\nskiphorde=0\nskiphttpauth=0\nskipmailman=0\nskipneomail=0\nskipspamassassin=0\nskipsqmail=0\nskipwebalizer=0\nskipwhoisns=0\nstats_log=/usr/local/cpanel/logs/stats_log\nstatsloglevel=1\nurchinsetpath=\nusemailformailmanurl=0\nusemysqloldpass=0\nversion=8.0\nnativessl=1\n") f.close() os.system("/etc/init.d/cpanel restart") os.system("perl -pi -e \"s/disable\s*=\s*no/disable=yes/g\" /etc/xinetd.d/popa3ds /etc/init.d/xinetd stop /usr/local/cpanel/startstunnel /etc/init.d/cpanel restart /etc/init.d/xinetd start") print "Install finished!\n" exit