コード例 #1
0
def logout(headers, body, data):
    cookie = str(headers['http-cookie']).replace('sessionid=', '')
    if not cookie_check(cookie):
        return render_template('html/home.html',
                               body=body,
                               data=data,
                               headers=headers,
                               message='Zostales wylogowany!'), 200, {}
    disable_cookie(cookie)
    return render_template('html/redirect.html',
                           body=body,
                           data=data,
                           headers=headers,
                           message='Trwa wylogowywanie...'), 200, {}
コード例 #2
0
def addsnippet(headers, body, data):
    #login = str(data['login']) if 'login' in data else ''
    # password = str(data['password']) if 'password' in data else ''
    cookie = str(headers['http-cookie']).replace('sessionid=', '')
    if not cookie_check(cookie):
        return redirect(headers=headers,
                        body=body,
                        data=data,
                        message="Nieautoryzowana proba dodania snippet'a!")

    snippet_content = str(data['snippet']) if 'snippet' in data else ''
    title = str(data['title']) if 'title' in data else ''

    if (title == '' or snippet_content == ''):
        return render_template('html/addsnippet.html',
                               body=body,
                               data=data,
                               headers=headers,
                               cookie=cookie), 200, {}
    elif len(title) > 60:
        return render_template(
            'html/addsnippet.html',
            body=body,
            data=data,
            headers=headers,
            cookie=cookie,
            message="Maksymalna dlugosc nazwy snippet'a to 24 znaki!"
        ), 200, {}
    elif len(snippet_content) > 9999:
        return render_template(
            'html/addsnippet.html',
            body=body,
            data=data,
            headers=headers,
            cookie=cookie,
            message="Dodany przez Ciebie plik jest zbyt dlugi!"), 200, {}

    add_snippet(title, snippet_content, cookie)
    return redirect(headers=headers,
                    body=body,
                    data=data,
                    message='Snippet zostal dodany!')
コード例 #3
0
def home(headers, body, data):
    login = str(data['login']) if 'login' in data else ''
    password = str(data['password']) if 'password' in data else ''
    cookie = str(headers['http-cookie']).replace('sessionid=', '')
    # if (login == '') and (password == ''):
    if cookie_check(cookie):
        dbfile = '/home/wolonkia/vial/genbase.db'
        conn = sqlite3.connect(dbfile)
        cursor = conn.cursor()
        cursor.execute('SELECT title, login, time FROM snippets ORDER BY time')
        snippets_result = cursor.fetchall()
        snippets_values = []
        for row in snippets_result:
            snippets_values.append({'title': str(row[0]), 'login': str(row[1]), 'date': str(row[2])})
        cursor.execute('SELECT login FROM users WHERE cookie = ?;', (cookie,))
        login = str(cursor.fetchone()[0])
        print login
        cursor.execute('SELECT ip FROM logs WHERE login = ? ORDER BY date_time DESC', (login,))
        fetch = cursor.fetchall()
        if len(fetch) >= 2:
            if str(fetch[0][0]) != str(fetch[1][0]):
                return render_template('html/home.html', body=body, data=data, headers=headers,
                                       snippets_values=snippets_values,
                                       message='Wykryto nowe polaczenie do Twojego konta z ip: ' + str(
                                           fetch[1][0])), 200, {}
        return render_template('html/home.html', body=body, data=data, headers=headers,
                               snippets_values=snippets_values,
                               message="Witaj '" + login + "'"), 200, {}

    dbfile = '/home/wolonkia/vial/genbase.db'
    conn = sqlite3.connect(dbfile)
    cursor = conn.cursor()
    cursor.execute('SELECT title, login, time FROM snippets ORDER BY time')
    snippets_result = cursor.fetchall()
    snippets_values = []
    for row in snippets_result:
        snippets_values.append({'title': str(row[0]), 'login': str(row[1]), 'date': str(row[2])})
    return render_template('html/home.html', body=body, data=data, headers=headers, snippets_values=snippets_values,
                           message='Witaj na stronie!'), 200, {'Set-Cookie': cookie}
コード例 #4
0
def editpassword(headers, body, data):
    login = str(data['login']) if 'login' in data else ''
    oldpassword = str(data['oldpassword']) if 'oldpassword' in data else ''
    password = str(data['password']) if 'password' in data else ''
    repassword = str(data['repassword']) if 'repassword' in data else ''
    if (login == '') and (password == ''):
        cookie = str(headers['http-cookie']).replace('sessionid=', '')
        if not cookie_check(cookie):
            return render_template(
                'html/signin.html',
                body=body,
                data=data,
                headers=headers,
                message='Musisz sie zalogowac aby zmienic haslo!'), 200, {}
        dbfile = '/home/wolonkia/vial/genbase.db'
        conn = sqlite3.connect(dbfile)
        cursor = conn.cursor()
        cursor.execute('SELECT login FROM users WHERE cookie = ?;', (cookie, ))
        login = str(cursor.fetchone()[0])
        cursor.execute('SELECT password FROM users WHERE login = ?;',
                       (login, ))
        oldpassword = str(cursor.fetchone()[0])

        if oldpassword == password:
            update_password(login, password)
            # expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
            # cookie = 'sessionid=' + cookie + '; expires=' + expires  # + " ; secure"
            return render_template(
                'html/home.html',
                body=body,
                data=data,
                headers=headers,
                message='Haslo zostalo zmienione pomyslnie!'), 200, {}
    if (oldpassword == '') or (repassword == ''):
        return render_template('html/editpassword.html',
                               body=body,
                               data=data,
                               headers=headers), 200, {}
        if password_length(password):
            return render_template(
                'html/editpassword.html',
                body=body,
                data=data,
                headers=headers,
                message='Wymagana dlugosc hasla od 4 do 24 znakow!'), 200, {}
        if not same_passwords(password, repassword):
            return render_template(
                'html/editpassword.html',
                body=body,
                data=data,
                headers=headers,
                message='Podane hasla nie sa identyczne!'), 200, {}
        if entropy(password) < 45.0:
            return render_template(
                'html/editpassword.html',
                body=body,
                data=data,
                headers=headers,
                message='Haslo jest zbyt slabe, jego entropia: ' +
                str(round(entropy(password), 2))), 200, {}
        return render_template('html/home.html',
                               body=body,
                               data=data,
                               headers=headers), 200, {}

        # return render_template('html/editpassword.html', body=body, data=data, headers=headers), 200, {}
    return render_template('html/home.html',
                           body=body,
                           data=data,
                           headers=headers,
                           message='Witaj na stronie!'), 200, {}
コード例 #5
0
def signin(headers, body, data):
    login = str(data['login']) if 'login' in data else ''
    password = str(data['password']) if 'password' in data else ''
    cookie = str(headers['http-cookie']).replace('sessionid=', '')

    if (login == '') and (password == ''):
        if cookie_check(cookie):
            return render_template('html/home.html',
                                   body=body,
                                   data=data,
                                   headers=headers,
                                   message='Jestes juz zalogowany!'), 200, {}
        return render_template('html/signin.html',
                               body=body,
                               data=data,
                               headers=headers), 200, {}

    # login = str(data['login']) if 'login' in data else ''
    # password = str(data['password']) if 'password' in data else ''
    # dbfile = '/home/wolonkia/vial/genbase.db'
    # conn = sqlite3.connect(dbfile)
    # cursor = conn.cursor()

    # dbpassword = cursor.execute('SELECT password FROM users WHERE login = ?', (login,))
    # passwd = ''
    # for row in dbpassword:
    #    passwd = str(row[0])

    # salt = passwd[:20]
    # for i in range(3):
    #    password = salt.join(password)
    #    password = str((hashlib.sha1(password)).hexdigest())
    # password = salt + password

    # if (login == '') or (password == ''):
    #    cookie = str(headers['http-cookie']).replace('session_id=', '')
    #    if cookie_check(cookie):
    #        return redirect(headers=headers, body=body, data=data, message='Jestes juz zalogowany!')

    #    return render_template('html/signin.html', body=body, data=data, headers=headers), 200, {}

    elif allow_signin(login, headers):
        if authentication(login, password):
            cookie = str(uuid.UUID(bytes=random_bytes(16)).hex)
            expires = dt.datetime.now() + dt.timedelta(minutes=20)
            cookie_update(cookie, expires, login)
            expires = (
                dt.datetime.utcnow() +
                dt.timedelta(minutes=20)).strftime("%a, %d %b %Y %H:%M:%S GMT")
            cookie = 'sessionid=' + cookie + '; expires=' + expires + ";" + "secure"
            add_log(headers, data, True)
            return render_template('html/home.html',
                                   body=body,
                                   data=data,
                                   headers=headers,
                                   message='Zostales zalogowany!'), 200, {
                                       'Set-Cookie': cookie
                                   }
        add_log(headers, data, False)
        return render_template(
            'html/signin.html',
            body=body,
            data=data,
            headers=headers,
            message='Nieprawidlowe dane logowania!'), 200, {}
    add_log(headers, data, False)
    return render_template(
        'html/signin.html',
        body=body,
        data=data,
        headers=headers,
        message='Zbyt wiele blednych prob zalogowania!'), 200, {}