Ejemplo n.º 1
0
    def post(self):
        login_user = self.get_login_user()
        if not login_user:
            return
        if not login_user.user_right & UserRight.MANUAL_START:
            self.redirect("/")
            return

        a_dict = dict()
        a_dict['success'] = False
        a_dict['content'] = list()
        a_dict['item_count'] = 0

        Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
        user_email = self.get_argument("user_email")
        off_set = self.get_argument("off_set")
        limit = self.get_argument("limit")
        start_time = self.get_argument('start_time')
        end_time = self.get_argument('end_time')
        if not start_time or not end_time:
            self.write(json.dumps(a_dict, ensure_ascii=False))
            return
        start_time = float(start_time)
        end_time = float(end_time)

        text = DbOperator.query_start_history(user_email, off_set, limit, start_time, end_time)
        self.write(text)
Ejemplo n.º 2
0
 def post(self):
     login_user = self.get_login_user()
     if not login_user:
         return
     if not login_user.user_right & UserRight.MANUAL_START:
         self.redirect("/")
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     # Prepare return result
     a_dict = dict()
     a_dict['code'] = -1
     a_dict['msg'] = ''
     # Get argument
     str_service_id = self.get_argument('service_id')
     action = self.get_argument('action')
     # Send request to monitor server
     url = Config.MONITOR_URL + '/api_start_stop_service'
     request_data = {
         'service_id': str_service_id,
         'action': action,
         'user_email': login_user.user_email,
     }
     r = requests.post(url, data=request_data)
     Logger.info("url=[%s], service_id=[%s], action[%s], status_code=[%s], response=[%s]" % (url, str_service_id, action, r.status_code, r.text))
     if r.status_code != 200:
         a_dict['msg'] = 'send request to monitor server failed'
         self.write(json.dumps(a_dict, ensure_ascii=False))
         return
     # Return response to browser
     json_dict = json.loads(r.text)
     self.write(json.dumps(json_dict, ensure_ascii=False))
Ejemplo n.º 3
0
    def post(self):
        login_user = self.get_login_user()
        if not login_user:
            return
        Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
        room_name = self.get_argument('room_name')
        room_pwd = self.get_argument('room_pwd')
        rooter_name = self.get_argument('rooter_name')
        rooter_pwd = self.get_argument('rooter_pwd')
        wifi_name = self.get_argument('wifi_name')
        wifi_pwd = self.get_argument('wifi_pwd')
        electric_date = self.get_argument('electric_date')
        electric_fee = self.get_argument('electric_fee')
        water_date = self.get_argument('water_date')
        water_fee = self.get_argument('water_fee')
        gas_date = self.get_argument('gas_date')
        gas_fee = self.get_argument('gas_fee')
        net_date = self.get_argument('net_date')
        net_fee = self.get_argument('net_fee')
        room_desc = self.get_argument('room_desc')

        a_dict = dict()
        if not room_name:
            a_dict['code'] = 1
            a_dict['msg'] = 'Room name is empty'
            self.write(json.dumps(a_dict, ensure_ascii=False))
            return
        user_id = self.get_secure_cookie('user_id')
        code, msg = DbOperator.insert_one_room(user_id, room_name, room_pwd, rooter_name, rooter_pwd, wifi_name, wifi_pwd,
                                               electric_date, electric_fee, water_date, water_fee,
                                               gas_date, gas_fee, net_date, net_fee, room_desc)
        a_dict['code'] = code
        a_dict['msg'] = msg
        self.write(json.dumps(a_dict, ensure_ascii=False))
Ejemplo n.º 4
0
    def post(self):
        login_user = self.get_login_user()
        if not login_user:
            return
        Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)

        a_dict = dict()
        a_dict['code'] = -1
        a_dict['healthy_code'] = 0
        a_dict['command_healthy_code'] = dict()
        a_dict['monitor_time'] = '1970-01-01 00:00:00'

        # Check service id
        service_id = self.get_argument('service_id')
        if not service_id or not service_id.isdigit():
            self.write(json.dumps(a_dict, ensure_ascii=False))
            return

        url = Config.MONITOR_URL + '/api_get_detail_status'
        request_data = {
            'service_id': service_id,
        }
        r = requests.post(url, data=request_data)
        Logger.info("url=[%s], service_id=[%s], status_code=[%s], response=[%s]" % (url, service_id, r.status_code, r.text))
        if r.status_code != 200:
            self.write(json.dumps(a_dict, ensure_ascii=False))
            return
        json_dict = json.loads(r.text)
        self.write(json.dumps(json_dict, ensure_ascii=False))
Ejemplo n.º 5
0
 def get(self):
     login_user = self.get_login_user()
     if not login_user:
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     json_text = DbOperator.query_plats()
     self.write(json_text)
Ejemplo n.º 6
0
    def __get_monitor_status(cls, job_id_set, service_list):
        """
        :type job_id_set: set[int]
        :param service_list: list[dict[str, Object]]
        :return:
        """
        try:
            if len(job_id_set) <= 0:
                return

            service_id_string = ','.join([str(item) for item in job_id_set])
            request_data = {'service_id': service_id_string}
            url = config.monitor_server_url + '/api_monitor_status'
            r = requests.post(url, data=request_data)
            Logger.info(
                "url=[%s], service_id_list=[%s], status_code=[%s], response=[%s]"
                % (url, job_id_set, r.status_code, r.text))
            if r.status_code != 200:
                return

            json_dict = json.loads(r.text)
            if json_dict['code'] != 0:
                return

            status_dict = json_dict['content']
            for a_service in service_list:
                result = status_dict.get(str(a_service['id']), None)
                if result is not None:
                    (healthy_code, last) = result
                    a_service[
                        'monitor_time'] = datetime.datetime.fromtimestamp(
                            last).strftime('%Y-%m-%d %H:%M:%S')
                    a_service['healthy_code'] = healthy_code
        except:
            Logger.error(traceback.format_exc())
Ejemplo n.º 7
0
    def get(self):
        login_user = self.get_login_user()
        if not login_user:
            return
        content = self.read_public_key(Config.PUBLIC_KEY_FILE)
        Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)

        self.render('machine/show_pubkey.html', content=content)
Ejemplo n.º 8
0
 def get(self):
     login_user = self.get_login_user()
     if not login_user:
         return
     if not login_user.user_right & UserRight.MANUAL_START:
         self.redirect("/")
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     self.render('history/start_history.html', login_user=login_user)
Ejemplo n.º 9
0
 def get(self):
     login_user = self.get_login_user()
     if not login_user:
         return
     if not login_user.user_right & UserRight.EDIT_MANAGER:
         self.redirect("/")
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     self.render('machine/machine_list.html', login_user=login_user)
Ejemplo n.º 10
0
 def get(self):
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     self.clear_cookie("user_email")
     self.clear_cookie("user_name")
     self.clear_cookie("user_right")
     self.clear_cookie("last_time")
     self.clear_cookie("page_right")
     self.set_status(302)
     self.redirect('/')
Ejemplo n.º 11
0
 def post(self):
     login_user = self.get_login_user()
     if not login_user:
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     room_id = self.get_argument('room_id')
     states = self.get_argument('states')
     json_text = DbOperator.save_room_states(room_id, states)
     self.write(json_text)
Ejemplo n.º 12
0
 def get(self):
     login_user = self.get_login_user()
     if not login_user:
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     room_id = self.get_argument('room_id')
     start_dt = self.get_argument('start_dt')
     end_dt = self.get_argument('end_dt')
     json_text = DbOperator.query_room_state(room_id, start_dt, end_dt)
     self.write(json_text)
Ejemplo n.º 13
0
 def post(self):
     login_user = self.get_login_user()
     if not login_user:
         return
     service_name = self.get_argument("service_name")
     off_set = self.get_argument("off_set")
     limit = self.get_argument("limit")
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     text = DbOperator.query_all_monitor_base(service_name, off_set, limit)
     self.write(text)
Ejemplo n.º 14
0
 def post(self):
     login_user = self.get_login_user()
     if not login_user:
         return
     if not login_user.user_right & UserRight.EDIT_MANAGER:
         self.redirect("/")
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     service_id = self.get_argument('service_id')
     text = DbOperator.delete_monitor_detail(service_id)
     self.write(text)
Ejemplo n.º 15
0
 def get(self, *args, **kwargs):
     login_user = self.get_login_user()
     if not login_user:
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     room_id = self.get_argument('room_id', None)
     room_name = DbOperator.query_room_by_id(room_id)
     if not room_name:
         self.render('404.html')
         return
     self.render('order/add_order.html', login_user=login_user, room_id=room_id, room_name=room_name)
Ejemplo n.º 16
0
 def post(self):
     login_user = self.get_login_user()
     if not login_user:
         return
     if not login_user.user_right & UserRight.USER_MANAGER:
         self.redirect("/")
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     user_id_list = self.get_argument("user_id_list")
     text = DbOperator.delete_users(user_id_list)
     self.write(text)
Ejemplo n.º 17
0
 def post(self):
     login_user = self.get_login_user()
     if not login_user:
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     room_name = self.get_argument('room_name')
     sort_column = self.get_argument("sort_column")
     desc_order = self.get_argument("desc_order")
     off_set = self.get_argument("off_set")
     limit = self.get_argument("limit")
     user_id = self.get_secure_cookie('user_id')
     text = DbOperator.query_room_list(user_id, room_name, sort_column, desc_order, off_set, limit)
     self.write(text)
Ejemplo n.º 18
0
 def post(self):
     login_user = self.get_login_user()
     if not login_user:
         return
     if not login_user.user_right & UserRight.EDIT_MANAGER:
         self.redirect("/")
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     machine = self.get_argument("machine")
     off_set = self.get_argument("off_set")
     limit = self.get_argument("limit")
     text = DbOperator.query_machine_list(machine, off_set, limit)
     self.write(text)
Ejemplo n.º 19
0
 def post(self):
     login_user = self.get_login_user()
     if not login_user:
         return
     if not login_user.user_right & UserRight.EDIT_MANAGER:
         self.redirect("/")
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     machine_id = self.get_argument("machine_id")
     ssh_user = self.get_argument("ssh_user")
     ssh_ip = self.get_argument("ssh_ip")
     ssh_port = self.get_argument("ssh_port")
     text = DbOperator.edit_machine(machine_id, ssh_user, ssh_ip, ssh_port)
     self.write(text)
Ejemplo n.º 20
0
    def get(self, *args, **kwargs):
        login_user = self.get_login_user()
        if not login_user:
            return
        Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)

        api = self.get_argument("api", None)
        if not api:
            self.render('order/order_list.html', login_user=login_user)
            return
        room_name = self.get_argument("room_name", None)
        off_set = self.get_argument("off_set", None)
        limit = self.get_argument("limit", None)
        json_text = DbOperator.query_order_list(room_name, off_set, limit)
        self.write(json_text)
Ejemplo n.º 21
0
 def get(self):
     login_user = self.get_login_user()
     if not login_user:
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     service_id = self.get_argument('service_id')
     monitor_detail = DbOperator.query_monitor_detail(service_id)
     if not monitor_detail:
         self.redirect('/')
         return
     self.render('monitor/view_monitor.html',
                 login_user=login_user,
                 base=monitor_detail.base_info,
                 healthy=monitor_detail.healthy_check_list,
                 unhealthy=monitor_detail.unhealthy_check_list,
                 rely=monitor_detail.rely_service_list)
Ejemplo n.º 22
0
 def post(self):
     login_user = self.get_login_user()
     if not login_user:
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     user_name = self.get_argument('user_name')
     user_count = DbOperator.get_user_count(user_name)
     a_dict = dict()
     if user_count is not None:
         a_dict['code'] = 0
         a_dict['msg'] = 'OK'
         a_dict['count'] = user_count
     else:
         a_dict['code'] = 1
         a_dict['msg'] = 'Internal error'
         a_dict['count'] = -1
     self.write(json.dumps(a_dict, ensure_ascii=False))
Ejemplo n.º 23
0
 def post(self, *args, **kwargs):
     login_user = self.get_login_user()
     if not login_user:
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     room_id = self.get_argument('room_id')
     plat_id = self.get_argument('plat_id')
     checkin_date = self.get_argument('check_in_date')
     checkout_date = self.get_argument('check_out_date')
     user_name = self.get_argument('user_name')
     order_fee = self.get_argument('order_fee')
     person_count = self.get_argument('person_count')
     phone = self.get_argument('phone')
     wechat = self.get_argument('wechat')
     order_desc = self.get_argument('order_desc')
     json_text = DbOperator.insert_one_order(room_id, plat_id, checkin_date, checkout_date, user_name, order_fee, person_count, phone, wechat,
                                             order_desc)
     self.write(json_text)
Ejemplo n.º 24
0
    def post(self):
        login_user = self.get_login_user()
        if not login_user:
            return
        Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)

        a_dict = dict()
        user_name = self.get_argument('user_name')
        if not user_name:
            a_dict['code'] = 1
            a_dict['msg'] = 'User name is empty'
            self.write(json.dumps(a_dict, ensure_ascii=False))
            return
        code = DbOperator.change_user_name(login_user.user_email, user_name)
        if code == 0:
            self.set_secure_cookie("user_name", user_name, expires_days=None)
            a_dict['code'] = 0
            a_dict['msg'] = 'OK'
        else:
            a_dict['code'] = 2
            a_dict['msg'] = 'Internal error'
        self.write(json.dumps(a_dict, ensure_ascii=False))
Ejemplo n.º 25
0
 def get(self):
     login_user = self.get_login_user()
     if not login_user:
         return
     if not login_user.user_right & UserRight.EDIT_MANAGER:
         self.redirect("/")
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     service_id = self.get_argument('service_id')
     monitor_detail = DbOperator.query_monitor_detail(service_id)
     all_rely = DbOperator.query_all_monitor_base_v2(service_id)
     all_machine = DbOperator.query_machine_list_v2()
     if monitor_detail is None or all_rely is None or all_machine is None:
         self.redirect('/')
         return
     self.render('monitor/edit_monitor.html',
                 login_user=login_user,
                 base=monitor_detail.base_info,
                 healthy=monitor_detail.healthy_check_list,
                 unhealthy=monitor_detail.unhealthy_check_list,
                 rely_id_set=set([item.id for item in monitor_detail.rely_service_list]),
                 all_rely=all_rely,
                 all_machine=all_machine)
Ejemplo n.º 26
0
 def get(self):
     login_user = self.get_login_user()
     if not login_user:
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     self.redirect('/monitor_list')
Ejemplo n.º 27
0
 def get(self):
     login_user = self.get_login_user()
     if not login_user:
         return
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     self.render('user/personal.html', login_user=login_user)
Ejemplo n.º 28
0
    def get(self):
        if Config.FAKE_LOGIN:
            # 本机fake登录
            self.redirect('/fake_login')
            return

        # 线上真实登录
        Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
        user_email = self.get_current_user()
        if user_email:
            if self.check_login_valid():
                self.redirect("/")
                return

        code_from_auth = self.get_argument('code', None)
        if not code_from_auth:
            redirect_url = Config.OAUTH_AUTH_URL
            redirect_url += '?appid=%s' % Config.OAUTH_APP_ID
            redirect_url += '&response_type=code'
            redirect_url += '&redirect_uri=%s' % quote(Config.OAUTH_REDIRECT_URL)
            redirect_url += '&scope=user_info'
            redirect_url += '&state=test'
            self.redirect(redirect_url)
            return

        status, content = Login.get_access_token(code_from_auth)
        if status != 200:
            self.write(content)
            return
        Logger.info("get_access_token: [%s]" % content)

        try:
            a_dict = json.loads(content)
        except:
            Logger.error("parse token error: content[%s]" % content)
            self.write(content)
            return

        access_token = a_dict.get("access_token", None)
        openid = a_dict.get("openid", None)
        status, content = Login.get_user_info(access_token, openid)
        if status != 200:
            self.write(content)
            return
        Logger.info("get_user_info: [%s]" % content)

        try:
            a_dict = json.loads(content)
        except:
            Logger.error("parse user_info error: contnet[%s]" % content)
            self.write(content)
            return

        user_name = a_dict.get("name")
        user_email = a_dict.get("email")
        db_user = DbOperator.get_user_info(user_email)
        if not db_user:
            self.redirect('/refuse')
            return

        # 保存session
        self.set_secure_cookie("user_email", user_email, expires_days=None)
        self.set_secure_cookie("user_name", user_name, expires_days=None)
        self.set_secure_cookie("user_right", str(db_user.user_right), expires_days=None)
        self.set_secure_cookie("last_time", str(time.time()), expires_days=None)
        self.set_cookie("page_right", str(db_user.user_right), expires_days=None)

        # 重向定
        self.redirect("/")
Ejemplo n.º 29
0
def __main__():
    # 设置编码
    reload(sys)
    sys.setdefaultencoding('utf-8')

    # Do nothing
    setting.description()

    # 解析参数
    options.parse_command_line()
    if not Config.init(options.conf):
        print 'parse %s error' % options.conf
        return
    if not Config.check():
        return

    # 设置程序名称
    setproctitle.setproctitle('MTMonitorPlatServer')

    # 不要输出日志到屏幕
    logging.getLogger("tornado.access").propagate = False
    logging.getLogger("tornado.application").propagate = False
    logging.getLogger("tornado.general").propagate = False
    logging.getLogger("process").propagate = False
    logging.getLogger("report").propagate = False
    logging.getLogger("third").propagate = False

    # 初始化日志
    Logger.init(Config.LOG_ENV, Config.LOG_TARGET, Config.LOG_NAME, Config.LOG_SIZE, Config.LOG_COUNT)

    # 重定向tornado自带日志
    logging.getLogger("tornado.access").addHandler(Logger.get_third_handler())
    logging.getLogger("tornado.application").addHandler(Logger.get_third_handler())
    logging.getLogger("tornado.general").addHandler(Logger.get_third_handler())

    # 设置request日志
    logging.getLogger("requests").setLevel(logging.WARNING)

    # 打印启动日志
    print "server is starting..."
    Logger.info("server is starting...")
    Logger.info("config.listen_port: %s" % Config.LISTEN_PORT)
    Config.log_config()

    # 初始化DB连接参数
    if not DbOperator.init():
        return

    app = tornado.web.Application(
        [
            (r'/', RoomList),
            (r'/refuse', RefuseHandler),
            (r'/login', LoginHandler),
            (r'/logout', LogoutHandler),
            (r'/user_list', UserListHandler),
            (r'/api_add_user', AddUserHandler),
            (r'/api_del_user', DeleteUserHandler),
            (r'/api_edit_user', EditUserHandler),
            (r'/api_query_user', QueryUserListHandler),
            (r'/personal', PersonalHandler),
            (r'/get_user_count', GetUserCount),
            (r'/api_change_user_name', ApiChangeUserName),
            (r'/api_change_user_pwd', ApiChangeUserPwd),
            (r'/room_plat', RoomPlat),
            (r'/add_room', AddRoom),
            (r'/room_list', RoomList),
            (r'/edit_room', EditRoom),
            (r'/room_state', RoomState),
            (r'/captcha', Captcha),
            (r'/order', Order),
            (r'/order_list', OrderList),
            (r'/dis', DisHandler),
        ],
        cookie_secret=Config.LOGIN_COOKIE_SECRET,
        template_path=os.path.join(os.path.dirname(__file__), "templates"),
        static_path=os.path.join(os.path.dirname(__file__), "static"),
        xsrf_cookies=False,
        debug=Config.DEBUG_MODE
    )
    # http_server = tornado.httpserver.HTTPServer(app, ssl_options={
    #     'certfile': '/Users/liyanguo/cluster/centos/work/room_manager/key/ssl.crt',
    #     'keyfile': '/Users/liyanguo/cluster/centos/work/room_manager/key/ssl.key'
    # })
    # http_server.listen(433)
    app.listen(Config.LISTEN_PORT, Config.LISTEN_HOST)
    now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    print '%s starting' % now
    tornado.ioloop.IOLoop.current().start()
Ejemplo n.º 30
0
 def get(self):
     Logger.info(json.dumps(self.request.arguments, ensure_ascii=False), self.request.uri)
     self.render('reload.html')