Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

1.9 KB
Raw Blame
import { t } from "@/lib/i18n";
import { productName } from "@/lib/brand";
import type { CompanionState } from "@/lib/companion-types";

const NOTE = "w-full rounded-lg border border-warning/30 bg-warning/10 px-3 py-2 text-left text-[12px] leading-relaxed text-warning";

/** The command that lets a phone in on the device port; ufw is the only firewall the sidecar reports. */
export const hostFirewallCommand = (port: number) => `sudo ufw allow ${port}/tcp`;

/** The code reaches this computer only on its own network: no relay and no HTTPS address to pair through instead. */
export const wifiOnlyCode = (state: Pick<CompanionState, "e2e" | "endpoints">): boolean =>
  !state.e2e?.descriptor?.r?.length && !state.endpoints?.some((endpoint) => endpoint.kind === "hosted");

/** Linux: ufw is on, its rules are readable and none lets the device port in, so a phone on the Wi-Fi may never connect. */
export function HostFirewallNote({ state, className = "mt-3" }: { state: Pick<CompanionState, "hostFirewall" | "port">; className?: string }) {
  if (state.hostFirewall !== "ufw" || !Number.isSafeInteger(state.port)) return null;
  return (
    <div role="note" data-host-firewall="" className={`${NOTE} ${className}`}>
      <p>{t("phone.code.hostFirewall", { app: productName() })}</p>
      <code className="mt-1 block select-all font-mono text-[12px] text-ink">{hostFirewallCommand(state.port)}</code>
    </div>
  );
}

/** The Wi-Fi code panel's firewall notes: Windows calls the network Public, or ufw is on. */
export function FirewallNotes({ state, className = "mt-3 max-w-[390px]" }: { state: Pick<CompanionState, "hostFirewall" | "port" | "publicNetwork">; className?: string }) {
  return <>
    {state.publicNetwork && <p role="note" className={`${NOTE} ${className}`}>{t("phone.code.publicNetwork", { network: state.publicNetwork })}</p>}
    <HostFirewallNote state={state} className={className} />
  </>;
}