示例#1
0
def run_after_this_response(e):
    if e is not None:
        return
    if hasattr(g, 'after_this_response'):
        for f in g.after_this_response:
            try:
                f()
            except:
                logger.error_traceback('WEB')
示例#2
0
def users_reset_passwrod(cn):
    ret = {'success': False, 'new_password': None}
    try:
        new_password = strings.random_str(12)
        models.reset_password(cn, new_password)
        ret['success'] = True
        ret['new_password'] = new_password
    except:
        logger.error_traceback(LOGGER_NAME)
    return strings.to_json(ret, True)
示例#3
0
def test_connection():
    try:
        models.test_connection()
        return 'success'
    except LDAPSocketOpenError:
        return '连接错误'
    except LDAPBindError:
        return '授权错误'
    except Exception as e:
        logger.error_traceback(LOGGER_NAME)
        return str(e)
示例#4
0
 def mkdir_parent(self, dirname):
     from ftplib import error_perm
     from os.path import sep
     dirname = strings.rtrim(dirname, sep)
     dir_arr = dirname.split(sep)
     for i in range(2 if dirname.startswith("/") else 1, len(dir_arr) + 1):
         try:
             self.mkdir(sep.join(dir_arr[:i]))
         except error_perm:
             pass
         except:
             logger.error_traceback()
示例#5
0
def save():
    schedule_type = num.safe_int(request.form.get('scheduletype'))
    try:
        models.save_schedule_manually({
            'id':
            request.form.get('oid'),
            'type':
            schedule_type,
            'data':
            get_data(schedule_type),
            'starttime':
            get_time(schedule_type, True),
            'endtime':
            get_time(schedule_type, False),
            'func':
            request.form.get('func', None),
            'module':
            request.form.get('module', None),
            'maxinstance':
            num.safe_int(request.form.get('maxinstance', 5), 5),
            'enabled':
            num.safe_int(request.form.get('enabled', None)),
            'args':
            request.form.get('args', None),
            'sourceid':
            request.form.get('sourceid', None)
        })
        return 'success'
    except:
        return logger.error_traceback()
示例#6
0
def user_session():
    if request.endpoint is None:
        return

    from ...modules.user.models import get_user_byid, get_user_byloginid, get_umsession_bytoken
    try:
        token = webutils.get_cookie('AUTHTOKEN')
        if strings.is_not_blank(token):
            session = get_umsession_bytoken(token)
            if session is not None:
                user = get_user_byid(session['user_id'])
                if user is not None:
                    g.curr_user = user
                    return
            webutils.set_cookie('AUTHTOKEN', '', expire_days=0)
        g.curr_user = get_user_byloginid('guest')
    except:
        logger.error_traceback()
示例#7
0
def users_save():
    dn = request.form.get('dn')
    ret = {'success': False, 'error_msg': None, 'new_password': None}
    try:
        if strings.is_blank(dn):
            response = models.add_user(
                cn=request.form.get('cn'),
                sn=request.form.get('sn'),
                uid_number=request.form.get('uid'),
                gid_number=request.form.get('gid'),
                gecos=request.form.get('gecos'),
                mail=request.form.get('mail'),
                display_name=request.form.get('displayName'),
            )
            if not response:
                ret['error_msg'] = '添加失败,请查询 slapd.server 日志'
            else:
                # new password
                new_password = strings.random_str(12)
                models.reset_password(request.form.get('cn'), new_password)
                ret['success'] = True
                ret['new_password'] = new_password
        else:
            response = models.modify_user(
                cn=request.form.get('cn'),
                sn=request.form.get('sn'),
                uid_number=request.form.get('uid'),
                gid_number=request.form.get('gid'),
                gecos=request.form.get('gecos'),
                mail=request.form.get('mail'),
                display_name=request.form.get('displayName'),
            )
            if not response:
                ret['error_msg'] = '添加失败,请查询 slapd.server 日志'
            else:
                ret['success'] = True
    except LDAPBindError:
        ret['error_msg'] = '授权错误'
        return ret
    except Exception as e:
        logger.error_traceback(LOGGER_NAME)
        ret['error_msg'] = str(e)
    return strings.to_json(ret, True)
示例#8
0
文件: task.py 项目: major1201/raphael
def load_task_from_database():
    from raphael.utils import logger
    from raphael.app.modules.schedule import models as schedule

    # add new jobstore
    try:
        _scheduler.remove_jobstore(schedule.TASK_DATABASE)
    except:
        pass
    _scheduler.add_jobstore(MemoryJobStore(), schedule.TASK_DATABASE)
    # clear the jobstore
    remove_all_jobs(schedule.TASK_DATABASE)
    # add add tasks
    schedule_list = schedule.find_schedules(enabled=1).fetch()
    for item in schedule_list:
        try:
            schedule.save_task_schedule(item)
        except:
            logger.error_traceback()
示例#9
0
def command_groups_save():
    opt = request.form.get('opt')
    cn = request.form.get('cn')
    if opt == 'NEW':
        return 'success' if models.add_command_group(cn) else 'fail'
    elif opt == 'EDIT':
        try:
            unique_member = json.loads(request.form.get('unique_member'))
            return 'success' if models.modify_command_group(
                cn, unique_member) else '保存失败,请查阅 slapd 日志!'
        except:
            return logger.error_traceback(LOGGER_NAME)
示例#10
0
def write_log(e):
    if e is not None:
        logger.error_traceback()
    log_arr = (str(g.status_code), request.method, request.full_path,
               '(' + request.remote_addr + ')')
    logger.info(' '.join(log_arr), 'WEB')
示例#11
0
 def close(self):
     try:
         self.session.close()
     except IOError:
         logger.error_traceback(DAO_LOGGER)