def update_mac():
    form = UserSearchForm().validate_for_api()
    command = ["/usr/local/bin/update_macaddress.sh", form.openvpn_user_info.data]
    command = ' '.join(str(d) for d in command)
    value = remote_server.onetime_shell(command)
    if re.findall(r'已更新', value):
        return Success(msg='MAC address updated successfully')
    else:
        return NotFound(msg='No MAC information')
Beispiel #2
0
def get_user_ip():
    form = UserSearchForm().validate_for_api()
    command = ["/usr/local/bin/get_user_ip.sh", form.openvpn_user_info.data]
    command = ' '.join(str(d) for d in command)
    value = remote_server.onetime_shell(command)
    if re.findall('未注册', value):
        return ParameterException(msg='未注册')
    elif re.findall('未登入', value):
        return NotFound(msg='Never login')
    else:
        return Success(msg=value)
def download_cert():
    form = UserSearchForm().validate_for_api()
    filename = form.openvpn_user_info.data + ".zip"
    directory = os.path.abspath('/opt/vpnuser/')
    if os.path.isdir(directory):
        response = make_response(send_from_directory(directory, filename, as_attachment=True))
        print("response: ", response)
        response.headers['Access-Control-Allow-Origin'] = '*'
        response.headers['Access-Control-Allow-Methods'] = 'GET'
        response.headers['Access-Control-Allow-Headers'] = 'x-requested-with,content-type'
        response.headers["Content-Disposition"] = "attachment; filename={}".format(filename.encode().decode('latin-1'))
        print("response_headers: ", response.headers)
        if not response:
            return NotFound(msg='File does not exist')
        return response
    return NotFound(msg='Directory does not exist')