Added modify php.ini from phpserver module
This commit is contained in:
parent
56157e4adb
commit
ffdf81ec07
6 changed files with 295 additions and 37 deletions
95
dashboard.py
95
dashboard.py
|
|
@ -1,6 +1,6 @@
|
|||
from modules.phpserver import phpserver_app
|
||||
from settings import config
|
||||
from flask import g, url_for, request, session, make_response, abort
|
||||
from flask import g, url_for, request, session, make_response, abort, flash
|
||||
from paramecio2.libraries.generate_admin_class import GenerateAdminClass
|
||||
from paramecio2.libraries.lists import SimpleList
|
||||
from paramecio2.libraries.i18n import I18n, PGetText
|
||||
|
|
@ -20,6 +20,7 @@ from modules.pastafari2.models.tasks import Task as SSHTask
|
|||
from modules.pastafari2.libraries.configtask import config_task
|
||||
from modules.pastafari2.libraries.progress import load_progress
|
||||
import os
|
||||
import configparser
|
||||
|
||||
try:
|
||||
import ujson as json
|
||||
|
|
@ -98,8 +99,9 @@ def delete_php(php_server_id):
|
|||
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:
|
||||
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 AND virtualhost.php=%s', [php_server_id, arr_server['version']]) as cursor:
|
||||
num_php_vhosts=cursor.fetchone()['num_php_vhosts']
|
||||
|
||||
|
||||
return t.load_template('del_phpserver.phtml', title=_('Remove PHP FPM server'), path_module='phpserver_app.php_dashboard', php_server_id=php_server_id, domain=arr_server['hostname'], num_php_vhosts=num_php_vhosts)
|
||||
|
||||
|
|
@ -167,6 +169,7 @@ def php_edit_server(php_server_id):
|
|||
|
||||
if arr_server:
|
||||
|
||||
#arr_form=BaseForm
|
||||
|
||||
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)
|
||||
|
||||
|
|
@ -213,32 +216,42 @@ def get_php_server(php_server_id):
|
|||
|
||||
# No more of 60 seconds
|
||||
|
||||
arr_log={}
|
||||
if task_id:
|
||||
|
||||
check_task=True
|
||||
|
||||
result={}
|
||||
|
||||
while check_task:
|
||||
arr_log={}
|
||||
|
||||
with db.query('select * from logtask where task_id=%s order by id DESC limit 1', [task_id]) as cursor:
|
||||
check_task=True
|
||||
|
||||
result={}
|
||||
|
||||
while check_task:
|
||||
|
||||
arr_log=cursor.fetchone()
|
||||
|
||||
if arr_log:
|
||||
with db.query('select * from logtask where task_id=%s order by id DESC limit 1', [task_id]) as cursor:
|
||||
|
||||
if arr_log['status']==1:
|
||||
arr_log=cursor.fetchone()
|
||||
|
||||
if arr_log:
|
||||
|
||||
if arr_log['status']==1:
|
||||
|
||||
error=arr_log['error']
|
||||
check_task=False
|
||||
if not error:
|
||||
with db.query('select * from resulttask where task_id=%s', [task_id]) as cursor:
|
||||
result=cursor.fetchone()
|
||||
error=arr_log['error']
|
||||
check_task=False
|
||||
if not error:
|
||||
with db.query('select * from resulttask where task_id=%s', [task_id]) as cursor:
|
||||
result=cursor.fetchone()
|
||||
# PHP configuration
|
||||
|
||||
#
|
||||
|
||||
#config=configparser.ConfigParser()
|
||||
#print(json.loads(result['message'])['file'])
|
||||
#config.read_string(json.loads(result['message'])['file'])
|
||||
|
||||
#print(config['PHP']['display_errors'])
|
||||
|
||||
return {'error': error, 'error_form': error_form, 'log': arr_log, 'result': result, 'task_id': task_id}
|
||||
|
||||
@phpserver_app.route('/phpserver/save_php_ini/<int:php_server_id>/')
|
||||
@phpserver_app.route('/phpserver/save_php_ini/<int:php_server_id>/', methods=['POST'])
|
||||
def save_php_ini(php_server_id):
|
||||
|
||||
db=g.connection
|
||||
|
|
@ -248,6 +261,7 @@ def save_php_ini(php_server_id):
|
|||
task_id=0
|
||||
|
||||
result={}
|
||||
arr_log={}
|
||||
|
||||
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()
|
||||
|
|
@ -255,5 +269,46 @@ def save_php_ini(php_server_id):
|
|||
if arr_server:
|
||||
|
||||
sshtask=SSHTask(db)
|
||||
|
||||
file=request.form.get('php_ini_file')
|
||||
|
||||
if file.strip()!='':
|
||||
|
||||
with open('./tmp/php.ini', 'w') as f:
|
||||
f.write(file)
|
||||
|
||||
|
||||
if not sshtask.run_task(arr_server['ip'], 'modules.phpserver.tasks.php.php.save_php_ini', 'Save PHP.ini in server', 'save_php_ini', 'Task for save php.ini config on 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
|
||||
|
||||
if task_id:
|
||||
|
||||
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:
|
||||
|
||||
error=arr_log['error']
|
||||
check_task=False
|
||||
|
||||
if not error:
|
||||
flash(_('The php configuration was sucessfully changed'))
|
||||
|
||||
return {'error': error, 'error_form': error_form, 'log': arr_log, 'result': result, 'task_id': task_id}
|
||||
else:
|
||||
error=1
|
||||
error_form['empty_file']=1
|
||||
|
||||
return {'error': error, 'error_form': error_form, 'log': arr_log, 'task_id': task_id}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue