from modules.pastafari2.libraries.task import Task from flask import url_for from paramecio2.libraries.i18n import I18n import re from paramecio2.libraries.urls import make_url class WebAppTask(Task): def __init__(self, server, conn, remote_user='root', remote_password='', private_key='./ssh/id_rsa', password_key='', remote_path='pastafari2', task_id=0, data={}, ssh_port=22): super().__init__(server, conn, remote_user, remote_password, private_key, password_key, remote_path, task_id, data, ssh_port) self.path_module='admin_app.webservers' webserver_id=0 with self.connection.query('select webserver_id from virtualhost WHERE id=%s', [self.data['virtualhost_id']]) as cursor: arr_vhost=cursor.fetchone() if arr_vhost: webserver_id=arr_vhost['webserver_id'] self.webserver_id=webserver_id #
Webservers list >> Websites >> Webapps >> Add webapp
self.links=''.format(make_url('webservers/servers'), I18n.lang('webservers', 'webservers_list', 'Webservers list'), make_url('webservers/virtualhost/'+str(webserver_id)), I18n.lang('webservers', 'websites', 'Websites'), make_url('webapps/'+str(self.data['virtualhost_id'])), I18n.lang('webservers', 'webapps', 'Webapps'), make_url('add_new_app/'+str(self.data['virtualhost_id'])), I18n.lang('webservers', 'add_webapp', 'Add webapp')) self.delete_task=False def pre_task(self): if not self.delete_task: with self.connection.query('select count(*) as num_webapps from webapp where path=%s and virtualhost_id=%s', [self.data['path'], self.data['virtualhost_id']]) as cursor: arr_webapp=cursor.fetchone() if arr_webapp['num_webapps']>0: self.logtask.insert({'status':1, 'progress': 100, 'error': 1, 'task_id': self.id, 'server': self.server, 'message': 'Error: exists an app in the same path %s or exists a webapp %s with the same system, you can install one by domain' % (self.data['path'], self.data['webapp'])}) return False if self.data['path']!='/' and not re.match('^/[\w.-]*/$', self.data['path'].strip()): self.logtask.insert({'status':1, 'progress': 100, 'error': 1, 'task_id': self.id, 'server': self.server, 'message': 'Error: format wrong for path, you need this format / or /path/ '+self.data['path']}) return False #self.data['url_return']=make_url('webapps/'+str(self.data['virtualhost_id'])) return True