Added proxy support
This commit is contained in:
parent
666d31f3b3
commit
a9aab71d12
3 changed files with 311 additions and 1 deletions
165
tasks/apache/scripts/proxy.py
Normal file
165
tasks/apache/scripts/proxy.py
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
#/usr/bin/env python3
|
||||
|
||||
from collections import OrderedDict
|
||||
import os
|
||||
#from modules.pastafari2.models.servers import Server
|
||||
from modules.webservers.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, UrlField
|
||||
from modules.webservers.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 Proxy App in an Apache Httpd Server'
|
||||
|
||||
self.description_task='Install Proxy app in an Apache Httpd Server.'
|
||||
|
||||
self.codename_task='apache_webserver_proxy'
|
||||
|
||||
self.files=[['modules/apache/scripts/webapps/proxy/install_proxy_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 proxy application'
|
||||
self.arr_form['path'].help='The path of proxy application. <p>For example, if you have a domain called http://example.com, if you install in / path, you access to proxy app, directly in http://example.com. <br />If you add path to /webapp/, the proxy webapp site will be accesible using http://example.com/webapp'
|
||||
|
||||
self.arr_form['url']=coreforms.BaseForm('url', '')
|
||||
|
||||
self.arr_form['url'].required=True
|
||||
|
||||
self.arr_form['url'].label='The url used for proxy the app'
|
||||
self.arr_form['url'].help='The url used for proxy the app. Example, if you want install an gitea server that use 3000 port, you can use this url http://localhost:3000'
|
||||
|
||||
|
||||
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_proxy='--domain %s --home_user %s --url %s --user %s --path %s' % (self.data['domain'], self.data['home_user'], self.data['url'], self.data['username'], self.data['path'])
|
||||
|
||||
self.commands_to_execute.append(['modules/apache/scripts/webapps/proxy/install_proxy_site.py', install_proxy])
|
||||
|
||||
|
||||
|
||||
return True
|
||||
|
||||
def form(self, t, yes_error=False, pass_values=False, values={}):
|
||||
|
||||
#Here load the form for it task
|
||||
|
||||
return '<h2>'+I18n.lang('apache', 'add_proxy_site', 'Add site by proxy')+'</h2>'+show_form(values, self.arr_form, t, yes_error, pass_values)
|
||||
|
||||
def check_form(self, post):
|
||||
|
||||
return_val=True
|
||||
|
||||
usernamefield=UserNameField('user')
|
||||
|
||||
urlfield=UrlField('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
|
||||
|
||||
url=urlfield.check(request.form.get('url', ''))
|
||||
|
||||
if url=='':
|
||||
self.arr_form['url'].error=True
|
||||
self.arr_form['url'].txt_error='Wrong value for http proxy url.'
|
||||
|
||||
return_val=False
|
||||
|
||||
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']
|
||||
|
||||
app_name='proxy'
|
||||
|
||||
home=arr_virtualhost['home']+path
|
||||
|
||||
if 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['url']=url
|
||||
|
||||
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'], 'proxy', self.data['path'], json.dumps(self.data)])
|
||||
|
||||
|
||||
return True
|
||||
Loading…
Add table
Add a link
Reference in a new issue