diff --git a/striker-ui-api/src/lib/request_handlers/job/getJob.ts b/striker-ui-api/src/lib/request_handlers/job/getJob.ts index 529478f8..4b041124 100644 --- a/striker-ui-api/src/lib/request_handlers/job/getJob.ts +++ b/striker-ui-api/src/lib/request_handlers/job/getJob.ts @@ -1,11 +1,14 @@ +import { REP_PEACEFUL_STRING } from '../../consts'; + import buildGetRequestHandler from '../buildGetRequestHandler'; import { sanitize } from '../../sanitize'; import { date, stdout } from '../../shell'; export const getJob = buildGetRequestHandler((request, buildQueryOptions) => { - const { start: rawStart } = request.query; + const { start: rStart, command: rCommand } = request.query; - const start = sanitize(rawStart, 'number'); + const start = sanitize(rStart, 'number'); + const jcmd = sanitize(rCommand, 'string'); let condModifiedDate = ''; @@ -19,6 +22,12 @@ export const getJob = buildGetRequestHandler((request, buildQueryOptions) => { ); } + let condJobCommand = ''; + + if (REP_PEACEFUL_STRING.test(jcmd)) { + condJobCommand = `AND job.job_command LIKE '%${jcmd}%'`; + } + stdout(`condModifiedDate=[${condModifiedDate}]`); if (buildQueryOptions) { @@ -78,5 +87,6 @@ export const getJob = buildGetRequestHandler((request, buildQueryOptions) => { JOIN hosts AS hos ON job.job_host_uuid = hos.host_uuid WHERE (job.job_progress < 100 ${condModifiedDate}) + ${condJobCommand} AND job_name NOT LIKE 'get_server_screenshot%';`; }); diff --git a/striker-ui-api/src/routes/init.ts b/striker-ui-api/src/routes/init.ts index 1855060e..83c21feb 100644 --- a/striker-ui-api/src/routes/init.ts +++ b/striker-ui-api/src/routes/init.ts @@ -4,11 +4,33 @@ import { assertInit } from '../middlewares'; import { setMapNetwork } from '../lib/request_handlers/command'; import { configStriker } from '../lib/request_handlers/host'; +import { getJob } from '../lib/request_handlers/job'; import { getNetworkInterface } from '../lib/request_handlers/network-interface'; const router = express.Router(); router + .get( + '/job', + (request, response, next) => { + const { + path, + query: { command, start }, + } = request; + + if (command) return next(); + + return response.redirect( + `/api/init${path}?command=anvil-configure-host&start=${start}`, + ); + }, + assertInit({ + fail: ({ url }, response) => { + response.redirect(307, `/api${url}`); + }, + }), + getJob, + ) .get( '/network-interface/:hostUUID?', assertInit({