Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #16 from sinamics/dev
Browse files Browse the repository at this point in the history
merge dev branch
  • Loading branch information
sinamics authored Jul 26, 2022
2 parents a25a314 + 0566137 commit c608f29
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion backend/src/resolvers/VpnResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class VpnResolver {
@Query(() => ZerotierNetworkResponse)
async zerotierNetworks(): Promise<any> {
try {
const listnetworks = await childProcessCmd({ cmd: 'sudo zerotier-cli -j listnetworks' });
const listnetworks = await childProcessCmd({ cmd: 'sudo zerotier-cli -j listnetworks', sensitiv: true });
const networks = JSON.parse(listnetworks.toString('utf8'));

// const peers = await childProcessCmd({ cmd: 'sudo zerotier-cli -j peers' });
Expand Down
24 changes: 21 additions & 3 deletions backend/src/utils/childProcessCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,23 @@ export const childProcessCmd = ({ cmd, args = [], sensitiv = false, options }: C
// spawn commands
const child = spawn(cmd, args, { cwd: path.join(process.cwd(), '..'), shell: true, ...options });
child.stdout.on('data', async (data: any) => {
ServerLog.info({ message: data.toString(), data: `(command: ${cmd} ${args})`, path: __filename });
if (sensitiv) {
// log activity
ServerLog.info({ message: data.toString(), data: `Sensitiv information, logging skipped!`, path: __filename });
} else {
// log activity
ServerLog.info({ message: data.toString(), data: `(command: ${cmd} ${args})`, path: __filename });
}
resolve(data);
});
child.stderr.on('data', async (error: any) => {
ServerLog.error({ message: error.toString(), data: `(command: ${cmd} ${args})`, path: __filename });
if (sensitiv) {
// log activity
ServerLog.error({ message: error.toString(), data: `Sensitiv information, logging skipped!`, path: __filename });
} else {
// log activity
ServerLog.error({ message: error.toString(), data: `(command: ${cmd} ${args})`, path: __filename });
}
reject(error);
});
child.on('close', async () => {
Expand Down Expand Up @@ -63,7 +75,13 @@ export const childProcessCmdCallback = (
});
} else {
child.stderr.on('data', async (error) => {
ServerLog.error({ message: error.toString(), data: cmd, path: __filename });
if (sensitiv) {
// log activity
ServerLog.error({ message: error.toString(), data: `Sensitiv information, logging skipped!`, path: __filename });
} else {
// log activity
ServerLog.error({ message: error.toString(), data: `(command: ${cmd} ${args})`, path: __filename });
}
typeof callback === 'function' && callback({ response: null, error });
});
child.on('close', async (code: any) => {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/vpn/containers/zerotier.footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ZerotierFooter = () => {
<Button
onClick={() =>
kernelCommand({
variables: { cmd: 'sudo zerotier-cli info', path: '/' }
variables: { cmd: 'sudo zerotier-cli info', path: '/', sensitiv: true }
})
}
>
Expand All @@ -18,7 +18,7 @@ const ZerotierFooter = () => {
<Button
onClick={() =>
kernelCommand({
variables: { cmd: 'sudo zerotier-cli info -j', path: '/' }
variables: { cmd: 'sudo zerotier-cli info -j', path: '/', sensitiv: true }
})
}
>
Expand All @@ -28,7 +28,7 @@ const ZerotierFooter = () => {
<Button
onClick={() =>
kernelCommand({
variables: { cmd: 'sudo zerotier-cli peers', path: '/' }
variables: { cmd: 'sudo zerotier-cli peers', path: '/', sensitiv: true }
})
}
>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/vpn/containers/zerotierTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useZerotierNetworksQuery, useChildProcessCmdMutation, ZerotierNetworksD
const ZerotierTable = () => {
const [kernelCommand] = useChildProcessCmdMutation();
const { data: { zerotierNetworks: { networks = [] } = {} } = {} }: any = useZerotierNetworksQuery({
fetchPolicy: 'network-only',
pollInterval: 5000
});
return (
Expand Down

0 comments on commit c608f29

Please sign in to comment.