diff options
Diffstat (limited to '_www/http_target.js')
| -rw-r--r-- | _www/http_target.js | 196 |
1 files changed, 98 insertions, 98 deletions
diff --git a/_www/http_target.js b/_www/http_target.js index 716c7e3..7e3928a 100644 --- a/_www/http_target.js +++ b/_www/http_target.js @@ -2,7 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later import { WuiInputSelect } from "./wui/input/select.js"; import { WuiInputString } from "./wui/input/string.js"; -import { GenerateFormInput, LoadHttpTargetHeader, LoadHttpTargetParam, } from "./functions.js"; +import { generateFormInput, loadHttpTargetHeader, loadHttpTargetParam, } from "./functions.js"; import { CLASS_INPUT, CLASS_INPUT_LABEL, } from "./interface.js"; const CLASS_HTTP_TARGET = "http_target"; const CLASS_HTTP_TARGET_ACTIONS = "http_target_actions"; @@ -21,61 +21,61 @@ export class HttpTarget { this.target = target; this.opts = opts; this.el = document.createElement("div"); - this.el_button_run = document.createElement("button"); - this.el_button_attack = document.createElement("button"); - this.el_request_input = document.createElement("div"); - this.el_out_request = document.createElement("div"); - this.el_out_response = document.createElement("div"); - this.el_out_response_body = document.createElement("div"); - this.el_out_attack = document.createElement("fieldset"); - this.el_out_attack_results = document.createElement("div"); + this.elButtonRun = document.createElement("button"); + this.elButtonAttack = document.createElement("button"); + this.elRequestInput = document.createElement("div"); + this.elOutRequest = document.createElement("div"); + this.elOutResponse = document.createElement("div"); + this.elOutResponseBody = document.createElement("div"); + this.elOutAttack = document.createElement("fieldset"); + this.elOutAttackResults = document.createElement("div"); 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); - this.generateActions(el_title); + const elTitle = document.createElement("h3"); + elTitle.innerText = opts.Name; + this.el.appendChild(elTitle); + this.generateActions(elTitle); this.generateHint(this.el); this.generateInput(this.el); this.generateOutput(this.el); this.generateOutputAttack(this.el); } generateActions(parent) { - const el_actions = document.createElement("span"); - el_actions.classList.add(CLASS_HTTP_TARGET_ACTIONS); - this.el_button_run.innerText = "Run"; - this.el_button_run.onclick = () => { + const elActions = document.createElement("span"); + elActions.classList.add(CLASS_HTTP_TARGET_ACTIONS); + 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); } generateHint(parent) { 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); } generateInput(parent) { - this.el_request_input.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); - parent.appendChild(this.el_request_input); + this.elRequestInput.classList.add(CLASS_HTTP_TARGET_INPUT); + this.generateRequestMethod(this.elRequestInput); + this.generateRequestContentType(this.elRequestInput); + this.generateRequestHeaders(this.elRequestInput); + this.generateRequestParameters(this.elRequestInput); + parent.appendChild(this.elRequestInput); } generateRequestMethod(parent) { const m = "" + this.opts.Method; - const select_opts = { + const selectOpts = { label: "", name: "", options: { @@ -121,9 +121,9 @@ export class HttpTarget { this.opts.Method = parseInt(value); }, }; - const wui_request_method = new WuiInputSelect(select_opts); - const path_opts = { - label: wui_request_method.el, + const wuiRequestMethod = new WuiInputSelect(selectOpts); + const pathOpts = { + label: wuiRequestMethod.el, value: this.opts.Path, class_input: CLASS_INPUT, class_label: CLASS_INPUT_LABEL, @@ -132,12 +132,12 @@ export class HttpTarget { this.opts.Path = path; }, }; - const wui_request_path = new WuiInputString(path_opts); - parent.appendChild(wui_request_path.el); + const wuiRequestPath = new WuiInputString(pathOpts); + parent.appendChild(wuiRequestPath.el); } generateRequestContentType(parent) { const ct = "" + this.opts.RequestType; - const select_opts = { + const selectOpts = { label: "Content type", name: "", options: { @@ -169,8 +169,8 @@ export class HttpTarget { this.opts.RequestType = parseInt(value); }, }; - const wui_request_type = new WuiInputSelect(select_opts); - parent.appendChild(wui_request_type.el); + const wuiRequestType = new WuiInputSelect(selectOpts); + parent.appendChild(wuiRequestType.el); } generateRequestHeaders(parent) { if (!this.opts.Headers) { @@ -185,8 +185,8 @@ export class HttpTarget { legend.innerText = "Headers"; 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); } @@ -203,8 +203,8 @@ export class HttpTarget { title.innerText = "Parameters"; 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); } @@ -213,19 +213,19 @@ export class HttpTarget { wrapper.classList.add(CLASS_HTTP_TARGET_OUT_RUN); 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); - 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); + title.appendChild(btnClear); + 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(); } @@ -233,13 +233,13 @@ export class HttpTarget { if (!this.opts.AllowAttack) { 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.el_out_attack.appendChild(title); - this.el_out_attack.appendChild(this.el_out_attack_results); - parent.appendChild(this.el_out_attack); + this.generateAttackResults(this.elOutAttackResults); + this.elOutAttack.appendChild(title); + this.elOutAttack.appendChild(this.elOutAttackResults); + parent.appendChild(this.elOutAttack); } generateAttackResults(parent) { parent.innerText = ""; @@ -249,91 +249,91 @@ export class HttpTarget { for (const result of this.opts.Results) { 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 el_report_hist = document.createElement("div"); - el_report_hist.style.display = "none"; - el_report_hist.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 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; 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 = () => { - this.onClickAttackShow(result.Name, btn_attack_show, el_report_text, el_report_hist); + const btnAttackShow = document.createElement("button"); + btnAttackShow.innerText = "Show"; + btnAttackShow.onclick = () => { + this.onClickAttackShow(result.Name, 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); } } async onClickAttack() { - await this.trunks.AttackHttp(this.target, this.opts); + await this.trunks.attackHttp(this.target, this.opts); } async onClickAttackDelete(result) { - const res = await this.trunks.AttackHttpDelete(result.Name); + const res = await this.trunks.attackHttpDelete(result.Name); if (!res) { return; } this.opts.Results.forEach((r, x) => { if (r.Name == result.Name) { this.opts.Results.splice(x, 1); - this.generateAttackResults(this.el_out_attack_results); + this.generateAttackResults(this.elOutAttackResults); return; } }); } - async onClickAttackShow(result_name, btn, el_report_text, el_report_hist) { + async onClickAttackShow(resultName, btn, elReportText, elReportHist) { 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; - el_report_text.innerText = atob(res.TextReport); - el_report_text.style.display = "block"; - el_report_hist.innerText = atob(res.HistReport); - el_report_hist.style.display = "block"; + const res = resJSON.data; + elReportText.innerText = atob(res.TextReport); + elReportText.style.display = "block"; + elReportHist.innerText = atob(res.HistReport); + elReportHist.style.display = "block"; btn.innerText = "Hide"; } 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"; } 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(JSON.parse(body), null, 2); + this.elOutResponseBody.innerText = JSON.stringify(JSON.parse(body), null, 2); } else { - this.el_out_response_body.innerText = body; + this.elOutResponseBody.innerText = body; } } AddAttackResult(result) { this.opts.Results.push(result); - this.generateAttackResults(this.el_out_attack_results); + this.generateAttackResults(this.elOutAttackResults); } } |
