Exemplo n.º 1
0
def shortcut_update():
    name = sanitize(
        request.forms.get('original_name'))  # do not allow editing name
    platform = sanitize(request.forms.get('platform'))
    hidden = sanitize(request.forms.get('hidden'))
    banner = request.files.get('banner')
    content = request.files.get('content')

    shortcuts_file = "{shortcuts_dir}/steam-buddy.{platform}.yaml".format(
        shortcuts_dir=SHORTCUT_DIR, platform=platform)
    shortcuts = load_shortcuts(platform)

    matches = [
        e for e in shortcuts if e['name'] == name and e['cmd'] == platform
    ]
    shortcut = matches[0]

    banner_path = upsert_file(BANNER_DIR, platform, name, banner)
    content_path = upsert_file(CONTENT_DIR, platform, name, content)

    shortcut['name'] = name
    shortcut['cmd'] = platform
    shortcut['hidden'] = hidden == 'on'
    if banner:
        shortcut['banner'] = banner_path
    if content:
        shortcut['dir'] = '"' + os.path.dirname(content_path) + '"'
        shortcut['params'] = '"' + os.path.basename(content_path) + '"'

    yaml.dump(shortcuts, open(shortcuts_file, 'w'), default_flow_style=False)

    redirect('/platforms/{platform}'.format(platform=platform))
Exemplo n.º 2
0
def shortcut_create():
    name = sanitize(request.forms.get('name'))
    platform = sanitize(request.forms.get('platform'))
    hidden = sanitize(request.forms.get('hidden'))
    banner_url = request.forms.get('banner-url')
    banner = request.forms.get('banner')
    content = request.forms.get('content')

    if not name or name.strip() == '':
        redirect('/platforms/{platform}/new'.format(platform=platform))
        return

    name = name.strip()

    shortcuts_file = "{shortcuts_dir}/steam-buddy.{platform}.yaml".format(
        shortcuts_dir=SHORTCUT_DIR, platform=platform)
    shortcuts = load_shortcuts(platform)

    matches = [
        e for e in shortcuts if e['name'] == name and e['cmd'] == platform
    ]
    if len(matches) > 0:
        return 'Shortcut already exists'

    banner_path = None
    if banner:
        (banner_src_path, banner_dst_name) = tmpfiles[banner]
        del tmpfiles[banner]
        banner_path = upsert_file(banner_src_path, BANNER_DIR, platform, name,
                                  banner_dst_name)
    elif banner_url:
        banner_path = os.path.join(BANNER_DIR, platform, "{}.png".format(name))
        if not os.path.isdir(os.path.dirname(banner_path)):
            os.makedirs(os.path.dirname(banner_path))
        download = requests.get(banner_url)
        with open(banner_path, "wb") as banner_file:
            banner_file.write(download.content)

    if content:
        (content_src_path, content_dst_name) = tmpfiles[content]
        del tmpfiles[content]
        content_path = upsert_file(content_src_path, CONTENT_DIR, platform,
                                   name, content_dst_name)

    shortcut = {}
    shortcut['name'] = name
    shortcut['cmd'] = platform
    shortcut['hidden'] = hidden == 'on'
    shortcut['tags'] = [PLATFORMS[platform]]
    if banner or banner_url:
        shortcut['banner'] = banner_path
    if content:
        shortcut['dir'] = '"' + os.path.dirname(content_path) + '"'
        shortcut['params'] = '"' + os.path.basename(content_path) + '"'

    shortcuts.append(shortcut)
    yaml.dump(shortcuts, open(shortcuts_file, 'w'), default_flow_style=False)

    redirect('/platforms/{platform}'.format(platform=platform))
Exemplo n.º 3
0
def shortcut_update():
    name = sanitize(
        request.forms.get('original_name'))  # do not allow editing name
    platform = sanitize(request.forms.get('platform'))
    hidden = sanitize(request.forms.get('hidden'))
    banner_url = request.forms.get('banner-url')
    banner = request.forms.get('banner')
    content = request.forms.get('content')

    shortcuts_file = "{shortcuts_dir}/steam-buddy.{platform}.yaml".format(
        shortcuts_dir=SHORTCUT_DIR, platform=platform)
    shortcuts = load_shortcuts(platform)

    matches = [
        e for e in shortcuts if e['name'] == name and e['cmd'] == platform
    ]
    shortcut = matches[0]

    banner_path = None
    if banner:
        (banner_src_path, banner_dst_name) = tmpfiles[banner]
        del tmpfiles[banner]
        banner_path = upsert_file(banner_src_path, BANNER_DIR, platform, name,
                                  banner_dst_name)
    elif banner_url:
        banner_path = os.path.join(BANNER_DIR, platform, "{}.png".format(name))
        if not os.path.isdir(os.path.dirname(banner_path)):
            os.makedirs(os.path.dirname(banner_path))
        download = requests.get(banner_url)
        with open(banner_path, "wb") as banner_file:
            banner_file.write(download.content)

    if content:
        (content_src_path, content_dst_name) = tmpfiles[content]
        del tmpfiles[content]
        content_path = upsert_file(content_src_path, CONTENT_DIR, platform,
                                   name, content_dst_name)

    shortcut['name'] = name
    shortcut['cmd'] = platform
    shortcut['hidden'] = hidden == 'on'
    if banner or banner_url:
        shortcut['banner'] = banner_path
    if content:
        shortcut['dir'] = '"' + os.path.dirname(content_path) + '"'
        shortcut['params'] = '"' + os.path.basename(content_path) + '"'

    yaml.dump(shortcuts, open(shortcuts_file, 'w'), default_flow_style=False)

    redirect('/platforms/{platform}'.format(platform=platform))
Exemplo n.º 4
0
def settings_update():
    SETTINGS_HANDLER.set_setting(
        "enable_ftp_server",
        sanitize(request.forms.get('enable_ftp_server')) == 'on')
    SETTINGS_HANDLER.set_setting("ftp_username",
                                 sanitize(request.forms.get('ftp_username')))
    SETTINGS_HANDLER.set_setting("ftp_password",
                                 sanitize(request.forms.get('ftp_password')))

    # port number for FTP server
    ftp_port = int(sanitize(request.forms.get('ftp_port')))
    if ftp_port and 1024 < ftp_port < 65536 and ftp_port != 8844:
        SETTINGS_HANDLER.set_setting("ftp_port", ftp_port)

    FTP_SERVER.reload()

    redirect('/settings')
Exemplo n.º 5
0
def shortcut_delete():
    name = sanitize(request.forms.get('name'))
    platform = sanitize(request.forms.get('platform'))

    shortcuts_file = "{shortcuts_dir}/steam-buddy.{platform}.yaml".format(
        shortcuts_dir=SHORTCUT_DIR, platform=platform)
    shortcuts = load_shortcuts(platform)

    matches = [
        e for e in shortcuts if e['name'] == name and e['cmd'] == platform
    ]
    shortcut = matches[0]

    delete_file(CONTENT_DIR, platform, name)
    delete_file(BANNER_DIR, platform, name)

    shortcuts.remove(shortcut)
    yaml.dump(shortcuts, open(shortcuts_file, 'w'), default_flow_style=False)

    redirect('/platforms/{platform}'.format(platform=platform))
Exemplo n.º 6
0
def shortcut_create():
    name = sanitize(request.forms.get('name'))
    platform = sanitize(request.forms.get('platform'))
    hidden = sanitize(request.forms.get('hidden'))
    banner = request.files.get('banner')
    content = request.files.get('content')

    if not name or name.strip() == '':
        redirect('/platforms/{platform}/new'.format(platform=platform))
        return

    name = name.strip()

    shortcuts_file = "{shortcuts_dir}/steam-buddy.{platform}.yaml".format(
        shortcuts_dir=SHORTCUT_DIR, platform=platform)
    shortcuts = load_shortcuts(platform)

    matches = [
        e for e in shortcuts if e['name'] == name and e['cmd'] == platform
    ]
    if len(matches) > 0:
        return 'Shortcut already exists'

    banner_path = upsert_file(BANNER_DIR, platform, name, banner)
    content_path = upsert_file(CONTENT_DIR, platform, name, content)

    shortcut = {}
    shortcut['name'] = name
    shortcut['cmd'] = platform
    shortcut['hidden'] = hidden == 'on'
    shortcut['tags'] = [PLATFORMS[platform]]
    if banner:
        shortcut['banner'] = banner_path
    if content:
        shortcut['dir'] = '"' + os.path.dirname(content_path) + '"'
        shortcut['params'] = '"' + os.path.basename(content_path) + '"'

    shortcuts.append(shortcut)
    yaml.dump(shortcuts, open(shortcuts_file, 'w'), default_flow_style=False)

    redirect('/platforms/{platform}'.format(platform=platform))
Exemplo n.º 7
0
def upload_file_chunk():
    key = request.query.get('patch')
    path = tmpfiles[key][0]
    if not path:
        abort(400)

    tmpfiles[key] = (path, sanitize(request.headers.get('Upload-Name')))

    f = open(path, 'ab')
    f.seek(int(request.headers.get('Upload-Offset')))
    f.write(request.body.read())
    f.close()
Exemplo n.º 8
0
def start_file_upload():
    file_name = None
    file_data = request.files.get('banner') or request.files.get('content')

    if file_data:
        file_name = sanitize(file_data.filename)

    (_, path) = tempfile.mkstemp()
    key = os.path.basename(path)
    tmpfiles[key] = (path, file_name)

    if file_data:
        file_data.save(path, True)

    return key
Exemplo n.º 9
0
def start_file_upload():
    file_name = None
    file_data = request.files.get('banner') or request.files.get('content')

    if file_data:
        file_name = sanitize(file_data.filename)

    if not os.path.exists(UPLOADS_DIR):
        os.makedirs(UPLOADS_DIR)
    (_, path) = tempfile.mkstemp(dir=UPLOADS_DIR)
    key = os.path.basename(path)
    tmpfiles[key] = (path, file_name)

    if file_data:
        file_data.save(path, True)

    return key
Exemplo n.º 10
0
def settings_update():
    SETTINGS_HANDLER.set_setting(
        "enable_ftp_server",
        sanitize(request.forms.get('enable_ftp_server')) == 'on')

    # Make sure the login password is long enough
    login_password = sanitize(request.forms.get('login_password'))
    if len(login_password) > 7:
        password = bcrypt.hashpw(login_password.encode('utf-8'),
                                 bcrypt.gensalt())
        SETTINGS_HANDLER.set_setting("password", password.decode('utf-8'))

    # Only allow enabling keep password if a password is set
    keep_password = sanitize(request.forms.get('generate_password')) != 'on'
    if keep_password and SETTINGS_HANDLER.get_setting(
            'password') or not keep_password:
        SETTINGS_HANDLER.set_setting("keep_password", keep_password)

    # Make sure the FTP username is not set to empty
    ftp_username = sanitize(request.forms.get('ftp_username'))
    if ftp_username:
        SETTINGS_HANDLER.set_setting("ftp_username", ftp_username)

    # Make sure the FTP password is long enough
    ftp_password = sanitize(request.forms.get('ftp_password'))
    if len(ftp_password) > 7:
        SETTINGS_HANDLER.set_setting("ftp_password", ftp_password)

    # port number for FTP server
    ftp_port = int(sanitize(request.forms.get('ftp_port')))
    if ftp_port and 1024 < ftp_port < 65536 and ftp_port != 8844:
        SETTINGS_HANDLER.set_setting("ftp_port", ftp_port)

    # Delete SSH keys if asked
    ssh_key_ids = SSH_KEY_HANDLER.get_key_ids()
    for key_id in ssh_key_ids:
        if sanitize(request.forms.get(html.escape(key_id)) == 'on'):
            SSH_KEY_HANDLER.remove_key(key_id)

    # After we are done deleting the selected ssh keys, add a new key if specified
    # The add_key function makes sanitization not needed
    SSH_KEY_HANDLER.add_key(request.forms.get('ssh_key'))

    FTP_SERVER.reload()

    redirect('/settings')
Exemplo n.º 11
0
def type_string():
    str = sanitize(request.forms.get('str'))
    try:
        subprocess.call(["xdotool", "type", "--", str])
    finally:
        redirect('/virtual_keyboard')