zotero-plugin 5.0.26 → 5.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/fetch-zotero-log.py +54 -17
- package/bin/release.js +1 -1
- package/debug-log.js +4 -2
- package/package.json +1 -1
package/bin/fetch-zotero-log.py
CHANGED
|
@@ -3,21 +3,58 @@
|
|
|
3
3
|
import sys, os
|
|
4
4
|
import urllib.request
|
|
5
5
|
from zipfile import ZipFile
|
|
6
|
+
from types import SimpleNamespace
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
from cryptography.hazmat.primitives.asymmetric import padding
|
|
9
|
+
from cryptography.hazmat.primitives import hashes
|
|
10
|
+
from cryptography.hazmat.primitives.serialization import load_pem_private_key
|
|
11
|
+
|
|
12
|
+
def debuglog():
|
|
13
|
+
local, host, remote = sys.argv[1].split('-')
|
|
14
|
+
if host != '0x0':
|
|
15
|
+
print('unexpected debug log host', host)
|
|
16
|
+
sys.exit(1)
|
|
17
|
+
|
|
18
|
+
encrypted = ('.') in remote
|
|
19
|
+
remote = remote.split('.')[0]
|
|
20
|
+
ext = '.enc' if encrypted else '.zip'
|
|
21
|
+
url = f'https://0x0.com/{remote}{ext}'
|
|
22
|
+
return SimpleNamespace(local=local, host=host, remote=remote, encrypted=encrypted, ext=ext, url=url)
|
|
23
|
+
|
|
24
|
+
def download():
|
|
25
|
+
debuglog.downloaded = f'logs/{debuglog.local}{debuglog.ext}'
|
|
26
|
+
print(debuglog.url, '=>', debuglog.downloaded)
|
|
27
|
+
logs = os.path.dirname(log)
|
|
28
|
+
if not os.path.exists(logs):
|
|
29
|
+
os.makedirs(logs)
|
|
30
|
+
urllib.request.urlretrieve(debuglog.url, debuglog.downloaded)
|
|
31
|
+
|
|
32
|
+
def decrypt():
|
|
33
|
+
if not debuglog.encrypted:
|
|
34
|
+
return
|
|
35
|
+
|
|
36
|
+
encrypted = debuglog.downloaded
|
|
37
|
+
debuglog.downloaded = f'logs/{debuglog.local}.zip'
|
|
38
|
+
|
|
39
|
+
with open(sys.argv[2], 'rb') as f:
|
|
40
|
+
private_key = load_pem_private_key(f.read(), password=None)
|
|
41
|
+
with open(encrypted, 'rb') as f:
|
|
42
|
+
encrypted_data = f.read()
|
|
43
|
+
with open(debuglog.downloaded, 'wb') as f:
|
|
44
|
+
f.write(private_key.decrypt(encrypted_data, padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None)))
|
|
45
|
+
|
|
46
|
+
def show():
|
|
47
|
+
with ZipFile(debuglod.downloaded) as f:
|
|
48
|
+
for name in f.namelist():
|
|
49
|
+
if not '/' in name:
|
|
50
|
+
print('Unexpected', name, 'in', sys.argv[1])
|
|
51
|
+
sys.exit(1)
|
|
52
|
+
print(name)
|
|
53
|
+
f.extractall(path='logs')
|
|
54
|
+
os.remove(debuglog.downloaded)
|
|
55
|
+
print(debuglog.local)
|
|
56
|
+
|
|
57
|
+
debuglog = debuglog()
|
|
58
|
+
download()
|
|
59
|
+
decrypt()
|
|
60
|
+
show()
|
package/bin/release.js
CHANGED
|
@@ -8448,7 +8448,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
8448
8448
|
"package.json"(exports, module) {
|
|
8449
8449
|
module.exports = {
|
|
8450
8450
|
name: "zotero-plugin",
|
|
8451
|
-
version: "5.0.
|
|
8451
|
+
version: "5.0.27",
|
|
8452
8452
|
description: "Zotero plugin builder",
|
|
8453
8453
|
homepage: "https://github.com/retorquere/zotero-plugin/wiki",
|
|
8454
8454
|
bin: {
|
package/debug-log.js
CHANGED
|
@@ -88,6 +88,7 @@ class DebugLogSender {
|
|
|
88
88
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
89
89
|
const zip = new Uint8Array(UZip.encode(files));
|
|
90
90
|
let blob;
|
|
91
|
+
let ext = '';
|
|
91
92
|
if (pubkey) {
|
|
92
93
|
try {
|
|
93
94
|
const subtle = Zotero.getMainWindow().crypto.subtle;
|
|
@@ -99,6 +100,7 @@ class DebugLogSender {
|
|
|
99
100
|
const publicKey = await subtle.importKey('spki', keyBuffer, { name: 'RSA-OAEP', hash: 'SHA-256' }, true, ['encrypt']);
|
|
100
101
|
const encrypted = await subtle.encrypt({ name: 'RSA-OAEP' }, publicKey, zip);
|
|
101
102
|
blob = new Blob([encrypted], { type: 'application/octet-stream' });
|
|
103
|
+
ext = '.enc';
|
|
102
104
|
}
|
|
103
105
|
catch (err) {
|
|
104
106
|
Services.prompt.alert(null, `Log encryption for ${plugin} failed`, err.message);
|
|
@@ -107,7 +109,7 @@ class DebugLogSender {
|
|
|
107
109
|
if (!blob)
|
|
108
110
|
blob = new Blob([zip], { type: 'application/zip' });
|
|
109
111
|
const formData = new FormData();
|
|
110
|
-
formData.append('file', blob, `${key}.zip`);
|
|
112
|
+
formData.append('file', blob, `${key}${ext || '.zip'}`);
|
|
111
113
|
formData.append('expire', `${7 * 24}`);
|
|
112
114
|
try {
|
|
113
115
|
const response = await fetch('https://0x0.st', {
|
|
@@ -121,7 +123,7 @@ class DebugLogSender {
|
|
|
121
123
|
const id = body.match(/https:\/\/0x0.st\/([A-Z0-9]+)\.zip/i);
|
|
122
124
|
if (!id)
|
|
123
125
|
throw new Error(body);
|
|
124
|
-
Services.prompt.alert(null, `Debug log ID for ${plugin}`, `${key}-0x0-${id[1]}`);
|
|
126
|
+
Services.prompt.alert(null, `Debug log ID for ${plugin}`, `${key}-0x0-${id[1]}{ext}`);
|
|
125
127
|
}
|
|
126
128
|
catch (err) {
|
|
127
129
|
Services.prompt.alert(null, `Could not post debug log for ${plugin}`, err.message);
|