From 79bb4e585b0efc8012c646e2757b3e8ff65d845b Mon Sep 17 00:00:00 2001 From: Pujit Mehrotra Date: Tue, 8 Oct 2024 13:53:02 -0400 Subject: [PATCH] refactor(CookieService): use paths store to get default sessions directory instead of a literal --- api/src/store/modules/paths.ts | 30 +++++++++-------------- api/src/unraid-api/auth/cookie.service.ts | 3 ++- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/api/src/store/modules/paths.ts b/api/src/store/modules/paths.ts index a78f817cb..6a5fe88fc 100644 --- a/api/src/store/modules/paths.ts +++ b/api/src/store/modules/paths.ts @@ -5,24 +5,19 @@ const initialState = { core: __dirname, 'unraid-api-base': '/usr/local/bin/unraid-api/' as const, 'unraid-data': resolvePath( - process.env.PATHS_UNRAID_DATA ?? - ('/boot/config/plugins/dynamix.my.servers/data/' as const) + process.env.PATHS_UNRAID_DATA ?? ('/boot/config/plugins/dynamix.my.servers/data/' as const) ), 'docker-autostart': '/var/lib/docker/unraid-autostart' as const, 'docker-socket': '/var/run/docker.sock' as const, 'parity-checks': '/boot/config/parity-checks.log' as const, htpasswd: '/etc/nginx/htpasswd' as const, 'emhttpd-socket': '/var/run/emhttpd.socket' as const, - states: resolvePath( - process.env.PATHS_STATES ?? ('/usr/local/emhttp/state/' as const) - ), + states: resolvePath(process.env.PATHS_STATES ?? ('/usr/local/emhttp/state/' as const)), 'dynamix-base': resolvePath( - process.env.PATHS_DYNAMIX_BASE ?? - ('/boot/config/plugins/dynamix/' as const) + process.env.PATHS_DYNAMIX_BASE ?? ('/boot/config/plugins/dynamix/' as const) ), 'dynamix-config': resolvePath( - process.env.PATHS_DYNAMIX_CONFIG ?? - ('/boot/config/plugins/dynamix/dynamix.cfg' as const) + process.env.PATHS_DYNAMIX_CONFIG ?? ('/boot/config/plugins/dynamix/dynamix.cfg' as const) ), 'myservers-base': '/boot/config/plugins/dynamix.my.servers/' as const, 'myservers-config': resolvePath( @@ -30,22 +25,19 @@ const initialState = { ('/boot/config/plugins/dynamix.my.servers/myservers.cfg' as const) ), 'myservers-config-states': join( - resolvePath( - process.env.PATHS_STATES ?? ('/usr/local/emhttp/state/' as const) - ), + resolvePath(process.env.PATHS_STATES ?? ('/usr/local/emhttp/state/' as const)), 'myservers.cfg' as const ), 'myservers-env': '/boot/config/plugins/dynamix.my.servers/env' as const, 'myservers-keepalive': - process.env.PATHS_MY_SERVERS_FB ?? ('/boot/config/plugins/dynamix.my.servers/fb_keepalive' as const), - 'keyfile-base': resolvePath( - process.env.PATHS_KEYFILE_BASE ?? ('/boot/config' as const) - ), - 'machine-id': resolvePath( - process.env.PATHS_MACHINE_ID ?? ('/var/lib/dbus/machine-id' as const) - ), + process.env.PATHS_MY_SERVERS_FB ?? + ('/boot/config/plugins/dynamix.my.servers/fb_keepalive' as const), + 'keyfile-base': resolvePath(process.env.PATHS_KEYFILE_BASE ?? ('/boot/config' as const)), + 'machine-id': resolvePath(process.env.PATHS_MACHINE_ID ?? ('/var/lib/dbus/machine-id' as const)), 'log-base': resolvePath('/var/log/unraid-api/' as const), 'var-run': '/var/run' as const, + // contains sess_ files that correspond to authenticated user sessions + 'auth-sessions': '/var/lib/php' as const, }; export const paths = createSlice({ diff --git a/api/src/unraid-api/auth/cookie.service.ts b/api/src/unraid-api/auth/cookie.service.ts index 92138ace6..3a4f08a4e 100644 --- a/api/src/unraid-api/auth/cookie.service.ts +++ b/api/src/unraid-api/auth/cookie.service.ts @@ -1,4 +1,5 @@ import { fileExists } from '@app/core/utils/files/file-exists'; +import { getters } from '@app/store'; import { batchProcess } from '@app/utils'; import { Injectable, Inject } from '@nestjs/common'; import { join } from 'path'; @@ -21,7 +22,7 @@ export class CookieService { * @returns new SessionCookieOptions with `namePrefix: 'unraid_', sessionDir: '/var/lib/php'` */ static defaultOpts(): SessionCookieConfig { - return { namePrefix: 'unraid_', sessionDir: '/var/lib/php' }; + return { namePrefix: 'unraid_', sessionDir: getters.paths()['auth-sessions'] }; } /**