diff --git a/scripts/webapps/delete_app_apache.py b/scripts/webapps/delete_app_apache.py new file mode 100644 index 0000000..31be715 --- /dev/null +++ b/scripts/webapps/delete_app_apache.py @@ -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..') diff --git a/scripts/webapps/delete_wordpress.py b/scripts/webapps/delete_wordpress.py new file mode 100644 index 0000000..4c6adc3 --- /dev/null +++ b/scripts/webapps/delete_wordpress.py @@ -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..') diff --git a/tasks/apache/scripts/delete_app.py b/tasks/apache/scripts/delete_app.py new file mode 100644 index 0000000..f4f21bb --- /dev/null +++ b/tasks/apache/scripts/delete_app.py @@ -0,0 +1,172 @@ +#!/usr/bin/python3 -u + +from collections import OrderedDict +import os +#from modules.pastafari2.models.servers import Server +from modules.apache.models.webservers import WebServer, VirtualHost +import json + +from modules.pastafari2.libraries.task import Task +from modules.apache.libraries.webapptask import WebAppTask +from modules.pastafari2.models.pastafari2 import ServerDbTask +from paramecio2.libraries.db import coreforms +from paramecio2.libraries.i18n import I18n +from paramecio2.libraries.formsutils import show_form +from paramecio2.libraries.db.extrafields.usernamefield import UserNameField +from paramecio2.libraries.db.extrafields.emailfield import EmailField +from paramecio2.libraries.db.extrafields.urlfield import DomainField +from paramecio2.libraries.urls import make_url +from modules.apache.admin.install_apps import scripts_lists +from flask import request + +class ServerTask(WebAppTask): + + def __init__(self, server, conn, remote_user='root', remote_password='', private_key='./ssh/id_rsa', password_key='', remote_path='pastafari2', task_id=0, data={}, port=22): + + super().__init__(server, conn, remote_user, remote_password, private_key, password_key, remote_path, task_id, data, port) + + self.name_task='Uninstall a webapp using a simple script' + + self.description_task='Drop application using a script' + + self.codename_task='apache_webserver_delete_app' + + self.files=[] + + #THe files to delete + + self.delete_files=[] + + self.delete_directories=['modules/apache/scripts'] + + self.path_module='admin_app.webservers' + + self.links='
{} >> {} >> {}'.format(make_url('webservers/servers'), I18n.lang('webservers', 'webservers_list', 'Webservers list'), make_url('webservers/virtualhost/'+str(self.webserver_id)), I18n.lang('webservers', 'websites', 'Websites'), make_url('webapps/'+str(self.data['virtualhost_id'])), I18n.lang('webservers', 'webapps', 'Webapps')) + + self.arr_form=OrderedDict() + + self.arr_form['webapp_id']=coreforms.HiddenForm('webapp_id', '') + + self.arr_form['webapp_id'].required=True + + self.arr_form['webapp']=coreforms.BaseForm('webapp', '') + + self.arr_form['webapp'].required=True + + self.arr_form['webapp'].label=I18n.lang('webapps', 'put_the_webapp_name_for_delete', 'Fill with the webapp name for delete') + + self.delete_task=True + + self.code_app='' + + def form(self, t, yes_error=False, pass_values=False, values={}): + + #Here load the form for it task + + webapp=request.args.get('webapp', '') + + #webapp_name=scripts_lists[webapp][0] + + webapp_id=request.args.get('webapp_id', '0') + + with self.connection.query('select * from webapp where id=%s', [webapp_id]) as cursor: + arr_webapp=cursor.fetchone() + + webapp_name=arr_webapp['app_name'] + + self.arr_form['webapp_id'].default_value=webapp_id + + return '