|
|
@ -1,11 +1,15 @@ |
|
|
|
import { RequestHandler } from 'express'; |
|
|
|
import { RequestHandler } from 'express'; |
|
|
|
|
|
|
|
|
|
|
|
import { sub } from '../../accessModule'; |
|
|
|
import { HOST_KEY_CHANGED_PREFIX } from '../../consts/HOST_KEY_CHANGED_PREFIX'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { dbQuery, getLocalHostUUID, sub } from '../../accessModule'; |
|
|
|
|
|
|
|
import { sanitizeSQLParam } from '../../sanitizeSQLParam'; |
|
|
|
import { stderr } from '../../shell'; |
|
|
|
import { stderr } from '../../shell'; |
|
|
|
|
|
|
|
|
|
|
|
export const getHostSSH: RequestHandler< |
|
|
|
export const getHostSSH: RequestHandler< |
|
|
|
unknown, |
|
|
|
unknown, |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
badSSHKeys?: DeleteSSHKeyConflictRequestBody; |
|
|
|
hostName: string; |
|
|
|
hostName: string; |
|
|
|
hostOS: string; |
|
|
|
hostOS: string; |
|
|
|
hostUUID: string; |
|
|
|
hostUUID: string; |
|
|
@ -29,6 +33,8 @@ export const getHostSSH: RequestHandler< |
|
|
|
rawIsInetConnected: string, |
|
|
|
rawIsInetConnected: string, |
|
|
|
rawIsOSRegistered: string; |
|
|
|
rawIsOSRegistered: string; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const localHostUUID = getLocalHostUUID(); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
({ |
|
|
|
({ |
|
|
|
host_name: hostName, |
|
|
|
host_name: hostName, |
|
|
@ -54,11 +60,37 @@ export const getHostSSH: RequestHandler< |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isConnected: boolean = hostName.length > 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let badSSHKeys: DeleteSSHKeyConflictRequestBody | undefined; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isConnected) { |
|
|
|
|
|
|
|
const rows = dbQuery(` |
|
|
|
|
|
|
|
SELECT sta.state_note, sta.state_uuid |
|
|
|
|
|
|
|
FROM states AS sta |
|
|
|
|
|
|
|
WHERE sta.state_host_uuid = '${localHostUUID}' |
|
|
|
|
|
|
|
AND sta.state_name = '${HOST_KEY_CHANGED_PREFIX}${sanitizeSQLParam( |
|
|
|
|
|
|
|
target, |
|
|
|
|
|
|
|
)}';`).stdout as [stateNote: string, stateUUID: string][];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (rows.length > 0) { |
|
|
|
|
|
|
|
badSSHKeys = rows.reduce<DeleteSSHKeyConflictRequestBody>( |
|
|
|
|
|
|
|
(previous, [, stateUUID]) => { |
|
|
|
|
|
|
|
previous[localHostUUID].push(stateUUID); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return previous; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ [localHostUUID]: [] }, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
response.status(200).send({ |
|
|
|
response.status(200).send({ |
|
|
|
|
|
|
|
badSSHKeys, |
|
|
|
hostName, |
|
|
|
hostName, |
|
|
|
hostOS, |
|
|
|
hostOS, |
|
|
|
hostUUID, |
|
|
|
hostUUID, |
|
|
|
isConnected: hostName.length > 0, |
|
|
|
isConnected, |
|
|
|
isInetConnected: rawIsInetConnected === '1', |
|
|
|
isInetConnected: rawIsInetConnected === '1', |
|
|
|
isOSRegistered: rawIsOSRegistered === 'yes', |
|
|
|
isOSRegistered: rawIsOSRegistered === 'yes', |
|
|
|
}); |
|
|
|
}); |
|
|
|