Beispiel #1
0
def debug(message, **kwargs):
    if not isinstance(message, unicode):
        message = safeunicode(message)
    if EVENT_DEBUG in dispatch.dispatch.callbacks:
        dispatch.pub(EVENT_DEBUG, message, **kwargs)
        if EVENT_TRACE in dispatch.dispatch.callbacks:
            dispatch.pub(EVENT_TRACE, "debug", message, **kwargs)
Beispiel #2
0
def error(message, **kwargs):
    if not isinstance(message, unicode):
        message = safeunicode(message)
    if EVENT_ERROR in dispatch.dispatch.callbacks:
        dispatch.pub(EVENT_ERROR, message, **kwargs)
        if EVENT_TRACE in dispatch.dispatch.callbacks:
            dispatch.pub(EVENT_TRACE, "error", message, **kwargs)
Beispiel #3
0
def debug(message,**kwargs):
    if not isinstance(message, unicode):
        message = safeunicode(message)
    if EVENT_DEBUG in dispatch.dispatch.callbacks:
        dispatch.pub(EVENT_DEBUG,message,**kwargs)
        if EVENT_TRACE in dispatch.dispatch.callbacks:
            dispatch.pub(EVENT_TRACE,"debug",message,**kwargs)
Beispiel #4
0
def info(message, **kwargs):
    if not isinstance(message, unicode):
        message = safeunicode(message)
    if EVENT_INFO in dispatch.dispatch.callbacks:
        dispatch.pub(EVENT_INFO, message, **kwargs)
        if EVENT_TRACE in dispatch.dispatch.callbacks:
            dispatch.pub(EVENT_TRACE, "info", message, **kwargs)
Beispiel #5
0
def error(message,**kwargs):
    if not isinstance(message, unicode):
        message = safeunicode(message)
    if EVENT_ERROR in dispatch.dispatch.callbacks:
        dispatch.pub(EVENT_ERROR,message,**kwargs)
        if EVENT_TRACE in dispatch.dispatch.callbacks:
            dispatch.pub(EVENT_TRACE,"error",message,**kwargs)
Beispiel #6
0
def info(message,**kwargs):
    if not isinstance(message, unicode):
        message = safeunicode(message)
    if EVENT_INFO in dispatch.dispatch.callbacks:
        dispatch.pub(EVENT_INFO,message,**kwargs)
        if EVENT_TRACE in dispatch.dispatch.callbacks:
            dispatch.pub(EVENT_TRACE,"info",message,**kwargs)
Beispiel #7
0
    def post(self):
        form = operator_form.operator_add_form()
        if not form.validates(source=self.get_params()):
            return self.render("base_form.html", form=form)
        if self.db.query(models.SysOperator.id).filter_by(
                operator_name=form.d.operator_name).count() > 0:
            return self.render("base_form.html", form=form, msg=u"操作员已经存在")
        operator = models.SysOperator()
        operator.operator_name = form.d.operator_name
        operator.operator_pass = tools.saltmd5(form.d.operator_pass.encode())
        operator.operator_type = 1
        operator.operator_desc = form.d.operator_desc
        operator.operator_status = form.d.operator_status
        self.db.add(operator)

        self.add_oplog(u'新增操作员信息:%s' %
                       utils.safeunicode(operator.operator_name))

        for path in self.get_arguments("rule_item"):
            item = permit.get_route(path)
            if not item: continue
            rule = models.SysOperatorRule()
            rule.operator_name = operator.operator_name
            rule.rule_name = item['name']
            rule.rule_path = item['path']
            rule.rule_category = item['category']
            self.db.add(rule)

        self.db.commit()

        for rule in self.db.query(models.SysOperatorRule).filter_by(
                operator_name=operator.operator_name):
            permit.bind_opr(rule.operator_name, rule.rule_path)

        self.redirect("/admin/operator", permanent=False)
Beispiel #8
0
 def dataReceived(self, request):
     try:
         message = msgpack.unpackb(request[0])
         if self.config.system.debug:
             logger.debug(u"received radius start request:"+utils.safeunicode(message))
         self.que.appendleft(message)
     except:
         traceback.print_exc()
Beispiel #9
0
    def get(self):
        operator_id = self.get_argument("operator_id")
        opr = self.db.query(models.SysOperator).get(operator_id)
        self.db.query(models.SysOperatorRule).filter_by(
            operator_name=opr.operator_name).delete()
        self.db.query(models.SysOperator).filter_by(id=operator_id).delete()

        self.add_oplog(u'删除操作员%s信息' % utils.safeunicode(opr.operator_name))
        self.db.commit()
        self.redirect("/admin/operator", permanent=False)
Beispiel #10
0
def make_sign(api_secret, params=[]):
    """
        >>> make_sign("123456",[1,'2',u'中文'])
        '33C9065427EECA3490C5642C99165145'
    """
    _params = [utils.safeunicode(p) for p in params if p is not None]
    _params.sort()
    # print 'sorted params:',_params
    _params.insert(0, api_secret)
    strs = ''.join(_params)
    # print 'sign params:',strs
    mds = md5(strs.encode('utf-8')).hexdigest()
    return mds.upper()
Beispiel #11
0
    def emit(self, eventDict):
        try:
            text = txlog.textFromEventDict(eventDict)
            if text is None:
                return
            if not isinstance(text, (unicode, str, dict, list)):
                text = text
            else:
                text = safeunicode(text)

            if eventDict['isError'] and 'failure' in eventDict:
                self.syslogger.exception(eventDict['failure'])
            else:
                self.info(text)
        except:
            import traceback
            traceback.print_exc()
Beispiel #12
0
    def emit(self, eventDict):
        try:
            text = txlog.textFromEventDict(eventDict)
            if text is None:
                return
            if not isinstance(text, (unicode,str,dict,list)):
                text = text
            else:
                text = safeunicode(text)

            if eventDict['isError'] and 'failure' in eventDict:
                self.syslogger.exception(eventDict['failure'])
            else:
                self.info(text)
        except:
            import traceback
            traceback.print_exc()
Beispiel #13
0
    def post(self):
        form = operator_form.operator_update_form()
        if not form.validates(source=self.get_params()):
            rules = self.db.query(models.SysOperatorRule.rule_path).filter_by(
                operator_name=form.d.operator_name)
            rules = [r[0] for r in rules]
            return self.render("base_form.html", form=form, rules=rules)
        operator = self.db.query(models.SysOperator).get(form.d.id)
        if form.d.operator_pass:
            operator.operator_pass = tools.saltmd5(
                form.d.operator_pass.encode())
        operator.operator_desc = form.d.operator_desc
        operator.operator_status = form.d.operator_status

        self.add_oplog(u'修改操作员%s信息' %
                       utils.safeunicode(operator.operator_name))

        # update rules
        self.db.query(models.SysOperatorRule).filter_by(
            operator_name=operator.operator_name).delete()

        for path in self.get_arguments("rule_item"):
            item = permit.get_route(path)
            if not item: continue
            rule = models.SysOperatorRule()
            rule.operator_name = operator.operator_name
            rule.rule_name = item['name']
            rule.rule_path = item['path']
            rule.rule_category = item['category']
            self.db.add(rule)

        permit.unbind_opr(operator.operator_name)

        self.db.commit()

        for rule in self.db.query(models.SysOperatorRule).filter_by(
                operator_name=operator.operator_name):
            permit.bind_opr(rule.operator_name, rule.rule_path)

        self.redirect("/admin/operator", permanent=False)
Beispiel #14
0
 def add_oplog(self, message):
     msg = u"operate_log: %s %s %s %s" % (
         self.current_user.username, self.current_user.ipaddr,
         utils.get_currtime(), utils.safeunicode(message))
     logger.info(msg, trace="oplog")