Add option to post Bitlocker info to osTicket
This commit is contained in:
parent
813157fd17
commit
e963b2afa6
1 changed files with 56 additions and 7 deletions
|
|
@ -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():
|
||||
|
|
|
|||
Loading…
Reference in a new issue