mirror of https://github.com/tp4a/teleport
temp.
parent
36efcb1989
commit
79e7f641ca
|
@ -28,6 +28,17 @@ class ConfigFile(AttrDict):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
self['core'] = AttrDict()
|
||||||
|
self['core']['ssh'] = AttrDict()
|
||||||
|
self['core']['ssh']['enable'] = False
|
||||||
|
self['core']['ssh']['port'] = 52189
|
||||||
|
self['core']['rdp'] = AttrDict()
|
||||||
|
self['core']['rdp']['enable'] = False
|
||||||
|
self['core']['rdp']['port'] = 52089
|
||||||
|
self['core']['telnet'] = AttrDict()
|
||||||
|
self['core']['telnet']['enable'] = False
|
||||||
|
self['core']['telnet']['port'] = 52389
|
||||||
|
|
||||||
def load_web(self, cfg_file):
|
def load_web(self, cfg_file):
|
||||||
if not os.path.exists(cfg_file):
|
if not os.path.exists(cfg_file):
|
||||||
log.e('configuration file does not exists: [{}]\n'.format(cfg_file))
|
log.e('configuration file does not exists: [{}]\n'.format(cfg_file))
|
||||||
|
|
|
@ -35,7 +35,6 @@ controllers = [
|
||||||
(r'/auth/logout', auth.LogoutHandler),
|
(r'/auth/logout', auth.LogoutHandler),
|
||||||
(r'/auth/get-captcha', auth.GetCaptchaHandler),
|
(r'/auth/get-captcha', auth.GetCaptchaHandler),
|
||||||
(r'/auth/verify-captcha', auth.VerifyCaptchaHandler),
|
(r'/auth/verify-captcha', auth.VerifyCaptchaHandler),
|
||||||
(r'/auth/verify-ticket', auth.VerifyTicketHandler),
|
|
||||||
(r'/auth/modify-pwd', auth.ModifyPwd),
|
(r'/auth/modify-pwd', auth.ModifyPwd),
|
||||||
|
|
||||||
(r'/group/list', group.GetListHandler),
|
(r'/group/list', group.GetListHandler),
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import random
|
|
||||||
# from random import Random
|
|
||||||
|
|
||||||
from eom_app.module import user
|
from eom_app.module import user
|
||||||
from eom_common.eomcore.logger import *
|
from eom_common.eomcore.logger import *
|
||||||
|
@ -12,16 +10,12 @@ from eom_app.app.util import gen_captcha
|
||||||
|
|
||||||
class LoginHandler(SwxAppHandler):
|
class LoginHandler(SwxAppHandler):
|
||||||
def get(self):
|
def get(self):
|
||||||
# _ref = self.get_argument('ref', '/')
|
|
||||||
|
|
||||||
_user = self.get_current_user()
|
_user = self.get_current_user()
|
||||||
if _user['id'] == 0:
|
if _user['id'] == 0:
|
||||||
user_name = ''
|
user_name = ''
|
||||||
else:
|
else:
|
||||||
user_name = _user['name']
|
user_name = _user['name']
|
||||||
|
|
||||||
#self.render('auth/login.mako', user_name=user_name, reference=ref, captcha_random=random.random())
|
|
||||||
|
|
||||||
page_param = {
|
page_param = {
|
||||||
'ref': self.get_argument('ref', '/'),
|
'ref': self.get_argument('ref', '/'),
|
||||||
'login_type': 'account',
|
'login_type': 'account',
|
||||||
|
@ -51,7 +45,6 @@ class VerifyUser(SwxJsonpHandler):
|
||||||
|
|
||||||
self.del_session('captcha')
|
self.del_session('captcha')
|
||||||
|
|
||||||
# log.v('try to set-session.\n')
|
|
||||||
try:
|
try:
|
||||||
user_id, account_type, nickname = user.verify_user(username, userpwd)
|
user_id, account_type, nickname = user.verify_user(username, userpwd)
|
||||||
if user_id == 0:
|
if user_id == 0:
|
||||||
|
@ -87,11 +80,10 @@ class VerifyUser(SwxJsonpHandler):
|
||||||
|
|
||||||
class LogoutHandler(SwxAppHandler):
|
class LogoutHandler(SwxAppHandler):
|
||||||
def get(self):
|
def get(self):
|
||||||
user = self.get_current_user()
|
_user = self.get_current_user()
|
||||||
user['is_login'] = False
|
_user['is_login'] = False
|
||||||
self.set_session('user', user)
|
self.set_session('user', _user)
|
||||||
|
|
||||||
# self.render('login/login.mako', captcha_random=random.random())
|
|
||||||
self.redirect('/auth/login')
|
self.redirect('/auth/login')
|
||||||
|
|
||||||
|
|
||||||
|
@ -122,104 +114,6 @@ class VerifyCaptchaHandler(SwxJsonpHandler):
|
||||||
self.write_jsonp(0)
|
self.write_jsonp(0)
|
||||||
|
|
||||||
|
|
||||||
class VerifyTicketHandler(SwxJsonpHandler):
|
|
||||||
def get(self):
|
|
||||||
# print('verify-ticket')
|
|
||||||
|
|
||||||
code = self.get_session('captcha')
|
|
||||||
if code is None:
|
|
||||||
self.write_jsonp(-1)
|
|
||||||
return
|
|
||||||
|
|
||||||
captcha = self.get_argument('captcha', None)
|
|
||||||
username = self.get_argument('username', None)
|
|
||||||
user_id = self.get_argument('user_id', None)
|
|
||||||
ticket = self.get_argument('ticket', None)
|
|
||||||
|
|
||||||
if captcha is None or username is None or ticket is None:
|
|
||||||
self.write_jsonp(-1)
|
|
||||||
return
|
|
||||||
|
|
||||||
if code.lower() != captcha.lower():
|
|
||||||
self.write_jsonp(-1)
|
|
||||||
return
|
|
||||||
|
|
||||||
self.del_session('captcha')
|
|
||||||
|
|
||||||
# if not self.is_ticket_valid(username, ticket):
|
|
||||||
# self.write_jsonp(-1)
|
|
||||||
# return
|
|
||||||
|
|
||||||
# log.v('try to set-session.\n')
|
|
||||||
try:
|
|
||||||
_user = user.get_user_by_id(user_id)
|
|
||||||
if _user is None:
|
|
||||||
self.write_jsonp(-1)
|
|
||||||
return
|
|
||||||
|
|
||||||
# _user = dict()
|
|
||||||
# _user['id'] = user_id
|
|
||||||
# # user['account'] = username # login-name
|
|
||||||
# _user['name'] = username # real-name
|
|
||||||
_user['is_login'] = True
|
|
||||||
|
|
||||||
self.set_session('user', _user)
|
|
||||||
# log.v('set session ok.\n')
|
|
||||||
|
|
||||||
self.write_jsonp(0)
|
|
||||||
except:
|
|
||||||
log.e('can not set session.')
|
|
||||||
self.write_jsonp(-1)
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# class QuickLoginHandler(SwxJsonpHandler):
|
|
||||||
# def get(self):
|
|
||||||
# # code = self.get_session('captcha')
|
|
||||||
# # if code is None:
|
|
||||||
# # self.write_jsonp(-1)
|
|
||||||
# # return
|
|
||||||
#
|
|
||||||
# # captcha = self.get_argument('captcha', None)
|
|
||||||
# # username = self.get_argument('username', None)
|
|
||||||
# user_id = self.get_argument('uid', None)
|
|
||||||
# ticket = self.get_argument('ticket', None)
|
|
||||||
#
|
|
||||||
# # if captcha is None or username is None or ticket is None:
|
|
||||||
# # self.write_jsonp(-1)
|
|
||||||
# # return
|
|
||||||
# #
|
|
||||||
# # if code.lower() != captcha.lower():
|
|
||||||
# # self.write_jsonp(-1)
|
|
||||||
# # return
|
|
||||||
#
|
|
||||||
# # self.del_session('captcha')
|
|
||||||
#
|
|
||||||
# if not self.is_ticket_valid(ticket):
|
|
||||||
# self.write_jsonp(-1)
|
|
||||||
# return
|
|
||||||
#
|
|
||||||
# _user = user.get_user_by_id(user_id)
|
|
||||||
# if _user is None:
|
|
||||||
# self.write_jsonp(-1)
|
|
||||||
# return
|
|
||||||
#
|
|
||||||
# # _user = dict()
|
|
||||||
# # _user['id'] = user_id
|
|
||||||
# # # user['account'] = username # login-name
|
|
||||||
# # _user['name'] = username # real-name
|
|
||||||
# _user['is_login'] = True
|
|
||||||
#
|
|
||||||
# log.v('quick login ok, try to set session.\n')
|
|
||||||
# try:
|
|
||||||
# self.set_session('user', _user)
|
|
||||||
# log.v('set session ok.\n')
|
|
||||||
# self.write_jsonp(0)
|
|
||||||
# except:
|
|
||||||
# log.v('set session failed.\n')
|
|
||||||
# self.write_jsonp(1)
|
|
||||||
|
|
||||||
|
|
||||||
class ModifyPwd(SwxAuthJsonHandler):
|
class ModifyPwd(SwxAuthJsonHandler):
|
||||||
def post(self):
|
def post(self):
|
||||||
# print('verify-ticket')
|
# print('verify-ticket')
|
||||||
|
@ -242,48 +136,6 @@ class ModifyPwd(SwxAuthJsonHandler):
|
||||||
user_info = self.get_current_user()
|
user_info = self.get_current_user()
|
||||||
try:
|
try:
|
||||||
ret = user.modify_pwd(_old_pwd, _new_pwd, user_info['id'])
|
ret = user.modify_pwd(_old_pwd, _new_pwd, user_info['id'])
|
||||||
code = dict()
|
self.write_json(0, ret)
|
||||||
code['code'] = ret
|
|
||||||
self.write_json(0, data=code)
|
|
||||||
except:
|
except:
|
||||||
log.e('can not set session.')
|
|
||||||
self.write_json(-1)
|
self.write_json(-1)
|
||||||
|
|
||||||
#
|
|
||||||
# class GetEncData(SwxAuthJsonHandler):
|
|
||||||
# def post(self):
|
|
||||||
# # print('verify-ticket')
|
|
||||||
#
|
|
||||||
# args = self.get_argument('args', None)
|
|
||||||
# if args is not None:
|
|
||||||
# args = json.loads(args)
|
|
||||||
# # print('args', args)
|
|
||||||
# else:
|
|
||||||
# # ret = {'code':-1}
|
|
||||||
# self.write_json(-1)
|
|
||||||
# return
|
|
||||||
# _pwd = args['pwd']
|
|
||||||
#
|
|
||||||
# if _pwd is None:
|
|
||||||
# self.write_json(-1)
|
|
||||||
# return
|
|
||||||
#
|
|
||||||
# try:
|
|
||||||
# ret, data = user.get_enc_data_helper(_pwd)
|
|
||||||
# code = dict()
|
|
||||||
# code['code'] = ret
|
|
||||||
# code['data'] = data
|
|
||||||
# self.write_json(0, data=code)
|
|
||||||
# except:
|
|
||||||
# log.e('can not set session.')
|
|
||||||
# self.write_json(-1)
|
|
||||||
|
|
||||||
|
|
||||||
# def random_str(randomlength=8):
|
|
||||||
# _str = ''
|
|
||||||
# chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
|
|
||||||
# length = len(chars) - 1
|
|
||||||
# _random = Random()
|
|
||||||
# for i in range(randomlength):
|
|
||||||
# _str += chars[_random.randint(0, length)]
|
|
||||||
# return _str
|
|
||||||
|
|
|
@ -3,18 +3,15 @@
|
||||||
import time
|
import time
|
||||||
import csv
|
import csv
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
import threading
|
import threading
|
||||||
import urllib
|
|
||||||
import urllib.parse
|
|
||||||
import urllib.request
|
|
||||||
import tornado.gen
|
import tornado.gen
|
||||||
import tornado.httpclient
|
import tornado.httpclient
|
||||||
|
|
||||||
from eom_app.app.configs import app_cfg
|
from eom_app.app.configs import app_cfg
|
||||||
# from eom_app.module import set
|
|
||||||
from eom_app.app.util import *
|
from eom_app.app.util import *
|
||||||
from eom_app.module import host
|
from eom_app.module import host
|
||||||
from eom_app.module.common import *
|
# from eom_app.module.common import *
|
||||||
from eom_common.eomcore.logger import *
|
from eom_common.eomcore.logger import *
|
||||||
from eom_app.app.session import web_session
|
from eom_app.app.session import web_session
|
||||||
from .base import SwxAuthHandler, SwxAuthJsonHandler, SwxAdminJsonHandler
|
from .base import SwxAuthHandler, SwxAuthJsonHandler, SwxAdminJsonHandler
|
||||||
|
|
|
@ -1,16 +1,10 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import gzip
|
|
||||||
import json
|
|
||||||
import urllib.parse
|
|
||||||
import urllib.request
|
|
||||||
|
|
||||||
import eom_common.eomcore.eom_mysql as mysql
|
import eom_common.eomcore.eom_mysql as mysql
|
||||||
import eom_common.eomcore.eom_sqlite as sqlite
|
import eom_common.eomcore.eom_sqlite as sqlite
|
||||||
from eom_app.app.configs import app_cfg
|
# from eom_app.app.configs import app_cfg
|
||||||
# from eom_app.module import set
|
|
||||||
|
|
||||||
cfg = app_cfg()
|
# cfg = app_cfg()
|
||||||
|
|
||||||
|
|
||||||
class DbItem(dict):
|
class DbItem(dict):
|
||||||
|
@ -34,73 +28,3 @@ def get_db_con():
|
||||||
sql_exec = sqlite.get_sqlite_pool().get_tssqlcon()
|
sql_exec = sqlite.get_sqlite_pool().get_tssqlcon()
|
||||||
return sql_exec
|
return sql_exec
|
||||||
|
|
||||||
|
|
||||||
# def post_http(url, values):
|
|
||||||
# try:
|
|
||||||
# # log.v('post_http(), url={}\n'.format(url))
|
|
||||||
#
|
|
||||||
# user_agent = 'Mozilla/4.0 (compatible;MSIE 5.5; Windows NT)'
|
|
||||||
# # values = {
|
|
||||||
# # 'act': 'login',
|
|
||||||
# # 'login[email]': 'yzhang@i9i8.com',
|
|
||||||
# # 'login[password]': '123456'
|
|
||||||
# # }
|
|
||||||
# values = json.dumps(values)
|
|
||||||
# data = urllib.parse.quote(values).encode('utf-8')
|
|
||||||
# # data = urllib.parse.urlencode(values).encode()
|
|
||||||
# headers = {'User-Agent': user_agent}
|
|
||||||
# # url = 'http://www.baidu.com'
|
|
||||||
# req = urllib.request.Request(url=url, data=data, headers=headers)
|
|
||||||
# response = urllib.request.urlopen(req, timeout=3)
|
|
||||||
# the_page = response.read()
|
|
||||||
# info = response.info()
|
|
||||||
# _zip = info.get('Content-Encoding')
|
|
||||||
# if _zip == 'gzip':
|
|
||||||
# the_page = gzip.decompress(the_page)
|
|
||||||
# else:
|
|
||||||
# pass
|
|
||||||
# the_page = the_page.decode()
|
|
||||||
# return the_page
|
|
||||||
# except:
|
|
||||||
# return None
|
|
||||||
|
|
||||||
|
|
||||||
# def get_enc_data(data):
|
|
||||||
# # url = cfg.ts_enc_url
|
|
||||||
# config_list = set.get_config_list()
|
|
||||||
# rpc_port = 52080
|
|
||||||
# if 'ts_server_rpc_port' in config_list:
|
|
||||||
# rpc_port = int(config_list['ts_server_rpc_port'])
|
|
||||||
# ts_server_rpc_ip = '127.0.0.1'
|
|
||||||
# if 'ts_server_rpc_ip' in config_list:
|
|
||||||
# ts_server_rpc_ip = config_list['ts_server_rpc_ip']
|
|
||||||
#
|
|
||||||
# url = 'http://{}:{}/enc'.format(ts_server_rpc_ip, rpc_port)
|
|
||||||
#
|
|
||||||
# values = dict()
|
|
||||||
# if not isinstance(data, str):
|
|
||||||
# data = "{}".format(data)
|
|
||||||
#
|
|
||||||
# values['p'] = data
|
|
||||||
# return_data = post_http(url, values)
|
|
||||||
# if return_data is None:
|
|
||||||
# return -2, ''
|
|
||||||
#
|
|
||||||
# if return_data is not None:
|
|
||||||
# return_data = json.loads(return_data)
|
|
||||||
# else:
|
|
||||||
# return -3, ''
|
|
||||||
#
|
|
||||||
# ret_code = return_data['code']
|
|
||||||
# if ret_code != 0:
|
|
||||||
# return ret_code, ''
|
|
||||||
# if 'data' not in return_data:
|
|
||||||
# return -5, ''
|
|
||||||
#
|
|
||||||
# data = return_data['data']
|
|
||||||
# if 'c' not in data:
|
|
||||||
# return -6, ''
|
|
||||||
#
|
|
||||||
# decry_data = data['c']
|
|
||||||
#
|
|
||||||
# return 0, decry_data
|
|
||||||
|
|
Loading…
Reference in New Issue