Beispiel #1
0
    def handleException(self, trans, exceptionType, exception, tb):
        plainTextMessage = u"""On request: {0} {1}
the following exception occured at {2}:

""".format(trans.get_request_method(), trans.get_path(),
           TimeUtils.nowDate().isoformat())
        plainTextMessage += self.generatePlainTextMessage(
            trans, exceptionType, exception, tb)
        print(plainTextMessage.encode("utf-8"))

        if "mail-to" in errors:
            try:
                mailConfig = errors["mail-to"]
                subject = mailConfig["subject"].format(exceptionType.__name__,
                                                       unicode(exception))
                to = mailConfig["to"]
                sender = mailConfig["sender"]
                smtp = mailConfig["smtp"]

                mail = MIMEText(plainTextMessage.encode("utf-8"),
                                _charset="utf-8")
                mail["Subject"] = subject
                mail["To"] = ",".join(to)
                mail["From"] = sender
                mail["Date"] = self.model.formatHTTPTimestamp(TimeUtils.now())

                host = smtp["host"]
                port = int(smtp.get("port", 25))
                user = smtp.get("user", None)
                password = smtp.get("password", None)
                secure = smtp.get("secure", None)
                if not secure in ["starttls", "ssl"]:
                    raise ValueError(
                        "Invalid value for secure: {0}".format(secure))
                if secure == "ssl":
                    conn = smtplib.SMTP_SSL(host, port)
                else:
                    conn = smtplib.SMTP(host, port)
                    if secure == "starttls":
                        conn.starttls()
                if user is not None and password is not None:
                    conn.login(user, password)
                conn.sendmail(mail["From"], mail["To"], mail.as_string())
                conn.quit()
            except Exception as e:
                print("Could not send exception mail: {0}".format(e))

        trans.rollback()
        trans.set_response_code(500)
        self.out = trans.get_response_stream()
        trans.set_content_type(ContentType("text/html", "utf-8"))

        s = u"""
<html>
    <head>
        <title>Priyom.org internal API error</title>
        <link rel="stylesheet" type="text/css" href="{0}"/>
    </head>
    <body>
        <h1>Internal API error</h1>""".format(
            application.get("urlroot", u"") + u"/css/error.css")
        if self.show:
            s += u"""
        <h2>Error information</h2>
        <dl class="exc-info">
            <dt>Exception class:</dt>
            <dd>{1}</dd>
            <dt>Message:</dt>
            <dd>{2}</dd>
        </dl>
        <h2>Stacktrace</h2>
        <p>(most recent call last)</p>
        <ul>{0}</ul>""".format(
                u"\n".join((
                    u"""<li><div class="tb-item-head">File &quot;<span class="tb-file">{0}</span>&quot;, line <span class="tb-lineno">{1:d}</span>, in <span class="tb-func">{2}</span></div><div class="tb-item-code">{3}</div>"""
                    .format(
                        escape(os.path.relpath(filename, application["root"])),
                        lineno, escape(funcname), escape(text))
                    for (filename, lineno, funcname,
                         text) in traceback.extract_tb(tb))),
                escape(unicode(exceptionType)),
                escape(unicode(exception)).replace("\n", "<br/>"))

        else:
            s += u"""
        <p>An internal error has occured. Please report this to <a href="mailto:{0}">{1}</a></p>""".format(
                admin["mail"], admin["name"])

        s += u"""
    </body>
</html>"""
        print >> self.out, s.encode("utf-8")
Beispiel #2
0
 def rootPath(self, rootPath):
     if len(rootPath) > 0 and rootPath[0] != u"/":
         return application.get("urlroot", u"") + u"/" + rootPath
     else:
         return application.get("urlroot", u"") + rootPath
Beispiel #3
0
 def rootPath(self, rootPath):
     if len(rootPath) > 0 and rootPath[0] != u"/":
         return application.get("urlroot", u"") + u"/" + rootPath
     else:
         return application.get("urlroot", u"") + rootPath
Beispiel #4
0
the GNU General Public license (the  "GPL License"), in which case  the
provisions of GPL License are applicable instead of those above.

FEEDBACK & QUESTIONS

For feedback and questions about priyomdb please e-mail one of the
authors:
    Jonas Wielicki <*****@*****.**>
"""
import sys, os
sys.path.append('/etc/priyomdb/')
from cfg_priyomhttpd import application, database
sys.path.append(application["root"])
import os
import os.path
mplconfig = application.get("mplconfigdir", u"{0}/runtime/mpl").format(application["root"])
os.environ["MPLCONFIGDIR"] = mplconfig
if not os.path.isdir(mplconfig):
    os.makedirs(mplconfig)
plots = application.get("plotdir", u"{0}/runtime/plots").format(application["root"])
if not os.path.isdir(plots):
    os.makedirs(plots)
application["mplconfigdir"] = mplconfig
application["plots"] = plots

import storm
from storm.locals import *

import WebStack
from WebStack.Adapters.WSGI import WSGIAdapter
Beispiel #5
0
the GNU General Public license (the  "GPL License"), in which case  the
provisions of GPL License are applicable instead of those above.

FEEDBACK & QUESTIONS

For feedback and questions about priyomdb please e-mail one of the
authors:
    Jonas Wielicki <*****@*****.**>
"""
import sys, os
sys.path.append('/etc/priyomdb/')
from cfg_priyomhttpd import application, database
sys.path.append(application["root"])
import os
import os.path
mplconfig = application.get("mplconfigdir",
                            u"{0}/runtime/mpl").format(application["root"])
os.environ["MPLCONFIGDIR"] = mplconfig
if not os.path.isdir(mplconfig):
    os.makedirs(mplconfig)
plots = application.get("plotdir",
                        u"{0}/runtime/plots").format(application["root"])
if not os.path.isdir(plots):
    os.makedirs(plots)
application["mplconfigdir"] = mplconfig
application["plots"] = plots

import storm
from storm.locals import *

import WebStack
from WebStack.Adapters.WSGI import WSGIAdapter
Beispiel #6
0
    def handleException(self, trans, exceptionType, exception, tb):
        plainTextMessage = u"""On request: {0} {1}
the following exception occured at {2}:

""".format(trans.get_request_method(), trans.get_path(), TimeUtils.nowDate().isoformat())
        plainTextMessage += self.generatePlainTextMessage(trans, exceptionType, exception, tb)
        print(plainTextMessage.encode("utf-8"))
        
        if "mail-to" in errors:
            try:
                mailConfig = errors["mail-to"]
                subject = mailConfig["subject"].format(exceptionType.__name__, unicode(exception))
                to = mailConfig["to"]
                sender = mailConfig["sender"]
                smtp = mailConfig["smtp"]
                
                mail = MIMEText(plainTextMessage.encode("utf-8"), _charset="utf-8")
                mail["Subject"] = subject
                mail["To"] = ",".join(to)
                mail["From"] = sender
                mail["Date"] = self.model.formatHTTPTimestamp(TimeUtils.now())
                
                host = smtp["host"]
                port = int(smtp.get("port", 25))
                user = smtp.get("user", None)
                password = smtp.get("password", None)
                secure = smtp.get("secure", None)
                if not secure in ["starttls", "ssl"]:
                    raise ValueError("Invalid value for secure: {0}".format(secure))
                if secure == "ssl":
                    conn = smtplib.SMTP_SSL(host, port)
                else:
                    conn = smtplib.SMTP(host, port)
                    if secure == "starttls":
                        conn.starttls()
                if user is not None and password is not None:
                    conn.login(user, password)
                conn.sendmail(mail["From"], mail["To"], mail.as_string())
                conn.quit()
            except Exception as e :
                print("Could not send exception mail: {0}".format(e))
        
        trans.rollback()
        trans.set_response_code(500)
        self.out = trans.get_response_stream()
        trans.set_content_type(ContentType("text/html", "utf-8"))

        s = u"""
<html>
    <head>
        <title>Priyom.org internal API error</title>
        <link rel="stylesheet" type="text/css" href="{0}"/>
    </head>
    <body>
        <h1>Internal API error</h1>""".format(application.get("urlroot", u"") + u"/css/error.css")
        if self.show:
            s += u"""
        <h2>Error information</h2>
        <dl class="exc-info">
            <dt>Exception class:</dt>
            <dd>{1}</dd>
            <dt>Message:</dt>
            <dd>{2}</dd>
        </dl>
        <h2>Stacktrace</h2>
        <p>(most recent call last)</p>
        <ul>{0}</ul>""".format(
                u"\n".join((u"""<li><div class="tb-item-head">File &quot;<span class="tb-file">{0}</span>&quot;, line <span class="tb-lineno">{1:d}</span>, in <span class="tb-func">{2}</span></div><div class="tb-item-code">{3}</div>""".format(escape(os.path.relpath(filename, application["root"])), lineno, escape(funcname), escape(text)) for (filename, lineno, funcname, text) in traceback.extract_tb(tb))), 
                
                escape(unicode(exceptionType)),
                escape(unicode(exception)).replace("\n", "<br/>")
            )
                
        else:
            s += u"""
        <p>An internal error has occured. Please report this to <a href="mailto:{0}">{1}</a></p>""".format(admin["mail"], admin["name"])
            
        s += u"""
    </body>
</html>"""
        print >>self.out, s.encode("utf-8")