def __init__(self, i, o, *args, **kwargs): super(ClockApp, self).__init__(i, o) self.menu_name = "Clock" self.refresher = Refresher(self.on_refresh, i, o) default_config = '{}' config_filename = "config.json" self.config = read_or_create_config(local_path(config_filename), default_config, self.menu_name+" app")
def __init__(self, *args, **kwargs): ZeroApp.__init__(self, *args, **kwargs) # Initializing variables from config file self.config = read_or_create_config(local_path(self.config_filename), self.default_config, self.menu_name + " app") self.save_config = save_config_method_gen( self, local_path(self.config_filename)) self.current_chip = self.config["default_part"] self.current_programmer = self.config["default_programmer"] self.filter_programmers = self.config["filter_programmers"] self.bitclock = self.config["last_bitclock"] self.read_filename = self.config["last_read_filename"] self.read_dir = self.config["last_read_dir"] self.write_file = self.config["last_write_file"] self.write_fuse_params = self.config["last_write_fuse_params"] self.bootloader_config_filename = self.config[ "bootloader_config_filename"] # Creating UI elements to be used in run_and_monitor_process() # they're reusable anyway, and we don't have to init them each time # that we enter run_and_monitor_process() . self.erase_restore_indicator = LoadingIndicator(self.i, self.o, message="Erasing") self.read_write_bar = ProgressBar(self.i, self.o)
def __init__(self, check_revisions=True): GenericUpdater.__init__(self) self.check_revisions = check_revisions self.config = read_or_create_config(local_path(self.config_filename), self.default_config, "Git updater") self.save_config = save_config_method_gen( self, local_path(self.config_filename))
def __init__(self, i, o): self.i = i self.o = o self.config = read_or_create_config(local_path("config.json"), '{"lockscreen_type":"KeyScreen"}', "Lockscreen app config") self.save_config = save_config_method_gen(self, local_path("ls_config.json")) self.current_screen = None # Need to continue writing this
def __init__(self, i, o, *args, **kwargs): super(ClockApp, self).__init__(i, o) self.menu_name = "Clock" self.countdown = None self.refresher = Refresher( self.on_refresh, i, o, keymap={"KEY_RIGHT": self.countdown_settings}) default_config = '{}' config_filename = "config.json" self.config = read_or_create_config(local_path(config_filename), default_config, self.menu_name + " app")
def __init__(self, *args, **kwargs): ZeroApp.__init__(self, *args, **kwargs) # Read config and create a function for saving it self.config = read_or_create_config(local_path(self.config_filename), self.default_config, self.menu_name + " app") self.save_config = save_config_method_gen( self, local_path(self.config_filename)) self.server = self.config.get("server", "matrix.org") self.login_runner = BackgroundRunner(self.background_login) self.login_runner.run() self.init_vars()
query about whether there's a fix concerning a bugreport sent by particular UUID, \ and then notify the owner about it (opt-in, of course).""" bugreport_optin_text = """ZPUI has built-in bugreport facilities to ensure error-free operation. \ These allow to automatically send somewhat-anonymized logs to ZeroPhone servers \ whenever some kind of exception happens in ZPUI (either core or apps), \ so that the bug that caused the exception can be fixed. Your logs, once submitted, will be handled with care, processed quickly \ and fully deleted as soon as possible. You can read more (and change your choice) \ in the Settings=>Bugreport menu.""" default_config = '{"uuid":"", "last_choices":"", "autosend":false}' config_filename = "bugreport_config.json" local_path = local_path_gen(__name__) config = read_or_create_config(local_path(config_filename), default_config, "Bugreport app") save_config = save_config_gen(local_path(config_filename)) logger = setup_logger(__name__, "info") log_options = [ ["ZPUI logs", "zpui_logs"], ["ZPUI info (config, git info)", "zpui_info"], ["ZPUI threads", "zpui_threads"], ["ZPUI screenshots", "zpui_screenshots"], #["ZPUI contexts", "zpui_contexts"], ["dmesg output", "dmesg"], ["/var/log/ contents", "var_log"], ["Processes", "ps"], ["Custom files", "custom"] ]
from traceback import format_exc from time import sleep import socket import sys import os #Some globals for us i = None o = None config_filename = "config.json" default_config = '{"timeout":1,"dst":"239.255.255.250","st":"upnp:rootdevice"}' local_path = local_path_gen(__name__) config_path = local_path(config_filename) config = read_or_create_config(config_path, default_config, menu_name + " app") def run_scan(): Printer("Scanning:", i, o, 0) msg = [ 'M-SEARCH * HTTP/1.1', 'Host:{}:1900'.format(config["dst"]), 'ST:{}'.format(config["st"]), 'Man:"ssdp:discover"', 'MX:1', '' ] s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) s.settimeout(config["timeout"]) s.sendto('\r\n'.join(msg), (config["dst"], 1900)) found_devices = OrderedDict() while True: try:
default_config = \ """ { "ip_source":\""""+default_ip_source+"""\", "connectivity_sources": [ "https://example.org/", "https://zerophone.org/" ] } """ logger = setup_logger(__name__, "info") local_path = local_path_gen(__name__) config = read_or_create_config(local_path("config.json"), default_config, "Internet tools app") class InternetTools(ZeroApp): menu_name = "Internet tools" def set_context(self, c): self.context = c self.context.register_firstboot_action( FBA("check_connectivity", self.firstboot)) def firstboot(self): return self.check_connectivity_ui() def check_connectivity_ui(self):
menu_name = "2FA TOTP" import pyotp from ui import Menu, PrettyPrinter as Printer, UniversalInput, Canvas, Refresher, DialogBox from helpers import read_or_create_config, local_path_gen, save_config_gen local_path = local_path_gen(__name__) config_path = local_path("config.json") config = read_or_create_config(config_path, '{"secrets":[]}', menu_name) save_config = save_config_gen(config_path) i = None o = None def init_app(input, output): global i, o i = input o = output # Showing TOTP entries def show_totp(name, secret): display_func = lambda: render_totp(name, secret) r = Refresher(display_func, i, o, 1) delete_func = lambda: delete_config_entry(name, secret, r) r.set_keymap({"KEY_RIGHT": delete_func}) r.activate()
import os from actions import Action, ContextSwitchAction, FirstBootAction from ui import Menu, PrettyPrinter, Checkbox, Listbox from helpers import read_or_create_config, local_path_gen, save_config_gen, setup_logger i = None o = None context = None zeromenu = None default_config = '{"ordering":[], "excluded_actions":[], "app_open_entries":[]}' config_filename = "config.json" local_path = local_path_gen(__name__) config = read_or_create_config(local_path(config_filename), default_config, menu_name + " app") save_config = save_config_gen(local_path(config_filename)) logger = setup_logger(__name__, "warning") def set_context(received_context): global context context = received_context context.request_global_keymap({"KEY_PROG2": context.request_switch}) context.threaded = True context.set_target(zeromenu.activate) def set_ordering(): pass
except: logging.exception('Failed to load config from {}'.format(config_path)) config_path = None else: logging.info('Successfully loaded config from {}'.format(config_path)) break # After this loop, the config_path global should contain # path for config that successfully loaded return config, config_path default_log_config = """{"dir":"logs/", "filename":"zpui.log", "format": ["[%(levelname)s] %(asctime)s %(name)s: %(message)s","%Y-%m-%d %H:%M:%S"], "file_size":1048576, "files_to_store":5} """ log_config = read_or_create_config("log_config.json", default_log_config, "ZPUI logging") logging_dir = log_config["dir"] log_filename = log_config["filename"] # Making sure the log dir exists - create it if it's not try: os.makedirs(logging_dir) except OSError: pass #Set all the logging parameter variables logging_path = os.path.join(logging_dir, log_filename) logging_format = log_config["format"] logfile_size = log_config["file_size"] files_to_store = log_config["files_to_store"]
def callback(): global config config = read_or_create_config(config_path, default_config, menu_name) Menu([], i, o, "TOTP app main menu", contents_hook=contents_hook).activate()