Added get_php_ini.py script
This commit is contained in:
parent
ff9a221ed0
commit
05025fbdb5
4 changed files with 191 additions and 2 deletions
62
dashboard.py
62
dashboard.py
|
|
@ -39,6 +39,8 @@ t.env.directories=admin_t.env.directories
|
|||
t.env.directories.insert(1, os.path.dirname(__file__).replace('/admin', '')+'/templates/admin')
|
||||
t.env.directories.insert(2, '../pastafari2/templates/admin')
|
||||
|
||||
config_task.pastafari_paths.append('modules/phpserver/tasks')
|
||||
|
||||
@phpserver_app.route('/phpserver/servers')
|
||||
def php_dashboard():
|
||||
|
||||
|
|
@ -166,14 +168,70 @@ def php_edit_server(php_server_id):
|
|||
if arr_server:
|
||||
|
||||
|
||||
return t.load_template('edit_phpserver.phtml', title=_('Edit PHP FPM server'), path_module='phpserver_app.php_dashboard', domain=arr_server['hostname'])
|
||||
return t.load_template('edit_phpserver.phtml', title=_('Edit PHP FPM server'), path_module='phpserver_app.php_dashboard', domain=arr_server['hostname'], php_server_id=php_server_id)
|
||||
|
||||
return {}
|
||||
|
||||
@phpserver_app.route('/phpserver/get_php_server/<int:php_server_id>/')
|
||||
def get_php_server(php_server_id):
|
||||
|
||||
db=g.connection
|
||||
|
||||
error=1
|
||||
error_form={}
|
||||
task_id=0
|
||||
|
||||
return {}
|
||||
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:
|
||||
|
||||
sshtask=SSHTask(db)
|
||||
|
||||
#user=config_task.remote_user
|
||||
|
||||
|
||||
|
||||
#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='/home/'+username+'/sites/'+domain
|
||||
|
||||
#ftp_user=arr_user['user']
|
||||
|
||||
#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('phpserver_app.php_dashboard'), ssh_key_priv=ssh_key_priv, ssh_key_password='', send_task=True, ssh_port=arr_server['ssh_port']):
|
||||
if not sshtask.run_task(arr_server['ip'], 'modules.phpserver.tasks.php.php.get_php_ini', 'Get PHP.ini from server', 'get_php_ini', 'Task for get php.ini config from server', {'version': arr_server['version'], 'php_server_id': php_server_id}, config_task.remote_user, '', '', url_for('phpserver_app.php_dashboard'), ssh_key_priv=config_task.ssh_private_key, ssh_key_password=config_task.ssh_private_key_password, send_task=True, ssh_port=arr_server['ssh_port']):
|
||||
|
||||
error=1
|
||||
|
||||
else:
|
||||
error=0
|
||||
|
||||
task_id=sshtask.task_id
|
||||
|
||||
# wait while tasks is completed
|
||||
|
||||
# No more of 60 seconds
|
||||
|
||||
arr_log={}
|
||||
|
||||
check_task=True
|
||||
|
||||
while check_task:
|
||||
|
||||
with db.query('select * from logtask where task_id=%s order by id DESC limit 1', [task_id]) as cursor:
|
||||
|
||||
arr_log=cursor.fetchone()
|
||||
|
||||
if arr_log:
|
||||
|
||||
if arr_log['status']==1:
|
||||
print(arr_log)
|
||||
error=arr_log['error']
|
||||
check_task=False
|
||||
|
||||
|
||||
|
||||
return {'error': error, 'error_form': error_form, 'log': arr_log, 'task_id': task_id}
|
||||
|
||||
|
||||
|
|
|
|||
24
scripts/get_php_ini.py
Normal file
24
scripts/get_php_ini.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
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()
|
||||
|
||||
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)
|
||||
|
||||
63
tasks/php/php/get_php_ini.py
Normal file
63
tasks/php/php/get_php_ini.py
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#/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='Get php.ini from server'
|
||||
|
||||
self.description_task='Get php.ini from server'
|
||||
|
||||
self.codename_task='get_php_ini'
|
||||
|
||||
self.files=[]
|
||||
|
||||
self.files=[['modules/phpserver/scripts/get_php_ini.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/get_php_ini.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/get_php_ini.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():
|
||||
|
||||
return True
|
||||
44
templates/admin/edit_phpserver.phtml
Normal file
44
templates/admin/edit_phpserver.phtml
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<%inherit file="dashboard.phtml"/>
|
||||
<%block name="extra_css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ace-builds@1.43.4/css/ace.min.css">
|
||||
</%block>
|
||||
<%block name="content">
|
||||
<h3>${_('Edit php.ini')}</h3>
|
||||
<div class="form">
|
||||
<div id="php_ini">
|
||||
</div>
|
||||
</div>
|
||||
</%block>
|
||||
<%block name="jscript_block">
|
||||
<script src=" https://cdnjs.cloudflare.com/ajax/libs/ace/1.43.3/ace.min.js"></script>
|
||||
<script>
|
||||
|
||||
$.ajax({
|
||||
url: "${url_for('phpserver_app.get_php_server', php_server_id=php_server_id)}",
|
||||
method: "GET",
|
||||
dataType: "json",
|
||||
data: {},
|
||||
success: function (data) {
|
||||
|
||||
console.log(data);
|
||||
|
||||
if(data.log.error) {
|
||||
|
||||
$('#php_ini').html(data.log.message);
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
error: function (data) {
|
||||
|
||||
alert('Error: '+data.status+' '+data.statusText);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
var editor = ace.edit("php_ini");
|
||||
editor.setTheme("ace/theme/twilight");
|
||||
editor.session.setMode("ace/mode/javascript");
|
||||
|
||||
</script>
|
||||
</%block>
|
||||
Loading…
Add table
Add a link
Reference in a new issue