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