feat: add configuration - closes #7 for now
This commit is contained in:
parent
a6641d7ceb
commit
6f7e81e08c
18
.env.example
Normal file
18
.env.example
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# How long a user stays signed in, in seconds
|
||||||
|
SESSION_LIFETIME=86400
|
||||||
|
|
||||||
|
# Whether to use the 'Secure' attribute on the session cookie
|
||||||
|
USE_SECURE=true
|
||||||
|
|
||||||
|
# Set to true if you're running this behing a reverse proxy (you should, given there is no built-in SSL support)
|
||||||
|
USE_REVERSE_PROXY=true
|
||||||
|
|
||||||
|
# Name of the header containing the request's emitter's IP adress. No effect is USE_REVERSE_PROXY is false.
|
||||||
|
REAL_IP_HEADER=X-Forwarded-For
|
||||||
|
|
||||||
|
# Uncomment to choose your own default admin password (you should change it afterwards regardless)
|
||||||
|
# Else, a random one will be generated and printed to logs and written to ./data/default_admin_pass.txt
|
||||||
|
# DEFAULT_ADMIN_PASS=changeme
|
||||||
|
|
||||||
|
# Prefix for the tabs' titles
|
||||||
|
PUBLIC_SITE_NAME=WOL Panel
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { env } from '$env/dynamic/private';
|
||||||
import { initRepos, users } from '$lib/server/db';
|
import { initRepos, users } from '$lib/server/db';
|
||||||
import { Guard } from '$lib/server/guard';
|
import { Guard } from '$lib/server/guard';
|
||||||
import { getUserFromSession } from '$lib/server/sessions';
|
import { getUserFromSession } from '$lib/server/sessions';
|
||||||
@ -10,7 +11,16 @@ export const init: ServerInit = async () => {
|
|||||||
await initRepos();
|
await initRepos();
|
||||||
|
|
||||||
if (!(await users.any())) {
|
if (!(await users.any())) {
|
||||||
const pass = nanoid();
|
let pass = env.DEFAULT_ADMIN_PASS;
|
||||||
|
|
||||||
|
if (!pass) {
|
||||||
|
pass = nanoid();
|
||||||
|
|
||||||
|
console.log(`default admin password: ${pass}`);
|
||||||
|
console.log("saved to ./default_admin_pass.txt, don't share it and change it asap");
|
||||||
|
|
||||||
|
writeFileSync('./data/default_admin_pass.txt', pass);
|
||||||
|
}
|
||||||
|
|
||||||
await users.create({
|
await users.create({
|
||||||
name: 'admin',
|
name: 'admin',
|
||||||
@ -19,11 +29,6 @@ export const init: ServerInit = async () => {
|
|||||||
groups: [],
|
groups: [],
|
||||||
devices: [],
|
devices: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`default admin password: ${pass}`);
|
|
||||||
console.log("saved to ./default_admin_pass.txt, don't share it and change it asap");
|
|
||||||
|
|
||||||
writeFileSync('./data/default_admin_pass.txt', pass);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from '$app/state';
|
import { page } from '$app/state';
|
||||||
|
import { env } from '$env/dynamic/public';
|
||||||
import { pageTitle } from '$lib/v2/globalStores.js';
|
import { pageTitle } from '$lib/v2/globalStores.js';
|
||||||
import { slideFade } from '$lib/v2/transitions/slideFade.js';
|
import { slideFade } from '$lib/v2/transitions/slideFade.js';
|
||||||
import NavBar from '$lib/v2/ui/NavBar.svelte';
|
import NavBar from '$lib/v2/ui/NavBar.svelte';
|
||||||
@ -21,7 +22,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>Dashboard - {$pageTitle}</title>
|
<title>{env.PUBLIC_SITE_NAME} - {$pageTitle}</title>
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { dev } from '$app/environment';
|
import { env } from '$env/dynamic/private';
|
||||||
import { PARSE_ERROR } from '$lib/server/commonResponses';
|
import { PARSE_ERROR } from '$lib/server/commonResponses';
|
||||||
import { users } from '$lib/server/db';
|
import { users } from '$lib/server/db';
|
||||||
import { createSession } from '$lib/server/sessions';
|
import { createSession } from '$lib/server/sessions';
|
||||||
@ -42,9 +42,9 @@ export const actions = {
|
|||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: !dev, // safari doesn't allow secure cookies on localhost
|
secure: env.USE_SECURE != 'false',
|
||||||
sameSite: true,
|
sameSite: true,
|
||||||
maxAge: 60 * 60 * 24,
|
maxAge: parseInt(env.SESSION_LIFETIME) || 86400,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>WOL Panel - Sign In</title>
|
<title>{env.PUBLIC_SITE_NAME} - Sign In</title>
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<div class="flex items-center justify-center w-svw h-svh bg-neutral-900">
|
<div class="flex items-center justify-center w-svw h-svh bg-neutral-900">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user