From e963b2afa6888e0fa8065716c5d5e92c98512abc Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Fri, 23 Dec 2022 18:05:44 -0800 Subject: [PATCH] Add option to post Bitlocker info to osTicket --- scripts/wk/os/win.py | 63 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/scripts/wk/os/win.py b/scripts/wk/os/win.py index 96028528..647cd63d 100644 --- a/scripts/wk/os/win.py +++ b/scripts/wk/os/win.py @@ -25,12 +25,14 @@ from wk.cfg.windows_builds import ( ) from wk.exe import get_json_from_command, run_program from wk.kit.tools import find_kit_dir +from wk.osticket import osTicket, pad_with_dots from wk.std import ( GenericError, GenericWarning, bytes_to_string, color_string, input_text, + pause, sleep, ) @@ -192,16 +194,63 @@ def export_bitlocker_info(): ['manage-bde', '-status', SYSTEMDRIVE], ['manage-bde', '-protectors', '-get', SYSTEMDRIVE], ] + file_name = '' + output = [] + output_raw = [] + output_str = '' - # Get filename - file_name = input_text(prompt='Enter filename', allow_empty_response=False) + # Get info + for cmd in commands: + proc = run_program(cmd, check=False) + if proc.stdout: + output_raw.extend(proc.stdout.splitlines()[3:]) + for line in output_raw: + if line.startswith(' ') and ':' in line: + parts = line.split(':') + if len(parts) < 2: + # Not a key/value pair + output.append(f'.. {line}') + continue + key = parts.pop(0) + key = f'.. {key.strip()+":":<22}' + key = pad_with_dots(key, pad_right=True) + value = ' '.join(parts) + value = value.strip() + output.append(f'{key} {value}') + else: + output.append(line) + output_str = '\n'.join(output) + + # Show info + print('\n'.join(output_raw), '\n\n') + + # Save to osTicket + ost = osTicket() + ost.init() + ost.select_ticket() + if not ost.disabled: + ost.post_response(output_str) + result = 'OK' + if ost.disabled or ost.errors: + result = 'Unknown' + print( + color_string( + ['\nPost info to osTicket... ', result], + [None, 'GREEN' if result == 'OK' else 'YELLOW'], + ) + ) + + # Save to file + if ost.ticket_name: + file_name = f'{ost.ticket_id}_{ost.ticket_name.replace(" ", "-")}' + if not file_name: + file_name = input_text(prompt='Enter filename', allow_empty_response=False) file_path = pathlib.Path(f'../../Bitlocker_{file_name}.txt').resolve() - - # Save info with open(file_path, 'a', encoding='utf-8') as _f: - for cmd in commands: - proc = run_program(cmd, check=False) - _f.write(f'{proc.stdout}\n\n') + _f.write(f'{output_str}\n\n') + + # Done + pause('\nPress Enter to exit...') def get_installed_antivirus():