Add qrcode for briar address

main
bashrc 2026-07-05 11:15:08 +01:00
parent 35e40455bb
commit e5cafd9d53
6 changed files with 80 additions and 11 deletions

View File

@ -8,8 +8,13 @@ __status__ = "Production"
__module_group__ = "Profile Metadata"
import pyqrcode
from src.utils import load_json
from src.utils import acct_dir
from src.utils import get_attachment_property_value
from src.utils import remove_html
from src.data import is_a_file
from src.data import erase_file
def get_briar_address(actor_json: {}) -> str:
@ -64,9 +69,47 @@ def get_briar_address(actor_json: {}) -> str:
return ''
def set_briar_address(actor_json: {}, briar_address: str) -> None:
def save_briar_qrcode(base_dir: str,
nickname: str, domain: str,
scale: int = 6) -> bool:
"""Saves a qrcode image for the briar address of the person
This helps to transfer onion or i2p handles to a mobile device
"""
qrcode_filename = \
acct_dir(base_dir, nickname, domain) + '/qrcode_briar.png'
if is_a_file(qrcode_filename):
return False
actor_filename = \
acct_dir(base_dir, nickname, domain) + '.json'
if not is_a_file(actor_filename):
return False
actor_json = load_json(actor_filename)
if not actor_json:
return False
briar_address = get_briar_address(actor_json)
if not briar_address:
return False
url = pyqrcode.create(briar_address)
try:
url.png(qrcode_filename, scale)
return True
except ModuleNotFoundError:
print('EX: save_briar_qrcode pyqrcode png module not found')
return False
def set_briar_address(base_dir: str, nickname: str, domain: str,
actor_json: {}, briar_address: str,
qrcode_scale: int) -> None:
"""Sets an briar address for the given actor
"""
if not briar_address:
qrcode_filename = \
acct_dir(base_dir, nickname, domain) + '/qrcode_briar.png'
if is_a_file(qrcode_filename):
erase_file(qrcode_filename,
'EX: cannot remove briar qrcode ' + qrcode_filename)
not_briar_address: bool = False
if len(briar_address) < 50:
@ -147,3 +190,4 @@ def set_briar_address(actor_json: {}, briar_address: str) -> None:
"value": briar_address
}
actor_json['attachment'].append(new_briar_address)
save_briar_qrcode(base_dir, nickname, domain, qrcode_scale)

View File

@ -2716,7 +2716,8 @@ def daemon_http_get(self) -> None:
if is_image_file(self.path) and \
(string_starts_with(self.path,
('/login.', '/qrcode.png', '/qrcode_lxmf.png',
'/qrcode_ricochet.png', '/qrcode_enigma.png'))):
'/qrcode_ricochet.png', '/qrcode_enigma.png',
'/qrcode_briar.png'))):
icon_filename = data_dir(self.server.base_dir) + self.path
if is_a_file(icon_filename):
if etag_exists(self, icon_filename):
@ -2757,6 +2758,7 @@ def daemon_http_get(self) -> None:
(self.path.endswith('/qrcode.png') or
self.path.endswith('/qrcode_lxmf.png') or
self.path.endswith('/qrcode_ricochet.png') or
self.path.endswith('/qrcode_briar.png') or
self.path.endswith('/qrcode_enigma.png'))):
if show_qrcode(self, calling_domain, self.path,
self.server.base_dir,

View File

@ -31,6 +31,7 @@ from src.person import save_person_qrcode
from src.lxmf import save_lxmf_qrcode
from src.ricochet import save_ricochet_qrcode
from src.enigma import save_enigma_qrcode
from src.briar import save_briar_qrcode
from src.data import load_string
from src.data import load_binary
from src.data import is_a_file
@ -488,6 +489,11 @@ def show_qrcode(self, calling_domain: str, path: str,
acct_dir(base_dir, nickname, domain) + '/qrcode_enigma.png'
qrcode_scale = 6
save_enigma_qrcode(base_dir, nickname, domain, qrcode_scale)
elif path.endswith('_briar.png'):
qr_filename = \
acct_dir(base_dir, nickname, domain) + '/qrcode_briar.png'
qrcode_scale = 6
save_briar_qrcode(base_dir, nickname, domain, qrcode_scale)
else:
if onion_domain:
qrcode_domain = onion_domain

View File

@ -1770,19 +1770,22 @@ def _profile_post_cwtch_address(fields: {}, actor_json: {},
return actor_changed
def _profile_post_briar_address(fields: {}, actor_json: {},
def _profile_post_briar_address(base_dir: str, nickname: str, domain: str,
fields: {}, actor_json: {},
actor_changed: bool) -> bool:
""" HTTP POST change briar address
"""
qrcode_scale = 6
current_briar_address = get_briar_address(actor_json)
if fields.get('briarAddress'):
if fields['briarAddress'] != current_briar_address:
set_briar_address(actor_json,
fields['briarAddress'])
set_briar_address(base_dir, nickname, domain, actor_json,
fields['briarAddress'], qrcode_scale)
actor_changed = True
else:
if current_briar_address:
set_briar_address(actor_json, '')
set_briar_address(base_dir, nickname, domain,
actor_json, '', qrcode_scale)
actor_changed = True
return actor_changed
@ -3101,7 +3104,8 @@ def profile_edit(self, calling_domain: str, cookie: str,
actor_changed)
actor_changed = \
_profile_post_briar_address(fields, actor_json,
_profile_post_briar_address(base_dir, nickname, domain,
fields, actor_json,
actor_changed)
actor_changed = \

View File

@ -515,11 +515,17 @@ def html_person_options(default_timeline: str,
if briar_address.startswith('briar://'):
options_str += \
' <p class="imText">' + \
remove_html(briar_address) + '</p>\n'
remove_html(briar_address)
else:
options_str += \
' <p class="imText">briar://' + \
remove_html(briar_address) + '</p>\n'
remove_html(briar_address)
options_str += \
' <a href="/users/' + nickname + \
'/qrcode_briar.png" alt="' + translate['QR Code'] + '" title="' + \
translate['QR Code'] + '" tabindex="1">' + \
'<img class="qrcode" alt="' + translate['QR Code'] + \
'" src="/icons/qrcode.png" /></a></p>\n'
if ricochet_address:
if ricochet_address.startswith('ricochet:'):
options_str += \

View File

@ -1502,11 +1502,18 @@ def html_profile(signing_priv_key_pem: str,
if briar_address.startswith('briar://'):
donate_section += \
'<p><label class="toxaddr">' + \
briar_address + '</label></p>\n'
briar_address + '</label>'
else:
donate_section += \
'<p>briar://<label class="toxaddr">' + \
briar_address + '</label></p>\n'
briar_address + '</label>'
donate_section += \
' <a href="/users/' + nickname + \
'/qrcode_briar.png" alt="' + translate['QR Code'] + \
'" title="' + \
translate['QR Code'] + '" tabindex="1">' + \
'<img class="qrcode" alt="' + translate['QR Code'] + \
'" src="/icons/qrcode.png" /></a></p>\n'
if ricochet_address:
if ricochet_address.startswith('ricochet:'):
donate_section += \