Ejemplo n.º 1
0
 def edit(self, locker, hostname, path=None, token=None, alias=''):
     if pylons.request.response_ext:
         hostname += pylons.request.response_ext
     if path is not None:
         if token != auth.token():
             flash("Invalid token!")
         else:
             try:
                 vhosts.set_path(locker, hostname, path)
             except vhosts.UserError, e:
                 flash(e.message)
             else:
                 flash("Host '%s' reconfigured." % hostname)
                 redirect('/index/' + locker)
Ejemplo n.º 2
0
    def reject(self, id, subject=None, body=None, token=None, silent=False):
        t = queue.Ticket.get(int(id))
        if t.state != 'open':
            flash("This ticket's not open!")
            redirect('/ticket/%s' % id)
        if t.rtid is None:
            flash("This ticket has no RT ID!")
            redirect('/ticket/%s' % id)
        if (subject and body) or silent:
            if token != auth.token():
                flash("Invalid token!")
            else:
                # Send mail and records it as an event
                if not silent:
                    mail.send_correspondence(subject, body, t.rtid,
                                             auth.current_user())
                    t.addEvent(type=u'mail',
                               state=u'rejected',
                               target=u'user',
                               subject=subject,
                               body=body)
                    flash("Ticket rejected; mail sent to user.")
                else:
                    mail.send_comment(subject,
                                      "Ticket rejected silently.\n\n" + body,
                                      t.id, t.rtid, auth.current_user())
                    t.addEvent(type=u'mail',
                               state=u'rejected',
                               target=u'rt',
                               subject=subject,
                               body=body)
                    flash("Ticket rejected silently.")
                redirect('/queue')
        return dict(tickets=[t],
                    action=url('/reject/%s' % id),
                    subject="Re: Request for hostname %s" % t.hostname,
                    body="""Hello,

Unfortunately, the hostname %(hostname)s is not available.  You can go to http://pony.scripts.mit.edu/ to request a different one.

Sorry for the inconvenience,
-%(first)s

/set status=rejected
""" % dict(hostname=t.hostname, first=auth.first_name()),
                    submit='Send to %s' % t.requestor,
                    extra_buttons={'silent': 'Send as Comment'})
Ejemplo n.º 3
0
 def new(self,
         locker,
         hostname='',
         path='',
         desc='',
         token=None,
         confirmed=False,
         personal_ok=False,
         requestor=None):
     personal = locker == auth.current_user()
     if confirmed:
         auth.scripts_team_sudo()
     else:
         requestor = None
     if pylons.request.response_ext:
         locker += pylons.request.response_ext
     if hostname:
         if token != auth.token():
             flash("Invalid token!")
         elif not desc and not confirmed:
             flash("Please specify the purpose of this hostname.")
         elif requestor is not None and not requestor.strip():
             flash("Please specify requestor.")
         elif personal and not personal_ok:
             flash(
                 "Please acknowledge that your hostname will be served from your personal locker and will be deleted when you leave MIT."
             )
         else:
             try:
                 status = vhosts.request_vhost(locker,
                                               hostname,
                                               path,
                                               user=requestor,
                                               desc=desc)
             except vhosts.UserError, e:
                 flash(e.message)
             else:
                 flash(status)
                 if confirmed:
                     redirect('/queue')
                 else:
                     redirect('/index/' + locker)
Ejemplo n.º 4
0
 def delete(self, locker, hostname, confirm=False, token=None):
     if request.response_ext:
         hostname += request.response_ext
     if confirm:
         if token != auth.token():
             flash("Invalid token!")
         else:
             try:
                 vhosts.delete(locker, hostname)
             except vhosts.UserError as e:
                 flash(e.message)
             else:
                 flash("Host '%s' deleted." % hostname)
                 redirect("/index/" + locker)
         _, aliases = vhosts.get_vhost_info(locker, hostname)
     else:
         try:
             path, aliases = vhosts.get_vhost_info(locker, hostname)
         except vhosts.UserError as e:
             flash(e.message)
             redirect("/index/" + locker)
     return dict(locker=locker, hostname=hostname, path=path, aliases=aliases)
Ejemplo n.º 5
0
 def approve(self, id, subject=None, body=None, token=None, silent=False):
     t = queue.Ticket.get(int(id))
     if t.state != 'open':
         flash("This ticket's not open!")
         redirect('/ticket/%s' % id)
     if t.rtid is None:
         flash("This ticket has no RT ID!")
         redirect('/ticket/%s' % id)
     if subject and body:
         if token != auth.token():
             flash("Invalid token!")
         else:
             try:
                 vhosts.actually_create_vhost(t.locker, t.hostname, t.path)
             except vhosts.UserError, e:
                 flash(e.message)
             else:
                 if not silent:
                     # Send mail and records it as an event
                     mail.send_comment(subject, body, t.id, t.rtid,
                                       auth.current_user(),
                                       'accounts-internal')
                     t.addEvent(type='mail',
                                state='moira',
                                target='accounts-internal',
                                subject=subject,
                                body=body)
                     flash(
                         "Ticket approved; mail sent to accounts-internal.")
                 else:
                     mail.send_comment(
                         subject, "Ticket approved silently.\n\n" + body,
                         t.id, t.rtid, auth.current_user())
                     t.addEvent(type='mail', state='dns', target='us')
                     flash("Ticket approved silently.")
                 redirect('/queue')
Ejemplo n.º 6
0
 def new(self,
         locker,
         hostname='',
         path='',
         desc='',
         token=None,
         confirmed=False,
         requestor=None):
     if confirmed:
         auth.scripts_team_sudo()
     else:
         requestor = None
     if pylons.request.response_ext:
         locker += pylons.request.response_ext
     if hostname:
         if token != auth.token():
             flash("Invalid token!")
         elif not desc and not confirmed:
             flash("Please specify the purpose of this hostname.")
         elif requestor is not None and not requestor.strip():
             flash("Please specify requestor.")
         else:
             try:
                 status = vhosts.request_vhost(locker,
                                               hostname,
                                               path,
                                               user=requestor,
                                               desc=desc)
             except vhosts.UserError, e:
                 flash(e.message)
             else:
                 flash(status)
                 if confirmed:
                     redirect('/queue')
                 else:
                     redirect('/index/' + locker)
Ejemplo n.º 7
0
    def approve(self, id, subject=None, body=None, token=None, silent=False):
        t = queue.Ticket.get(int(id))
        if t.state != "open":
            flash("This ticket's not open!")
            redirect("/ticket/%s" % id)
        if t.rtid is None:
            flash("This ticket has no RT ID!")
            redirect("/ticket/%s" % id)
        if subject and body:
            if token != auth.token():
                flash("Invalid token!")
            else:
                try:
                    vhosts.actually_create_vhost(t.locker, t.hostname, t.path)
                except vhosts.UserError as e:
                    flash(e.message)
                else:
                    if not silent:
                        # Send mail and records it as an event
                        rt.call(
                            "ticket/%d/comment" % (t.rtid,),
                            Action="comment",
                            Text=body,
                            Cc="*****@*****.**",
                        )

                        t.addEvent(
                            type="mail",
                            state="moira",
                            target="accounts-internal",
                            subject=subject,
                            body=body,
                        )
                        flash("Ticket approved; mail sent to accounts-internal.")
                    else:
                        rt.call(
                            "ticket/%d/comment" % (t.rtid,),
                            Action="comment",
                            Text="Ticket approved silently.\n\n" + body,
                        )
                        t.addEvent(type="mail", state="dns", target="us")
                        flash("Ticket approved silently.")
                    redirect("/queue")
        short = t.hostname[: -len(".mit.edu")]
        assert t.hostname[0] != "-"
        stella = subprocess.Popen(
            ["/usr/bin/stella", t.hostname],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        out, err = stella.communicate()
        return dict(
            tickets=[t],
            action=url("/approve/%s" % id),
            subject="scripts-vhosts CNAME request: %s" % short,
            body="""Hi accounts-internal,

At your convenience, please make %(short)s an alias of scripts-vhosts.

stella scripts-vhosts -a %(short)s

Thanks!
-%(first)s
SIPB Scripts Team

/set status=stalled
"""
            % dict(short=short, first=auth.first_name()),
            help_text_html="<p>Make sure the host name is not being used:</p><pre>$ stella %s\n%s\n%s</pre><p>If it's DELETED, you need to forward explicit confirmation that it's OK to reuse (from owner/contact/billing contact, or rccsuper for dorms, or a FSILG's net contact, or similar).</p>"
            % (cgi.escape(t.hostname), cgi.escape(out), cgi.escape(err)),
            extra_buttons={"silent": "Approve without mailing accounts-internal"},
        )
Ejemplo n.º 8
0
     hostname += pylons.request.response_ext
 if path is not None:
     if token != auth.token():
         flash("Invalid token!")
     else:
         try:
             vhosts.set_path(locker, hostname, path)
         except vhosts.UserError, e:
             flash(e.message)
         else:
             flash("Host '%s' reconfigured." % hostname)
             redirect('/index/' + locker)
     _, aliases = vhosts.get_vhost_info(locker, hostname)
 else:
     if alias:
         if token != auth.token():
             flash("Invalid token!")
         else:
             try:
                 vhosts.add_alias(locker, hostname, alias)
             except vhosts.UserError, e:
                 flash(e.message)
             else:
                 flash("Alias '%s' added to hostname '%s'." %
                       (alias, hostname))
                 redirect('/index/' + locker)
     try:
         path, aliases = vhosts.get_vhost_info(locker, hostname)
     except vhosts.UserError, e:
         flash(e.message)
         redirect('/index/' + locker)
Ejemplo n.º 9
0
    def reject(self,
               id,
               subject=None,
               body=None,
               token=None,
               silent=False,
               **kwargs):
        t = queue.Ticket.get(int(id))
        if t.state != "open":
            flash("This ticket's not open!")
            redirect("/ticket/%s" % id)
        if t.rtid is None:
            flash("This ticket has no RT ID!")
            redirect("/ticket/%s" % id)
        if (subject and body) or silent:
            if token != auth.token():
                flash("Invalid token!")
            else:
                # Send mail and records it as an event
                if not silent:
                    rt.call("ticket/%d/comment" % (t.rtid, ),
                            Action="correspond",
                            Text=body)
                    t.addEvent(
                        type=u"mail",
                        state=u"rejected",
                        target=u"user",
                        subject=subject,
                        body=body,
                    )
                    flash("Ticket rejected; mail sent to user.")
                else:
                    rt.call(
                        "ticket/%d/comment" % (t.rtid, ),
                        Action="comment",
                        Text="Ticket rejected silently.\n\n" + body,
                    )
                    t.addEvent(
                        type=u"mail",
                        state=u"rejected",
                        target=u"rt",
                        subject=subject,
                        body=body,
                    )
                    flash("Ticket rejected silently.")
                redirect("/queue")
        return dict(
            tickets=[t],
            action=url("/reject/%s" % id),
            subject="Re: Request for hostname %s" % t.hostname,
            body="""Hello,

Unfortunately, the hostname %(hostname)s is not available.  You can go to https://pony.scripts.mit.edu/ to request a different one.

Sorry for the inconvenience,
-%(first)s

/set status=rejected
""" % dict(hostname=t.hostname, first=auth.first_name()),
            submit="Send to %s" % t.requestor,
            extra_buttons={"silent": "Send as Comment"},
        )
Ejemplo n.º 10
0
 def edit(self,
          locker,
          hostname,
          pool=None,
          path=None,
          token=None,
          alias="",
          **kwargs):
     if request.response_ext:
         hostname += request.response_ext
     if path is not None or pool is not None:
         if token != auth.token():
             flash("Invalid token!")
         else:
             try:
                 if path is not None:
                     vhosts.set_path(locker, hostname, path)
                 if pool is not None:
                     vhosts.set_pool(locker, hostname, pool)
             except vhosts.UserError as e:
                 flash(e.message)
             else:
                 flash("Host '%s' reconfigured." % hostname)
                 redirect("/index/" + locker)
     else:
         if alias:
             if token != auth.token():
                 flash("Invalid token!")
             else:
                 try:
                     vhosts.add_alias(locker, hostname, alias)
                 except vhosts.UserError as e:
                     flash(e.message)
                 else:
                     flash("Alias '%s' added to hostname '%s'." %
                           (alias, hostname))
                     redirect("/index/" + locker)
     try:
         info = vhosts.get_vhost_info(locker, hostname)
     except vhosts.UserError as e:
         flash(e.message)
         redirect("/index/" + locker)
     pools = vhosts.list_pools()
     pool_choices = []
     pool_choices.append({
         "name": pools[None]["description"],
         "value": 'default',
         "selected": info['poolIPv4'] is None
     })
     for ip, pool in pools.items():
         # TODO: Only show selectable pools
         if pool["scriptsVhostPoolUserSelectable"] == "TRUE":
             pool_choices.append({
                 "name": pool["description"],
                 "value": ip,
                 "selected": info['poolIPv4'] == ip
             })
     if not any(choice["selected"] for choice in pool_choices):
         name = pools.get(info['poolIPv4'],
                          {"description": info['poolIPv4']})["description"]
         pool_choices.insert(
             0, {
                 "name": "Unchanged (%s)" % (name, ),
                 "value": "unchanged",
                 "selected": True
             })
     return dict(
         locker=locker,
         hostname=hostname,
         path=info["path"],
         aliases=info["aliases"],
         alias=alias,
         pool_choices=pool_choices,
     )