Пример #1
0
    def create_cred(self, service, username, password=None):
        if password is None:
            password = Password.generate(mn=64)

        new_entry = {
            "username": username,
            "password": Password().encrypt(password).decode()
        }
        self.creds[service] = new_entry
        Pwdfile().write(self.creds)
def generate_password():
    password = Password()
    pyperclip.copy(password.generate())
    ent_pass.insert(0, password.generate())
Пример #3
0
def upload_file():

    if request.method == 'GET':
        return render_template('upload.html')

    file = request.files['file']

    if not file.filename:
        return response(request, 'No file selected', 400)

    username = request.form['username']
    password = request.form['password']
    download_password = request.form['download_password']
    expire = '0'
    one_time_download = False

    fb = FbQuery()
    pw = Password(config.get('settings', 'secret_key'))

    user = authenticate(fb, pw, username, password)
    if not user:
        return response(request, 'Invalid username or password', 401)

    allowed_expires = {
        '1h': datetime.now() + relativedelta(hours=1),
        '1d': datetime.now() + relativedelta(days=1),
        '1w': datetime.now() + relativedelta(weeks=1),
        '1m': datetime.now() + relativedelta(months=1),
    }

    if request.form['expire'] in allowed_expires:
        expire = allowed_expires[request.form['expire']].strftime(
            '%Y%m%d%H%M%S')

    if request.form['one_time_download'] == '1':
        one_time_download = True

    if download_password:
        download_password = pw.generate(download_password)

    # Generate download hash
    filename = secure_filename(os.path.basename(file.filename))
    download_hash = hashlib.sha1(filename +
                                 datetime.now().strftime('%f')).hexdigest()

    # Create a directory based on hash and save file to that folder
    try:
        os.mkdir(os.path.join(app.config['UPLOAD_FOLDER'], download_hash))
    except OSError:
        return response(
            request, 'Could not upload file(storage directory does not exist)',
            500)

    file.save(
        os.path.join(app.config['UPLOAD_FOLDER'], download_hash, filename))

    fb.file_add(download_hash, user.id, filename, expire, one_time_download,
                download_password)

    # everything ok, return download url to client
    return response(request, urljoin(app.config['URL'], download_hash), 200)