mirror of
				https://github.com/9001/copyparty.git
				synced 2025-11-04 13:53:18 +00:00 
			
		
		
		
	Compare commits
	
		
			4 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					223657e5f8 | ||
| 
						 | 
					0c53de6767 | ||
| 
						 | 
					9c309b1498 | ||
| 
						 | 
					1aa1b34c80 | 
@@ -13,3 +13,7 @@
 | 
				
			|||||||
init-scripts to start copyparty as a service
 | 
					init-scripts to start copyparty as a service
 | 
				
			||||||
* [`systemd/copyparty.service`](systemd/copyparty.service)
 | 
					* [`systemd/copyparty.service`](systemd/copyparty.service)
 | 
				
			||||||
* [`openrc/copyparty`](openrc/copyparty)
 | 
					* [`openrc/copyparty`](openrc/copyparty)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Reverse-proxy
 | 
				
			||||||
 | 
					copyparty has basic support for running behind another webserver
 | 
				
			||||||
 | 
					* [`nginx/copyparty.conf`](nginx/copyparty.conf)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										26
									
								
								contrib/nginx/copyparty.conf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								contrib/nginx/copyparty.conf
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					upstream cpp {
 | 
				
			||||||
 | 
						server 127.0.0.1:3923;
 | 
				
			||||||
 | 
						keepalive 120;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					server {
 | 
				
			||||||
 | 
						listen 443 ssl;
 | 
				
			||||||
 | 
						listen [::]:443 ssl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						server_name fs.example.com;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						location / {
 | 
				
			||||||
 | 
							proxy_pass http://cpp;
 | 
				
			||||||
 | 
							proxy_redirect off;
 | 
				
			||||||
 | 
							# disable buffering (next 4 lines)
 | 
				
			||||||
 | 
							proxy_http_version 1.1;
 | 
				
			||||||
 | 
							client_max_body_size 0;
 | 
				
			||||||
 | 
							proxy_buffering off;
 | 
				
			||||||
 | 
							proxy_request_buffering off;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							proxy_set_header   Host              $host;
 | 
				
			||||||
 | 
							proxy_set_header   X-Real-IP         $remote_addr;
 | 
				
			||||||
 | 
							proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
 | 
				
			||||||
 | 
							proxy_set_header   X-Forwarded-Proto $scheme;
 | 
				
			||||||
 | 
							proxy_set_header   Connection        "Keep-Alive";
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,8 +1,8 @@
 | 
				
			|||||||
# coding: utf-8
 | 
					# coding: utf-8
 | 
				
			||||||
 | 
					
 | 
				
			||||||
VERSION = (0, 5, 3)
 | 
					VERSION = (0, 5, 4)
 | 
				
			||||||
CODENAME = "fuse jelly"
 | 
					CODENAME = "fuse jelly"
 | 
				
			||||||
BUILD_DT = (2020, 11, 13)
 | 
					BUILD_DT = (2020, 11, 17)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -83,6 +83,10 @@ class HttpCli(object):
 | 
				
			|||||||
        v = self.headers.get("connection", "").lower()
 | 
					        v = self.headers.get("connection", "").lower()
 | 
				
			||||||
        self.keepalive = not v.startswith("close")
 | 
					        self.keepalive = not v.startswith("close")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        v = self.headers.get("x-forwarded-for", None)
 | 
				
			||||||
 | 
					        if v is not None and self.conn.addr[0] in ["127.0.0.1", "::1"]:
 | 
				
			||||||
 | 
					            self.log_src = self.conn.set_rproxy(v.split(",")[0])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.uname = "*"
 | 
					        self.uname = "*"
 | 
				
			||||||
        if "cookie" in self.headers:
 | 
					        if "cookie" in self.headers:
 | 
				
			||||||
            cookies = self.headers["cookie"].split(";")
 | 
					            cookies = self.headers["cookie"].split(";")
 | 
				
			||||||
@@ -462,7 +466,7 @@ class HttpCli(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        spd = self._spd(post_sz)
 | 
					        spd = self._spd(post_sz)
 | 
				
			||||||
        self.log("{} thank".format(spd))
 | 
					        self.log("{} thank".format(spd))
 | 
				
			||||||
        self.reply("thank")
 | 
					        self.reply(b"thank")
 | 
				
			||||||
        return True
 | 
					        return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def handle_login(self):
 | 
					    def handle_login(self):
 | 
				
			||||||
@@ -1073,7 +1077,12 @@ class HttpCli(object):
 | 
				
			|||||||
            dt = datetime.utcfromtimestamp(inf.st_mtime)
 | 
					            dt = datetime.utcfromtimestamp(inf.st_mtime)
 | 
				
			||||||
            dt = dt.strftime("%Y-%m-%d %H:%M:%S")
 | 
					            dt = dt.strftime("%Y-%m-%d %H:%M:%S")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            item = [margin, quotep(href), html_escape(fn), sz, dt]
 | 
					            try:
 | 
				
			||||||
 | 
					                ext = "---" if is_dir else fn.rsplit(".", 1)[1]
 | 
				
			||||||
 | 
					            except:
 | 
				
			||||||
 | 
					                ext = "%"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            item = [margin, quotep(href), html_escape(fn), sz, ext, dt]
 | 
				
			||||||
            if is_dir:
 | 
					            if is_dir:
 | 
				
			||||||
                dirs.append(item)
 | 
					                dirs.append(item)
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,7 +46,7 @@ class HttpConn(object):
 | 
				
			|||||||
        self.nbyte = 0
 | 
					        self.nbyte = 0
 | 
				
			||||||
        self.workload = 0
 | 
					        self.workload = 0
 | 
				
			||||||
        self.log_func = hsrv.log
 | 
					        self.log_func = hsrv.log
 | 
				
			||||||
        self.log_src = "{} \033[36m{}".format(addr[0], addr[1]).ljust(26)
 | 
					        self.set_rproxy()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        env = jinja2.Environment()
 | 
					        env = jinja2.Environment()
 | 
				
			||||||
        env.loader = jinja2.FileSystemLoader(os.path.join(E.mod, "web"))
 | 
					        env.loader = jinja2.FileSystemLoader(os.path.join(E.mod, "web"))
 | 
				
			||||||
@@ -56,6 +56,18 @@ class HttpConn(object):
 | 
				
			|||||||
        self.tpl_md = env.get_template("md.html")
 | 
					        self.tpl_md = env.get_template("md.html")
 | 
				
			||||||
        self.tpl_mde = env.get_template("mde.html")
 | 
					        self.tpl_mde = env.get_template("mde.html")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def set_rproxy(self, ip=None):
 | 
				
			||||||
 | 
					        if ip is None:
 | 
				
			||||||
 | 
					            color = 36
 | 
				
			||||||
 | 
					            ip = self.addr[0]
 | 
				
			||||||
 | 
					            self.rproxy = None
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            color = 34
 | 
				
			||||||
 | 
					            self.rproxy = ip
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.log_src = "{} \033[{}m{}".format(ip, color, self.addr[1]).ljust(26)
 | 
				
			||||||
 | 
					        return self.log_src
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def respath(self, res_name):
 | 
					    def respath(self, res_name):
 | 
				
			||||||
        return os.path.join(E.mod, "web", res_name)
 | 
					        return os.path.join(E.mod, "web", res_name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,13 +34,14 @@
 | 
				
			|||||||
                <th></th>
 | 
					                <th></th>
 | 
				
			||||||
                <th>File Name</th>
 | 
					                <th>File Name</th>
 | 
				
			||||||
                <th sort="int">File Size</th>
 | 
					                <th sort="int">File Size</th>
 | 
				
			||||||
 | 
					                <th>T</th>
 | 
				
			||||||
                <th>Date</th>
 | 
					                <th>Date</th>
 | 
				
			||||||
            </tr>
 | 
					            </tr>
 | 
				
			||||||
        </thead>
 | 
					        </thead>
 | 
				
			||||||
        <tbody>
 | 
					        <tbody>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{%- for f in files %}
 | 
					{%- for f in files %}
 | 
				
			||||||
<tr><td>{{ f[0] }}</td><td><a href="{{ f[1] }}">{{ f[2] }}</a></td><td>{{ f[3] }}</td><td>{{ f[4] }}</td></tr>
 | 
					<tr><td>{{ f[0] }}</td><td><a href="{{ f[1] }}">{{ f[2] }}</a></td><td>{{ f[3] }}</td><td>{{ f[4] }}</td><td>{{ f[5] }}</td></tr>
 | 
				
			||||||
{%- endfor %}
 | 
					{%- endfor %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        </tbody>
 | 
					        </tbody>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -617,8 +617,8 @@ function unblocked() {
 | 
				
			|||||||
// show ui to manually start playback of a linked song
 | 
					// show ui to manually start playback of a linked song
 | 
				
			||||||
function autoplay_blocked(tid) {
 | 
					function autoplay_blocked(tid) {
 | 
				
			||||||
	show_modal(
 | 
						show_modal(
 | 
				
			||||||
		'<div id="blk_play"><a id="blk_go"></a></div>' +
 | 
							'<div id="blk_play"><a href="#" id="blk_go"></a></div>' +
 | 
				
			||||||
		'<div id="blk_abrt"><a id="blk_na">Cancel<br />(show file list)</a></div>');
 | 
							'<div id="blk_abrt"><a href="#" id="blk_na">Cancel<br />(show file list)</a></div>');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var go = o('blk_go');
 | 
						var go = o('blk_go');
 | 
				
			||||||
	var na = o('blk_na');
 | 
						var na = o('blk_na');
 | 
				
			||||||
@@ -627,7 +627,8 @@ function autoplay_blocked(tid) {
 | 
				
			|||||||
	fn = decodeURIComponent(fn.replace(/\+/g, ' '));
 | 
						fn = decodeURIComponent(fn.replace(/\+/g, ' '));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	go.textContent = 'Play "' + fn + '"';
 | 
						go.textContent = 'Play "' + fn + '"';
 | 
				
			||||||
	go.onclick = function () {
 | 
						go.onclick = function (e) {
 | 
				
			||||||
 | 
							if (e) e.preventDefault();
 | 
				
			||||||
		unblocked();
 | 
							unblocked();
 | 
				
			||||||
		mp.au.play();
 | 
							mp.au.play();
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -602,7 +602,7 @@ function fmt_table(e) {
 | 
				
			|||||||
        //o0 = txt.lastIndexOf('\n\n', ofs),
 | 
					        //o0 = txt.lastIndexOf('\n\n', ofs),
 | 
				
			||||||
        //o1 = txt.indexOf('\n\n', ofs);
 | 
					        //o1 = txt.indexOf('\n\n', ofs);
 | 
				
			||||||
        o0 = reLastIndexOf(txt, /\n\s*\n/m, ofs),
 | 
					        o0 = reLastIndexOf(txt, /\n\s*\n/m, ofs),
 | 
				
			||||||
        o1 = txt.slice(ofs).search(/\n\s*\n/m);
 | 
					        o1 = txt.slice(ofs).search(/\n\s*\n|\n\s*$/m);
 | 
				
			||||||
    // note \s contains \n but its fine
 | 
					    // note \s contains \n but its fine
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (o0 < 0)
 | 
					    if (o0 < 0)
 | 
				
			||||||
@@ -625,10 +625,18 @@ function fmt_table(e) {
 | 
				
			|||||||
        re_lpipe = lpipe ? /^\s*\|\s*/ : /^\s*/,
 | 
					        re_lpipe = lpipe ? /^\s*\|\s*/ : /^\s*/,
 | 
				
			||||||
        re_rpipe = rpipe ? /\s*\|\s*$/ : /\s*$/;
 | 
					        re_rpipe = rpipe ? /\s*\|\s*$/ : /\s*$/;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // the second row defines the table,
 | 
				
			||||||
 | 
					    // need to process that first
 | 
				
			||||||
 | 
					    var tmp = tab[0];
 | 
				
			||||||
 | 
					    tab[0] = tab[1];
 | 
				
			||||||
 | 
					    tab[1] = tmp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (var a = 0; a < tab.length; a++) {
 | 
					    for (var a = 0; a < tab.length; a++) {
 | 
				
			||||||
 | 
					        var row_name = (a == 1) ? 'header' : 'row#' + (a + 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var ind2 = tab[a].match(re_ind)[0];
 | 
					        var ind2 = tab[a].match(re_ind)[0];
 | 
				
			||||||
        if (ind != ind2 && a > 0)  // the table can be a list entry or something, ignore [0]
 | 
					        if (ind != ind2 && a != 1)  // the table can be a list entry or something, ignore [0]
 | 
				
			||||||
            return alert(err + 'indentation mismatch on row 2 and ' + (a + 1) + ',\n' + tab[a]);
 | 
					            return alert(err + 'indentation mismatch on row#2 and ' + row_name + ',\n' + tab[a]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var t = tab[a].slice(ind.length);
 | 
					        var t = tab[a].slice(ind.length);
 | 
				
			||||||
        t = t.replace(re_lpipe, "");
 | 
					        t = t.replace(re_lpipe, "");
 | 
				
			||||||
@@ -637,17 +645,25 @@ function fmt_table(e) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if (a == 0)
 | 
					        if (a == 0)
 | 
				
			||||||
            ncols = tab[a].length;
 | 
					            ncols = tab[a].length;
 | 
				
			||||||
 | 
					        else if (ncols < tab[a].length)
 | 
				
			||||||
 | 
					            return alert(err + 'num.columns(' + row_name + ') exceeding row#2;  ' + ncols + ' < ' + tab[a].length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (ncols != tab[a].length)
 | 
					        // if row has less columns than row2, fill them in
 | 
				
			||||||
            return alert(err + 'num.columns mismatch on row 2 and ' + (a + 1) + '; ' + ncols + ' != ' + tab[a].length);
 | 
					        while (tab[a].length < ncols)
 | 
				
			||||||
 | 
					            tab[a].push('');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // aight now swap em back
 | 
				
			||||||
 | 
					    tmp = tab[0];
 | 
				
			||||||
 | 
					    tab[0] = tab[1];
 | 
				
			||||||
 | 
					    tab[1] = tmp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var re_align = /^ *(:?)-+(:?) *$/;
 | 
					    var re_align = /^ *(:?)-+(:?) *$/;
 | 
				
			||||||
    var align = [];
 | 
					    var align = [];
 | 
				
			||||||
    for (var col = 0; col < tab[1].length; col++) {
 | 
					    for (var col = 0; col < tab[1].length; col++) {
 | 
				
			||||||
        var m = tab[1][col].match(re_align);
 | 
					        var m = tab[1][col].match(re_align);
 | 
				
			||||||
        if (!m)
 | 
					        if (!m)
 | 
				
			||||||
            return alert(err + 'invalid column specification, row 2, col ' + (col + 1) + ', [' + tab[1][col] + ']');
 | 
					            return alert(err + 'invalid column specification, row#2, col ' + (col + 1) + ', [' + tab[1][col] + ']');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (m[2]) {
 | 
					        if (m[2]) {
 | 
				
			||||||
            if (m[1])
 | 
					            if (m[1])
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -139,6 +139,10 @@ a newline toplevel
 | 
				
			|||||||
a table | big text in this | aaakbfddd
 | 
					a table | big text in this | aaakbfddd
 | 
				
			||||||
second row | centred | bbb
 | 
					second row | centred | bbb
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					||
 | 
				
			||||||
 | 
					--|--|--
 | 
				
			||||||
 | 
					foo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* list entry
 | 
					* list entry
 | 
				
			||||||
* [x] yes
 | 
					* [x] yes
 | 
				
			||||||
* [ ] no
 | 
					* [ ] no
 | 
				
			||||||
@@ -227,3 +231,7 @@ unrelated neat stuff:
 | 
				
			|||||||
awk '/./ {printf "%s %d\n", $0, NR; next} 1' <test.md >ln.md
 | 
					awk '/./ {printf "%s %d\n", $0, NR; next} 1' <test.md >ln.md
 | 
				
			||||||
gawk '{print gensub(/([a-zA-Z\.])/,NR" \\1","1")}' <test.md >ln.md
 | 
					gawk '{print gensub(/([a-zA-Z\.])/,NR" \\1","1")}' <test.md >ln.md
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					a|b|c
 | 
				
			||||||
 | 
					--|--|--
 | 
				
			||||||
 | 
					foo
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user