-
-
Save Zeerg/5c30cff6ece85ad49e42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os.path | |
import yum | |
import random | |
import string | |
# Global Vars | |
yb = yum.YumBase() | |
# Sanity Checks | |
def errorchecking(): | |
if yb.rpmdb.searchNevra(name="phpMyAdmin"): | |
print "phpMyAdmin Exists Exiting \033[1;31m[Failed]\033[1;m" | |
quit() | |
else: | |
print "No Installation Found \033[1;32m[OK]\033[1;m" | |
if os.path.exists("/etc/redhat-release"): | |
print "CentOS/Redhat \033[1;32m[OK]\033[1;m" | |
else: | |
print "Sorry Not For Debian Exiting \033[1;31m[Failed]\033[1;m" | |
quit() | |
if yb.rpmdb.searchNevra(name="httpd"): | |
print "Apache Found \033[1;32m[OK]\033[1;m" | |
else: | |
print "No Apache Found Exiting \033[1;31m[Failed]\033[1;m" | |
quit() | |
errorchecking() | |
# Installing phpMyAdmin with yum | |
def install(): | |
print "Starting Install" | |
os.system("yum install phpMyAdmin libmcrypt.x86_64 -y 2>&1 > /tmp/install") | |
yb = yum.YumBase() | |
if yb.rpmdb.searchNevra(name="phpMyAdmin"): | |
print "Yum Install \033[1;32m[Success]\033[1;m" | |
else: | |
print "Yum Install \033[1;31m[Failed]\033[1;m" | |
print "Check /tmp/install For Information" | |
quit() | |
install() | |
# Configure (/etc/phpMyAdmin/config.inc.php, phpMyAdmin.conf, htpasswd). Need a better way. | |
def configure(): | |
#Generate Random Password | |
password = ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(32)]) | |
#phpMyAdmin Config | |
f = open("/etc/phpMyAdmin/config.inc.php", "w") | |
f.write("<?php"'\n') | |
f.write("/*"'\n') | |
f.write("* This is needed for cookie based authentication to encrypt password in"'\n') | |
f.write("* cookie"'\n') | |
f.write(" */"'\n') | |
f.write("$cfg['blowfish_secret'] = " + repr(password) + ";"'\n') | |
f.write("/**"'\n') | |
f.write("* Server(s) configuration"'\n') | |
f.write(" */"'\n') | |
f.write("$i = 0;"'\n') | |
f.write("$i++;"'\n') | |
f.write("$cfg['Servers'][$i]['host'] = 'localhost';"'\n') | |
f.write("$cfg['Servers'][$i]['port'] = '';"'\n') | |
f.write("$cfg['Servers'][$i]['socket'] = '';"'\n') | |
f.write("$cfg['Servers'][$i]['connect_type'] = 'tcp';"'\n') | |
f.write("$cfg['Servers'][$i]['extension'] = 'mysqli';"'\n') | |
f.write("$cfg['Servers'][$i]['compress'] = FALSE;"'\n') | |
f.write("$cfg['Servers'][$i]['controluser'] = '';"'\n') | |
f.write("$cfg['Servers'][$i]['controlpass'] = '';"'\n') | |
f.write("$cfg['Servers'][$i]['auth_type'] = 'cookie';"'\n') | |
f.write("$cfg['Servers'][$i]['user'] = '';"'\n') | |
f.write("$cfg['Servers'][$i]['password'] = '';"'\n') | |
f.write("$cfg['Servers'][$i]['only_db'] = '';"'\n') | |
f.write("$cfg['Servers'][$i]['hide_db'] = '';"'\n') | |
f.write("$cfg['Servers'][$i]['verbose'] = '';"'\n') | |
f.write("$cfg['Servers'][$i]['pmadb'] = '';"'\n') | |
f.write("$cfg['Servers'][$i]['bookmarktable'] = '';"'\n') | |
f.write("$cfg['Servers'][$i]['relation'] = '';"'\n') | |
f.write("$cfg['Servers'][$i]['table_info'] = '';"'\n') | |
f.write("$cfg['Servers'][$i]['table_coords'] = '';"'\n') | |
f.write("$cfg['Servers'][$i]['pdf_pages'] = '';"'\n') | |
f.write("$cfg['Servers'][$i]['column_info'] = '';"'\n') | |
f.write("$cfg['Servers'][$i]['history'] = '';"'\n') | |
f.write("$cfg['Servers'][$i]['verbose_check'] = TRUE;"'\n') | |
f.write("$cfg['Servers'][$i]['AllowRoot'] = TRUE;"'\n') | |
f.write("$cfg['Servers'][$i]['AllowDeny']['order'] "'\n') | |
f.write(" = '';"'\n') | |
f.write("$cfg['Servers'][$i]['AllowDeny']['rules']"'\n') | |
f.write(" = array();"'\n') | |
f.write("$cfg['Servers'][$i]['AllowNoPassword']"'\n') | |
f.write(" = FALSE;"'\n') | |
f.write("$cfg['Servers'][$i]['designer_coords']"'\n') | |
f.write(" = '';"'\n') | |
f.write("$cfg['Servers'][$i]['bs_garbage_threshold']"'\n') | |
f.write(" = 50;"'\n') | |
f.write("$cfg['Servers'][$i]['bs_repository_threshold']"'\n') | |
f.write(" = '32M';"'\n') | |
f.write("$cfg['Servers'][$i]['bs_temp_blob_timeout']"'\n') | |
f.write(" = 600;"'\n') | |
f.write("$cfg['Servers'][$i]['bs_temp_log_threshold']"'\n') | |
f.write(" = '32M';"'\n') | |
f.write("$cfg['UploadDir'] = '/var/lib/phpMyAdmin/upload';"'\n') | |
f.write("$cfg['SaveDir'] = '/var/lib/phpMyAdmin/save';"'\n') | |
f.write("$cfg['PmaNoRelation_DisableWarning'] = TRUE;"'\n') | |
f.write("?>") | |
f.close() | |
#Apache Config | |
f2 = open("/etc/httpd/conf.d/phpMyAdmin.conf", "w") | |
f2.write("<Directory /usr/share/phpMyAdmin/>"'\n') | |
f2.write("<Directory /usr/share/phpMyAdmin/>"'\n') | |
f2.write("<Directory /usr/share/phpMyAdmin/>"'\n') | |
f2.write(" AuthName 'PMA Access'"'\n') | |
f2.write(" AuthType Basic"'\n') | |
f2.write(" AuthUserFile /etc/phpMyAdmin/htpasswd"'\n') | |
f2.write(" Require valid-user"'\n') | |
f2.write("</Directory>"'\n') | |
f2.close() | |
#htpasswd | |
os.system("htpasswd -csb /etc/phpMyAdmin/htpasswd pma " + repr(password) > "/tmp/htpassword") | |
#Create MySQL User | |
os.system("mysql -e create user pma") | |
configure() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment