Added delete flask webapp
This commit is contained in:
parent
4f7d88f995
commit
90990ab1c0
10 changed files with 969 additions and 2 deletions
|
|
@ -124,7 +124,7 @@ class ServerTask(WebAppTask):
|
|||
|
||||
self.code_app=arr_webapp['code']
|
||||
|
||||
self.files.append(['modules/apache/scripts/webapps/delete_'+arr_webapp['app_type']+'.py', 0o700])
|
||||
self.files.append(['modules/apache/scripts/webapps/'+arr_webapp['app_type']+'/delete_'+arr_webapp['app_type']+'.py', 0o700])
|
||||
self.files.append(['modules/apache/scripts/webapps/delete_app_apache.py', 0o700])
|
||||
|
||||
home_user=arr_webapp['home']+'/htdocs/'
|
||||
|
|
@ -145,7 +145,7 @@ class ServerTask(WebAppTask):
|
|||
|
||||
#python3 delete_app_apache.py --domain prueba.cuchulu.com --webapp wordpress
|
||||
|
||||
self.commands_to_execute.append(['modules/apache/scripts/webapps/delete_'+arr_webapp['app_type']+'.py', '--user=%s --home_user=%s %s' % (arr_webapp['username'], home_user, db_opts)])
|
||||
self.commands_to_execute.append(['modules/apache/scripts/webapps/'+arr_webapp['app_type']+'/delete_'+arr_webapp['app_type']+'.py', '--user=%s --home_user=%s %s' % (arr_webapp['username'], home_user, db_opts)])
|
||||
|
||||
self.commands_to_execute.append(['modules/apache/scripts/webapps/delete_app_apache.py', '--domain={} --webapp={}'.format(arr_webapp['domain'], arr_webapp['app_name'])])
|
||||
|
||||
|
|
|
|||
202
tasks/apache/scripts/flask.py
Normal file
202
tasks/apache/scripts/flask.py
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
#/usr/bin/env python3
|
||||
|
||||
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.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, GitUrlField
|
||||
from modules.apache.libraries.webapptask import WebAppTask
|
||||
from flask import url_for, request
|
||||
import re
|
||||
|
||||
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='Install Flask app in an Apache Httpd Server'
|
||||
|
||||
self.description_task='Install Flask app using git in an Apache Httpd Server.'
|
||||
|
||||
self.codename_task='apache_webserver_flask'
|
||||
|
||||
self.files=[['modules/apache/scripts/webapps/flask/install_flask_site.py', 0o700]]
|
||||
|
||||
#THe files to delete
|
||||
|
||||
self.delete_files=[]
|
||||
|
||||
self.delete_directories=['modules/apache/scripts']
|
||||
|
||||
self.arr_form=OrderedDict()
|
||||
|
||||
self.arr_form['path']=coreforms.BaseForm('path', '')
|
||||
|
||||
self.arr_form['path'].required=True
|
||||
|
||||
self.arr_form['path'].label='The path of flask application'
|
||||
self.arr_form['path'].help='The path of flask application. <p>For example, if you have a domain called http://example.com, if you install in / path, you access to flask app, directly in http://example.com. <br />If you add path to /webapp/, the flask webapp site will be accesible using http://example.com/webapp'
|
||||
|
||||
self.arr_form['git_url']=coreforms.BaseForm('git_url', '')
|
||||
|
||||
self.arr_form['git_url'].required=True
|
||||
|
||||
self.arr_form['git_url'].label='The git url used for get the flask app'
|
||||
self.arr_form['git_url'].help='The git url used for get the flask app. Pastafari get the last tag of the git repo and install it in webserver'
|
||||
|
||||
self.arr_form['dependencies']=coreforms.BaseForm('dependencies', '')
|
||||
|
||||
#self.arr_form['dependencies'].required=True
|
||||
|
||||
self.arr_form['dependencies'].label='The python dependencies of the app'
|
||||
|
||||
self.arr_form['dependencies'].help='The python dependencies of the app separated by commas. If your application need extra dependencies, for example, pymysql or paramiko, use this string in form: pymsql,paramiko'
|
||||
|
||||
self.arr_form['app_flask']=coreforms.BaseForm('app_flask', '')
|
||||
|
||||
self.arr_form['app_flask'].required=True
|
||||
|
||||
self.arr_form['app_flask'].label='The app flask string used for gunicorn.'
|
||||
|
||||
self.arr_form['app_flask'].help='The app flask string used for gunicorn. If you have a principal file of gunicorn called app, with a flask app called "app", you can use app:app'
|
||||
|
||||
|
||||
def pre_task(self):
|
||||
|
||||
if not super().pre_task():
|
||||
return False
|
||||
|
||||
##python3 install_flask_site.py --domain red.cuchulu.com --home_user /home/absurdo/sites/red.cuchulu.com/superapp/ --git_url https://webtsys@bitbucket.org/paramecio/flasktest.git --user=absurdo --dependencies=paramiko,pymysql --app_flask=app:app --path /superapp/
|
||||
|
||||
install_flask='--domain %s --home_user %s --git_url %s --user %s --dependencies=%s --app_flask %s --path %s' % (self.data['domain'], self.data['home_user'], self.data['git_url'], self.data['username'], self.data['dependencies'], self.data['app_flask'], self.data['path'])
|
||||
|
||||
self.commands_to_execute.append(['modules/apache/scripts/webapps/flask/install_flask_site.py', install_flask])
|
||||
|
||||
|
||||
|
||||
return True
|
||||
|
||||
def form(self, t, yes_error=False, pass_values=False, values={}):
|
||||
|
||||
#Here load the form for it task
|
||||
|
||||
return '<h2>'+I18n.lang('webservers', 'add_flask_site', 'Add flask site')+'</h2>'+show_form(values, self.arr_form, t, yes_error, pass_values)
|
||||
|
||||
def check_form(self, post):
|
||||
|
||||
return_val=True
|
||||
|
||||
usernamefield=UserNameField('user')
|
||||
|
||||
urlfield=GitUrlField('git_url')
|
||||
|
||||
path=post['path'].strip()
|
||||
|
||||
if 'path' in post:
|
||||
if path=='':
|
||||
|
||||
self.arr_form['path'].error=True
|
||||
self.arr_form['path'].txt_error='Empty value.'
|
||||
|
||||
return_val=False
|
||||
|
||||
git_url=urlfield.check(request.form.get('git_url', ''))
|
||||
|
||||
if git_url=='':
|
||||
self.arr_form['git_url'].error=True
|
||||
self.arr_form['git_url'].txt_error='Wrong value for http git url.'
|
||||
|
||||
return_val=False
|
||||
|
||||
app_flask=request.form.get('app_flask')
|
||||
|
||||
if not re.match('\w+:\w+', app_flask):
|
||||
self.arr_form['app_flask'].error=True
|
||||
self.arr_form['app_flask'].txt_error='Bad format: the format must be app:app.'
|
||||
|
||||
return_val=False
|
||||
|
||||
dependencies=post['dependencies'].strip()
|
||||
|
||||
arr_dep=[]
|
||||
|
||||
if dependencies!='':
|
||||
arr_dep=[dep.strip() for dep in dependencies.split(',') if dep.strip()!='']
|
||||
|
||||
final_dependencies=''
|
||||
|
||||
if len(arr_dep)>0:
|
||||
final_dependencies=",".join(arr_dep)
|
||||
|
||||
virtualhost_id=self.data.get('virtualhost_id', '0')
|
||||
# ImmutableMultiDict([('send_task', '1'), ('amp;virtualhost_id', '42')])
|
||||
|
||||
#print(virtualhost_id)
|
||||
|
||||
domain=''
|
||||
home=''
|
||||
app_name=''
|
||||
|
||||
with self.connection.query('select domain, home, username from virtualhost where id=%s', [virtualhost_id]) as cursor:
|
||||
arr_virtualhost=cursor.fetchone()
|
||||
|
||||
if arr_virtualhost:
|
||||
domain=arr_virtualhost['domain']
|
||||
|
||||
home=arr_virtualhost['home']+'/flask/'
|
||||
|
||||
app_name='flask'
|
||||
|
||||
if path!='/':
|
||||
home=arr_virtualhost['home']+path
|
||||
app_name=os.path.basename(os.path.dirname(home))
|
||||
|
||||
username=arr_virtualhost['username']
|
||||
|
||||
if domain=='':
|
||||
return_val=False
|
||||
|
||||
if return_val:
|
||||
|
||||
# (self.data['user_wp'], self.data['password_wp'], self.data['mysql_user'], self.data['mysql_password'], self.data['mysql_db'], self.data['email_wp'], self.data['domain_wp'], self.data['title_wp'], self.data['mysql_host'], 3306)
|
||||
|
||||
self.data['domain']=domain
|
||||
self.data['path']=path
|
||||
|
||||
self.data['virtualhost_id']=virtualhost_id
|
||||
|
||||
self.data['home_user']=home
|
||||
self.data['username']=username
|
||||
self.data['webapp']=app_name
|
||||
self.data['dependencies']=final_dependencies
|
||||
|
||||
self.data['git_url']=git_url
|
||||
self.data['app_flask']=app_flask
|
||||
|
||||
return return_val
|
||||
|
||||
def post_task(self):
|
||||
|
||||
#virtualhost=VirtualHost(self.connection)
|
||||
|
||||
#virtualhost.safe_query()
|
||||
|
||||
#if not virtualhost.insert({'virtualhost_id': int(self.data['virtualhost_id']), 'app_name': 'wordpress', 'path': self.data['path']}):
|
||||
# return False
|
||||
#print(virtualhost.show_errors())
|
||||
|
||||
#virtua
|
||||
self.connection.query('insert into webapp (`virtualhost_id`, `app_name`, `app_type`, `path`, `data`) VALUES (%s, %s, %s, %s, %s)', [int(self.data['virtualhost_id']), self.data['webapp'], 'flask', self.data['path'], json.dumps(self.data)])
|
||||
|
||||
|
||||
return True
|
||||
212
tasks/apache/scripts/phpmyadmin.py
Normal file
212
tasks/apache/scripts/phpmyadmin.py
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
#/usr/bin/env python3
|
||||
|
||||
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
|
||||
import uuid
|
||||
|
||||
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='Install PHPMyAdmin in an Apache Httpd Server'
|
||||
|
||||
self.description_task='Installation of PhpMyAdmin site in an Apache httpd server.'
|
||||
|
||||
self.codename_task='apache_webserver_phpmyadmin'
|
||||
|
||||
#self.files=[['modules/apache/scripts/check_php.sh', 0o700], ['modules/apache/scripts/install_phpmyadmin_site.py', 0o700], ['modules/apache/scripts/add_php_vhost.py', 0o700]]
|
||||
self.files=[['modules/apache/scripts/webapps/phpmyadmin/install_phpmyadmin_site.py', 0o700]]
|
||||
|
||||
|
||||
#THe files to delete
|
||||
|
||||
self.delete_files=[]
|
||||
|
||||
self.delete_directories=['modules/apache/scripts']
|
||||
|
||||
self.arr_form=OrderedDict()
|
||||
|
||||
self.arr_form['path']=coreforms.BaseForm('path', '')
|
||||
|
||||
self.arr_form['path'].required=True
|
||||
|
||||
self.arr_form['path'].label='The path of phpmyadmin application'
|
||||
self.arr_form['path'].help='The path of phpmyadmin application. <p>For example, if you have a domain called http://example.com, if you install in / path, you access to wordpress, directly in http://example.com. <br />If you add path to /phpmyadmin/, the phpmyadmin site will be accesible using http://example.com/phpmyadmin'
|
||||
|
||||
self.arr_form['mysql_host']=coreforms.BaseForm('mysql_host', '')
|
||||
|
||||
self.arr_form['mysql_host'].required=True
|
||||
|
||||
self.arr_form['mysql_host'].label='The mysql/mariadb server used by phpmyadmin'
|
||||
self.arr_form['mysql_host'].help='You can get the host from "MariaDB servers" section in the control panel'
|
||||
|
||||
self.path_module='admin_app.webservers'
|
||||
|
||||
|
||||
def pre_task(self):
|
||||
|
||||
#self.commands_to_execute.append(['modules/apache/scripts/install_mariadb.py', '--password=%s' % self.extra_data['mysql_password']])
|
||||
|
||||
with self.connection.query('select php from virtualhost where id=%s', [self.data['virtualhost_id']]) as cursor:
|
||||
arr_virtualhost=cursor.fetchone()
|
||||
|
||||
|
||||
if arr_virtualhost['php']=='':
|
||||
|
||||
self.logtask.insert({'status':1, 'progress': 100, 'error': 1, 'task_id': self.id, 'server': self.server, 'message': 'You need install php for this virtualhost!'})
|
||||
|
||||
return False
|
||||
|
||||
if not super().pre_task():
|
||||
return False
|
||||
|
||||
#self.commands_to_execute.append(['modules/apache/scripts/check_php.sh', '8.2'])
|
||||
|
||||
#python3 install_phpmyadmin_site.py --home_user /home/developer/sites/enjoy.cuchulu.com/htdocs/ --user developer --path /sql/ --server_mysql localhost --port_mysql 3306 --domain enjoy.cuchulu.com
|
||||
#python3 install_phpmyadmin_site.py --home_user /home/developer/sites/enjoy.cuchulu.com/htdocs/ --user developer --server_mysql localhost --port_mysql 3306 --domain enjoy.cuchulu.com
|
||||
|
||||
path='--path='+self.data['path']
|
||||
|
||||
if path=='/':
|
||||
path=''
|
||||
pass
|
||||
|
||||
mysql_port=3306
|
||||
|
||||
#self.commands_to_execute.append(['modules/apache/scripts/install_phpmyadmin.sh', '%s %s %s' % (self.data['home'], self.data['mysql_host'], self.data['username'])])
|
||||
self.commands_to_execute.append(['modules/apache/scripts/webapps/phpmyadmin/install_phpmyadmin_site.py', '--home_user=%s --user=%s %s --server_mysql=%s --port_mysql=%i --domain=%s --php_version=%s' % (self.data['home'], self.data['username'], path, self.data['mysql_host'], mysql_port, self.data['domain'], arr_virtualhost['php'])])
|
||||
|
||||
#self.commands_to_execute.append(['modules/apache/scripts/add_php_vhost.py', '--user=%s --php_version=8.2 --domain=%s' % (self.data['username'], self.data['domain']), 'sudo'])
|
||||
|
||||
return True
|
||||
|
||||
def form(self, t, yes_error=False, pass_values=False, values={}):
|
||||
|
||||
#Here load the form for it task
|
||||
|
||||
return '<h2>'+I18n.lang('webservers', 'add_phpmyadmin_site', 'Add PHPMyAdmin')+'</h2>'+show_form(values, self.arr_form, t, yes_error, pass_values)
|
||||
|
||||
def check_form(self, post):
|
||||
|
||||
return_val=True
|
||||
|
||||
if 'mysql_host' in post:
|
||||
|
||||
#for i in ('mysql_host'):
|
||||
if post['mysql_host'].strip()=='':
|
||||
|
||||
self.arr_form['mysql_host'].error=True
|
||||
self.arr_form['mysql_host'].txt_error='Empty value.'
|
||||
|
||||
return_val=False
|
||||
|
||||
else:
|
||||
return_val=False
|
||||
|
||||
path=''
|
||||
|
||||
if 'path' in post:
|
||||
|
||||
path=post['path'].strip()
|
||||
|
||||
if path=='':
|
||||
|
||||
self.arr_form['path'].error=True
|
||||
self.arr_form['path'].txt_error='Empty value.'
|
||||
|
||||
return_val=False
|
||||
|
||||
virtualhost_id=self.data.get('virtualhost_id')
|
||||
|
||||
with self.connection.query('select domain, home, username from virtualhost where id=%s', [virtualhost_id]) as cursor:
|
||||
arr_virtualhost=cursor.fetchone()
|
||||
|
||||
if arr_virtualhost:
|
||||
domain=arr_virtualhost['domain']
|
||||
home=arr_virtualhost['home']+'/htdocs/'
|
||||
username=arr_virtualhost['username']
|
||||
|
||||
if domain=='':
|
||||
return_val=False
|
||||
|
||||
if return_val:
|
||||
|
||||
# (self.data['user_wp'], self.data['password_wp'], self.data['mysql_user'], self.data['mysql_password'], self.data['mysql_db'], self.data['email_wp'], self.data['domain_wp'], self.data['title_wp'], self.data['mysql_host'], 3306)
|
||||
|
||||
self.data['path']=path
|
||||
|
||||
self.data['mysql_host']=post['mysql_host'].strip()
|
||||
|
||||
self.data['virtualhost_id']=virtualhost_id
|
||||
self.data['domain']=domain
|
||||
self.data['home']=home
|
||||
self.data['username']=username
|
||||
self.data['webapp']='phpmyadmin'
|
||||
|
||||
return return_val
|
||||
|
||||
def post_task(self):
|
||||
|
||||
#virtualhost=VirtualHost(self.connection)
|
||||
|
||||
#virtualhost.safe_query()
|
||||
|
||||
#if not virtualhost.insert({'virtualhost_id': int(self.data['virtualhost_id']), 'app_name': 'wordpress', 'path': self.data['path']}):
|
||||
# return False
|
||||
#print(virtualhost.show_errors())
|
||||
|
||||
#virtua
|
||||
|
||||
app_name=os.path.basename(os.path.dirname(self.data['path']))
|
||||
|
||||
if app_name=='':
|
||||
app_name='phpmyadmin'
|
||||
|
||||
code_webapp=uuid.uuid4()
|
||||
|
||||
self.connection.query('insert into webapp (`virtualhost_id`, `app_name`, `app_type`, `path`, `data`, `code`) VALUES (%s, %s, %s, %s, "{}", %s)', [int(self.data['virtualhost_id']), app_name, 'phpmyadmin', self.data['path'], code_webapp])
|
||||
|
||||
"""
|
||||
| id | int(11) | NO | PRI | NULL | auto_increment |
|
||||
| name | varchar(255) | NO | | | |
|
||||
| file | varchar(255) | NO | | | |
|
||||
| server_id | int(11) | YES | MUL | NULL | |
|
||||
| position | int(11) | NO | | 0 | |
|
||||
"""
|
||||
|
||||
with self.connection.query('select id from serverdbtask where ip=%s', [self.server]) as cursor:
|
||||
arr_server=cursor.fetchone()
|
||||
|
||||
with self.connection.query('select domain, home, username from virtualhost where id=%s', [self.data['virtualhost_id']]) as cursor:
|
||||
arr_virtualhost=cursor.fetchone()
|
||||
|
||||
if arr_virtualhost:
|
||||
domain=arr_virtualhost['domain']
|
||||
|
||||
if self.data['path']=='/':
|
||||
|
||||
home=arr_virtualhost['home']+'/htdocs/'
|
||||
|
||||
else:
|
||||
home=arr_virtualhost['home']+self.data['path']
|
||||
|
||||
args='--user={} --home_user={}'.format(self.data['username'], home)
|
||||
|
||||
self.connection.query('insert into updateserverscripts (`name`, `file`, `args`, `server_id`, `position`, `code`) VALUES (%s, %s, %s, %s, %s, %s)', ['phpadmin update', './modules/apache/scripts/webapps/phpmyadmin/update_phpmyadmin.py', args, arr_server['id'], 20, code_webapp])
|
||||
|
||||
return True
|
||||
Loading…
Add table
Add a link
Reference in a new issue