"use strict";(()=>{var e={};e.id=837,e.ids=[837],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}}})},8635:(e,t,r)=>{r.r(t),r.d(t,{config:()=>p,default:()=>h,routeModule:()=>f});var s={};r.r(s),r.d(s,{default:()=>m});var n=r(1802),i=r(7153),o=r(6249),u=r(2632),a=r(8804),c=r.n(a),d=r(2253),l=r(246);async function m(e,t){try{if("POST"!==e.method)return t.json({success:!1,msg:"Wrong Method"});let{singleRes:r}=await (0,u.Z)({req:e});if(!r?.id||!r.super_admin)return t.json({success:!1,msg:"Unauthorized"});let{new_user:s,user_id:n}=e.body;if(!s)throw Error("No User Form Sent.");let{first_name:i,last_name:o,email:a,image:m,username:h}=s;if(!i?.match(/./))return t.json({success:!1,msg:"First name is required"});return await c().update({table:"users",targetId:(0,d._n)(n),data:{first_name:i,last_name:o,email:a,image:m,username:h}}),await (0,l.Z)({user_id:(0,d._n)(n)}),t.json({success:!0})}catch(e){return t.json({success:!1,msg:e.message})}}let h=(0,o.l)(s,"default"),p=(0,o.l)(s,"config"),f=new n.PagesAPIRouteModule({definition:{kind:i.x.PAGES_API,page:"/api/admin/edit-user",pathname:"/api/admin/edit-user",bundlePath:"",filename:""},userland:s})},2253:(e,t,r)=>{r.d(t,{dF:()=>o(),_n:()=>d,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 o=r.n(i);let u=require("@moduletrace/datasquirel/dist/package-shared/utils/slugify");var a=r.n(u);let c=require("@moduletrace/datasquirel/dist/package-shared/utils/numberfy"),d=r.n(c)();n().utils.serializeQuery,n().utils.deserializeQuery},246:(e,t,r)=>{r.d(t,{Z:()=>c});var s=r(2253),n=r(2481),i=r(8804),o=r.n(i),u=r(1282),a=r(2048);async function c({user_id:e}){let t=(await o().select({table:"users",targetId:(0,s._n)(e)})).singleRes;if(!t?.id||!t.username||t.is_super_admin)return;let{username:r}=t,{force_command_file:i,ssh_dir:c,ssh_key_file:d,sshd_config_file:l,user_dir:m}=(0,n.Z)({user:t}),h=`/bin/bash << 'TURBOCIHEREDOC'
`;(0,a.existsSync)(m)||(h+=`useradd --create-home --shell /bin/bash --comment "TurboCI Deployment user ${r}" ${r}
passwd --lock "${r}"
mkdir -p "${c}"
ssh-keygen -t ed25519 -f "${d}" -N "" -C "${r}@$(hostname)"
cp "${d}.pub" "${c}/authorized_keys"
chown -R "${r}:${r}" "${c}"
chmod 700 "${c}"
chmod 600 "${d}"
chmod 644 "${d}.pub"
chmod 600 "${c}/authorized_keys"
`),h+=`cat << 'EOF' > ${i}
#!/bin/bash
case "$SSH_ORIGINAL_COMMAND" in
    "shell")
        exec /bin/bash
        ;;
    *)
        echo "Access denied."
        exit 1
        ;;
esac
EOF

chmod +x ${i}

cat << 'EOF' > ${l}
Match User ${r}
    PasswordAuthentication no
    PubkeyAuthentication yes
    AuthenticationMethods publickey
    AllowTcpForwarding yes
    X11Forwarding no
    ForceCommand ${i}
    PermitOpen localhost:80
    PermitTTY no
EOF
TURBOCIHEREDOC
`,(0,u.execSync)(h)}},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],o=[`${encodeURIComponent(s)}=${encodeURIComponent(i)}`];n.expires&&o.push(`Expires=${n.expires.toDate().toUTCString()}`),void 0!==n.maxAge&&o.push(`Max-Age=${n.maxAge}`),n.path&&o.push(`Path=${n.path}`),n.domain&&o.push(`Domain=${n.domain}`),n.secure&&o.push("Secure"),n.httpOnly&&o.push("HttpOnly"),r.push(o)}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:()=>o});var s=r(2048);let n=require("path");var i=r.n(n);function o(){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"),o=i().join(t,".ssh"),u=i().join(o,"turboci");return{APP_DIR:e,TURBOCI_CONFIG_DIR:r,TURBOCI_CONFIG_JSON_FILE:s,TURBOCI_DIR:t,TURBOCI_SSH_DIR:o,TURBOCI_SSH_KEY_FILE:u,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),o=r(2253),u=r(9786);async function a({req:e,bun_req:t}){try{let{auth_key_cookie_name:r,csrf_cookie_name:n}=(0,u.Z)(),a=e?.headers.cookie||t?.headers.get("cookie");if(!a)return{success:!1,msg:"Couldn't grab cookie string"};let c=(0,s.ej)(a,r);if(!c)return{success:!1,msg:`No ${r} found in request object.`};let d=i()({encryptedString:c}),l=o.dF.parse(d);if(!l?.id)return{success:!1,msg:"Invalid Auth Key"};let m=(0,s.ej)(a,n);if(!m)return{success:!1,msg:`No ${n} found in request object.`};if(m!==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=8635);module.exports=r})();