Added support to delete webapps
This commit is contained in:
parent
25aaa0a4bf
commit
4f7d88f995
4 changed files with 288 additions and 1 deletions
60
scripts/webapps/delete_app_apache.py
Normal file
60
scripts/webapps/delete_app_apache.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/python3 -u
|
||||
|
||||
import argparse
|
||||
import os
|
||||
#from pastafariutils.unix import add_user, del_user
|
||||
from pathlib import Path
|
||||
from subprocess import call, DEVNULL
|
||||
import json
|
||||
import time
|
||||
import shutil
|
||||
import pwd
|
||||
import distro
|
||||
import subprocess
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
parser=argparse.ArgumentParser(prog='delete_wordpress.py', description='A tool for delete wordpress')
|
||||
|
||||
parser.add_argument('--domain', help='Domain to delete', required=True)
|
||||
parser.add_argument('--webapp', help='Webapp config to delete', required=True)
|
||||
|
||||
args=parser.parse_args()
|
||||
|
||||
apache_cmd='apache2'
|
||||
|
||||
apachectl='apache2ctl'
|
||||
|
||||
linux_distro=distro.id()
|
||||
|
||||
if linux_distro!='debian' and linux_distro!='ubuntu':
|
||||
apache_cmd='httpd'
|
||||
apachectl='apachectl'
|
||||
|
||||
print('Deleting the apache configuration of webapp..')
|
||||
|
||||
# /etc/httpd/vhosts.d/php/prueba.cuchulu.com-php.conf
|
||||
"""
|
||||
apache_php='/etc/{}/vhosts.d/php/{}-php.conf'.format(apache_cmd, args.domain)
|
||||
|
||||
if os.path.isfile(apache_php):
|
||||
if subprocess.call("sudo rm %s" % (apache_php), shell=True) > 0:
|
||||
print('Error: cannot delete php config %s' % apache_php)
|
||||
sys.exit(1)
|
||||
"""
|
||||
|
||||
# /etc/httpd/vhosts.d/extra/prueba.cuchulu.com-wordpress.conf
|
||||
|
||||
apache_webapp='/etc/{}/vhosts.d/extra/{}-{}.conf'.format(apache_cmd, args.domain, args.webapp)
|
||||
|
||||
if os.path.isfile(apache_webapp):
|
||||
if subprocess.call("sudo rm %s" % (apache_webapp), shell=True) > 0:
|
||||
print('Error: cannot delete webapp config %s' % apache_webapp)
|
||||
sys.exit(1)
|
||||
|
||||
if subprocess.call("sudo systemctl restart %s" % (apache_cmd), shell=True) > 0:
|
||||
print('Error: cannot restart Apache server')
|
||||
sys.exit(1)
|
||||
|
||||
print('Deleted the apache configuration of webapp successfully..')
|
||||
55
scripts/webapps/delete_wordpress.py
Normal file
55
scripts/webapps/delete_wordpress.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/python3 -u
|
||||
|
||||
import argparse
|
||||
import os
|
||||
#from pastafariutils.unix import add_user, del_user
|
||||
from pathlib import Path
|
||||
from subprocess import call, DEVNULL
|
||||
import json
|
||||
import time
|
||||
import shutil
|
||||
import pwd
|
||||
import distro
|
||||
import subprocess
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
parser=argparse.ArgumentParser(prog='delete_wordpress.py', description='A tool for delete wordpress')
|
||||
|
||||
parser.add_argument('--home_user', help='Home where wordpress resides', required=True)
|
||||
parser.add_argument('--user', help='The user', required=True)
|
||||
parser.add_argument('--mysql_host', help='The host of mysql', required=True)
|
||||
parser.add_argument('--mysql_db', help='The db to clean', required=True)
|
||||
|
||||
print('Deleting Wordpress..')
|
||||
|
||||
args=parser.parse_args()
|
||||
|
||||
home_user=args.home_user
|
||||
|
||||
if home_user.find('/htdocs/', -8)!=-1:
|
||||
|
||||
if subprocess.call("sudo su %s -s /bin/bash -c 'rm -f -r %s && mkdir %s'" % (args.user, args.home_user, args.home_user), shell=True) > 0:
|
||||
print('Error: cannot delete %s' % args.home_user)
|
||||
sys.exit(1)
|
||||
|
||||
else:
|
||||
|
||||
if subprocess.call("sudo su %s -s /bin/bash -c 'rm -f -r %s'" % (args.user, args.home_user), shell=True) > 0:
|
||||
print('Error: cannot delete %s' % args.home_user)
|
||||
sys.exit(1)
|
||||
|
||||
print('Deleting Database if in localhost..')
|
||||
|
||||
if args.mysql_host=='127.0.0.1' or args.mysql_host=='localhost':
|
||||
|
||||
if subprocess.call("sudo mysql --execute=\"drop database %s\"" % (args.mysql_db), shell=True) > 0:
|
||||
print('Error: cannot delete database %s' % args.mysql_db)
|
||||
sys.exit(1)
|
||||
|
||||
else:
|
||||
|
||||
print('I cannot delete db because are not in the same server, please, delete manually the db.')
|
||||
|
||||
print('Deleted Wordpress successfully..')
|
||||
Loading…
Add table
Add a link
Reference in a new issue