Merge remote-tracking branch 'origin/master' into upload_rom_and_custom_artwork

This commit is contained in:
zurdi
2023-08-28 09:30:25 +02:00
19 changed files with 126 additions and 81 deletions

View File

@@ -77,9 +77,9 @@ Inspired by [Jellyfin](https://jellyfin.org/), allows you to manage all your gam
Docker should be installed and set up before running the [image](https://hub.docker.com/r/zurdi15/romm/tags).
1. Generate an API key for [IGDB](https://www.igdb.com/), and set the `CLIENT_ID` and `CLIENT_SECRET` variables. _This is required to run a library scan._ Instructions on generating the ID and Secret are [here](https://api-docs.igdb.com/#about). Note that IDGB requires a Twitch account with 2FA enabled to generate the ID and Secret.
1. Generate an API key for [IGDB](https://www.igdb.com/), and set the `IGDB_CLIENT_ID` and `IGDB_CLIENT_SECRET` variables. _This is required to run a library scan._ Instructions on generating the ID and Secret are [here](https://api-docs.igdb.com/#about). Note that IDGB requires a Twitch account with 2FA enabled to generate the ID and Secret.
2. Verify that your library folder structure matches one of the options listed in the [following section](#folder-structure).
3. Create a docker-compose file. See the following example [docker-compose.yml](https://github.com/zurdi15/romm/blob/master/examples/docker-compose.example.yml) file for reference. Customize for your setup and include the `CLIENT_ID` and `CLIENT_SECRET` vareiables where indicated in the environment section of the file.
3. Create a docker-compose file. See the following example [docker-compose.yml](https://github.com/zurdi15/romm/blob/master/examples/docker-compose.example.yml) file for reference. Customize for your setup and include the `IGDB_CLIENT_ID` and `IGDB_CLIENT_SECRET` vareiables where indicated in the environment section of the file.
4. Launch the container:
```bash

21
SECURITY.md Normal file
View File

@@ -0,0 +1,21 @@
Thanks for helping make RomM safer for everyone.
## Reporting Security Issues
If you believe you have found a security vulnerability in RomM, please report it to us through coordinated disclosure.
**Do not report security vulnerabilities through public GitHub issues, discussions, pull requests, or on our public Discord server.**
Instead, use the [vulnerability report form](https://github.com/zurdi15/romm/security/advisories/new) on GitHub.
Please include as much of the information listed below as you can to help us better understand and resolve the issue:
- The type of issue (e.g., permission bypass, remote code execution, etc.)
- Full paths of source file(s) related to the manifestation of the issue
- The location of the affected source code (tag/branch/commit or direct URL)
- Any special configuration required to reproduce the issue
- Step-by-step instructions to reproduce the issue
- Proof-of-concept or exploit code (if possible)
- Impact of the issue (including how an attacker might exploit the issue)
This information will help us investigate and patch the issue more quickly.

View File

@@ -37,13 +37,19 @@ DB_PASSWD: Final = os.environ.get("DB_PASSWD")
DB_NAME: Final = os.environ.get("DB_NAME", "romm")
# REDIS
ENABLE_EXPERIMENTAL_REDIS: Final = os.environ.get("ENABLE_EXPERIMENTAL_REDIS", "false") == "true"
ENABLE_EXPERIMENTAL_REDIS: Final = (
os.environ.get("ENABLE_EXPERIMENTAL_REDIS", "false") == "true"
)
REDIS_HOST: Final = os.environ.get("REDIS_HOST", "localhost")
REDIS_PORT: Final = os.environ.get("REDIS_PORT", "6379")
# IGDB
CLIENT_ID: Final = os.environ.get("CLIENT_ID", "")
CLIENT_SECRET: Final = os.environ.get("CLIENT_SECRET", "")
IGDB_CLIENT_ID: Final = os.environ.get(
"IGDB_CLIENT_ID", os.environ.get("CLIENT_ID", "")
)
IGDB_CLIENT_SECRET: Final = os.environ.get(
"IGDB_CLIENT_SECRET", os.environ.get("CLIENT_SECRET", "")
)
# STEAMGRIDDB
STEAMGRIDDB_API_KEY: Final = os.environ.get("STEAMGRIDDB_API_KEY", "")

View File

@@ -134,7 +134,6 @@ def update_user(
status_code=400,
detail="Cannot update user: ROMM_AUTH_ENABLED is set to False",
)
print(form_data.username)
user = dbh.get_user(user_id)
if not user:
raise HTTPException(status_code=404, detail="User not found")

View File

@@ -3,14 +3,14 @@ import socketio # type: ignore
from rq import Queue
from logger.logger import log
from config import ENABLE_EXPERIMENTAL_REDIS
from utils import fs, fastapi
from exceptions.fs_exceptions import PlatformsNotFoundException, RomsNotFoundException
from handler import dbh
from utils.socket import socket_server
from utils.cache import redis_client, redis_url, redis_connectable
from utils.cache import redis_client, redis_url
from endpoints.platform import PlatformSchema
from endpoints.rom import RomSchema
from config import ENABLE_EXPERIMENTAL_REDIS
scan_queue = Queue(connection=redis_client)
@@ -21,7 +21,7 @@ async def scan_platforms(
# Connect to external socketio server
sm = (
socketio.AsyncRedisManager(redis_url, write_only=True)
if redis_connectable
if ENABLE_EXPERIMENTAL_REDIS
else socket_server
)
@@ -89,7 +89,7 @@ async def scan_handler(_sid: str, options: dict):
selected_roms = options.get("roms", [])
# Run in worker if redis is available
if redis_connectable and ENABLE_EXPERIMENTAL_REDIS:
if ENABLE_EXPERIMENTAL_REDIS:
return scan_queue.enqueue(
scan_platforms, platform_slugs, complete_rescan, selected_roms
)

View File

@@ -8,7 +8,7 @@ from unidecode import unidecode as uc
from requests.exceptions import HTTPError, Timeout
from typing import Final
from config import CLIENT_ID, CLIENT_SECRET
from config import IGDB_CLIENT_ID, IGDB_CLIENT_SECRET
from utils import get_file_name_with_no_tags as get_search_term
from logger.logger import log
from utils.cache import cache
@@ -29,7 +29,7 @@ class IGDBHandler:
self.screenshots_url = "https://api.igdb.com/v4/screenshots/"
self.twitch_auth = TwitchAuth()
self.headers = {
"Client-ID": CLIENT_ID,
"Client-ID": IGDB_CLIENT_ID,
"Authorization": f"Bearer {self.twitch_auth.get_oauth_token()}",
"Accept": "application/json",
}
@@ -49,9 +49,23 @@ class IGDBHandler:
try:
res = requests.post(url, data, headers=self.headers, timeout=timeout)
res.raise_for_status()
return res.json()
except (HTTPError, Timeout) as err:
if err.response.status_code != 401:
log.error(err)
return [] # All requests to the IGDB API return a list
# Attempt to force a token refresh if the token is invalid
log.warning("Twitch token invalid: fetching a new one...")
token = self.twitch_auth._update_twitch_token()
self.headers["Authorization"] = f"Bearer {token}"
try:
res = requests.post(url, data, headers=self.headers, timeout=timeout)
res.raise_for_status()
except (HTTPError, Timeout) as err:
# Log the error and return an empty list if the request fails again
log.error(err)
# All requests to the IGDB API return a list
return []
return res.json()
@@ -206,8 +220,8 @@ class TwitchAuth:
res = requests.post(
url="https://id.twitch.tv/oauth2/token",
params={
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
"client_id": IGDB_CLIENT_ID,
"client_secret": IGDB_CLIENT_SECRET,
"grant_type": "client_credentials",
},
timeout=30,

View File

@@ -1,15 +1,10 @@
from redis import Redis, ConnectionError
from redis import Redis
from config import REDIS_HOST, REDIS_PORT
from config import REDIS_HOST, REDIS_PORT, ENABLE_EXPERIMENTAL_REDIS
redis_client = Redis(host=REDIS_HOST, port=int(REDIS_PORT), db=0)
redis_url = f"redis://{REDIS_HOST}:{REDIS_PORT}"
try:
redis_connectable = redis_client.ping()
except ConnectionError:
redis_connectable = False
class FallbackCache:
def __init__(self) -> None:
@@ -42,4 +37,4 @@ _cache_client = Redis(
host=REDIS_HOST, port=int(REDIS_PORT), db=0, decode_responses=True
)
_fallback_cache = FallbackCache()
cache = _cache_client if redis_connectable else _fallback_cache
cache = _cache_client if ENABLE_EXPERIMENTAL_REDIS else _fallback_cache

View File

@@ -1,6 +1,7 @@
import socketio # type: ignore
from utils.cache import redis_url, redis_connectable
from utils.cache import redis_url
from config import ENABLE_EXPERIMENTAL_REDIS
socket_server = socketio.AsyncServer(
@@ -8,7 +9,9 @@ socket_server = socketio.AsyncServer(
async_mode="asgi",
logger=False,
engineio_logger=False,
client_manager=socketio.AsyncRedisManager(redis_url) if redis_connectable else None,
client_manager=socketio.AsyncRedisManager(redis_url)
if ENABLE_EXPERIMENTAL_REDIS
else None,
)
socket_app = socketio.ASGIApp(socket_server)

View File

@@ -2,13 +2,13 @@ import sys
from rq import Worker, Queue, Connection
from config import ENABLE_EXPERIMENTAL_REDIS
from utils.cache import redis_client, redis_connectable
from utils.cache import redis_client
listen = ["high", "default", "low"]
if __name__ == "__main__":
# Exit if Redis is not connectable
if not redis_connectable or not ENABLE_EXPERIMENTAL_REDIS:
# Exit if Redis is not enabled
if not ENABLE_EXPERIMENTAL_REDIS:
sys.exit(0)
with Connection(redis_client):

View File

@@ -2,8 +2,8 @@ ROMM_BASE_PATH=/path/to/romm_mock
VITE_BACKEND_DEV_PORT=5000
# IGDB credentials
CLIENT_ID=
CLIENT_SECRET=
IGDB_CLIENT_ID=
IGDB_CLIENT_SECRET=
# STEAMGRIDDB API key
STEAMGRIDDB_API_KEY=

View File

@@ -1,4 +1,4 @@
version: '3'
version: "3"
volumes:
mysql_data:
services:
@@ -6,52 +6,58 @@ services:
image: zurdi15/romm:latest
container_name: romm
environment:
- ROMM_DB_DRIVER=mariadb # mariadb | sqlite (defaults to sqlite)
- DB_HOST=mariadb # [Optional]
- DB_PORT=3306 # [Optional]
- DB_USER=romm-user # [Optional]
- DB_NAME=romm # [Optional] Should match the MYSQL_DATABASE value in the mariadb container
- DB_PASSWD=<database password> # [Optional]
# - REDIS_HOST=redis # [Optional] Enables running long tasks (full rescans) in the background
# - REDIS_PORT=6379 # [Optional]
- CLIENT_ID=<IGDB client id> # [Optional] Required to fetch metadata from IGDB
- CLIENT_SECRET=<IGDB client secret> # [Optional]
- STEAMGRIDDB_API_KEY=<SteamGridDB api key> # [Optional] Only needed if you want to use SteamGridDB as a source for covers
- ROMM_AUTH_ENABLED=true # [Optional] Will enable user management and require authentication to access the interface (default to false)
- ROMM_AUTH_SECRET_KEY=<secret key> # [Optional]/[Mandatory if ROMM_AUTH_ENABLED=true] Used to encrypt user passwords, generate one with `openssl rand -hex 32`
- ROMM_AUTH_USERNAME=admin # [Optional] Username for default admin user
- ROMM_AUTH_PASSWORD=<admin password> # [Optional] Password for default admin user (defaults to admin)
- ROMM_DB_DRIVER=mariadb # mariadb | sqlite (default: sqlite)
# [Optional] Only required if using MariaDB as the database
- DB_HOST=mariadb
- DB_PORT=3306
- DB_USER=romm-user
- DB_NAME=romm # Should match the MYSQL_DATABASE value in the mariadb container
- DB_PASSWD=<database password>
# [Optional] Used to fetch metadata from IGDB
- IGDB_CLIENT_ID=<IGDB client id>
- IGDB_CLIENT_SECRET=<IGDB client secret>
# [Optional] Use SteamGridDB as a source for covers
- STEAMGRIDDB_API_KEY=<SteamGridDB api key>
# [Optional] Will enable user management and require authentication to access the interface (default to false)
- ROMM_AUTH_ENABLED=true # default: false
- ROMM_AUTH_SECRET_KEY=<secret key> # Generate a key with `openssl rand -hex 32`
- ROMM_AUTH_USERNAME=admin # default: admin
- ROMM_AUTH_PASSWORD=<admin password> # default: admin
# [Optional] Only required if authentication is enabled
- ENABLE_EXPERIMENTAL_REDIS=true # default: false
- REDIS_HOST=redis # default: localhost
- REDIS_PORT=6379 # default: 6379
volumes:
- '/path/to/library:/romm/library'
- '/path/to/resources:/romm/resources' # [Optional] Path where roms metadata (covers) are stored
- '/path/to/config.yml:/romm/config.yml' # [Optional] Path where config is stored
- '/path/to/database:/romm/database' # [Optional] Only needed if ROMM_DB_DRIVER=sqlite or ROMM_DB_DRIVER not exists
- '/path/to/logs:/romm/logs' # [Optional] Path where RomM logs are stored
- "/path/to/library:/romm/library"
- "/path/to/resources:/romm/resources" # [Optional] Path where roms metadata (covers) are stored
- "/path/to/config.yml:/romm/config.yml" # [Optional] Path where config is stored
- "/path/to/database:/romm/database" # [Optional] Only needed if ROMM_DB_DRIVER=sqlite or not set
- "/path/to/logs:/romm/logs" # [Optional] Path where logs are stored
ports:
- 80:80
depends_on:
- romm_db
restart: "unless-stopped"
# [Optional] Only needed if ROMM_DB_DRIVER=mariadb
# [Optional] Only required if using MariaDB as the database
mariadb:
image: mariadb:latest
container_name: mariadb
environment:
- MYSQL_ROOT_PASSWORD=RootPasswordChangeMe
- MYSQL_ROOT_PASSWORD=<root password>
- MYSQL_DATABASE=romm
- MYSQL_USER=romm-user
- MYSQL_PASSWORD=change-me
- MYSQL_PASSWORD=<database password>
volumes:
- mysql_data:/var/lib/mysql # Can also be mounted locally if preferred
- mysql_data:/var/lib/mysql # Can also be mounted locally
ports:
- 3306:3306
restart: "unless-stopped"
# [Optional][Experimental]
# redis:
# image: redis:alpine
# container_name: redis
# restart: unless-stopped
# ports:
# - 6379:6379
# [Optional] Only required if experimental Redis is enabled
redis:
image: redis:alpine
container_name: redis
restart: unless-stopped
ports:
- 6379:6379

View File

@@ -1,20 +1,20 @@
<script setup>
import { onBeforeMount } from "vue";
import { useTheme } from "vuetify";
import axios from "axios";
import cookie from "js-cookie";
import { themes } from "@/styles/themes";
import storeAuth from "@/stores/auth";
import Notification from "@/components/Notification.vue";
import { api } from "./services/api";
// Props
const auth = storeAuth();
onBeforeMount(async () => {
// Set CSRF token for all requests
const { data } = await axios.get("/api/heartbeat");
const { data } = await api.get("/heartbeat");
auth.setEnabled(data.ROMM_AUTH_ENABLED ?? false);
axios.defaults.headers.common["x-csrftoken"] = cookie.get("csrftoken");
api.defaults.headers.common["x-csrftoken"] = cookie.get("csrftoken");
});
useTheme().global.name.value =

View File

@@ -19,10 +19,6 @@ emitter.on("showEditRomDialog", (romToEdit) => {
async function updateRom() {
if (rom.value.file_name.includes("/")) {
emitter.emit("snackbarShow", {
msg: "Couldn't edit rom: invalid file name characters",
icon: "mdi-close-circle",
color: "red",
});
return;
} else if (!rom.value.file_name) {

View File

@@ -13,7 +13,6 @@ emitter.on("showEditUserDialog", (userToEdit) => {
});
function editUser() {
console.log(user.value)
updateUserApi(user.value)
.then((response) => {
emitter.emit("snackbarShow", {

View File

@@ -1,9 +1,9 @@
<script setup>
import { inject } from "vue";
import { useRouter } from "vue-router";
import axios from "axios";
import storeAuth from "@/stores/auth";
import { defaultAvatarPath } from "@/utils/utils"
import { api } from "@/services/api";
// Props
const props = defineProps(["rail"]);
@@ -13,8 +13,8 @@ const auth = storeAuth();
// Functions
async function logout() {
axios
.post("/api/logout", {})
api
.post("/logout", {})
.then(({ data }) => {
emitter.emit("snackbarShow", {
msg: data.message,

View File

@@ -3,7 +3,7 @@ import storeDownload from "@/stores/download";
import socket from "@/services/socket";
import router from "@/plugins/router";
let api = axios.create({ baseURL: "/api", timeout: 120000 });
export const api = axios.create({ baseURL: "/api", timeout: 120000 });
api.interceptors.response.use(
(response) => response,

View File

@@ -254,7 +254,6 @@ onBeforeRouteUpdate(async (to, _) => {
</template>
<style scoped>
.game-card.game-selected {
border: 2px solid rgba(var(--v-theme-romm-accent-2));
padding: 0;

View File

@@ -1,8 +1,8 @@
<script setup>
import { ref, inject, onBeforeMount } from "vue";
import { useRouter } from "vue-router";
import axios from "axios";
import storeAuth from "@/stores/auth";
import { api } from "@/services/api";
// Props
const auth = storeAuth();
@@ -13,9 +13,9 @@ const password = ref();
const visiblePassword = ref(false);
function login() {
axios
api
.post(
"/api/login",
"/login",
{},
{
auth: {

View File

@@ -33,12 +33,19 @@
<Config Name="Resources" Target="/romm/resources/" Default="" Mode="rw" Description="Metadata storage (covers, screenshots, etc.)" Type="Path" Display="always" Required="false" Mask="false">/mnt/user/appdata/romm/resources</Config>
<Config Name="Logs" Target="/romm/logs" Default="" Mode="rw" Description="Log file storage" Type="Path" Display="always" Required="false" Mask="false">/mnt/user/appdata/romm/logs</Config>
<Config Name="Database" Target="/romm/database" Default="" Mode="rw" Description="Only needed if using SQLite" Type="Path" Display="always" Required="false" Mask="false">/mnt/user/appdata/romm/database</Config>
<Config Name="CLIENT_ID" Target="CLIENT_ID" Default="" Mode="" Description="IGDB Client ID" Type="Variable" Display="always" Required="true" Mask="false"/>
<Config Name="CLIENT_SECRET" Target="CLIENT_SECRET" Default="" Mode="" Description="IGDB Client Secret" Type="Variable" Display="always" Required="true" Mask="true"/>
<Config Name="IGDB_CLIENT_ID" Target="IGDB_CLIENT_ID" Default="" Mode="" Description="IGDB Client ID" Type="Variable" Display="always" Required="true" Mask="false"/>
<Config Name="IGDB_CLIENT_SECRET" Target="IGDB_CLIENT_SECRET" Default="" Mode="" Description="IGDB Client Secret" Type="Variable" Display="always" Required="true" Mask="true"/>
<Config Name="DB_DRIVER" Target="DB_DRIVER" Default="sqlite" Mode="" Description="Database driver (mariadb or sqlite)" Type="always" Display="always" Required="false" Mask="false"/>
<Config Name="DB_HOST" Target="DB_HOST" Default="mariadb" Mode="" Description="Database host" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="DB_PORT" Target="DB_PORT" Default="3306" Mode="" Description="Database port" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="DB_USER" Target="DB_USER" Default="romm" Mode="" Description="Database user" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="DB_NAME" Target="DB_NAME" Default="romm" Mode="" Description="Database name" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="DB_PASSWD" Target="DB_PASSWD" Default="" Mode="" Description="Database password for DB_USER" Type="Variable" Display="advanced" Required="false" Mask="true"/>
</Container>
<Config Name="ENABLE_EXPERIMENTAL_REDIS" Target="ENABLE_EXPERIMENTAL_REDIS" Default="false" Mode="" Description="Enable Redis (experimental)" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="REDIS_HOST" Target="REDIS_HOST" Default="127.0.0.1" Mode="" Description="Redis host" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="REDIS_PORT" Target="REDIS_PORT" Default="6379" Mode="" Description="Redis port" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="ROMM_AUTH_ENABLED" Target="ROMM_AUTH_ENABLED" Default="false" Mode="" Description="Enable authentication" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="ROMM_AUTH_USERNAME" Target="ROMM_AUTH_USERNAME" Default="admin" Mode="" Description="Default admin username" Type="Variable" Display="advanced" Required="false" Mask="false"/>
<Config Name="ROMM_AUTH_PASSWORD" Target="ROMM_AUTH_PASSWORD" Default="" Mode="" Description="Default admin password" Type="Variable" Display="advanced" Required="false" Mask="true"/>
<Config Name="ROMM_AUTH_SECRET_KEY" Target="ROMM_AUTH_SECRET_KEY" Default="" Mode="" Description="Generate a key with `openssl rand -hex 32`" Type="Variable" Display="advanced" Required="false" Mask="true"/>
</Container>