Fixes in php delete
This commit is contained in:
parent
e403599bf5
commit
50204461ee
6 changed files with 197 additions and 71 deletions
10
dashboard.py
10
dashboard.py
|
|
@ -94,8 +94,12 @@ def delete_php(php_server_id):
|
|||
arr_server=cursor.fetchone()
|
||||
|
||||
if arr_server:
|
||||
|
||||
#select * from virtualhost, webserver, serverdbtask, phpserver where virtualhost.webserver_id=webserver.id AND serverdbtask.id=webserver.server_id AND phpserver.server_id=serverdbtask.id AND phpserver.id=19
|
||||
with db.query('select count(*) as num_php_vhosts from virtualhost, webserver, serverdbtask, phpserver where virtualhost.webserver_id=webserver.id AND serverdbtask.id=webserver.server_id AND phpserver.server_id=serverdbtask.id AND phpserver.id=%s', [php_server_id]) as cursor:
|
||||
num_php_vhosts=cursor.fetchone()['num_php_vhosts']
|
||||
|
||||
return t.load_template('del_phpserver.phtml', title=_('Remove PHP FPM server'), path_module='php_app.php_dashboard', php_server_id=php_server_id, domain=arr_server['hostname'])
|
||||
return t.load_template('del_phpserver.phtml', title=_('Remove PHP FPM server'), path_module='php_app.php_dashboard', php_server_id=php_server_id, domain=arr_server['hostname'], num_php_vhosts=num_php_vhosts)
|
||||
|
||||
abort(404)
|
||||
|
||||
|
|
@ -110,7 +114,7 @@ def delete_php_task(php_server_id):
|
|||
|
||||
error_form={}
|
||||
|
||||
with db.query('select serverdbtask.hostname, serverdbtask.ip, serverdbtask.ssh_port, phpserver.version from serverdbtask, phpserver where phpserver.server_id=serverdbtask.id') as cursor:
|
||||
with db.query('select serverdbtask.hostname, serverdbtask.ip, serverdbtask.ssh_port, phpserver.version from serverdbtask, phpserver where phpserver.server_id=serverdbtask.id and phpserver.id=%s', [php_server_id]) as cursor:
|
||||
arr_server=cursor.fetchone()
|
||||
|
||||
if arr_server:
|
||||
|
|
@ -127,7 +131,7 @@ def delete_php_task(php_server_id):
|
|||
#root_dir='/home/'+username+'/sites/'+domain
|
||||
|
||||
#ftp_user=arr_user['user']
|
||||
print('pep')
|
||||
|
||||
if not sshtask.run_task(arr_server['ip'], 'modules.phpserver.tasks.php.php.delete_php', 'Delete PHP server', 'delete_phpserver', 'Task for delete php-fpm server from server', {'version': arr_server['version'], 'php_server_id': php_server_id}, config_task.remote_user, '', '', url_for('php_app.php_dashboard'), ssh_key_priv=ssh_key_priv, ssh_key_password='', send_task=True, ssh_port=arr_server['ssh_port']):
|
||||
|
||||
error=1
|
||||
|
|
|
|||
79
scripts/delete_php.py
Normal file
79
scripts/delete_php.py
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
|
||||
from pastafariutils import linux
|
||||
import distro
|
||||
import argparse
|
||||
import os
|
||||
|
||||
php_versions=['8.2', '8.3', '8.4']
|
||||
|
||||
linux_distro=distro.id()
|
||||
|
||||
parser=argparse.ArgumentParser(prog='install_php.py', description='Script for install php')
|
||||
|
||||
parser.add_argument('--version', help='The version of php', required=True)
|
||||
|
||||
#parser.add_argument('--ip', help='The IP where php-fpm receive orders')
|
||||
|
||||
args=parser.parse_args()
|
||||
|
||||
ip=None
|
||||
|
||||
#if args.ip:
|
||||
# ip=args.ip
|
||||
|
||||
|
||||
version=args.version
|
||||
|
||||
if not version in php_versions:
|
||||
linux.json_log('Error: php version not supported', error=1, status=1, progress=100, no_progress=0);
|
||||
exit(1)
|
||||
|
||||
|
||||
os_update={'debian': 'sudo apt-get update', 'fedora': 'sudo dnf update'}
|
||||
|
||||
os_update['rocky']=os_update['fedora']
|
||||
os_update['almalinux']=os_update['fedora']
|
||||
|
||||
linux.exec(os_update)
|
||||
|
||||
linux.json_log('Deleting php {}...'.format(args.version), error=0, status=0, progress=0, no_progress=1);
|
||||
|
||||
# Install php-fpm version
|
||||
|
||||
remove_php={'debian': 'sudo apt-get remove -y php{version}-fpm php{version}-gd php{version}-mysql php{version}-curl php{version}-mbstring php{version}-intl php{version}-imagick php{version}-xml php{version}-zip php{version}-redis'.format(version=version)}
|
||||
|
||||
remove_php['fedora']='sudo dnf remove -y php{version} php{version}-fpm php{version}-gd php{version}-mysql php{version}-curl php{version}-mbstring php{version}-intl php{version}-imagick php{version}-xml php{version}-zip php{version}-redis'.format(version=version.replace('.', ''))
|
||||
|
||||
print('sudo dnf remove -y php{version} php{version}-fpm php{version}-gd php{version}-mysql php{version}-curl php{version}-mbstring php{version}-intl php{version}-imagick php{version}-xml php{version}-zip php{version}-redis'.format(version=version.replace('.', '')))
|
||||
|
||||
remove_php['almalinux']=remove_php['fedora']
|
||||
remove_php['rocky']=remove_php['fedora']
|
||||
|
||||
linux.exec(remove_php)
|
||||
|
||||
linux.json_log('Deleted php {}...'.format(version), error=0, status=0, progress=0, no_progress=1);
|
||||
|
||||
install_php={'debian': 'sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y php-gd php-mysql php-curl php-mbstring php-intl php-imagick php-xml php-zip php-redis unzip'}
|
||||
|
||||
install_php['fedora']='sudo dnf -y install php php-gd php-mysqlnd php-intl php-process composer'
|
||||
|
||||
install_php['almalinux']=install_php['fedora']
|
||||
install_php['rocky']=install_php['fedora']
|
||||
|
||||
linux.json_log('Reinstall official php for scripts if deleted...', error=0, status=0, progress=0, no_progress=1);
|
||||
|
||||
linux.exec(install_php)
|
||||
|
||||
|
||||
#sed_php={'debian' : ['ServerTokens OS', "ServerTokens Prod", '\/etc\/apache2\/conf-enabled\/security.conf']}
|
||||
|
||||
"""
|
||||
debian_package='apache2 logrotate socat curl'
|
||||
|
||||
redhat_package='httpd mod_ssl mod_md openssl tar socat policycoreutils-python-utils wget'
|
||||
|
||||
linux_package={'debian' : debian_package, 'ubuntu' : debian_package, 'fedora' : redhat_package, 'almalinux' : redhat_package, 'rocky' : redhat_package, 'arch' : 'apache'}
|
||||
|
||||
linux.install_package(linux_package);
|
||||
|
||||
"""
|
||||
|
|
@ -40,11 +40,13 @@ if linux_distro=='debian':
|
|||
|
||||
linux.exec(add_repos)
|
||||
|
||||
linux.exec({'debian': 'sudo apt-get update'})
|
||||
repos={'debian': 'sudo apt-get update', 'fedora': 'echo "Remi repos installed by default..."'}
|
||||
|
||||
if linux_distro=='almalinux' or linux_distro=='rocky' or linux_distro=='fedora':
|
||||
repos['rocky']=repos['fedora']
|
||||
|
||||
repos['almalinux']=repos['fedora']
|
||||
|
||||
pass
|
||||
linux.exec(repos)
|
||||
|
||||
linux.json_log('Repos installed...', error=0, status=0, progress=100, no_progress=0);
|
||||
|
||||
|
|
@ -52,6 +54,11 @@ linux.json_log('Repos installed...', error=0, status=0, progress=100, no_progres
|
|||
|
||||
install_php={'debian': 'sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y php{version}-fpm php{version}-gd php{version}-mysql php{version}-curl php{version}-mbstring php{version}-intl php{version}-imagick php{version}-xml php{version}-zip php{version}-redis unzip'.format(version=version)}
|
||||
|
||||
install_php={'fedora': 'sudo dnf -y install php{version} php{version}-php-gd php{version}-php-mysqlnd php{version}-php-imap php{version}-php-intl php{version}-php-fpm php{version}-php-process composer unzip mariadb php{version}-php-pecl-zip'.format(version=version.replace('.', ''))}
|
||||
|
||||
install_php['almalinux']=install_php['fedora']
|
||||
install_php['rocky']=install_php['fedora']
|
||||
|
||||
linux.json_log('Install php {}...'.format(version), error=0, status=0, progress=0, no_progress=1);
|
||||
|
||||
linux.exec(install_php)
|
||||
|
|
|
|||
65
tasks/php/php/delete_php.py
Normal file
65
tasks/php/php/delete_php.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#/usr/bin/env python3
|
||||
|
||||
from collections import OrderedDict
|
||||
import json
|
||||
from modules.pastafari2.libraries.task import Task
|
||||
from modules.pastafari2.models.pastafari2 import ServerDbTask
|
||||
from modules.pastafari2.libraries.configtask import config_task
|
||||
#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='Remove php version in server'
|
||||
|
||||
self.description_task='Delete php version in server'
|
||||
|
||||
self.codename_task='del_php'
|
||||
|
||||
self.files=[]
|
||||
|
||||
self.files=[['modules/phpserver/scripts/delete_php.py', 0o755]]
|
||||
|
||||
# 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/phpserver/scripts/delete_php.py', '']]
|
||||
|
||||
#THe files to delete
|
||||
|
||||
self.delete_files=[]
|
||||
|
||||
self.delete_directories=['modules/phpserver/scripts']
|
||||
|
||||
#self.task=Task(conn)
|
||||
|
||||
self.one_time=False
|
||||
|
||||
self.version='1.0'
|
||||
|
||||
self.path_module='php_app.php_dashboard'
|
||||
|
||||
def pre_task(self):
|
||||
|
||||
#self.commands_to_execute=[['modules/webservers/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=[['/home/{}/pythonenv/bin/python3 -u modules/phpserver/scripts/delete_php.py'.format(config_task.remote_user), '--version={}'.format(self.data['version'])]]
|
||||
|
||||
return True
|
||||
|
||||
def post_task(self):
|
||||
|
||||
#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.set_conditions('WHERE domain=%s', [self.data['domain']]).delete():
|
||||
if not self.connection.query('delete from phpserver where id=%s', [self.data['php_server_id']]):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
|
@ -35,17 +35,12 @@ class ServerTask(Task):
|
|||
# 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/pastafari/scripts/servers/databases/mysql/install_mariadb.py', '']];
|
||||
|
||||
#THe files to delete
|
||||
|
||||
self.delete_files=[]
|
||||
|
||||
self.delete_directories=['modules/phpserver/scripts/']
|
||||
|
||||
#self.task=Task(conn)
|
||||
|
||||
#self.one_time=True
|
||||
|
||||
|
||||
self.version='1.0'
|
||||
|
||||
|
|
@ -59,31 +54,8 @@ class ServerTask(Task):
|
|||
|
||||
self.arr_form['version'].label=_('Version')
|
||||
|
||||
"""
|
||||
self.arr_form['mysql_password']=coreforms.PasswordForm('mysql_password', '')
|
||||
self.path_module='php_app.php_dashboard'
|
||||
|
||||
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'
|
||||
|
||||
self.arr_form['access_localhost']=coreforms.SimpleTextForm('access_localhost', '')
|
||||
|
||||
self.arr_form['access_localhost'].required=True
|
||||
|
||||
#self.arr_form['access_localhost'].default_value='1'
|
||||
|
||||
self.arr_form['access_localhost'].label='IP for access to mariadb server'
|
||||
self.arr_form['access_localhost'].help='Empty if you want only localhost access. If you want all ips, use 0.0.0.0 or if you want other ip, put it'
|
||||
"""
|
||||
|
||||
#self.commands_to_execute=[['modules/pastafari/scripts/servers/databases/mariadb/install_mariadb.py', '--password=%s' % self.data['mysql_password']]]
|
||||
|
||||
def post_task(self):
|
||||
|
||||
if server_db:
|
||||
|
|
@ -127,41 +99,6 @@ class ServerTask(Task):
|
|||
def check_form(self, post):
|
||||
|
||||
error=False
|
||||
"""
|
||||
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.data['mysql_password']=post['mysql_password'].strip()
|
||||
|
||||
else:
|
||||
|
||||
self.arr_form['mysql_password'].error=True
|
||||
self.arr_form['mysql_password'].txt_error='Passwords doesn\'t match'
|
||||
error=True
|
||||
|
||||
if 'access_localhost' in post:
|
||||
|
||||
self.data['ip']=''
|
||||
|
||||
ip_check=IpField('ip')
|
||||
|
||||
ip_host=post['access_localhost'].strip()
|
||||
|
||||
if ip_host!='':
|
||||
|
||||
ip_host=ip_check.check(ip_host)
|
||||
|
||||
if ip_host!='':
|
||||
self.data['ip']=ip_host
|
||||
|
||||
if ip_check.error:
|
||||
|
||||
self.arr_form['access_localhost'].error=True
|
||||
self.arr_form['access_localhost'].txt_error='Wrong ip format'
|
||||
error=True
|
||||
|
||||
"""
|
||||
|
||||
self.data['version']=post['version'].strip()
|
||||
#print(self.data['version'])
|
||||
|
|
|
|||
34
templates/admin/del_phpserver.phtml
Normal file
34
templates/admin/del_phpserver.phtml
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<%inherit file="dashboard.phtml"/>
|
||||
<%block name="content">
|
||||
<p><a href="${url_for('php_app.php_dashboard')}">${_('PHP servers list')}</a> >> ${_('Delete php server')}</p>
|
||||
<form method="post" name="del_phpserver" id="del_phpserver">
|
||||
<input type="hidden" name="php_server_id" value="${php_server_id}" />
|
||||
<h3>${domain}</h3>
|
||||
% if num_php_vhosts==0:
|
||||
<p><input type="submit" value="${_('Delete php server')}" />
|
||||
|
||||
% else:
|
||||
|
||||
<p>Sorry, you need delete all sites using this php version</p>
|
||||
|
||||
% endif
|
||||
</form>
|
||||
<p><a href="${url_for('php_app.php_dashboard')}">${_('PHP servers list')}</a> >> ${_('Delete php server')}</p>
|
||||
</%block>
|
||||
<%block name="jscript_block">
|
||||
<script language="Javascript" src="${make_media_url('js/jsutils/posting2.js', 'pastafari2')}"></script>
|
||||
<script>
|
||||
|
||||
/* options: url: url to post, loading: dom id, success: func, pre_callback, separated_data:boolean, upload: {progressbar: '#progressbar', 'total_loader': '#total_loader', 'status': '#status'} */
|
||||
|
||||
options={'url': '${url_for("php_app.delete_php_task", php_server_id=php_server_id)}', 'loading': '#layer_loading', 'success': function (data) {
|
||||
|
||||
location.href="${url_for('php_app.php_progress', php_server_id=php_server_id)}?task_id="+data.task_id;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
$('#del_phpserver').sendPost(options);
|
||||
|
||||
</script>
|
||||
</%block>
|
||||
Loading…
Add table
Add a link
Reference in a new issue