Skip to content

Commit

Permalink
Merge pull request #18 from sadnub/urlaction-rework
Browse files Browse the repository at this point in the history
Serverside cli, tasks, and scripts.  Plus REST URL Actions
  • Loading branch information
wh1te909 authored Jun 28, 2024
2 parents 1d14f5a + c420e06 commit a0c4062
Show file tree
Hide file tree
Showing 63 changed files with 4,500 additions and 2,610 deletions.
5 changes: 2 additions & 3 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ version: '3.7'
services:
app-dev:
container_name: trmm-app-dev
image: node:18-alpine
image: node:20-alpine
restart: always
command: /bin/sh -c "npm install --cache ~/.npm && npm run serve"
user: 1000:1000
command: /bin/sh -c "npm install --cache ~/.npm && npm i -g @quasar/cli && npm run serve"
working_dir: /workspace/web
volumes:
- ..:/workspace:cached
Expand Down
2,722 changes: 1,694 additions & 1,028 deletions package-lock.json

Large diffs are not rendered by default.

41 changes: 21 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,37 @@
},
"dependencies": {
"@quasar/extras": "1.16.11",
"apexcharts": "3.48.0",
"axios": "1.6.8",
"@vueuse/core": "10.11.0",
"@vueuse/integrations": "10.11.0",
"@vueuse/shared": "10.11.0",
"apexcharts": "3.49.2",
"axios": "1.7.2",
"dotenv": "16.4.5",
"pinia": "^2.1.7",
"qrcode.vue": "3.4.1",
"quasar": "2.15.3",
"vue": "3.4.23",
"vue3-apexcharts": "1.5.2",
"monaco-editor": "0.50.0",
"pinia": "2.1.7",
"qrcode": "1.5.3",
"quasar": "2.16.4",
"vue": "3.4.31",
"vue-router": "4.4.0",
"vue3-apexcharts": "1.5.3",
"vuedraggable": "4.1.0",
"vue-router": "4.3.2",
"@vueuse/core": "10.9.0",
"@vueuse/shared": "10.9.0",
"monaco-editor": "0.47.0",
"vuex": "4.1.0",
"xterm": "^5.3.0",
"xterm-addon-fit": "^0.8.0",
"yaml": "2.4.1"
"@xterm/xterm": "5.5.0",
"@xterm/addon-fit": "0.10.0",
"yaml": "2.4.5"
},
"devDependencies": {
"@quasar/cli": "2.4.0",
"@intlify/unplugin-vue-i18n": "4.0.0",
"@quasar/app-vite": "1.8.1",
"@types/node": "20.12.7",
"@typescript-eslint/eslint-plugin": "7.7.0",
"@typescript-eslint/parser": "7.7.0",
"@quasar/app-vite": "1.9.3",
"@quasar/cli": "2.4.1",
"@types/node": "20.14.9",
"@typescript-eslint/eslint-plugin": "7.14.1",
"@typescript-eslint/parser": "7.14.1",
"autoprefixer": "10.4.19",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-vue": "8.7.1",
"prettier": "3.2.5",
"typescript": "5.4.5"
"typescript": "5.5.2"
}
}
4 changes: 2 additions & 2 deletions quasar.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ module.exports = configure(function (/* ctx */) {
// app boot file (/src/boot)
// --> boot files are part of "main.js"
// https://v2.quasar.dev/quasar-cli-vite/boot-files
boot: ["axios", "monaco", "integrations"],
boot: ["pinia", "axios", "monaco", "integrations"],

// https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#css
css: ["app.sass"],

// https://github.com/quasarframework/quasar/tree/dev/extras
extras: [
"ionicons-v4",
"mdi-v5",
"mdi-v7",
"fontawesome-v6",
// 'eva-icons',
// 'themify',
Expand Down
10 changes: 5 additions & 5 deletions src/api/agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function openAgentWindow(agent_id) {

export function runRemoteBackground(agent_id, agentPlatform) {
const url = router.resolve(
`/remotebackground/${agent_id}?agentPlatform=${agentPlatform}`
`/remotebackground/${agent_id}?agentPlatform=${agentPlatform}`,
).href;
openURL(url, null, {
popup: true,
Expand Down Expand Up @@ -129,7 +129,7 @@ export async function refreshAgentWMI(agent_id) {
export async function runScript(agent_id, payload) {
const { data } = await axios.post(
`${baseUrl}/${agent_id}/runscript/`,
payload
payload,
);
return data;
}
Expand All @@ -153,7 +153,7 @@ export async function fetchAgentProcesses(agent_id, params = {}) {
export async function killAgentProcess(agent_id, pid, params = {}) {
const { data } = await axios.delete(
`${baseUrl}/${agent_id}/processes/${pid}/`,
{ params: params }
{ params: params },
);
return data;
}
Expand All @@ -162,7 +162,7 @@ export async function fetchAgentEventLog(agent_id, logType, days, params = {}) {
try {
const { data } = await axios.get(
`${baseUrl}/${agent_id}/eventlog/${logType}/${days}/`,
{ params: params }
{ params: params },
);
return data;
} catch (e) {
Expand Down Expand Up @@ -199,7 +199,7 @@ export async function agentShutdown(agent_id) {
export async function sendAgentRecoverMesh(agent_id, params = {}) {
const { data } = await axios.post(
`${baseUrl}/${agent_id}/meshcentral/recover/`,
{ params: params }
{ params: params },
);
return data;
}
Expand Down
13 changes: 13 additions & 0 deletions src/api/alerts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import axios from "axios";

import type { AlertTemplate } from "@/types/alerts";

export async function saveAlertTemplate(id: number, payload: AlertTemplate) {
const { data } = await axios.put(`alerts/templates/${id}/`, payload);
return data;
}

export async function addAlertTemplate(payload: AlertTemplate) {
const { data } = await axios.post("alerts/templates/", payload);
return data;
}
45 changes: 0 additions & 45 deletions src/api/core.js

This file was deleted.

97 changes: 97 additions & 0 deletions src/api/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import axios from "axios";
import { openURL } from "quasar";
import { router } from "@/router";

import type {
URLAction,
TestRunURLActionRequest,
TestRunURLActionResponse,
} from "@/types/core/urlactions";

const baseUrl = "/core";

export async function fetchDashboardInfo(params = {}) {
const { data } = await axios.get(`${baseUrl}/dashinfo/`, { params: params });
return data;
}

export async function fetchCustomFields(params = {}) {
try {
const { data } = await axios.get(`${baseUrl}/customfields/`, {
params: params,
});
return data;
} catch (e) {
console.error(e);
}
}

export async function fetchURLActions(params = {}): Promise<URLAction[]> {
const { data } = await axios.get(`${baseUrl}/urlaction/`, {
params: params,
});
return data;
}

export async function saveURLAction(action: URLAction) {
const { data } = await axios.post(`${baseUrl}/urlaction/`, action);
return data;
}

export async function editURLAction(id: number, action: URLAction) {
const { data } = await axios.put(`${baseUrl}/urlaction/${id}/`, action);
return data;
}

export async function removeURLAction(id: number) {
const { data } = await axios.delete(`${baseUrl}/urlaction/${id}/`);
return data;
}

interface RunURLActionRequest {
agent_id?: string;
client?: number;
site?: number;
action: number;
}

export async function runURLAction(payload: RunURLActionRequest) {
const { data } = await axios.patch(`${baseUrl}/urlaction/run/`, payload);
openURL(data);
}

export async function runTestURLAction(
payload: TestRunURLActionRequest,
): Promise<TestRunURLActionResponse> {
const { data } = await axios.post(`${baseUrl}/urlaction/run/test/`, payload);
return data;
}

export async function checkWebTermPerms(): Promise<{
message: string;
status: number;
}> {
const ret = await axios.post(`${baseUrl}/webtermperms/`);
return { message: ret.data, status: ret.status };
}

export function openWebTerminal(): void {
const url: string = router.resolve("/webterm").href;
openURL(url, undefined, {
popup: true,
scrollbars: false,
location: false,
status: false,
toolbar: false,
menubar: false,
width: 1280,
height: 720,
});
}

// TODO: Build out type for openai payload
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export async function generateScript(payload: any) {
const { data } = await axios.post(`${baseUrl}/openai/generate/`, payload);
return data;
}
7 changes: 6 additions & 1 deletion src/api/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export async function testScript(agent_id, payload) {
return data;
}

export async function testScriptOnServer(payload) {
const { data } = await axios.post("core/serverscript/test/", payload);
return data;
}

export async function saveScript(payload) {
const { data } = await axios.post(`${baseUrl}/`, payload);
return data;
Expand Down Expand Up @@ -56,7 +61,7 @@ export async function fetchScriptSnippet(id, params = {}) {
export async function editScriptSnippet(payload) {
const { data } = await axios.put(
`${baseUrl}/snippets/${payload.id}/`,
payload
payload,
);
return data;
}
Expand Down
16 changes: 6 additions & 10 deletions src/boot/axios.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from "axios";
import { useAuthStore } from "@/stores/auth";
import { Notify } from "quasar";

export const getBaseUrl = () => {
Expand All @@ -18,27 +19,22 @@ export function setErrorMessage(data, message) {
];
}

export default function ({ app, router, store }) {
export default function ({ app, router }) {
app.config.globalProperties.$axios = axios;

axios.interceptors.request.use(
function (config) {
const auth = useAuthStore();
config.baseURL = getBaseUrl();
const token = store.state.token;
const token = auth.token;
if (token != null) {
config.headers.Authorization = `Token ${token}`;
}
// config.transformResponse = [
// function (data) {
// console.log(data);
// return data;
// },
// ];
return config;
},
function (err) {
return Promise.reject(err);
}
},
);

axios.interceptors.response.use(
Expand Down Expand Up @@ -101,6 +97,6 @@ export default function ({ app, router, store }) {
}

return Promise.reject({ ...error });
}
},
);
}
11 changes: 11 additions & 0 deletions src/boot/pinia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { boot } from "quasar/wrappers";
import { createPinia } from "pinia";

export default boot(({ app }) => {
const pinia = createPinia();

app.use(pinia);

// You can add Pinia plugins here
// pinia.use(SomePiniaPlugin)
});
4 changes: 2 additions & 2 deletions src/components/AlertsManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export default {
},
{
name: "resolved_action_name",
label: "Resolve Action",
label: "Resolved Action",
field: "resolved_action_name",
align: "left",
},
Expand Down Expand Up @@ -326,7 +326,7 @@ export default {
this.refresh();
this.$q.loading.hide();
this.notifySuccess(
`Alert template ${template.name} was deleted!`
`Alert template ${template.name} was deleted!`,
);
})
.catch(() => {
Expand Down
Loading

0 comments on commit a0c4062

Please sign in to comment.