Skip to content

Commit

Permalink
refactor(website): adopt new application and repository name
Browse files Browse the repository at this point in the history
lhp -> Host Patrol
  • Loading branch information
vst committed Apr 14, 2024
1 parent 4013460 commit d10190e
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 51 deletions.
2 changes: 1 addition & 1 deletion website/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# lhpui
# Host Patrol Website

## Getting Started

Expand Down
2 changes: 1 addition & 1 deletion website/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
basePath: '/lhp',
basePath: '/hostpatrol',
output: 'export',
images: {
unoptimized: true,
Expand Down
4 changes: 2 additions & 2 deletions website/package-lock.json

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

2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "lhpui",
"name": "hostpatrol-website",
"version": "0.0.0",
"private": true,
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions website/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { Providers } from './providers';
const font = JetBrains_Mono({ subsets: ['latin'] });

export const metadata: Metadata = {
title: 'lhp',
description: "Lazy Hacker's Linux Host Patrol",
title: 'Host Patrol',
description: "Lazy Hacker's Host Patrol",
};

export default function RootLayout({
Expand Down
11 changes: 7 additions & 4 deletions website/src/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ export default function Header() {
classNames={{ base: 'z-50 bg-gray-200' }}
>
<NavbarBrand>
<p className="font-mono text-2xl font-bold tracking-widest text-inherit">lhp</p>
<p className="text-2xl tracking-tight text-inherit">
<span className="font-medium text-gray-700">HOST</span>
<span className="font-black">PATROL</span>
</p>
</NavbarBrand>

<NavbarContent className="hidden md:flex" justify="center">
<NavbarItem>Lazy Hacker&apos;s Linux Host Patrol</NavbarItem>
<NavbarItem>Lazy Hacker&apos;s Host Patrol</NavbarItem>
</NavbarContent>

<NavbarContent justify="end">
Expand All @@ -45,7 +48,7 @@ export default function Header() {
</NavbarItem>

<NavbarItem className="hidden sm:flex">
<Link href="https://github.com/vst/lhp" className="w-full">
<Link href="https://github.com/vst/hostpatrol" className="w-full">
GitHub
</Link>
</NavbarItem>
Expand All @@ -67,7 +70,7 @@ export default function Header() {
</NavbarMenuItem>

<NavbarMenuItem>
<Link href="https://github.com/vst/lhp" className="w-full">
<Link href="https://github.com/vst/hostpatrol" className="w-full">
GitHub
</Link>
</NavbarMenuItem>
Expand Down
18 changes: 9 additions & 9 deletions website/src/components/report/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LhpHostReport, LhpPatrolReport, buildSshKeysTable } from '@/lib/data';
import { HostPatrolReport, HostReport, buildSshKeysTable } from '@/lib/data';
import { Tab, Tabs } from '@nextui-org/react';
import { Just, Maybe, Nothing } from 'purify-ts/Maybe';
import { useEffect, useState } from 'react';
Expand All @@ -8,8 +8,8 @@ import { TabOverview } from './TabOverview';
import { TabulateHosts } from './TabulateHosts';
import { TabulateSshKeys } from './TabulateSshKeys';

export function App({ data, onFlushRequest }: { data: LhpPatrolReport; onFlushRequest: () => void }) {
const [host, setHost] = useState<Maybe<LhpHostReport>>(Nothing);
export function App({ data, onFlushRequest }: { data: HostPatrolReport; onFlushRequest: () => void }) {
const [host, setHost] = useState<Maybe<HostReport>>(Nothing);
type TabKey = 'overview' | 'tabulate-hosts' | 'show-host-details' | 'ssh-keys' | 'flush';
const [tab, setTab] = useState<TabKey>('overview');

Expand Down Expand Up @@ -60,8 +60,8 @@ export function TabTabulateHosts({
data,
setHost,
}: {
data: LhpPatrolReport;
setHost: (x: Maybe<LhpHostReport>) => void;
data: HostPatrolReport;
setHost: (x: Maybe<HostReport>) => void;
}) {
return <TabulateHosts hosts={data.hosts} onHostSelect={(x) => setHost(Just(x))} />;
}
Expand All @@ -71,9 +71,9 @@ export function TabShowHostDetails({
host,
setHost,
}: {
data: LhpPatrolReport;
host: Maybe<LhpHostReport>;
setHost: (x: Maybe<LhpHostReport>) => void;
data: HostPatrolReport;
host: Maybe<HostReport>;
setHost: (x: Maybe<HostReport>) => void;
}) {
return (
<div className="grid grid-cols-6">
Expand All @@ -91,6 +91,6 @@ export function TabShowHostDetails({
);
}

export function TabSshKeys({ data }: { data: LhpPatrolReport }) {
export function TabSshKeys({ data }: { data: HostPatrolReport }) {
return <TabulateSshKeys records={Object.values(buildSshKeysTable(data))} />;
}
4 changes: 2 additions & 2 deletions website/src/components/report/DataLoader.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { LhpPatrolReport, parseData, saveData } from '@/lib/data';
import { HostPatrolReport, parseData, saveData } from '@/lib/data';
import { Card, CardBody, CardFooter, CardHeader } from '@nextui-org/card';
import { Divider } from '@nextui-org/divider';
import { ChangeEvent, useState } from 'react';
import { Centered } from '../helpers';

export function DataLoader({ onLoadData }: { onLoadData: (x: LhpPatrolReport) => void }) {
export function DataLoader({ onLoadData }: { onLoadData: (x: HostPatrolReport) => void }) {
const [error, setError] = useState<string>();

const changeHandler = (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
Expand Down
6 changes: 3 additions & 3 deletions website/src/components/report/ShowHostDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LhpHostReport, LhpPatrolReport, SshPublicKey } from '@/lib/data';
import { HostPatrolReport, HostReport, SshPublicKey } from '@/lib/data';
import {
Card,
CardBody,
Expand All @@ -18,7 +18,7 @@ import Link from 'next/link';
import { toast } from 'react-toastify';
import { KVBox } from '../helpers';

export function ShowHostDetails({ host, data }: { host: LhpHostReport; data: LhpPatrolReport }) {
export function ShowHostDetails({ host, data }: { host: HostReport; data: HostPatrolReport }) {
return (
<div className="space-y-4 px-4 py-4">
<h1 className="flex flex-row items-center justify-between text-xl font-bold">
Expand Down Expand Up @@ -212,7 +212,7 @@ export function ShowHostDetails({ host, data }: { host: LhpHostReport; data: Lhp
);
}

export function TabulateSshKeys({ host, data }: { host: LhpHostReport; data: LhpPatrolReport }) {
export function TabulateSshKeys({ host, data }: { host: HostReport; data: HostPatrolReport }) {
const keysKnownGlobal = (data.knownSshKeys || []).reduce(
(acc, x) => ({ ...acc, [`${x.fingerprint}`]: x }),
{} as Record<string, SshPublicKey>
Expand Down
6 changes: 3 additions & 3 deletions website/src/components/report/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { LhpHostReport } from '@/lib/data';
import { HostReport } from '@/lib/data';
import { Listbox, ListboxItem } from '@nextui-org/listbox';
import Image from 'next/image';
import { getCloudIconName } from './helpers';

export interface SidebarProps {
data: LhpHostReport[];
onHostSelect: (host: LhpHostReport) => void;
data: HostReport[];
onHostSelect: (host: HostReport) => void;
}

export function Sidebar({ data, onHostSelect }: SidebarProps) {
Expand Down
4 changes: 2 additions & 2 deletions website/src/components/report/TabOverview.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LhpPatrolReport, buildSshKeysTable } from '@/lib/data';
import { HostPatrolReport, buildSshKeysTable } from '@/lib/data';
import { SimpleBarChart, histogram } from '../helpers';

export function TabOverview({ data }: { data: LhpPatrolReport }) {
export function TabOverview({ data }: { data: HostPatrolReport }) {
const sshkeys = Object.values(buildSshKeysTable(data));

return (
Expand Down
10 changes: 5 additions & 5 deletions website/src/components/report/TabulateHosts.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LhpHostReport } from '@/lib/data';
import { HostReport } from '@/lib/data';
import { Chip } from '@nextui-org/chip';
import { Radio, RadioGroup, Select, SelectItem, Selection, Slider } from '@nextui-org/react';
import { Table, TableBody, TableCell, TableColumn, TableHeader, TableRow } from '@nextui-org/table';
Expand All @@ -11,11 +11,11 @@ export function TabulateHosts({
hosts,
onHostSelect,
}: {
hosts: LhpHostReport[];
onHostSelect: (host: LhpHostReport) => void;
hosts: HostReport[];
onHostSelect: (host: HostReport) => void;
}) {
const [filters, setFilters] = useState<Record<string, (host: LhpHostReport) => boolean>>({});
const [filteredHosts, setFilteredHosts] = useState<LhpHostReport[]>(hosts);
const [filters, setFilters] = useState<Record<string, (host: HostReport) => boolean>>({});
const [filteredHosts, setFilteredHosts] = useState<HostReport[]>(hosts);

useEffect(() => {
setFilteredHosts(hosts.filter((host) => Object.values(filters).reduce((acc, f) => acc && f(host), true)));
Expand Down
4 changes: 2 additions & 2 deletions website/src/components/report/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use client';

import { LhpPatrolReport, deleteData, loadData } from '@/lib/data';
import { HostPatrolReport, deleteData, loadData } from '@/lib/data';
import { Just, Maybe, Nothing } from 'purify-ts/Maybe';
import { useEffect, useState } from 'react';
import { BigSpinner } from '../helpers';
import { App } from './App';
import { DataLoader } from './DataLoader';

export function Report() {
const [data, setAppData] = useState<Maybe<Maybe<LhpPatrolReport>>>(Nothing);
const [data, setAppData] = useState<Maybe<Maybe<HostPatrolReport>>>(Nothing);

useEffect(() => {
loadData().caseOf({
Expand Down
28 changes: 14 additions & 14 deletions website/src/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FromSchema } from 'json-schema-to-ts';
import { Either, Left, Right } from 'purify-ts/Either';
import { Just, Maybe, Nothing } from 'purify-ts/Maybe';

export const LHP_PATROL_REPORT_SCHEMA = {
export const HOSTPATROL_REPORT_SCHEMA = {
$comment: 'Host Patrol Report\nReport',
properties: {
hosts: {
Expand Down Expand Up @@ -262,22 +262,22 @@ export const LHP_PATROL_REPORT_SCHEMA = {
type: 'object',
} as const satisfies JSONSchema;

export type LhpPatrolReport = FromSchema<typeof LHP_PATROL_REPORT_SCHEMA>;
export type HostPatrolReport = FromSchema<typeof HOSTPATROL_REPORT_SCHEMA>;

export type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[]
? ElementType
: never;

export type LhpHostReport = ArrayElement<LhpPatrolReport['hosts']>;
export type SshPublicKey = ArrayElement<LhpHostReport['authorizedSshKeys']>;
export type HostReport = ArrayElement<HostPatrolReport['hosts']>;
export type SshPublicKey = ArrayElement<HostReport['authorizedSshKeys']>;

const AJV = new Ajv();

const LHP_PATROL_REPORT_VALIDATOR = AJV.compile<LhpPatrolReport>(LHP_PATROL_REPORT_SCHEMA);
const HOSTPATROL_REPORT_VALIDATOR = AJV.compile<HostPatrolReport>(HOSTPATROL_REPORT_SCHEMA);

const _LOCAL_STORAGE_KEY_DATA = 'LHP_DATA';
const _LOCAL_STORAGE_KEY_DATA = 'HOSTPATROL_DATA';

export function loadData(): Either<string, Maybe<LhpPatrolReport>> {
export function loadData(): Either<string, Maybe<HostPatrolReport>> {
const data = localStorage.getItem(_LOCAL_STORAGE_KEY_DATA);

if (data === null) {
Expand All @@ -287,14 +287,14 @@ export function loadData(): Either<string, Maybe<LhpPatrolReport>> {
return parseData(data).map(Just);
}

export function parseData(data: string): Either<string, LhpPatrolReport> {
export function parseData(data: string): Either<string, HostPatrolReport> {
try {
const parsed = JSON.parse(data);
const result = LHP_PATROL_REPORT_VALIDATOR(parsed);
const result = HOSTPATROL_REPORT_VALIDATOR(parsed);

if (!result) {
console.error(LHP_PATROL_REPORT_VALIDATOR.errors);
return Left('Invalid lhp patrol report object.');
console.error(HOSTPATROL_REPORT_VALIDATOR.errors);
return Left('Invalid Host Patrol report object.');
}

return Right(parsed);
Expand All @@ -303,7 +303,7 @@ export function parseData(data: string): Either<string, LhpPatrolReport> {
}
}

export function saveData(x: LhpPatrolReport): void {
export function saveData(x: HostPatrolReport): void {
localStorage.setItem(_LOCAL_STORAGE_KEY_DATA, JSON.stringify(x));
}

Expand All @@ -315,13 +315,13 @@ export type SshKeysTable = Record<string, SshKeysTableRecord>;

export interface SshKeysTableRecord {
key: SshPublicKey;
seenHosts: Set<LhpHostReport>;
seenHosts: Set<HostReport>;
seenComments: Set<string>;
isKnown: boolean;
knownComment: string;
}

export function buildSshKeysTable(data: LhpPatrolReport): SshKeysTable {
export function buildSshKeysTable(data: HostPatrolReport): SshKeysTable {
// Initialize the return value:
const keys: SshKeysTable = {};

Expand Down

0 comments on commit d10190e

Please sign in to comment.