diff --git a/src/lib/components/indicatorDot.svelte b/src/lib/components/indicatorDot.svelte index 643ed01..0a0c9b2 100644 --- a/src/lib/components/indicatorDot.svelte +++ b/src/lib/components/indicatorDot.svelte @@ -1,11 +1,9 @@ - + diff --git a/src/lib/components/itemBox.svelte b/src/lib/components/itemBox.svelte index 1038b5d..535f963 100644 --- a/src/lib/components/itemBox.svelte +++ b/src/lib/components/itemBox.svelte @@ -1,38 +1,28 @@ - +
- - +
- {boxData.name.toUpperCase()} + {detail.boxContent.name.toUpperCase()} - {#await check(boxData.name) then status} - - {/await} +
-

{serviceDetail.description}

-

Login with: {serviceDetail.loginMethod}

-

Current status: {serviceDetail.statusMessage}

+

{detail.description}

+

Login with: {detail.loginMethod}

+

Current status: {detail.statusMessage || "Unknown"}

@@ -75,5 +65,12 @@ border-radius: 20px; transition-property: all; transition-duration: 0.2s; + width: 35%; + max-width: 250px; + font-family: sans-serif; + font-size: 14px; + } + .tooltipDesc { + font-size: 18px; } \ No newline at end of file diff --git a/src/lib/scripts/checks/homeassistant.ts b/src/lib/scripts/checks/homeassistant.ts new file mode 100644 index 0000000..b794915 --- /dev/null +++ b/src/lib/scripts/checks/homeassistant.ts @@ -0,0 +1,10 @@ +export async function checkHA()/*: Promise*/ { + const url = "https://ha.fjla.uk" + const data = await fetch(url) + const text = await data.text() + if ( data.status === 200 && text.includes("ha-launch-screen-info-box")) { + return "OK" + } else { + return "Unavailable" + } +} \ No newline at end of file diff --git a/src/lib/scripts/checks/jellyfin.ts b/src/lib/scripts/checks/jellyfin.ts new file mode 100644 index 0000000..e35a896 --- /dev/null +++ b/src/lib/scripts/checks/jellyfin.ts @@ -0,0 +1,10 @@ +export async function checkJellyfin()/*: Promise*/ { + const url = "https://jf.fjla.uk" + const data = await fetch(url) + const text = await data.text() + if ( data.status === 200 && text.includes("Jellyfin")) { + return "OK" + } else { + return "Unavailable" + } +} \ No newline at end of file diff --git a/src/lib/scripts/checks/nextcloud.ts b/src/lib/scripts/checks/nextcloud.ts new file mode 100644 index 0000000..bd95bbe --- /dev/null +++ b/src/lib/scripts/checks/nextcloud.ts @@ -0,0 +1,10 @@ +export async function checkNextcloud()/*: Promise*/ { + const url = "https://cloud.fjla.uk" + const data = await fetch(url) + const text = await data.text() + if ( data.status === 200 && text.includes("Login")) { + return "OK" + } else { + return "Unavailable" + } +} \ No newline at end of file diff --git a/src/lib/scripts/checks/owlboard.ts b/src/lib/scripts/checks/owlboard.ts new file mode 100644 index 0000000..492d770 --- /dev/null +++ b/src/lib/scripts/checks/owlboard.ts @@ -0,0 +1,10 @@ +export async function checkOwlBoard()/*: Promise*/ { + const url = "https://owlboard.info" + const data = await fetch(url) + const text = await data.text() + if ( data.status === 200 && text.includes("Train Details & PIS")) { + return "OK" + } else { + return "Unavailable" + } +} \ No newline at end of file diff --git a/src/lib/scripts/checks/traccar.ts b/src/lib/scripts/checks/traccar.ts new file mode 100644 index 0000000..5a9d39e --- /dev/null +++ b/src/lib/scripts/checks/traccar.ts @@ -0,0 +1,10 @@ +export async function checkTraccar()/*: Promise*/ { + const url = "https://traccar.fjla.uk" + const data = await fetch(url) + const text = await data.text() + if ( data.status === 200 && text.includes("Traccar GPS Tracking System")) { + return "OK" + } else { + return "Unavailable" + } +} \ No newline at end of file diff --git a/src/lib/scripts/checks/webmail.ts b/src/lib/scripts/checks/webmail.ts new file mode 100644 index 0000000..7cc6db1 --- /dev/null +++ b/src/lib/scripts/checks/webmail.ts @@ -0,0 +1,10 @@ +export async function checkWebmail()/*: Promise*/ { + const url = "https://mx0123.fb-infra.uk/mail" + const data = await fetch(url) + const text = await data.text() + if ( data.status === 200 && text.includes("rcube")) { + return "OK" + } else { + return "Unavailable" + } +} \ No newline at end of file diff --git a/src/lib/scripts/serviceDetailMap.ts b/src/lib/scripts/serviceDetailMap.ts new file mode 100644 index 0000000..6b17ff7 --- /dev/null +++ b/src/lib/scripts/serviceDetailMap.ts @@ -0,0 +1,38 @@ +import type { ServiceDetail } from "$lib/types/serviceDetail" + +export const defaultVal: ServiceDetail = {description: "Unknown", loginMethod: "Unknown"} + +export const detailMap = new Map ([ + ["nextcloud", { + description: "Personal Cloud, Organisation and workspace", + loginMethod: "FJLA.net Credentials" + }], + ["gitea", { + description: "Git repositories & development tools", + loginMethod: "FJLA.net Credentials" + }], + ["jellyfin", { + description: "Music, Film and TV Services", + loginMethod: "FJLA.net Credentials" + }], + ["home assistant", { + description: "Smart & Connected Home", + loginMethod: "Home Assistant Credentials" + }], + ["traccar", { + description: "Device and Person Tracking", + loginMethod: "Traccar Credentials" + }], + ["owlboard", { + description: "Live train service data", + loginMethod: "No login required" + }], + ["webmail", { + description: "Mail services for FJLA.net, FJLA.uk, OwlBoard.info & fb-infra.uk", + loginMethod: "Email Credentials" + }], + ["account", { + description: "FJLA.net account settings", + loginMethod: "FJLA.net Credentials" + }] +]) \ No newline at end of file diff --git a/src/lib/scripts/statusChecks.ts b/src/lib/scripts/statusChecks.ts index 331fc24..ca04b28 100644 --- a/src/lib/scripts/statusChecks.ts +++ b/src/lib/scripts/statusChecks.ts @@ -1,4 +1,34 @@ +import { checkHA } from "./checks/homeassistant"; +import { checkJellyfin } from "./checks/jellyfin"; +import { checkNextcloud } from "./checks/nextcloud"; +import { checkOwlBoard } from "./checks/owlboard"; +import { checkTraccar } from "./checks/traccar"; +import { checkWebmail } from "./checks/webmail"; + export async function check(service: string): Promise { - console.log("Check call for: " + service) - return 'not_ok' + let result: string + switch (service) { + case "nextcloud": + result = await checkNextcloud() + break; + case "home assistant": + result = await checkHA() + break; + case "jellyfin": + result = await checkJellyfin() + break; + case "traccar": + result = await checkTraccar() + break; + case "owlboard": + result = await checkOwlBoard() + break; + case "webmail": + result = await checkWebmail() + break; + default: + result = "Unknown" + } + console.log(`${service}: ${result}`) + return result } \ No newline at end of file diff --git a/src/lib/types/serviceDetail.ts b/src/lib/types/serviceDetail.ts index 76a1582..3919c37 100644 --- a/src/lib/types/serviceDetail.ts +++ b/src/lib/types/serviceDetail.ts @@ -1,5 +1,8 @@ +import type { BoxContent } from "./boxContent"; + export interface ServiceDetail { + boxContent?: BoxContent, description: string, loginMethod: string, - statusMessage: string, + statusMessage?: string, } \ No newline at end of file diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts new file mode 100644 index 0000000..ac37a1e --- /dev/null +++ b/src/routes/+page.server.ts @@ -0,0 +1,26 @@ +import type { BoxContent } from "$lib/types/boxContent"; +import type { ServiceDetail } from "$lib/types/serviceDetail"; + +import { check } from "$lib/scripts/statusChecks"; +import { detailMap, defaultVal } from "$lib/scripts/serviceDetailMap"; + +const boxes: BoxContent[] = [ + {name: "nextcloud", link: "https://cloud.fjla.uk", img: "auto"}, + {name: "home assistant", link: "https://ha.fjla.uk", img: "auto"}, + {name: "jellyfin", link: "https://jf.fjla.uk", img: "auto"}, + {name: "traccar", link:"https://traccar.fjla.uk", img: "auto"}, + {name: "owlboard", link:"https://owlboard.info", img:"auto"}, + {name: "webmail", link:"https://mx0123.fb-infra.uk/mail", img: "auto"}, + {name: "account", link:"https://ipa0922.fjla.net", img:"auto"} +] + +export async function load() { + const data: ServiceDetail[] = [] + for (const item of boxes) { + const svcDetail = detailMap.get(item.name.toLowerCase()) || defaultVal + svcDetail.statusMessage = await check(item.name.toLowerCase()) + svcDetail.boxContent = item + data.push(svcDetail) + } + return {data: data} +} \ No newline at end of file diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 3fbf533..0026c74 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,23 +1,19 @@
FJLA Gateway
- {#each boxes as boxData} - + {#each data.data as detail} + {/each}