예제 #1
0
def list_on_sections(guid, responseType):

    forceRefresh = False
    if request.args.get("refresh"):
        forceRefresh = str_to_bool(request.args.get("refresh"))

    # Listing the Onenote notebooks
    if is_access_token_valid() == False:
        if responseType == safeglobals.TYPE_JSON:
            return jsonify(status=safeglobals.http_unauthorized,
                           message=safeglobals.MSG_NO_TOKENS)
        elif responseType == safeglobals.TYPE_SELECT:
            return send_response(
                [{
                    "guid": "",
                    "name": "Access token expired or doesn't exist"
                }], responseType, {"default": "select.sections.html"})
        else:
            return render_template("onenote.token.expired.html"), 401

    # Getting a list of sections
    access_token = get_access_token(safeglobals.service_onenote)
    sections = list_sections(access_token, forceRefresh, guid)

    # Returning response based on specified format
    return send_response(sections, responseType,
                         {"default": "select.sections.html"})
예제 #2
0
    def decorated_function(*args, **kwargs):
        '''
            This decorator functions is used to check all provided data while restoring the note. It does the following checks

                1. Checks if GUID has been provided
                2. Checks if the backup exists
                3. Checks the access token
        '''

        # Parsing JSON
        data = request.get_json()
        if not data:
            abort(safeglobals.http_bad_request,
                  {"message": safeglobals.MSG_MANDATORY_MISSING})
        if "guid" not in data:
            abort(safeglobals.http_bad_request,
                  {"message": safeglobals.MSG_MANDATORY_MISSING})

        # Checking that backup exists
        if os.path.exists(safeglobals.path_notes_backup %
                          data['guid']) == False:
            abort(
                safeglobals.http_not_found, {
                    "message":
                    safeglobals.MSG_NOTE_MISSING %
                    safeglobals.path_notes_backup % data['guid']
                })

        # Checking the Evernote/Onenote access token
        if get_access_token(data['service']) == "":
            abort(safeglobals.http_bad_request,
                  {"message": safeglobals.ERROR_NO_TOKEN})

        return f(*args, **kwargs)
예제 #3
0
def list_onenote_notebooks(responseType):

    forceRefresh = False
    if request.args.get("refresh"):
        forceRefresh = str_to_bool(request.args.get("refresh"))

    # Checking the access token
    if is_access_token_valid() == False:
        if responseType == safeglobals.TYPE_JSON:
            return jsonify(status=safeglobals.http_unauthorized,
                           message=safeglobals.MSG_NO_TOKENS)
        elif responseType == safeglobals.TYPE_SELECT:
            return send_response(
                [{
                    "guid": "",
                    "text": "Access token expired or doesn't exist"
                }], responseType, {"default": "onenote.select.notebooks.html"})
        else:
            return render_template("onenote.token.expired.html")

    # Getting access token and getting a list of notebooks
    access_token = get_access_token(safeglobals.service_onenote)
    notebooks = list_on_notebooks(access_token, forceRefresh)

    # Returning response based on specified format
    return send_response(notebooks, responseType,
                         {"default": "onenote.select.notebooks.html"})
예제 #4
0
    def decorated_function(*args, **kwargs):
        '''
            This decorator functions is used to check all provided data while encrypting the existing note. It does the following checks

                1. Checks if it was JSON request 
                2. Checks the data provided in the JSON request
        '''
        # Getting the data
        data = request.get_json()

        if not data:
            abort(safeglobals.http_bad_request,
                  {"message": safeglobals.MSG_MANDATORY_MISSING})
        if "guid" not in data or "mode" not in data or "pass" not in data or "service" not in data:
            abort(safeglobals.http_bad_request,
                  {"message": safeglobals.MSG_MANDATORY_MISSING})
        if data['mode'] == "otp" and data['pass'] == "":
            abort(safeglobals.http_bad_request,
                  {"message": safeglobals.MSG_MANDATORY_MISSING})

        # Checking the Evernote/Onenote access token
        if get_access_token(data['service']) == "":
            abort(safeglobals.http_bad_request,
                  {"message": safeglobals.ERROR_NO_TOKEN})

        # Checking the provided password
        if data['mode'] == "master" and not get_master_password():
            return handle_exception(safeglobals.TYPE_JSON,
                                    safeglobals.http_bad_request,
                                    safeglobals.ERROR_NO_PASSWORD)

        return f(*args, **kwargs)
예제 #5
0
def list_items(service, type, refresh):
    items = []
    notebooks = []
    sections = []
    if (service == "evernote"):
        if (type == "notebooks"):

            # Connecting to Evernote
            access_token = get_access_token()
            note_store = get_note_store(access_token)

            # Loading a list of notebooks
            notebooks = list_notebooks(note_store, access_token, refresh)

            # Collecting items
            for notebook in notebooks:
                items.append({
                    "name": notebook['name'].encode('utf-8'),
                    "guid": notebook['guid'].encode('utf-8'),
                    "parent": "--"
                })

    elif (service == "onenote"):
        if type == "notebooks":
            notebooks = list_on_notebooks(
                get_access_token(safeglobals.service_onenote), refresh)
            for notebook in notebooks:
                items.append({
                    "name": notebook['text'],
                    "guid": notebook['guid'],
                    "parent": "--"
                })
        elif type == "sections":
            sections = list_sections_all(
                get_access_token(safeglobals.service_onenote), refresh)
            for section in sections:
                items.append({
                    "name": section['text'],
                    "guid": section['guid'],
                    "parent": section['parent']
                })

    # Return items
    return items
예제 #6
0
def searches(responseType):
   
    # Getting access token
    access_token = get_access_token()
    if access_token == "":
        abort(safeglobals.http_bad_request,{"message":safeglobals.ERROR_NO_TOKEN})
    
    # Getting a list of Saved Searches
    searches = list_searches(access_token,False)

    # Returing the response based on specified format
    return send_response(searches,responseType,{safeglobals.TYPE_HTML:'list.searches.html'})
예제 #7
0
def restore_from_backup(guid):

    # Getting the note from the backup
    guid = request.get_json().get('guid')
    note = get_from_backup(guid)
    if not note:
        abort(safeglobals.http_internal_server, {"message": ""})

    # Getting Access Token
    access_token = get_access_token()

    # Getting the Note Store (connecting to Evernote)
    note_store = get_note_store(access_token)

    # Connecting to Evernote and updating the note
    update_note(note_store, access_token, note)

    # Sending the response
    return jsonify(status=safeglobals.http_ok,
                   message=safeglobals.MSG_UPDATENOTE_OK)
예제 #8
0
    def decorated_function(*args, **kwargs):
        '''
            This decorator functions is used to check all provided data while creating a new encrypted note                
        '''
        # Checking provided data
        if not request.form['title'] or request.form['title'] == "":
            abort(safeglobals.http_bad_request,
                  {"message": safeglobals.MSG_MANDATORY_MISSING})

        if not request.form['content'] or request.form['content'] == "":
            abort(safeglobals.http_bad_request,
                  {"message": safeglobals.MSG_MANDATORY_MISSING})

        if not request.form['notebook_guid'] or request.form[
                'notebook_guid'] == "":
            abort(safeglobals.http_bad_request,
                  {"message": safeglobals.MSG_MANDATORY_MISSING})

        if request.form[
                'service'] == safeglobals.service_onenote and request.form[
                    'section_guid'] == "":
            abort(safeglobals.http_bad_request,
                  {"message": safeglobals.MSG_MANDATORY_MISSING})

        if "en-media" in request.form[
                'content'] and not request.form['filelist']:
            abort(safeglobals.http_bad_request,
                  {"message": safeglobals.MSG_MANDATORY_MISSING})

        if not request.form['mode']:
            abort(safeglobals.http_bad_request,
                  {"message": safeglobals.MSG_MANDATORY_MISSING})
        if request.form['mode'] == "otp" and not request.form['pass']:
            abort(safeglobals.http_bad_request,
                  {"message": safeglobals.MSG_MANDATORY_MISSING})

        if get_access_token() == "":
            abort(safeglobals.http_bad_request,
                  {"message": safeglobals.ERROR_NO_TOKEN})

        return f(*args, **kwargs)
예제 #9
0
def tags():
    
    # Default values
    forceRefresh = False
    responseType = "html"

    # Checking request parameters
    if request.args.get("refresh"):
        forceRefresh = request.args.get("refresh")
    if request.args.get("format"):
        responseType = request.args.get("format")

    # Getting access token
    access_token = get_access_token()
    if access_token == "":
        abort(safeglobals.http_bad_request,{"message":safeglobals.ERROR_NO_TOKEN})

    # Getting a list of tags
    tags = list_tags(access_token,forceRefresh)

    # Returning response based on specified format
    return send_response(tags,responseType,{safeglobals.TYPE_SELECT:"select.tags.html",safeglobals.TYPE_HTML:'list.tags.html'})
예제 #10
0
def notebooks(responseType):

    # Checking Access Token
    access_token = get_access_token()
    if access_token == "":
        abort(safeglobals.http_bad_request,
              {"message": safeglobals.ERROR_NO_TOKEN})

    forceRefresh = False
    if request.args.get("refresh"):
        forceRefresh = str_to_bool(request.args.get("refresh"))

    # Connecting to Evernote
    note_store = get_note_store(access_token)

    # Getting a list of notebooks
    notebooks = list_notebooks(note_store, access_token, forceRefresh)

    # Returning response based on specified format
    return send_response(
        notebooks, responseType, {
            safeglobals.TYPE_SELECT: "select.notebooks.html",
            safeglobals.TYPE_HTML: "list.notebooks.html"
        })
예제 #11
0
    print "\n     %s\n" % message


# Checking Master password
print_title(safeglobals.TITLE_PRELIM_CHECK)

print("\n    {:36s} ......").format(safeglobals.MSG_PASSWORD_CHECK),
check['master_password'] = (get_master_password() != "")
if check['master_password'] == True:
    print safeglobals.MSG_LABEL_OK
else:
    print safeglobals.MSG_LABEL_NOK

# Checking Evernote developer token
print("    {:36s} ......").format(safeglobals.MSG_TOKEN_CHECK % "Evernote"),
check['developer_token'] = (get_access_token() != "")
if check['developer_token'] == True:
    print safeglobals.MSG_LABEL_OK
else:
    print safeglobals.MSG_LABEL_NOK

# Checking Onenote tokens
print("    {:36s} ......").format(safeglobals.MSG_TOKEN_CHECK % "Onenote"),
check['onenote_token'] = is_access_token_valid()
if check['onenote_token'] == True:
    print safeglobals.MSG_LABEL_OK
else:
    print safeglobals.MSG_LABEL_NOK

# Executing command
if option.which == "encrypt":