Esempio n. 1
0
def websiteHandlerDefault(request):
    try:
        filename = sanitizePath(request["raw-uri"])
        if filename[-1:] == "/": filename += indexfilename

        if filename == "":
            filetype = "text/html"
            meta = {}
            data = websitetemplate.formHeader(
                meta) + websitetemplate.formMainPage(
                    meta) + websitetemplate.formFooter(meta)
        else:
            filetype = workoutMimeType(filename)
            sourcefile = open(homedirectory + filename, "rb", 0)
            data = sourcefile.read()
            sourcefile.close()

            if filetype == "text/cool":
                filetype = "text/html"
                meta = {
                    "title": "." + filename[:-5],
                }
                dirname = string.rsplit("/" + filename, "/", 1)[0]
                #print "Dirname: " + dirname
                try:
                    mymenu = websitetemplate.readMenu(homedirectory +
                                                      dirname[1:] +
                                                      "/menus.xml")
                except IOError:
                    mymenu = []
                meta["extramenus"] = mymenu
                data = websitetemplate.formHeader(
                    meta) + websitetemplate.formMainTableHeader(
                        meta) + data + websitetemplate.formMainTableFooter(
                            meta) + websitetemplate.formFooter(meta)

        resource = {"type": filetype, "statuscode": "200", "data": data}
    except IOError:
        resource = getErrorPage(404)

    return resource
Esempio n. 2
0
def websiteKamaeliaIrcLogs(request):
    def currentDateString():
        curtime = time.gmtime()
        return time.strftime("%d-%m-%Y", curtime)
    
    arg = sanitizeFilename(string.rsplit(request["raw-uri"], "/", 1)[-1])
    meta = { "title" : ".kamaelia.irc" }
    if arg != "": meta["title"] += "." + arg
    
    dirname = string.rsplit("/" + request["raw-uri"], "/", 1)[0]
    #print "Dirname: " + dirname
    try:
        mymenu = websitetemplate.readMenu(homedirectory + "/kamaelia/menus.xml")
    except IOError:
        mymenu = []
    meta["extramenus"] = mymenu

    if arg == "":
        data = u"<h2>#kamaelia IRC channel logs</h2>\n<p>These logs are for the #kamaelia channel on irc.freenode.net</p>"
        datelist = dircache.listdir(homedirectory + "/kamaelia/irc/")
        datedict = {}
        for date in datelist:
            splitdata = date.split(".")[0].split("-")
            if len(splitdata) == 3:
                year = int(splitdata[2])
                month = int(splitdata[1])
                day = int(splitdata[0])
                if not datedict.has_key(year): datedict[year] = {}
                if not datedict[year].has_key(month): datedict[year][month] = {}
                datedict[int(splitdata[2])][int(splitdata[1])][int(splitdata[0])] = date
        monthnames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]
        for year, months in datedict.items():
            data += u"<h3>" + str(year) + u"</h3>\n"
            for month, days in months.items():
                data += u"<h4>" + monthnames[month-1] + u"</h4>\n"
                data += u"<ul style=\"font-size: 120%\">"
                for day, filename in days.items():
                    if filename == currentDateString() + ".txt":
                        data += u"<li><a href=\"/kamaelia/irc-view/" + unicode(filename, "utf-8") + u"\" style=\"color: #55AA22\">" + str(day) + u"</a> (today)</li>"
                    else:
                        data += u"<li><a href=\"/kamaelia/irc-view/" + unicode(filename, "utf-8") + u"\">" + str(day) + u"</a></li>"
                data += u"</ul>"
    
    	data = websitetemplate.formHeader(meta) + websitetemplate.formMainTableHeader(meta) + data + websitetemplate.formMainTableFooter(meta) + websitetemplate.formFooter(meta)
           
        resource = {
            "type" : "text/html",
            "statuscode" : "200",
            "data" : data
        }

    elif arg == "today":
       arg = currentDateString() + ".txt"
    
    if arg != "": #date given
        logsdata = websitetemplate.getIrcLogs(arg)
        if logsdata == 404:
            resource = getErrorPage(404, u"Specified log file not found.")
        else:
            data = u"<h2>#kamaelia IRC channel logs - " + arg + u"</h2><p>This page is also available in <a href=\"/kamaelia/irc/" + arg + u"\">plain text form</a>. All times given are in GMT.</p>\n<p style='font-family: Courier, monospace; font-size: 80%;'>"
            escapeddata = escape(logsdata)
            escapeddata = escapeddata.replace(u"\n", u"<br />\n")
            escapeddata = escapeddata.replace(u"@", u"<img src=\"/at.png\" /><!-->mail.<-->")
            data += escapeddata + u"</p>"
            data = websitetemplate.formHeader(meta) + websitetemplate.formMainTableHeader(meta) + data + websitetemplate.formMainTableFooter(meta) + websitetemplate.formFooter(meta)
            resource = {
                "type" : "text/html",
                "statuscode" : "200",
                "data" : data
            }
    return resource
Esempio n. 3
0
def websiteHandlerDefault(request):
    try:
        filename = sanitizePath(request["raw-uri"])
        if filename[-1:] == "/": filename += indexfilename
        
        if filename == "":
            filetype = "text/html"
            meta = {}
            data = websitetemplate.formHeader(meta) + websitetemplate.formMainPage(meta) + websitetemplate.formFooter(meta)
        else:
            filetype = workoutMimeType(filename)
            sourcefile = open(homedirectory + filename, "rb", 0)
            data = sourcefile.read()
            sourcefile.close()
            
            if filetype == "text/cool":
                filetype = "text/html"
                meta = { "title" : "." + filename[:-5], }
                dirname = string.rsplit("/" + filename, "/", 1)[0]
                #print "Dirname: " + dirname
                try:
                    mymenu = websitetemplate.readMenu(homedirectory + dirname[1:] + "/menus.xml")
                except IOError:
                    mymenu = []
                meta["extramenus"] = mymenu
                data = websitetemplate.formHeader(meta) + websitetemplate.formMainTableHeader(meta) + data + websitetemplate.formMainTableFooter(meta) + websitetemplate.formFooter(meta)
           
        resource = {
            "type" : filetype,
            "statuscode" : "200",
            "data" : data
        }
    except IOError:
        resource = getErrorPage(404)
    
    return resource
Esempio n. 4
0
def websiteKamaeliaIrcLogs(request):
    def currentDateString():
        curtime = time.gmtime()
        return time.strftime("%d-%m-%Y", curtime)

    arg = sanitizeFilename(string.rsplit(request["raw-uri"], "/", 1)[-1])
    meta = {"title": ".kamaelia.irc"}
    if arg != "": meta["title"] += "." + arg

    dirname = string.rsplit("/" + request["raw-uri"], "/", 1)[0]
    #print "Dirname: " + dirname
    try:
        mymenu = websitetemplate.readMenu(homedirectory +
                                          "/kamaelia/menus.xml")
    except IOError:
        mymenu = []
    meta["extramenus"] = mymenu

    if arg == "":
        data = u"<h2>#kamaelia IRC channel logs</h2>\n<p>These logs are for the #kamaelia channel on irc.freenode.net</p>"
        datelist = dircache.listdir(homedirectory + "/kamaelia/irc/")
        datedict = {}
        for date in datelist:
            splitdata = date.split(".")[0].split("-")
            if len(splitdata) == 3:
                year = int(splitdata[2])
                month = int(splitdata[1])
                day = int(splitdata[0])
                if not datedict.has_key(year): datedict[year] = {}
                if not datedict[year].has_key(month):
                    datedict[year][month] = {}
                datedict[int(splitdata[2])][int(splitdata[1])][int(
                    splitdata[0])] = date
        monthnames = [
            "January", "February", "March", "April", "May", "June", "July",
            "August", "September", "October", "November", "December"
        ]
        for year, months in datedict.items():
            data += u"<h3>" + str(year) + u"</h3>\n"
            for month, days in months.items():
                data += u"<h4>" + monthnames[month - 1] + u"</h4>\n"
                data += u"<ul style=\"font-size: 120%\">"
                for day, filename in days.items():
                    if filename == currentDateString() + ".txt":
                        data += u"<li><a href=\"/kamaelia/irc-view/" + unicode(
                            filename,
                            "utf-8") + u"\" style=\"color: #55AA22\">" + str(
                                day) + u"</a> (today)</li>"
                    else:
                        data += u"<li><a href=\"/kamaelia/irc-view/" + unicode(
                            filename,
                            "utf-8") + u"\">" + str(day) + u"</a></li>"
                data += u"</ul>"

        data = websitetemplate.formHeader(
            meta) + websitetemplate.formMainTableHeader(
                meta) + data + websitetemplate.formMainTableFooter(
                    meta) + websitetemplate.formFooter(meta)

        resource = {"type": "text/html", "statuscode": "200", "data": data}

    elif arg == "today":
        arg = currentDateString() + ".txt"

    if arg != "":  #date given
        logsdata = websitetemplate.getIrcLogs(arg)
        if logsdata == 404:
            resource = getErrorPage(404, u"Specified log file not found.")
        else:
            data = u"<h2>#kamaelia IRC channel logs - " + arg + u"</h2><p>This page is also available in <a href=\"/kamaelia/irc/" + arg + u"\">plain text form</a>. All times given are in GMT.</p>\n<p style='font-family: Courier, monospace; font-size: 80%;'>"
            escapeddata = escape(logsdata)
            escapeddata = escapeddata.replace(u"\n", u"<br />\n")
            escapeddata = escapeddata.replace(
                u"@", u"<img src=\"/at.png\" /><!-->mail.<-->")
            data += escapeddata + u"</p>"
            data = websitetemplate.formHeader(
                meta) + websitetemplate.formMainTableHeader(
                    meta) + data + websitetemplate.formMainTableFooter(
                        meta) + websitetemplate.formFooter(meta)
            resource = {"type": "text/html", "statuscode": "200", "data": data}
    return resource