diff options
Diffstat (limited to '_www/trunks.js')
| -rw-r--r-- | _www/trunks.js | 238 |
1 files changed, 119 insertions, 119 deletions
diff --git a/_www/trunks.js b/_www/trunks.js index 342e59f..8e8eaac 100644 --- a/_www/trunks.js +++ b/_www/trunks.js @@ -1,11 +1,11 @@ // SPDX-FileCopyrightText: 2021 M. Shulhan <ms@kilabit.info> // SPDX-License-Identifier: GPL-3.0-or-later import { Environment } from "./environment.js"; -import { Save } from "./functions.js"; +import { save } from "./functions.js"; import { HASH_ENVIRONMENT, } from "./interface.js"; import { NavLinks } from "./nav_links.js"; import { Target } from "./target.js"; -import { wui_notif } from "./vars.js"; +import { wuiNotif } from "./vars.js"; const API_ATTACK_HTTP = "/_trunks/api/attack/http"; const API_ATTACK_RESULT = "/_trunks/api/attack/result"; const API_ENVIRONMENT = "/_trunks/api/environment"; @@ -30,51 +30,51 @@ export class Trunks { this.targets = {}; this.navLinks = {}; this.el = document.createElement("div"); - this.com_env = new Environment(this, this.env); + this.comEnv = new Environment(this, this.env); this.generateNav(); this.generateContent(); document.body.appendChild(this.el); } generateNav() { - const el_nav = document.createElement("div"); - el_nav.classList.add(CLASS_NAV); - this.el_ws_conn_status = document.createElement("div"); - const fs_attack_running = document.createElement("fieldset"); + const elNav = document.createElement("div"); + elNav.classList.add(CLASS_NAV); + this.elWSConnStatus = document.createElement("div"); + const fsAttackRunning = document.createElement("fieldset"); const legend = document.createElement("legend"); legend.innerText = "Attack running"; - this.el_attack_running = document.createElement("span"); - this.el_attack_running.classList.add(CLASS_ATTACK_RUNNING); - this.el_nav_content = document.createElement("div"); - this.el_nav_links = document.createElement("div"); - const el_nav_footer = document.createElement("div"); - el_nav_footer.classList.add(CLASS_FOOTER); - el_nav_footer.innerHTML = ` + this.elAttackRunning = document.createElement("span"); + this.elAttackRunning.classList.add(CLASS_ATTACK_RUNNING); + this.elNavContent = document.createElement("div"); + this.elNavLinks = document.createElement("div"); + const elNavFooter = document.createElement("div"); + elNavFooter.classList.add(CLASS_FOOTER); + elNavFooter.innerHTML = ` <div> <div>Powered by <a href="https://sr.ht/~shulhan/trunks" target="_blank">Trunks</a></div> <div><a href="/doc/" target="_blank">Documentation</a></div> </div> `; - el_nav.appendChild(this.el_ws_conn_status); - fs_attack_running.appendChild(legend); - fs_attack_running.appendChild(this.el_attack_running); - el_nav.appendChild(fs_attack_running); - el_nav.appendChild(this.com_env.el_nav); - el_nav.appendChild(this.el_nav_content); - el_nav.appendChild(document.createElement("hr")); - el_nav.appendChild(this.el_nav_links); - el_nav.appendChild(el_nav_footer); - this.el.appendChild(el_nav); + elNav.appendChild(this.elWSConnStatus); + fsAttackRunning.appendChild(legend); + fsAttackRunning.appendChild(this.elAttackRunning); + elNav.appendChild(fsAttackRunning); + elNav.appendChild(this.comEnv.elNav); + elNav.appendChild(this.elNavContent); + elNav.appendChild(document.createElement("hr")); + elNav.appendChild(this.elNavLinks); + elNav.appendChild(elNavFooter); + this.el.appendChild(elNav); } generateContent() { const wrapper = document.createElement("div"); wrapper.classList.add(CLASS_MAIN); - this.el_attack_cancel = document.createElement("button"); - this.el_attack_cancel.innerHTML = "Cancel"; - this.el_content = document.createElement("div"); - wrapper.appendChild(this.el_content); + this.elAttackCancel = document.createElement("button"); + this.elAttackCancel.innerHTML = "Cancel"; + this.elContent = document.createElement("div"); + wrapper.appendChild(this.elContent); this.el.appendChild(wrapper); } - async Init() { + async init() { await this.apiEnvironmentGet(); await this.initTargets(); await this.initNavLinks(); @@ -84,56 +84,56 @@ export class Trunks { }; } async apiEnvironmentGet() { - const http_res = await fetch(API_ENVIRONMENT); - const res = await http_res.json(); + const httpRes = await fetch(API_ENVIRONMENT); + const res = await httpRes.json(); if (res.code != 200) { - wui_notif.error(res.message); + wuiNotif.error(res.message); return; } this.env = res.data; this.setAttackRunning(this.env.AttackRunning); - this.com_env.Set(this.env); + this.comEnv.set(this.env); } async initNavLinks() { - const http_res = await fetch(API_NAVLINKS); - const res = await http_res.json(); + const httpRes = await fetch(API_NAVLINKS); + const res = await httpRes.json(); if (res.code != 200) { - wui_notif.error(res.message); + wuiNotif.error(res.message); return; } - this.com_nav_links = new NavLinks(this, res.data); - this.el_nav_links.appendChild(this.com_nav_links.el_nav); + this.comNavLinks = new NavLinks(this, res.data); + this.elNavLinks.appendChild(this.comNavLinks.elNav); for (const nav of res.data) { this.navLinks[nav.ID] = nav; } } async initTargets() { - const http_res = await fetch(API_TARGETS); - const res = await http_res.json(); + const httpRes = await fetch(API_TARGETS); + const res = await httpRes.json(); if (res.code != 200) { - wui_notif.error(res.message); + wuiNotif.error(res.message); return; } const targets = res.data; - this.el_nav_content.innerHTML = ""; + this.elNavContent.innerHTML = ""; for (const target of targets) { - const com_target = new Target(this, target); - this.targets[target.ID] = com_target; - this.el_nav_content.appendChild(com_target.el_nav); + const comTarget = new Target(this, target); + this.targets[target.ID] = comTarget; + this.elNavContent.appendChild(comTarget.elNav); } } async onClickAttackCancel() { const fres = await fetch(API_ATTACK_HTTP, { method: "DELETE", }); - const json_res = await fres.json(); - if (json_res.code != 200) { - wui_notif.error(json_res.message); + const jsonRes = await fres.json(); + if (jsonRes.code != 200) { + wuiNotif.error(jsonRes.message); return null; } - wui_notif.info(json_res.message); + wuiNotif.info(jsonRes.message); this.setAttackRunning(null); - return json_res; + return jsonRes; } windowOnHashChange() { // Parse the location hash. @@ -143,8 +143,8 @@ export class Trunks { return; } if (paths[1] === HASH_ENVIRONMENT) { - this.el_content.innerHTML = ""; - this.el_content.appendChild(this.com_env.el_content); + this.elContent.innerHTML = ""; + this.elContent.appendChild(this.comEnv.elContent); return; } console.log("paths: ", paths); @@ -160,8 +160,8 @@ export class Trunks { case 2: case 3: if (target) { - this.el_content.innerHTML = ""; - this.el_content.appendChild(target.el_content); + this.elContent.innerHTML = ""; + this.elContent.appendChild(target.elContent); el = document.getElementById(paths[1]); if (el) { el.scrollIntoView(); @@ -170,19 +170,19 @@ export class Trunks { break; case 4: if (paths[2] === "http") { - this.el_content.innerHTML = ""; - this.el_content.appendChild(target.el_content); + this.elContent.innerHTML = ""; + this.elContent.appendChild(target.elContent); } else if (paths[2] === "ws") { - this.el_content.innerHTML = ""; - this.el_content.appendChild(target.el_content); + this.elContent.innerHTML = ""; + this.elContent.appendChild(target.elContent); } else if (paths[2] === "link") { if (paths[3]) { const nav = this.navLinks[paths[3]]; if (nav) { - this.el_content.innerHTML = ""; - this.com_nav_links.open(nav); + this.elContent.innerHTML = ""; + this.comNavLinks.open(nav); } } } @@ -195,26 +195,26 @@ export class Trunks { } setAttackRunning(runRequest) { if (!runRequest) { - this.el_attack_running.innerHTML = "-"; + this.elAttackRunning.innerHTML = "-"; return; } if (!runRequest.Target || !runRequest.HttpTarget) { - this.el_attack_running.innerHTML = "-"; + this.elAttackRunning.innerHTML = "-"; return; } - this.el_attack_running.innerHTML = ` + this.elAttackRunning.innerHTML = ` ${runRequest.Target.Name} <br/> / ${runRequest.HttpTarget.Name} <br/> <br/> `; - this.el_attack_cancel.onclick = () => { + this.elAttackCancel.onclick = () => { this.onClickAttackCancel(); }; - this.el_attack_running.appendChild(this.el_attack_cancel); - wui_notif.info(`Attacking "${runRequest.Target.Name}/${runRequest.HttpTarget.Name}" ...`); + this.elAttackRunning.appendChild(this.elAttackCancel); + wuiNotif.info(`Attacking "${runRequest.Target.Name}/${runRequest.HttpTarget.Name}" ...`); } - async AttackHttp(target, http_target) { - Save(target, http_target, null); + async attackHttp(target, httpTarget) { + save(target, httpTarget, null); const attackReq = { Target: { ID: target.ID, @@ -226,35 +226,35 @@ export class Trunks { WebSocketTargets: [], }, HttpTarget: { - ID: http_target.ID, - Name: http_target.Name, - Method: http_target.Method, - Path: http_target.Path, - RequestType: http_target.RequestType, - Headers: http_target.Headers, - Params: http_target.Params, + ID: httpTarget.ID, + Name: httpTarget.Name, + Method: httpTarget.Method, + Path: httpTarget.Path, + RequestType: httpTarget.RequestType, + Headers: httpTarget.Headers, + Params: httpTarget.Params, Results: [], - AllowAttack: http_target.AllowAttack, - IsCustomizable: http_target.IsCustomizable, + AllowAttack: httpTarget.AllowAttack, + IsCustomizable: httpTarget.IsCustomizable, }, WebSocketTarget: null, }; - const http_res = await fetch(API_ATTACK_HTTP, { + const httpRes = await fetch(API_ATTACK_HTTP, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(attackReq), }); - const json_res = await http_res.json(); - if (json_res.code != 200) { - wui_notif.error(json_res.message); + const jsonRes = await httpRes.json(); + if (jsonRes.code != 200) { + wuiNotif.error(jsonRes.message); return null; } this.setAttackRunning(attackReq); - return json_res; + return jsonRes; } - async AttackHttpDelete(name) { + async attackHttpDelete(name) { const msg = `Are you sure you want to delete the result: ${name}?`; const yes = window.confirm(msg); if (!yes) { @@ -264,39 +264,39 @@ export class Trunks { const fres = await fetch(url, { method: "DELETE", }); - const json_res = await fres.json(); - if (json_res.code != 200) { - wui_notif.error(json_res.message); + const jsonRes = await fres.json(); + if (jsonRes.code != 200) { + wuiNotif.error(jsonRes.message); return null; } - return json_res; + return jsonRes; } - async AttackHttpGet(name) { + async attackHttpGet(name) { const url = API_ATTACK_RESULT + "?name=" + name; const fres = await fetch(url); const res = await fres.json(); if (res.code != 200) { - wui_notif.error(res.message); + wuiNotif.error(res.message); } return res; } - ContentRenderer(target, http_target, ws_target, nav_link, el) { + contentRenderer(target, httpTarget, wsTarget, navLink, el) { let hash = "#/" + target.ID; - if (http_target) { - hash += "/http/" + http_target.ID; + if (httpTarget) { + hash += "/http/" + httpTarget.ID; } - else if (ws_target) { - hash += "/ws/" + ws_target.ID; + else if (wsTarget) { + hash += "/ws/" + wsTarget.ID; } - else if (nav_link) { - hash += "/link/" + nav_link.ID; + else if (navLink) { + hash += "/link/" + navLink.ID; } window.location.hash = hash; - this.el_content.innerHTML = ""; - this.el_content.appendChild(el); + this.elContent.innerHTML = ""; + this.elContent.appendChild(el); } - async RunHttp(target, http_target) { - Save(target, http_target, null); + async runHttp(target, httpTarget) { + save(target, httpTarget, null); const req = { Target: { ID: target.ID, @@ -307,32 +307,32 @@ export class Trunks { HttpTargets: [], WebSocketTargets: [], }, - HttpTarget: http_target, + HttpTarget: httpTarget, WebSocketTarget: null, }; - const http_res = await fetch(API_TARGET_RUN_HTTP, { + const httpRes = await fetch(API_TARGET_RUN_HTTP, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(req), }); - const json_res = await http_res.json(); - if (json_res.code != 200) { - wui_notif.error(json_res.message); + const jsonRes = await httpRes.json(); + if (jsonRes.code != 200) { + wuiNotif.error(jsonRes.message); return null; } - const res = json_res.data; + const res = jsonRes.data; if (res.ResponseStatusCode != 200) { - wui_notif.error(`${http_target.Name}: ${res.ResponseStatus}`); + wuiNotif.error(`${httpTarget.Name}: ${res.ResponseStatus}`); } else { - wui_notif.info(`${http_target.Name}: ${res.ResponseStatus}`); + wuiNotif.info(`${httpTarget.Name}: ${res.ResponseStatus}`); } return res; } - async RunWebSocket(target, ws_target) { - Save(target, null, ws_target); + async runWebSocket(target, wsTarget) { + save(target, null, wsTarget); const req = { Target: { ID: target.ID, @@ -344,7 +344,7 @@ export class Trunks { WebSocketTargets: [], }, HttpTarget: null, - WebSocketTarget: ws_target, + WebSocketTarget: wsTarget, }; const fres = await fetch(API_TARGET_RUN_WEBSOCKET, { method: "POST", @@ -353,18 +353,18 @@ export class Trunks { }, body: JSON.stringify(req), }); - const json_res = await fres.json(); - if (json_res.code != 200) { - wui_notif.error(json_res.message); + const jsonRes = await fres.json(); + if (jsonRes.code != 200) { + wuiNotif.error(jsonRes.message); return null; } - wui_notif.info(`${ws_target.Name}: success.`); - return json_res; + wuiNotif.info(`${wsTarget.Name}: success.`); + return jsonRes; } - SetContent(path, el) { - this.el_content.innerHTML = ""; + setContent(path, el) { + this.elContent.innerHTML = ""; if (el) { - this.el_content.appendChild(el); + this.elContent.appendChild(el); } window.location.hash = "#/" + path; } |
