def create_www_user(): global domain, homeRoot if (basics.command("grep --quiet \"" + domain + "\" /etc/passwd")): basics.command( "adduser --force-badname --disabled-password --gecos \"\" --home \"" + homeRoot + "/" + domain + "\" --shell /bin/bash \"" + domain + "\"") #basics.command("usermod --append --groups www-data") basics.command("usermod --append --groups www-data \"" + domain + "\"")
def create_www_home(): global domain, homeRoot print colored("create www home", 'red') path = homeRoot + "/" + domain basics.make_ordner(path + "/htdocs") basics.make_ordner(path + "/tmp") basics.make_ordner(path + "/config") basics.make_ordner(path + "/logs") basics.command("chown --recursive \""+domain+":"+domain+"\" \""+homeRoot+"/"+domain+"\"") basics.command("chmod 755 --recursive \""+homeRoot+"/"+domain+"\"")
def create_www_home(): global domain, homeRoot print colored("create www home", 'red') path = homeRoot + "/" + domain basics.make_ordner(path + "/htdocs") basics.make_ordner(path + "/tmp") basics.make_ordner(path + "/config") basics.make_ordner(path + "/logs") basics.command("chown --recursive \"" + domain + ":" + domain + "\" \"" + homeRoot + "/" + domain + "\"") basics.command("chmod 755 --recursive \"" + homeRoot + "/" + domain + "\"")
def add_phpfpm_conf(): global domain, homeRoot, fpmPort print colored("add php fpm conf", 'red') if not(basics.check_file("/etc/php5/fpm/pool.d/",domain + ".conf")): templateFile = open("templates/php-fpm_conf.txt", "r") template = templateFile.read(); templateFile.close(); template = template.replace("[root_path]",homeRoot); template = template.replace("[domain]",domain); template = template.replace("[port]",str(fpmPort)); configFile = open("/etc/php5/fpm/pool.d/" + domain + ".conf", "w") configFile.write(template) configFile.close(); basics.command("service php5-fpm force-reload")
def add_phpfpm_conf(): global domain, homeRoot, fpmPort print colored("add php fpm conf", 'red') if not (basics.check_file("/etc/php5/fpm/pool.d/", domain + ".conf")): templateFile = open("templates/php-fpm_conf.txt", "r") template = templateFile.read() templateFile.close() template = template.replace("[root_path]", homeRoot) template = template.replace("[domain]", domain) template = template.replace("[port]", str(fpmPort)) configFile = open("/etc/php5/fpm/pool.d/" + domain + ".conf", "w") configFile.write(template) configFile.close() basics.command("service php5-fpm force-reload")
def move_folder(domain, homeRoot): basics.make_ordner("/home/removed") basics.command("mv \"" + homeRoot + "/" + domain + "\" \"" + homeRoot + "/removed/" + domain + "_" + str(time.time()) + "\"")
# argumente auswerten parser = argparse.ArgumentParser(description='Anlegen einer neuen Domain') #parser.add_argument("-h", help="print this help") parser.add_argument("-n", "--home", help="home root path. default: \"/home\"", default="/home") parser.add_argument("-d", "--domain", help="domain name", required=True) #parser.add_argument("-o", "--overwrite", help="overwrite existent files", action="store_true", default=False) args = vars(parser.parse_args()) domain = args["domain"] homeRoot = args["home"] #verwrite = args["overwrite"] if check_if_vhost(domain): deactivate_vhost(domain) print("deaktivate vhost") basics.command("service apache2 reload") print("service apache2 reload") remove_configs(domain) print("remove configs") basics.command("service php5-fpm reload") print("service php5-fpm reload") move_folder(domain, homeRoot) print("move folder") delete_user(domain) # delete user with home dir print("delete user") else: print("value is no valid vhost")
def lets_encrypt(): global domain, homeRoot basics.command("certbot --apache certonly --webroot -w " + homeRoot + " -d " + domain)
def remove_configs(domain): if (basics.check_file("/etc/php5/fpm/pool.d/",domain + ".conf")): basics.command("rm " + "/etc/php5/fpm/pool.d/" + domain + ".conf") if (basics.check_file("/etc/apache2/sites-available/",domain + ".conf")): basics.command("/etc/apache2/sites-available/" + domain + ".conf")
def move_folder(domain, homeRoot): basics.make_ordner("/home/removed") basics.command("mv \""+homeRoot+"/"+domain+"\" \""+homeRoot+"/removed/"+domain+"_"+ str(time.time()) +"\"")
def delete_user(domain): basics.command("userdel -r -f " + domain)
def verbose_command(cmd): print colored("command:", 'cyan'), colored(cmd, 'magenta') basics.command(cmd)
#!/usr/bin/python3.4 # # written by David Bauer, initial start 17.09.2014 # import helper.basic as basics import sys # erstma updaten print("sourcen updaten") basics.command("aptitude -y update 1>/dev/null") print("sourcen geupdatet") # add more cool tools basics.command("aptitude install apache2-mpm-worker") basics.command("aptitude install apache2-utils libapache2-mod-fastcgi") basics.command("aptitude install php5-fpm") basics.command("a2enmod actions ssl rewrite auth_digest proxy") basics.command("service apache2 restart") #basics.command('echo "apache2-mpm-worker 2.4 (sid), php5-fpm 5.6 (sid) and fastcgi setup" >> /etc/motd') #basics.command('echo "apache2-mpm-worker, php5-fpm and fastcgi setup" >> /etc/motd') #basics.command('echo "by david bauer aka debauer - [email protected]" >> /etc/motd') #basics.command('echo "" >> /etc/motd') #basics.command('echo "USAGE:" >> /etc/motd') #basics.command('echo "- do not install change anything relatet to this packages!" >> /etc/motd') #basics.command('echo "- use setup_domain.py script to add new vHosts. location: /root/scripts" >> /etc/motd')
def restart_services(): basics.command("service apache2 reload") basics.command("service php5-fpm force-reload")
def enable_apache_site(): global domain basics.command("/usr/sbin/a2ensite " + domain) basics.command("service apache2 reload")
def deactivate_vhost(domain): basics.command("/usr/sbin/a2dissite " + domain)
def remove_configs(domain): if (basics.check_file("/etc/php5/fpm/pool.d/", domain + ".conf")): basics.command("rm " + "/etc/php5/fpm/pool.d/" + domain + ".conf") if (basics.check_file("/etc/apache2/sites-available/", domain + ".conf")): basics.command("/etc/apache2/sites-available/" + domain + ".conf")
def lets_encrypt(): global domain, homeRoot basics.command("certbot --apache certonly --webroot -w " + homeRoot + " -d " + domain )
else: return False # argumente auswerten parser = argparse.ArgumentParser(description='Anlegen einer neuen Domain') #parser.add_argument("-h", help="print this help") parser.add_argument("-n", "--home", help="home root path. default: \"/home\"", default="/home") parser.add_argument("-d", "--domain", help="domain name", required=True) #parser.add_argument("-o", "--overwrite", help="overwrite existent files", action="store_true", default=False) args = vars(parser.parse_args()) domain = args["domain"] homeRoot = args["home"] #verwrite = args["overwrite"] if check_if_vhost(domain): deactivate_vhost(domain) print("deaktivate vhost") basics.command("service apache2 reload") print("service apache2 reload") remove_configs(domain) print("remove configs") basics.command("service php5-fpm reload") print("service php5-fpm reload") move_folder(domain, homeRoot) print("move folder") delete_user(domain) # delete user with home dir print("delete user") else: print("value is no valid vhost")
def create_www_user(): global domain, homeRoot if(basics.command("grep --quiet \"" + domain + "\" /etc/passwd")): basics.command("adduser --force-badname --disabled-password --gecos \"\" --home \""+ homeRoot + "/" + domain +"\" --shell /bin/bash \"" + domain + "\"") #basics.command("usermod --append --groups www-data") basics.command("usermod --append --groups www-data \""+ domain +"\"")