Forking what is left of ZeroNet and hopefully adding an AT Proto Frontend/Proxy
at main 72 lines 2.7 kB view raw
1import io 2import os 3 4from Plugin import PluginManager 5from Config import config 6from Translate import Translate 7from util.Flag import flag 8 9 10plugin_dir = os.path.dirname(__file__) 11 12if "_" not in locals(): 13 _ = Translate(plugin_dir + "/languages/") 14 15 16@PluginManager.registerTo("UiRequest") 17class UiRequestPlugin(object): 18 def actionWrapper(self, path, extra_headers=None): 19 if path.strip("/") != "Config": 20 return super(UiRequestPlugin, self).actionWrapper(path, extra_headers) 21 22 if not extra_headers: 23 extra_headers = {} 24 25 script_nonce = self.getScriptNonce() 26 27 self.sendHeader(extra_headers=extra_headers, script_nonce=script_nonce) 28 site = self.server.site_manager.get(config.homepage) 29 return iter([super(UiRequestPlugin, self).renderWrapper( 30 site, path, "uimedia/plugins/uiconfig/config.html", 31 "Config", extra_headers, show_loadingscreen=False, script_nonce=script_nonce 32 )]) 33 34 def actionUiMedia(self, path, *args, **kwargs): 35 if path.startswith("/uimedia/plugins/uiconfig/"): 36 file_path = path.replace("/uimedia/plugins/uiconfig/", plugin_dir + "/media/") 37 if config.debug and (file_path.endswith("all.js") or file_path.endswith("all.css")): 38 # If debugging merge *.css to all.css and *.js to all.js 39 from Debug import DebugMedia 40 DebugMedia.merge(file_path) 41 42 if file_path.endswith("js"): 43 data = _.translateData(open(file_path).read(), mode="js").encode("utf8") 44 elif file_path.endswith("html"): 45 data = _.translateData(open(file_path).read(), mode="html").encode("utf8") 46 else: 47 data = open(file_path, "rb").read() 48 49 return self.actionFile(file_path, file_obj=io.BytesIO(data), file_size=len(data)) 50 else: 51 return super(UiRequestPlugin, self).actionUiMedia(path) 52 53 54@PluginManager.registerTo("UiWebsocket") 55class UiWebsocketPlugin(object): 56 @flag.admin 57 def actionConfigList(self, to): 58 back = {} 59 config_values = vars(config.arguments) 60 config_values.update(config.pending_changes) 61 for key, val in config_values.items(): 62 if key not in config.keys_api_change_allowed: 63 continue 64 is_pending = key in config.pending_changes 65 if val is None and is_pending: 66 val = config.parser.get_default(key) 67 back[key] = { 68 "value": val, 69 "default": config.parser.get_default(key), 70 "pending": is_pending 71 } 72 return back