mirror of
https://github.com/markqvist/NomadNet.git
synced 2026-12-04 13:50:01 -05:00
Improved string sanitization, added dynamic timeout calculations, improved state persistence, fixed .allowed not being respected for downloadable files, by Zenith
This commit is contained in:
parent
3eb410afdd
commit
54491d8f2b
14 changed files with 139 additions and 99 deletions
|
|
@ -279,6 +279,7 @@ class TextUI:
|
|||
self.set_colormode(colormode)
|
||||
|
||||
self.main_display.start()
|
||||
if intro_timeout <= 0 and self.app.peer_settings_notice: self.main_display.show_notice(self.app.peer_settings_notice)
|
||||
self.loop.run()
|
||||
|
||||
def set_colormode(self, colormode):
|
||||
|
|
@ -297,3 +298,4 @@ class TextUI:
|
|||
|
||||
def display_main(self, loop, user_data):
|
||||
self.loop.widget = self.main_display.widget
|
||||
if self.app.peer_settings_notice: self.main_display.show_notice(self.app.peer_settings_notice)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import threading
|
|||
from threading import Lock
|
||||
from .MicronParser import markup_to_attrmaps, make_style, default_state
|
||||
from nomadnet.Directory import DirectoryEntry
|
||||
from nomadnet.Conversation import ConversationMessage
|
||||
from nomadnet.vendor.Scrollable import *
|
||||
from nomadnet.util import strip_modifiers
|
||||
from nomadnet.util import sanitize_name
|
||||
|
|
@ -825,10 +826,9 @@ class Browser:
|
|||
partial["pr_throttle"] = time.time()+15
|
||||
RNS.log(f"Requesting path for partial: {partial_destination_hash} / {path}", RNS.LOG_EXTREME)
|
||||
RNS.Transport.request_path(partial_destination_hash)
|
||||
pr_time = time.time()+RNS.Transport.first_hop_timeout(partial_destination_hash)
|
||||
pr_time = time.time()+self.path_timeout(partial_destination_hash)
|
||||
while not RNS.Transport.has_path(partial_destination_hash):
|
||||
now = time.time()
|
||||
if now > pr_time+self.timeout: return
|
||||
if time.time() > pr_time: return
|
||||
time.sleep(0.25)
|
||||
|
||||
for pid in self.page_partials:
|
||||
|
|
@ -853,7 +853,7 @@ class Browser:
|
|||
partial["link"] = None
|
||||
|
||||
partial["link"] = RNS.Link(destination, established_callback = established, closed_callback = closed)
|
||||
timeout = time.time()+self.timeout
|
||||
timeout = time.time()+max(self.timeout, partial["link"].establishment_timeout)
|
||||
while partial["link"].status != RNS.Link.ACTIVE and time.time() < timeout: time.sleep(0.1)
|
||||
|
||||
if partial["link"] and partial["link"].status == RNS.Link.ACTIVE and partial["request_id"] == None:
|
||||
|
|
@ -1065,6 +1065,9 @@ class Browser:
|
|||
def set_timeout(self, timeout):
|
||||
self.timeout = timeout
|
||||
|
||||
def path_timeout(self, destination_hash):
|
||||
return max(self.timeout + self.app.rns.get_first_hop_timeout(destination_hash), self.app.rns.get_medium_path_timeout())
|
||||
|
||||
def download_local_file(self, path):
|
||||
try:
|
||||
file_path = self.app.filespath+path.replace("/file", "", 1)
|
||||
|
|
@ -1110,10 +1113,9 @@ class Browser:
|
|||
self.status = Browser.PATH_REQUESTED
|
||||
self.update_display()
|
||||
|
||||
pr_time = time.time()+RNS.Transport.first_hop_timeout(self.destination_hash)
|
||||
pr_time = time.time()+self.path_timeout(self.destination_hash)
|
||||
while not RNS.Transport.has_path(self.destination_hash):
|
||||
now = time.time()
|
||||
if now > pr_time+self.timeout:
|
||||
if time.time() > pr_time:
|
||||
self.request_timeout()
|
||||
return
|
||||
|
||||
|
|
@ -1493,10 +1495,9 @@ class Browser:
|
|||
self.status = Browser.PATH_REQUESTED
|
||||
self.update_display()
|
||||
|
||||
pr_time = time.time()+RNS.Transport.first_hop_timeout(self.destination_hash)
|
||||
pr_time = time.time()+self.path_timeout(self.destination_hash)
|
||||
while not RNS.Transport.has_path(self.destination_hash):
|
||||
now = time.time()
|
||||
if now > pr_time+self.timeout:
|
||||
if time.time() > pr_time:
|
||||
self.request_timeout()
|
||||
return
|
||||
|
||||
|
|
@ -1738,9 +1739,13 @@ class Browser:
|
|||
|
||||
def file_received(self, request_receipt):
|
||||
try:
|
||||
if type(request_receipt.response) == io.BufferedReader:
|
||||
if isinstance(request_receipt.response, bytes):
|
||||
markup = request_receipt.response.decode("utf-8")
|
||||
self.attr_maps = markup_to_attrmaps(strip_modifiers(markup), url_delegate=self, fg_color=self.page_foreground_color, bg_color=self.page_background_color)
|
||||
|
||||
elif type(request_receipt.response) == io.BufferedReader:
|
||||
if request_receipt.metadata != None:
|
||||
file_name = os.path.basename(request_receipt.metadata["name"].decode("utf-8"))
|
||||
file_name = ConversationMessage.safe_attachment_name(request_receipt.metadata["name"])
|
||||
file_handle = request_receipt.response
|
||||
file_destination = self.app.downloads_path+"/"+file_name
|
||||
|
||||
|
|
@ -1759,7 +1764,7 @@ class Browser:
|
|||
else:
|
||||
file_name = request_receipt.response[0]
|
||||
file_data = request_receipt.response[1]
|
||||
file_destination_name = os.path.basename(file_name)
|
||||
file_destination_name = ConversationMessage.safe_attachment_name(file_name)
|
||||
file_destination = self.app.downloads_path+"/"+file_destination_name
|
||||
|
||||
counter = 0
|
||||
|
|
|
|||
|
|
@ -2809,7 +2809,7 @@ class LXMessageWidget(urwid.WidgetWrap):
|
|||
title_string = g["warning"]+" "+g["arrow_l"]+" "+message.get_signature_description() + "\n " + title_string
|
||||
|
||||
if message.get_title() != "":
|
||||
title_string += " | " + message.get_title()
|
||||
title_string += " | " + strip_modifiers(message.get_title())
|
||||
|
||||
inbound_untrusted = False
|
||||
if not is_outbound and msg_source_hash is not None:
|
||||
|
|
|
|||
|
|
@ -953,18 +953,18 @@ class PageEditorDisplay():
|
|||
common, restricted, total = self._folder_permissions(path)
|
||||
content = common or ""
|
||||
if not total:
|
||||
state = "This folder contains no pages."
|
||||
state = "This folder contains no files."
|
||||
elif not restricted:
|
||||
state = "All %d pages here are public." % total
|
||||
state = "All %d files here are public." % total
|
||||
elif common is not None:
|
||||
state = "All %d pages here share these entries." % total
|
||||
state = "All %d files here share these entries." % total
|
||||
else:
|
||||
state = "Entries differ across pages (%d of %d restricted)." % (restricted, total)
|
||||
state = "Entries differ across files (%d of %d restricted)." % (restricted, total)
|
||||
note = ("Allowed identity hashes per line.\n"
|
||||
+ state + "\nSaving applies these entries to every page in this folder and its subfolders.")
|
||||
+ state + "\nSaving applies these entries to every file in this folder and its subfolders.")
|
||||
else:
|
||||
content = self._read_allowed(path)
|
||||
note = "Allowed identity hashes per line. Empty = public.\nApplies to this page."
|
||||
note = "Allowed identity hashes per line. Empty = public.\nApplies to this page or file."
|
||||
|
||||
title = "Permissions: " + os.path.basename(path) + ("/" if is_dir else "")
|
||||
self.show_dialog(PermissionsDialog(title, note, content,
|
||||
|
|
|
|||
|
|
@ -498,9 +498,9 @@ By default, you can find the examples in `!~/.nomadnetwork/examples`!. If you bu
|
|||
|
||||
>>Authenticating Users
|
||||
|
||||
Sometimes, you don't want everyone to be able to view certain pages or execute certain scripts. In such cases, you can use `*authentication`* to control who gets to run certain requests.
|
||||
Sometimes, you don't want everyone to be able to view certain pages, download certain files or execute certain scripts. In such cases, you can use `*authentication`* to control who gets to run certain requests.
|
||||
|
||||
To enable authentication for any page, simply add a new file to your pages directory with ".allowed" added to the file-name of the page. If your page is named "secret_page.mu", just add a file named "secret_page.mu.allowed".
|
||||
To enable authentication for any page or file, simply add a new file next to it with ".allowed" added to its file-name. If your page is named "secret_page.mu", just add a file named "secret_page.mu.allowed". The same works for files in your files directory, and the ".allowed" file itself is never served.
|
||||
|
||||
For each user allowed to access the page, add a line to this file, containing the hash of that users primary identity. Users can find their own identity hash in the `![ Network ]`! part of the program, under `!Local Peer Info`!. If you want to allow access for three different users, your file would look like this:
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import itertools
|
|||
import mmap
|
||||
import urwid
|
||||
import nomadnet
|
||||
from nomadnet.util import strip_modifiers
|
||||
|
||||
|
||||
class LogDisplayShortcuts():
|
||||
|
|
@ -68,7 +69,7 @@ class LogTerminal(urwid.WidgetWrap):
|
|||
class LogTail(urwid.WidgetWrap):
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.log_tail = urwid.Text(tail(self.app.logfilepath, 50))
|
||||
self.log_tail = urwid.Text(strip_modifiers(tail(self.app.logfilepath, 50)))
|
||||
self.log = urwid.Scrollable(self.log_tail)
|
||||
self.log.set_scrollpos(-1)
|
||||
self.log_scrollbar = urwid.ScrollBar(self.log)
|
||||
|
|
|
|||
|
|
@ -249,6 +249,12 @@ class MainDisplay():
|
|||
valign="middle", height=8, min_width=20,
|
||||
)
|
||||
|
||||
def show_notice(self, text):
|
||||
def close(button=None): self.app.ui.loop.widget = self.frame
|
||||
pile = urwid.Pile([urwid.Text(text, align="center"), urwid.Divider(), urwid.Button("OK", on_press=close)])
|
||||
dialog = QuitDialogLineBox(urwid.Filler(pile, urwid.TOP), title="Notice", on_cancel=close)
|
||||
self.app.ui.loop.widget = urwid.Overlay(dialog, self.frame, align="center", width=64, valign="middle", height=9, min_width=20)
|
||||
|
||||
def do_quit(self, sender=None):
|
||||
logterm_pid = None
|
||||
if True or RNS.vendor.platformutils.is_android():
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from urwid.util import is_mouse_press
|
|||
from urwid.text_layout import calc_coords
|
||||
from .ReadlineEdit import ReadlineEdit
|
||||
from RNS.Utilities.rngit.util import MarkdownToMicron
|
||||
from nomadnet.util import STRIP_CONTROL_RE
|
||||
|
||||
DEFAULT_FG_DARK = "ddd"
|
||||
DEFAULT_FG_LIGHT = "222"
|
||||
|
|
@ -101,6 +102,7 @@ def ensure_selected_styles():
|
|||
else: SELECTED_STYLES = STYLES_LIGHT
|
||||
|
||||
def markup_to_attrmaps(markup, url_delegate = None, fg_color=None, bg_color=None, link_class=None, anchors=None):
|
||||
markup = STRIP_CONTROL_RE.sub("", markup)
|
||||
global LINK_CLASS
|
||||
if link_class: LINK_CLASS = link_class
|
||||
else: LINK_CLASS = LinkableText
|
||||
|
|
|
|||
|
|
@ -419,7 +419,7 @@ class ProbeView:
|
|||
|
||||
def _timeout(self):
|
||||
try:
|
||||
return DEFAULT_PROBE_TIMEOUT + self.app.rns.get_first_hop_timeout(self._dest_hash)
|
||||
return max(DEFAULT_PROBE_TIMEOUT + self.app.rns.get_first_hop_timeout(self._dest_hash), self.app.rns.get_medium_path_timeout())
|
||||
except Exception:
|
||||
return DEFAULT_PROBE_TIMEOUT
|
||||
|
||||
|
|
@ -639,7 +639,7 @@ class PathView:
|
|||
|
||||
def _timeout(self):
|
||||
try:
|
||||
return DEFAULT_PROBE_TIMEOUT + self.app.rns.get_first_hop_timeout(self._dest_hash)
|
||||
return max(DEFAULT_PROBE_TIMEOUT + self.app.rns.get_first_hop_timeout(self._dest_hash), self.app.rns.get_medium_path_timeout())
|
||||
except Exception:
|
||||
return DEFAULT_PROBE_TIMEOUT
|
||||
|
||||
|
|
@ -830,7 +830,7 @@ class IdentityView:
|
|||
self.lookup_button.original_widget.set_label("Looking up…")
|
||||
self._log("Identity unknown, requesting from the network …")
|
||||
try:
|
||||
self._deadline = time.time() + DEFAULT_PROBE_TIMEOUT + self.app.rns.get_first_hop_timeout(dest_hash)
|
||||
self._deadline = time.time() + max(DEFAULT_PROBE_TIMEOUT + self.app.rns.get_first_hop_timeout(dest_hash), self.app.rns.get_medium_path_timeout())
|
||||
except Exception:
|
||||
self._deadline = time.time() + DEFAULT_PROBE_TIMEOUT
|
||||
self.app.ui.loop.set_alarm_in(0.25, self._await_identity)
|
||||
|
|
@ -975,7 +975,7 @@ class SendFileView:
|
|||
|
||||
def _timeout(self):
|
||||
try:
|
||||
return DEFAULT_PROBE_TIMEOUT + self.app.rns.get_first_hop_timeout(self._dest_hash)
|
||||
return max(DEFAULT_PROBE_TIMEOUT + self.app.rns.get_first_hop_timeout(self._dest_hash), self.app.rns.get_medium_path_timeout())
|
||||
except Exception:
|
||||
return DEFAULT_PROBE_TIMEOUT
|
||||
|
||||
|
|
@ -1040,7 +1040,7 @@ class SendFileView:
|
|||
self._log("Could not establish link: %s" % str(e), "error_text")
|
||||
self._finish()
|
||||
return
|
||||
self._link_deadline = time.time() + self._timeout()
|
||||
self._link_deadline = time.time() + max(self._timeout(), self._link.establishment_timeout)
|
||||
self.app.ui.loop.set_alarm_in(0.5, self._check_link)
|
||||
|
||||
def _check_link(self, loop, user_data):
|
||||
|
|
@ -1402,7 +1402,7 @@ class SpeedTestView:
|
|||
return
|
||||
self._incoming_link = link
|
||||
link.set_remote_identified_callback(self._on_remote_identified)
|
||||
self.app.ui.loop.set_alarm_in(8, lambda l, u: self._incoming_timeout(link))
|
||||
self.app.ui.loop.set_alarm_in(max(8, self.app.rns.get_medium_path_timeout()), lambda l, u: self._incoming_timeout(link))
|
||||
|
||||
def _incoming_timeout(self, link):
|
||||
if self._recv_link is link:
|
||||
|
|
@ -1565,7 +1565,7 @@ class SpeedTestView:
|
|||
|
||||
def _timeout(self):
|
||||
try:
|
||||
return DEFAULT_PROBE_TIMEOUT + self.app.rns.get_first_hop_timeout(self._dest_hash)
|
||||
return max(DEFAULT_PROBE_TIMEOUT + self.app.rns.get_first_hop_timeout(self._dest_hash), self.app.rns.get_medium_path_timeout())
|
||||
except Exception:
|
||||
return DEFAULT_PROBE_TIMEOUT
|
||||
|
||||
|
|
@ -1594,7 +1594,7 @@ class SpeedTestView:
|
|||
self._log("Could not establish link: %s" % str(e), "error_text")
|
||||
self._finish()
|
||||
return
|
||||
self._link_deadline = time.time() + self._timeout()
|
||||
self._link_deadline = time.time() + max(self._timeout(), self._client_link.establishment_timeout)
|
||||
self.app.ui.loop.set_alarm_in(0.5, self._check_link)
|
||||
|
||||
def _check_link(self, loop, user_data):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue