From 11f4d5c58a44ac10b0c2a4ae444c3cf20f80c7c7 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 30 Sep 2024 17:20:16 +0530 Subject: [PATCH 01/56] feat(wip): proxy form --- src/components/organisms/ProxyForm.tsx | 100 +++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/components/organisms/ProxyForm.tsx diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx new file mode 100644 index 00000000..5bd4ec41 --- /dev/null +++ b/src/components/organisms/ProxyForm.tsx @@ -0,0 +1,100 @@ +import React, { useState } from 'react'; +import { TextField, Button, MenuItem, Box } from '@mui/material'; +import { styled } from '@mui/system'; +import axios from 'axios'; + +const proxyTypes = [ + { label: 'HTTP', value: 'http' }, + { label: 'HTTPS', value: 'https' }, + { label: 'SOCKS5', value: 'socks5' }, +]; + +const FormContainer = styled(Box)({ + display: 'flex', + flexDirection: 'column', + gap: '20px', + width: '400px', + margin: '0 auto', + padding: '20px', + backgroundColor: '#f9f9f9', + borderRadius: '8px', +}); + +const ProxyForm: React.FC = () => { + const [proxyConfig, setProxyConfig] = useState({ + type: '', + server: '', + username: '', + password: '', + }); + + const handleChange = (e: React.ChangeEvent) => { + const { name, value } = e.target; + setProxyConfig({ ...proxyConfig, [name]: value }); + }; + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + try { + const response = await axios.post('/api/proxy', proxyConfig); + alert(`Successfully added the proxy`); + } catch (error) { + alert('Error submitting proxy configuration'); + } + }; + + return ( + +
+ + {proxyTypes.map((option) => ( + + {option.label} + + ))} + + + + + + + + + + +
+ ); +}; + +export default ProxyForm; From 071db325bbfbbcd3607f07ddb7c104eaa7a94cb5 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 30 Sep 2024 18:02:02 +0530 Subject: [PATCH 02/56] feat: proxy case --- src/pages/MainPage.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pages/MainPage.tsx b/src/pages/MainPage.tsx index b3a36349..a6a62258 100644 --- a/src/pages/MainPage.tsx +++ b/src/pages/MainPage.tsx @@ -3,6 +3,7 @@ import { MainMenu } from "../components/organisms/MainMenu"; import { Grid, Stack } from "@mui/material"; import { Recordings } from "../components/organisms/Recordings"; import { Runs } from "../components/organisms/Runs"; +import ProxyForm from '../components/organisms/ProxyForm'; import { useGlobalInfoStore } from "../context/globalInfo"; import { createRunForStoredRecording, interpretStoredRecording, notifyAboutAbort, scheduleStoredRecording } from "../api/storage"; import { handleUploadCredentials } from "../api/integration" @@ -142,6 +143,8 @@ export const MainPage = ({ handleEditRecording }: MainPageProps) => { runId={ids.runId} runningRecordingName={runningRecordingName} />; + case 'proxy': + return ; default: return null; } From b4e71cf917e5eca195b4d8c550b4a28a246b7c69 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 30 Sep 2024 18:06:05 +0530 Subject: [PATCH 03/56] feat: proxy case --- src/components/organisms/MainMenu.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/organisms/MainMenu.tsx b/src/components/organisms/MainMenu.tsx index 55dcd27c..b9f10255 100644 --- a/src/components/organisms/MainMenu.tsx +++ b/src/components/organisms/MainMenu.tsx @@ -44,6 +44,10 @@ export const MainMenu = ({ value = 'recordings', handleChangeContent }: MainMenu alignItems: 'baseline', fontSize:'medium', }} value="runs" label="Runs" /> + From e16f68a779ddb5f769f9e4ded0b2d5179ee51bf3 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 30 Sep 2024 18:06:30 +0530 Subject: [PATCH 04/56] chore: -rm unused import --- src/components/organisms/MainMenu.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/organisms/MainMenu.tsx b/src/components/organisms/MainMenu.tsx index b9f10255..39202214 100644 --- a/src/components/organisms/MainMenu.tsx +++ b/src/components/organisms/MainMenu.tsx @@ -3,7 +3,6 @@ import Tabs from '@mui/material/Tabs'; import Tab from '@mui/material/Tab'; import Box from '@mui/material/Box'; import { Paper } from "@mui/material"; -import styled from "styled-components"; interface MainMenuProps { value: string; From 4fa8d933f886797b376a3392536e6de9e6472128 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 30 Sep 2024 18:06:46 +0530 Subject: [PATCH 05/56] chore: prettier --- src/components/organisms/MainMenu.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/organisms/MainMenu.tsx b/src/components/organisms/MainMenu.tsx index 39202214..50a9f849 100644 --- a/src/components/organisms/MainMenu.tsx +++ b/src/components/organisms/MainMenu.tsx @@ -37,17 +37,17 @@ export const MainMenu = ({ value = 'recordings', handleChangeContent }: MainMenu > - - + ); From 15ac55b44a6dcbea83c0a3db12b1fd3d2c2a8a68 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 30 Sep 2024 23:26:24 +0530 Subject: [PATCH 06/56] feat: custom form control --- src/components/organisms/ProxyForm.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index 5bd4ec41..ce4b565f 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -20,6 +20,10 @@ const FormContainer = styled(Box)({ borderRadius: '8px', }); +const FormControl = styled(Box)({ + marginBottom: '10px', +}); + const ProxyForm: React.FC = () => { const [proxyConfig, setProxyConfig] = useState({ type: '', From 83adb99b042b04c76f385482d3f16233075baf2e Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 30 Sep 2024 23:27:59 +0530 Subject: [PATCH 07/56] feat: use radio for proxy type + style improvements --- src/components/organisms/ProxyForm.tsx | 99 ++++++++++++-------------- 1 file changed, 47 insertions(+), 52 deletions(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index ce4b565f..06199006 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -1,32 +1,24 @@ import React, { useState } from 'react'; -import { TextField, Button, MenuItem, Box } from '@mui/material'; +import { TextField, Button, RadioGroup, FormControlLabel, Radio, Box } from '@mui/material'; import { styled } from '@mui/system'; import axios from 'axios'; -const proxyTypes = [ - { label: 'HTTP', value: 'http' }, - { label: 'HTTPS', value: 'https' }, - { label: 'SOCKS5', value: 'socks5' }, -]; - const FormContainer = styled(Box)({ display: 'flex', flexDirection: 'column', - gap: '20px', - width: '400px', - margin: '0 auto', + gap: '16px', padding: '20px', backgroundColor: '#f9f9f9', borderRadius: '8px', }); const FormControl = styled(Box)({ - marginBottom: '10px', + marginBottom: '16px', }); const ProxyForm: React.FC = () => { const [proxyConfig, setProxyConfig] = useState({ - type: '', + type: 'http', server: '', username: '', password: '', @@ -41,7 +33,7 @@ const ProxyForm: React.FC = () => { e.preventDefault(); try { const response = await axios.post('/api/proxy', proxyConfig); - alert(`Successfully added the proxy`); + alert(`Success!`); } catch (error) { alert('Error submitting proxy configuration'); } @@ -50,48 +42,51 @@ const ProxyForm: React.FC = () => { return (
- - {proxyTypes.map((option) => ( - - {option.label} - - ))} - + + + } label="HTTP" /> + } label="HTTPS" /> + } label="SOCKS5" /> + + - + + + - + + + - + + +
From 1c509ad1da1180ec8b791c47ee085ba3eef3e1a5 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 30 Sep 2024 23:29:06 +0530 Subject: [PATCH 09/56] chore: lint --- src/components/organisms/ProxyForm.tsx | 154 ++++++++++++------------- 1 file changed, 77 insertions(+), 77 deletions(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index efa205d8..074f6d9f 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -4,96 +4,96 @@ import { styled } from '@mui/system'; import axios from 'axios'; const FormContainer = styled(Box)({ - display: 'flex', - flexDirection: 'column', - gap: '16px', - padding: '20px', - backgroundColor: '#f9f9f9', - borderRadius: '8px', + display: 'flex', + flexDirection: 'column', + gap: '16px', + padding: '20px', + backgroundColor: '#f9f9f9', + borderRadius: '8px', }); const FormControl = styled(Box)({ - marginBottom: '16px', + marginBottom: '16px', }); const ProxyForm: React.FC = () => { - const [proxyConfig, setProxyConfig] = useState({ - type: 'http', - server: '', - username: '', - password: '', - }); + const [proxyConfig, setProxyConfig] = useState({ + type: 'http', + server: '', + username: '', + password: '', + }); - const handleChange = (e: React.ChangeEvent) => { - const { name, value } = e.target; - setProxyConfig({ ...proxyConfig, [name]: value }); - }; + const handleChange = (e: React.ChangeEvent) => { + const { name, value } = e.target; + setProxyConfig({ ...proxyConfig, [name]: value }); + }; - const handleSubmit = async (e: React.FormEvent) => { - e.preventDefault(); - try { - const response = await axios.post('/api/proxy', proxyConfig); - alert(`Success!`); - } catch (error) { - alert('Error submitting proxy configuration'); - } - }; + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + try { + const response = await axios.post('/api/proxy', proxyConfig); + alert(`Success!`); + } catch (error) { + alert('Error submitting proxy configuration'); + } + }; - return ( - -
- - - } label="HTTP" /> - } label="HTTPS" /> - } label="SOCKS5" /> - - + return ( + + + + + } label="HTTP" /> + } label="HTTPS" /> + } label="SOCKS5" /> + + - - - + + + - - - + + + - - - + + + - - -
- ); + + +
+ ); }; export default ProxyForm; From 8e20ae396cd13ab45507e5c1ce54490b7ec6144d Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 30 Sep 2024 23:35:00 +0530 Subject: [PATCH 10/56] feat: select proxy type --- src/components/organisms/ProxyForm.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index 074f6d9f..0b6cfd47 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { TextField, Button, RadioGroup, FormControlLabel, Radio, Box } from '@mui/material'; +import { TextField, Button, RadioGroup, FormControlLabel, Radio, Box, Typography } from '@mui/material'; import { styled } from '@mui/system'; import axios from 'axios'; @@ -43,6 +43,7 @@ const ProxyForm: React.FC = () => {
+ Select Proxy Type Date: Mon, 30 Sep 2024 23:36:33 +0530 Subject: [PATCH 11/56] feat: proxy config --- src/components/organisms/ProxyForm.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index 0b6cfd47..5fc4cc95 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -56,6 +56,8 @@ const ProxyForm: React.FC = () => { + Proxy Configuration + Date: Mon, 30 Sep 2024 23:37:26 +0530 Subject: [PATCH 12/56] feat: remove bg color --- src/components/organisms/ProxyForm.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index 5fc4cc95..15635437 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -8,7 +8,6 @@ const FormContainer = styled(Box)({ flexDirection: 'column', gap: '16px', padding: '20px', - backgroundColor: '#f9f9f9', borderRadius: '8px', }); From 5b6381272d44a40f66a161448da60f073d3fe979 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 30 Sep 2024 23:43:46 +0530 Subject: [PATCH 13/56] feat: add margin --- src/components/organisms/ProxyForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index 15635437..2a733cc8 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -55,7 +55,7 @@ const ProxyForm: React.FC = () => { - Proxy Configuration + Proxy Configuration Date: Mon, 30 Sep 2024 23:44:00 +0530 Subject: [PATCH 14/56] chore: lint --- src/components/organisms/ProxyForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index 2a733cc8..ac368339 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -55,7 +55,7 @@ const ProxyForm: React.FC = () => { - Proxy Configuration + Proxy Configuration Date: Mon, 30 Sep 2024 23:49:50 +0530 Subject: [PATCH 15/56] feat: api call route --- src/components/organisms/ProxyForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index ac368339..d45c5968 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -31,7 +31,7 @@ const ProxyForm: React.FC = () => { const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); try { - const response = await axios.post('/api/proxy', proxyConfig); + const response = await axios.post('http://localhost:8080/proxy/config', proxyConfig); alert(`Success!`); } catch (error) { alert('Error submitting proxy configuration'); From ed92259842079034b4cd733dd5b36d0ab69f6501 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 30 Sep 2024 23:51:12 +0530 Subject: [PATCH 16/56] feat: return response --- src/components/organisms/ProxyForm.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index d45c5968..ae6f7d72 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -32,7 +32,11 @@ const ProxyForm: React.FC = () => { e.preventDefault(); try { const response = await axios.post('http://localhost:8080/proxy/config', proxyConfig); - alert(`Success!`); + if (response.status === 200) { + return response.data; + } else { + throw new Error(`Failed to submit proxy configuration. Try again.`); + } } catch (error) { alert('Error submitting proxy configuration'); } From e6f08e4c4937490333209aa2ad67e75a55659a16 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 30 Sep 2024 23:53:35 +0530 Subject: [PATCH 17/56] feat: POST proxy config --- src/api/proxy.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/api/proxy.ts diff --git a/src/api/proxy.ts b/src/api/proxy.ts new file mode 100644 index 00000000..ff91d43f --- /dev/null +++ b/src/api/proxy.ts @@ -0,0 +1,15 @@ +import { default as axios } from "axios"; + +export const sendProxyConfig = async (proxyConfig: {}): Promise => { + try { + const response = await axios.post(`http://localhost:8080/proxy/config`); + if (response.status === 200) { + return response.data; + } else { + throw new Error(`Failed to submit proxy configuration. Try again.`); + } + } catch(error: any) { + console.log(error); + return false; + } + } \ No newline at end of file From 5120bdef4cbb53e444a3d1763c556c2f40621701 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 30 Sep 2024 23:54:20 +0530 Subject: [PATCH 18/56] feat: send proxyConfig --- src/api/proxy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/proxy.ts b/src/api/proxy.ts index ff91d43f..918b32fd 100644 --- a/src/api/proxy.ts +++ b/src/api/proxy.ts @@ -2,7 +2,7 @@ import { default as axios } from "axios"; export const sendProxyConfig = async (proxyConfig: {}): Promise => { try { - const response = await axios.post(`http://localhost:8080/proxy/config`); + const response = await axios.post(`http://localhost:8080/proxy/config`, proxyConfig); if (response.status === 200) { return response.data; } else { From 34247287e367c8a697344d5e4ae5467ab3379fd0 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 30 Sep 2024 23:55:12 +0530 Subject: [PATCH 19/56] feat: proxy config types --- src/api/proxy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/proxy.ts b/src/api/proxy.ts index 918b32fd..670c3d4f 100644 --- a/src/api/proxy.ts +++ b/src/api/proxy.ts @@ -1,6 +1,6 @@ import { default as axios } from "axios"; -export const sendProxyConfig = async (proxyConfig: {}): Promise => { +export const sendProxyConfig = async (proxyConfig: {type: string, server: string, username:string, password: string}): Promise => { try { const response = await axios.post(`http://localhost:8080/proxy/config`, proxyConfig); if (response.status === 200) { From 40f77be58425f8eb2a1afa09d543bd14c824cf9a Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 30 Sep 2024 23:55:37 +0530 Subject: [PATCH 20/56] chore: prttier --- src/api/proxy.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/api/proxy.ts b/src/api/proxy.ts index 670c3d4f..6246345d 100644 --- a/src/api/proxy.ts +++ b/src/api/proxy.ts @@ -1,15 +1,15 @@ import { default as axios } from "axios"; -export const sendProxyConfig = async (proxyConfig: {type: string, server: string, username:string, password: string}): Promise => { +export const sendProxyConfig = async (proxyConfig: { type: string, server: string, username: string, password: string }): Promise => { try { - const response = await axios.post(`http://localhost:8080/proxy/config`, proxyConfig); - if (response.status === 200) { - return response.data; - } else { - throw new Error(`Failed to submit proxy configuration. Try again.`); - } - } catch(error: any) { - console.log(error); - return false; + const response = await axios.post(`http://localhost:8080/proxy/config`, proxyConfig); + if (response.status === 200) { + return response.data; + } else { + throw new Error(`Failed to submit proxy configuration. Try again.`); + } + } catch (error: any) { + console.log(error); + return false; } - } \ No newline at end of file +} \ No newline at end of file From b145ea17a49f34fd1d93dc8d103e2a742c5a06bb Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 30 Sep 2024 23:56:04 +0530 Subject: [PATCH 21/56] feat: make username & password optional --- src/api/proxy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/proxy.ts b/src/api/proxy.ts index 6246345d..ebe87f95 100644 --- a/src/api/proxy.ts +++ b/src/api/proxy.ts @@ -1,6 +1,6 @@ import { default as axios } from "axios"; -export const sendProxyConfig = async (proxyConfig: { type: string, server: string, username: string, password: string }): Promise => { +export const sendProxyConfig = async (proxyConfig: { type: string, server: string, username?: string, password?: string }): Promise => { try { const response = await axios.post(`http://localhost:8080/proxy/config`, proxyConfig); if (response.status === 200) { From 40e81d1f59c550269a45c618de05c28d67be3368 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Tue, 1 Oct 2024 00:06:56 +0530 Subject: [PATCH 22/56] feat: use sendProxyConfig() --- src/components/organisms/ProxyForm.tsx | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index ae6f7d72..b92c9ae3 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -1,7 +1,8 @@ import React, { useState } from 'react'; -import { TextField, Button, RadioGroup, FormControlLabel, Radio, Box, Typography } from '@mui/material'; -import { styled } from '@mui/system'; import axios from 'axios'; +import { styled } from '@mui/system'; +import { TextField, Button, RadioGroup, FormControlLabel, Radio, Box, Typography } from '@mui/material'; +import { sendProxyConfig } from '../../api/proxy'; const FormContainer = styled(Box)({ display: 'flex', @@ -30,16 +31,13 @@ const ProxyForm: React.FC = () => { const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); - try { - const response = await axios.post('http://localhost:8080/proxy/config', proxyConfig); - if (response.status === 200) { - return response.data; - } else { - throw new Error(`Failed to submit proxy configuration. Try again.`); - } - } catch (error) { - alert('Error submitting proxy configuration'); - } + await sendProxyConfig(proxyConfig).then((response) => { + if (response) { + alert('Proxy configuration submitted successfully'); + } else { + alert('Failed to submit proxy configuration. Try again.'); + } + }); }; return ( From ca329e25b5a6950dd447b2263012a5f80a65f46d Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Tue, 1 Oct 2024 00:07:13 +0530 Subject: [PATCH 23/56] chore: remove axios import --- src/components/organisms/ProxyForm.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index b92c9ae3..450bfd71 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -1,5 +1,4 @@ import React, { useState } from 'react'; -import axios from 'axios'; import { styled } from '@mui/system'; import { TextField, Button, RadioGroup, FormControlLabel, Radio, Box, Typography } from '@mui/material'; import { sendProxyConfig } from '../../api/proxy'; From aabf48fa7e4a87775e25389b24297fbaeaf33bd4 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Tue, 1 Oct 2024 00:09:06 +0530 Subject: [PATCH 24/56] feat: use notify for alerts --- src/components/organisms/ProxyForm.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index 450bfd71..db0fe310 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -2,6 +2,7 @@ import React, { useState } from 'react'; import { styled } from '@mui/system'; import { TextField, Button, RadioGroup, FormControlLabel, Radio, Box, Typography } from '@mui/material'; import { sendProxyConfig } from '../../api/proxy'; +import { useGlobalInfoStore } from '../../context/globalInfo'; const FormContainer = styled(Box)({ display: 'flex', @@ -23,6 +24,8 @@ const ProxyForm: React.FC = () => { password: '', }); + const { notify } = useGlobalInfoStore(); + const handleChange = (e: React.ChangeEvent) => { const { name, value } = e.target; setProxyConfig({ ...proxyConfig, [name]: value }); @@ -32,9 +35,9 @@ const ProxyForm: React.FC = () => { e.preventDefault(); await sendProxyConfig(proxyConfig).then((response) => { if (response) { - alert('Proxy configuration submitted successfully'); + notify('success','Proxy configuration submitted successfully'); } else { - alert('Failed to submit proxy configuration. Try again.'); + notify('error', 'Failed to submit proxy configuration. Try again.'); } }); }; From 38d053f4af4b9aa7ac17cfb58f5e5ffc81c06cb3 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Tue, 1 Oct 2024 00:09:32 +0530 Subject: [PATCH 25/56] fix: format --- src/components/organisms/ProxyForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index db0fe310..157dad8e 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -35,7 +35,7 @@ const ProxyForm: React.FC = () => { e.preventDefault(); await sendProxyConfig(proxyConfig).then((response) => { if (response) { - notify('success','Proxy configuration submitted successfully'); + notify('success', 'Proxy configuration submitted successfully'); } else { notify('error', 'Failed to submit proxy configuration. Try again.'); } From 9a6f3a1b394bede71c872b15ab9ca24df4c95643 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Tue, 1 Oct 2024 15:28:37 +0530 Subject: [PATCH 26/56] feat: post config route --- server/src/routes/proxy.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 server/src/routes/proxy.ts diff --git a/server/src/routes/proxy.ts b/server/src/routes/proxy.ts new file mode 100644 index 00000000..2f130bb9 --- /dev/null +++ b/server/src/routes/proxy.ts @@ -0,0 +1,14 @@ +import { Router, Request, Response } from 'express'; +export const router = Router(); + +router.post('/config', async (req: Request, res: Response) => { + const { proxyConfig } = req.body; + try { + if (!proxyConfig) { + return res.status(400).send('Proxy configuration is required'); + } + console.log(proxyConfig); + } catch (error: any) { + res.status(500).send(`Could not send proxy configuration - ${error.message}`) + } +}) \ No newline at end of file From 911c40453f2b9d9133bb8941e70515a1e27555a9 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Tue, 1 Oct 2024 15:29:26 +0530 Subject: [PATCH 27/56] feat: import router as proxy --- server/src/routes/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/src/routes/index.ts b/server/src/routes/index.ts index 72be1ebd..bc616273 100644 --- a/server/src/routes/index.ts +++ b/server/src/routes/index.ts @@ -3,6 +3,7 @@ import { router as workflow } from './workflow'; import { router as storage } from './storage'; import { router as auth } from './auth'; import { router as integration } from './integration'; +import { router as proxy } from './proxy'; export { record, @@ -10,4 +11,5 @@ export { storage, auth, integration, + proxy }; From c348a988034357602f14b3eb49c74584fca0a27b Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Tue, 1 Oct 2024 15:30:13 +0530 Subject: [PATCH 28/56] feat: app.use proxy routes --- server/src/server.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/server.ts b/server/src/server.ts index 0d0512fc..ba44d260 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -3,7 +3,7 @@ import http from 'http'; import cors from 'cors'; import dotenv from 'dotenv'; dotenv.config(); -import { record, workflow, storage, auth, integration } from './routes'; +import { record, workflow, storage, auth, integration, proxy } from './routes'; import { BrowserPool } from "./browser-management/classes/BrowserPool"; import logger from './logger'; import { connectDB, syncDB } from './db/config'; @@ -46,6 +46,7 @@ app.use('/workflow', workflow); app.use('/storage', storage); app.use('/auth', auth); app.use('/integration', integration); +app.use('/proxy', proxy); app.get('/', function (req, res) { return res.send('Maxun server started 🚀'); From 1d625d307fabc7acdd019f0f7ab4d1963fd7a7ec Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Tue, 1 Oct 2024 23:37:21 +0530 Subject: [PATCH 29/56] feat: api key ui --- src/components/organisms/ProxyForm.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index 157dad8e..b9f854fc 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -22,6 +22,7 @@ const ProxyForm: React.FC = () => { server: '', username: '', password: '', + apiKey: '', }); const { notify } = useGlobalInfoStore(); @@ -73,6 +74,16 @@ const ProxyForm: React.FC = () => { /> + + + + Date: Tue, 1 Oct 2024 23:38:24 +0530 Subject: [PATCH 30/56] feat: pass apiKey to proxyConfig --- src/api/proxy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/proxy.ts b/src/api/proxy.ts index ebe87f95..28957be0 100644 --- a/src/api/proxy.ts +++ b/src/api/proxy.ts @@ -1,6 +1,6 @@ import { default as axios } from "axios"; -export const sendProxyConfig = async (proxyConfig: { type: string, server: string, username?: string, password?: string }): Promise => { +export const sendProxyConfig = async (proxyConfig: { type: string, server: string, username?: string, password?: string, apiKey?: string }): Promise => { try { const response = await axios.post(`http://localhost:8080/proxy/config`, proxyConfig); if (response.status === 200) { From 372e71a97c54f93b9cfbdf16b91aaf02ea9c5b74 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 20:59:45 +0530 Subject: [PATCH 31/56] feat: remove apiKeu from proxyConfig --- src/api/proxy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/proxy.ts b/src/api/proxy.ts index 28957be0..ebe87f95 100644 --- a/src/api/proxy.ts +++ b/src/api/proxy.ts @@ -1,6 +1,6 @@ import { default as axios } from "axios"; -export const sendProxyConfig = async (proxyConfig: { type: string, server: string, username?: string, password?: string, apiKey?: string }): Promise => { +export const sendProxyConfig = async (proxyConfig: { type: string, server: string, username?: string, password?: string }): Promise => { try { const response = await axios.post(`http://localhost:8080/proxy/config`, proxyConfig); if (response.status === 200) { From ed853618c3ad74e0e1a3eadd1117e59b1fa94aaf Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 21:02:45 +0530 Subject: [PATCH 32/56] refactor: -rm apiKey form control --- src/components/organisms/ProxyForm.tsx | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index b9f854fc..2a933a6d 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -74,16 +74,6 @@ const ProxyForm: React.FC = () => { /> - - - - Date: Wed, 2 Oct 2024 21:03:10 +0530 Subject: [PATCH 33/56] feat: -rm apiKey from proxyConfig --- src/components/organisms/ProxyForm.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index 2a933a6d..157dad8e 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -22,7 +22,6 @@ const ProxyForm: React.FC = () => { server: '', username: '', password: '', - apiKey: '', }); const { notify } = useGlobalInfoStore(); From 19f1f3c98942e4a3c4b10e73ab9a64047e3a1aa2 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 22:33:46 +0530 Subject: [PATCH 34/56] feat: include proxy url, username & password in UserAttributes --- server/src/models/User.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/src/models/User.ts b/server/src/models/User.ts index 40eb2198..a0fd34e6 100644 --- a/server/src/models/User.ts +++ b/server/src/models/User.ts @@ -6,6 +6,9 @@ interface UserAttributes { email: string; password: string; api_key?: string | null; + proxy_url?: string | null; + proxy_username?: string | null; + proxy_password?: string | null; } // Optional fields for creating a new user From 99e9b3f853b42b3109833738800cfa0b608bd5e2 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 22:34:16 +0530 Subject: [PATCH 35/56] feat: include proxy url, username & password in User model --- server/src/models/User.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/src/models/User.ts b/server/src/models/User.ts index a0fd34e6..fd23448a 100644 --- a/server/src/models/User.ts +++ b/server/src/models/User.ts @@ -19,6 +19,9 @@ class User extends Model implements User public email!: string; public password!: string; public api_key!: string | null; + public proxy_url!: string | null; + public proxy_username!: string | null; + public proxy_password!: string | null; } User.init( From 11d5b2f2baec4f97e0f13da3b548267c0c356145 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 22:37:28 +0530 Subject: [PATCH 36/56] feat: proxy url, username & password --- server/src/models/User.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/src/models/User.ts b/server/src/models/User.ts index fd23448a..6430c50f 100644 --- a/server/src/models/User.ts +++ b/server/src/models/User.ts @@ -47,6 +47,18 @@ User.init( type: DataTypes.STRING, allowNull: true, }, + proxy_url: { + type: DataTypes.STRING, + allowNull: true, + }, + proxy_username: { + type: DataTypes.STRING, + allowNull: true, + }, + proxy_password: { + type: DataTypes.STRING, + allowNull: true, + }, }, { sequelize, From c379b849428aad4c7e40c07099c82b5cab09d87a Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 22:39:09 +0530 Subject: [PATCH 37/56] feat: proxy password validation --- server/src/models/User.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/src/models/User.ts b/server/src/models/User.ts index 6430c50f..5e7c17e9 100644 --- a/server/src/models/User.ts +++ b/server/src/models/User.ts @@ -54,6 +54,13 @@ User.init( proxy_username: { type: DataTypes.STRING, allowNull: true, + validate: { + isProxyPasswordRequired(value: string | null) { + if (value && !this.proxy_password) { + throw new Error('Proxy password is required when proxy username is provided'); + } + }, + }, }, proxy_password: { type: DataTypes.STRING, From f1f7d142fbf62e75d5511623e4d339ea3b0fba49 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 22:43:14 +0530 Subject: [PATCH 38/56] chore: lint --- server/src/models/User.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/models/User.ts b/server/src/models/User.ts index 5e7c17e9..9bc6affb 100644 --- a/server/src/models/User.ts +++ b/server/src/models/User.ts @@ -45,7 +45,7 @@ User.init( }, api_key: { type: DataTypes.STRING, - allowNull: true, + allowNull: true, }, proxy_url: { type: DataTypes.STRING, From 1113cfa59f896c34c485a236bd7b93e90c7c6705 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 22:44:00 +0530 Subject: [PATCH 39/56] feat: -rm type from proxyConfig --- src/api/proxy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/proxy.ts b/src/api/proxy.ts index ebe87f95..7fe73ec6 100644 --- a/src/api/proxy.ts +++ b/src/api/proxy.ts @@ -1,6 +1,6 @@ import { default as axios } from "axios"; -export const sendProxyConfig = async (proxyConfig: { type: string, server: string, username?: string, password?: string }): Promise => { +export const sendProxyConfig = async (proxyConfig: { server: string, username?: string, password?: string }): Promise => { try { const response = await axios.post(`http://localhost:8080/proxy/config`, proxyConfig); if (response.status === 200) { From a8151c84759ec8d71fa0adf581ed31139e7fa209 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 22:44:55 +0530 Subject: [PATCH 40/56] feat: -rm proxy type form control --- src/components/organisms/ProxyForm.tsx | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index 157dad8e..a9edd6a6 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -18,7 +18,6 @@ const FormControl = styled(Box)({ const ProxyForm: React.FC = () => { const [proxyConfig, setProxyConfig] = useState({ - type: 'http', server: '', username: '', password: '', @@ -45,20 +44,6 @@ const ProxyForm: React.FC = () => { return ( - - Select Proxy Type - - } label="HTTP" /> - } label="HTTPS" /> - } label="SOCKS5" /> - - - Proxy Configuration From b1115218e73f703c37d8b8cfbb99554b93c78bce Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 22:45:46 +0530 Subject: [PATCH 41/56] chore: prettier --- src/components/organisms/ProxyForm.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index a9edd6a6..c2a17b3f 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -45,7 +45,6 @@ const ProxyForm: React.FC = () => { Proxy Configuration - { helperText="e.g., http://proxy-server.com:8080" /> - { fullWidth /> - { fullWidth /> - From 992c75bf0000f2ed15e93cd22fb5831205cb36b7 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 23:33:16 +0530 Subject: [PATCH 42/56] feat: check if proxy requires auth & accordingly show username & password fields --- src/components/organisms/ProxyForm.tsx | 58 ++++++++++++++++++-------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index c2a17b3f..b82bb86f 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -1,6 +1,6 @@ import React, { useState } from 'react'; import { styled } from '@mui/system'; -import { TextField, Button, RadioGroup, FormControlLabel, Radio, Box, Typography } from '@mui/material'; +import { TextField, Button, Switch, FormControlLabel, Box, Typography } from '@mui/material'; import { sendProxyConfig } from '../../api/proxy'; import { useGlobalInfoStore } from '../../context/globalInfo'; @@ -22,6 +22,7 @@ const ProxyForm: React.FC = () => { username: '', password: '', }); + const [requiresAuth, setRequiresAuth] = useState(false); const { notify } = useGlobalInfoStore(); @@ -30,6 +31,13 @@ const ProxyForm: React.FC = () => { setProxyConfig({ ...proxyConfig, [name]: value }); }; + const handleAuthToggle = (e: React.ChangeEvent) => { + setRequiresAuth(e.target.checked); + if (!e.target.checked) { + setProxyConfig({ ...proxyConfig, username: '', password: '' }); + } + }; + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); await sendProxyConfig(proxyConfig).then((response) => { @@ -44,7 +52,9 @@ const ProxyForm: React.FC = () => { return ( - Proxy Configuration + + Proxy Configuration + { /> - - - - } + label="Requires Authentication?" /> + {requiresAuth && ( + <> + + + + + + + + )} From 2e1a9381f200d5a0fa9d05ceeb049bc9c13eddb2 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 23:33:43 +0530 Subject: [PATCH 43/56] chore: lint --- src/components/organisms/ProxyForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index b82bb86f..45993e9c 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -105,4 +105,4 @@ const ProxyForm: React.FC = () => { ); }; -export default ProxyForm; +export default ProxyForm; \ No newline at end of file From bdb4102613c0df76fc01d66a2b8ed52c5b0cb065 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 23:34:39 +0530 Subject: [PATCH 44/56] feat: better auth question??? --- src/components/organisms/ProxyForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index 45993e9c..7b83be91 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -69,7 +69,7 @@ const ProxyForm: React.FC = () => { } - label="Requires Authentication?" + label="Does The Proxy Require Authentication?" /> {requiresAuth && ( From 3d0882f8285df520b2da8097a84e7db1be1ea5cb Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 23:39:08 +0530 Subject: [PATCH 45/56] feat: notify errors --- src/components/organisms/ProxyForm.tsx | 59 +++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index 7b83be91..39b1702c 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -23,9 +23,38 @@ const ProxyForm: React.FC = () => { password: '', }); const [requiresAuth, setRequiresAuth] = useState(false); - + const [errors, setErrors] = useState({ + server: '', + username: '', + password: '', + }); + const { notify } = useGlobalInfoStore(); + const validateForm = () => { + let valid = true; + let errorMessages = { server: '', username: '', password: '' }; + + if (!proxyConfig.server) { + errorMessages.server = 'Server URL is required'; + valid = false; + } + + if (requiresAuth) { + if (!proxyConfig.username) { + errorMessages.username = 'Username is required for authenticated proxies'; + valid = false; + } + if (!proxyConfig.password) { + errorMessages.password = 'Password is required for authenticated proxies'; + valid = false; + } + } + + setErrors(errorMessages); + return valid; + }; + const handleChange = (e: React.ChangeEvent) => { const { name, value } = e.target; setProxyConfig({ ...proxyConfig, [name]: value }); @@ -35,11 +64,16 @@ const ProxyForm: React.FC = () => { setRequiresAuth(e.target.checked); if (!e.target.checked) { setProxyConfig({ ...proxyConfig, username: '', password: '' }); + setErrors({ ...errors, username: '', password: '' }); } }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); + if (!validateForm()) { + return; + } + await sendProxyConfig(proxyConfig).then((response) => { if (response) { notify('success', 'Proxy configuration submitted successfully'); @@ -63,13 +97,14 @@ const ProxyForm: React.FC = () => { onChange={handleChange} fullWidth required - helperText="e.g., http://proxy-server.com:8080" + error={!!errors.server} + helperText={errors.server || 'e.g., http://proxy-server.com:8080'} /> } - label="Does The Proxy Require Authentication?" + label="Requires Authentication?" /> {requiresAuth && ( @@ -81,7 +116,9 @@ const ProxyForm: React.FC = () => { value={proxyConfig.username} onChange={handleChange} fullWidth - required + required={requiresAuth} + error={!!errors.username} + helperText={errors.username || ''} /> @@ -92,12 +129,20 @@ const ProxyForm: React.FC = () => { onChange={handleChange} type="password" fullWidth - required + required={requiresAuth} + error={!!errors.password} + helperText={errors.password || ''} /> )} -
@@ -105,4 +150,4 @@ const ProxyForm: React.FC = () => { ); }; -export default ProxyForm; \ No newline at end of file +export default ProxyForm; From 633514547031d4f291ce0a2b088910932133c604 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 23:39:19 +0530 Subject: [PATCH 46/56] chore: lint --- src/components/organisms/ProxyForm.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index 39b1702c..47e6c305 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -28,7 +28,7 @@ const ProxyForm: React.FC = () => { username: '', password: '', }); - + const { notify } = useGlobalInfoStore(); const validateForm = () => { @@ -73,7 +73,7 @@ const ProxyForm: React.FC = () => { if (!validateForm()) { return; } - + await sendProxyConfig(proxyConfig).then((response) => { if (response) { notify('success', 'Proxy configuration submitted successfully'); From 9572061c32caaefb975e6329e6587ecb8ca44bea Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 23:40:46 +0530 Subject: [PATCH 47/56] refactor: rename to server_url --- src/components/organisms/ProxyForm.tsx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index 47e6c305..62869fc9 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -18,13 +18,13 @@ const FormControl = styled(Box)({ const ProxyForm: React.FC = () => { const [proxyConfig, setProxyConfig] = useState({ - server: '', + server_url: '', username: '', password: '', }); const [requiresAuth, setRequiresAuth] = useState(false); const [errors, setErrors] = useState({ - server: '', + server_url: '', username: '', password: '', }); @@ -33,10 +33,10 @@ const ProxyForm: React.FC = () => { const validateForm = () => { let valid = true; - let errorMessages = { server: '', username: '', password: '' }; + let errorMessages = { server_url: '', username: '', password: '' }; - if (!proxyConfig.server) { - errorMessages.server = 'Server URL is required'; + if (!proxyConfig.server_url) { + errorMessages.server_url = 'Server URL is required'; valid = false; } @@ -92,13 +92,13 @@ const ProxyForm: React.FC = () => { @@ -141,7 +141,7 @@ const ProxyForm: React.FC = () => { color="primary" type="submit" fullWidth - disabled={!proxyConfig.server || (requiresAuth && (!proxyConfig.username || !proxyConfig.password))} + disabled={!proxyConfig.server_url || (requiresAuth && (!proxyConfig.username || !proxyConfig.password))} > Add Proxy From 01c1d8c60ad3be0fb04b6958ccccd223b0a5027b Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 23:41:08 +0530 Subject: [PATCH 48/56] refactor: rename to server_url --- src/api/proxy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/proxy.ts b/src/api/proxy.ts index 7fe73ec6..9ae00c55 100644 --- a/src/api/proxy.ts +++ b/src/api/proxy.ts @@ -1,6 +1,6 @@ import { default as axios } from "axios"; -export const sendProxyConfig = async (proxyConfig: { server: string, username?: string, password?: string }): Promise => { +export const sendProxyConfig = async (proxyConfig: { server_url: string, username?: string, password?: string }): Promise => { try { const response = await axios.post(`http://localhost:8080/proxy/config`, proxyConfig); if (response.status === 200) { From ea3a7011e57e924eeb9024129be49667ebfc6f48 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 23:47:32 +0530 Subject: [PATCH 49/56] feat: save proxy details to db --- server/src/routes/proxy.ts | 40 ++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/server/src/routes/proxy.ts b/server/src/routes/proxy.ts index 2f130bb9..a5bf7996 100644 --- a/server/src/routes/proxy.ts +++ b/server/src/routes/proxy.ts @@ -1,14 +1,42 @@ import { Router, Request, Response } from 'express'; +import User from '../models/User'; +import { hashPassword, comparePassword } from '../utils/auth'; + export const router = Router(); router.post('/config', async (req: Request, res: Response) => { - const { proxyConfig } = req.body; + const { server_url, username, password } = req.body; + try { - if (!proxyConfig) { - return res.status(400).send('Proxy configuration is required'); + if (!server_url) { + return res.status(400).send('Proxy URL is required'); } - console.log(proxyConfig); + + const userId = 1; + const user = await User.findByPk(userId); + + if (!user) { + return res.status(404).send('User not found'); + } + + let hashedProxyUsername: string | null = null; + let hashedProxyPassword: string | null = null; + + if (username && password) { + hashedProxyUsername = await hashPassword(username); + hashedProxyPassword = await hashPassword(password); + } else if (username && !password) { + return res.status(400).send('Proxy password is required when proxy username is provided'); + } + + user.proxy_url = server_url; + user.proxy_username = hashedProxyUsername; + user.proxy_password = hashedProxyPassword; + + await user.save(); + + res.status(200).send('Proxy configuration saved successfully'); } catch (error: any) { - res.status(500).send(`Could not send proxy configuration - ${error.message}`) + res.status(500).send(`Could not save proxy configuration - ${error.message}`); } -}) \ No newline at end of file +}); From ed6b3431f15d8b97e97cadae56d198eca0dc961d Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 23:47:45 +0530 Subject: [PATCH 50/56] chore: prettier --- server/src/routes/proxy.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/routes/proxy.ts b/server/src/routes/proxy.ts index a5bf7996..dd57129b 100644 --- a/server/src/routes/proxy.ts +++ b/server/src/routes/proxy.ts @@ -1,5 +1,5 @@ import { Router, Request, Response } from 'express'; -import User from '../models/User'; +import User from '../models/User'; import { hashPassword, comparePassword } from '../utils/auth'; export const router = Router(); @@ -12,7 +12,7 @@ router.post('/config', async (req: Request, res: Response) => { return res.status(400).send('Proxy URL is required'); } - const userId = 1; + const userId = 1; const user = await User.findByPk(userId); if (!user) { From 14ae8b2acb089d7b2a8571bf77e124b629e3c201 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 23:48:04 +0530 Subject: [PATCH 51/56] chore: remove unused import --- server/src/routes/proxy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/routes/proxy.ts b/server/src/routes/proxy.ts index dd57129b..c5821270 100644 --- a/server/src/routes/proxy.ts +++ b/server/src/routes/proxy.ts @@ -1,6 +1,6 @@ import { Router, Request, Response } from 'express'; import User from '../models/User'; -import { hashPassword, comparePassword } from '../utils/auth'; +import { hashPassword } from '../utils/auth'; export const router = Router(); From 92fa9435a820eeb76ad3348bf38f36c9d82bdb77 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 23:49:39 +0530 Subject: [PATCH 52/56] feat: use requireSignIn middleware --- server/src/routes/proxy.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/routes/proxy.ts b/server/src/routes/proxy.ts index c5821270..6665d581 100644 --- a/server/src/routes/proxy.ts +++ b/server/src/routes/proxy.ts @@ -1,10 +1,11 @@ import { Router, Request, Response } from 'express'; import User from '../models/User'; import { hashPassword } from '../utils/auth'; +import { requireSignIn } from '../middlewares/auth'; export const router = Router(); -router.post('/config', async (req: Request, res: Response) => { +router.post('/config', requireSignIn, async (req: Request, res: Response) => { const { server_url, username, password } = req.body; try { From 801fb0e1f9e4015aaaed4aa248bfc0cdf7948f6f Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 23:50:12 +0530 Subject: [PATCH 53/56] feat: authenticated request interface --- server/src/routes/proxy.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/src/routes/proxy.ts b/server/src/routes/proxy.ts index 6665d581..a4663a37 100644 --- a/server/src/routes/proxy.ts +++ b/server/src/routes/proxy.ts @@ -5,6 +5,10 @@ import { requireSignIn } from '../middlewares/auth'; export const router = Router(); +interface AuthenticatedRequest extends Request { + user?: { id: string }; +} + router.post('/config', requireSignIn, async (req: Request, res: Response) => { const { server_url, username, password } = req.body; From 1abf8348ffed37ee96ea33413af5c6f51c0b849a Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 23:50:59 +0530 Subject: [PATCH 54/56] feat: set req type as AuthenticatedRequest --- server/src/routes/proxy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/routes/proxy.ts b/server/src/routes/proxy.ts index a4663a37..13549f8d 100644 --- a/server/src/routes/proxy.ts +++ b/server/src/routes/proxy.ts @@ -9,7 +9,7 @@ interface AuthenticatedRequest extends Request { user?: { id: string }; } -router.post('/config', requireSignIn, async (req: Request, res: Response) => { +router.post('/config', requireSignIn, async (req: AuthenticatedRequest, res: Response) => { const { server_url, username, password } = req.body; try { From 538bf59510f75b94c3f4f87b99a43aa7b2fad2c6 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 23:51:55 +0530 Subject: [PATCH 55/56] feat: get user from req --- server/src/routes/proxy.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/server/src/routes/proxy.ts b/server/src/routes/proxy.ts index 13549f8d..eb2b89a4 100644 --- a/server/src/routes/proxy.ts +++ b/server/src/routes/proxy.ts @@ -13,15 +13,21 @@ router.post('/config', requireSignIn, async (req: AuthenticatedRequest, res: Res const { server_url, username, password } = req.body; try { - if (!server_url) { - return res.status(400).send('Proxy URL is required'); - } - const userId = 1; - const user = await User.findByPk(userId); + if (!req.user) { + return res.status(401).json({ ok: false, error: 'Unauthorized' }); + } + + const user = await User.findByPk(req.user.id, { + attributes: { exclude: ['password'] }, + }); if (!user) { - return res.status(404).send('User not found'); + return res.status(404).json({ message: 'User not found' }); + } + + if (!server_url) { + return res.status(400).send('Proxy URL is required'); } let hashedProxyUsername: string | null = null; From f0aad5685dd8ba2a4cd1911e988f9e96be8ea5fc Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 23:52:09 +0530 Subject: [PATCH 56/56] chore: lint --- server/src/routes/proxy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/routes/proxy.ts b/server/src/routes/proxy.ts index eb2b89a4..ff20d31e 100644 --- a/server/src/routes/proxy.ts +++ b/server/src/routes/proxy.ts @@ -17,7 +17,7 @@ router.post('/config', requireSignIn, async (req: AuthenticatedRequest, res: Res if (!req.user) { return res.status(401).json({ ok: false, error: 'Unauthorized' }); } - + const user = await User.findByPk(req.user.id, { attributes: { exclude: ['password'] }, });