From b624a387472be5fedf01f2ccac2f9134452d5758 Mon Sep 17 00:00:00 2001
From: ed
Date: Wed, 22 Oct 2025 22:10:02 +0000
Subject: [PATCH] ENTERPRISE file extensions (#941 omake);
in case a snakeoil salesman managed to convince your workplace into
purchasing their "internet security solution" which blocks downloads
of certain files according to file extensions -- or, in other words,
smoke and mirrors, with a comforting false sense of security
---
copyparty/__init__.py | 7 +++-
copyparty/httpcli.py | 34 +++++++++++++++----
copyparty/web/Makefile | 5 +--
.../web/a/{webdav-cfg.bat => webdav-cfg.txt} | 0
copyparty/web/svcs.html | 2 +-
pyproject.toml | 3 +-
scripts/make-sfx.sh | 2 +-
scripts/sfx.ls | 2 +-
8 files changed, 41 insertions(+), 14 deletions(-)
rename copyparty/web/a/{webdav-cfg.bat => webdav-cfg.txt} (100%)
diff --git a/copyparty/__init__.py b/copyparty/__init__.py
index 44ddd3c9..6baaaf5f 100644
--- a/copyparty/__init__.py
+++ b/copyparty/__init__.py
@@ -55,7 +55,7 @@ except:
zs = """
web/a/partyfuse.py
web/a/u2c.py
-web/a/webdav-cfg.bat
+web/a/webdav-cfg.txt
web/baguettebox.js
web/browser.css
web/browser.html
@@ -125,6 +125,11 @@ web/util.js
web/w.hash.js
"""
RES = set(zs.strip().split("\n"))
+RESM = {
+ "web/a/partyfuse.txt": "web/a/partyfuse.py",
+ "web/a/u2c.txt": "web/a/u2c.py",
+ "web/a/webdav-cfg.bat": "web/a/webdav-cfg.txt",
+}
class EnvParams(object):
diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py
index 48887cee..40bff7cb 100644
--- a/copyparty/httpcli.py
+++ b/copyparty/httpcli.py
@@ -30,7 +30,7 @@ try:
except:
pass
-from .__init__ import ANYWIN, RES, TYPE_CHECKING, EnvParams, unicode
+from .__init__ import ANYWIN, RES, RESM, TYPE_CHECKING, EnvParams, unicode
from .__version__ import S_VERSION
from .authsrv import LEELOO_DALLAS, VFS # typechk
from .bos import bos
@@ -1275,6 +1275,20 @@ class HttpCli(object):
else:
return self.tx_res(res_path)
+ if res_path in RESM:
+ ap = self.E.mod_ + RESM[res_path]
+ if (
+ "txt" not in self.uparam
+ and "mime" not in self.uparam
+ and not self.ouparam.get("dl")
+ ):
+ # return mimetype matching request extension
+ self.ouparam["dl"] = res_path.split("/")[-1]
+ if bos.path.exists(ap) or bos.path.exists(ap + ".gz"):
+ return self.tx_file(ap)
+ else:
+ return self.tx_res(res_path)
+
self.tx_404()
return False
@@ -4179,8 +4193,11 @@ class HttpCli(object):
# force download
if "dl" in self.ouparam:
- cdis = gen_content_disposition(os.path.basename(req_path))
- self.out_headers["Content-Disposition"] = cdis
+ cdis = self.ouparam["dl"] or req_path
+ zs = gen_content_disposition(os.path.basename(cdis))
+ self.out_headers["Content-Disposition"] = zs
+ else:
+ cdis = req_path
#
# if-modified
@@ -4246,7 +4263,7 @@ class HttpCli(object):
elif "mime" in self.uparam:
mime = str(self.uparam.get("mime"))
else:
- mime = guess_mime(req_path)
+ mime = guess_mime(cdis)
logmsg += unicode(status) + logtail
@@ -4354,8 +4371,11 @@ class HttpCli(object):
# force download
if "dl" in self.ouparam:
- cdis = gen_content_disposition(os.path.basename(req_path))
- self.out_headers["Content-Disposition"] = cdis
+ cdis = self.ouparam["dl"] or req_path
+ zs = gen_content_disposition(os.path.basename(cdis))
+ self.out_headers["Content-Disposition"] = zs
+ else:
+ cdis = req_path
#
# if-modified
@@ -4483,7 +4503,7 @@ class HttpCli(object):
elif "rmagic" in self.vn.flags:
mime = guess_mime(req_path, fs_path)
else:
- mime = guess_mime(req_path)
+ mime = guess_mime(cdis)
if "nohtml" in self.vn.flags and "html" in mime:
mime = "text/plain; charset=utf-8"
diff --git a/copyparty/web/Makefile b/copyparty/web/Makefile
index 99fd53f2..01ec4637 100644
--- a/copyparty/web/Makefile
+++ b/copyparty/web/Makefile
@@ -2,8 +2,9 @@
# which should help on really slow connections
# but then why are you using copyparty in the first place
-pk: $(addsuffix .gz, $(wildcard tl/*.js *.js *.css))
-un: $(addsuffix .un, $(wildcard tl/*.gz *.gz))
+pk: $(addsuffix .gz, $(wildcard tl/*.js *.js *.css) \
+ a/partyfuse.py a/u2c.py a/webdav-cfg.txt )
+un: $(addsuffix .un, $(wildcard tl/*.gz *.gz a/*.gz))
%.gz: %
pigz -11 -J 34 -I 573 $<
diff --git a/copyparty/web/a/webdav-cfg.bat b/copyparty/web/a/webdav-cfg.txt
similarity index 100%
rename from copyparty/web/a/webdav-cfg.bat
rename to copyparty/web/a/webdav-cfg.txt
diff --git a/copyparty/web/svcs.html b/copyparty/web/svcs.html
index f07a8fb6..a0bed2c7 100644
--- a/copyparty/web/svcs.html
+++ b/copyparty/web/svcs.html
@@ -64,7 +64,7 @@
= with (space)
if you want to use the native WebDAV client in windows instead (slow and buggy), first run webdav-cfg.bat to remove the 47 MiB filesize limit (also fixes latency and password login), then connect:
+if you want to use the native WebDAV client in windows instead (slow and buggy), first run webdav-cfg.bat to remove the 47 MiB filesize limit (also fixes latency and password login), then connect:
{%- if un %}
net use w: http{{ s }}://{{ ep }}/{{ rvp }}{% if accs %} {{ pw }} /user:{{ b_un }}{% endif %}
diff --git a/pyproject.toml b/pyproject.toml
index 6041a3ce..c5d41e31 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -96,7 +96,8 @@ copyparty = [
"web/*.xml",
"web/tl/*.js",
"web/tl/*.gz",
- "web/a/*.bat",
+ "web/a/*.txt",
+ "web/a/*.gz",
"web/deps/*.gz",
"web/deps/*.woff*",
]
diff --git a/scripts/make-sfx.sh b/scripts/make-sfx.sh
index e9aa80fb..36d5a792 100755
--- a/scripts/make-sfx.sh
+++ b/scripts/make-sfx.sh
@@ -571,7 +571,7 @@ gzres() {
$pk "$f" &
done < <(
find -printf '%s %p\n' |
- grep -E '\.(js|css)$' |
+ grep -E '\.(js|css)$|/web/a/[^_].*\.(py|txt)$' |
grep -vF /deps/ |
sort -nr
)
diff --git a/scripts/sfx.ls b/scripts/sfx.ls
index 3505ee63..59a13916 100644
--- a/scripts/sfx.ls
+++ b/scripts/sfx.ls
@@ -66,7 +66,7 @@ copyparty/web/a,
copyparty/web/a/__init__.py,
copyparty/web/a/partyfuse.py,
copyparty/web/a/u2c.py,
-copyparty/web/a/webdav-cfg.bat,
+copyparty/web/a/webdav-cfg.txt,
copyparty/web/baguettebox.js,
copyparty/web/browser.css,
copyparty/web/browser.html,