From b86712efb8dc4bcbcd7216e06ad8ebe4c762447b Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Thu, 14 Aug 2025 08:25:20 +0100 Subject: [PATCH] storage admin update --- actions/azurestorage.js | 27 -- pages/auth/signin2.js | 29 ++ pages/storageAdmin.js | 653 ++++++++++++++++++++++++---------------- 3 files changed, 416 insertions(+), 293 deletions(-) diff --git a/actions/azurestorage.js b/actions/azurestorage.js index 2ecad913..68206580 100644 --- a/actions/azurestorage.js +++ b/actions/azurestorage.js @@ -1715,33 +1715,6 @@ function formatDateDisplay(date) { : "Unknown"; } -function formatBlobDates(blob) { - const created = blob.createdOn ? new Date(blob.createdOn) : null; - const modified = blob.lastModified ? new Date(blob.lastModified) : null; - - if (!created && !modified) return "Unknown"; - - // If both exist and are the same - if (created && modified && created.getTime() === modified.getTime()) { - return `${created.toLocaleString("en-GB")} (${formatTimeSince( - created - )})`; - } - - // If modified exists and is newer than created - if (created && modified && modified.getTime() > created.getTime()) { - return `Created: ${created.toLocaleString("en-GB")} (${formatTimeSince( - created - )}), Modified: ${modified.toLocaleString("en-GB")} (${formatTimeSince( - modified - )})`; - } - - // Only one date exists - const date = modified || created; - return `${date.toLocaleString("en-GB")} (${formatTimeSince(date)})`; -} - export async function listBlobHierarchicalForUser(containerClient) { const blobNames = []; for await (const blob of containerClient.listBlobsFlat()) { diff --git a/pages/auth/signin2.js b/pages/auth/signin2.js index 0e14448a..569281e7 100644 --- a/pages/auth/signin2.js +++ b/pages/auth/signin2.js @@ -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: { diff --git a/pages/storageAdmin.js b/pages/storageAdmin.js index c65167d9..805cbdc3 100644 --- a/pages/storageAdmin.js +++ b/pages/storageAdmin.js @@ -110,11 +110,11 @@ const deleteCaseItem = (containerID, caseID) => { }); }; -export default function StoragePage({ data }) { - console.log(data); - +export default function StoragePage(props) { + const { data, userData } = props; const [showRepJson, setShowRepJson] = useState(true); const [showTmpFile, setShowTmpFile] = useState(true); + const [whichTab, setWhichTab] = useState("storage"); const toggleAll = () => { const newState = !(showRepJson || showTmpFile); @@ -130,283 +130,394 @@ export default function StoragePage({ data }) {
-
-

Storage Account Contents

+
+
+

Contents

+ +
+

Storage Account Contents

- {/* Toggle buttons */} -
- - - -
+ {/* Toggle buttons */} +
+ + + +
- {data.map((user) => ( -
- {user.containers.map((c) => ( -
-
-

- {c.container} - {user.email} -

- {c.folders.map((folder) => ( -
-

- {folder.folderPath || - "Root"} -

- {/* {folder.hasRepJson && ( + {data.map((user) => ( +
+ {user.containers.map((c) => ( +
+
+

+ {c.container} -{" "} + +

+ {folder.folderPath || + "Root"} +

+ {/* {folder.hasRepJson && (

rep.json file found:{" "} {folder.repJsonBlob.name}

)} */} - {folder.hasTmpFile && ( - <> - - - )} - {folder.hasRepJson && ( -
- {" "} - - {folder.repComplete && ( - - )} - {folder.repComplete && ( - - )} -
- )} - -
    - {folder.blobs.map( - (blob) => ( -
  • - + + + )} + {folder.hasRepJson && ( +
    + {" "} + + {folder.repComplete && ( + + )} + {folder.repComplete && ( + + )} +
    + )} + +
      + {folder.blobs.map( + (blob) => ( +
    • + + { + blob.name + }{" "} + ( + {bytesToSize( + blob.contentLength || + blob.size + )} + + ) + {" "} + {blob.lastModified && ( + + {/* { blob.displayDate } */} - {formatBlobDates( - blob + {formatBlobDates( + blob + )} + )} - - )} -
    • - ) - )} -
    +
  • + ) + )} +
+
+ ))}
- ))} -
+
+ ))}
))}
- ))} +
+

User Accounts

+
+
+
+ Name +
+
+ Last accessed +
+
+ + {userData.map((user) => ( +
+
+ + Last accessed: {user.created}{" "} +
+
+ ))} +
+
+