Fixes in tasks
This commit is contained in:
parent
ec52e45969
commit
6cd4598708
4 changed files with 50 additions and 54 deletions
|
|
@ -27,6 +27,7 @@ from importlib import import_module, reload
|
||||||
from modules.pastafari2.libraries.progress import load_progress
|
from modules.pastafari2.libraries.progress import load_progress
|
||||||
from modules.pastafari2.libraries.load_task import load_db_in_task
|
from modules.pastafari2.libraries.load_task import load_db_in_task
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
|
from subprocess import call
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import ujson as json
|
import ujson as json
|
||||||
|
|
@ -147,21 +148,38 @@ def pastafari2_edit_global_ssh_keys():
|
||||||
|
|
||||||
form={}
|
form={}
|
||||||
|
|
||||||
error=0
|
error=1
|
||||||
|
|
||||||
|
# -C "your_email@example.com" -f $HOME/.ssh/id_rsa
|
||||||
|
|
||||||
|
arr_type={'dsa': 'ssh-keygen -t dsa', 'ecdsa': 'ssh-keygen -t ecdsa -b 521', 'ed25519': 'ssh-keygen -t ed25519'}
|
||||||
|
|
||||||
|
ssh_key_type=request.args.get('ssh_key_type')
|
||||||
|
|
||||||
|
if ssh_key_type in arr_type:
|
||||||
|
|
||||||
|
file_ssh_path='-f {}/id_rsa -q -N ""'.format(system_path)
|
||||||
|
|
||||||
if not os.path.isfile(system_path+'id_rsa'):
|
if not os.path.isfile(system_path+'id_rsa'):
|
||||||
|
|
||||||
try:
|
if call(arr_type[ssh_key_type]+' '+file_ssh_path, shell=True) > 0:
|
||||||
|
|
||||||
key=paramiko.RSAKey.generate(2048)
|
|
||||||
key.write_private_key_file(system_path+'id_rsa')
|
|
||||||
|
|
||||||
with open(system_path+'id_rsa.pub',"w") as pub_key:
|
|
||||||
pub_key.write("%s %s" % (key.get_name(), key.get_base64()))
|
|
||||||
|
|
||||||
except:
|
|
||||||
|
|
||||||
error=1
|
error=1
|
||||||
|
else:
|
||||||
|
error=0
|
||||||
|
|
||||||
|
#try:
|
||||||
|
|
||||||
|
#key=paramiko.RSAKey.generate(2048)
|
||||||
|
#key=paramiko.Ed25519Key.generate()
|
||||||
|
#key.write_private_key_file(system_path+'id_rsa')
|
||||||
|
|
||||||
|
#with open(system_path+'id_rsa.pub',"w") as pub_key:
|
||||||
|
# pub_key.write("%s %s" % (key.get_name(), key.get_base64()))
|
||||||
|
|
||||||
|
#except:
|
||||||
|
|
||||||
|
# error=1
|
||||||
|
|
||||||
return {'error': error}
|
return {'error': error}
|
||||||
|
|
||||||
|
|
@ -398,7 +416,7 @@ def options_options(row_id, row):
|
||||||
|
|
||||||
arr_options=['<a href="{}">{}</a>'.format(url_for('admin_app.pastafari2_edit_server', id=row_id, op_admin=1), _('Edit'))]
|
arr_options=['<a href="{}">{}</a>'.format(url_for('admin_app.pastafari2_edit_server', id=row_id, op_admin=1), _('Edit'))]
|
||||||
|
|
||||||
arr_options.append('<a href="{}">{}</a>'.format(url_for('admin_app.pastafari2_edit_users', id=row_id, op_admin=1), _('Users')))
|
#arr_options.append('<a href="{}">{}</a>'.format(url_for('admin_app.pastafari2_edit_users', id=row_id, op_admin=1), _('Users')))
|
||||||
|
|
||||||
arr_options.append('<a href="{}">{}</a>'.format(url_for('admin_app.pastafari2_delete_server', server_id=row_id), _('Delete')))
|
arr_options.append('<a href="{}">{}</a>'.format(url_for('admin_app.pastafari2_delete_server', server_id=row_id), _('Delete')))
|
||||||
|
|
||||||
|
|
@ -839,7 +857,7 @@ def pastafari2_save_positions():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return {'error': error, 'form': error_form, 'txt_error': txt_error}
|
return {'error': error, 'form': error_form, 'txt_error': txt_error}
|
||||||
|
"""
|
||||||
@admin_app.route('/pastafari2/edit_users')
|
@admin_app.route('/pastafari2/edit_users')
|
||||||
def pastafari2_edit_users():
|
def pastafari2_edit_users():
|
||||||
|
|
||||||
|
|
@ -852,41 +870,6 @@ def pastafari2_get_server_users():
|
||||||
|
|
||||||
# {"fields": [{"Username": true, "Options": false}], "rows": [{"username": "developer", "options": ""}], "html_pages": ""}
|
# {"fields": [{"Username": true, "Options": false}], "rows": [{"username": "developer", "options": ""}], "html_pages": ""}
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
db=g.connection
|
|
||||||
|
|
||||||
group_sql=''
|
|
||||||
|
|
||||||
count_data=[]
|
|
||||||
sql_data=[]
|
|
||||||
|
|
||||||
group_id=request.form.get('group_id', '')
|
|
||||||
|
|
||||||
group_sql_count=''
|
|
||||||
group_sql=''
|
|
||||||
|
|
||||||
if group_id!='':
|
|
||||||
group_sql_count=' WHERE `group_id`=%s'
|
|
||||||
count_data=[group_id]
|
|
||||||
sql_data=[group_id]
|
|
||||||
group_sql=' WHERE `group_id`=%s'
|
|
||||||
|
|
||||||
fields=[[_('Hostname'), True], ['IP', True], [_('Selected'), False], [_('Options'), False]]
|
|
||||||
arr_order_fields=['hostname', 'ip']
|
|
||||||
|
|
||||||
count_query=['select count(serverdbtask.id) as num_elements from serverdbtask'+group_sql_count, count_data]
|
|
||||||
|
|
||||||
str_query=['select serverdbtask.hostname, serverdbtask.ip, serverdbtask.id as select_id, serverdbtask.id from serverdbtask'+group_sql, sql_data]
|
|
||||||
|
|
||||||
ajax=AjaxList(db, fields, arr_order_fields, count_query, str_query)
|
|
||||||
|
|
||||||
ajax.func_fields['select_id']=options_selected
|
|
||||||
ajax.func_fields['id']=options_options
|
|
||||||
ajax.limit=0
|
|
||||||
|
|
||||||
return ajax.show()
|
|
||||||
"""
|
|
||||||
fields=[['Username', True], ['Options', False]]
|
fields=[['Username', True], ['Options', False]]
|
||||||
|
|
||||||
rows=[{'username': 'developer', 'options': ''}]
|
rows=[{'username': 'developer', 'options': ''}]
|
||||||
|
|
@ -897,3 +880,4 @@ def pastafari2_get_server_users():
|
||||||
|
|
||||||
return json.dumps(arr_return)
|
return json.dumps(arr_return)
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
|
||||||
4
api.py
4
api.py
|
|
@ -28,7 +28,7 @@ from importlib import import_module, reload
|
||||||
from paramecio2.libraries.keyutils import create_key_encrypt
|
from paramecio2.libraries.keyutils import create_key_encrypt
|
||||||
from modules.pastafari2 import pastafari_app
|
from modules.pastafari2 import pastafari_app
|
||||||
from paramecio2.libraries.plugins import db
|
from paramecio2.libraries.plugins import db
|
||||||
from flask import g
|
from flask import g, request
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -143,7 +143,7 @@ def add_group(post: Annotated[ServerGroups, 'Add group to the cuchulucp system']
|
||||||
|
|
||||||
if insert(groupdb, db, post):
|
if insert(groupdb, db, post):
|
||||||
code_error=0
|
code_error=0
|
||||||
error=False
|
error=0
|
||||||
message=_('Success')
|
message=_('Success')
|
||||||
|
|
||||||
return {'error': error, 'message': message, 'code_error': code_error}
|
return {'error': error, 'message': message, 'code_error': code_error}
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,7 @@ class Task:
|
||||||
|
|
||||||
add_host=False
|
add_host=False
|
||||||
|
|
||||||
|
"""
|
||||||
rsa=None
|
rsa=None
|
||||||
if self.private_key!='':
|
if self.private_key!='':
|
||||||
try:
|
try:
|
||||||
|
|
@ -133,6 +134,8 @@ class Task:
|
||||||
except paramiko.ssh_exception.SSHException:
|
except paramiko.ssh_exception.SSHException:
|
||||||
rsa=paramiko.Ed25519Key.from_private_key_file(self.private_key, self.password_key)
|
rsa=paramiko.Ed25519Key.from_private_key_file(self.private_key, self.password_key)
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
if check_ssh_host.lookup(self.server)==None:
|
if check_ssh_host.lookup(self.server)==None:
|
||||||
|
|
||||||
# Be tolerant for the first connect with hostkey policy
|
# Be tolerant for the first connect with hostkey policy
|
||||||
|
|
@ -153,7 +156,9 @@ class Task:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
self.ssh.connect(self.server, port=self.port, username=self.remote_user, password=self.remote_password, pkey=rsa, key_filename=None, timeout=None, allow_agent=True, look_for_keys=True, compress=False, sock=None, gss_auth=False, gss_kex=False, gss_deleg_creds=True, gss_host=None, banner_timeout=None)
|
#self.ssh.connect(self.server, port=self.port, username=self.remote_user, password=self.remote_password, pkey=rsa, key_filename=None, timeout=None, allow_agent=True, look_for_keys=True, compress=False, sock=None, gss_auth=False, gss_kex=False, gss_deleg_creds=True, gss_host=None, banner_timeout=None)
|
||||||
|
|
||||||
|
self.ssh.connect(self.server, port=self.port, username=self.remote_user, password=self.remote_password, key_filename=self.private_key, passphrase=self.password_key, timeout=None, allow_agent=False, look_for_keys=False, compress=False, sock=None, gss_auth=False, gss_kex=False, gss_deleg_creds=True, gss_host=None, banner_timeout=None)
|
||||||
|
|
||||||
if add_host:
|
if add_host:
|
||||||
host_key.save(self.config.ssh_directory+'/known_hosts')
|
host_key.save(self.config.ssh_directory+'/known_hosts')
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,16 @@
|
||||||
<div class="form">
|
<div class="form">
|
||||||
${txt_error|n}
|
${txt_error|n}
|
||||||
${txt_generate_key|n}
|
${txt_generate_key|n}
|
||||||
</div>
|
|
||||||
% if not regenerate:
|
% if not regenerate:
|
||||||
|
<p>
|
||||||
|
<select name="ssh_key_type" id="ssh_key_type">
|
||||||
|
<option value="dsa">DSA</option>
|
||||||
|
<option value="ecdsa">ECDSA</option>
|
||||||
|
<option value="ed25519" selected>ED25519</option>
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
<p><input type="submit" value="${txt_generate_key_button}" /></p>
|
<p><input type="submit" value="${txt_generate_key_button}" /></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
% endif
|
% endif
|
||||||
</form>
|
</form>
|
||||||
|
|
@ -21,7 +28,7 @@
|
||||||
|
|
||||||
% if not regenerate:
|
% if not regenerate:
|
||||||
|
|
||||||
var options={url: "${url_for('admin_app.pastafari2_edit_global_ssh_keys')}", loading: '#layer_loading', pre_callback: function (data) {
|
var options={url: "${url_for('admin_app.pastafari2_edit_global_ssh_keys')}?ssh_key_type="+$('#ssh_key_type').val(), loading: '#layer_loading', pre_callback: function (data) {
|
||||||
|
|
||||||
//alert('This action overwrite all ssh keys');
|
//alert('This action overwrite all ssh keys');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue