Added files
This commit is contained in:
commit
25aaa0a4bf
31 changed files with 4035 additions and 0 deletions
85
tasks/apache/apache/add_vhost.py
Normal file
85
tasks/apache/apache/add_vhost.py
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
#/usr/bin/env python3
|
||||
|
||||
from collections import OrderedDict
|
||||
#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
|
||||
#import distro
|
||||
|
||||
class ServerTask(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={}, port=22):
|
||||
|
||||
super().__init__(server, conn, remote_user, remote_password, private_key, password_key, remote_path, task_id, data, port)
|
||||
|
||||
self.name_task='Install virtualhost in servers'
|
||||
|
||||
self.description_task='Installation of an virtual host in a server, or many of them'
|
||||
|
||||
self.codename_task='virtualhost_apache'
|
||||
|
||||
self.files=[]
|
||||
|
||||
self.files=[['modules/apache/scripts/manage_apache.py', 0o755], ['modules/apache/scripts/files/vhost.tpl', 0o644]]
|
||||
|
||||
# Format first array element is command with the interpreter, the task is agnostic, the files in os directory. The commands are setted with 750 permission.
|
||||
# First element is the file, next elements are the arguments
|
||||
|
||||
self.commands_to_execute=[['modules/apache/scripts/manage_apache.py', '']]
|
||||
|
||||
#THe files to delete
|
||||
|
||||
self.delete_files=[]
|
||||
|
||||
self.delete_directories=['modules/apache/scripts']
|
||||
|
||||
#self.task=Task(conn)
|
||||
|
||||
self.one_time=False
|
||||
|
||||
self.version='1.0'
|
||||
|
||||
self.path_module='admin_app.apache'
|
||||
|
||||
|
||||
def pre_task(self):
|
||||
|
||||
#self.commands_to_execute=[['modules/apache/scripts/manager/${os_server}/manage_apache.py', '--password=%s' % self.extra_data['mysql_password']]]
|
||||
|
||||
# usage: manager.py [-h] --operation OPERATION --domain DOMAIN [--email EMAIL] [--user USER] [--root_dir ROOT_DIR] [--indexes] [--allow_override]
|
||||
|
||||
indexes=''
|
||||
|
||||
if 'indexes' in self.data:
|
||||
indexes='--indexes'
|
||||
|
||||
#allow_override=''
|
||||
|
||||
#if 'allow_override' in self.data:
|
||||
allow_override='--allow_override'
|
||||
|
||||
password=''
|
||||
|
||||
if self.data.get('password', '')!='':
|
||||
password='--password=%s' % self.data.get('password', '')
|
||||
|
||||
self.commands_to_execute=[['modules/apache/scripts/manage_apache.py', '--operation=add --domain=%s --email=%s --user=%s --root_dir=%s --type_cgi=%s --ip=%s --port=%s %s %s %s' % (self.data['domain'], self.data['email'], self.data['user'], self.data['root_dir'], self.data['cgi_type'], self.data['ip'], self.data['port'], password, indexes, allow_override), 'sudo']]
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def post_task(self):
|
||||
|
||||
#real_root_dir=args.root_dir+'/'+args.domain+'/htdocs'
|
||||
|
||||
vhost=VirtualHost(self.connection)
|
||||
vhost.safe_query()
|
||||
|
||||
#vhost.insert({'servers': servers, 'principal_ip': servers[0], 'domain': self.extra_data['domain'], 'email': self.extra_data['email'], 'user': self.extra_data['user'], 'root_dir': self.extra_data['root_dir'], 'indexes': self.extra_data['indexes'], 'allow_override': self.extra_data['allow_override']})
|
||||
if not vhost.insert({'domain': self.data['domain'], 'username': self.data['user'], 'home': self.data['root_dir'], 'webserver_id': self.data['webserver_id'], 'ip': self.data['ip'], 'allow_override': 1}):
|
||||
return False
|
||||
|
||||
return True
|
||||
180
tasks/apache/apache/edit_vhost.py
Normal file
180
tasks/apache/apache/edit_vhost.py
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
#/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.pastafari2.models.pastafari2 import ServerDbTask
|
||||
#import distro
|
||||
|
||||
class ServerTask(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={}, port=22):
|
||||
|
||||
super().__init__(server, conn, remote_user, remote_password, private_key, password_key, remote_path, task_id, data, port)
|
||||
|
||||
self.name_task='Edit virtualhost in server'
|
||||
|
||||
self.description_task='Edot a virtual host in a server, or many of them'
|
||||
|
||||
self.codename_task='edit_virtualhost_apache'
|
||||
|
||||
self.files=[]
|
||||
|
||||
self.files=[['modules/apache/scripts/manage_apache.py', 0o755], ['modules/apache/scripts/files/vhost.tpl', 0o644]]
|
||||
|
||||
if self.data['ssl']=='2':
|
||||
|
||||
ssl_crt='modules/apache/scripts/files/'+self.data['domain']+'-ssl.crt'
|
||||
ssl_key='modules/apache/scripts/files/'+self.data['domain']+'-ssl.key'
|
||||
|
||||
if os.path.isfile(ssl_crt):
|
||||
self.files.append([ssl_crt, 0o644])
|
||||
self.files.append([ssl_key, 0o644])
|
||||
|
||||
pass
|
||||
|
||||
|
||||
# Format first array element is command with the interpreter, the task is agnostic, the files in os directory. The commands are setted with 750 permission.
|
||||
# First element is the file, next elements are the arguments
|
||||
|
||||
self.commands_to_execute=[['modules/apache/scripts/manage_apache.py', '']]
|
||||
|
||||
#THe files to delete
|
||||
|
||||
self.delete_files=[]
|
||||
|
||||
self.delete_directories=['modules/apache/scripts']
|
||||
|
||||
#self.task=Task(conn)
|
||||
|
||||
self.one_time=False
|
||||
|
||||
self.version='1.0'
|
||||
|
||||
self.path_module='admin_app.webservers'
|
||||
|
||||
"""
|
||||
self.arr_form=OrderedDict()
|
||||
|
||||
self.arr_form['mysql_password']=coreforms.PasswordForm('mysql_password', '')
|
||||
|
||||
self.arr_form['mysql_password'].required=True
|
||||
|
||||
self.arr_form['mysql_password'].label='The MySQL password used by all servers'
|
||||
|
||||
self.arr_form['repeat_mysql_password']=coreforms.PasswordForm('repeat_mysql_password', '')
|
||||
|
||||
self.arr_form['repeat_mysql_password'].required=True
|
||||
|
||||
self.arr_form['repeat_mysql_password'].label='Repeat MySQL password'
|
||||
"""
|
||||
|
||||
def pre_task(self):
|
||||
|
||||
#self.commands_to_execute=[['modules/apache/scripts/manager/${os_server}/manage_apache.py', '--password=%s' % self.extra_data['mysql_password']]]
|
||||
|
||||
# usage: manager.py [-h] --operation OPERATION --domain DOMAIN [--email EMAIL] [--user USER] [--root_dir ROOT_DIR] [--indexes] [--allow_override]
|
||||
|
||||
self.commands_to_execute=[]
|
||||
|
||||
indexes=''
|
||||
|
||||
if 'indexes' in self.data:
|
||||
if self.data['indexes']=='1':
|
||||
indexes='--indexes'
|
||||
|
||||
allow_override=''
|
||||
|
||||
if 'allow_override' in self.data:
|
||||
if self.data['allow_override']=='1':
|
||||
allow_override='--allow_override'
|
||||
|
||||
redirect_ssl=''
|
||||
|
||||
if 'redirect_ssl' in self.data:
|
||||
if self.data['redirect_ssl']=='1':
|
||||
redirect_ssl='--redirect_ssl'
|
||||
|
||||
php_support=''
|
||||
|
||||
if self.data['php']!='':
|
||||
php_support='--php_version='+self.data['php']
|
||||
|
||||
self.files.append(['modules/apache/scripts/check_php.sh', 0o700])
|
||||
self.files.append(['modules/apache/scripts/add_php_vhost.py', 0o700])
|
||||
|
||||
self.commands_to_execute.append(['modules/apache/scripts/check_php.sh', self.data['php']])
|
||||
|
||||
self.commands_to_execute.append(['modules/apache/scripts/add_php_vhost.py', '--user=%s --php_version=%s --domain=%s' % (self.data['user'], self.data['php'], self.data['domain']), 'sudo'])
|
||||
|
||||
else:
|
||||
|
||||
self.files.append(['modules/apache/scripts/delete_php.py', 0o700])
|
||||
self.commands_to_execute.append(['modules/apache/scripts/delete_php.py', '--domain=%s' % self.data['domain']])
|
||||
|
||||
|
||||
self.commands_to_execute.append(['modules/apache/scripts/manage_apache.py', '--operation=edit --domain=%s --email=%s --user=%s --root_dir=%s --type_cgi=%s --ip=%s --port=%s --ssl=%s --ssl_port=%s --aliases=%s %s %s %s' % (self.data['domain'], self.data['email'], self.data['user'], self.data['root_dir'], self.data['cgi_type'], self.data['ip'], self.data['port'], self.data['ssl'], self.data['ssl_port'], self.data['aliases'], indexes, allow_override, redirect_ssl), 'sudo'])
|
||||
#print(self.commands_to_execute[0])
|
||||
return True
|
||||
"""
|
||||
def form(self, t, yes_error=False, pass_values=False, values={}):
|
||||
|
||||
#Here load the form for it task
|
||||
|
||||
return '<h2>Mariadb/MySQL configuration</h2>'+show_form(values, self.arr_form, t, yes_error, pass_values)
|
||||
|
||||
def check_form(self, post):
|
||||
|
||||
if 'mysql_password' in post and 'repeat_mysql_password' in post:
|
||||
|
||||
if post['mysql_password'].strip()!='' and post['mysql_password']==post['repeat_mysql_password']:
|
||||
|
||||
self.extra_data={'mysql_password': post['mysql_password'].strip()}
|
||||
return True
|
||||
|
||||
else:
|
||||
|
||||
self.arr_form['mysql_password'].txt_error='Passwords doesn\'t match'
|
||||
|
||||
return False
|
||||
"""
|
||||
"""
|
||||
def post_task(self):
|
||||
|
||||
server=Server(self.connection)
|
||||
|
||||
hostname=server.set_conditions('WHERE ip=%s', [self.server]).select_a_row_where()['hostname']
|
||||
|
||||
webserver=WebServer(self.connection)
|
||||
webserver.safe_query()
|
||||
|
||||
data={'hostname': hostname, 'ip': self.server}
|
||||
|
||||
webserver.insert(data)
|
||||
|
||||
return True
|
||||
"""
|
||||
|
||||
def post_task(self):
|
||||
|
||||
#real_root_dir=args.root_dir+'/'+args.domain+'/htdocs'
|
||||
|
||||
vhost=VirtualHost(self.connection)
|
||||
vhost.safe_query()
|
||||
|
||||
ssl_crt='modules/apache/scripts/files/'+self.data['domain']+'-ssl.crt'
|
||||
ssl_key='modules/apache/scripts/files/'+self.data['domain']+'-ssl.key'
|
||||
|
||||
if os.path.isfile(ssl_crt):
|
||||
os.remove(ssl_crt)
|
||||
os.remove(ssl_key)
|
||||
|
||||
#vhost.insert({'servers': servers, 'principal_ip': servers[0], 'domain': self.extra_data['domain'], 'email': self.extra_data['email'], 'user': self.extra_data['user'], 'root_dir': self.extra_data['root_dir'], 'indexes': self.extra_data['indexes'], 'allow_override': self.extra_data['allow_override']})
|
||||
if not vhost.set_conditions('WHERE id=%s', [self.data['virtualhost_id']]).update({'domain': self.data['domain'], 'home': self.data['root_dir'], 'webserver_id': self.data['webserver_id'], 'indexes': self.data['indexes'], 'allow_override': self.data['allow_override'], 'port': self.data['port'], 'aliases': self.data['aliases'], 'ip': self.data['ip'], 'redirect_ssl': self.data['redirect_ssl'], 'ssl_port': self.data['ssl_port'], 'ssl': self.data['ssl'], 'php': self.data.get('php', '')}):
|
||||
return False
|
||||
|
||||
return True
|
||||
86
tasks/apache/apache/install_apache.py
Normal file
86
tasks/apache/apache/install_apache.py
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
#!/opt/pythonenv/bin/python3 -u
|
||||
|
||||
from modules.pastafari2.libraries.task import Task
|
||||
#from modules.pastafari.models.tasks import TaskModel
|
||||
from paramecio2.libraries.db import coreforms
|
||||
from paramecio2.libraries.db.webmodel import WebModel
|
||||
from paramecio2.libraries.formsutils import show_form
|
||||
from collections import OrderedDict
|
||||
from modules.pastafari2.models.tasks import ResultTask
|
||||
from modules.pastafari2.models.pastafari2 import ServerDbTask
|
||||
from modules.apache.models.webservers import WebServer
|
||||
from settings import config
|
||||
import json
|
||||
|
||||
class ServerTask(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={}, port=22):
|
||||
|
||||
super().__init__(server, conn, remote_user, remote_password, private_key, password_key, remote_path, task_id, data, port)
|
||||
|
||||
self.name_task='Apache installation'
|
||||
|
||||
self.description_task='Installation of a Apache webserver'
|
||||
|
||||
self.codename_task='apache_webserver'
|
||||
|
||||
#['modules/webservers/scripts/install_quota_home.py', 0o700],
|
||||
|
||||
self.files=[['modules/apache/scripts/install_apache.php', 0o700]]
|
||||
|
||||
#self.commands_to_execute=[]
|
||||
|
||||
#self.commands_to_execute.append(['modules/webservers/scripts/add_httpd.py', ''])
|
||||
|
||||
#mysql_server=config.webserver_host_db
|
||||
|
||||
#mysql_db=WebModel.connections['default']['db']
|
||||
|
||||
#--mysql_server={} --mysql_db={} --mysql_user={} --mysql_pass={}'.format(mysql_server, mysql_db, config.webserver_user_db, config.webserver_user_pass)
|
||||
|
||||
self.commands_to_execute=[['php modules/apache/scripts/install_apache.php', '']]
|
||||
|
||||
#self.commands_to_execute.append(['modules/webservers/scripts/install_quota_home.py', '', 'sudo'])
|
||||
|
||||
#self.delete_files=['modules/webservers/scripts/add_httpd.py']
|
||||
|
||||
self.delete_directories=['modules/apache/scripts']
|
||||
|
||||
#self.task=Task(conn)
|
||||
|
||||
self.one_time=True
|
||||
|
||||
self.version='1.0'
|
||||
|
||||
|
||||
def post_task(self):
|
||||
|
||||
serverdb=ServerDbTask(self.connection)
|
||||
|
||||
server=WebServer(self.connection)
|
||||
|
||||
resulttask=ResultTask(self.connection)
|
||||
|
||||
#arr_result=resulttask.set_conditions('WHERE task_id=%s', [self.id]).select_a_row_where()
|
||||
|
||||
#result=json.loads(arr_result['message'])
|
||||
|
||||
#if arr_result:
|
||||
|
||||
|
||||
server.safe_query()
|
||||
|
||||
#'subdomain_id': self.data['subdomain_id']
|
||||
#arr_ids=json.loads(self.data['server_ids'])
|
||||
|
||||
#server.insert({'hostname': self.data['hostname'], 'ip': self.data['ip'], 'group_id': self.data['group_id']})
|
||||
#for server_id in arr_ids:
|
||||
# server.insert({'server_id': server_id})
|
||||
|
||||
arr_server=serverdb.set_conditions('WHERE ip=%s', [self.server]).select_a_row_where()
|
||||
|
||||
if arr_server:
|
||||
#server.insert({'server_id': arr_server['id'], 'username': result['username'], 'uid_hosting': result['uid'], 'gid_hosting': result['gid'], 'home': result['home']})
|
||||
server.insert({'server_id': arr_server['id']})
|
||||
|
||||
return True
|
||||
8
tasks/apache/info.cfg
Normal file
8
tasks/apache/info.cfg
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[info]
|
||||
name=Apache WebServer
|
||||
description=Install apachewebserver infraestructure
|
||||
|
||||
|
||||
[modules]
|
||||
apache/install_apache=Apache server, the best web server available on the Internet with unix users support
|
||||
|
||||
318
tasks/apache/scripts/wordpress.py
Normal file
318
tasks/apache/scripts/wordpress.py
Normal file
|
|
@ -0,0 +1,318 @@
|
|||
#/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
|
||||
from modules.apache.libraries.webapptask import WebAppTask
|
||||
from flask import url_for
|
||||
|
||||
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 Wordpress in an Apache Httpd Server'
|
||||
|
||||
self.description_task='Installation of Wordpress site in an Apache httpd server.'
|
||||
|
||||
self.codename_task='apache_webserver_wordpress'
|
||||
|
||||
#self.files=[['modules/webservers/scripts/check_php.sh', 0o700], ['modules/webservers/scripts/install_wp.sh', 0o700], ['modules/webservers/scripts/install_wordpress_site.py', 0o700], ['modules/webservers/scripts/add_php_vhost.py', 0o700]]
|
||||
|
||||
self.files=[ ['modules/apache/scripts/webapps/wordpress/install_wp.php', 0o700], ['modules/apache/scripts/webapps/wordpress/install_wordpress_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 wordpress application'
|
||||
self.arr_form['path'].help='The path of wordpress 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 /wordpress/, the wordpress site will be accesible using http://example.com/wordpress'
|
||||
|
||||
self.arr_form['user_wp']=coreforms.BaseForm('user_wp', '')
|
||||
|
||||
self.arr_form['user_wp'].required=True
|
||||
|
||||
self.arr_form['user_wp'].label='The admin username of wordpress site'
|
||||
self.arr_form['user_wp'].help='The username for the user used for admin the wordpress site via /wp-admin'
|
||||
|
||||
self.arr_form['email_wp']=coreforms.BaseForm('email_wp', '')
|
||||
|
||||
self.arr_form['email_wp'].required=True
|
||||
|
||||
self.arr_form['email_wp'].label='The admin email for notifications of wordpress site'
|
||||
|
||||
self.arr_form['title_wp']=coreforms.BaseForm('title_wp', '')
|
||||
|
||||
self.arr_form['title_wp'].required=True
|
||||
|
||||
self.arr_form['title_wp'].label='The title of the wordpress site'
|
||||
|
||||
|
||||
self.arr_form['password_wp']=coreforms.PasswordForm('password_wp', '')
|
||||
|
||||
self.arr_form['password_wp'].required=True
|
||||
|
||||
self.arr_form['password_wp'].label='The password for the admin user of wordpress site'
|
||||
self.arr_form['password_wp'].help='You need a password for login how admin user in wordpress site'
|
||||
|
||||
self.arr_form['repeat_password_wp']=coreforms.PasswordForm('repeat_password_wp', '')
|
||||
|
||||
self.arr_form['repeat_password_wp'].required=True
|
||||
|
||||
self.arr_form['repeat_password_wp'].label='Repeat the password for the admin user of wordpress site'
|
||||
|
||||
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 for the wordpress site'
|
||||
self.arr_form['mysql_host'].help='You can get the host from "MariaDB servers" section in the control panel'
|
||||
|
||||
self.arr_form['mysql_db']=coreforms.BaseForm('mysql_db', '')
|
||||
|
||||
self.arr_form['mysql_db'].required=True
|
||||
|
||||
self.arr_form['mysql_db'].label='The mysql/mariadb database name for the wordpress site'
|
||||
self.arr_form['mysql_db'].help='The database used for the wordpress site'
|
||||
|
||||
self.arr_form['mysql_user']=coreforms.BaseForm('mysql_user', '')
|
||||
|
||||
self.arr_form['mysql_user'].required=True
|
||||
|
||||
self.arr_form['mysql_user'].label='The mysql/mariadb user for the wordpress site'
|
||||
|
||||
self.arr_form['mysql_password']=coreforms.PasswordForm('mysql_password', '')
|
||||
|
||||
self.arr_form['mysql_password'].required=True
|
||||
|
||||
self.arr_form['mysql_password'].label='The password for the mysql/mariadb database user'
|
||||
|
||||
#self.arr_form['user_wp']=coreforms.BaseForm('user_wp', '')
|
||||
#self.arr_form['user_wp'].required=True
|
||||
"""
|
||||
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.links='<p><a href="{}">{}</a> >> <a href="{}">{}</a> >> <a href="{}">{}</a> >> <a href="{}">{}</a></p>'.format(url_for('admin_app.webservers'), I18n.lang('webservers', 'webservers_list', 'Webservers list'), url_for('admin_app.virtualhost', webserver_id=webserver_id), I18n.lang('webservers', 'websites', 'Websites'), url_for('admin_app.webapps', virtualhost_id=self.data['virtualhost_id']), I18n.lang('webservers', 'webapps', 'Webapps'), url_for('admin_app.add_new_app', virtualhost_id=self.data['virtualhost_id']), I18n.lang('webservers', 'add_webapp', 'Add webapp'))
|
||||
"""
|
||||
|
||||
#print(self.data)
|
||||
|
||||
#Webservers list >> Websites >> Webapps >> Add webapp
|
||||
#<p><a href="${url_for('admin_app.webservers')}">${lang('webservers', 'webservers_list', 'Webservers list')}</a> >> <a href="${url_for('admin_app.virtualhost', webserver_id=webserver_id)}">${lang('webservers', 'websites', 'Websites')}</a> >> ${lang('webservers', 'webapps', 'Webapps')}</p>
|
||||
|
||||
def pre_task(self):
|
||||
|
||||
if not super().pre_task():
|
||||
return False
|
||||
|
||||
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
|
||||
else:
|
||||
self.logtask.insert({'status':0, 'progress': 0, 'error': 0, 'task_id': self.id, 'server': self.server, 'message': 'PHP '+arr_virtualhost['php']+' is installed'})
|
||||
|
||||
#self.commands_to_execute.append(['modules/webservers/scripts/install_mariadb.py', '--password=%s' % self.extra_data['mysql_password']])
|
||||
|
||||
#self.commands_to_execute.append(['modules/webservers/scripts/check_php.sh', '8.2'])
|
||||
|
||||
self.commands_to_execute.append(['php', 'modules/apache/scripts/webapps/wordpress/install_wp.php'])
|
||||
|
||||
#self.commands_to_execute.append(['modules/webservers/scripts/add_php_vhost.py', '--user=%s --php_version=8.2 --domain=%s' % (self.data['username'], self.data['domain_wp']), 'sudo'])
|
||||
|
||||
install_wordpress='--home_user=%s --user=%s --password=%s --email=%s --domain=%s --title="%s" --db_mysql=%s --user_mysql=%s --password_mysql=%s --server_mysql=%s --port_mysql=%i --path=%s --php_version=%s' % (self.data['home'], self.data['user_wp'], self.data['password_wp'], self.data['email_wp'], self.data['domain_wp'], self.data['title_wp'], self.data['mysql_db'], self.data['mysql_user'], self.data['mysql_password'], self.data['mysql_host'], 3306, self.data['path'], arr_virtualhost['php'])
|
||||
|
||||
#print(install_wordpress)
|
||||
|
||||
self.commands_to_execute.append(['modules/apache/scripts/webapps/wordpress/install_wordpress_site.py', install_wordpress])
|
||||
|
||||
|
||||
|
||||
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_wordpress_site', 'Add wordpress site')+'</h2>'+show_form(values, self.arr_form, t, yes_error, pass_values)
|
||||
|
||||
def check_form(self, post):
|
||||
|
||||
usernamefield=UserNameField('user_wp')
|
||||
|
||||
emailfield=EmailField('email_wp')
|
||||
|
||||
return_val=True
|
||||
|
||||
if 'mysql_host' in post and 'mysql_user' in post and 'mysql_password' in post:
|
||||
|
||||
for i in ('mysql_host', 'mysql_user', 'mysql_password', 'mysql_db'):
|
||||
if post[i].strip()=='':
|
||||
|
||||
self.arr_form[i].error=True
|
||||
self.arr_form[i].txt_error='Empty value.'
|
||||
|
||||
return_val=False
|
||||
|
||||
else:
|
||||
return_val=False
|
||||
|
||||
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
|
||||
|
||||
|
||||
user_wp=usernamefield.check(post.get('user_wp'))
|
||||
|
||||
if user_wp=='':
|
||||
self.arr_form['user_wp'].error=True
|
||||
self.arr_form['user_wp'].txt_error='Invalid username.'
|
||||
|
||||
return_val=False
|
||||
|
||||
email_wp=emailfield.check(post.get('email_wp'))
|
||||
|
||||
if email_wp=='':
|
||||
self.arr_form['email_wp'].error=True
|
||||
self.arr_form['email_wp'].txt_error='Invalid email.'
|
||||
|
||||
return_val=False
|
||||
|
||||
title_wp=post.get('title_wp').strip().replace('"', '"')
|
||||
|
||||
if title_wp=='':
|
||||
self.arr_form['title_wp'].error=True
|
||||
self.arr_form['title_wp'].txt_error='Empty value.'
|
||||
|
||||
return_val=False
|
||||
|
||||
|
||||
password_wp=post.get('password_wp', '').strip()
|
||||
|
||||
if password_wp=='':
|
||||
|
||||
self.arr_form['password_wp'].error=True
|
||||
self.arr_form['password_wp'].txt_error='Empty value.'
|
||||
|
||||
return_val=False
|
||||
|
||||
repeat_password_wp=post.get('repeat_password_wp', '').strip()
|
||||
|
||||
if repeat_password_wp=='':
|
||||
|
||||
self.arr_form['repeat_password_wp'].error=True
|
||||
self.arr_form['repeat_password_wp'].txt_error='Empty value.'
|
||||
|
||||
return_val=False
|
||||
|
||||
if repeat_password_wp!=password_wp:
|
||||
self.arr_form['password_wp'].error=True
|
||||
self.arr_form['password_wp'].txt_error='Passwords not equal!'
|
||||
|
||||
return_val=False
|
||||
|
||||
virtualhost_id=self.data.get('virtualhost_id', '0')
|
||||
# ImmutableMultiDict([('send_task', '1'), ('amp;virtualhost_id', '42')])
|
||||
|
||||
#print(virtualhost_id)
|
||||
|
||||
domain=''
|
||||
home=''
|
||||
|
||||
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['user_wp']=user_wp
|
||||
self.data['password_wp']=password_wp
|
||||
self.data['email_wp']=email_wp
|
||||
self.data['title_wp']=title_wp
|
||||
self.data['domain_wp']=domain
|
||||
|
||||
self.data['mysql_host']=post['mysql_host'].strip()
|
||||
self.data['mysql_user']=post['mysql_user'].strip()
|
||||
self.data['mysql_password']=post['mysql_password'].strip()
|
||||
self.data['mysql_db']=post['mysql_db'].strip()
|
||||
|
||||
self.data['virtualhost_id']=virtualhost_id
|
||||
|
||||
self.data['home']=home
|
||||
self.data['username']=username
|
||||
self.data['webapp']='wordpress'
|
||||
|
||||
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='wordpress'
|
||||
|
||||
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']), app_name, 'wordpress', self.data['path'], json.dumps({'mysql_host': self.data['mysql_host'], 'mysql_db': self.data['mysql_db']})])
|
||||
|
||||
|
||||
return True
|
||||
Loading…
Add table
Add a link
Reference in a new issue