Пример #1
0
def connect():
    global conn
    hostname = "{0}.mit.edu".format(LDAP_SERVERS[random.randint(0, 2)])
    conn = ldap.initialize("ldap://{0}".format(hostname))
    # Only try to use the keytab if we have one
    if keytab.exists():
        keytab.auth()
        auth = ldap.sasl.gssapi()
        conn.sasl_interactive_bind_s("", auth)
    else:
        conn.simple_bind_s()
Пример #2
0
def handle_mail():

    message = email.message_from_file(sys.stdin)

    if keytab.exists():
        keytab.auth()

    if ('subject' not in message or 'delivered-to' not in message
            or 'from' not in message):
        return

    ID_PATTERN = re.compile(r'pony\+(\d+)\@')
    toname, to = parseaddr(
        unicode(make_header(decode_header(message['delivered-to']))))
    m = ID_PATTERN.search(to)
    if m is None:
        return
    id = int(m.group(1))

    byname, by = parseaddr(unicode(make_header(decode_header(
        message['from']))))
    by = by.lower()
    if by.endswith(u'@mit.edu'):
        by = by[:-len(u'@mit.edu')]

    t = queue.Ticket.get(id)

    RTID_PATTERN = re.compile(r'\[help.mit.edu\s+\#(\d+)\]')
    subject = unicode(make_header(decode_header(message['subject'])))
    m = RTID_PATTERN.search(subject)
    if m:
        if t.rtid is None:
            by = u'rt'
        t.rtid = int(m.group(1))

    newstate = t.state
    # TODO: blanche accounts-internal
    if by in (u'aswayze', u'bowser', u'jtravers', u'kwitt', u'mannys',
              u'mwollman', u'ovidio', u'thorn'):
        newstate = u'dns'
    body = u''
    for part in message.walk():
        if (part.get_content_maintype() == 'text'):
            body += unicode(part.get_payload(decode=True),
                            part.get_content_charset('us-ascii'))
    t.addEvent(type=u'mail',
               state=newstate,
               by=by,
               target=u'us',
               subject=subject,
               body=body)

    transaction.commit()
Пример #3
0
def check_dns():
    if keytab.exists():
        keytab.auth()

    # Use a list so all the ids are resolved early and transactions aren't
    # a problem
    for tid in [t.id for t in queue.Ticket.query.filter_by(state=u'dns')]:
        t = queue.Ticket.get(tid)

        if hosts.points_at_scripts(t.hostname):
            path = '/mit/%s/web_scripts/%s' % (
                t.locker, vhosts.get_path(t.locker, t.hostname))
            wordpress = "This site looks like a WordPress blog; for the new URL to work properly, you'll need to access the WordPress admin interface via your old URL, go to General Settings, and change the WordPress address and Blog address to 'http://%s'." % t.hostname

            # Try to figure out what's up with the hostname currently
            try:
                page = urllib2.urlopen('http://%s/' % t.hostname)
                content = page.read()
                if ('<meta name="generator" content="WordPress' in content
                        or 'wp-login' in page.geturl()):
                    sitestatus = wordpress
                else:
                    sitestatus = "Your site appears to be working properly.  Have fun!"
            except urllib2.HTTPError, e:
                if 'wp-login' in e.geturl():
                    sitestatus = wordpress
                elif e.code == 404:
                    sitestatus = "There doesn't seem to be any content currently at %s; make sure that directory exists and has an index.html, index.cgi, or similar, or change this hostname to point somewhere else at http://pony.scripts.mit.edu." % path
                elif e.code == 403:
                    sitestatus = "Visiting that page yields a Forbidden error; this is often caused by a lack of valid content at %s.  Putting an index.html, index.cgi, or similar there may solve this.  Alternately, you may just have your site password-protected or cert-protected." % path
                elif e.code == 401:
                    sitestatus = "Visiting that page yields an Unauthorized error.  This generally means that you have your site password-protected or cert-protected, so we can't confirm whether it's working."
                else:
                    sitestatus = "Visiting that page yields a %s error, suggesting a problem with the content at %s.  Email us at [email protected] if you need help resolving this." % (
                        e.code, path)

            subject = u"Re: Request for hostname %s" % t.hostname
            body = u"""Hello,

Just wanted to let you know that the hostname %(hostname)s is now configured and working.  It currently points to %(path)s.  Visit http://%(hostname)s/ to check it out.

%(sitestatus)s

Let us know if you run into any issues.

~The SIPB Scripts Team
http://scripts.mit.edu/

/set status=resolved
""" % dict(hostname=t.hostname,
            locker=t.locker,
            path=path,
            sitestatus=sitestatus)
            mail.send_correspondence(subject, body, rtid=t.rtid)
            t.addEvent(type=u'mail',
                       state=u'resolved',
                       by=u'dns',
                       target=u'user',
                       subject=subject,
                       body=body)

            transaction.commit()
Пример #4
0
def handle_mail():

    message = email.message_from_file(sys.stdin)

    if keytab.exists():
        keytab.auth()

    if (
        "subject" not in message
        or "delivered-to" not in message
        or "from" not in message
    ):
        return

    ID_PATTERN = re.compile(r"pony\+(\d+)\@")
    toname, to = parseaddr(unicode(make_header(decode_header(message["delivered-to"]))))
    m = ID_PATTERN.search(to)
    if m is None:
        t = None
    else:
        t = queue.Ticket.get(int(m.group(1)))

    byname, by = parseaddr(unicode(make_header(decode_header(message["from"]))))
    by = by.lower()
    if by.endswith(u"@mit.edu"):
        by = by[: -len(u"@mit.edu")]

    RTID_PATTERN = re.compile(r"\[help.mit.edu\s+\#(\d+)\]")
    subject = unicode(make_header(decode_header(message["subject"])))
    m = RTID_PATTERN.search(subject)
    if m:
        rtid = int(m.group(1))
        if t is None:
            t = queue.Ticket.query.filter_by(rtid=rtid).one()
        else:
            if t.rtid is None:
                by = u"rt"
            t.rtid = rtid

    newstate = t.state
    # TODO: blanche accounts-internal
    if by in (
        u"aswayze",
        u"bowser",
        u"jtravers",
        u"kwitt",
        u"mannys",
        u"mwollman",
        u"ovidio",
        u"thorn",
    ):
        newstate = u"dns"
    body = u""
    for part in message.walk():
        if part.get_content_maintype() == "text":
            body += unicode(
                part.get_payload(decode=True), part.get_content_charset("us-ascii")
            )
    t.addEvent(
        type=u"mail", state=newstate, by=by, target=u"us", subject=subject, body=body
    )

    transaction.commit()