%PDF- %PDF-
Direktori : /usr/local/src/publicnginx/ |
Current File : //usr/local/src/publicnginx/nginxinstaller2 |
#!/usr/bin/env python # Nginx Admin Installer # Website: www.nginxcp.com # # Copyright (C) NGINXCP.COM. # import sys import os import subprocess import time import re sys.path.append('/scripts/') import createvhosts import xmlapi def findapacheversion(): proc = subprocess.Popen(["/usr/sbin/httpd", "-V"], stdout=subprocess.PIPE) output = proc.communicate()[0] m = re.search("Apache/(2\.[0-9]+\.[0-9]+)", output) if not m: print "Unsupported Apache version" sys.exit(1) return m.group(1) def installmodule(name): f=open('/usr/local/apache/conf/httpd.conf', 'r') fl = f.readlines() f.close include="Include \"/usr/local/apache/conf/includes/" + name + ".conf\"" if include not in fl: fl.insert(29, include) f=open('/usr/local/apache/conf/httpd.conf', 'w') f.writelines(fl) f.close ipliststring = createvhosts.getipliststring() apache_version = findapacheversion() if apache_version.startswith("2.4.") and os.path.exists("/var/cpanel/templates/apache2_4"): remoteipliststring = "" for ip in ipliststring.split(' '): remoteipliststring += "RemoteIPInternalProxy " + ip + "\n" moduleinclude = """cat >> "/usr/local/apache/conf/includes/remoteip.conf" <<EOF LoadModule remoteip_module modules/mod_remoteip.so #Mod_remoteip settings RemoteIPHeader X-Real-IP RemoteIPInternalProxy 127.0.0.1 %s EOF""" % (remoteipliststring) else: moduleinclude = """cat >> "/usr/local/apache/conf/includes/rpaf.conf" <<EOF LoadModule rpaf_module modules/mod_rpaf-2.0.so #Mod_rpaf settings RPAFenable On RPAFproxy_ips 127.0.0.1 %s RPAFsethostname On RPAFheader X-Real-IP EOF""" % (ipliststring) proc = subprocess.Popen(moduleinclude, shell=True) output = proc.communicate() proc = subprocess.Popen("sed -i 's/$HTTPD -k .*/\\0\\n\\/etc\\/init.d\\/nginx $ARGV/g' /etc/init.d/httpd", shell=True) output = proc.communicate() proc = subprocess.Popen("sed -i 's/$HTTPD -k .*/\\0\\n\\/etc\\/init.d\\/nginx $ARGV/g' /usr/local/apache/bin/apachectl", shell=True) output = proc.communicate() if apache_version.startswith("2.4.") and os.path.exists("/var/cpanel/templates/apache2_4"): remoteipinstall=installmodule("remoteip") else: rpafinstall=installmodule("rpaf") proc = subprocess.Popen("/usr/local/cpanel/bin/apache_conf_distiller --update > /dev/null 2>&1", shell=True) output = proc.communicate() time.sleep(5) rotatescript = """cat >> "/etc/logrotate.d/nginx" <<EOF /var/log/nginx/*log { missingok notifempty sharedscripts postrotate /sbin/service nginx reload > /dev/null 2>/dev/null || true endscript } EOF""" proc = subprocess.Popen(rotatescript, shell=True) output = proc.communicate() ncheckservd = "service[nginx]=x,x,x,/scripts/nginx_restart,nginx,root" nchkservdf = open('/etc/chkserv.d/nginx', 'w') nchkservdf.write(ncheckservd) nchkservdf.close() print " Reading Apache Configuration " print " updating Apache configuration " if not os.path.exists("/var/cpanel/templates/apache2/vhost.local"): proc = subprocess.Popen("cp -a /var/cpanel/templates/apache2/vhost.default /var/cpanel/templates/apache2/vhost.local", shell=True) output = proc.communicate() if not os.path.exists("/var/cpanel/templates/apache2/ssl_vhost.local"): proc = subprocess.Popen("cp -a /var/cpanel/templates/apache2/ssl_vhost.default /var/cpanel/templates/apache2/ssl_vhost.local", shell=True) output = proc.communicate() proc = subprocess.Popen("sed -i 's/CustomLog/#CustomLog/g' /var/cpanel/templates/apache2/vhost.local", shell=True) output = proc.communicate() proc = subprocess.Popen("sed -i 's/CustomLog/#CustomLog/g' /var/cpanel/templates/apache2/ssl_vhost.local", shell=True) output = proc.communicate() if apache_version.startswith("2.4.") and os.path.exists("/var/cpanel/templates/apache2_4"): if not os.path.exists("/var/cpanel/templates/apache2_4/vhost.local"): proc = subprocess.Popen("cp -a /var/cpanel/templates/apache2_4/vhost.default /var/cpanel/templates/apache2_4/vhost.local", shell=True) output = proc.communicate() if not os.path.exists("/var/cpanel/templates/apache2_4/ssl_vhost.local"): proc = subprocess.Popen("cp -a /var/cpanel/templates/apache2_4/ssl_vhost.default /var/cpanel/templates/apache2_4/ssl_vhost.local", shell=True) output = proc.communicate() proc = subprocess.Popen("sed -i 's/CustomLog/#CustomLog/g' /var/cpanel/templates/apache2_4/vhost.local", shell=True) output = proc.communicate() proc = subprocess.Popen("sed -i 's/CustomLog/#CustomLog/g' /var/cpanel/templates/apache2_4/ssl_vhost.local", shell=True) output = proc.communicate() proc = subprocess.Popen("/scripts/rebuildhttpdconf > /dev/null 2>&1", shell=True) output = proc.communicate() proc = subprocess.Popen("sed -i 's/localhost/localhost:8081/g' /etc/init.d/httpd", shell=True) output = proc.communicate() proc = subprocess.Popen("sed -i 's/localhost/localhost:8081/g' /usr/local/apache/bin/apachectl", shell=True) output = proc.communicate() proc = subprocess.Popen("sed -i 's/apache_port=0.0.0.0:80$/apache_port=0.0.0.0:8081/' /var/cpanel/cpanel.config", shell=True) output = proc.communicate() subprocess.Popen("/usr/local/cpanel/whostmgr/bin/whostmgr2 --updatetweaksettings > /dev/null 2>&1", shell=True) output = proc.communicate() time.sleep(15) proc = subprocess.Popen("/etc/init.d/httpd restart > /dev/null 2>&1", shell=True) output = proc.communicate() print " ****************************************************" print " * Installation Complete *" print " *run /etc/init.d/httpd restart to start Nginx Admin*" print " ****************************************************"