Forbid web redirect

This commit is contained in:
Keannu Bernasol 2023-07-23 21:49:36 +08:00
parent 0a289cdb0c
commit a34872affe

View file

@ -6,7 +6,7 @@ import { useState, useEffect } from "react";
const router = createHashRouter([
{
path: "redirect/:name/:slug1/:slug2",
path: "redirect/:name/:slug1/:slug2/:slug3",
element: <RedirectPage />,
},
]);
@ -23,11 +23,16 @@ function App() {
return <RouterProvider router={router} />;
}
function RedirectPage() {
const { name, slug1, slug2 } = useParams();
const [color, setColor] = useState<CircularProgressColor>("inherit");
const [feedback, setFeedback] = useState("");
const forbid_web_links = true;
const { name, slug1, slug2, slug3 } = useParams(); // URL Params
const [color, setColor] = useState<CircularProgressColor>("inherit"); // Spinner color
const [feedback, setFeedback] = useState(
"Opening " + name + " on your mobile device "
); // Feedback to display to user
const [error, setError] = useState(false);
const url = name + "://" + slug1 + "/" + slug2;
const [forbidden, setForbidden] = useState(false); // If link is forbidden (HTTP/HTTPS)
const [checked, setChecked] = useState(false); // If linked has been checked already
const url = name + "://" + slug1 + "/" + slug2 + "/" + slug3; // URL to redirect to
function ManualButton() {
if (error) {
return (
@ -43,6 +48,18 @@ function RedirectPage() {
return <view />;
}
useEffect(() => {
if (
(name === "http" ||
name === "HTTP" ||
name === "https" ||
name === "HTTPS") &&
forbid_web_links
) {
setFeedback("Simple redirect is not allowed to redirect HTTP links");
setColor("error");
setForbidden(true);
}
if (!forbidden && checked) {
setTimeout(() => {
window.open(url, "_blank");
}, 2000);
@ -57,10 +74,12 @@ function RedirectPage() {
);
setError(true);
}, 5000);
}, []);
}
setChecked(true);
}, [forbidden, name, url, checked, forbid_web_links]);
return (
<view>
<CircularProgress size={128} color={color} />
<CircularProgress size={error ? 128 : 0} color={color} />
<view
style={{
display: "flex",
@ -72,10 +91,8 @@ function RedirectPage() {
<view style={{ padding: 16 }} />
<h5>{"URL Payload 2:" + slug2}</h5>
</view>
<h1 style={{ color: "white", textAlign: "center" }}>
{"Opening " + name + " on your mobile device "}
</h1>
<h2>{feedback}</h2>
<h5>{"URL Payload 3:" + slug3}</h5>
<h2 style={{ color: "white", textAlign: "center" }}>{feedback}</h2>
<ManualButton />
</view>
);