diff --git a/front-js/package.json b/front-js/package.json index e322484..fc4d231 100644 --- a/front-js/package.json +++ b/front-js/package.json @@ -18,6 +18,7 @@ "js-cookie": "^3.0.5", "next": "15.1.0", "react": "^19.0.0", + "react-code-blocks": "^0.1.6", "react-apple-emojis": "^2.2.2", "react-code-blocks": "^0.1.6", "react-dom": "^19.0.0", diff --git a/front-js/src/app/dashboard/page.tsx b/front-js/src/app/dashboard/page.tsx index cfd4a9a..4e29c25 100644 --- a/front-js/src/app/dashboard/page.tsx +++ b/front-js/src/app/dashboard/page.tsx @@ -112,7 +112,7 @@ export default function Dashboard() { router.push("/modules/ipv6")} /> @@ -120,7 +120,7 @@ export default function Dashboard() { @@ -135,7 +135,7 @@ export default function Dashboard() { router.push("/modules/vlsm")} /> @@ -143,8 +143,9 @@ export default function Dashboard() { router.push("/modules/ethernet")} /> @@ -158,14 +159,14 @@ export default function Dashboard() { router.push("/modules/interface_reseau")} /> diff --git a/front-js/src/app/modules/ethernet/Cours.tsx b/front-js/src/app/modules/ethernet/Cours.tsx new file mode 100644 index 0000000..4a5c46f --- /dev/null +++ b/front-js/src/app/modules/ethernet/Cours.tsx @@ -0,0 +1,54 @@ +import Space from "@/components/Space" +import Title from "@/components/Title" +import { EmojiProvider } from "react-apple-emojis" +import Text from "@/components/Text" +import emojiData from "react-apple-emojis/src/data.json"; +import { Code, CodeBlock, solarizedLight } from "react-code-blocks"; +import { text } from "stream/consumers"; + + +const CoursEthernet: React.FC = () => { + + const example = `{ + "frame": { + "dst_mac": "FF:FF:FF:FF:FF:FF", + "src_mac": "00:11:22:33:44:55", + "eth_type": "0x0800", + "frame_hex": "FFFFFFFFFFFF0011223344550800" + } + }`; + + return ( + + + + Ethernet + + Bienvenue sur le module Ethernet. Ce module génère une trame Ethernet basée sur les paramètres fournis. + Elle utilise les informations sur les adresses MAC source et destination ainsi que le type Ethernet (exprimé en hexadécimal). + La trame générée est renvoyée au format JSON. + + + Entrées : + ・Adresse MAC de destination, (par exemple, FF:FF:FF:FF:FF:FF). + ・Adresse MAC source, (par exemple, 00:11:22:33:44:55). + ・Type de trame ethernet, (cf Types de trames). + + Types de trames Ethernet : + ・0x0800 pour IPv4 + ・0x0806 pour ARP + ・0x86DD pour IPv6 + ・0x8100 pour VLAN + + Exemple de réponse 200 OK + + + + ) +} + +export default CoursEthernet \ No newline at end of file diff --git a/front-js/src/app/modules/ethernet/EthernetSandbox.tsx b/front-js/src/app/modules/ethernet/EthernetSandbox.tsx new file mode 100644 index 0000000..817199e --- /dev/null +++ b/front-js/src/app/modules/ethernet/EthernetSandbox.tsx @@ -0,0 +1,113 @@ +import Title from "@/components/Title"; +import Button from "@/components/Button"; +import Input from "@/components/Input"; +import Space from "@/components/Space"; +import React from "react"; +import { useState } from "react"; +import { Alert } from "@mui/material"; +import Box from "@/components/Box"; +import Cookies from "js-cookie"; +import axios from "@/axiosConfig"; +import { AxiosError } from "axios"; +import { CodeBlock, solarizedLight } from "react-code-blocks"; + +const EthernetSandbox: React.FC = () => { + const [masdst, setMacdst] = useState(""); + const [macsrc, setMacsrc] = useState(""); + const [typetrame, setTypetrame] = useState(""); + const [simpleRes, setSimpleRes] = useState(""); + + const handleEthernet = async (e: { preventDefault: () => void }) => { + e.preventDefault(); + try { + const response = await axios.get( + `/scapy/ethernet-frame/${masdst}/${macsrc}/${typetrame}`, + { + headers: { + Authorization: `Bearer ${Cookies.get("access_token")}`, + }, + } + ); + const data = response.data; + if (response.status === 200) { + setSimpleRes(data.frame); + } + } catch (error: unknown) { + const axiosError = error as AxiosError; + if (axiosError.response?.status === 400) { + const data = axiosError.response.data as { detail: string }; + setSimpleRes(data.detail || "Erreur lors de la création de la trame Ethernet"); + } else { + setSimpleRes("Erreur inattendue lors de l'appel API"); + } + } + }; + + + return ( + <> + +
+ Rédiger votre trame Ethernet : + + setMacdst(e.target.value)} + required + label="Adresse mac destination" + /> + setMacsrc(e.target.value)} + required + label="Adresse mac source" + /> + setTypetrame(e.target.value)} + required + label="Type de trame Ethernet" + /> +