#!/usr/local/bin/python # VPS Post install script # Michael Watters - wattersm@example.com # some edits by: Don R Johnson - djohnson@example.com # 11/26/2006 - Rewrite using python # 12/11/2006 - ETHDEV venet0:0 (was eth0) and FTPTYPE to pure not pro, and warning msg at end(clean when fixed) -don # 12/12/2006 - translated last bits of old install.pl (zone file creation portion) # 12/15/2006 - zone file was getting in the way of new accounts, disabling that chunk for now. import commands import os import string import sys import time import datetime if len(sys.argv) <= 3: print "Usage: vps-install.py \n" sys.exit(1) hostname = sys.argv[1] contact_mail = sys.argv[2] main_ip = sys.argv[3] domain = hostname.split('.', 1)[1] ######################## # I'm disabling this portion for now. See me with questions -Don #netmask = "255.255.254.0" #nameserver1 = "ns1." + domain #nameserver2 = "ns2." + domain #ser_dt = time.strftime("%Y%m%d00") #dnsemail1 = contact_mail.split('@', 2)[0] #dnsemail2 = contact_mail.split('@', 2)[1] #f = open('/var/named/' + domain + '.db', 'w') # #f.write("""$TTL 14400 @ 14400 IN SOA %s. %s.%s. ( #%s ; serial --UPDATE EACH EDIT!! #14400 ; refresh, seconds #7200 ; retry, seconds #3600000 ; expire, seconds #86400 ) ; minimum, seconds # #) # #%s. 14400 IN NS %s. #%s. 14400 IN NS %s. # #%s. IN A %s #localhost.%s. 14400 IN A 127.0.0.1 #%s. 14400 IN MX 0 %s. #mail 14400 IN CNAME %s. #www 14400 IN CNAME %s. #ftp 14400 IN CNAME %s. #host 14400 IN A %s #""" %(nameserver1,dnsemail1,dnsemail2,ser_dt,domain,nameserver1,domain,nameserver2,hostname,main_ip,domain,domain,domain,domain,domain,domain,main_ip) ) # #f.close() # Install Fantastico Add-on os.chdir("/usr/local/cpanel/whostmgr/docroot/cgi") os.system("wget http://layer3.example.com/fantastico-files/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") os.system("wget -N http://layer3.example.com/fantastico-files/xcontroller.tgz") 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 venet0:0 FTPTYPE pure-ftpd 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") 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() #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("rpm -e lp-vhost mm3k-client-base mm3k-client-pull") os.system("rm -f /usr/local/lp/configs/httpd/vhost.conf") os.system("/usr/bin/yum -c /usr/local/lp/configs/yum/yum.stable.conf -y install mm3k-client-pull") os.system("/etc/init.d/named restart") os.system("/scripts/fixndc") os.system("/scripts/fixndc") os.system("rndc reload") #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\nmaildir=0\n") f.close() # Update chksrvd f = open('/etc/chkserv.d/chkservd.conf', 'w,') f.write("antirelayd:1\nclamd:1\ncpsrvd:1\nentropychat:0\nexim:1\neximstats:0\nftpd:1\nhttpd:1\nimap:1\ninterchange:0\nmysql:1\nnamed:1\npop:1\nspamd:1\n") f.close() os.system("chkconfig popa3d off; chkconfig popa3ds off; /etc/init.d/xinetd stop; /etc/init.d/xinetd start") os.system("/sbin/chkconfig pure-ftpd on") os.system("/scripts/mysqlup") os.system("/scripts/upcp") # Enable bash time stamps os.system("echo >> /etc/profile") os.system("echo HISTTIMEFORMAT=\"%Y%m%d - %H:%M:%S - \" >> /etc/profile") # Clean up os.system("rm -f /tmp/install.py") os.system("whiptail --msgbox 'Shell-based portion of installation complete. \nPlease contact your network administrator.' 8 55") print "*********************************************Install finished. DON'T FORGET TO INSTALL MODSEC\n" exit