/')
def virtualhost_progress(webserver_id):
db=g.connection
#Webservers list >> Web users >> Virtual Hosts
#cursor=db.query('select `usersftp`.`id` from `usersftp`')
return_tree=''+I18n.lang('webservers', 'webservers_list', 'Webservers list')+' >> '+I18n.lang('webservers', 'websites', 'Websites')+'
'
return load_progress(db, t, return_tree=return_tree, path_module='admin_app.webservers')
@admin_app.route('/virtualhost/delete/')
def virtualhost_delete(virtualhost_id):
db=g.connection
vhost=VirtualHost(db)
usersftp=UsersFtp(db)
arr_virtualhost=vhost.select_a_row(virtualhost_id, [], True)
#arr_user=usersftp.select_a_row(arr_virtualhost['user_id'], [], True)
return t.load_template('del_virtualhost.phtml', title=I18n.lang('webservers', 'remove_virtualhost', 'Remove Virtual Host'), path_module='admin_app.webservers', webserver_id=arr_virtualhost['webserver_id'], virtualhost_id=virtualhost_id, domain=arr_virtualhost['domain'])
@admin_app.route('/delete_virtualhost/', methods=['POST'])
def delete_virtualhost():
virtualhost_id=request.form.get('virtualhost_id', '0')
error=0
error_form={}
task_id=0
db=g.connection
vhost=VirtualHost(db)
#usersftp=UsersFtp(db)
arr_virtualhost=vhost.select_a_row(virtualhost_id, [], True)
if arr_virtualhost:
webserver_id=arr_virtualhost['webserver_id']
#arr_user=usersftp.set_conditions('WHERE usersftp.id=%s', [webserver_id]).select_a_row_where([])
#server_id=arr_virtualhost['server_id']
#username=arr_virtualhost['username']
root_dir=arr_virtualhost['home']
#ftp_user=arr_user['user']
webserver=WebServer(db)
arr_webserver=webserver.select_a_row(webserver_id, [], True)
#username=arr_webserver['username']
serverdb=ServerDbTask(db)
arr_server=serverdb.select_a_row(arr_webserver['server_id'], [], True)
domain=arr_virtualhost['domain']
username=arr_virtualhost['username']
if arr_virtualhost:
sshtask=SSHTask(db)
ssh_key_priv='./ssh/id_rsa'
if not sshtask.run_task(arr_server['ip'], 'modules.apache.tasks.apache.apache.delete_vhost', 'Remove Apache virtualhost', 'remove_apache_virtualhost', 'Task for remove a virtualhost to Apache Server', {'domain': domain, 'email': config.portal_email, 'webserver_id': arr_webserver['id'], 'user': username, 'root_dir': root_dir, 'cgi_type': ''}, config_task.remote_user, '', '', url_for('admin_app.virtualhost', webserver_id=webserver_id), ssh_key_priv=ssh_key_priv, ssh_key_password='', send_task=True, ssh_port=arr_server['ssh_port']):
error=1
task_id=sshtask.task_id
else:
error=1
pass
else:
error=1
return {'error': error, 'error_form': error_form, 'task_id': task_id}
@admin_app.route('/edit_virtualhost/', methods=['GET'])
def edit_virtualhost(virtualhost_id):
db=g.connection
vhost=VirtualHost(db)
arr_vhost=vhost.select_a_row(virtualhost_id, [], True)
if arr_vhost:
virtual=VirtualHost(db)
virtual.fields['aliases'].label=I18n.lang('webservers', 'domain_alias', 'Domain aliases')
virtual.fields['aliases'].help=I18n.lang('webservers', 'domain_alias_explain', 'Domain aliases are the other domain names of this server. For example www.domain.com, other-site.domain.com. You can separate the domains with commas')
virtual.fields['webserver_id'].name_form=HiddenForm
virtual.fields['webserver_id'].extra_parameters=[]
#virtual.fields['webserver_id'].default_value=arr_vhost['webserver_id']
#virtual.fields['cgi_type'].name_form=SelectForm
#virtual.fields['cgi_type'].extra_parameters=[{'': I18n.lang('webservers', 'anything', 'Anything cgi content'), 'php74': 'PHP 7.4 (php-fpm)', 'php80': 'PHP 8.0 (php-fpm)', 'php81': 'PHP 8.1 (php-fpm)', 'php82': 'PHP 8.2 (php-fpm)', 'python3': 'Python3 (mod_wsgi)'}]
#virtual.fields['cgi_type'].default_value=arr_vhost['cgi_type']
virtual.fields['ip'].label=I18n.lang('webservers', 'ip_if_empty', 'Ip of virtualhost, empty if server default')
virtual.fields['ip'].help=I18n.lang('webservers', 'ip_if_empty_explain', 'Ip of virtualhost, empty if server default. If you don\'t know that value your need, leave it empty')
virtual.fields['domain'].help=I18n.lang('webservers', 'domain_explain', 'The domain of new website')
virtual.fields['port'].help=I18n.lang('webservers', 'port_explain', 'Change the base port used for the website if you want use behind of a reverse proxy. The port need to be specified in http ports edit in webservers')
virtual.fields['ssl_port'].help=I18n.lang('webservers', 'port_explain', 'Change the base port used for the website if you want use behind of a reverse proxy. The port need to be specified in http ports edit in webservers')
virtual.fields['ssl'].name_form=SelectForm
virtual.fields['ssl'].extra_parameters=[{0: 'No', 1: 'Lets Encrypt', 2: 'SSL Files'}]
virtual.fields['redirect_ssl'].name_form=SelectForm
virtual.fields['redirect_ssl'].extra_parameters=[{0: I18n.lang('webservers', 'no', 'No'), 1: I18n.lang('webservers', 'yes', 'Yes')}]
virtual.fields['indexes'].name_form=SelectForm
virtual.fields['indexes'].extra_parameters=[{0: I18n.lang('webservers', 'no', 'No'), 1: I18n.lang('webservers', 'yes', 'Yes')}]
virtual.fields['indexes'].help=I18n.lang('webservers', 'add_support_for_show_files_if_index_not_exists', 'Add support show files if index.html not exists?')
virtual.fields['allow_override'].name_form=SelectForm
virtual.fields['allow_override'].extra_parameters=[{0: I18n.lang('webservers', 'no', 'No'), 1: I18n.lang('webservers', 'yes', 'Yes')}]
virtual.fields['allow_override'].help=I18n.lang('webservers', 'add_support_for_.htaccess', 'Add support for htaccess?')
virtual.fields['php'].label=I18n.lang('webservers', 'php_support', 'PHP support')
virtual.fields['php'].name_form=SelectForm
virtual.fields['php'].extra_parameters=[{'': 'No php support', '7.4': 'PHP 7.4', '8.0': 'PHP 8.0', '8.1': 'PHP 8.1', '8.2': 'PHP 8.2'}]
virtual.fields['php'].help=I18n.lang('webservers', 'add_php_support_to_virtualhost', 'Add support to php to virtualhost. You can choose ophp version that you prefer')
#'port', 'ssl_port',
virtual.create_forms(['domain', 'aliases', 'webserver_id', 'ip', 'indexes', 'allow_override', 'redirect_ssl', 'ssl', 'php'])
#print(virtual.fields.keys())
arr_form=virtual.forms
#print(arr_form['user_id'].model.fields.keys())
arr_form['ssl_crt']=TextForm('ssl_crt', '')
arr_form['ssl_crt'].help=I18n.lang('webservers', 'ssl_crt_explain', 'Certificate text from file of ssl certificate, normally ending with .crt')
arr_form['ssl_crt'].label=I18n.lang('webservers', 'ssl_crt', 'Ssl certificate')
arr_form['ssl_crt'].css='hide_form'
arr_form['ssl_key']=TextForm('ssl_key', '')
arr_form['ssl_key'].help=I18n.lang('webservers', 'ssl_key_explain', 'Key text from file of ssl certificate, normally ending with .key')
arr_form['ssl_key'].label=I18n.lang('webservers', 'ssl_key', 'Ssl key')
arr_form['ssl_key'].css='hide_form'
if arr_vhost['ssl_port']==0:
arr_vhost['ssl_port']=443
form=show_form(arr_vhost, arr_form, t, yes_error=True, pass_values=True, modelform_tpl='forms/modelform.phtml')
return t.load_template('edit_virtualhost.phtml', title=I18n.lang('webservers', 'edit_virtualhost', 'Edit Virtual Host'), path_module='admin_app.webservers', form=form, webserver_id=arr_vhost['webserver_id'], virtualhost_id=virtualhost_id)
pass
return ""
@admin_app.route('/save_edit_virtualhost/', methods=['POST'])
def save_edit_virtualhost():
db=g.connection
domain=request.form.get('domain', '').strip()
#home=slugify(request.form.get('home' '').strip())
webserver_id=request.form.get('webserver_id', '0')
virtualhost_id=request.args.get('virtualhost_id', '0')
cgi_type=request.form.get('cgi_type', '')
#port=request.form.get('port', '0')
#ssl_port=request.form.get('ssl_port', '0')
port=80
ssl_port=443
ssl=request.form.get('ssl', '0')
indexes=request.form.get('indexes', '0')
redirect_ssl=request.form.get('redirect_ssl', '0')
if indexes!='1':
indexes='0'
allow_override=request.form.get('allow_override', '0')
if allow_override!='1':
allow_override='0'
ip=request.form.get('ip', '')
error=0
error_form={}
webserver=WebServer(db)
virtualhost=VirtualHost(db)
if virtualhost.fields['domain'].check(domain)=='':
error_form['#domain_error']='Sorry, invalid domain'
error=1
check_port=int(virtualhost.fields['port'].check(port))
if check_port==0 or check_port<0 or (check_port<1000 and check_port!=80) or check_port>65536:
error_form['#port_error']='Sorry, invalid port'
error=1
else:
port=check_port
check_ssl_port=int(virtualhost.fields['ssl_port'].check(ssl_port))
if check_ssl_port==0 or check_ssl_port<0 or (check_ssl_port<1000 and check_ssl_port!=443) or check_ssl_port>65536:
error_form['#ssl_port_error']='Sorry, invalid port'
error=1
else:
ssl_port=check_ssl_port
check_ssl=int(virtualhost.fields['ssl'].check(ssl))
if check_ssl<0 and check_ssl>2:
error_form['#ssl_error']='Sorry, invalid ssl options'
error=1
else:
ssl=check_ssl
if ssl==2:
#Load text ssl files
ssl_crt_text=request.form.get('ssl_crt', '').strip()
ssl_key_text=request.form.get('ssl_key', '').strip()
if ssl_crt_text!='':
with open('modules/webservers/scripts/files/'+domain+'-ssl.crt', 'w') as f:
f.write(ssl_crt_text)
if ssl_key_text!='':
with open('modules/webservers/scripts/files/'+domain+'-ssl.key', 'w') as f:
f.write(ssl_key_text)
ip=virtualhost.fields['ip'].check(ip)
if ip=='':
ip='*'
"""
if virtualhost.fields['home'].check(home)=='':
error_form['#home_error']='Sorry, invalid home'
error=1
"""
aliases=request.form.get('aliases', '')
arr_aliases=[]
if aliases!='':
arr_aliases=[virtualhost.fields['domain'].check(alias.strip()) for alias in aliases.split(',') if virtualhost.fields['domain'].check(alias.strip())!='']
if len(arr_aliases)>0:
aliases=",".join(arr_aliases)
php=request.form.get('php', '')
if php!='':
if php!='7.4' and php!='8.0' and php!='8.1' and php!='8.2':
php=''
task_id=0
serverdb=ServerDbTask(db)
arr_webserver=webserver.set_conditions('WHERE webserver.id=%s', [webserver_id]).select_a_row_where([], True)
if arr_webserver and not error:
arr_server=serverdb.select_a_row(arr_webserver['server_id'], [], True)
arr_virtualhost=virtualhost.select_a_row(virtualhost_id, [], True)
username=arr_virtualhost['username']
#print(arr_user)
#server_id=arr_user['webserver_id_server_id']
#username=arr_user['webserver_id_username']
#Check if not exists domain, etc
#arr_server=serverdb.select_a_row(server_id)
#print(arr_server)
sshtask=SSHTask(db)
#user=config_task.remote_user
ssh_key_priv='./ssh/id_rsa'
#run_task(self, server, path, name_task, codename_task, description_task, data={}, user='', password='', where_sql_server='', url='', ssh_key_priv='', ssh_key_password='', send_task=True)
# user=user, password='', where_sql_server=where_sql, ssh_key_priv=ssh_key_priv, url='', data=data, send_task=True
root_dir=arr_virtualhost['home']
#ftp_user=arr_user['user']
if not sshtask.run_task(arr_server['ip'], 'modules.apache.tasks.apache.apache.edit_vhost', 'Edit Apache virtualhost', 'edit_apache_virtualhost', 'Task for edit a virtualhost to Apache Server', {'domain': domain, 'email': config.portal_email, 'webserver_id': arr_webserver['id'], 'user': username, 'root_dir': root_dir, 'cgi_type': cgi_type, 'ip': ip, 'port': port, 'ssl': ssl, 'ssl_port': ssl_port, 'aliases': aliases, 'indexes': indexes, 'allow_override': allow_override, 'virtualhost_id': virtualhost_id, 'redirect_ssl': redirect_ssl, 'php': php}, config_task.remote_user, '', '', url_for('admin_app.virtualhost', webserver_id=arr_webserver['id']), ssh_key_priv=ssh_key_priv, ssh_key_password='', send_task=True, ssh_port=arr_server['ssh_port']):
error=1
task_id=sshtask.task_id
else:
error=1
return {'error': error, 'error_form': error_form, 'task_id': task_id}
@admin_app.route('/webservers/change_user_password', methods=['POST'])
def change_user_password():
webserver_id=request.args.get('webserver_id', '0')
error=0
error_form={}
task_id=0
db=g.connection
vhost=VirtualHost(db)
#usersftp=UsersFtp(db)
webserver=WebServer(db)
arr_webserver=webserver.select_a_row(webserver_id, [], True)
if arr_webserver:
"""
password=request.form.get('password', '')
repeat_password=request.form.get('repeat_password', '')
if password!=repeat_password and password!='':
error_form['#password_error']='Passwords doesn\'t match'
password=''
error=1
"""
#ssh-keygen -l -f id_rsa.pub
ssh_pub_key=request.form.get('ssh_pub_key', '')
user=request.form.get('user', '')
if user=='':
error_form['#user_error']=I18n.lang('webservers', 'error_you_need_an_user', 'Error: you need an user')
error=1
if ssh_pub_key=='':
error_form['#ssh_pub_key_error']=I18n.lang('webservers', 'error_you_need_a_ssh_pub_key', 'Error: you need a ssh public key')
error=1
#username=arr_webserver['username']
serverdb=ServerDbTask(db)
arr_server=serverdb.select_a_row(arr_webserver['server_id'], [], True)
sshtask=SSHTask(db)
ssh_key_priv='./ssh/id_rsa'
#'password': password
if not sshtask.run_task(arr_server['ip'], 'modules.pastafari2.tasks.system.change_password_user', 'Change user password', 'Change user password', 'Task for change unix user password', {'user': user, 'ssh_pub_key': ssh_pub_key}, config_task.remote_user, '', '', url_for('admin_app.virtualhost', webserver_id=webserver_id), ssh_key_priv=ssh_key_priv, ssh_key_password='', send_task=True, ssh_port=arr_server['ssh_port']):
error=1
task_id=sshtask.task_id
else:
error=1
return {'error': error, 'error_form': error_form, 'task_id': task_id}
@admin_app.route('/webservers/users_list', methods=['GET'])
def users_list():
return {}