partial synch with ph2 updates
This commit is contained in:
@@ -207,6 +207,35 @@ const SignIn = (props) => {
|
||||
};
|
||||
|
||||
export async function getServerSideProps(context) {
|
||||
const { query, req, res } = context;
|
||||
|
||||
// Load allowed IPs from env and trim spaces
|
||||
const ALLOWED_IPS = process.env.ALLOWED_IPS
|
||||
? process.env.ALLOWED_IPS.split(",").map((ip) => ip.trim())
|
||||
: [];
|
||||
|
||||
// Always allow localhost addresses
|
||||
const LOCALHOST_IPS = ["127.0.0.1", "::1"];
|
||||
|
||||
// Get IP address from headers or socket
|
||||
const forwarded = req.headers["x-forwarded-for"];
|
||||
const ip =
|
||||
typeof forwarded === "string"
|
||||
? forwarded.split(",")[0]
|
||||
: req.socket.remoteAddress;
|
||||
|
||||
console.log("Visitor IP:", ip);
|
||||
|
||||
// Check whitelist + localhost
|
||||
if (![...ALLOWED_IPS, ...LOCALHOST_IPS].includes(ip)) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/403", // custom "Access Denied" page
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (process.env.SHOWLOGIN == false) {
|
||||
return {
|
||||
redirect: {
|
||||
|
||||
Reference in New Issue
Block a user