Compare commits

...

4 Commits

Author SHA1 Message Date
ed
6da2a083f9 v0.11.37 2021-07-12 00:51:59 +02:00
ed
8837c8f822 print zip/tar errors to log 2021-07-12 00:47:22 +02:00
ed
bac301ed66 get rid of iffy default-args 2021-07-12 00:15:13 +02:00
ed
061db3906d v0.11.36 2021-07-11 06:39:58 +02:00
15 changed files with 57 additions and 51 deletions

View File

@@ -345,7 +345,7 @@ class Gateway(object):
except: except:
pass pass
def sendreq(self, *args, headers={}, **kwargs): def sendreq(self, meth, path, headers, **kwargs):
if self.password: if self.password:
headers["Cookie"] = "=".join(["cppwd", self.password]) headers["Cookie"] = "=".join(["cppwd", self.password])
@@ -354,21 +354,21 @@ class Gateway(object):
if c.rx_path: if c.rx_path:
raise Exception() raise Exception()
c.request(*list(args), headers=headers, **kwargs) c.request(meth, path, headers=headers, **kwargs)
c.rx = c.getresponse() c.rx = c.getresponse()
return c return c
except: except:
tid = threading.current_thread().ident tid = threading.current_thread().ident
dbg( dbg(
"\033[1;37;44mbad conn {:x}\n {}\n {}\033[0m".format( "\033[1;37;44mbad conn {:x}\n {} {}\n {}\033[0m".format(
tid, " ".join(str(x) for x in args), c.rx_path if c else "(null)" tid, meth, path, c.rx_path if c else "(null)"
) )
) )
self.closeconn(c) self.closeconn(c)
c = self.getconn() c = self.getconn()
try: try:
c.request(*list(args), headers=headers, **kwargs) c.request(meth, path, headers=headers, **kwargs)
c.rx = c.getresponse() c.rx = c.getresponse()
return c return c
except: except:
@@ -386,7 +386,7 @@ class Gateway(object):
path = dewin(path) path = dewin(path)
web_path = self.quotep("/" + "/".join([self.web_root, path])) + "?dots" web_path = self.quotep("/" + "/".join([self.web_root, path])) + "?dots"
c = self.sendreq("GET", web_path) c = self.sendreq("GET", web_path, {})
if c.rx.status != 200: if c.rx.status != 200:
self.closeconn(c) self.closeconn(c)
log( log(
@@ -440,7 +440,7 @@ class Gateway(object):
) )
) )
c = self.sendreq("GET", web_path, headers={"Range": hdr_range}) c = self.sendreq("GET", web_path, {"Range": hdr_range})
if c.rx.status != http.client.PARTIAL_CONTENT: if c.rx.status != http.client.PARTIAL_CONTENT:
self.closeconn(c) self.closeconn(c)
raise Exception( raise Exception(

View File

@@ -54,10 +54,13 @@ MACOS = platform.system() == "Darwin"
info = log = dbg = None info = log = dbg = None
print("{} v{} @ {}".format( print(
platform.python_implementation(), "{} v{} @ {}".format(
".".join([str(x) for x in sys.version_info]), platform.python_implementation(),
sys.executable)) ".".join([str(x) for x in sys.version_info]),
sys.executable,
)
)
try: try:
@@ -299,14 +302,14 @@ class Gateway(object):
except: except:
pass pass
def sendreq(self, *args, headers={}, **kwargs): def sendreq(self, meth, path, headers, **kwargs):
tid = get_tid() tid = get_tid()
if self.password: if self.password:
headers["Cookie"] = "=".join(["cppwd", self.password]) headers["Cookie"] = "=".join(["cppwd", self.password])
try: try:
c = self.getconn(tid) c = self.getconn(tid)
c.request(*list(args), headers=headers, **kwargs) c.request(meth, path, headers=headers, **kwargs)
return c.getresponse() return c.getresponse()
except: except:
dbg("bad conn") dbg("bad conn")
@@ -314,7 +317,7 @@ class Gateway(object):
self.closeconn(tid) self.closeconn(tid)
try: try:
c = self.getconn(tid) c = self.getconn(tid)
c.request(*list(args), headers=headers, **kwargs) c.request(meth, path, headers=headers, **kwargs)
return c.getresponse() return c.getresponse()
except: except:
info("http connection failed:\n" + traceback.format_exc()) info("http connection failed:\n" + traceback.format_exc())
@@ -331,7 +334,7 @@ class Gateway(object):
path = dewin(path) path = dewin(path)
web_path = self.quotep("/" + "/".join([self.web_root, path])) + "?dots&ls" web_path = self.quotep("/" + "/".join([self.web_root, path])) + "?dots&ls"
r = self.sendreq("GET", web_path) r = self.sendreq("GET", web_path, {})
if r.status != 200: if r.status != 200:
self.closeconn() self.closeconn()
log( log(
@@ -368,7 +371,7 @@ class Gateway(object):
) )
) )
r = self.sendreq("GET", web_path, headers={"Range": hdr_range}) r = self.sendreq("GET", web_path, {"Range": hdr_range})
if r.status != http.client.PARTIAL_CONTENT: if r.status != http.client.PARTIAL_CONTENT:
self.closeconn() self.closeconn()
raise Exception( raise Exception(

View File

@@ -1,8 +1,8 @@
# coding: utf-8 # coding: utf-8
VERSION = (0, 11, 35) VERSION = (0, 11, 37)
CODENAME = "the grid" CODENAME = "the grid"
BUILD_DT = (2021, 7, 11) BUILD_DT = (2021, 7, 12)
S_VERSION = ".".join(map(str, VERSION)) S_VERSION = ".".join(map(str, VERSION))
S_BUILD_DT = "{0:04d}-{1:02d}-{2:02d}".format(*BUILD_DT) S_BUILD_DT = "{0:04d}-{1:02d}-{2:02d}".format(*BUILD_DT)

View File

@@ -16,7 +16,7 @@ from .util import IMPLICATIONS, uncyg, undot, Pebkac, fsdec, fsenc, statdir
class VFS(object): class VFS(object):
"""single level in the virtual fs""" """single level in the virtual fs"""
def __init__(self, log, realpath, vpath, uread=[], uwrite=[], uadm=[], flags={}): def __init__(self, log, realpath, vpath, uread, uwrite, uadm, flags):
self.log = log self.log = log
self.realpath = realpath # absolute path on host filesystem self.realpath = realpath # absolute path on host filesystem
self.vpath = vpath # absolute path in the virtual filesystem self.vpath = vpath # absolute path in the virtual filesystem
@@ -81,7 +81,7 @@ class VFS(object):
# leaf does not exist; create and keep permissions blank # leaf does not exist; create and keep permissions blank
vp = "{}/{}".format(self.vpath, dst).lstrip("/") vp = "{}/{}".format(self.vpath, dst).lstrip("/")
vn = VFS(self.log, src, vp) vn = VFS(self.log, src, vp, [], [], [], {})
vn.dbv = self.dbv or self vn.dbv = self.dbv or self
self.nodes[dst] = vn self.nodes[dst] = vn
return vn return vn
@@ -497,10 +497,10 @@ class AuthSrv(object):
if not mount: if not mount:
# -h says our defaults are CWD at root and read/write for everyone # -h says our defaults are CWD at root and read/write for everyone
vfs = VFS(self.log_func, os.path.abspath("."), "", ["*"], ["*"]) vfs = VFS(self.log_func, os.path.abspath("."), "", ["*"], ["*"], ["*"], {})
elif "" not in mount: elif "" not in mount:
# there's volumes but no root; make root inaccessible # there's volumes but no root; make root inaccessible
vfs = VFS(self.log_func, None, "") vfs = VFS(self.log_func, None, "", [], [], [], {})
vfs.flags["d2d"] = True vfs.flags["d2d"] = True
maxdepth = 0 maxdepth = 0

View File

@@ -227,7 +227,7 @@ class HttpCli(object):
except Pebkac: except Pebkac:
return False return False
def send_headers(self, length, status=200, mime=None, headers={}): def send_headers(self, length, status=200, mime=None, headers=None):
response = ["{} {} {}".format(self.http_ver, status, HTTPCODE[status])] response = ["{} {} {}".format(self.http_ver, status, HTTPCODE[status])]
if length is not None: if length is not None:
@@ -237,7 +237,8 @@ class HttpCli(object):
response.append("Connection: " + ("Keep-Alive" if self.keepalive else "Close")) response.append("Connection: " + ("Keep-Alive" if self.keepalive else "Close"))
# headers{} overrides anything set previously # headers{} overrides anything set previously
self.out_headers.update(headers) if headers:
self.out_headers.update(headers)
# default to utf8 html if no content-type is set # default to utf8 html if no content-type is set
if not mime: if not mime:
@@ -254,7 +255,7 @@ class HttpCli(object):
except: except:
raise Pebkac(400, "client d/c while replying headers") raise Pebkac(400, "client d/c while replying headers")
def reply(self, body, status=200, mime=None, headers={}): def reply(self, body, status=200, mime=None, headers=None):
# TODO something to reply with user-supplied values safely # TODO something to reply with user-supplied values safely
self.send_headers(len(body), status, mime, headers) self.send_headers(len(body), status, mime, headers)
@@ -270,7 +271,7 @@ class HttpCli(object):
self.log(body.rstrip()) self.log(body.rstrip())
self.reply(b"<pre>" + body.encode("utf-8") + b"\r\n", *list(args), **kwargs) self.reply(b"<pre>" + body.encode("utf-8") + b"\r\n", *list(args), **kwargs)
def urlq(self, add={}, rm=[]): def urlq(self, add, rm):
""" """
generates url query based on uparam (b, pw, all others) generates url query based on uparam (b, pw, all others)
removing anything in rm, adding pairs in add removing anything in rm, adding pairs in add
@@ -795,7 +796,7 @@ class HttpCli(object):
vfs, rem = self.asrv.vfs.get(self.vpath, self.uname, False, True) vfs, rem = self.asrv.vfs.get(self.vpath, self.uname, False, True)
self._assert_safe_rem(rem) self._assert_safe_rem(rem)
sanitized = sanitize_fn(new_dir) sanitized = sanitize_fn(new_dir, "", [])
if not nullwrite: if not nullwrite:
fdir = os.path.join(vfs.realpath, rem) fdir = os.path.join(vfs.realpath, rem)
@@ -832,7 +833,7 @@ class HttpCli(object):
if not new_file.endswith(".md"): if not new_file.endswith(".md"):
new_file += ".md" new_file += ".md"
sanitized = sanitize_fn(new_file) sanitized = sanitize_fn(new_file, "", [])
if not nullwrite: if not nullwrite:
fdir = os.path.join(vfs.realpath, rem) fdir = os.path.join(vfs.realpath, rem)
@@ -865,7 +866,7 @@ class HttpCli(object):
if p_file and not nullwrite: if p_file and not nullwrite:
fdir = os.path.join(vfs.realpath, rem) fdir = os.path.join(vfs.realpath, rem)
fname = sanitize_fn( fname = sanitize_fn(
p_file, bad=[".prologue.html", ".epilogue.html"] p_file, "", [".prologue.html", ".epilogue.html"]
) )
if not os.path.isdir(fsenc(fdir)): if not os.path.isdir(fsenc(fdir)):
@@ -1312,7 +1313,7 @@ class HttpCli(object):
fgen = vn.zipgen(rem, items, self.uname, dots, not self.args.no_scandir) fgen = vn.zipgen(rem, items, self.uname, dots, not self.args.no_scandir)
# for f in fgen: print(repr({k: f[k] for k in ["vp", "ap"]})) # for f in fgen: print(repr({k: f[k] for k in ["vp", "ap"]}))
bgen = packer(fgen, utf8="utf" in uarg, pre_crc="crc" in uarg) bgen = packer(self.log, fgen, utf8="utf" in uarg, pre_crc="crc" in uarg)
bsent = 0 bsent = 0
for buf in bgen.gen(): for buf in bgen.gen():
if not buf: if not buf:
@@ -1423,7 +1424,7 @@ class HttpCli(object):
return True return True
def tx_mounts(self): def tx_mounts(self):
suf = self.urlq(rm=["h"]) suf = self.urlq({}, ["h"])
rvol, wvol, avol = [ rvol, wvol, avol = [
[("/" + x).rstrip("/") + "/" for x in y] [("/" + x).rstrip("/") + "/" for x in y]
for y in [self.rvol, self.wvol, self.avol] for y in [self.rvol, self.wvol, self.avol]
@@ -1634,7 +1635,7 @@ class HttpCli(object):
if self.writable: if self.writable:
perms.append("write") perms.append("write")
url_suf = self.urlq() url_suf = self.urlq({}, [])
is_ls = "ls" in self.uparam is_ls = "ls" in self.uparam
tpl = "browser" tpl = "browser"

View File

@@ -33,10 +33,11 @@ class QFile(object):
class StreamTar(object): class StreamTar(object):
"""construct in-memory tar file from the given path""" """construct in-memory tar file from the given path"""
def __init__(self, fgen, **kwargs): def __init__(self, log, fgen, **kwargs):
self.ci = 0 self.ci = 0
self.co = 0 self.co = 0
self.qfile = QFile() self.qfile = QFile()
self.log = log
self.fgen = fgen self.fgen = fgen
self.errf = None self.errf = None
@@ -91,7 +92,8 @@ class StreamTar(object):
errors.append([f["vp"], repr(ex)]) errors.append([f["vp"], repr(ex)])
if errors: if errors:
self.errf = errdesc(errors) self.errf, txt = errdesc(errors)
self.log("\n".join(([repr(self.errf)] + txt[1:])))
self.ser(self.errf) self.ser(self.errf)
self.tar.close() self.tar.close()

View File

@@ -25,4 +25,4 @@ def errdesc(errors):
"vp": "archive-errors-{}.txt".format(dt), "vp": "archive-errors-{}.txt".format(dt),
"ap": tf_path, "ap": tf_path,
"st": os.stat(tf_path), "st": os.stat(tf_path),
} }, report

View File

@@ -89,7 +89,7 @@ def gen_hdr(h_pos, fn, sz, lastmod, utf8, crc32, pre_crc):
ret += spack(b"<LL", vsz, vsz) ret += spack(b"<LL", vsz, vsz)
# windows support (the "?" replace below too) # windows support (the "?" replace below too)
fn = sanitize_fn(fn, ok="/") fn = sanitize_fn(fn, "/", [])
bfn = fn.encode("utf-8" if utf8 else "cp437", "replace").replace(b"?", b"_") bfn = fn.encode("utf-8" if utf8 else "cp437", "replace").replace(b"?", b"_")
z64_len = len(z64v) * 8 + 4 if z64v else 0 z64_len = len(z64v) * 8 + 4 if z64v else 0
@@ -183,7 +183,8 @@ def gen_ecdr64_loc(ecdr64_pos):
class StreamZip(object): class StreamZip(object):
def __init__(self, fgen, utf8=False, pre_crc=False): def __init__(self, log, fgen, utf8=False, pre_crc=False):
self.log = log
self.fgen = fgen self.fgen = fgen
self.utf8 = utf8 self.utf8 = utf8
self.pre_crc = pre_crc self.pre_crc = pre_crc
@@ -246,8 +247,8 @@ class StreamZip(object):
errors.append([f["vp"], repr(ex)]) errors.append([f["vp"], repr(ex)])
if errors: if errors:
errf = errdesc(errors) errf, txt = errdesc(errors)
print(repr(errf)) self.log("\n".join(([repr(errf)] + txt[1:])))
for x in self.ser(errf): for x in self.ser(errf):
yield x yield x

View File

@@ -260,7 +260,7 @@ class ThumbSrv(object):
pass # default q = 75 pass # default q = 75
if im.mode not in fmts: if im.mode not in fmts:
print("conv {}".format(im.mode)) # print("conv {}".format(im.mode))
im = im.convert("RGB") im = im.convert("RGB")
im.save(tpath, quality=40, method=6) im.save(tpath, quality=40, method=6)

View File

@@ -195,7 +195,7 @@ class Up2k(object):
return True, ret return True, ret
def init_indexes(self, all_vols, scan_vols=[]): def init_indexes(self, all_vols, scan_vols=None):
self.pp = ProgressPrinter() self.pp = ProgressPrinter()
vols = all_vols.values() vols = all_vols.values()
t0 = time.time() t0 = time.time()
@@ -991,7 +991,7 @@ class Up2k(object):
if cj["ptop"] not in self.registry: if cj["ptop"] not in self.registry:
raise Pebkac(410, "location unavailable") raise Pebkac(410, "location unavailable")
cj["name"] = sanitize_fn(cj["name"], bad=[".prologue.html", ".epilogue.html"]) cj["name"] = sanitize_fn(cj["name"], "", [".prologue.html", ".epilogue.html"])
cj["poke"] = time.time() cj["poke"] = time.time()
wark = self._get_wark(cj) wark = self._get_wark(cj)
now = time.time() now = time.time()

View File

@@ -672,7 +672,7 @@ def undot(path):
return "/".join(ret) return "/".join(ret)
def sanitize_fn(fn, ok="", bad=[]): def sanitize_fn(fn, ok, bad):
if "/" not in ok: if "/" not in ok:
fn = fn.replace("\\", "/").split("/")[-1] fn = fn.replace("\\", "/").split("/")[-1]

View File

@@ -28,8 +28,8 @@ window.baguetteBox = (function () {
isOverlayVisible = false, isOverlayVisible = false,
touch = {}, // start-pos touch = {}, // start-pos
touchFlag = false, // busy touchFlag = false, // busy
re_i = /.+\.(gif|jpe?g|png|webp)/i, re_i = /.+\.(gif|jpe?g|png|webp)(\?|$)/i,
re_v = /.+\.(webm|mp4)/i, re_v = /.+\.(webm|mp4)(\?|$)/i,
data = {}, // all galleries data = {}, // all galleries
imagesElements = [], imagesElements = [],
documentLastFocus = null; documentLastFocus = null;

View File

@@ -23,10 +23,10 @@ def hdr(query):
class Cfg(Namespace): class Cfg(Namespace):
def __init__(self, a=[], v=[], c=None): def __init__(self, a=None, v=None, c=None):
super(Cfg, self).__init__( super(Cfg, self).__init__(
a=a, a=a or [],
v=v, v=v or [],
c=c, c=c,
rproxy=0, rproxy=0,
ed=False, ed=False,

View File

@@ -16,7 +16,7 @@ from copyparty import util
class Cfg(Namespace): class Cfg(Namespace):
def __init__(self, a=[], v=[], c=None): def __init__(self, a=None, v=None, c=None):
ex = {k: False for k in "nw e2d e2ds e2dsa e2t e2ts e2tsr".split()} ex = {k: False for k in "nw e2d e2ds e2dsa e2t e2ts e2tsr".split()}
ex2 = { ex2 = {
"mtp": [], "mtp": [],
@@ -27,7 +27,7 @@ class Cfg(Namespace):
"rproxy": 0, "rproxy": 0,
} }
ex.update(ex2) ex.update(ex2)
super(Cfg, self).__init__(a=a, v=v, c=c, **ex) super(Cfg, self).__init__(a=a or [], v=v or [], c=c, **ex)
class TestVFS(unittest.TestCase): class TestVFS(unittest.TestCase):

View File

@@ -126,7 +126,6 @@ class VHttpConn(object):
self.hsrv = VHttpSrv() self.hsrv = VHttpSrv()
self.nreq = 0 self.nreq = 0
self.nbyte = 0 self.nbyte = 0
self.workload = 0
self.ico = None self.ico = None
self.thumbcli = None self.thumbcli = None
self.t0 = time.time() self.t0 = time.time()