Beispiel #1
0
def SaveUploadedFile(form):
	if not CheckFields(form, ["filename", "username", "password"]):
		return "Missing formdata"
	username = form.getvalue("username")
	password = form.getvalue("password")
	accountid = CheckAuth(username, password)
	if not accountid:
		return "Invalid Username or Password"
	fileitem = form["filename"]
	if not fileitem.file:
		return "Missing file form"

	tmpdir = "/tmp/springfiles-upload"
	os.makedirs(tmpdir, exist_ok=True)


	from lib import upqconfig
	cfg = upqconfig.UpqConfig()
	for path in [cfg.paths["files"], tmpdir]:
		total, used, free = shutil.disk_usage(path)
		if free < 5 * 1024 * 1024 * 1024:
			return "To few disk space available: %d MiB in %s" %(free / (1024 * 1024), path)

	filename = save_uploaded_file(fileitem, tmpdir)
	if not filename:
		return "Couldn't store file"

	assert(accountid > 0)
	output =  ParseAndAddFile(filename, accountid, cfg)
	return output
Beispiel #2
0
#!/usr/bin/env python3

# This file is part of the "upq" program used on springfiles.springrts.com to manage file
# uploads, mirror distribution etc. It is published under the GPLv3.
#
#Copyright (C) 2011 Matthias Ableitner (spring #at# abma #dot# de)
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.

# sf-sync: syncs file data with springfiles
# can be either initiaded by an updated file
# or maybe by the xml-rpc interface (or cron?)

from lib import log, upqconfig, upqdb, versionfetch

import sys
import json
import os

cfg = upqconfig.UpqConfig()
db = upqdb.UpqDB(cfg.db['url'], cfg.db['debug'])
versionfetch.Versionfetch(cfg, db)
Beispiel #3
0
def GetResult(request):
    cfg = upqconfig.UpqConfig()
    db = upqdb.UpqDB(cfg.db['url'], cfg.db['debug'])
    wherecond = ""

    if "logical" in request and request["logical"] == "or":
        logical = " OR "
    else:
        logical = " AND "

    if "nosensitive" in request:
        binary = ""
    else:
        binary = "BINARY"

    conditions = {
        "tag": "t.tag LIKE {binary} '{tag}'",
        "filename": "f.filename LIKE {binary} '{filename}'",
        "category": "c.name LIKE {binary} '{category}'",
        "name": "f.name LIKE {binary} '{name}'",
        "version": "f.version LIKE {binary}'{version}'",
        "sdp": "f.sdp LIKE {binary} '{sdp}'",
        # FIXME: concat is really slow!
        "springname":
        "((f.name LIKE {binary} '{springname}' OR f.version LIKE {binary} '{springname}') OR (CONCAT(f.name,' ',f.version) LIKE {binary} '{springname}'))",
        "md5": "f.md5 = '{md5}'",
    }

    wheres = []
    for tag, condition in conditions.items():
        wheres += GetQuery(request, binary, tag, condition)

    wherecond = logical.join(wheres)
    if wherecond:
        wherecond = " AND " + wherecond

    #print(wherecond)
    rows = db.query("""SELECT
	distinct(f.fid) as fid,
	f.name as name,
	f.filename as filename,
	f.path as path,
	f.md5 as md5,
	f.sdp as sdp,
	f.version as version,
	LOWER(c.name) as category,
	f.size as size,
	f.timestamp as timestamp,
	f.metadata as metadata
	FROM file as f
	LEFT JOIN categories as c ON f.cid=c.cid
	LEFT JOIN tag as t ON  f.fid=t.fid
	WHERE c.cid>0
	AND f.status=1
	%s
	ORDER BY f.timestamp DESC
	%s
	""" % (wherecond, getlimit(request)))

    clientres = []
    for row in rows:
        d = dict(row)
        #inject local file as mirror
        if d["category"] in ["game", "map"]:
            d["mirrors"] = [
                "https://springfiles.springrts.com/files/" + d["path"] + "/" +
                d["filename"]
            ]
        else:
            d["mirrors"] = []

        d["mirrors"] += GetMirrors(db, d["fid"])
        #print(mirrors)
        #print(row)

        try:
            d["metadata"] = json.loads(d["metadata"]) if d["metadata"] else {}
        except json.decoder.JSONDecodeError:
            d["metadata"] = ""
        if "images" in request:
            for k in ["splash", "mapimages"]:
                if k in d["metadata"]:
                    d[k] = GetMetadataPaths(d["metadata"][k])
                    del (d["metadata"][k])

        if not "metadata" in request:
            del (d["metadata"])

        #if "splash" in request:
        #if "images" in request:

        #json.dumps(row)
        d["tags"] = GetTags(db, d["fid"])
        del (d["fid"])
        if d["timestamp"]:
            d["timestamp"] = d["timestamp"].isoformat()

        if d["version"] == "":
            d["springname"] = d["name"]
        else:
            d["springname"] = d["name"] + " " + d["version"]

        clientres.append(d)

    return clientres