This repository has been archived by the owner on Jul 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from gt732/react
React
- Loading branch information
Showing
28 changed files
with
522 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { Box, Button, Text, Textarea } from '@chakra-ui/react'; | ||
import Disclaimer from '../main/Disclaimer'; | ||
import Chatgpt from '../chatgpt/Chatgpt'; | ||
|
||
export default function Interfaces() { | ||
const [intfs, setIntfs] = useState([]); | ||
const [buttonLoading, setButtonLoading] = useState([]); | ||
const [debugOutput, setDebugOutput] = useState(''); | ||
const [ChatGptPrompt, setChatGptPrompt] = useState(''); | ||
const [documentationLink, setDocumentationLink] = useState(''); | ||
|
||
function getInterfaces() { | ||
// Fetch the list of BGP neighbors | ||
fetch(`/network/get_interface_list`) | ||
.then(response => response.json()) | ||
.then(data => { | ||
const interfaceValuesArray = Object.values(data.results); | ||
setIntfs(interfaceValuesArray); | ||
setButtonLoading(interfaceValuesArray.map(() => false)); | ||
}) | ||
.catch(error => { | ||
console.error(error); | ||
}); | ||
} | ||
|
||
function handleClick(intf, index) { | ||
const requestOptions = { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
intf: intf, | ||
}), | ||
}; | ||
// Set loading state of the individual button to true | ||
setButtonLoading(buttonLoading.map((val, i) => (i === index ? true : val))); | ||
|
||
fetch('network/interface_issue_script', requestOptions) | ||
.then(response => response.text()) | ||
.then(data => { | ||
setDebugOutput(data); | ||
|
||
// Set loading state of the individual button to false | ||
setButtonLoading( | ||
buttonLoading.map((val, i) => (i === index ? false : val)) | ||
); | ||
}) | ||
|
||
.catch(error => { | ||
setDebugOutput('Try Logging in again'); | ||
|
||
// Set loading state of the individual button to false | ||
setButtonLoading( | ||
buttonLoading.map((val, i) => (i === index ? false : val)) | ||
); | ||
}); | ||
} | ||
|
||
useEffect(() => { | ||
// Fetch the chatgpt prompt | ||
fetch('/chatgpt_prompts/network/interface_issue.txt') | ||
.then(response => response.text()) | ||
.then(text => { | ||
setChatGptPrompt(text); | ||
}) | ||
.catch(error => { | ||
console.error(error); | ||
}); | ||
}, []); | ||
|
||
useEffect(() => { | ||
// Fetch the documentation link | ||
fetch('/chatgpt_prompts/network/interface_issue_link.txt') | ||
.then(response => response.text()) | ||
.then(text => { | ||
setDocumentationLink(text); | ||
}) | ||
.catch(error => { | ||
console.error(error); | ||
}); | ||
}, []); | ||
|
||
useEffect(() => { | ||
getInterfaces(); | ||
}, []); | ||
|
||
return [ | ||
<Text p="10px" fontSize={15} color="white"> | ||
👉 Instructions: Click on the Interface to gather debugs and statistics, | ||
once complete click on Run FortiGPT 👈 | ||
</Text>, | ||
|
||
<Box my="4"> | ||
{intfs.map((intf, index) => ( | ||
<Button | ||
onClick={() => handleClick(intf.name, index)} | ||
colorScheme={intf.link == true ? 'green' : 'red'} | ||
key={intf.name} | ||
borderRadius="full" | ||
m="2" | ||
isLoading={buttonLoading[index]} | ||
loadingText={intf.name} | ||
> | ||
{intf.name} | ||
</Button> | ||
))} | ||
</Box>, | ||
|
||
<Text p="15px" color="white" fontWeight="bold"> | ||
✨ DEBUG OUTPUT ✨ | ||
</Text>, | ||
|
||
<Textarea | ||
color="white" | ||
bg="gray.800" | ||
defaultValue={debugOutput} | ||
my={4} | ||
size="md" | ||
maxWidth="2xl" | ||
/>, | ||
<> | ||
<Disclaimer documentationLink={documentationLink} /> | ||
</>, | ||
<> | ||
{debugOutput && ( | ||
<Chatgpt debugOutput={debugOutput} chatGptPrompt={ChatGptPrompt} /> | ||
)} | ||
</>, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { Button, HStack, Text, Textarea } from '@chakra-ui/react'; | ||
import Disclaimer from '../main/Disclaimer'; | ||
import Chatgpt from '../chatgpt/Chatgpt'; | ||
|
||
export default function Fortiguard() { | ||
const [debugOutput, setDebugOutput] = useState(''); | ||
const [loading, setLoading] = useState(false); | ||
const [ChatGptPrompt, setChatGptPrompt] = useState(''); | ||
const [documentationLink, setDocumentationLink] = useState(''); | ||
|
||
function handleClick() { | ||
// Run the fortiguard debug script | ||
setLoading(true); | ||
setDebugOutput(''); | ||
fetch('/system/fortiguard_script', { | ||
method: 'POST', | ||
}) | ||
.then(response => response.text()) | ||
.then(data => { | ||
setDebugOutput(data); | ||
setLoading(false); | ||
}) | ||
.catch(error => { | ||
console.error(error); | ||
setDebugOutput('Try Logging in again'); | ||
setLoading(false); | ||
}); | ||
} | ||
|
||
useEffect(() => { | ||
// Get the chatgpt prompt | ||
fetch('/chatgpt_prompts/system/fortiguard.txt') | ||
.then(response => response.text()) | ||
.then(text => { | ||
setChatGptPrompt(text); | ||
}) | ||
.catch(error => { | ||
console.error(error); | ||
}); | ||
}, []); | ||
|
||
useEffect(() => { | ||
// Get the documentation link | ||
fetch('/chatgpt_prompts/system/fortiguard_link.txt') | ||
.then(response => response.text()) | ||
.then(text => { | ||
setDocumentationLink(text); | ||
}) | ||
.catch(error => { | ||
console.error(error); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<Text p="10px" fontSize={15} color="white"> | ||
👉 Instructions: Click Start Debug to gather Fortiguard statistics, once | ||
complete click on Run FortiGPT 👈 | ||
</Text> | ||
|
||
<HStack> | ||
<Text p="15px" color="white" fontWeight="bold"> | ||
✨ DEBUG OUTPUT ✨ | ||
</Text> | ||
<Button | ||
borderRadius="full" | ||
colorScheme="blue" | ||
size="md" | ||
ml={4} | ||
isLoading={loading} | ||
onClick={handleClick} | ||
loadingText="Start Debug" | ||
> | ||
Start Debug | ||
</Button> | ||
</HStack> | ||
|
||
<Textarea | ||
color="white" | ||
bg="gray.800" | ||
defaultValue={debugOutput} | ||
my={4} | ||
size="md" | ||
maxWidth="2xl" | ||
/> | ||
|
||
<> | ||
<Disclaimer documentationLink={documentationLink} /> | ||
</> | ||
|
||
<> | ||
{debugOutput && ( | ||
<Chatgpt debugOutput={debugOutput} chatGptPrompt={ChatGptPrompt} /> | ||
)} | ||
</> | ||
</> | ||
); | ||
} |
Oops, something went wrong.