def user():
    """
        update user info
    :return: respond model
    """
    request_model = RequestModel(request)
    user_info_form = request_model.data.get('user_info')
    jwt = request_model.token
    user_info_jwt = decode_jwt(jwt)['user_info']
    respond_model = RespondModel()
    save_user_info = False
    if (user_info_form and user_info_form['name']
            == user_info_jwt['name']) or 'admin' in user_info_jwt['roles']:
        if not user_info_form.get('password') or user_info_form.get(
                'password') == '':
            user_info_form['password'] = get_password_from_db(user_info_form)
            save_user_info = user_service.update(user_info_form)
        else:
            save_user_info = update_password(user_info_form)
        respond_model.message = 'success'
        if save_user_info:
            respond_model.token = generate_jwt(user_info_form)
        return respond_model
    respond_model.message = 'error'
    return respond_model
Esempio n. 2
0
def all_plugin_info(lang):
    """
        return all plugin info available in the server
    :return: respond_model
    """
    respond_model = RespondModel()
    respond_model.data = get_all_plugin_info(lang)
    return respond_model
def install_by_version():
    """
        get all user info
    :return:
    """
    respond_model = RespondModel()
    respond_model.data = get_all_user_info()
    return respond_model
Esempio n. 4
0
def get_node():
    """
        get current node info
    """
    respond_model = RespondModel()
    node_info = get_node_info()
    if node_info:
        respond_model.data = node_info
    return respond_model
Esempio n. 5
0
def del_user(username):
    """
        del user
    :return:
    """
    respond_model = RespondModel()
    respond_model.data = del_user_by_username(username)
    delete_user_setting(username)
    return respond_model
Esempio n. 6
0
def cluster_run_scan():
    """
        heart beat check
    """
    request_model = RequestModel(request)
    data = request_model.data
    respond_model = RespondModel()
    respond_model.data = run_scan_from_master(data.get('plugin_name'), data.get('user_setting'), data.get('query'))
    return respond_model
Esempio n. 7
0
def test_canvas():
    """
        test canvas setting
    :return: respond_model
    """
    request_model = RequestModel(request)
    user = request_model.data.get('user_info')
    respond_model = RespondModel()
    respond_model.data = check_canvas_setting(user)
    return respond_model
Esempio n. 8
0
def plugin_infos():
    """
        return all plugins info which user have the authority to access
    :return: respond_model
    """
    plugin_names = request.args.get("pluginNames")
    lang = request.args.get("lang")
    respond_model = RespondModel()
    respond_model.data = get_plugin_infos(plugin_names, lang)
    return respond_model
Esempio n. 9
0
def sign_up():
    """
        user sign up
    :return:
    """
    request_model = RequestModel(request)
    respond_model = RespondModel()
    respond_model.data = user_service.user_sign_up(request_model.data.get('user_info'))
    respond_model.code = 20000
    return respond_model.dump_json()
Esempio n. 10
0
def del_user(username):
    """
        del user
    :return:
    """
    respond_model = RespondModel()
    respond_model.data = del_user_by_username(username)
    del_libraries_setting_by_username(username)
    del_plugin_setting_by_username(username)
    return respond_model
Esempio n. 11
0
def get_plugin_version_info():
    """
        get all plugin version from github
    :return:
    """
    respond_model = RespondModel()
    request_model = RequestModel(request)
    respond_model.data = get_plugin_version_from_github(
        request_model.data.get('github'))
    return respond_model
Esempio n. 12
0
 def fun_dec(*args, **kwargs):
     request_model = RequestModel(request)
     user_info = decode_jwt(request_model.token)['user_info']
     if self.roles in user_info.get('roles'):
         respond_model = api_function(*args, **kwargs)
         return respond_model
     else:
         respond_model = RespondModel()
         respond_model.message = 'authorization error'
         return respond_model
def detail():
    """
        return all libraries settings detail
    :return: respond_model
    """
    request_model = RequestModel(request)
    jwt = request_model.token
    user_info_jwt = decode_jwt(jwt)['user_info']
    respond_model = RespondModel()
    respond_model.data = libraries_detail(user_info_jwt['name'], request_model.data.get('libraries'))
    return respond_model
def libraries_settings():
    """
        return all libraries settings by user
    :return: respond_model
    """
    request_model = RequestModel(request)
    jwt = request_model.token
    user_info_jwt = decode_jwt(jwt)['user_info']
    respond_model = RespondModel()
    respond_model.data = get_libraries_settings(user_info_jwt['name'])
    return respond_model
Esempio n. 15
0
def install_new_plugin():
    """
        install new plugin
    :return:
    """
    request_model = RequestModel(request)
    respond_model = RespondModel()
    respond_model.data = install_plugin(request_model.data.get('github'))
    # install plugin requirements
    install_plugin_require()
    return respond_model
def manual_scan():
    """
        manual scan
    :return: respond model with metaDate
    """
    respond_model = RespondModel()
    request_model = RequestModel(request)
    jwt = request_model.token
    user_info_jwt = decode_jwt(jwt)['user_info']
    meta_data_list = run_manual_scan(request_model.data, user_info_jwt)
    respond_model.data = meta_data_list
    return respond_model
Esempio n. 17
0
def install_by_version():
    """
        install plugin by version
    :return:
    """
    request_model = RequestModel(request)
    respond_model = RespondModel()
    respond_model.data = install_plugin_version(
        request_model.data.get('github'), request_model.data.get('version'))
    # install plugin requirements
    install_plugin_require()
    return respond_model
Esempio n. 18
0
def user_info():
    """
        get user info
    :return: respond model
    """
    request_model = RequestModel(request)
    jwt = request_model.token
    user_info_jwt = decode_jwt(jwt)['user_info']
    respond_model = RespondModel()
    respond_model.message = 'success'
    respond_model.data = user_info_jwt
    return respond_model
    def fun_dec(*args, **kwargs):
        request_model = RequestModel(request)
        if validate_master(request_model.data.get("token")):
            respond_model = api_function(*args, **kwargs)
            respond_model.code = 20000
            respond_model.message = 'success'
            return respond_model.dump_json(), 200

        else:
            respond_model = RespondModel()
            respond_model.message = 'authorization error'
            respond_model.code = 50012
            return respond_model.dump_json(), 403
Esempio n. 20
0
def plugin_info(lang, plugin_name):
    """
        return plugin info if user have authority
    :param lang: language for i18n
    :param plugin_name: plugin name
    :return: respond_model
    """
    respond_model = RespondModel()
    if not plugin_authorization(plugin_name):
        respond_model.message = 'authorization error'
        return respond_model
    respond_model.data = get_plugin_info(plugin_name, lang)
    return respond_model
Esempio n. 21
0
def get_admin_log():
    """
        get plugin full log
    :return: {
                "length" : "length of log file",
                "log" : "log string"
            }
    """
    plugin_log_file = 'log/general.log'
    respond_model = RespondModel()
    file_length = get_log_file_length(plugin_log_file)
    log_string = get_log_string(plugin_log_file)
    respond_model.data = {"length": file_length, "log": log_string}
    return respond_model
def user_info():
    """
        get user info
    :return: respond model
    """
    request_model = RequestModel(request)
    jwt = request_model.token
    user_info_jwt = decode_jwt(jwt)['user_info']
    respond_model = RespondModel()
    respond_model.message = 'success'
    if 'admin' in user_info_jwt.get('roles'):
        user_info_jwt['roles'] = 'admin,' + get_all_plugin_name()
    respond_model.data = user_info_jwt
    return respond_model
Esempio n. 23
0
def get_plugin_log(plugin_name):
    """
        get plugin full log
    :param plugin_name: plugin name
    :return: {
                "length" : "length of log file",
                "log" : "log string"
            }
    """
    plugin_log_file = 'log/plugin/%s.log' % plugin_name
    respond_model = RespondModel()
    file_length = get_log_file_length(plugin_log_file)
    log_string = get_log_string(plugin_log_file)
    respond_model.data = {"length": file_length, "log": log_string}
    return respond_model
Esempio n. 24
0
def get_admin_log_new(line_number):
    """
        get plugin log from specific line
    :param line_number: specific line number
    :return: {
                "length" : "length of log file",
                "log" : "log string"
            }
    """
    plugin_log_file = 'log/general.log'
    respond_model = RespondModel()
    file_length = get_log_file_length(plugin_log_file)
    log_string = get_new_log(plugin_log_file, line_number)
    respond_model.data = {"length": file_length, "log": log_string}
    return respond_model
Esempio n. 25
0
def save_setting(plugin_name):
    """
        save user plugin setting
    :param plugin_name: plugin name
    :return: respond_model
    """
    respond_model = RespondModel()
    request_model = RequestModel(request)
    jwt = request_model.token
    user_info_jwt = decode_jwt(jwt)['user_info']
    if not plugin_authorization(plugin_name):
        respond_model.message = 'authorization error'
        return respond_model
    save_plugin_setting(plugin_name, request_model.data, user_info_jwt)
    return respond_model
def save_token():
    """
        save plugin token
    :return:
    """
    request_model = RequestModel(request)
    jwt = request_model.token
    user_info_jwt = decode_jwt(jwt)['user_info']
    respond_model = RespondModel()
    respond_model.message = 'success'
    token = generate_token(user_info_jwt)
    respond_model.data['token'] = token
    user_info_jwt['token'] = token
    respond_model.token = generate_jwt(user_info_jwt)
    return respond_model
Esempio n. 27
0
def get_setting():
    """
        get setting
    :return: respond model
    """
    request_model = RequestModel(request)
    respond_model = RespondModel()
    jwt = request_model.token
    user_info_jwt = decode_jwt(jwt)['user_info']
    setting = get_setting_by_username(user_info_jwt.get('name'))
    if setting:
        respond_model.data = setting.get('setting')
    else:
        respond_model.data = {}
    return respond_model
Esempio n. 28
0
def get_plugin_log_new(plugin_name, line_number):
    """
        get plugin log from specific line
    :param line_number: specific line number
    :param plugin_name: plugin name
    :return: {
                "length" : "length of log file",
                "log" : "log string"
            }
    """
    plugin_log_file = 'log/plugin/%s.log' % plugin_name
    respond_model = RespondModel()
    file_length = get_log_file_length(plugin_log_file)
    log_string = get_new_log(plugin_log_file, line_number)
    respond_model.data = {"length": file_length, "log": log_string}
    return respond_model
Esempio n. 29
0
def set_node():
    """
        set current node info
    """
    request_model = RequestModel(request)
    respond_model = RespondModel()
    set_node_info(request_model.data)
    return respond_model
Esempio n. 30
0
 def fun_dec(*args, **kwargs):
     request_model = RequestModel(request)
     if request_model.token and verify_jwt(request_model.token):
         respond_model = api_function(*args, **kwargs)
         if not respond_model.token:
             respond_model.token = renew_jwt(request_model.token)
         if respond_model.message == 'authorization error':
             respond_model.code = 50012
             return respond_model.dump_json(), 403
         respond_model.code = 20000
         respond_model.message = 'success'
         return respond_model.dump_json(), 200
     else:
         respond_model = RespondModel()
         respond_model.message = 'authentication error, please login'
         respond_model.code = 50012
         return respond_model.dump_json(), 401