Exemple #1
0
    def test_list_user(self, m1, m2, m3):
        m1.return_value = [
           {'username': '******', 'tx': '2000', 'local_ip': '10.8.1.100',
             'rx': '1000', 'time': '2013-08-11 20:52', 
             'device': 'ppp0', 'type' : 'pptp', 'remote_ip': '9.9.9.9'}
        ]
        m2.return_value = []
        m3.return_value = tzoffset('Asia/Shanghai', 8 * 3600)
        users = list_users()

        self.assertEqual(len(users), 1)
        self.assertEqual(users[0]['time'], '2013-08-11T20:52:00+08:00')
Exemple #2
0
def main():
    args = docopt(__doc__)
    if args['list']:
        users = list_users()
        for user in users:
            print user
        sys.exit(0)
    elif args['kick']:
        username = args['NAME']
        if kick_user(username):
            print 'user "%s" kicked' % username
            sys.exit(0)
        else:
            print 'user "%s" not found' % username
            sys.exit(-1)
Exemple #3
0
def main():
    args = docopt(__doc__)
    if args['list']:
        users = list_users()
        for user in users:
            print user
        sys.exit(0)
    elif args['kick']:
        conn_id = args['CONN_ID']
        if kick_user(conn_id):
            print 'user "%s" kicked' % conn_id
            sys.exit(0)
        else:
            print 'user "%s" not found' % conn_id
            sys.exit(-1)
Exemple #4
0
 def GET(self):
     users = list_users()
     return json.dumps(users, indent=2)
Exemple #5
0
 def GET(self, fmt):
     users = list_users()
     if fmt == 'html':
         return self.render_html(users)
     else:
         return self.render_json(users)