diff --git a/copyparty/authsrv.py b/copyparty/authsrv.py index ca26ea3d..5d869c02 100644 --- a/copyparty/authsrv.py +++ b/copyparty/authsrv.py @@ -14,6 +14,7 @@ from datetime import datetime from .__init__ import WINDOWS from .util import ( IMPLICATIONS, + META_NOBOTS, uncyg, undot, unhumanize, @@ -861,6 +862,19 @@ class AuthSrv(object): if use: vol.lim = lim + if self.args.no_robots: + for vol in vfs.all_vols.values(): + # volflag "robots" overrides global "norobots", allowing indexing by search engines for this vol + if not vol.flags.get("robots"): + vol.flags["norobots"] = True + + for vol in vfs.all_vols.values(): + h = [vol.flags.get("html_head", self.args.html_head)] + if vol.flags.get("norobots"): + h.insert(0, META_NOBOTS) + + vol.flags["html_head"] = "\n".join([x for x in h if x]) + for vol in vfs.all_vols.values(): fk = vol.flags.get("fk") if fk: diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 8083c05d..8edbf1d7 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -65,8 +65,11 @@ class HttpCli(object): "Access-Control-Allow-Origin": "*", "Cache-Control": "no-store; max-age=0", } + h = self.args.html_head if self.args.no_robots: + h = META_NOBOTS + (("\n" + h) if h else "") self.out_headers["X-Robots-Tag"] = "noindex, nofollow" + self.html_head = h def log(self, msg, c=0): ptn = self.asrv.re_pwd @@ -95,7 +98,7 @@ class HttpCli(object): if ka: ka["ts"] = self.conn.hsrv.cachebuster() ka["svcname"] = self.args.doctitle - ka["html_head"] = self.args.html_head + ka["html_head"] = self.html_head return tpl.render(**ka) return tpl @@ -1680,13 +1683,15 @@ class HttpCli(object): boundary = "\roll\tide" targs = { + "ts": self.conn.hsrv.cachebuster(), + "svcname": self.args.doctitle, + "html_head": self.html_head, "edit": "edit" in self.uparam, "title": html_escape(self.vpath, crlf=True), "lastmod": int(ts_md * 1000), "md_plug": "true" if self.args.emp else "false", "md_chk_rate": self.args.mcr, "md": boundary, - "ts": self.conn.hsrv.cachebuster(), "arg_base": arg_base, } html = template.render(**targs).encode("utf-8", "replace") @@ -2069,6 +2074,12 @@ class HttpCli(object): ): raise Pebkac(403) + self.html_head = vn.flags.get("html_head", "") + if vn.flags.get("norobots"): + self.out_headers["X-Robots-Tag"] = "noindex, nofollow" + else: + self.out_headers.pop("X-Robots-Tag", None) + is_dir = stat.S_ISDIR(st.st_mode) if self.can_read: th_fmt = self.uparam.get("th") diff --git a/copyparty/svchub.py b/copyparty/svchub.py index a57b84ec..7d189472 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -70,10 +70,6 @@ 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/util.py b/copyparty/util.py index c6c69f08..fb5f6723 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -71,6 +71,8 @@ SYMTIME = sys.version_info >= (3, 6) and os.supports_follow_symlinks HTTP_TS_FMT = "%a, %d %b %Y %H:%M:%S GMT" +META_NOBOTS = '' + HTTPCODE = { 200: "OK", 204: "No Content", diff --git a/copyparty/web/browser.html b/copyparty/web/browser.html index b39ad9be..e2246513 100644 --- a/copyparty/web/browser.html +++ b/copyparty/web/browser.html @@ -6,7 +6,7 @@