check root permission with id -u also

This commit is contained in:
joshuaboud 2022-06-28 15:14:39 -03:00
parent 9fcffceab9
commit 75df808dad
No known key found for this signature in database
GPG Key ID: 17EFB59E2A8BF50E
2 changed files with 31 additions and 9 deletions

View File

@ -1,30 +1,47 @@
<template>
<ShieldExclamationIcon v-if="isRoot" class="size-icon icon-danger" />
<ShieldExclamationIcon v-if="showWarning" class="size-icon icon-danger" />
</template>
<script>
import { onUnmounted, ref } from 'vue';
import { ShieldExclamationIcon } from '@heroicons/vue/solid'
import { onUnmounted, ref, watch } from 'vue';
import { ShieldExclamationIcon } from '@heroicons/vue/solid';
import { useSpawn } from '@45drives/cockpit-helpers';
export default {
setup() {
props: {
host: String,
},
setup(props) {
const showWarning = ref(false);
const isRoot = ref(false);
const permission = cockpit.permission({ admin: true });
const updateIsRoot = () => {
isRoot.value = permission.allowed;
const updateShowWarning = () => {
showWarning.value = permission.allowed || isRoot.value;
}
permission.addEventListener('changed', updateIsRoot);
permission.addEventListener('changed', updateShowWarning);
onUnmounted(() => {
permission.removeEventListener('changed', updateIsRoot);
permission.removeEventListener('changed', updateShowWarning);
permission.close();
})
watch(() => props.host, async (host) => {
try {
const idStr = (await useSpawn(['id', '-u'], { superuser: 'try', host }).promise()).stdout;
isRoot.value = parseInt(idStr) === 0;
} catch (state) {
isRoot.value = false;
} finally {
updateShowWarning();
}
}, { immediate: true });
return {
isRoot,
showWarning,
}
},
components: {

View File

@ -239,6 +239,9 @@
/>
</IconToggle>
</Teleport>
<Teleport to="#footer-icons-left">
<RootDangerNotifier :host="pathHistory.current()?.host" />
</Teleport>
</template>
<script>
@ -274,6 +277,7 @@ import ContextMenu from '../components/ContextMenu.vue';
import ModalPrompt from '../components/ModalPrompt.vue';
import { commonPath } from '../functions/commonPath';
import { streamProcDownload } from '../functions/streamProcDownload';
import RootDangerNotifier from "../components/RootDangerNotifier.vue";
const encodePartial = (string) =>
encodeURIComponent(string)
@ -668,6 +672,7 @@ export default {
DownloadIcon,
FolderDownloadIcon,
ModalPrompt,
RootDangerNotifier,
},
}
</script>