#!/usr/bin/python3 import os import getpass import lib.vamtam as vamtam import pymysql from colorama import Fore, Back, Style print("Create database", "") mysql_user = vamtam.option("Mysql user") mysql_pass = getpass.getpass("%s password:"******"Enter new database name") if(vamtam.confirm('Creating database %s with user %s' % (mysql_database, mysql_user), True)): db1 = pymysql.connect(host='localhost', unix_socket='/var/run/mysqld/mysqld.sock', user=mysql_user, passwd=mysql_pass) cursor = db1.cursor() sql = 'CREATE DATABASE %s' % mysql_database cursor.execute(sql) if(vamtam.confirm('Create new database user?', True)): new_user = vamtam.option("Username", True, mysql_database) new_pass = vamtam.option("Password", True, vamtam.password_generator(25)) sql = "grant all on "+mysql_database+".* to %(user)s identified by %(pass)s" cursor.execute(sql, { 'user': new_user, 'pass': new_pass }); cursor.execute('flush privileges');
# Index file and Document Root (where the public files are located) DirectoryIndex index.html index.php DocumentRoot %(home)s/public # Log file locations LogLevel warn ErrorLog %(home)s/log/error.log CustomLog %(home)s/log/access.log combined </VirtualHost> '''.strip() print("Setting up apache vhost.") domain = vamtam.option("Enter domain") home = vamtam.option("Enter home directory", True, os.path.expanduser('~/public/%s' % domain)) if vamtam.confirm("Creating vhost configuration for %s at %s" % (domain, home), True): vamtam.mkdir_p("%s/public" % home) vamtam.mkdir_p("%s/backup" % home) vamtam.mkdir_p("%s/log" % home) os.system("sudo chown -R www-data:www-data ~/public/%s/public" % domain) mydict = { 'domain': domain, 'home': home } vhost = open(('/tmp/%s' % domain), 'w') vhost.write(vhost_template % mydict) vhost.close() os.system("sudo mv /tmp/%s /etc/apache2/sites-available/" % domain)