|
|
@ -1,5 +1,12 @@ |
|
|
|
|
|
|
|
import assert from 'assert'; |
|
|
|
import { RequestHandler } from 'express'; |
|
|
|
import { RequestHandler } from 'express'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
|
|
|
REP_DOMAIN, |
|
|
|
|
|
|
|
REP_INTEGER, |
|
|
|
|
|
|
|
REP_IPV4, |
|
|
|
|
|
|
|
REP_IPV4_CSV, |
|
|
|
|
|
|
|
} from '../../consts/REG_EXP_PATTERNS'; |
|
|
|
import SERVER_PATHS from '../../consts/SERVER_PATHS'; |
|
|
|
import SERVER_PATHS from '../../consts/SERVER_PATHS'; |
|
|
|
|
|
|
|
|
|
|
|
import { sub } from '../../accessModule'; |
|
|
|
import { sub } from '../../accessModule'; |
|
|
@ -10,39 +17,102 @@ const fvar = (configStepCount: number, fieldName: string) => |
|
|
|
const buildNetworkLinks = ( |
|
|
|
const buildNetworkLinks = ( |
|
|
|
configStepCount: number, |
|
|
|
configStepCount: number, |
|
|
|
networkShortName: string, |
|
|
|
networkShortName: string, |
|
|
|
interfaces: NetworkInterfaceOverview[], |
|
|
|
interfaces: InitializeStrikerNetworkForm['interfaces'], |
|
|
|
) => |
|
|
|
) => |
|
|
|
interfaces.reduce<string>( |
|
|
|
interfaces.reduce<string>((reduceContainer, iface, index) => { |
|
|
|
(reduceContainer, { networkInterfaceMACAddress }, index) => |
|
|
|
let result = reduceContainer; |
|
|
|
`${reduceContainer} |
|
|
|
|
|
|
|
|
|
|
|
if (iface) { |
|
|
|
|
|
|
|
const { networkInterfaceMACAddress } = iface; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result += ` |
|
|
|
${fvar( |
|
|
|
${fvar( |
|
|
|
configStepCount, |
|
|
|
configStepCount, |
|
|
|
`${networkShortName}_link${index + 1}_mac_to_set`, |
|
|
|
`${networkShortName}_link${index + 1}_mac_to_set`, |
|
|
|
)}=${networkInterfaceMACAddress}`,
|
|
|
|
)}=${networkInterfaceMACAddress}`;
|
|
|
|
'', |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
}, ''); |
|
|
|
|
|
|
|
|
|
|
|
export const initializeStriker: RequestHandler< |
|
|
|
export const initializeStriker: RequestHandler< |
|
|
|
unknown, |
|
|
|
unknown, |
|
|
|
undefined, |
|
|
|
undefined, |
|
|
|
InitializeStrikerForm |
|
|
|
InitializeStrikerForm |
|
|
|
> = (request, response) => { |
|
|
|
> = ({ body }, response) => { |
|
|
|
console.log('Begin initialize Striker.'); |
|
|
|
console.log('Begin initialize Striker.'); |
|
|
|
console.dir(request.body); |
|
|
|
console.dir(body, { depth: null }); |
|
|
|
|
|
|
|
|
|
|
|
const { |
|
|
|
const { |
|
|
|
body: { |
|
|
|
adminPassword = '', |
|
|
|
adminPassword, |
|
|
|
domainName = '', |
|
|
|
domainName, |
|
|
|
hostName = '', |
|
|
|
hostName, |
|
|
|
hostNumber = 0, |
|
|
|
hostNumber, |
|
|
|
networkDNS = '', |
|
|
|
networkDNS, |
|
|
|
networkGateway = '', |
|
|
|
networkGateway, |
|
|
|
networks = [], |
|
|
|
networks, |
|
|
|
organizationName = '', |
|
|
|
organizationName, |
|
|
|
organizationPrefix = '', |
|
|
|
organizationPrefix, |
|
|
|
} = body || {}; |
|
|
|
}, |
|
|
|
|
|
|
|
} = request; |
|
|
|
const dataAdminPassword = String(adminPassword); |
|
|
|
|
|
|
|
const dataDomainName = String(domainName); |
|
|
|
|
|
|
|
const dataHostName = String(hostName); |
|
|
|
|
|
|
|
const dataHostNumber = String(hostNumber); |
|
|
|
|
|
|
|
const dataNetworkDNS = String(networkDNS); |
|
|
|
|
|
|
|
const dataNetworkGateway = String(networkGateway); |
|
|
|
|
|
|
|
const dataOrganizationName = String(organizationName); |
|
|
|
|
|
|
|
const dataOrganizationPrefix = String(organizationPrefix); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
assert( |
|
|
|
|
|
|
|
!/['"/\\><}{]/g.test(dataAdminPassword), |
|
|
|
|
|
|
|
`Data admin password cannot contain single-quote, double-quote, slash, backslash, angle brackets, and curly brackets; got [${dataAdminPassword}]`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert( |
|
|
|
|
|
|
|
REP_DOMAIN.test(dataDomainName), |
|
|
|
|
|
|
|
`Data domain name can only contain alphanumeric, hyphen, and dot characters; got [${dataDomainName}]`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert( |
|
|
|
|
|
|
|
REP_DOMAIN.test(dataHostName), |
|
|
|
|
|
|
|
`Data host name can only contain alphanumeric, hyphen, and dot characters; got [${dataHostName}]`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert( |
|
|
|
|
|
|
|
REP_INTEGER.test(dataHostNumber) && hostNumber > 0, |
|
|
|
|
|
|
|
`Data host number can only contain digits; got [${dataHostNumber}]`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert( |
|
|
|
|
|
|
|
REP_IPV4_CSV.test(dataNetworkDNS), |
|
|
|
|
|
|
|
`Data network DNS must be a comma separated list of valid IPv4 addresses; got [${dataNetworkDNS}]`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert( |
|
|
|
|
|
|
|
REP_IPV4.test(dataNetworkGateway), |
|
|
|
|
|
|
|
`Data network gateway must be a valid IPv4 address; got [${dataNetworkGateway}]`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert( |
|
|
|
|
|
|
|
dataOrganizationName.length > 0, |
|
|
|
|
|
|
|
`Data organization name cannot be empty; got [${dataOrganizationName}]`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert( |
|
|
|
|
|
|
|
/^[a-z0-9]{1,5}$/.test(dataOrganizationPrefix), |
|
|
|
|
|
|
|
`Data organization prefix can only contain 1 to 5 lowercase alphanumeric characters; got [${dataOrganizationPrefix}]`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} catch (assertError) { |
|
|
|
|
|
|
|
console.log( |
|
|
|
|
|
|
|
`Failed to assert value when trying to initialize striker; CAUSE: ${assertError}.`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response.status(400).send(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
sub('insert_or_update_jobs', { |
|
|
|
sub('insert_or_update_jobs', { |
|
|
@ -87,9 +157,7 @@ ${buildNetworkLinks(2, networkShortName, interfaces)}`; |
|
|
|
}, |
|
|
|
}, |
|
|
|
}).stdout; |
|
|
|
}).stdout; |
|
|
|
} catch (subError) { |
|
|
|
} catch (subError) { |
|
|
|
console.log( |
|
|
|
console.log(`Failed to queue striker initialization; CAUSE: ${subError}`); |
|
|
|
`Failed to queue fetch server screenshot job; CAUSE: ${subError}`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response.status(500).send(); |
|
|
|
response.status(500).send(); |
|
|
|
|
|
|
|
|
|
|
|