示例#1
0
    def ssh(self, user, passwd, db, host=None,
            sport=3306, mport=27017, local=False):
        if not (user and passwd and db):
                return 'Please fill in all details' + JavaScript.timed_redirect(location='../',
                                                                                time=1500)
        if not local:
            if not host:
                return 'Please provide host address' + JavaScript.timed_redirect(location='../',
                                                                                 time=1500)
            else:
                ssh.create_ssh_tunnels(host=host,
                                       user=user,
                                       sqlport=sport,
                                       mongoport=mport)

        try:
            self._sql = SQLConnector(host='127.0.0.1',
                                     user=user,
                                     passwd=passwd,
                                     db=db,
                                     port=int(sport))
            self._mongo = MongoConnector(host='localhost',
                                         db=db,
                                         port=int(mport))
        except Exception, e:
            print e
            raise cherrypy.HTTPRedirect('../auth')
def main():
    arg_parser = argument_parser()
    args = arg_parser.parse_args(args=sys.argv[1:])

    if not (args.user and args.db):
        sys.exit(arg_parser.print_help())

    if not args.local:
        if not (args.host and args.port and args.mongoport):
            sys.exit(arg_parser.print_help())
        create_ssh_tunnels(host=args.host, 
                           user=args.user,
                           sqlport=args.port,
                           mongoport=args.mongoport)
    else:
        args.port = 3306
        args.mongoport = 27017

    if not args.password:
        print 'Connecting to MySQL'
        args.password = getpass()

    args.host = '127.0.0.1'
    args.H = 'localhost'

    return args