"use strict";(()=>{var e={};e.id=204,e.ids=[204],e.modules={8804:e=>{e.exports=require("@moduletrace/nsqlite")},1635:e=>{e.exports=require("dayjs")},145:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},6249:(e,t)=>{Object.defineProperty(t,"l",{enumerable:!0,get:function(){return function e(t,r){return r in t?t[r]:"then"in t&&"function"==typeof t.then?t.then(t=>e(t,r)):"function"==typeof t&&"default"===r?t:void 0}}})},7541:(e,t,r)=>{r.r(t),r.d(t,{config:()=>g,default:()=>h,routeModule:()=>_});var s={};r.r(s),r.d(s,{default:()=>p});var n=r(1802),i=r(7153),u=r(6249),o=r(2632),a=r(2253),d=r(2481),c=r(8804),l=r.n(c),f=r(1282);async function m({user_id:e}){let t=(await l().select({table:"users",targetId:(0,a._n)(e)})).singleRes;if(!t?.id||!t.username||t.is_super_admin)return;let{username:r}=t;console.log("username",r);let{force_command_file:s,sshd_config_file:n}=(0,d.Z)({user:t}),i=`/bin/bash << 'TURBOCIHEREDOC'
`;i+=`deluser --remove-all-files ${r} || echo "User Deleted!"
rm -f ${s}
rm -f ${n}
TURBOCIHEREDOC
`,(0,f.execSync)(i),l().delete({table:"users",targetId:t.id})}async function p(e,t){try{if("POST"!==e.method)return t.json({success:!1,msg:"Wrong Method"});let{singleRes:r}=await (0,o.Z)({req:e});if(!r?.id||!r.super_admin)return t.json({success:!1,msg:"Unauthorized"});let{user_id:s}=e.body;if((0,a._n)(s)==r.id)throw Error("Can't delete root user!");return await m({user_id:(0,a._n)(s)}),t.json({success:!0})}catch(e){return t.json({success:!1,msg:e.message})}}let h=(0,u.l)(s,"default"),g=(0,u.l)(s,"config"),_=new n.PagesAPIRouteModule({definition:{kind:i.x.PAGES_API,page:"/api/admin/delete-user",pathname:"/api/admin/delete-user",bundlePath:"",filename:""},userland:s})},2253:(e,t,r)=>{r.d(t,{dF:()=>u(),_n:()=>c,lV:()=>a()});let s=require("@moduletrace/datasquirel/dist/client");var n=r.n(s);let i=require("@moduletrace/datasquirel/dist/package-shared/utils/ejson");var u=r.n(i);let o=require("@moduletrace/datasquirel/dist/package-shared/utils/slugify");var a=r.n(o);let d=require("@moduletrace/datasquirel/dist/package-shared/utils/numberfy"),c=r.n(d)();n().utils.serializeQuery,n().utils.deserializeQuery},6941:(e,t,r)=>{function s(e,t){let r=[];for(let e=0;e<t.length;e++){let{name:s,options:n,value:i}=t[e],u=[`${encodeURIComponent(s)}=${encodeURIComponent(i)}`];n.expires&&u.push(`Expires=${n.expires.toDate().toUTCString()}`),void 0!==n.maxAge&&u.push(`Max-Age=${n.maxAge}`),n.path&&u.push(`Path=${n.path}`),n.domain&&u.push(`Domain=${n.domain}`),n.secure&&u.push("Secure"),n.httpOnly&&u.push("HttpOnly"),r.push(u)}let s=r.map(e=>e.join("; "));e.setHeader("Set-Cookie",s)}function n(e,t){return e.split(";").reduce((e,t)=>{let[r,s]=t.trim().split("=").map(decodeURIComponent);return e[r]=s,e},{})[t]||null}r.d(t,{d8:()=>s,ej:()=>n}),r(1635)},9786:(e,t,r)=>{r.d(t,{Z:()=>u});var s=r(2048);let n=require("path");var i=r.n(n);function u(){let{TURBOCI_DEPLOYMENT_ID_FILE:e}=function(){let e=i().resolve(__dirname,"../../"),t="/root/.turboci",r=i().join(t,".config"),s=i().join(r,"turboci.json"),n=i().join(t,"deployment_id"),u=i().join(t,".ssh"),o=i().join(u,"turboci");return{APP_DIR:e,TURBOCI_CONFIG_DIR:r,TURBOCI_CONFIG_JSON_FILE:s,TURBOCI_DIR:t,TURBOCI_SSH_DIR:u,TURBOCI_SSH_KEY_FILE:o,TURBOCI_DEPLOYMENT_ID_FILE:n}}();if(!(0,s.existsSync)(e))throw Error(`\`${e}\` does not exist.`);let t=(0,s.readFileSync)(e,"utf-8").split("-").shift();if(!t)throw Error("Invalid deployment_id");return{auth_key_cookie_name:`turboci-admin-${t}-auth-key`,csrf_cookie_name:`turboci-admin-${t}-csrf`}}},2481:(e,t,r)=>{r.d(t,{Z:()=>s});function s({user:e}){let{username:t}=e,r=`/home/${t}`,s=`${r}/.ssh`,n=`${s}/${t}`;return{user_dir:r,ssh_dir:s,ssh_key_file:n,sshd_config_file:`/etc/ssh/sshd_config.d/${t}.conf`,force_command_file:`/usr/local/bin/turboci-deployment-user-${t}`}}},2632:(e,t,r)=>{r.d(t,{Z:()=>a});var s=r(6941);let n=require("@moduletrace/datasquirel/dist/package-shared/functions/dsql/decrypt");var i=r.n(n),u=r(2253),o=r(9786);async function a({req:e,bun_req:t}){try{let{auth_key_cookie_name:r,csrf_cookie_name:n}=(0,o.Z)(),a=e?.headers.cookie||t?.headers.get("cookie");if(!a)return{success:!1,msg:"Couldn't grab cookie string"};let d=(0,s.ej)(a,r);if(!d)return{success:!1,msg:`No ${r} found in request object.`};let c=i()({encryptedString:d}),l=u.dF.parse(c);if(!l?.id)return{success:!1,msg:"Invalid Auth Key"};let f=(0,s.ej)(a,n);if(!f)return{success:!1,msg:`No ${n} found in request object.`};if(f!==l.csrf_k)return{success:!1,msg:"CSRF mismatch"};return{success:!0,singleRes:l}}catch(e){return{success:!1}}}},7153:(e,t)=>{var r;Object.defineProperty(t,"x",{enumerable:!0,get:function(){return r}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE"}(r||(r={}))},1802:(e,t,r)=>{e.exports=r(145)}};var t=require("../../../webpack-api-runtime.js");t.C(e);var r=t(t.s=7541);module.exports=r})();