-
Notifications
You must be signed in to change notification settings - Fork 0
/
osprey_app-sbit_qrid-v2.py
executable file
·101 lines (76 loc) · 3.34 KB
/
osprey_app-sbit_qrid-v2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/python3.8
# LICENSE CREATIVE_COMMONS-ATTRIBUTION_SHARE_ALIKE
# https://creativecommons.org/licenses/by-sa/3.0/legalcode
# Copyright (c) 2020-2022 Nathaniel Steven Henry Brown [[email protected]]
import sys
from sys import exit
import os.path
import json
import pyqrcode as qrcode
import io
import subprocess
import re
sources = """
Sources:
https://www.askpython.com/python/built-in-methods/python-read-file
"""
SCRIPT_SBIT = '/osprey_app-scripts/osprey_app-sbit-v8.py'
SCRIPT_QRID = '/osprey_app-scripts/osprey_app-qrid-v1.py'
version = 'sbit_qrid-v1'
if len(sys.argv) == 1:
motd_help = """
Welcome to OSPREY.app's {0}
-----------------------------------------------------
LICENSE CREATIVE_COMMONS-ATTRIBUTION_SHARE_ALIKE
https://creativecommons.org/licenses/by-sa/3.0/legalcode
Copyright (c) 2020-2022 Nathaniel Steven Henry Brown [[email protected]]
[REQS]
This is script is compiled to run on Ubuntu 16LTS and above with
python3 support having net-tools and OpenSSL 1.1.1l installed.
[USAGE]
The purpose of this script is to generate a qrcode based on a string
used through to the latest sbit script (v8) as of writing this code.
To run this command, use start as the first parameter.
./osprey_app-{0} "Your Message Here"
"""
print(motd_help.format(version))
exit(0)
if len(sys.argv) <= 1:
print('[ERROR] Missing message.')
exit(1)
else:
message = sys.argv[1]
msg_as_file_name = re.sub(r'[^a-zA-Z0-9]+', '_', message)
sbit_json_file_path = '/sbit.osprey.app/json/' + msg_as_file_name[:255] + '.json'
cmd = SCRIPT_SBIT + ' -json "' + message + '" > ' + sbit_json_file_path
sbit_json_proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, executable="/bin/bash")
sbit_json = sbit_json_proc.stdout.read().decode('utf-8').strip()
sbit_json_proc.terminate()
if os.path.isfile(sbit_json_file_path):
print("** file created: " + sbit_json_file_path)
def sha2_256_sumfile(sbit_json_file_path):
cmd = 'openssl dgst -sha256 ' + sbit_json_file_path
json_sha2_256_proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, executable="/bin/bash")
json_sha2_256_return = json_sha2_256_proc.stdout.read().decode('utf-8').strip()
json_sha2_256_proc.terminate()
# print(json_sha2_256)
json_sha2_256 = json_sha2_256_return.split(' ')[1]
cmd = 'echo "' + json_sha2_256 + '" > ' + sbit_json_file_path + '.sha2_256'
json_sha2_256_copy_proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, executable="/bin/bash")
json_sha2_256_copy_proc.terminate()
print("** file created: " + sbit_json_file_path + '.sha2_256')
cmd = SCRIPT_SBIT + ' "' + json_sha2_256 + '" > ' + sbit_json_file_path + '.sbit'
sbit_proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, executable="/bin/bash")
sbit_return = sbit_proc.stdout.read().decode('utf-8').strip()
sbit_proc.terminate()
print("** file created: " + sbit_json_file_path + '.sbit')
sha2_256_sumfile(sbit_json_file_path)
cmd = SCRIPT_QRID + ' "' + sbit_json_file_path + '"'
sbit_json_proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, executable="/bin/bash")
sbit_json = sbit_json_proc.stdout.read().decode('utf-8').strip()
sbit_json_proc.terminate()
png_filename = '/sbit.osprey.app/qr.png/' + os.path.basename(sbit_json_file_path) + '.png'
if os.path.isfile(png_filename):
print("** file created: " + png_filename)
sha2_256_sumfile(png_filename)
exit(0)