Merge branch 'main' of https://github.com/itsdave-de/msp into main

This commit is contained in:
Beate Trzensiok 2022-03-14 16:28:43 +01:00
commit eafc50851e
11 changed files with 363 additions and 9 deletions

View File

@ -2,7 +2,35 @@
// For license information, please see license.txt
frappe.ui.form.on('IT Landscape', {
// refresh: function(frm) {
refresh: function(frm) {
frm.add_custom_button('Copy SSH Keys', () => frm.trigger('copy_ssh_keys'), 'Actions');
},
copy_ssh_keys: function(frm) {
frappe.call({
"method": "msp.whitelisted_tools.get_ssh_keys_for_landscape",
args: {
"landscape": frm.doc.name,
},
callback: (response) => {
if (response.message.startsWith("#")) {
console.log(response.message),
frm.events.CopyToClipboard(response.message),
frappe.msgprint(__('Keys copied to clipboard.'))
}
else {
frappe.msgprint(__(response.message));
}
// }
});
}
})
},
CopyToClipboard: function(value) {
var tempInput = document.createElement("textarea");
tempInput.value = value;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand("copy");
document.body.removeChild(tempInput);
}
})

View File

@ -1,4 +1,5 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "field:abbreviation",
"creation": "2021-03-18 01:39:06.814363",
@ -9,7 +10,9 @@
"title",
"abbreviation",
"customer",
"description"
"customer_name",
"description",
"section_break_6"
],
"fields": [
{
@ -39,9 +42,22 @@
"in_standard_filter": 1,
"label": "Abbreviation",
"unique": 1
},
{
"fetch_from": "customer.customer_name",
"fieldname": "customer_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Customer Name",
"read_only": 1
},
{
"fieldname": "section_break_6",
"fieldtype": "Section Break"
}
],
"modified": "2021-03-24 00:34:10.605746",
"links": [],
"modified": "2022-01-27 23:36:00.711074",
"modified_by": "Administrator",
"module": "MSP",
"name": "IT Landscape",

View File

@ -9,7 +9,7 @@ def get_data():
'transactions': [
{
'label': _('Objects'),
'items': ['IT Object', 'IT User Account', 'IP Network', 'IP Address' ]
'items': ['IT Object', 'IT User Account', 'IP Network', 'IP Address', 'SSH Public Key' ]
},
{
'label': _('Processes'),

View File

@ -1,4 +1,5 @@
{
"actions": [],
"autoname": "ITO-.#####",
"creation": "2021-03-18 01:33:25.740040",
"doctype": "DocType",
@ -120,7 +121,8 @@
}
],
"image_field": "image",
"modified": "2021-03-24 13:25:22.542341",
"links": [],
"modified": "2022-01-27 22:39:21.190206",
"modified_by": "Administrator",
"module": "MSP",
"name": "IT Object",
@ -140,7 +142,7 @@
}
],
"quick_entry": 1,
"search_fields": "title, main_ip, item, description",
"search_fields": "title, main_ip, item",
"sort_field": "modified",
"sort_order": "DESC",
"title_field": "title",

View File

@ -0,0 +1,8 @@
// Copyright (c) 2022, itsdave GmbH and contributors
// For license information, please see license.txt
frappe.ui.form.on('SSH Public Key', {
// refresh: function(frm) {
// }
});

View File

@ -0,0 +1,111 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2022-01-27 22:32:57.359431",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"employee",
"host",
"it_landscape",
"column_break_4",
"employee_name",
"host_name",
"customer_name",
"ssh_key_section",
"status",
"ssh_public_key"
],
"fields": [
{
"fieldname": "employee",
"fieldtype": "Link",
"in_standard_filter": 1,
"label": "Employee",
"options": "Employee"
},
{
"description": "System of the employee, on which this key is used from.",
"fieldname": "host",
"fieldtype": "Link",
"in_standard_filter": 1,
"label": "Host",
"options": "IT Object"
},
{
"fieldname": "it_landscape",
"fieldtype": "Link",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "IT Landscape",
"options": "IT Landscape"
},
{
"fieldname": "ssh_public_key",
"fieldtype": "Long Text",
"label": "SSH Public Key"
},
{
"fieldname": "column_break_4",
"fieldtype": "Column Break"
},
{
"fetch_from": "employee.employee_name",
"fieldname": "employee_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Employee Name",
"read_only": 1
},
{
"fetch_from": "host.title",
"fieldname": "host_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Host Name",
"read_only": 1
},
{
"fieldname": "ssh_key_section",
"fieldtype": "Section Break",
"label": "SSH Key"
},
{
"fieldname": "status",
"fieldtype": "Select",
"label": "Status",
"options": "active\ninactive\ncompromised"
},
{
"fetch_from": "it_landscape.customer_name",
"fieldname": "customer_name",
"fieldtype": "Data",
"label": "Customer",
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2022-01-27 23:40:39.860991",
"modified_by": "Administrator",
"module": "MSP",
"name": "SSH Public Key",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC"
}

View File

@ -0,0 +1,8 @@
# Copyright (c) 2022, itsdave GmbH and contributors
# For license information, please see license.txt
# import frappe
from frappe.model.document import Document
class SSHPublicKey(Document):
pass

View File

@ -0,0 +1,8 @@
# Copyright (c) 2022, itsdave GmbH and Contributors
# See license.txt
# import frappe
import unittest
class TestSSHPublicKey(unittest.TestCase):
pass

View File

@ -0,0 +1,153 @@
{
"cards_label": "Authentication",
"category": "Modules",
"charts": [],
"creation": "2022-01-27 22:35:58.651670",
"developer_mode_only": 0,
"disable_user_customization": 0,
"docstatus": 0,
"doctype": "Workspace",
"extends_another_page": 0,
"hide_custom": 0,
"icon": "support",
"idx": 0,
"is_default": 0,
"is_standard": 1,
"label": "MSP",
"links": [
{
"hidden": 0,
"is_query_report": 0,
"label": "Master Data",
"link_type": "DocType",
"onboard": 0,
"type": "Card Break"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Objects",
"link_to": "IT Object",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Networks",
"link_to": "IP Network",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Addresses",
"link_to": "IP Address",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Authentication",
"link_type": "DocType",
"onboard": 0,
"type": "Card Break"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "SSH Keys",
"link_to": "SSH Public Key",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "User Accounts",
"link_to": "IT User Account",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Processes",
"link_type": "DocType",
"onboard": 0,
"type": "Card Break"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Checklists",
"link_to": "IT Checklist",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Contracts",
"link_to": "IT Contract",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Settings",
"link_type": "DocType",
"onboard": 0,
"type": "Card Break"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Checklist Templates",
"link_to": "IT Checklist Template",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Contract Types",
"link_to": "IT Contract Type",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
}
],
"modified": "2022-01-27 22:49:32.927072",
"modified_by": "Administrator",
"module": "MSP",
"name": "MSP",
"owner": "Administrator",
"pin_to_bottom": 0,
"pin_to_top": 1,
"shortcuts": [
{
"doc_view": "List",
"label": "Objects",
"link_to": "IT Object",
"type": "DocType"
},
{
"doc_view": "List",
"label": "Landscapes",
"link_to": "IT Landscape",
"type": "DocType"
}
]
}

20
msp/whitelisted_tools.py Normal file
View File

@ -0,0 +1,20 @@
import frappe
from datetime import datetime
@frappe.whitelist()
def get_ssh_keys_for_landscape(landscape):
keys = frappe.get_all("SSH Public Key", filters={"it_landscape": landscape, "status": "active"})
print(keys)
if len(keys) >= 1:
keys_str = ""
for key in keys:
kd = frappe.get_doc("SSH Public Key", key["name"])
company_str = str(frappe.get_doc("Employee", kd.employee).company)
c_str = datetime.strftime(kd.creation, "%d.%m.%Y")
o_str = datetime.strftime(datetime.now(), "%d.%m.%Y %H:%M")
comment = "#"+ company_str + "|" + str(kd.employee_name) + "@" + str(kd.host_name) + " ITL:" + str(kd.it_landscape) + " C:" + c_str + " O:" + o_str
keys_str += comment + "\n" + kd.ssh_public_key + "\n"
return keys_str
else:
return "No keys found."