2024-11-05 11:12:42 +00:00
"use strict" ;
( ( ) => {
var exports = { } ;
exports . id = 3363 ;
exports . ids = [ 3363 ] ;
exports . modules = {
/***/ 3785 :
/***/ ( ( module ) => {
module . exports = require ( "generate-password" ) ;
/***/ } ) ,
/***/ 6517 :
/***/ ( ( module ) => {
module . exports = require ( "lodash" ) ;
/***/ } ) ,
/***/ 2261 :
/***/ ( ( module ) => {
module . exports = require ( "serverless-mysql" ) ;
/***/ } ) ,
/***/ 4300 :
/***/ ( ( module ) => {
module . exports = require ( "buffer" ) ;
/***/ } ) ,
/***/ 2081 :
/***/ ( ( module ) => {
module . exports = require ( "child_process" ) ;
/***/ } ) ,
/***/ 6113 :
/***/ ( ( module ) => {
module . exports = require ( "crypto" ) ;
/***/ } ) ,
/***/ 7147 :
/***/ ( ( module ) => {
module . exports = require ( "fs" ) ;
/***/ } ) ,
/***/ 3685 :
/***/ ( ( module ) => {
module . exports = require ( "http" ) ;
/***/ } ) ,
/***/ 1017 :
/***/ ( ( module ) => {
module . exports = require ( "path" ) ;
/***/ } ) ,
/***/ 8210 :
/***/ ( ( _ _unused _webpack _module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) => {
_ _webpack _require _ _ . r ( _ _webpack _exports _ _ ) ;
/* harmony export */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , {
/* harmony export */ "default" : ( ) => ( /* binding */ handler )
/* harmony export */ } ) ;
/* harmony import */ var _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _0 _ _ = _ _webpack _require _ _ ( 6825 ) ;
/* harmony import */ var _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _0 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _0 _ _ ) ;
/* harmony import */ var _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ = _ _webpack _require _ _ ( 2163 ) ;
/* harmony import */ var _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ ) ;
/* harmony import */ var lodash _ _WEBPACK _IMPORTED _MODULE _2 _ _ = _ _webpack _require _ _ ( 6517 ) ;
/* harmony import */ var lodash _ _WEBPACK _IMPORTED _MODULE _2 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( lodash _ _WEBPACK _IMPORTED _MODULE _2 _ _ ) ;
/* harmony import */ var path _ _WEBPACK _IMPORTED _MODULE _3 _ _ = _ _webpack _require _ _ ( 1017 ) ;
/* harmony import */ var path _ _WEBPACK _IMPORTED _MODULE _3 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( path _ _WEBPACK _IMPORTED _MODULE _3 _ _ ) ;
/* harmony import */ var child _process _ _WEBPACK _IMPORTED _MODULE _4 _ _ = _ _webpack _require _ _ ( 2081 ) ;
/* harmony import */ var child _process _ _WEBPACK _IMPORTED _MODULE _4 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( child _process _ _WEBPACK _IMPORTED _MODULE _4 _ _ ) ;
/* harmony import */ var _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _5 _ _ = _ _webpack _require _ _ ( 2224 ) ;
/* harmony import */ var _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _5 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _5 _ _ ) ;
/* harmony import */ var _package _shared _functions _backend _encrypt _ _WEBPACK _IMPORTED _MODULE _6 _ _ = _ _webpack _require _ _ ( 7547 ) ;
/* harmony import */ var _package _shared _functions _backend _encrypt _ _WEBPACK _IMPORTED _MODULE _6 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _package _shared _functions _backend _encrypt _ _WEBPACK _IMPORTED _MODULE _6 _ _ ) ;
// @ts-check
const fs = _ _webpack _require _ _ ( 7147 ) ;
const generator = _ _webpack _require _ _ ( 3785 ) ;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ / * *
* API handler
* === === === === === === === === === === === === === === === === === === === === === === === === === ===
* @ type { import ( "next" ) . NextApiHandler }
* / a s y n c f u n c t i o n h a n d l e r ( r e q , r e s ) {
/ * *
* Check method
*
* @ description Check request method and return if invalid
* / i f ( r e q . m e t h o d ! = = " P O S T " ) r e t u r n r e s . j s o n ( {
user : null ,
msg : "Registration Failed!"
} ) ;
/ * *
* User Auth
*
* @ description User Auth
* / c o n s t u s e r = a w a i t _ f u n c t i o n s _ b a c k e n d _ u s e r A u t h _ _ W E B P A C K _ I M P O R T E D _ M O D U L E _ 0 _ _ _ d e f a u l t ( ) ( r e q , r e s , t r u e ) ;
if ( ! user ) {
return res . json ( {
success : false ,
msg : "Unauthorized"
} ) ;
}
/ * *
* Validate Form
*
* @ description Check if request body is valid
* / c o n s t { d a t a , e d i t , g r a n t s } = r e q . b o d y ;
/ * *
* Validate Form
*
* @ description Check if request body is valid
* / t r y {
const defaultMariadbUserHost = process . env . DSQL _DB _HOST || "127.0.0.1" ;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
const username = ` dsql_user_ ${ user . id } ` ;
const { host , password } = data ;
if ( ! host . match ( /./ ) ) {
throw new Error ( "Invalid host" ) ;
}
if ( host . match ( /^%$/ ) ) {
throw new Error ( "Cannot set a catch-all host for this user." ) ;
}
const sanitizedNewHost = String ( host ) . replace ( /[^a-zA-Z0-9-\.\:\/\%]/g , "" ) ;
const finPassword = password ? . match ( /./ ) ? password : generator . generate ( {
length : 16 ,
numbers : true ,
symbols : true ,
uppercase : true ,
exclude : "*#.'`\""
} ) ;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
const existinSQLUser = await _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _5 _ _ _default ( ) ( ` SELECT * FROM mysql.user WHERE User = ? AND (Host = ? OR Host = ?) ` , [
username ,
sanitizedNewHost ,
defaultMariadbUserHost
] ) ;
const doesSQLUserExist = Boolean ( existinSQLUser ? . [ 0 ] ? . User ) ;
if ( doesSQLUserExist ) {
throw new Error ( "SQL User already exists. Remember if you have the '%' host on your primary user, it catches all other hosts." ) ;
}
const absoluteHost = Boolean ( sanitizedNewHost . match ( /^%$/ ) ) ;
if ( absoluteHost ) {
throw new Error ( "Can't create a catch-all host for this username. Catch-all host is only allowed on the primary user." ) ;
}
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
const existingUsersCount = await _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _5 _ _ _default ( ) ( ` SELECT COUNT(*) FROM mariadb_users WHERE user_id = ? ` , [
user . id
] ) ;
if ( existingUsersCount ? . [ 0 ] ? . [ "COUNT(*)" ] >= 10 ) {
throw new Error ( "User limit reached" ) ;
}
const encryptedPassword = _package _shared _functions _backend _encrypt _ _WEBPACK _IMPORTED _MODULE _6 _ _ _default ( ) ( finPassword ) ;
const newMariaDBUser = await _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _5 _ _ _default ( ) ( ` INSERT INTO mariadb_users (user_id, username, host, password, grants) VALUES (?, ?, ?, ?, ?) ` , [
user . id ,
username ,
sanitizedNewHost ,
encryptedPassword ,
JSON . stringify ( grants ) ,
] ) ;
if ( ! newMariaDBUser ? . insertId ) {
throw new Error ( "Error in adding SQL user" ) ;
}
2024-11-06 09:37:01 +00:00
const execPath = path _ _WEBPACK _IMPORTED _MODULE _3 _ _ _default ( ) . resolve ( process . cwd ( ) , "./shell/mariadb-users" ) ;
2024-11-05 11:12:42 +00:00
const execSQLUserScript = ( 0 , child _process _ _WEBPACK _IMPORTED _MODULE _4 _ _ . execSync ) ( ` node refreshUsersAndGrants.js --userId ${ user . id } --username ${ username } --host ${ sanitizedNewHost } ` , {
cwd : execPath
} ) ;
res . json ( {
success : true
} ) ;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} catch ( /** @type {any} */ error ) {
2024-11-06 09:37:01 +00:00
console . log ( "Create MariaDB user ERROR:" , error . message ) ;
2024-11-05 11:12:42 +00:00
_functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ _default ( ) ( {
component : "/api/acceptUserInvitation/catch-error" ,
message : error . message ,
user : user
} ) ;
res . json ( {
success : false ,
msg : "Error in adding SQL user =>" + error . message ,
err : error . message
} ) ;
}
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
/***/ } )
} ;
;
// load runtime
var _ _webpack _require _ _ = require ( "../../../webpack-api-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 , [ 2224 , 2163 , 6825 , 3017 , 7547 ] , ( ) => ( _ _webpack _exec _ _ ( 8210 ) ) ) ;
2024-11-05 11:12:42 +00:00
module . exports = _ _webpack _exports _ _ ;
} ) ( ) ;