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> <template>
<ShieldExclamationIcon v-if="isRoot" class="size-icon icon-danger" /> <ShieldExclamationIcon v-if="showWarning" class="size-icon icon-danger" />
</template> </template>
<script> <script>
import { onUnmounted, ref } from 'vue'; import { onUnmounted, ref, watch } from 'vue';
import { ShieldExclamationIcon } from '@heroicons/vue/solid' import { ShieldExclamationIcon } from '@heroicons/vue/solid';
import { useSpawn } from '@45drives/cockpit-helpers';
export default { export default {
setup() { props: {
host: String,
},
setup(props) {
const showWarning = ref(false);
const isRoot = ref(false); const isRoot = ref(false);
const permission = cockpit.permission({ admin: true }); const permission = cockpit.permission({ admin: true });
const updateIsRoot = () => { const updateShowWarning = () => {
isRoot.value = permission.allowed; showWarning.value = permission.allowed || isRoot.value;
} }
permission.addEventListener('changed', updateIsRoot); permission.addEventListener('changed', updateShowWarning);
onUnmounted(() => { onUnmounted(() => {
permission.removeEventListener('changed', updateIsRoot); permission.removeEventListener('changed', updateShowWarning);
permission.close(); 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 { return {
isRoot, showWarning,
} }
}, },
components: { components: {

View File

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