Skip to content

Commit

Permalink
finished fixing up frontend bugs and most typescript rework that was …
Browse files Browse the repository at this point in the history
…started
  • Loading branch information
sadnub committed Mar 4, 2024
1 parent 70b7dfe commit 4d35f5a
Show file tree
Hide file tree
Showing 21 changed files with 755 additions and 1,089 deletions.
359 changes: 204 additions & 155 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions src/api/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ import type { AutomatedTask } from "@/types/tasks";

const baseUrl = "/core";

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 = {}) {
const { data } = await axios.get(`${baseUrl}/urlaction/`, {
params: params,
Expand Down Expand Up @@ -65,7 +76,6 @@ export async function runServerTask(id: number): Promise<ServerScriptResponse> {
}

export interface ServerScriptRunRequest {
id: number;
timeout: number;
env_vars: string[];
args: string[];
Expand All @@ -74,7 +84,7 @@ export interface ServerScriptRunRequest {
export async function runServerScript(
id: number,
payload: ServerScriptRunRequest,
): Promise<ServerScriptResponse> {
): Promise<string> {
const { data } = await axios.post(
`${baseUrl}/serverscript/${id}/run/`,
payload,
Expand Down
12 changes: 8 additions & 4 deletions src/components/agents/AutomatedTasksTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ export default {
try {
const result = await fetchAgentTasks(selectedAgent.value);
tasks.value = result.filter(
(task) => task.sync_status !== "pendingdeletion"
(task) => task.sync_status !== "pendingdeletion",
);
} catch (e) {
console.error(e);
Expand Down Expand Up @@ -495,7 +495,7 @@ export default {
try {
const result = await runTask(
task.id,
task.policy ? { agent_id: selectedAgent.value } : {}
task.policy ? { agent_id: selectedAgent.value } : {},
);
notifySuccess(result);
} catch (e) {
Expand All @@ -508,7 +508,9 @@ export default {
$q.dialog({
component: AutomatedTaskForm,
componentProps: {
parent: { agent: selectedAgent.value },
type: "agent",
parent: selectedAgent.value,
plat: agentPlatform.value,
},
}).onOk(() => {
getTasks();
Expand All @@ -522,7 +524,9 @@ export default {
component: AutomatedTaskForm,
componentProps: {
task: task,
parent: { agent: selectedAgent.value },
type: "agent",
parent: selectedAgent.value,
plat: agentPlatform.value,
},
}).onOk(() => {
getTasks();
Expand Down
6 changes: 4 additions & 2 deletions src/components/automation/PolicyAutomatedTasksTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ export default {
.dialog({
component: AutomatedTaskForm,
componentProps: {
parent: { policy: this.selectedPolicy },
parent: this.selectedPolicy,
type: "policy",
},
})
.onOk(this.getTasks);
Expand All @@ -304,7 +305,8 @@ export default {
component: AutomatedTaskForm,
componentProps: {
task: task,
parent: { policy: this.selectedPolicy },
parent: this.selectedPolicy,
type: "policy",
},
})
.onOk(this.getTasks);
Expand Down
3 changes: 2 additions & 1 deletion src/components/checks/ScriptCheck.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ export default {
defaultTimeout,
defaultArgs,
defaultEnvVars,
} = useScriptDropdown(props.check ? props.check.script : undefined, {
} = useScriptDropdown({
script: props.check ? props.check.script : undefined,
onMount: true,
});
Expand Down
167 changes: 63 additions & 104 deletions src/components/modals/agents/RunScript.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<tactical-dropdown
:rules="[(val) => !!val || '*Required']"
v-model="state.script"
:options="filteredScriptOptions"
:options="filterByPlatformOptions(agent.plat)"
label="Select script"
outlined
mapOptions
Expand Down Expand Up @@ -182,23 +182,23 @@
</q-dialog>
</template>

<script>
<script setup lang="ts">
// composition imports
import { ref, watch, computed } from "vue";
import { ref, watch } from "vue";
import { useDialogPluginComponent, openURL } from "quasar";
import { useScriptDropdown } from "@/composables/scripts";
import { useCustomFieldDropdown } from "@/composables/core";
import { runScript } from "@/api/agents";
import { notifySuccess } from "@/utils/notify";
import { envVarsLabel, runAsUserToolTip } from "@/constants/constants";
import {
formatScriptSyntax,
removeExtraOptionCategories,
} from "@/utils/format";
import { formatScriptSyntax } from "@/utils/format";
//ui imports
import TacticalDropdown from "@/components/ui/TacticalDropdown.vue";
// types
import type { Agent } from "@/types/Agent";
// static data
const outputOptions = [
{ label: "Wait for Output", value: "wait" },
Expand All @@ -208,110 +208,69 @@ const outputOptions = [
{ label: "Save results to Agent Notes", value: "note" },
];
export default {
name: "RunScript",
emits: [...useDialogPluginComponent.emits],
components: { TacticalDropdown },
props: {
agent: !Object,
script: Number,
},
setup(props) {
// setup quasar dialog plugin
const { dialogRef, onDialogHide } = useDialogPluginComponent();
// setup dropdowns
const {
script,
scriptOptions,
defaultTimeout,
defaultArgs,
defaultEnvVars,
syntax,
link,
} = useScriptDropdown(props.script, {
onMount: true,
filterByPlatform: props.agent.plat,
});
const { customFieldOptions } = useCustomFieldDropdown({ onMount: true });
// main run script functionaity
const state = ref({
output: "wait",
emails: [],
emailMode: "default",
custom_field: null,
save_all_output: false,
script,
args: defaultArgs,
env_vars: defaultEnvVars,
timeout: defaultTimeout,
run_as_user: false,
});
const ret = ref(null);
const loading = ref(false);
const maximized = ref(false);
// emits
defineEmits([...useDialogPluginComponent.emits]);
async function sendScript() {
ret.value = null;
loading.value = true;
// props
const props = defineProps<{
agent: Agent;
script?: number;
}>();
ret.value = await runScript(props.agent.agent_id, state.value);
loading.value = false;
if (state.value.output === "forget") {
onDialogHide();
notifySuccess(ret.value);
}
}
// setup quasar dialog plugin
const { dialogRef, onDialogHide } = useDialogPluginComponent();
function openScriptURL() {
link.value ? openURL(link.value) : null;
}
// setup dropdowns
const {
script,
filterByPlatformOptions,
defaultTimeout,
defaultArgs,
defaultEnvVars,
syntax,
link,
} = useScriptDropdown({
onMount: true,
});
const { customFieldOptions } = useCustomFieldDropdown({ onMount: true });
const filteredScriptOptions = computed(() => {
return removeExtraOptionCategories(
scriptOptions.value.filter(
(script) =>
script.category ||
!script.supported_platforms ||
script.supported_platforms.length === 0 ||
script.supported_platforms.includes(props.agent.plat)
)
);
});
// main run script functionaity
const state = ref({
output: "wait",
emails: [],
emailMode: "default",
custom_field: null,
save_all_output: false,
script,
args: defaultArgs,
env_vars: defaultEnvVars,
timeout: defaultTimeout,
run_as_user: false,
});
// watchers
watch(
[() => state.value.output, () => state.value.emailMode],
() => (state.value.emails = [])
);
const ret = ref(null);
const loading = ref(false);
const maximized = ref(false);
return {
// reactive data
state,
loading,
filteredScriptOptions,
link,
syntax,
ret,
maximized,
customFieldOptions,
async function sendScript() {
ret.value = null;
loading.value = true;
// non-reactive data
outputOptions,
runAsUserToolTip,
envVarsLabel,
ret.value = await runScript(props.agent.agent_id, state.value);
loading.value = false;
if (state.value.output === "forget") {
onDialogHide();
notifySuccess(ret.value);
}
}
//methods
formatScriptSyntax,
sendScript,
openScriptURL,
function openScriptURL() {
link.value ? openURL(link.value) : null;
}
// quasar dialog plugin
dialogRef,
onDialogHide,
};
},
};
// watchers
watch(
[() => state.value.output, () => state.value.emailMode],
() => (state.value.emails = []),
);
</script>
Loading

0 comments on commit 4d35f5a

Please sign in to comment.