Compare commits

..

No commits in common. "5889e81f04925b3214313b4096817c8bd085877d" and "af780b1247077d5bfc06b83eb71934c5760ac577" have entirely different histories.

3 changed files with 43 additions and 56 deletions

Binary file not shown.

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-08 18:25+0100\n" "POT-Creation-Date: 2024-10-15 21:15+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,19 +17,19 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: workbench-script.py:49 workbench-script.py:54 #: workbench-script.py:48 workbench-script.py:53
msgid "Running command `%s`" msgid "Running command `%s`"
msgstr "Ejecutando comando `%s`" msgstr "Ejecutando comando `%s`"
#: workbench-script.py:279 #: workbench-script.py:284
msgid "Created snapshots directory at '%s'" msgid "Created snapshots directory at '%s'"
msgstr "Creado directorio de snapshots en '%s'" msgstr "Creado directorio de snapshots en '%s'"
#: workbench-script.py:282 #: workbench-script.py:287
msgid "Snapshot written in path '%s'" msgid "Snapshot written in path '%s'"
msgstr "Snapshot escrito en ruta '%s'" msgstr "Snapshot escrito en ruta '%s'"
#: workbench-script.py:285 #: workbench-script.py:290
msgid "" msgid ""
"Attempting to save file in actual path. Reason: Failed to write in snapshots " "Attempting to save file in actual path. Reason: Failed to write in snapshots "
"directory:\n" "directory:\n"
@ -39,11 +39,11 @@ msgstr ""
"escribir en el directorio de snapshots:\n" "escribir en el directorio de snapshots:\n"
" %s." " %s."
#: workbench-script.py:292 #: workbench-script.py:297
msgid "Snapshot written in fallback path '%s'" msgid "Snapshot written in fallback path '%s'"
msgstr "Snapshot escrito en ruta alternativa '%s'" msgstr "Snapshot escrito en ruta alternativa '%s'"
#: workbench-script.py:294 #: workbench-script.py:299
msgid "" msgid ""
"Could not save snapshot locally. Reason: Failed to write in fallback path:\n" "Could not save snapshot locally. Reason: Failed to write in fallback path:\n"
" %s" " %s"
@ -52,53 +52,49 @@ msgstr ""
"alternativa:\n" "alternativa:\n"
" %s" " %s"
#: workbench-script.py:317 #: workbench-script.py:316
msgid "Snapshot successfully sent to '%s'" msgid "Snapshot successfully sent to '%s'"
msgstr "Snapshot enviado con éxito a '%s'" msgstr "Snapshot enviado con éxito a '%s'"
#: workbench-script.py:335 #: workbench-script.py:331
msgid "Snapshot %s could not be sent to URL '%s'"
msgstr "Snapshot %s no se pudo enviar a la URL '%s'"
#: workbench-script.py:338
msgid "" msgid ""
"Snapshot %s not remotely sent to URL '%s'. Do you have internet? Is your " "Snapshot not remotely sent to URL '%s'. Do you have internet? Is your server "
"server up & running? Is the url token authorized?\n" "up & running? Is the url token authorized?\n"
" %s" " %s"
msgstr "" msgstr ""
"Snapshot %s no enviado remotamente a la URL '%s'. Tienes internet? Está el " "Snapshot no enviado remotamente a la URL '%s'. Tienes internet? Está el "
"servidor en marcha? Está autorizado el url token?\n" "servidor en marcha? Está autorizado el url token?\n"
" %s" " %s"
#: workbench-script.py:350 #: workbench-script.py:342
msgid "Found config file in path: %s." msgid "Found config file in path: %s."
msgstr "Encontrado fichero de configuración en ruta: %s." msgstr "Encontrado fichero de configuración en ruta: %s."
#: workbench-script.py:361 #: workbench-script.py:353
msgid "Config file '%s' not found. Using default values." msgid "Config file '%s' not found. Using default values."
msgstr "" msgstr ""
"Fichero de configuración '%s' no encontrado. Utilizando valores por defecto." "Fichero de configuración '%s' no encontrado. Utilizando valores por defecto."
#: workbench-script.py:379 #: workbench-script.py:373
msgid "workbench-script.py [-h] [--config CONFIG]" msgid "workbench-script.py [-h] [--config CONFIG]"
msgstr "" msgstr ""
#: workbench-script.py:380 #: workbench-script.py:374
msgid "Optional config loader for workbench." msgid "Optional config loader for workbench."
msgstr "Cargador opcional de configuración para workbench" msgstr "Cargador opcional de configuración para workbench"
#: workbench-script.py:383 #: workbench-script.py:377
msgid "" msgid ""
"path to the config file. Defaults to 'settings.ini' in the current directory." "path to the config file. Defaults to 'settings.ini' in the current directory."
msgstr "" msgstr ""
"ruta al fichero de configuración. Por defecto es 'settings.ini' en el " "ruta al fichero de configuración. Por defecto es 'settings.ini' en el "
"directorio actual" "directorio actual"
#: workbench-script.py:416 #: workbench-script.py:410
msgid "START" msgid "START"
msgstr "INICIO" msgstr "INICIO"
#: workbench-script.py:430 #: workbench-script.py:423
msgid "" msgid ""
"This script must be run as root. Collected data will be incomplete or " "This script must be run as root. Collected data will be incomplete or "
"unusable" "unusable"
@ -106,6 +102,6 @@ msgstr ""
"Es conveniente que este script sea ejecutado como administrador (root). Los " "Es conveniente que este script sea ejecutado como administrador (root). Los "
"datos recopilados serán incompletos o no usables." "datos recopilados serán incompletos o no usables."
#: workbench-script.py:448 #: workbench-script.py:441
msgid "END" msgid "END"
msgstr "FIN" msgstr "FIN"

View file

@ -6,7 +6,6 @@ import uuid
import hashlib import hashlib
import argparse import argparse
import configparser import configparser
import urllib.parse
import urllib.request import urllib.request
import gettext import gettext
@ -17,7 +16,6 @@ from datetime import datetime
## Legacy Functions ## ## Legacy Functions ##
def convert_to_legacy_snapshot(snapshot): def convert_to_legacy_snapshot(snapshot):
snapshot["sid"] = str(uuid.uuid4()).split("-")[0] snapshot["sid"] = str(uuid.uuid4()).split("-")[0]
snapshot["software"] = "workbench-script" snapshot["software"] = "workbench-script"
@ -27,6 +25,7 @@ def convert_to_legacy_snapshot(snapshot):
snapshot["timestamp"] = snapshot["timestamp"].replace(" ", "T") snapshot["timestamp"] = snapshot["timestamp"].replace(" ", "T")
snapshot["data"]["smart"] = snapshot["data"]["disks"] snapshot["data"]["smart"] = snapshot["data"]["disks"]
snapshot["data"].pop("disks") snapshot["data"].pop("disks")
snapshot.pop("code")
snapshot.pop("erase") snapshot.pop("erase")
## End Legacy Functions ## ## End Legacy Functions ##
@ -55,6 +54,11 @@ def exec_cmd_erase(cmd):
return '' return ''
# return os.popen(cmd).read() # return os.popen(cmd).read()
def gen_code():
uid = str(uuid.uuid4()).encode('utf-8')
return hashlib.shake_256(uid).hexdigest(3)
## End Utility functions ## ## End Utility functions ##
@ -62,6 +66,7 @@ SNAPSHOT_BASE = {
'timestamp': str(datetime.now()), 'timestamp': str(datetime.now()),
'type': 'Snapshot', 'type': 'Snapshot',
'uuid': str(uuid.uuid4()), 'uuid': str(uuid.uuid4()),
'code': gen_code(),
'software': "workbench-script", 'software': "workbench-script",
'version': "0.0.1", 'version': "0.0.1",
'data': {}, 'data': {},
@ -295,13 +300,7 @@ def save_snapshot_in_disk(snapshot, path):
# TODO sanitize url, if url is like this, it fails # TODO sanitize url, if url is like this, it fails
# url = 'http://127.0.0.1:8000/api/snapshot/' # url = 'http://127.0.0.1:8000/api/snapshot/'
def send_snapshot_to_devicehub(snapshot, token, url, legacy): def send_snapshot_to_devicehub(snapshot, token, url):
url_components = urllib.parse.urlparse(url)
ev_path = "evidence/{}".format(snapshot["uuid"])
components = (url_components.schema, url_components.netloc, ev_path, '', '', '')
ev_url = urllib.parse.urlunparse(components)
# apt install qrencode
headers = { headers = {
"Authorization": f"Bearer {token}", "Authorization": f"Bearer {token}",
"Content-Type": "application/json" "Content-Type": "application/json"
@ -315,28 +314,21 @@ def send_snapshot_to_devicehub(snapshot, token, url, legacy):
if 200 <= status_code < 300: if 200 <= status_code < 300:
logger.info(_("Snapshot successfully sent to '%s'"), url) logger.info(_("Snapshot successfully sent to '%s'"), url)
if legacy:
try: try:
response = json.loads(response_text) response = json.loads(response_text)
if response.get('url'): if response.get('url'):
# apt install qrencode # apt install qrencode
qr = "echo {} | qrencode -t ANSI".format(response['url']) qr = "echo {} | qrencode -t ANSI".format(response['url'])
print(exec_cmd(qr))
print("url: {}".format(response['url']))
if response.get("dhid"):
print("dhid: {}".format(response['dhid']))
except Exception:
logger.error(response_text)
else:
qr = "echo {} | qrencode -t ANSI".format(ev_url)
print(exec_cmd(qr)) print(exec_cmd(qr))
print(f"url: {ev_url}") print("url: {}".format(response['url']))
else: if response.get("dhid"):
logger.error(_("Snapshot %s could not be sent to URL '%s'"), snapshot["uuid"], url) print("dhid: {}".format(response['dhid']))
except Exception:
logger.error(response_text)
except Exception as e: except Exception as e:
logger.error(_("Snapshot %s not remotely sent to URL '%s'. Do you have internet? Is your server up & running? Is the url token authorized?\n %s"), snapshot["uuid"], url, e) logger.error(_("Snapshot not remotely sent to URL '%s'. Do you have internet? Is your server up & running? Is the url token authorized?\n %s"), url, e)
def load_config(config_file="settings.ini"): def load_config(config_file="settings.ini"):
""" """
@ -422,7 +414,6 @@ def main():
config_file = args.config config_file = args.config
config = load_config(config_file) config = load_config(config_file)
legacy = config.get("legacy")
# TODO show warning if non root, means data is not complete # TODO show warning if non root, means data is not complete
# if annotate as potentially invalid snapshot (pending the new API to be done) # if annotate as potentially invalid snapshot (pending the new API to be done)
@ -437,13 +428,13 @@ def main():
elif config['erase'] and not config.get("legacy"): elif config['erase'] and not config.get("legacy"):
snapshot['erase'] = gen_erase(all_disks, config['erase']) snapshot['erase'] = gen_erase(all_disks, config['erase'])
if legacy: if config.get("legacy"):
convert_to_legacy_snapshot(snapshot) convert_to_legacy_snapshot(snapshot)
save_snapshot_in_disk(snapshot, config['path']) save_snapshot_in_disk(snapshot, config['path'])
if config['url']: if config['url']:
send_snapshot_to_devicehub(snapshot, config['token'], config['url'], legacy) send_snapshot_to_devicehub(snapshot, config['token'], config['url'])
logger.info(_("END")) logger.info(_("END"))