Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """Sample controller with all its actions protected."""
- from tg import expose, flash, redirect, url, response, tmpl_context, validate
- from tg.decorators import with_trailing_slash
- from pylons.i18n import ugettext as _, lazy_ugettext as l_
- from repoze.what.predicates import has_permission, in_group, in_any_group
- from supporttools.lib.base import BaseController
- from supporttools.widgets.dslcheck_form import dslcheck_form
- from sqlalchemy.sql.functions import current_date
- from pexpect import spawn
- from re import search
- __all__ = ['DSLCheckController']
- class DSLCheckController(BaseController):
- """Sample controller-wide authorization"""
- # The predicate that must be met for all the actions in this controller:
- allow_only = in_any_group('Admin', 'Accounting', 'Support', 'Operations',
- msg=l_('This controller restricted to the following groups: Admin/Accounting/Support/Operations'))
- prompt = 'Router#'
- @with_trailing_slash
- @expose('supporttools.templates.dslcheck')
- def index(self, **kw):
- tmpl_context.form = dslcheck_form
- p = self.Router()
- p.sendline('show vpdn tunnel')
- p.expect(self.prompt)
- tunnel = p.before
- showint = showipint = user = None
- if 'username' in kw:
- p.sendline('show vpdn session all username ' + kw['username'])
- p.expect(self.prompt)
- user = p.before
- # look to see if we have a Vi
- rxp = search('Vi[0-9]*', user)
- if rxp:
- interface = rxp.group()
- p.sendline('show interface ' + interface)
- p.expect(self.prompt)
- showint = p.before
- p.sendline('show ip interface ' + interface)
- p.expect(self.prompt)
- showipint = p.before
- return dict(page='index', tunnel=tunnel, user=user, showint=showint, showipint=showipint, value=kw)
- def Router(self):
- prompt = self.prompt
- passwd = 'password:'
- sshkey = 'Are you sure you want to continue connecting (yes/no)?'
- p = spawn('/usr/bin/ssh -l Username Router')
- loggedin = 0
- while not loggedin:
- i = p.expect([ sshkey , passwd , prompt ])
- if i == 0: # sshkey
- p.sendline('yes')
- elif i == 1: # passwd
- p.sendline('Password')
- elif i == 2: # prompt
- loggedin = 1
- else: # oh the humanity
- flash('Something bad happened. Tell The Administrator.')
- redirect('/')
- # so now we're logged in
- p.sendline('terminal length 0')
- p.expect(prompt)
- p.sendline('terminal width 0')
- p.expect(prompt)
- return p
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement