add a favorite menu to agent's context menu for easy way to run scripts

This commit is contained in:
wh1te909
2020-12-14 11:28:00 +00:00
parent 3416a71ebd
commit aebe855078
4 changed files with 83 additions and 11 deletions

View File

@@ -115,11 +115,41 @@
<q-item-section>Send Command</q-item-section> <q-item-section>Send Command</q-item-section>
</q-item> </q-item>
<q-item clickable v-ripple v-close-popup @click="showRunScript = true"> <q-item clickable v-ripple>
<q-item-section side> <q-item-section side>
<q-icon size="xs" name="fas fa-terminal" /> <q-icon size="xs" name="fas fa-terminal" />
</q-item-section> </q-item-section>
<q-item-section>Run Script</q-item-section> <q-item-section>Run Script</q-item-section>
<q-item-section side>
<q-icon name="keyboard_arrow_right" />
</q-item-section>
<q-menu anchor="top end" self="top start">
<q-list dense style="min-width: 200px">
<q-item clickable v-ripple v-close-popup @click="showRunScript = true">
<q-item-section>Select Script</q-item-section>
</q-item>
<q-item clickable v-ripple @click="getFavoriteScripts">
<q-item-section>Favorites</q-item-section>
<q-item-section side>
<q-icon name="keyboard_arrow_right" />
</q-item-section>
<q-menu auto-close anchor="top end" self="top start">
<q-list>
<q-item
v-for="script in favoriteScripts"
:key="script.value"
dense
clickable
v-close-popup
@click="runFavScript(script.value, props.row.id)"
>
{{ script.label }}
</q-item>
</q-list>
</q-menu>
</q-item>
</q-list>
</q-menu>
</q-item> </q-item>
<q-item clickable v-close-popup @click.stop.prevent="remoteBG(props.row.id)"> <q-item clickable v-close-popup @click.stop.prevent="remoteBG(props.row.id)">
@@ -386,6 +416,7 @@ export default {
policyAddPk: null, policyAddPk: null,
showPendingActions: false, showPendingActions: false,
pendingActionAgentPk: null, pendingActionAgentPk: null,
favoriteScripts: [],
}; };
}, },
methods: { methods: {
@@ -451,6 +482,31 @@ export default {
this.showEditAgentModal = true; this.showEditAgentModal = true;
}, 500); }, 500);
}, },
runFavScript(scriptpk, agentpk) {
const data = {
pk: agentpk,
timeout: 900,
scriptPK: scriptpk,
output: "forget",
args: [],
};
this.$axios
.post("/agents/runscript/", data)
.then(r => this.notifySuccess(r.data))
.catch(e => this.notifyError(e.response.data));
},
getFavoriteScripts() {
this.$axios.get("/scripts/scripts/").then(r => {
if (r.data.filter(k => k.favorite === true).length === 0) {
this.notifyWarning("You don't have any scripts favorited!");
return;
}
this.favoriteScripts = r.data
.filter(k => k.favorite === true)
.map(script => ({ label: script.name, value: script.id }))
.sort((a, b) => a.label.localeCompare(b.label));
});
},
runPatchStatusScan(pk, hostname) { runPatchStatusScan(pk, hostname) {
axios.get(`/winupdate/${pk}/runupdatescan/`).then(r => { axios.get(`/winupdate/${pk}/runupdatescan/`).then(r => {
this.notifySuccess(`Scan will be run shortly on ${hostname}`); this.notifySuccess(`Scan will be run shortly on ${hostname}`);

View File

@@ -103,6 +103,7 @@
flat flat
class="q-ml-sm" class="q-ml-sm"
:label="showCommunityScripts ? 'Hide Community Scripts' : 'Show Community Scripts'" :label="showCommunityScripts ? 'Hide Community Scripts' : 'Show Community Scripts'"
:icon="showCommunityScripts ? 'visibility_off' : 'visibility'"
@click="setShowCommunityScripts(!showCommunityScripts)" @click="setShowCommunityScripts(!showCommunityScripts)"
/> />
<q-space /> <q-space />

View File

@@ -154,6 +154,7 @@
</template> </template>
<script> <script>
import { mapState } from "vuex";
import mixins from "@/mixins/mixins"; import mixins from "@/mixins/mixins";
export default { export default {
@@ -182,16 +183,23 @@ export default {
}; };
}, },
computed: { computed: {
...mapState(["showCommunityScripts"]),
sites() { sites() {
return !!this.client ? this.formatSiteOptions(this.client.sites) : []; return !!this.client ? this.formatSiteOptions(this.client.sites) : [];
}, },
}, },
methods: { methods: {
getScripts() { getScripts() {
let scripts;
this.$axios.get("/scripts/scripts/").then(r => { this.$axios.get("/scripts/scripts/").then(r => {
this.scriptOptions = r.data.map( if (this.showCommunityScripts) {
script => ({ label: script.name, value: script.id })).sort((a, b) => a.label.localeCompare(b.label) scripts = r.data;
); } else {
scripts = r.data.filter(i => i.script_type !== "builtin");
}
this.scriptOptions = scripts
.map(script => ({ label: script.name, value: script.id }))
.sort((a, b) => a.label.localeCompare(b.label));
}); });
}, },
send() { send() {
@@ -255,7 +263,7 @@ export default {
this.setTitles(); this.setTitles();
this.getClients(); this.getClients();
this.getAgents(); this.getAgents();
this.getScripts() this.getScripts();
this.selected_mode = this.mode; this.selected_mode = this.mode;
}, },

View File

@@ -66,7 +66,7 @@
<script> <script>
import mixins from "@/mixins/mixins"; import mixins from "@/mixins/mixins";
import { mapGetters } from "vuex"; import { mapGetters, mapState } from "vuex";
export default { export default {
name: "RunScript", name: "RunScript",
@@ -86,6 +86,7 @@ export default {
}; };
}, },
computed: { computed: {
...mapState(["showCommunityScripts"]),
hostname() { hostname() {
return this.$store.state.agentSummary.hostname; return this.$store.state.agentSummary.hostname;
}, },
@@ -95,10 +96,16 @@ export default {
}, },
methods: { methods: {
getScripts() { getScripts() {
let scripts;
this.$axios.get("/scripts/scripts/").then(r => { this.$axios.get("/scripts/scripts/").then(r => {
this.scriptOptions = r.data.map( if (this.showCommunityScripts) {
script => ({ label: script.name, value: script.id })).sort((a, b) => a.label.localeCompare(b.label) scripts = r.data;
); } else {
scripts = r.data.filter(i => i.script_type !== "builtin");
}
this.scriptOptions = scripts
.map(script => ({ label: script.name, value: script.id }))
.sort((a, b) => a.label.localeCompare(b.label));
}); });
}, },
send() { send() {
@@ -130,7 +137,7 @@ export default {
}, },
}, },
created() { created() {
this.getScripts() this.getScripts();
} },
}; };
</script> </script>