コード例 #1
0
def action(req, fields):
    req.write(InstDB.header("Edit profile"))

    if not InstDB.AssertLogin(req):
        req.write(InstDB.footer())
        return

    itemCells = UsersHelper.edit_cell_format
    itemFields = InstDB.cells_to_fields(itemCells)

    errmsg = None

    # Was Save button clicked? - Update field values
    if fields.get("Save", None):
        data = fields

        password = fields.get("Password", "")
        verify = fields.get("PassVerify", "")
        email = fields.get("UserEmail", "")

        if len(password) > 0 and len(password) < 5:
            errmsg = "Passwords must be 5-32 characters, leave blank for no change"

        if not errmsg and password != verify:
            errmsg = "Password and Verify don't match"

        if not errmsg:
            n = string.find(email, "@")
            n2 = string.find(email, " ")
            if n <= 0 or n == len(email) - 1 or n2 >= 0:
                errmsg = "A valid email address is required"

        if not errmsg:
            update = UsersHelper.sql_update(itemFields, fields)

            if password:                update.setnesc["Password"] = '******' \
       % MySQLdb.escape_string (password + InstDB.FuKraXor)

            update.where = ("UserId=%d" % InstDB.User["UserId"], )

            # Use login if UserName not set
            if not fields.get("UserName", None):
                update.setnesc["UserName"] = "******"
                if update.set.get("UserName"): del update.set["UserName"]

            InstDB.Cur.execute(update.query())
            req.write("<font size=+1>User profile updated</font>\n<p>\n")
        else:
            req.write('<font class="error">%s</font><p>\n' % errmsg)
    else:  # First page load?
        sel = UsersHelper.sql_select(itemFields)
        sel.where.insert(0, "UserId=%d" % InstDB.User["UserId"])
        InstDB.Cur.execute(sel.query())
        data = InstDB.Cur.fetchone()

    tab = (("Password", "<input type=password name=Password>"),
           ("Verify", "<input type=password name=PassVerify>"))
    tab += tuple(UsersHelper.form_cell_vals(itemCells, data))
    tab += (("<input type=submit name=Save value=\"Save\">\n", ), )

    # Display form
    box = InstDB.html_box()
    req.write(box.start("User Profile"))
    req.write(
        "<table border=0 cellpadding=8>\n<tr>\n<td valign=top bgcolor=#408ee6>\n"
    )
    req.write("<form action=\"patches.py?Action=profile\" method=POST>\n")

    split = InstDB.tabsplits(tab)
    req.write(split.render())

    req.write("</form>\n")
    req.write("</td>\n<td valign=top>\n")

    req.write("<vr>\n</td>\n<td valign=top>\n")

    req.write(InstDB.IncFile("profile.inc"))

    req.write("</td>\n</tr>\n</table>\n")
    req.write(box.end())

    req.write(InstDB.footer())
コード例 #2
0
def action(req, fields):
    req.write(InstDB.header("Patch submission"))

    if not InstDB.AssertLogin(req):
        req.write(InstDB.footer())
        return

    req.write("""
Upload files to <a href="ftp://sounds.resonance.org/incoming/">ftp://sounds.resonance.org/incoming/</a>.
It is recommended that you read the <a href="patches.py?Action=help&amp;Topic=submit">Content Submission Help</a>.
<p>
""")

    # Check if any incoming files have been selected
    Files = fields.getlist("Files")
    for fname in Files:
        (evil, fname) = os.path.split(fname)  # Make sure no path of evil

        if not os.path.isfile(InstDB.IncomingPath + os.sep + fname):
            InstDB.error(req, "File not found '%s'" % cgi.escape(fname))
        else:
            # Create new import queue task (don't activate yet)
            InstDB.Cur.execute(
                "INSERT INTO Queue"
                " (Type, Status, FileName, UserId)"
                " VALUES ('Import', 'Queued', %s, %s)",
                (fname, InstDB.User["UserId"]))

    # Get list of files in incoming directory
    file_list = os.listdir(InstDB.IncomingPath)
    file_list.sort()

    box = InstDB.html_box()
    box.tableattr = 'width="100%"'
    req.write(box.start("Incoming files"))

    req.write("<form action=\"patches.py?Action=submit\" method=POST>\n")

    if file_list:
        table = InstDB.tabular(("Import", "File", "Size", "Date"))
        table.tableattr = 'width="100%"'

        for file in file_list:
            check = "<input type=checkbox name=Files value=\"%s\">" \
                    % cgi.escape (file)
            stats = os.stat(InstDB.IncomingPath + "/" + file)
            req.write(
                table.addrow((check, cgi.escape(file),
                              InstDB.pretty_size(stats.st_size),
                              time.ctime(stats.st_mtime))))
        req.write(table.end())

    else:
        req.write("<b>No files in incoming directory</b><br>\n")

    req.write(box.end())

    req.write("<center><input type=submit name=FileSelect"
              " value=\"Import and/or Refresh\"></center>\n")
    req.write("</form>\n")

    req.write("<p><p>\n")

    # Get queued tasks

    box = InstDB.html_box()
    box.tableattr = 'width="100%"'
    req.write(box.start("Your queued tasks"))

    sel = SqlHelpers.Select()
    sel.fields = ("QueueId", "Type", "Status", "UserId", "FileName", "Date")
    sel.tables = ("Queue", )
    sel.where = ("Type in ('Import','Activate')", )
    sel.orderby = "QueueId"

    InstDB.Cur.execute(sel.query())

    table = InstDB.tabular(
        ("Position", "File Name", "Action", "Status", "Start Time"))
    table.tableattr = 'width="100%"'

    index = 0
    any = False
    for row in InstDB.Cur.fetchall():
        if row["UserId"] == InstDB.User["UserId"]:
            any = True

            if row["Status"] != "Error":
                ndxval = index
                status = row["Status"]
            else:
                ndxval = "N/A"
                status = '<font class="Error">' + row["Status"] + '</font>'

            req.write(
                table.addrow((ndxval, cgi.escape(row["FileName"]), row["Type"],
                              status, row["Date"])))
        if row["Status"] != "Error":
            index += 1

    if any: req.write(table.end())
    else: req.write("<b>No queued tasks</b><br>\n")

    req.write(box.end())
    req.write("<p><p>\n")

    # Any activation form data submitted?  Group fields by patch ID.
    patchFields = {}
    if fields.get("Activate", None):
        for field in fields.list:
            # Fields have "P<PatchId>_" prefix
            match = re.match("P([0-9]{1,10})_(.+)", field.name)
            if match:
                patchId = match.group(1)
                if not patchFields.get(patchId, None):
                    patchFields[patchId] = {}

                patchFields[patchId][match.group(2)] = fields[field.name]

    # Files pending activation

    box = InstDB.html_box()
    box.tableattr = 'width="100%"'
    req.write(box.start("Files pending activation"))

    InstDB.Cur.execute(
        "SELECT PatchId, PatchType FROM PatchInfo"
        " WHERE UserId=%s && State='Imported'", InstDB.User["UserId"])
    pendRows = InstDB.Cur.fetchall()

    if pendRows:
        activateCells = PatchHelper.edit_cell_format
        activateFields = InstDB.cells_to_fields(activateCells)
    displayedOne = False

    for pendRow in pendRows:
        pFields = patchFields.get(str(pendRow["PatchId"]), None)
        patchId = int(pendRow["PatchId"])
        activate = pFields and pFields.get("Activate", None)
        errorMsg = ""

        if pFields:  # Form data submitted for this patch?
            pFields["FileName"] = pFields["FileName"].strip()
            if not pFields["FileName"]:
                errorMsg = "File name is required"

            # Check if filename already used
            if not errorMsg:
                InstDB.Cur.execute(
                    "SELECT COUNT(*) AS count FROM PatchInfo"
                    " WHERE PatchId != %s && FileName=%s"
                    " && PatchType=%s",
                    (patchId, pFields["FileName"], pendRow["PatchType"]))
                if int(InstDB.Cur.fetchone()["count"]) > 0:
                    errorMsg = "File name already in use"

        if pFields:
            update = PatchHelper.sql_update(activateFields, pFields)
            update.set["FileName"] = pFields["FileName"]
            update.where = ("PatchInfo.PatchId=%d" % patchId, )
            if activate and not errorMsg: update.set["State"] = "Activating"

            InstDB.Cur.execute(update.query())
            props_update(patchId, pFields)  # Update extra properties

            # Queue activation task
            if activate and not errorMsg:
                InstDB.Cur.execute(
                    "INSERT INTO Queue"
                    " (Type, Status, UserId, ItemId, FileName)"
                    " VALUES ('Activate', 'Queued', %s, %s, %s)",
                    (InstDB.User["UserId"], patchId, "%s.%s" %
                     (pFields["FileName"], pendRow["PatchType"])))

        if (not activate or errorMsg) and not displayedOne:
            req.write(
                "<form action=\"patches.py?Action=submit\" method=POST>\n")
            displayedOne = True

        if errorMsg:
            req.write('<font class="error">%s</font><br>\n' %
                      cgi.escape(errorMsg))

        if not activate or errorMsg:
            sel = PatchHelper.sql_select(activateFields)
            sel.fields.insert(0, "PatchInfo.PatchId")
            sel.where.insert(0, "PatchInfo.PatchId=%d" % patchId)
            InstDB.Cur.execute(sel.query())
            row = InstDB.Cur.fetchone()
            display_patch(req, row, pFields)

    if displayedOne:
        req.write("<input type=submit name=Activate" " value=\"Update\">\n")
        req.write("</form>\n")
    else:
        req.write("<b>No files pending activation</b><br>\n")

    req.write(box.end())
    req.write(InstDB.footer())