Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1,996 changes: 1,078 additions & 918 deletions addon/globalPlugins/remoteClient/__init__.py

Large diffs are not rendered by default.

122 changes: 64 additions & 58 deletions addon/globalPlugins/remoteClient/configuration.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,64 @@
from io import StringIO
import os
import configobj
from configobj import validate
import globalVars
from . import socket_utils
readonly = globalVars.appArgs.secure or globalVars.appArgs.launcher

CONFIG_FILE_NAME = 'teleNVDA.ini'

_config = None
configspec = StringIO("""
[connections]
last_connected = list(default=list("remote.nvda.es"))
[controlserver]
autoconnect = boolean(default=False)
self_hosted = boolean(default=False)
UPNP = boolean(default=False)
connection_type = integer(default=0)
host = string(default="remote.nvda.es")
port = integer(default=6837)
key = string(default="")
encryption_key = string(default="")

[seen_motds]
__many__ = string(default="")

[trusted_certs]
__many__ = string(default="")

[ui]
play_sounds = boolean(default=True)
alert_before_slave_disconnect = boolean(default=True)
mute_when_controlling_local_machine = boolean(default=False)
allow_speech_commands = boolean(default=True)
display_motd_once = boolean(default=False)
portcheck = string(default="https://nvda.es/portcheck.php?port={port}")
""")
def get_config():
global _config
if not _config:
path = os.path.abspath(os.path.join(globalVars.appArgs.configPath, CONFIG_FILE_NAME))
_config = configobj.ConfigObj(infile=path, configspec=configspec, default_encoding='utf8', create_empty=not readonly)
val = validate.Validator()
_config.validate(val, copy=True)
return _config

def write_connection_to_config(address):
"""Writes an address to the last connected section of the config.
If the address is already in the config, move it to the end."""
conf = get_config()
last_cons = conf['connections']['last_connected']
address = socket_utils.hostport_to_address(address)
if address in last_cons:
conf['connections']['last_connected'].remove(address)
conf['connections']['last_connected'].append(address)
if not readonly:
conf.write()
from io import StringIO
import os
import configobj
from configobj import validate
import globalVars
from . import socket_utils

readonly = globalVars.appArgs.secure or globalVars.appArgs.launcher

CONFIG_FILE_NAME = "teleNVDA.ini"

_config = None
configspec = StringIO("""
[connections]
last_connected = list(default=list("remote.nvda.es"))
[controlserver]
autoconnect = boolean(default=False)
self_hosted = boolean(default=False)
UPNP = boolean(default=False)
connection_type = integer(default=0)
host = string(default="remote.nvda.es")
port = integer(default=6837)
key = string(default="")
encryption_key = string(default="")

[seen_motds]
__many__ = string(default="")

[trusted_certs]
__many__ = string(default="")

[ui]
play_sounds = boolean(default=True)
alert_before_slave_disconnect = boolean(default=True)
mute_when_controlling_local_machine = boolean(default=False)
allow_speech_commands = boolean(default=True)
display_motd_once = boolean(default=False)
portcheck = string(default="https://nvda.es/portcheck.php?port={port}")
""")


def get_config():
global _config
if not _config:
path = os.path.abspath(os.path.join(globalVars.appArgs.configPath, CONFIG_FILE_NAME))
_config = configobj.ConfigObj(
infile=path, configspec=configspec, default_encoding="utf8", create_empty=not readonly
)
val = validate.Validator()
_config.validate(val, copy=True)
return _config


def write_connection_to_config(address):
"""Writes an address to the last connected section of the config.
If the address is already in the config, move it to the end."""
conf = get_config()
last_cons = conf["connections"]["last_connected"]
address = socket_utils.hostport_to_address(address)
if address in last_cons:
conf["connections"]["last_connected"].remove(address)
conf["connections"]["last_connected"].append(address)
if not readonly:
conf.write()
23 changes: 15 additions & 8 deletions addon/globalPlugins/remoteClient/connection_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def from_url(cls, url):
parsed_query = parse_qs(parsed_url.query)
hostname = parsed_url.hostname
port = parsed_url.port
key = parsed_query.get('key', [""])[0]
encryption_key = parsed_query.get('encryption_key', [""])[0]
mode = parsed_query.get('mode', [""])[0].lower()
key = parsed_query.get("key", [""])[0]
encryption_key = parsed_query.get("encryption_key", [""])[0]
mode = parsed_query.get("mode", [""])[0].lower()
if not hostname:
raise URLParsingError("No hostname provided")
if not key:
Expand All @@ -43,7 +43,14 @@ def from_url(cls, url):
return cls(hostname=hostname, mode=mode, key=key, port=port)

def __repr__(self):
return "{classname} (hostname={hostname}, port={port}, mode={mode}, key={key}, encryption_key={encryption_key})".format(classname=self.__class__.__name__, hostname=self.hostname, port=self.port, mode=self.mode, key=self.key, encryption_key=self.encryption_key)
return "{classname} (hostname={hostname}, port={port}, mode={mode}, key={key}, encryption_key={encryption_key})".format(
classname=self.__class__.__name__,
hostname=self.hostname,
port=self.port,
mode=self.mode,
key=self.key,
encryption_key=self.encryption_key,
)

def get_address(self):
hostname = self.hostname if ":" not in self.hostname else "[" + self.hostname + "]"
Expand All @@ -53,10 +60,10 @@ def get_url_to_connect(self, protocol):
result = URL_PREFIX[protocol] + socket_utils.hostport_to_address((self.hostname, self.port))
result += "?"
mode = self.mode
if mode == 'master':
mode = 'slave'
elif mode == 'slave':
mode = 'master'
if mode == "master":
mode = "slave"
elif mode == "slave":
mode = "master"
if self.encryption_key:
result += urlencode(dict(key=self.key, encryption_key=self.encryption_key, mode=mode))
else:
Expand Down
Loading