mirror of
https://github.com/45Drives/cockpit-navigator.git
synced 2025-07-29 16:45:13 +02:00
check root permission with id -u
also
This commit is contained in:
parent
9fcffceab9
commit
75df808dad
@ -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: {
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user