From b55cb8a025b4bfb17060e034ccfb9a37b36524ed Mon Sep 17 00:00:00 2001 From: Shahrad Elahi Date: Thu, 28 Sep 2023 10:19:20 +0330 Subject: [PATCH] Adds a feature for removing duplicate lines in the `torrc` file, and provides a few minor updates to the UI. --- docker-entrypoint.sh | 10 ++--- src/pages/[serverId]/index.tsx | 67 +++++++++++++++++----------------- src/pages/index.tsx | 39 +++++++++++++------- src/ui/CopiableWrapper.tsx | 40 ++++++++++++++++++++ src/ui/EditableText.tsx | 2 +- 5 files changed, 104 insertions(+), 54 deletions(-) create mode 100644 src/ui/CopiableWrapper.tsx diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 3f49fb0..8508ddd 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -35,16 +35,16 @@ EOF cat /etc/tor/bridges >>/etc/tor/torrc fi -# Removing duplicated lines form /etc/tor/torrc file -awk '!seen[$0]++' /etc/tor/torrc >/tmp/torrc -mv /tmp/torrc /etc/tor/torrc - # any other environment variables that start with TOR_ are added to the torrc # file env | grep ^TOR_ | sed -e 's/TOR_//' -e 's/=/ /' >>/etc/tor/torrc +# Removing duplicated lines form /etc/tor/torrc file +awk '!seen[$0]++' /etc/tor/torrc >/tmp/torrc +mv /tmp/torrc /etc/tor/torrc + # Start Tor in the background -screen -L -Logfile /var/vlogs/tor -dmS tor bash -c "tor" +screen -L -Logfile /var/vlogs/tor -dmS tor bash -c "tor -f /etc/tor/torrc" # Starting Redis server in detached mode screen -L -Logfile /var/vlogs/redis -dmS redis bash -c "redis-server --port 6479 --daemonize no --dir /data --appendonly yes" diff --git a/src/pages/[serverId]/index.tsx b/src/pages/[serverId]/index.tsx index 8c10a1a..87c9d2d 100644 --- a/src/pages/[serverId]/index.tsx +++ b/src/pages/[serverId]/index.tsx @@ -17,6 +17,7 @@ import { getPeerConf } from "@lib/wireguard-utils"; import EditableText from "@ui/EditableText"; import { RLS_NAME_INPUT } from "@lib/form-rules"; import { UPDATE_CLIENT } from "@lib/swr-fetch"; +import CopiableWrapper from "@ui/CopiableWrapper"; export async function getServerSideProps(context: any) { @@ -42,15 +43,13 @@ export default function ServerPage(props: PageProps) { async (url: string) => { const resp = await fetch(url, { method: 'GET', - headers: { - 'Content-Type': 'application/json' - } + headers: { 'Content-Type': 'application/json' } }) if (resp.status === 404) { router.replace('/').catch() return false } - const data = await resp.json() as APIResponse + const data = await resp.json() as APIResponse if (!data.ok) throw new Error('Server responded with error status') return data.result } @@ -58,17 +57,11 @@ export default function ServerPage(props: PageProps) { const { isMutating: isChangingStatus, trigger: changeStatus } = useSWRMutation( `/api/wireguard/${props.serverId}`, - async (url: string, { arg }: { - arg: string - }) => { + async (url: string, { arg }: { arg: string }) => { const resp = await fetch(url, { method: arg === 'remove' ? 'DELETE' : 'PUT', - headers: { - 'Content-Type': 'application/json' - }, - body: arg === 'remove' ? undefined : JSON.stringify({ - status: arg - }) + headers: { 'Content-Type': 'application/json' }, + body: arg === 'remove' ? undefined : JSON.stringify({ status: arg }) }) if (resp.status === 404) { router.replace('/').catch() @@ -98,7 +91,7 @@ export default function ServerPage(props: PageProps) { { title: data ? data.name.toString() : 'LOADING...' } ]} /> - {error ? ( + {error || (!isLoading && !data) ? ( ! ERROR ! @@ -106,21 +99,26 @@ export default function ServerPage(props: PageProps) { Loading... - ) : ( + ) : data && (
.ant-card-body]:max-md:p1-2'}>
 {data.address}/24 
+ +
 {data.listen} 
+
- + + +
@@ -269,25 +267,26 @@ function Client(props: ClientProps) {
-
- {/* User Icon */} + +
-
-
- trigger({ name: v })} - /> -
-
+ +
+ trigger({ name: v })} + /> + {props.allowedIps} -
+
+
{/* QRCode */} diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 603f6d5..dde964e 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -15,6 +15,7 @@ import EditableText from "@ui/EditableText"; import useSWRMutation from "swr/mutation"; import { UPDATE_SERVER } from "@lib/swr-fetch"; import { RLS_NAME_INPUT } from "@lib/form-rules"; +import CopiableWrapper from "@ui/CopiableWrapper"; export default function Home() { const { data, error, isLoading, mutate } = useSWR( @@ -99,16 +100,26 @@ function ServerListItem(props: ServerListItemProps) { return ( -
- - trigger({ name: v })} - /> +
+ +
+ trigger({ name: v })} + /> + + {props.address}:{props.listen} + +
@@ -129,13 +140,13 @@ type ServerIconProps = { function ServerIcon(props: ServerIconProps) { return ( -
-
+
+
{'VPS'} {props.type !== 'direct' && (
diff --git a/src/ui/CopiableWrapper.tsx b/src/ui/CopiableWrapper.tsx new file mode 100644 index 0000000..77bc75c --- /dev/null +++ b/src/ui/CopiableWrapper.tsx @@ -0,0 +1,40 @@ +import React from "react"; +import { ReactHTMLProps } from "@lib/typings"; +import { message } from "antd"; +import { twMerge } from "tailwind-merge"; + +export interface CopiableWrapperProps extends Omit, 'content'> { + rootClassName?: string + content: string | number + showInHover?: boolean +} + +export default function CopiableWrapper(props: CopiableWrapperProps) { + const { + content, + children, + rootClassName, + className, + showInHover = false, + ...rest + } = props + const [ messageApi, contextHolder ] = message.useMessage() + return ( +
+ {contextHolder} + {children} + { + navigator.clipboard.writeText(content.toString()) + .then(() => messageApi.success('Copied!')) + .catch() + }} + /> +
+ ) +} diff --git a/src/ui/EditableText.tsx b/src/ui/EditableText.tsx index 28be949..9e42089 100644 --- a/src/ui/EditableText.tsx +++ b/src/ui/EditableText.tsx @@ -39,7 +39,7 @@ export default function EditableText(props: EditableTextProps) { }, [ val ]) const [ form ] = Form.useForm() return ( -
+