diff options
Diffstat (limited to '_www/http_target.ts')
| -rw-r--r-- | _www/http_target.ts | 208 |
1 files changed, 104 insertions, 104 deletions
diff --git a/_www/http_target.ts b/_www/http_target.ts index 8d5c972..69a76b8 100644 --- a/_www/http_target.ts +++ b/_www/http_target.ts @@ -5,9 +5,9 @@ import { WuiInputSelect, WuiInputSelectOpts } from "./wui/input/select.js"; import { WuiInputString, WuiInputStringOpts } from "./wui/input/string.js"; import { - GenerateFormInput, - LoadHttpTargetHeader, - LoadHttpTargetParam, + generateFormInput, + loadHttpTargetHeader, + loadHttpTargetParam, } from "./functions.js"; import { CLASS_INPUT, @@ -34,14 +34,14 @@ const CONTENT_TYPE_JSON = "application/json"; export class HttpTarget { el: HTMLElement = document.createElement("div"); - el_button_run: HTMLButtonElement = document.createElement("button"); - el_button_attack: HTMLButtonElement = document.createElement("button"); - el_request_input: HTMLElement = document.createElement("div"); - el_out_request: HTMLElement = document.createElement("div"); - el_out_response: HTMLElement = document.createElement("div"); - el_out_response_body: HTMLElement = document.createElement("div"); - el_out_attack: HTMLElement = document.createElement("fieldset"); - el_out_attack_results: HTMLElement = document.createElement("div"); + elButtonRun: HTMLButtonElement = document.createElement("button"); + elButtonAttack: HTMLButtonElement = document.createElement("button"); + elRequestInput: HTMLElement = document.createElement("div"); + elOutRequest: HTMLElement = document.createElement("div"); + elOutResponse: HTMLElement = document.createElement("div"); + elOutResponseBody: HTMLElement = document.createElement("div"); + elOutAttack: HTMLElement = document.createElement("fieldset"); + elOutAttackResults: HTMLElement = document.createElement("div"); constructor( public trunks: TrunksInterface, @@ -51,11 +51,11 @@ export class HttpTarget { this.el.id = opts.ID; this.el.classList.add(CLASS_HTTP_TARGET); - const el_title = document.createElement("h3"); - el_title.innerText = opts.Name; - this.el.appendChild(el_title); + const elTitle = document.createElement("h3"); + elTitle.innerText = opts.Name; + this.el.appendChild(elTitle); - this.generateActions(el_title); + this.generateActions(elTitle); this.generateHint(this.el); this.generateInput(this.el); this.generateOutput(this.el); @@ -63,49 +63,49 @@ export class HttpTarget { } private generateActions(parent: HTMLElement) { - const el_actions = document.createElement("span"); - el_actions.classList.add(CLASS_HTTP_TARGET_ACTIONS); + const elActions = document.createElement("span"); + elActions.classList.add(CLASS_HTTP_TARGET_ACTIONS); - this.el_button_run.innerText = "Run"; - this.el_button_run.onclick = () => { + this.elButtonRun.innerText = "Run"; + this.elButtonRun.onclick = () => { this.onClickRun(); }; - el_actions.appendChild(this.el_button_run); + elActions.appendChild(this.elButtonRun); if (this.opts.AllowAttack) { - this.el_button_attack.innerText = "Attack"; - this.el_button_attack.onclick = () => { + this.elButtonAttack.innerText = "Attack"; + this.elButtonAttack.onclick = () => { this.onClickAttack(); }; - el_actions.appendChild(this.el_button_attack); + elActions.appendChild(this.elButtonAttack); } - parent.appendChild(el_actions); + parent.appendChild(elActions); } private generateHint(parent: HTMLElement) { if (!this.opts.Hint) { return; } - const el_hint = document.createElement("p"); - el_hint.innerHTML = this.opts.Hint; - parent.appendChild(el_hint); + const elHint = document.createElement("p"); + elHint.innerHTML = this.opts.Hint; + parent.appendChild(elHint); } private generateInput(parent: HTMLElement) { - this.el_request_input.classList.add(CLASS_HTTP_TARGET_INPUT); + this.elRequestInput.classList.add(CLASS_HTTP_TARGET_INPUT); - this.generateRequestMethod(this.el_request_input); - this.generateRequestContentType(this.el_request_input); - this.generateRequestHeaders(this.el_request_input); - this.generateRequestParameters(this.el_request_input); + this.generateRequestMethod(this.elRequestInput); + this.generateRequestContentType(this.elRequestInput); + this.generateRequestHeaders(this.elRequestInput); + this.generateRequestParameters(this.elRequestInput); - parent.appendChild(this.el_request_input); + parent.appendChild(this.elRequestInput); } private generateRequestMethod(parent: HTMLElement) { const m = "" + this.opts.Method; - const select_opts: WuiInputSelectOpts = { + const selectOpts: WuiInputSelectOpts = { label: "", name: "", options: { @@ -151,10 +151,10 @@ export class HttpTarget { this.opts.Method = parseInt(value); }, }; - const wui_request_method = new WuiInputSelect(select_opts); + const wuiRequestMethod = new WuiInputSelect(selectOpts); - const path_opts: WuiInputStringOpts = { - label: wui_request_method.el, + const pathOpts: WuiInputStringOpts = { + label: wuiRequestMethod.el, value: this.opts.Path, class_input: CLASS_INPUT, class_label: CLASS_INPUT_LABEL, @@ -163,14 +163,14 @@ export class HttpTarget { this.opts.Path = path; }, }; - const wui_request_path = new WuiInputString(path_opts); + const wuiRequestPath = new WuiInputString(pathOpts); - parent.appendChild(wui_request_path.el); + parent.appendChild(wuiRequestPath.el); } private generateRequestContentType(parent: HTMLElement) { const ct = "" + this.opts.RequestType; - const select_opts: WuiInputSelectOpts = { + const selectOpts: WuiInputSelectOpts = { label: "Content type", name: "", options: { @@ -202,9 +202,9 @@ export class HttpTarget { this.opts.RequestType = parseInt(value); }, }; - const wui_request_type = new WuiInputSelect(select_opts); + const wuiRequestType = new WuiInputSelect(selectOpts); - parent.appendChild(wui_request_type.el); + parent.appendChild(wuiRequestType.el); } private generateRequestHeaders(parent: HTMLElement) { @@ -223,8 +223,8 @@ export class HttpTarget { wrapper.appendChild(legend); for (const [key, fi] of Object.entries(this.opts.Headers)) { - fi.value = LoadHttpTargetHeader(this.target, this.opts, key); - GenerateFormInput(wrapper, fi); + fi.value = loadHttpTargetHeader(this.target, this.opts, key); + generateFormInput(wrapper, fi); } parent.appendChild(wrapper); @@ -246,8 +246,8 @@ export class HttpTarget { wrapper.appendChild(title); for (const [key, fi] of Object.entries(this.opts.Params)) { - fi.value = LoadHttpTargetParam(this.target, this.opts, key); - GenerateFormInput(wrapper, fi); + fi.value = loadHttpTargetParam(this.target, this.opts, key); + generateFormInput(wrapper, fi); } parent.appendChild(wrapper); @@ -260,21 +260,21 @@ export class HttpTarget { const title = document.createElement("legend"); title.innerText = "Run output"; - const btn_clear = document.createElement("button"); - btn_clear.innerText = "Clear"; - btn_clear.onclick = () => { + const btnClear = document.createElement("button"); + btnClear.innerText = "Clear"; + btnClear.onclick = () => { this.onClickClearOutput(); }; - title.appendChild(btn_clear); + title.appendChild(btnClear); - this.el_out_request.classList.add(CLASS_HTTP_TARGET_OUT_MONO); - this.el_out_response.classList.add(CLASS_HTTP_TARGET_OUT_MONO); - this.el_out_response_body.classList.add(CLASS_HTTP_TARGET_OUT_MONO); + this.elOutRequest.classList.add(CLASS_HTTP_TARGET_OUT_MONO); + this.elOutResponse.classList.add(CLASS_HTTP_TARGET_OUT_MONO); + this.elOutResponseBody.classList.add(CLASS_HTTP_TARGET_OUT_MONO); wrapper.appendChild(title); - wrapper.appendChild(this.el_out_request); - wrapper.appendChild(this.el_out_response); - wrapper.appendChild(this.el_out_response_body); + wrapper.appendChild(this.elOutRequest); + wrapper.appendChild(this.elOutResponse); + wrapper.appendChild(this.elOutResponseBody); parent.appendChild(wrapper); this.onClickClearOutput(); @@ -285,16 +285,16 @@ export class HttpTarget { return; } - this.el_out_attack.classList.add(CLASS_HTTP_TARGET_OUT_ATTACK); + this.elOutAttack.classList.add(CLASS_HTTP_TARGET_OUT_ATTACK); const title = document.createElement("legend"); title.innerText = "Attack results"; - this.generateAttackResults(this.el_out_attack_results); + this.generateAttackResults(this.elOutAttackResults); - this.el_out_attack.appendChild(title); - this.el_out_attack.appendChild(this.el_out_attack_results); - parent.appendChild(this.el_out_attack); + this.elOutAttack.appendChild(title); + this.elOutAttack.appendChild(this.elOutAttackResults); + parent.appendChild(this.elOutAttack); } private generateAttackResults(parent: HTMLElement) { @@ -308,13 +308,13 @@ export class HttpTarget { const wrapper = document.createElement("div"); wrapper.classList.add(CLASS_HTTP_TARGET_ATTACK_RESULT); - const el_report_text = document.createElement("div"); - el_report_text.style.display = "none"; - el_report_text.classList.add(CLASS_HTTP_TARGET_OUT_MONO); + const elReportText = document.createElement("div"); + elReportText.style.display = "none"; + elReportText.classList.add(CLASS_HTTP_TARGET_OUT_MONO); - const el_report_hist = document.createElement("div"); - el_report_hist.style.display = "none"; - el_report_hist.classList.add(CLASS_HTTP_TARGET_OUT_MONO); + const elReportHist = document.createElement("div"); + elReportHist.style.display = "none"; + elReportHist.classList.add(CLASS_HTTP_TARGET_OUT_MONO); const el = document.createElement("div"); el.innerText = result.Name; @@ -322,109 +322,109 @@ export class HttpTarget { const actions = document.createElement("span"); actions.classList.add(CLASS_HTTP_TARGET_ATTACK_RESULT_ACTIONS); - const btn_attack_show = document.createElement("button"); - btn_attack_show.innerText = "Show"; - btn_attack_show.onclick = () => { + const btnAttackShow = document.createElement("button"); + btnAttackShow.innerText = "Show"; + btnAttackShow.onclick = () => { this.onClickAttackShow( result.Name, - btn_attack_show, - el_report_text, - el_report_hist, + btnAttackShow, + elReportText, + elReportHist, ); }; - const btn_attack_del = document.createElement("button"); - btn_attack_del.innerText = "Delete"; - btn_attack_del.onclick = () => { + const btnAttackDel = document.createElement("button"); + btnAttackDel.innerText = "Delete"; + btnAttackDel.onclick = () => { this.onClickAttackDelete(result); }; - actions.appendChild(btn_attack_show); - actions.appendChild(btn_attack_del); + actions.appendChild(btnAttackShow); + actions.appendChild(btnAttackDel); el.appendChild(actions); wrapper.appendChild(el); - wrapper.appendChild(el_report_text); - wrapper.appendChild(el_report_hist); + wrapper.appendChild(elReportText); + wrapper.appendChild(elReportHist); parent.appendChild(wrapper); } } private async onClickAttack() { - await this.trunks.AttackHttp(this.target, this.opts); + await this.trunks.attackHttp(this.target, this.opts); } private async onClickAttackDelete(result: AttackResult) { - const res = await this.trunks.AttackHttpDelete(result.Name); + const res = await this.trunks.attackHttpDelete(result.Name); if (!res) { return; } this.opts.Results.forEach((r: AttackResult, x: number) => { if (r.Name == result.Name) { this.opts.Results.splice(x, 1); - this.generateAttackResults(this.el_out_attack_results); + this.generateAttackResults(this.elOutAttackResults); return; } }); } private async onClickAttackShow( - result_name: string, + resultName: string, btn: HTMLButtonElement, - el_report_text: HTMLElement, - el_report_hist: HTMLElement, + elReportText: HTMLElement, + elReportHist: HTMLElement, ) { if (btn.innerText === "Hide") { btn.innerText = "Show"; - el_report_text.style.display = "none"; - el_report_hist.style.display = "none"; + elReportText.style.display = "none"; + elReportHist.style.display = "none"; return; } - const res_json = await this.trunks.AttackHttpGet(result_name); - if (res_json.code != 200) { + const resJSON = await this.trunks.attackHttpGet(resultName); + if (resJSON.code != 200) { return; } - const res = res_json.data as AttackResult; + const res = resJSON.data as AttackResult; - el_report_text.innerText = atob(res.TextReport); - el_report_text.style.display = "block"; + elReportText.innerText = atob(res.TextReport); + elReportText.style.display = "block"; - el_report_hist.innerText = atob(res.HistReport); - el_report_hist.style.display = "block"; + elReportHist.innerText = atob(res.HistReport); + elReportHist.style.display = "block"; btn.innerText = "Hide"; } private async onClickClearOutput() { - this.el_out_request.innerText = "Raw request"; - this.el_out_response.innerText = "Raw response"; - this.el_out_response_body.innerText = "JSON formatted response body"; + this.elOutRequest.innerText = "Raw request"; + this.elOutResponse.innerText = "Raw response"; + this.elOutResponseBody.innerText = "JSON formatted response body"; } private async onClickRun() { - const res = await this.trunks.RunHttp(this.target, this.opts); + const res = await this.trunks.runHttp(this.target, this.opts); if (!res) { return; } - this.el_out_request.innerText = atob(res.DumpRequest); - this.el_out_response.innerText = atob(res.DumpResponse); + this.elOutRequest.innerText = atob(res.DumpRequest); + this.elOutResponse.innerText = atob(res.DumpResponse); const body = atob(res.ResponseBody); if (res.ResponseType === CONTENT_TYPE_JSON) { - this.el_out_response_body.innerText = JSON.stringify( + this.elOutResponseBody.innerText = JSON.stringify( JSON.parse(body), null, 2, ); } else { - this.el_out_response_body.innerText = body; + this.elOutResponseBody.innerText = body; } } AddAttackResult(result: AttackResult) { this.opts.Results.push(result); - this.generateAttackResults(this.el_out_attack_results); + this.generateAttackResults(this.elOutAttackResults); } } |
