Skip to content

Commit

Permalink
make webui respect Snowstorm.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
Shrecknt committed Feb 22, 2024
1 parent 93619a8 commit 4786154
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 36 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ Other versions of some of the listed programs will probably work but it is not r

Create a postgres database using the [postgres setup script](postgres_setup.sql)

I was too lazy to figure out how environment variables work with svelte, so you are going to have to manually change some stuff in the webui. Try searching for all instances of 'shrecked.dev' in the
`web/` directory and replace that with whatever works best for you.

```sh
git clone https://git.shrecked.dev/Shrecknt/snowstorm.git
cd snowstorm
Expand Down
8 changes: 4 additions & 4 deletions crates/snowstorm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,8 @@ async fn ping_loop(
if duration_since_last_update
> Duration::from_secs(config.scanner.mode_duration)
{
let discovered = state.lock().await.discovered
* config.scanner.mode_duration
/ duration_since_last_update.as_secs().max(1);
println!("discovered {discovered} servers (extrapolated to duration)");
let discovered = state.lock().await.discovered;
println!("discovered {discovered} servers");
requester.0.send(Some((current_mode, discovered)))?;
request_state = RequestState::Requested;
println!("requesting new state");
Expand All @@ -134,6 +132,7 @@ async fn ping_loop(
(current_mode, current_addresses) = new_state;
total_addresses = current_addresses.count_addresses();
assert_ne!(total_addresses, 0);
println!("total addresses = {total_addresses}");
index = 0;
request_state = RequestState::None;
last_update = Instant::now();
Expand All @@ -154,6 +153,7 @@ async fn ping_loop(
(current_mode, current_addresses) = receiver.1.recv()?;
total_addresses = current_addresses.count_addresses();
assert_ne!(total_addresses, 0);
println!("total addresses = {total_addresses}");
index = 0;
request_state = RequestState::None;
last_update = Instant::now();
Expand Down
29 changes: 19 additions & 10 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@
"typescript": "^5.0.0",
"vite": "^5.0.3"
},
"type": "module"
"type": "module",
"dependencies": {
"toml": "^3.0.0"
}
}
2 changes: 0 additions & 2 deletions web/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

<meta name="description" content="mass surveillance for block game" />
<meta property="og:title" content="Snowstorm Server Scanner" />
<meta property="og:image" content="https://snowstorm.shrecked.dev/logo.png" />
<meta property="og:url" content="https://snowstorm.shrecked.dev/" />
<meta property="og:type" content="website">
<meta property="og:site_name" content="Snowstorm" />
<meta property="og:description" content="mass surveillance for block game" />
Expand Down
24 changes: 24 additions & 0 deletions web/src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import fs from "node:fs";
import toml from "toml";

const configFile = fs.readFileSync("../Snowstorm.toml");

export const config: Config = toml.parse(configFile.toString());
export type Config = {
database_url: string,
web: {
enabled: boolean,
listen_uri: boolean,
domain: string,
oauth: {
discord: {
enabled: boolean,
client_id: string
},
forgejo: {
enabled: boolean,
client_id: string
}
}
}
};
5 changes: 5 additions & 0 deletions web/src/routes/Header.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<script>
import { config } from '$lib/config';
export let title = 'title';
export let description = 'description';
</script>

<svelte:head>
<meta property="og:image" content="https://{config.web.domain}/logo.png" />
<meta property="og:url" content="https://{config.web.domain}/" />

<style>
.forgejo-icon {
display: inline-block;
Expand Down
25 changes: 17 additions & 8 deletions web/src/routes/login/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script>
import { config } from '$lib/config';
import Header from '../Header.svelte';
</script>

Expand All @@ -23,13 +24,21 @@
<input type="submit" value="Login" />
<a href="/signup"><input type="button" value="Create Account &UpperRightArrow;" /></a>
</form>
<a
href="https://discord.com/oauth2/authorize?client_id=1077019155410202757&response_type=code&redirect_uri=https%3A%2F%2Fsnowstorm.shrecked.dev%2Foauth2_discord&scope=identify+guilds.members.read"
><input type="button" value="Login with Discord" /></a
>
<a
href="https://git.shrecked.dev/login/oauth/authorize?client_id=2938b5c8-f959-479b-8afe-f6d528470f99&redirect_uri=https%3A%2F%2Fsnowstorm.shrecked.dev%2Foauth2_forgejo&response_type=code"
><input type="button" value="Login with Forgejo" /></a
>
{#if config.web.oauth.discord.enabled}
<a
href="https://discord.com/oauth2/authorize?client_id={config.web.oauth.discord
.client_id}&response_type=code&redirect_uri=https%3A%2F%2F{config.web
.domain}%2Foauth2_discord&scope=identify+guilds.members.read"
><input type="button" value="Login with Discord" /></a
>
{/if}
{#if config.web.oauth.forgejo.enabled}
<a
href="https://git.shrecked.dev/login/oauth/authorize?client_id={config.web.oauth.forgejo
.client_id}&redirect_uri=https%3A%2F%2F{config.web
.domain}%2Foauth2_forgejo&response_type=code"
><input type="button" value="Login with Forgejo" /></a
>
{/if}
<a href="/minecraft_login"><input type="button" value="Login with Minecraft" /></a>
</div>
25 changes: 17 additions & 8 deletions web/src/routes/signup/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script>
import { config } from '$lib/config';
import Header from '../Header.svelte';
</script>

Expand Down Expand Up @@ -26,13 +27,21 @@
<input type="submit" value="Create Account" />
<a href="/login"><input type="button" value="Login &UpperRightArrow;" /></a>
</form>
<a
href="https://discord.com/oauth2/authorize?client_id=1077019155410202757&response_type=code&redirect_uri=https%3A%2F%2Fsnowstorm.shrecked.dev%2Foauth2_discord&scope=identify+guilds.members.read"
><input type="button" value="Login with Discord" /></a
>
<a
href="https://git.shrecked.dev/login/oauth/authorize?client_id=2938b5c8-f959-479b-8afe-f6d528470f99&redirect_uri=https%3A%2F%2Fsnowstorm.shrecked.dev%2Foauth2_forgejo&response_type=code"
><input type="button" value="Login with Forgejo" /></a
>
{#if config.web.oauth.discord.enabled}
<a
href="https://discord.com/oauth2/authorize?client_id={config.web.oauth.discord
.client_id}&response_type=code&redirect_uri=https%3A%2F%2F{config.web
.domain}%2Foauth2_discord&scope=identify+guilds.members.read"
><input type="button" value="Login with Discord" /></a
>
{/if}
{#if config.web.oauth.forgejo.enabled}
<a
href="https://git.shrecked.dev/login/oauth/authorize?client_id={config.web.oauth.forgejo
.client_id}&redirect_uri=https%3A%2F%2F{config.web
.domain}%2Foauth2_forgejo&response_type=code"
><input type="button" value="Login with Forgejo" /></a
>
{/if}
<a href="/minecraft_login"><input type="button" value="Login with Minecraft" /></a>
</div>

0 comments on commit 4786154

Please sign in to comment.