dsql-admin/dsql-app/.local_dist/server/pages/admin/[user_id]/connect.js

1552 lines
70 KiB
JavaScript
Raw Normal View History

2024-11-05 11:12:42 +00:00
"use strict";
(() => {
var exports = {};
exports.id = 3095;
exports.ids = [3095];
exports.modules = {
/***/ 5782:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
"ConnectContext": () => (/* binding */ ConnectContext),
"default": () => (/* binding */ DatabaseSchema),
"getServerSideProps": () => (/* binding */ getServerSideProps)
});
// EXTERNAL MODULE: external "react/jsx-runtime"
var jsx_runtime_ = __webpack_require__(997);
// EXTERNAL MODULE: external "react"
var external_react_ = __webpack_require__(6689);
var external_react_default = /*#__PURE__*/__webpack_require__.n(external_react_);
// EXTERNAL MODULE: ./layouts/AdminLayout.jsx + 2 modules
var AdminLayout = __webpack_require__(4858);
// EXTERNAL MODULE: ./functions/backend/userAuth.js
var userAuth = __webpack_require__(370);
var userAuth_default = /*#__PURE__*/__webpack_require__.n(userAuth);
// EXTERNAL MODULE: ./package-shared/utils/backend/global-db/DB_HANDLER.js
var DB_HANDLER = __webpack_require__(9395);
var DB_HANDLER_default = /*#__PURE__*/__webpack_require__.n(DB_HANDLER);
// EXTERNAL MODULE: ./components/general/Breadcrumbs.jsx
var Breadcrumbs = __webpack_require__(424);
;// CONCATENATED MODULE: external "@mui/icons-material/ContentCopyOutlined"
const ContentCopyOutlined_namespaceObject = require("@mui/icons-material/ContentCopyOutlined");
var ContentCopyOutlined_default = /*#__PURE__*/__webpack_require__.n(ContentCopyOutlined_namespaceObject);
;// CONCATENATED MODULE: external "@mui/icons-material/SystemUpdateAltOutlined"
const SystemUpdateAltOutlined_namespaceObject = require("@mui/icons-material/SystemUpdateAltOutlined");
var SystemUpdateAltOutlined_default = /*#__PURE__*/__webpack_require__.n(SystemUpdateAltOutlined_namespaceObject);
;// CONCATENATED MODULE: ./components/admin/connect/ConnectionInfo.jsx
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Main Component { Functional }
* ==============================================================================
* @param {Object} props - Server props
*/ function ConnectionInfo(props) {
/**
* Get Contexts
*
* @abstract { React.useContext }
*/ const { user , query , mariadbUserCred } = external_react_default().useContext(ConnectContext);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Javascript Variables
*
* @abstract Non hook variables and functions
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* React Hooks
*
* @abstract { useState, useEffect, useRef, etc ... }
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Function Return
*
* @abstract Main Function Return
*/ return /*#__PURE__*/ jsx_runtime_.jsx("section", {
className: "paper",
children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "flex-col items-start w-full",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("span", {
children: "You can connect to your database remotely using any MySQL/Mariadb client. Use these credentials to connect:"
}),
/*#__PURE__*/ jsx_runtime_.jsx("hr", {}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("ul", {
className: "m-0",
children: [
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("li", {
children: [
"Server:",
" ",
/*#__PURE__*/ jsx_runtime_.jsx("b", {
children: "172.72.0.32" || 0
})
]
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("li", {
children: [
"Username: ",
/*#__PURE__*/ jsx_runtime_.jsx("b", {
children: mariadbUserCred.mariadb_user
})
]
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("li", {
children: [
"Host: ",
/*#__PURE__*/ jsx_runtime_.jsx("b", {
children: mariadbUserCred.mariadb_host
})
]
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("li", {
children: [
"Password: ",
/*#__PURE__*/ jsx_runtime_.jsx("b", {
children: "*****************"
}),
/*#__PURE__*/ jsx_runtime_.jsx("button", {
className: "ghost inline-block -my-4",
onClick: (e)=>{
navigator.clipboard.writeText(mariadbUserCred.mariadb_pass || "").then(()=>{
window.alert("Copied Password!");
});
},
children: /*#__PURE__*/ jsx_runtime_.jsx((ContentCopyOutlined_default()), {})
})
]
}),
/*#__PURE__*/ jsx_runtime_.jsx("li", {
children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "flex",
children: [
"SSL Certificate:",
" ",
/*#__PURE__*/ jsx_runtime_.jsx("b", {
children: /*#__PURE__*/ jsx_runtime_.jsx("span", {
className: "flex items-center gap-2",
children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)("a", {
href: "https://datasquirel.com/documents/ssl/ca-cert.pem",
className: "flex items-center gap-2 border-none hover:opacity-60",
target: "_blank",
children: [
/*#__PURE__*/ jsx_runtime_.jsx((SystemUpdateAltOutlined_default()), {
className: "-mt-[3px]"
}),
"Download"
]
})
})
})
]
})
})
]
})
]
})
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
;// CONCATENATED MODULE: external "@mui/icons-material/EditNoteOutlined"
const EditNoteOutlined_namespaceObject = require("@mui/icons-material/EditNoteOutlined");
var EditNoteOutlined_default = /*#__PURE__*/__webpack_require__.n(EditNoteOutlined_namespaceObject);
// EXTERNAL MODULE: ./components/general/GeneralPopup.jsx
var GeneralPopup = __webpack_require__(5472);
// EXTERNAL MODULE: ./components/general/LoadingBlock.jsx
var LoadingBlock = __webpack_require__(5264);
// EXTERNAL MODULE: external "@mui/icons-material/DeleteOutlineOutlined"
var DeleteOutlineOutlined_ = __webpack_require__(8757);
var DeleteOutlineOutlined_default = /*#__PURE__*/__webpack_require__.n(DeleteOutlineOutlined_);
// EXTERNAL MODULE: ./functions/frontend/fetchApi.js
var fetchApi = __webpack_require__(6729);
;// CONCATENATED MODULE: ./components/admin/connect/MariaDBUserCard.jsx
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Main Component { Functional }
* ==============================================================================
* @param {Object} props - Server props
* @param {import("@/package-shared/types").MYSQL_mariadb_users_table_def} props.mariadbUser
*/ function MariaDBUserCard({ mariadbUser }) {
/**
* Get Contexts
*
* @abstract { React.useContext }
*/ const { setTargetMariadbUser } = external_react_default().useContext(ConnectContext);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Javascript Variables
*
* @abstract Non hook variables and functions
*/ const isPrimary = String(mariadbUser.primary)?.match(/1/) ? true : false;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* React Hooks
*
* @abstract { useState, useEffect, useRef, etc ... }
*/ const [loading, setLoading] = external_react_default().useState(false);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Function Return
*
* @abstract Main Function Return
*/ return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "card w-full col" + (isPrimary ? " green" : ""),
children: [
loading && /*#__PURE__*/ jsx_runtime_.jsx(LoadingBlock/* default */.Z, {
width: "25px"
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "w-full justify-between h-auto md:h-8 flex-wrap",
children: [
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("span", {
className: "title",
children: [
mariadbUser.username,
"@",
mariadbUser.host
]
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
children: [
isPrimary && /*#__PURE__*/ jsx_runtime_.jsx("span", {
className: "info small w-auto",
children: "Primary User"
}),
/*#__PURE__*/ jsx_runtime_.jsx("button", {
className: "ghost",
title: "Edit User",
onClick: (e)=>{
setTargetMariadbUser(mariadbUser);
(0,GeneralPopup/* openPopup */.Mw)("edit-mariadb-user-popup");
},
children: /*#__PURE__*/ jsx_runtime_.jsx((EditNoteOutlined_default()), {})
}),
!isPrimary && /*#__PURE__*/ jsx_runtime_.jsx("button", {
className: "ghost -ml-6",
title: "Edit User",
onClick: (e)=>{
if (window.confirm("Are you sure you want to delete this User?")) {
setLoading(true);
(0,fetchApi/* default */.Z)("/api/sql-users/delete", {
method: "POST",
body: {
id: mariadbUser.id
}
}, true).then((res)=>{
if (res.success) {
window.location.reload();
} else if (res.msg) {
window.alert(res.msg);
}
}).finally(()=>{
setTimeout(()=>{
setLoading(false);
}, 1000);
});
}
},
children: /*#__PURE__*/ jsx_runtime_.jsx((DeleteOutlineOutlined_default()), {})
})
]
})
]
}),
/*#__PURE__*/ jsx_runtime_.jsx("hr", {}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("ul", {
className: "m-0",
children: [
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("li", {
children: [
"Username: ",
/*#__PURE__*/ jsx_runtime_.jsx("b", {
children: mariadbUser.username
})
]
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("li", {
children: [
"Host: ",
/*#__PURE__*/ jsx_runtime_.jsx("b", {
children: mariadbUser.host
}),
/*#__PURE__*/ jsx_runtime_.jsx("span", {
className: "info gray font-normal",
children: "% is a wildcard. Example: 192.168.1.%"
})
]
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("li", {
children: [
"Password: ",
/*#__PURE__*/ jsx_runtime_.jsx("b", {
children: "*****************"
}),
/*#__PURE__*/ jsx_runtime_.jsx("button", {
className: "ghost inline-block -my-4",
onClick: (e)=>{
navigator.clipboard.writeText(mariadbUser.password || "").then(()=>{
window.alert("Copied Password!");
});
},
children: /*#__PURE__*/ jsx_runtime_.jsx((ContentCopyOutlined_default()), {
className: "text-[15px] -ml-2"
})
})
]
})
]
})
]
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
;// CONCATENATED MODULE: ./components/admin/connect/MariaDBUsers.jsx
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Main Component { Functional }
* ==============================================================================
* @param {Object} props - Server props
*/ function MariaDBUsers(props) {
/**
* Get Contexts
*
* @abstract { React.useContext }
*/ const { mariadbUsers } = external_react_default().useContext(ConnectContext);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Javascript Variables
*
* @abstract Non hook variables and functions
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* React Hooks
*
* @abstract { useState, useEffect, useRef, etc ... }
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Function Return
*
* @abstract Main Function Return
*/ return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("section", {
className: "paper",
children: [
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "w-full justify-between",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("h2", {
className: "text-xl m-0",
children: "SQL Users"
}),
/*#__PURE__*/ jsx_runtime_.jsx("div", {
children: /*#__PURE__*/ jsx_runtime_.jsx("button", {
onClick: (e)=>{
(0,GeneralPopup/* openPopup */.Mw)("new-mariadb-user-popup");
},
children: "Add SQL User"
})
})
]
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "flex-col items-start w-full",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("span", {
children: "You can customize your SQL users and permissions here. You can add up to 10 hosts/IP addresses (including your primary host)"
}),
/*#__PURE__*/ jsx_runtime_.jsx("hr", {}),
/*#__PURE__*/ jsx_runtime_.jsx("div", {
className: "grid w-full grid-cols-1 xl:grid-cols-2 gap-6",
children: mariadbUsers.map((mdbUser, index)=>{
return /*#__PURE__*/ jsx_runtime_.jsx(MariaDBUserCard, {
mariadbUser: mdbUser
}, index + 1);
})
})
]
})
]
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
;// CONCATENATED MODULE: ./components/admin/connect/ConnectContent.jsx
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Main Component { Functional }
* ==============================================================================
* @param {Object} props - Server props
*/ function ConnectContent(props) {
/**
* Get Contexts
*
* @abstract { React.useContext }
*/ const { user , query , mariadbUserCred } = external_react_default().useContext(ConnectContext);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Javascript Variables
*
* @abstract Non hook variables and functions
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* React Hooks
*
* @abstract { useState, useEffect, useRef, etc ... }
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Function Return
*
* @abstract Main Function Return
*/ return /*#__PURE__*/ (0,jsx_runtime_.jsxs)((external_react_default()).Fragment, {
children: [
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "flex-col items-start gap-0 w-full",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("div", {
className: "",
children: /*#__PURE__*/ jsx_runtime_.jsx("h1", {
className: "text-3xl m-0",
children: "Connect"
})
}),
/*#__PURE__*/ jsx_runtime_.jsx(Breadcrumbs/* default */.Z, {
user: user
})
]
}),
/*#__PURE__*/ jsx_runtime_.jsx(ConnectionInfo, {}),
/*#__PURE__*/ jsx_runtime_.jsx(MariaDBUsers, {})
]
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
;// CONCATENATED MODULE: ./components/admin/connect/MariDBUserFormGrantsSection.jsx
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* @typedef {Object} APIDatabase
* @property {string | number} id
* @property {string} db_full_name
* @property {string} db_name
* @property {string} db_slug
*/ /**
* @typedef {Object} APITable
* @property {string | number} id
* @property {string} table_name
* @property {string} table_slug
*/ /**
* ==============================================================================
* Main Component { Functional }
* ==============================================================================
* @param {Object} props
* @param {import("@/shell/mariadb-users/handleGrants").GrantType[]} props.grants
* @param {React.Dispatch<React.SetStateAction<import("@/shell/mariadb-users/handleGrants").GrantType[]>> } props.setGrants
* @param {boolean} [props.edit]
*/ function MariDBUserFormGrantsSection({ grants , setGrants , edit , }) {
/**
* Get Contexts
*
* @abstract { React.useContext }
*/ const { user , targetMariadbUser } = external_react_default().useContext(ConnectContext);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Javascript Variables
*
* @abstract Non hook variables and functions
*/ /** @type {import("@/shell/mariadb-users/handleGrants").GrantType[]} */ const grantsArray = [];
/** @type {string[]} */ const permissionsArray = [
"ALL PRIVILEGES",
"ALTER",
"ALTER ROUTINE",
"CREATE",
"CREATE ROUTINE",
"CREATE TEMPORARY TABLES",
"CREATE VIEW",
"DELETE",
"DROP",
"EVENT",
"EXECUTE",
"FILE",
"INDEX",
"INSERT",
"LOCK TABLES",
"PROCESS",
"REFERENCES",
"RELOAD",
"REPLICATION CLIENT",
"REPLICATION SLAVE",
"SELECT",
"SHOW VIEW",
"SUPER",
"TRIGGER",
"UPDATE",
"USAGE",
];
const isPrimary = Boolean(String(targetMariadbUser?.primary).match(/1/)) && edit;
const isAllDatabasesGranted = Boolean(grants.find((grant)=>grant.database == "*"));
const isAllTablesGranted = Boolean(grants.find((grant)=>grant.table == "*"));
const isPrivilegesGranted = Boolean(grants.find((grant)=>grant.privileges.includes("ALL PRIVILEGES")));
const isAllGranted = isAllDatabasesGranted && isAllTablesGranted && isPrivilegesGranted;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* React Hooks
*
* @abstract { useState, useEffect, useRef, etc ... }
*/ /** @type {[ state: APIDatabase[], dispatch: React.Dispatch<React.SetStateAction<APIDatabase[]>> ]} */ // @ts-ignore
const [databases, setDatabases] = external_react_default().useState([]);
/** @type {[ state: APIDatabase, dispatch: React.Dispatch<React.SetStateAction<APIDatabase>> ]} */ // @ts-ignore
const [targetDatabase, setTargetDatabase] = external_react_default().useState({});
/** @type {[ state: APITable[], dispatch: React.Dispatch<React.SetStateAction<APITable[]>> ]} */ // @ts-ignore
const [tables, setTables] = external_react_default().useState([]);
/** @type {[ state: APITable, dispatch: React.Dispatch<React.SetStateAction<APITable>> ]} */ // @ts-ignore
const [targetTable, setTargetTable] = external_react_default().useState({});
const [permissions, setPermissions] = external_react_default().useState([
"ALL PRIVILEGES"
]);
/** @type {[ state: string, dispatch: React.Dispatch<React.SetStateAction<string>> ]} */ // @ts-ignore
const [targetPermission, setTargetPermission] = external_react_default().useState("ALL PRIVILEGES");
const [newGrant, setNewGrant] = external_react_default().useState(false);
external_react_default().useEffect(()=>{
(0,fetchApi/* default */.Z)("/api/getUserDatabases").then((res)=>{
if (res.databases) {
setDatabases(res.databases);
}
});
}, []);
external_react_default().useEffect(()=>{
if (!targetDatabase?.id) return;
(0,fetchApi/* default */.Z)(`/api/getUserDatabaseTables?dbId=${targetDatabase.id}`).then((res)=>{
if (res.tables) {
setTables(res.tables);
}
});
}, [
targetDatabase
]);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Function Return
*
* @abstract Main Function Return
*/ return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
id: "grant-select-block",
className: "flex flex-col items-stretch w-full p-6 border border-slate-200 border-solid rounded",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("h4", {
className: "m-0 text-lg",
children: "Grants"
}),
/*#__PURE__*/ jsx_runtime_.jsx("span", {
children: "This section determines fine grained access of this user to databases and tables"
}),
/*#__PURE__*/ jsx_runtime_.jsx("hr", {}),
/*#__PURE__*/ jsx_runtime_.jsx("div", {
className: "flex-wrap",
children: grants?.[0] ? grants.map((grant, index)=>{
return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "text-sm pr-10 bg-secondary text-white px-3 py-2 rounded flex-wrap relative",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("span", {
children: grant.privileges
}),
/*#__PURE__*/ jsx_runtime_.jsx("span", {
children: "="
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("span", {
children: [
" ",
grant.database.replace(/datasquirel_user_\d+_/, "")
]
}),
/*#__PURE__*/ jsx_runtime_.jsx("span", {
children: "."
}),
/*#__PURE__*/ jsx_runtime_.jsx("span", {
children: grant.table
}),
!isPrimary && /*#__PURE__*/ jsx_runtime_.jsx("div", {
className: "button white absolute top-1.5 right-1.5 p-2 w-6 h-6",
onClick: (e)=>{
const newGrants = [
...grants
];
newGrants.splice(index, 1);
setGrants(newGrants);
},
children: "x"
})
]
});
}) : /*#__PURE__*/ jsx_runtime_.jsx("span", {
className: "text-slate-400 px-4 py-2 bg-slate-100 w-full flex items-center justify-center",
children: "No Grants"
})
}),
/*#__PURE__*/ jsx_runtime_.jsx("hr", {}),
isAllGranted ? /*#__PURE__*/ jsx_runtime_.jsx("span", {
className: "text-sm text-slate-500",
children: 'All Privileges have been granted! Delete "ALL PRIVILEGES on *.*" to add fine-grained privileges'
}) : newGrant ? /*#__PURE__*/ jsx_runtime_.jsx(jsx_runtime_.Fragment, {
children: isPrimary ? /*#__PURE__*/ jsx_runtime_.jsx("span", {
className: "text-slate-400",
children: "Primary users have full control over all databases."
}) : /*#__PURE__*/ (0,jsx_runtime_.jsxs)(jsx_runtime_.Fragment, {
children: [
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "flex-col items-start w-full gap-1",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("label", {
htmlFor: "grants-database",
children: "Database"
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("select", {
name: "grants-database",
id: "grants-database",
className: "text-sm",
onChange: (e)=>{
const selectedDatabase = e.target.value;
if (selectedDatabase == "NULL") {
return;
}
const selectedDatabaseObject = databases.find((db)=>db.db_full_name == selectedDatabase);
if (selectedDatabaseObject) {
setTargetDatabase(selectedDatabaseObject);
}
},
children: [
/*#__PURE__*/ jsx_runtime_.jsx("option", {
value: "*",
children: "--ALL-DATABASES--"
}),
databases.map((database, index)=>{
return /*#__PURE__*/ jsx_runtime_.jsx("option", {
value: database.db_full_name,
children: database.db_name
}, index + 1);
})
]
})
]
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "flex-col items-start w-full gap-1",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("label", {
htmlFor: "grants-table",
children: "Table"
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("select", {
name: "grants-table",
id: "grants-table",
className: "text-sm",
onChange: (e)=>{
const selectedTable = e.target.value;
if (selectedTable == "NULL") {
return;
}
const selectedTableObject = tables.find((table)=>table.table_slug == selectedTable);
if (selectedTableObject) {
setTargetTable(selectedTableObject);
}
},
children: [
/*#__PURE__*/ jsx_runtime_.jsx("option", {
value: "*",
children: "--ALL-TABLES--"
}),
tables?.[0] && tables.map((table, index)=>{
return /*#__PURE__*/ jsx_runtime_.jsx("option", {
value: table.table_slug,
children: table.table_name
}, index + 1);
})
]
})
]
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "flex-col items-start w-full gap-1",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("label", {
htmlFor: "grants-databases",
children: "Permissions"
}),
/*#__PURE__*/ jsx_runtime_.jsx("div", {
className: "flex-wrap gap-y-2 mb-1",
children: permissions?.[0] ? permissions.map((permission, index)=>{
return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("span", {
className: "text-xs px-2 py-1 border border-solid border-slate-200 rounded",
children: [
permission,
/*#__PURE__*/ jsx_runtime_.jsx("span", {
className: "cursor-pointer p-2 hover:opacity-50",
onClick: (e)=>{
const newPermissions = [
...permissions,
];
newPermissions.splice(index, 1);
setPermissions(newPermissions);
},
children: "x"
})
]
});
}) : /*#__PURE__*/ jsx_runtime_.jsx("span", {
className: "text-xs px-3 py-1 bg-slate-100 text-slate-400",
children: "No Permissions Selected"
})
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "w-full items-stretch",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("select", {
name: "grants-databases",
id: "grants-databases",
className: "text-sm",
onChange: (e)=>{
const selectedPermission = e.target.value;
setTargetPermission(selectedPermission);
},
children: permissionsArray.map((permission, index)=>{
return /*#__PURE__*/ jsx_runtime_.jsx("option", {
value: permission,
children: permission
}, index);
})
}),
/*#__PURE__*/ jsx_runtime_.jsx("div", {
className: "button outlined gray text-2xl",
onClick: (e)=>{
if (permissions.includes(targetPermission)) return;
if (permissions.includes("ALL PRIVILEGES")) {
alert("ALL PRIVILEGES already covers for the rest. Remove ALL PRIVILEGES permission to add others");
return;
}
setPermissions([
...permissions,
targetPermission,
]);
},
children: "+"
})
]
})
]
}),
!isPrimary && /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "button outlined secondary",
onClick: (e)=>{
if (!permissions?.[0]) {
alert("Please select atleast 1 permission. *REMEMBER to click the + button to add the permission to the list");
return;
}
/**
* @type {import("@/shell/mariadb-users/handleGrants").GrantType}
*/ const newGrant = {
database: targetDatabase.db_full_name || "*",
privileges: permissions,
table: targetTable.table_slug || "*"
};
const newGrants = [
...grants,
newGrant
];
setGrants(newGrants);
setNewGrant(false);
},
children: [
/*#__PURE__*/ jsx_runtime_.jsx("span", {
className: "text-2xl h-6 flex items-center justify-center",
children: "+"
}),
"\xa0Add Grant"
]
}),
/*#__PURE__*/ jsx_runtime_.jsx("div", {
className: "button outlined gray",
onClick: ()=>{
setNewGrant(false);
},
children: "Cancel"
})
]
})
}) : isPrimary ? /*#__PURE__*/ jsx_runtime_.jsx("span", {
className: "text-slate-400",
children: "Primary users have full control over all databases."
}) : /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "button outlined gray",
onClick: (e)=>{
setNewGrant(true);
},
children: [
/*#__PURE__*/ jsx_runtime_.jsx("span", {
className: "text-2xl h-6 flex items-center justify-center",
children: "+"
}),
"\xa0Add Grant"
]
})
]
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
;// CONCATENATED MODULE: ./components/admin/connect/MariDBUserForm.jsx
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Main Component { Functional }
* ==============================================================================
* @param {Object} props
* @param {import("@/package-shared/types").MYSQL_mariadb_users_table_def} [props.mariaDBUser]
* @param {boolean} [props.edit]
* @param {string} [props.username]
*/ function MariDBUserForm({ mariaDBUser , edit , username }) {
/**
* Get Contexts
*
* @abstract { React.useContext }
*/ const { user } = external_react_default().useContext(ConnectContext);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Javascript Variables
*
* @abstract Non hook variables and functions
*/ const formFields = mariaDBUser ? Object.keys(mariaDBUser) : [
"username",
"host",
"password"
];
const KEYS_REGEXP = /username|host|password/;
const UNEDITABLE_REGEXP = edit ? /username/ : /username/;
const REQUIRED_REGEXP = /host/;
const existingGrants = (()=>{
try {
if (edit && mariaDBUser?.grants) return JSON.parse(mariaDBUser.grants);
return null;
} catch (error) {
return null;
}
})();
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* React Hooks
*
* @abstract { useState, useEffect, useRef, etc ... }
*/ /** @type {[ state: import("@/shell/mariadb-users/handleGrants").GrantType[], dispatch: React.Dispatch<React.SetStateAction<import("@/shell/mariadb-users/handleGrants").GrantType[]>> ]} */ // @ts-ignore
const [grants, setGrants] = external_react_default().useState(existingGrants ? existingGrants : [
{
database: "*",
table: "*",
privileges: [
"ALL PRIVILEGES"
]
},
]);
const [loading, setLoading] = external_react_default().useState(false);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Function Return
*
* @abstract Main Function Return
*/ return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("form", {
onSubmit: (e)=>{
e.preventDefault();
console.log("form clicked");
/**
* @type {HTMLFormElement}
*/ // @ts-ignore
const formEl = e.target;
const formFields = Array.from(formEl);
/**
* @type any
*/ const formData = {};
formFields.forEach((el)=>{
if (el.nodeName != "INPUT") return;
/**
* @type {HTMLInputElement}
*/ // @ts-ignore
const inputEl = el;
formData[inputEl.name] = inputEl.value;
});
if (edit) {
delete formData.username;
}
if (!grants?.[0]) {
alert("Please add at least one grant");
return;
}
setLoading(true);
const fetchUrl = edit ? "/api/sql-users/update" : "/api/sql-users/create";
(0,fetchApi/* default */.Z)(fetchUrl, {
method: "POST",
body: {
data: formData,
edit: Boolean(edit),
prev: mariaDBUser,
grants
}
}, true).then((res)=>{
if (res.success) {
window.location.reload();
} else if (res.msg) {
window.alert(res.msg);
setLoading(false);
}
});
},
className: "w-full gap-4 flex flex-col",
children: [
loading && /*#__PURE__*/ jsx_runtime_.jsx(LoadingBlock/* default */.Z, {
width: "25px"
}),
formFields.map((key, index)=>{
/** @type {string | null} */ const existingValue = mariaDBUser ? mariaDBUser[key] : key == "username" ? `dsql_user_${user.id}` : null;
const isReadOnly = UNEDITABLE_REGEXP.test(key);
const isRequired = REQUIRED_REGEXP.test(key);
if (!key.match(KEYS_REGEXP)) return null;
return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "flex-col items-start w-full gap-1",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("label", {
htmlFor: key,
children: key
}),
/*#__PURE__*/ jsx_runtime_.jsx("input", {
type: key.match("password") ? "password" : "text",
name: key,
id: key,
defaultValue: existingValue || undefined,
readOnly: isReadOnly,
className: "" + (isReadOnly ? "bg-slate-100 opacity-50 pointer-events-none" : ""),
placeholder: key,
required: isRequired
})
]
}, index + 1);
}),
/*#__PURE__*/ jsx_runtime_.jsx(MariDBUserFormGrantsSection, {
grants: grants,
setGrants: setGrants,
edit: edit
}),
/*#__PURE__*/ jsx_runtime_.jsx("button", {
type: "submit",
children: edit ? "Update User" : "Create SQL User"
})
]
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
;// CONCATENATED MODULE: ./components/admin/connect/EditMariadbUserPopup.jsx
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Main Component { Functional }
* ==============================================================================
* @param {Object} props - Server props
*/ function EditMariadbUserPopup(props) {
/**
* Get Contexts
*
* @abstract { React.useContext }
*/ const { targetMariadbUser } = external_react_default().useContext(ConnectContext);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Javascript Variables
*
* @abstract Non hook variables and functions
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* React Hooks
*
* @abstract { useState, useEffect, useRef, etc ... }
*/ const [ready, setReady] = external_react_default().useState(false);
external_react_default().useEffect(()=>{
setReady(false);
setTimeout(()=>{
setReady(true);
}, 200);
}, [
targetMariadbUser
]);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Function Return
*
* @abstract Main Function Return
*/ return /*#__PURE__*/ jsx_runtime_.jsx(GeneralPopup/* default */.ZP, {
title: "edit-mariadb-user-popup",
children: ready && targetMariadbUser ? /*#__PURE__*/ (0,jsx_runtime_.jsxs)(jsx_runtime_.Fragment, {
children: [
/*#__PURE__*/ jsx_runtime_.jsx("h3", {
children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
className: "flex",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("span", {
children: "Edit"
}),
/*#__PURE__*/ (0,jsx_runtime_.jsxs)("span", {
className: "info inline w-auto text-xl green",
children: [
targetMariadbUser.username,
"@",
targetMariadbUser.host
]
})
]
})
}),
/*#__PURE__*/ jsx_runtime_.jsx("hr", {}),
/*#__PURE__*/ jsx_runtime_.jsx(MariDBUserForm, {
mariaDBUser: targetMariadbUser,
edit: true
})
]
}) : /*#__PURE__*/ jsx_runtime_.jsx("div", {
className: "p-20",
children: /*#__PURE__*/ jsx_runtime_.jsx(LoadingBlock/* default */.Z, {
width: "25px"
})
})
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
;// CONCATENATED MODULE: ./components/admin/connect/NewMariadbUserPopup.jsx
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Main Component { Functional }
* ==============================================================================
* @param {Object} props - Server props
*/ function NewMariadbUserPopup(props) {
/**
* Get Contexts
*
* @abstract { React.useContext }
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Javascript Variables
*
* @abstract Non hook variables and functions
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* React Hooks
*
* @abstract { useState, useEffect, useRef, etc ... }
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Function Return
*
* @abstract Main Function Return
*/ return /*#__PURE__*/ (0,jsx_runtime_.jsxs)(GeneralPopup/* default */.ZP, {
title: "new-mariadb-user-popup",
children: [
/*#__PURE__*/ jsx_runtime_.jsx("h3", {
children: "New MariaDB User"
}),
/*#__PURE__*/ jsx_runtime_.jsx("hr", {}),
/*#__PURE__*/ jsx_runtime_.jsx(MariDBUserForm, {})
]
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
// EXTERNAL MODULE: ./package-shared/functions/backend/decrypt.js
var decrypt = __webpack_require__(5304);
var decrypt_default = /*#__PURE__*/__webpack_require__.n(decrypt);
;// CONCATENATED MODULE: ./pages/admin/[user_id]/connect/index.jsx
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/** ****************************************************************************** */ /** @type {import("@/package-shared/types").ConnectContextType} */ // @ts-ignore
const init = {};
const ConnectContext = /*#__PURE__*/ external_react_default().createContext(init);
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Main Component { Functional }
* ==============================================================================
* @param {Object} props - Server props
* @param {import("@/package-shared/types").UserType} props.user
* @param {any} props.query
* @param {import("@/package-shared/types").MariaDBUserCredType} props.mariadbUserCred
* @param {import("@/package-shared/types").MYSQL_mariadb_users_table_def[]} props.mariadbUsers
*/ function DatabaseSchema({ user , query , mariadbUserCred , mariadbUsers , }) {
/**
* Get Contexts
*
* @abstract { React.useContext }
*/ ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Javascript Variables
*
* @abstract Non hook variables and functions
*/ const pageTitle = "SQL Connect | Datasquirel";
const pageDescription = "Connect to your database remotely";
let head = /*#__PURE__*/ (0,jsx_runtime_.jsxs)(jsx_runtime_.Fragment, {
children: [
/*#__PURE__*/ jsx_runtime_.jsx("title", {
children: pageTitle
}),
/*#__PURE__*/ jsx_runtime_.jsx("meta", {
name: "description",
content: pageDescription
})
]
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* React Hooks
*
* @abstract { useState, useEffect, useRef, etc ... }
*/ /** @type {[ state: import("@/package-shared/types").MYSQL_mariadb_users_table_def | null, dispatch: React.Dispatch<React.SetStateAction<import("@/package-shared/types").MYSQL_mariadb_users_table_def | null>> ]} */ // @ts-ignore
const [targetMariadbUser, setTargetMariadbUser] = external_react_default().useState(null);
/** @type {[ state: number, dispatch: React.Dispatch<React.SetStateAction<number>> ]} */ // @ts-ignore
const [refresh, setRefresh] = external_react_default().useState(null);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Function Return
*
* @abstract Main Function Return
*/ return /*#__PURE__*/ jsx_runtime_.jsx(AdminLayout/* default */.Z, {
head: head,
user: user,
aceEditor: true,
children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)(ConnectContext.Provider, {
value: {
user,
query,
mariadbUserCred,
mariadbUsers,
targetMariadbUser,
setTargetMariadbUser,
refresh,
setRefresh
},
children: [
/*#__PURE__*/ jsx_runtime_.jsx(ConnectContent, {}),
/*#__PURE__*/ jsx_runtime_.jsx(EditMariadbUserPopup, {}),
/*#__PURE__*/ jsx_runtime_.jsx(NewMariadbUserPopup, {})
]
})
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Server Side Props or Static Props
* ==============================================================================
* @type {import("next").GetServerSideProps}
*/ async function getServerSideProps({ req , res , query }) {
/**
* User Auth
*
* @description User Auth
*/ const user = await userAuth_default()(req, res);
if (!user?.logged_in_status) {
return {
redirect: {
destination: "/login",
permanent: false
}
};
}
/**
* Page/Site Data Data Fetching
*
* @description Fetch data on the server before returning
*/ const mariadbUserCredArray = await DB_HANDLER_default()(`SELECT mariadb_user, mariadb_host, mariadb_pass FROM users WHERE id = ?`, [
user.id
]);
const mariadbUserCred = mariadbUserCredArray?.[0] || {};
if (mariadbUserCred?.mariadb_pass) {
mariadbUserCred.mariadb_pass = decrypt_default()(mariadbUserCred.mariadb_pass);
}
////////////////////////////////////////
const mariadbUsers = await DB_HANDLER_default()(`SELECT * FROM mariadb_users WHERE user_id = ?`, [
user.id
]);
if (mariadbUsers?.[0]) {
for(let i = 0; i < mariadbUsers.length; i++){
const mariaDBUser = mariadbUsers[i];
mariaDBUser.password = decrypt_default()(mariaDBUser.password);
}
}
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Server props return
*
* @description Return data fetched on the server side
*/ return {
props: {
user: user,
query,
mariadbUserCred,
mariadbUsers
}
};
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
/***/ }),
/***/ 4003:
/***/ ((module) => {
module.exports = require("@mui/icons-material/AdminPanelSettingsTwoTone");
/***/ }),
/***/ 69:
/***/ ((module) => {
module.exports = require("@mui/icons-material/CloudOffTwoTone");
/***/ }),
/***/ 4008:
/***/ ((module) => {
module.exports = require("@mui/icons-material/CloudQueueRounded");
/***/ }),
/***/ 7306:
/***/ ((module) => {
module.exports = require("@mui/icons-material/CollectionsTwoTone");
/***/ }),
/***/ 386:
/***/ ((module) => {
module.exports = require("@mui/icons-material/CottageTwoTone");
/***/ }),
/***/ 8757:
/***/ ((module) => {
module.exports = require("@mui/icons-material/DeleteOutlineOutlined");
/***/ }),
/***/ 8979:
/***/ ((module) => {
module.exports = require("@mui/icons-material/DynamicFormTwoTone");
/***/ }),
/***/ 300:
/***/ ((module) => {
module.exports = require("@mui/icons-material/LanguageOutlined");
/***/ }),
/***/ 2814:
/***/ ((module) => {
module.exports = require("@mui/icons-material/LockTwoTone");
/***/ }),
/***/ 5557:
/***/ ((module) => {
module.exports = require("@mui/icons-material/MenuBookTwoTone");
/***/ }),
/***/ 9806:
/***/ ((module) => {
module.exports = require("@mui/icons-material/PeopleOutlineTwoTone");
/***/ }),
/***/ 36:
/***/ ((module) => {
module.exports = require("@mui/icons-material/RefreshRounded");
/***/ }),
/***/ 1799:
/***/ ((module) => {
module.exports = require("@mui/icons-material/SchemaTwoTone");
/***/ }),
/***/ 2423:
/***/ ((module) => {
module.exports = require("lucide-react");
/***/ }),
/***/ 968:
/***/ ((module) => {
module.exports = require("next/head");
/***/ }),
/***/ 6689:
/***/ ((module) => {
module.exports = require("react");
/***/ }),
/***/ 997:
/***/ ((module) => {
module.exports = require("react/jsx-runtime");
/***/ }),
/***/ 2261:
/***/ ((module) => {
module.exports = require("serverless-mysql");
/***/ }),
/***/ 4300:
/***/ ((module) => {
module.exports = require("buffer");
/***/ }),
/***/ 6113:
/***/ ((module) => {
module.exports = require("crypto");
/***/ }),
/***/ 7147:
/***/ ((module) => {
module.exports = require("fs");
/***/ }),
/***/ 3685:
/***/ ((module) => {
module.exports = require("http");
/***/ })
};
;
// load runtime
var __webpack_require__ = require("../../../webpack-runtime.js");
__webpack_require__.C(exports);
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
2024-11-05 14:18:40 +00:00
var __webpack_exports__ = __webpack_require__.X(0, [4017,8313,5264,6729,5449,913,4480,370,424,4858,5472], () => (__webpack_exec__(5782)));
2024-11-05 11:12:42 +00:00
module.exports = __webpack_exports__;
})();