From a90586e6a8140b05585f0d9e535ef239b598c9d4 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 6 Nov 2021 19:05:58 +0100 Subject: [PATCH] add reload api --- copyparty/__main__.py | 1 + copyparty/httpcli.py | 17 +++++++++++++++++ copyparty/svchub.py | 7 +++++-- copyparty/web/browser.js | 2 +- copyparty/web/splash.css | 6 ++++-- copyparty/web/splash.html | 4 +++- 6 files changed, 31 insertions(+), 6 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 2d246c2e..c7ec8c4f 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -423,6 +423,7 @@ def run_argparse(argv, formatter): ap2.add_argument("--lf-url", metavar="RE", type=u, default=r"^/\.cpr/|\?th=[wj]$", help="dont log URLs matching") ap2 = ap.add_argument_group('admin panel options') + ap2.add_argument("--no-reload", action="store_true", help="disable ?reload=cfg (reload users/volumes/volflags from config file)") ap2.add_argument("--no-rescan", action="store_true", help="disable ?scan (volume reindexing)") ap2.add_argument("--no-stack", action="store_true", help="disable ?stack (list all stacks)") diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 80f4674e..0f56aac9 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -419,6 +419,9 @@ class HttpCli(object): return self.scanvol() if not self.vpath: + if "reload" in self.uparam: + return self.handle_reload() + if "stack" in self.uparam: return self.tx_stack() @@ -1724,6 +1727,20 @@ class HttpCli(object): raise Pebkac(500, x) + def handle_reload(self): + act = self.uparam.get("reload") + if act != "cfg": + raise Pebkac(400, "only config files ('cfg') can be reloaded rn") + + if not [x for x in self.wvol if x in self.rvol]: + raise Pebkac(403, "not allowed for user " + self.uname) + + if self.args.no_reload: + raise Pebkac(403, "the reload feature is disabled in server config") + + x = self.conn.hsrv.broker.put(True, "reload") + return self.redirect("", "?h", x.get(), "return to", False) + def tx_stack(self): if not [x for x in self.wvol if x in self.rvol]: raise Pebkac(403, "not allowed for user " + self.uname) diff --git a/copyparty/svchub.py b/copyparty/svchub.py index 2c5620a3..7e62aee3 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -226,10 +226,14 @@ class SvcHub(object): self.stop_thr() def reload(self): + if self.reloading: + return "cannot reload; already in progress" + self.reloading = True t = threading.Thread(target=self._reload) t.daemon = True t.start() + return "reload initiated" def _reload(self): self.log("root", "reload scheduled") @@ -247,8 +251,7 @@ class SvcHub(object): if self.reload_req: self.reload_req = False - if not self.reloading: - self.reload() + self.reload() self.shutdown() diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index bde35fd3..596de6b1 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -195,8 +195,8 @@ ebi('tree').innerHTML = ( ' \n' + ' 🎯\n' + ' 📃\n' + - ' a\n' + ' 📌\n' + + ' a\n' + ' ↵\n' + ' 👀\n' + '\n' + diff --git a/copyparty/web/splash.css b/copyparty/web/splash.css index 4c6fd5ea..a0fed50f 100644 --- a/copyparty/web/splash.css +++ b/copyparty/web/splash.css @@ -29,15 +29,17 @@ a { border-radius: .2em; padding: .2em .8em; } +a+a { + margin-left: .5em; +} .refresh, .logout { float: right; - margin-top: -.2em; + margin: -.2em 0 0 .5em; } .logout { color: #c04; border-color: #c7a; - margin-right: .5em; } #repl { border: none; diff --git a/copyparty/web/splash.html b/copyparty/web/splash.html index e35bc94c..076ddbe7 100644 --- a/copyparty/web/splash.html +++ b/copyparty/web/splash.html @@ -49,7 +49,8 @@
- dump stack + dump stack + reload cfg
{%- endif %} @@ -88,5 +89,6 @@ if (localStorage.lightmode != 1) +