diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 176e5bfe..ac49dd9c 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -472,6 +472,7 @@ def run_argparse(argv, formatter): ap2.add_argument("--no-readme", action="store_true", help="disable rendering readme.md into directory listings") ap2.add_argument("--vague-403", action="store_true", help="send 404 instead of 403 (security through ambiguity, very enterprise)") ap2.add_argument("--force-js", action="store_true", help="don't send HTML folder listings, force clients to use the embedded json instead") + ap2.add_argument("--no-robots", action="store_true", help="adds http and html headers asking search engines to not index anything") ap2 = ap.add_argument_group('yolo options') ap2.add_argument("--ign-ebind", action="store_true", help="continue running even if it's impossible to listen on some of the requested endpoints") @@ -540,6 +541,7 @@ def run_argparse(argv, formatter): ap2 = ap.add_argument_group('ui options') ap2.add_argument("--js-browser", metavar="L", type=u, help="URL to additional JS to include") ap2.add_argument("--css-browser", metavar="L", type=u, help="URL to additional CSS to include") + ap2.add_argument("--html-head", metavar="TXT", type=u, default="", help="text to append to the of all HTML pages") ap2.add_argument("--textfiles", metavar="CSV", type=u, default="txt,nfo,diz,cue,readme", help="file extensions to present as plaintext") ap2.add_argument("--doctitle", metavar="TXT", type=u, default="copyparty", help="title / service-name to show in html documents") diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index b19de920..8083c05d 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -65,6 +65,8 @@ class HttpCli(object): "Access-Control-Allow-Origin": "*", "Cache-Control": "no-store; max-age=0", } + if self.args.no_robots: + self.out_headers["X-Robots-Tag"] = "noindex, nofollow" def log(self, msg, c=0): ptn = self.asrv.re_pwd @@ -93,6 +95,7 @@ class HttpCli(object): if ka: ka["ts"] = self.conn.hsrv.cachebuster() ka["svcname"] = self.args.doctitle + ka["html_head"] = self.args.html_head return tpl.render(**ka) return tpl diff --git a/copyparty/svchub.py b/copyparty/svchub.py index 7d189472..a57b84ec 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -70,6 +70,10 @@ class SvcHub(object): self.log("root", m, c=3) + if args.no_robots: + h = ['', args.html_head] + args.html_head = "\n\t".join([x for x in h if x]) + # initiate all services to manage self.asrv = AuthSrv(self.args, self.log) if args.ls: diff --git a/copyparty/web/browser.html b/copyparty/web/browser.html index 1e123fe0..b39ad9be 100644 --- a/copyparty/web/browser.html +++ b/copyparty/web/browser.html @@ -6,6 +6,7 @@ ⇆🎉 {{ title }} + {{ html_head }} {%- if css %} diff --git a/copyparty/web/browser2.html b/copyparty/web/browser2.html index 9babebf6..0e64e86c 100644 --- a/copyparty/web/browser2.html +++ b/copyparty/web/browser2.html @@ -6,6 +6,7 @@ {{ title }} + {{ html_head }}