yunopaste: anonymize_output is too harsh and not yunopaste's job + print_usage ain't called ...

This commit is contained in:
Alexandre Aubin 2023-07-10 19:25:25 +02:00
parent 773bf803b8
commit a16fabeb86

View file

@ -3,7 +3,6 @@
import sys
import requests
import json
import re
SERVER_URL = "https://paste.yunohost.org"
TIMEOUT = 3
@ -19,43 +18,14 @@ def create_snippet(data):
print("\033[31mError: {}\033[0m".format(e))
sys.exit(1)
def anonymize_output(output):
# Replace IPv4 addresses
output = re.sub(r"\b(?:\d{1,3}\.){3}\d{1,3}\b", "[IPv4]", output)
# Replace IPv6 addresses
output = re.sub(r"\b(?:[A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}\b", "[IPv6]", output)
# Replace domain names
output = re.sub(r"\b(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}\b", "[DOMAIN]", output)
return output
def print_usage():
print("\033[33mUsage:")
print("\033[34m yunopaste [-na|--no-anonymize]\033[0m")
print("\033[33mDescription:")
print("\033[36m Reads the command output from stdin and pastes it to the YunoHost Haste server.")
print(" Prints the URL of the created snippet.\033[0m")
print("\033[33mOptions:")
print("\033[35m -na, --no-anonymize\t\033[0mDo not anonymize the output")
print("\033[33mExample:")
print("\033[35m yunohost diagnosis show | yunopaste\033[0m")
print("\033[35m yunohost diagnosis show | yunopaste -na\033[0m")
def main():
if "-na" in sys.argv or "--no-anonymize" in sys.argv:
anonymize_output_flag = False
else:
anonymize_output_flag = True
output = sys.stdin.read()
if not output:
print("\033[31mError: No input received from stdin.\033[0m")
sys.exit(1)
if anonymize_output_flag:
output = anonymize_output(output)
url = create_snippet(output)
print("\033[32mURL: {}\033[0m".format(url))