Added support for call make_task for other scripts
This commit is contained in:
parent
e1710bf434
commit
c56366923f
6 changed files with 108 additions and 11 deletions
|
|
@ -552,7 +552,17 @@ def pastafari2_make_task():
|
||||||
|
|
||||||
url_exec=url_for('.pastafari2_make_task', send_task=1)
|
url_exec=url_for('.pastafari2_make_task', send_task=1)
|
||||||
|
|
||||||
return t.load_template('maketask.phtml', title=I18n.lang('pastafari2', 'make_task', 'Make task'), form=task_first.form(t, yes_error=False, pass_values=False), url_exec=url_exec, ids=json_ids, task_file=task_path)
|
links='<a href="'+url_for('admin_app.pastafari2_dashboard')+'">'+I18n.lang('pastafari2', 'servers', 'Servers')+'</a>'
|
||||||
|
|
||||||
|
path_module='admin_app.pastafari2_dashboard'
|
||||||
|
|
||||||
|
if hasattr(task_first, 'links'):
|
||||||
|
links=task_firs.links
|
||||||
|
|
||||||
|
if hasattr(task_first, 'path_module'):
|
||||||
|
links=task_firs.path_module
|
||||||
|
|
||||||
|
return t.load_template('maketask.phtml', title=I18n.lang('pastafari2', 'make_task', 'Make task'), form=task_first.form(t, yes_error=False, pass_values=False), url_exec=url_exec, ids=json_ids, task_file=task_path, links=links, path_module=path_module)
|
||||||
|
|
||||||
elif send_task!='':
|
elif send_task!='':
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ if pyv[0]!='3':
|
||||||
parser = argparse.ArgumentParser(description='Script for create a new mariadb server.')
|
parser = argparse.ArgumentParser(description='Script for create a new mariadb server.')
|
||||||
|
|
||||||
parser.add_argument('--password', help='The password of the new server', required=True)
|
parser.add_argument('--password', help='The password of the new server', required=True)
|
||||||
|
parser.add_argument('--ip', help='The IP where mariadb petitions are listened, if not, only listen in localhost')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
@ -32,7 +33,19 @@ if linux_distro=='debian':
|
||||||
if subprocess.call("sudo DEBIAN_FRONTEND=noninteractive apt-get -y --force-yes install mariadb-server", shell=True) > 0:
|
if subprocess.call("sudo DEBIAN_FRONTEND=noninteractive apt-get -y --force-yes install mariadb-server", shell=True) > 0:
|
||||||
print('Error, cannot install MariaDB...')
|
print('Error, cannot install MariaDB...')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif linux_distro=='arch':
|
|
||||||
|
# sed -i 's/old-text/new-text/g' input.txt
|
||||||
|
|
||||||
|
# /etc/mysql/mariadb.conf.d/50-server.cnf
|
||||||
|
# bind-address = 127.0.0.1
|
||||||
|
|
||||||
|
if args.ip:
|
||||||
|
if subprocess.call("sudo sed -i 's/bind-address = 127.0.0.1/bind-address = {}/g' /etc/mysql/mariadb.conf.d/50-server.cnf".format(args.ip), shell=True) > 0:
|
||||||
|
print('Error, cannot install MariaDB...')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
elif linux_distro=='arch':
|
||||||
|
|
||||||
if call("sudo pacman -S --noconfirm mariadb", shell=True) > 0:
|
if call("sudo pacman -S --noconfirm mariadb", shell=True) > 0:
|
||||||
print('Error, cannot install MariaDB...')
|
print('Error, cannot install MariaDB...')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
@ -46,6 +59,11 @@ else:
|
||||||
print('Mariadb installed successfully')
|
print('Mariadb installed successfully')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
if subprocess.call("sudo systemctl restart mariadb", shell=True) > 0:
|
||||||
|
print('Error, cannot restart mariadb')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if subprocess.call("sudo echo 'mariadb-server mariadb-server/root_password_again password "+args.password+"' | sudo debconf-set-selections", shell=True) > 0:
|
if subprocess.call("sudo echo 'mariadb-server mariadb-server/root_password_again password "+args.password+"' | sudo debconf-set-selections", shell=True) > 0:
|
||||||
print('Error, cannot set the password again')
|
print('Error, cannot set the password again')
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ if [ $? -eq 0 ]; then
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
echo "Sorry, cannot install distro python package..."
|
echo "Sorry, cannot install certbot python package..."
|
||||||
|
|
||||||
exit 1;
|
exit 1;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,16 @@
|
||||||
from modules.pastafari2.libraries.task import Task
|
from modules.pastafari2.libraries.task import Task
|
||||||
#from modules.pastafari.models.tasks import TaskModel
|
#from modules.pastafari.models.tasks import TaskModel
|
||||||
from paramecio2.libraries.db import coreforms
|
from paramecio2.libraries.db import coreforms
|
||||||
|
from paramecio2.libraries.db.extrafields.ipfield import IpField
|
||||||
from paramecio2.libraries.formsutils import show_form
|
from paramecio2.libraries.formsutils import show_form
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
from modules.pastafari2.models.pastafari2 import ServerDbTask
|
||||||
|
try:
|
||||||
|
from modules.mariadb.models.mariadb import DbServerMariaDb
|
||||||
|
server_db=True
|
||||||
|
except:
|
||||||
|
server_db=False
|
||||||
|
|
||||||
|
|
||||||
class ServerTask(Task):
|
class ServerTask(Task):
|
||||||
|
|
||||||
|
|
@ -51,12 +59,43 @@ class ServerTask(Task):
|
||||||
|
|
||||||
self.arr_form['repeat_mysql_password'].label='Repeat MySQL password'
|
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']]]
|
#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:
|
||||||
|
dbserver=DbServerMariaDb(self.connection)
|
||||||
|
|
||||||
|
dbserver.safe_query()
|
||||||
|
|
||||||
|
serverdb=ServerDbTask(self.connection)
|
||||||
|
|
||||||
|
arr_server=serverdb.set_conditions('WHERE ip=%s', [self.server]).select_a_row_where()
|
||||||
|
|
||||||
|
if arr_server:
|
||||||
|
dbserver.insert({'server_id': arr_server['id']})
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def pre_task(self):
|
def pre_task(self):
|
||||||
|
|
||||||
self.commands_to_execute=[['modules/pastafari2/scripts/servers/databases/mariadb/install_mariadb.py', '--password=%s' % self.data['mysql_password']]]
|
ip_option=''
|
||||||
|
|
||||||
|
if 'ip' in self.data:
|
||||||
|
ip_option='--ip='+self.data['ip']
|
||||||
|
|
||||||
|
self.commands_to_execute=[['modules/pastafari2/scripts/servers/databases/mariadb/install_mariadb.py', '--password=%s %s' % (self.data['mysql_password'], ip_option)]]
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
@ -68,19 +107,42 @@ class ServerTask(Task):
|
||||||
|
|
||||||
def check_form(self, post):
|
def check_form(self, post):
|
||||||
|
|
||||||
|
error=False
|
||||||
|
|
||||||
if 'mysql_password' in post and 'repeat_mysql_password' in post:
|
if 'mysql_password' in post and 'repeat_mysql_password' in post:
|
||||||
|
|
||||||
if post['mysql_password'].strip()!='' and post['mysql_password']==post['repeat_mysql_password']:
|
if post['mysql_password'].strip()!='' and post['mysql_password']==post['repeat_mysql_password']:
|
||||||
|
|
||||||
self.data['mysql_password']=post['mysql_password'].strip()
|
self.data['mysql_password']=post['mysql_password'].strip()
|
||||||
return True
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
self.arr_form['mysql_password'].error=True
|
self.arr_form['mysql_password'].error=True
|
||||||
self.arr_form['mysql_password'].txt_error='Passwords doesn\'t match'
|
self.arr_form['mysql_password'].txt_error='Passwords doesn\'t match'
|
||||||
|
error=True
|
||||||
|
|
||||||
|
if 'access_localhost' in post:
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
if error:
|
||||||
return False
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,12 @@ $(document).ready(function () {
|
||||||
else {
|
else {
|
||||||
|
|
||||||
//Make a normal submit to url_task for make_task form
|
//Make a normal submit to url_task for make_task form
|
||||||
if($('#'+task.replace(/\//g, '_')+'_form').val()==1) {
|
|
||||||
|
//modules/pastafari2/tasks/servers/databases/mysql/standalone_mysql.py
|
||||||
|
//alert($('#modules_pastafari2_tasks_servers_databases_mysql_standalone_mysql.py_form').val());
|
||||||
|
//alert(document.getElementById(task.replace(/\//g, '_')+'_form').value);
|
||||||
|
//if($('#'+task.replace(/\//g, '_')+'_form').val()==1) {
|
||||||
|
if(document.getElementById(task.replace(/\//g, '_')+'_form').value==1) {
|
||||||
|
|
||||||
var form=$("<form/>", { 'action': url_task, 'method': 'POST'});
|
var form=$("<form/>", { 'action': url_task, 'method': 'POST'});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<%inherit file="dashboard.phtml"/>
|
<%inherit file="dashboard.phtml"/>
|
||||||
<%block name="content">
|
<%block name="content">
|
||||||
|
${links|n}
|
||||||
<form method="post" name="update_servers" id="update_servers" action="${url_exec}">
|
<form method="post" name="update_servers" id="update_servers" action="${url_exec}">
|
||||||
${form|n}
|
${form|n}
|
||||||
<input type="hidden" name="ids" value="${ids|h}" />
|
<input type="hidden" name="ids" value="${ids|h}" />
|
||||||
|
|
@ -7,6 +8,7 @@ ${form|n}
|
||||||
${csrf_token()|n}
|
${csrf_token()|n}
|
||||||
<p><input type="submit" value="${lang('pastafari','execute_task', 'Execute task')}" /></p>
|
<p><input type="submit" value="${lang('pastafari','execute_task', 'Execute task')}" /></p>
|
||||||
</form>
|
</form>
|
||||||
|
${links|n}
|
||||||
</%block>
|
</%block>
|
||||||
<%block name="jscript_block">
|
<%block name="jscript_block">
|
||||||
<script language="Javascript" src="${make_media_url('js/jsutils/posting2.js', 'monit')}"></script>
|
<script language="Javascript" src="${make_media_url('js/jsutils/posting2.js', 'monit')}"></script>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue