MCPcopy
hub / github.com/Dokploy/dokploy / serverAudit

Function serverAudit

packages/server/src/setup/server-audit.ts:84–151  ·  view source on GitHub ↗
(serverId: string)

Source from the content-addressed store, hash-verified

82`;
83
84export const serverAudit = async (serverId: string) => {
85 const client = new Client();
86 const server = await findServerById(serverId);
87 if (!server.sshKeyId) {
88 throw new Error("No SSH Key found");
89 }
90
91 return new Promise<any>((resolve, reject) => {
92 client
93 .once("ready", () => {
94 const bashCommand = `
95 command_exists() {
96 command -v "$@" > /dev/null 2>&1
97 }
98
99 ufwStatus=$(${validateUfw()})
100 sshStatus=$(${validateSsh()})
101 fail2banStatus=$(${validateFail2ban()})
102
103 echo "{\\"ufw\\": $ufwStatus, \\"ssh\\": $sshStatus, \\"fail2ban\\": $fail2banStatus}"
104 `;
105
106 client.exec(bashCommand, (err, stream) => {
107 if (err) {
108 reject(err);
109 return;
110 }
111 let output = "";
112 stream
113 .on("close", () => {
114 client.end();
115 try {
116 const result = JSON.parse(output.trim());
117 resolve(result);
118 } catch (parseError) {
119 reject(
120 new Error(
121 `Failed to parse output: ${parseError instanceof Error ? parseError.message : parseError}`,
122 ),
123 );
124 }
125 })
126 .on("data", (data: string) => {
127 output += data;
128 })
129 .stderr.on("data", (_data) => {});
130 });
131 })
132 .on("error", (err) => {
133 client.end();
134 if (err.level === "client-authentication") {
135 reject(
136 new Error(
137 `Authentication failed: Invalid SSH private key. ❌ Error: ${err.message} ${err.level}`,
138 ),
139 );
140 } else {
141 reject(new Error(`SSH connection error: ${err.message}`));

Callers 1

server.tsFile · 0.90

Calls 4

findServerByIdFunction · 0.90
validateUfwFunction · 0.85
validateSshFunction · 0.85
validateFail2banFunction · 0.85

Tested by

no test coverage detected