2025-01-19 19:12:00 +01:00
|
|
|
<script setup>
|
|
|
|
|
|
|
|
|
|
import { ref, onMounted, computed } from 'vue';
|
|
|
|
|
import { Button, FormGroup, Checkbox, PasswordInput, TextInput } from 'pankow';
|
|
|
|
|
import { copyToClipboard } from 'pankow/utils';
|
2025-04-21 12:48:22 +02:00
|
|
|
import Section from '../components/Section.vue';
|
2025-01-19 19:12:00 +01:00
|
|
|
import DomainsModel from '../models/DomainsModel.js';
|
|
|
|
|
import DashboardModel from '../models/DashboardModel.js';
|
|
|
|
|
import UserDirectoryModel from '../models/UserDirectoryModel.js';
|
|
|
|
|
|
2025-01-31 21:02:48 +01:00
|
|
|
const domainsModel = DomainsModel.create();
|
|
|
|
|
const dashboardModel = DashboardModel.create();
|
|
|
|
|
const userDirectoryModel = UserDirectoryModel.create();
|
2025-01-19 19:12:00 +01:00
|
|
|
|
|
|
|
|
const adminDomain = ref({});
|
|
|
|
|
|
|
|
|
|
// form
|
|
|
|
|
const editError = ref({});
|
|
|
|
|
const busy = ref(false);
|
|
|
|
|
const enabled = ref(false);
|
|
|
|
|
const ldapUrl = ref('');
|
|
|
|
|
const secret = ref('');
|
|
|
|
|
const allowlist = ref('');
|
|
|
|
|
|
|
|
|
|
const isValid = computed(() => {
|
|
|
|
|
// TODO check all
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function onCopyToClipboard(value) {
|
|
|
|
|
copyToClipboard(value);
|
|
|
|
|
window.pankow.notify({ type: 'success', text: 'LDAP Url copied!' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function onSubmit() {
|
|
|
|
|
if (!isValid.value) return;
|
|
|
|
|
|
|
|
|
|
busy.value = true;
|
|
|
|
|
editError.value = {};
|
|
|
|
|
|
|
|
|
|
const [error] = await userDirectoryModel.setExposedLdapConfig({ enabled: enabled.value, allowlist: allowlist.value, secret: secret.value });
|
|
|
|
|
busy.value = false;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
if (error.status === 400) {
|
|
|
|
|
if (error.body.message.indexOf('secret') !== -1) editError.value.secret = error.body.message;
|
|
|
|
|
else editError.value.allowlist = error.body.message;
|
|
|
|
|
} else {
|
|
|
|
|
editError.value.generic = error.body ? error.body.message : 'Internal error';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
2025-01-27 22:20:26 +01:00
|
|
|
let [error, result] = await domainsModel.list();
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
const domains = result;
|
|
|
|
|
|
2025-03-12 13:41:07 +01:00
|
|
|
[error, result] = await dashboardModel.config();
|
2025-01-24 14:00:33 +01:00
|
|
|
if (error) return console.error(error);
|
2025-01-19 19:12:00 +01:00
|
|
|
|
2025-01-24 14:00:33 +01:00
|
|
|
ldapUrl.value = 'ldaps://' + result.adminFqdn + ':636';
|
|
|
|
|
adminDomain.value = domains.find(d => d.domain === result.adminDomain) || domains[0];
|
2025-01-19 19:12:00 +01:00
|
|
|
|
2025-01-24 14:00:33 +01:00
|
|
|
[error, result] = await userDirectoryModel.getExposedLdapConfig();
|
2025-01-19 19:12:00 +01:00
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
enabled.value = result.enabled;
|
|
|
|
|
secret.value = result.secret;
|
|
|
|
|
allowlist.value = result.allowlist;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-04-21 12:48:22 +02:00
|
|
|
<div class="content">
|
2025-01-19 19:12:00 +01:00
|
|
|
<Section :title="$t('users.exposedLdap.title')">
|
|
|
|
|
<p>{{ $t('users.exposedLdap.description') }}</p>
|
|
|
|
|
|
|
|
|
|
<form novalidate @submit.prevent="onSubmit()" autocomplete="off">
|
|
|
|
|
<fieldset :disabled="busy">
|
|
|
|
|
<input style="display: none" type="submit" :disabled="busy || !isValid" />
|
|
|
|
|
|
2025-02-16 15:59:07 +01:00
|
|
|
<Checkbox v-model="enabled" :label="$t('users.exposedLdap.enabled')" /><sup><a href="https://docs.cloudron.io/user-directory/#directory-server" class="help" target="_blank"><i class="fa fa-question-circle"></i></a></sup>
|
2025-01-19 19:12:00 +01:00
|
|
|
|
|
|
|
|
<FormGroup>
|
|
|
|
|
<label for="ldapUrlInput">{{ $t('users.exposedLdap.secret.url') }}</label>
|
|
|
|
|
<TextInput id="ldapUrlInput" v-model="ldapUrl" readonly @click="onCopyToClipboard(ldapUrl)" style="cursor: copy" />
|
|
|
|
|
<p class="text-small text-warning" v-show="adminDomain.provider === 'cloudflare'">{{ $t('users.exposedLdap.cloudflarePortWarning') }} </p>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
|
|
<FormGroup>
|
|
|
|
|
<label for="secretInput">{{ $t('users.exposedLdap.secret.label') }}</label>
|
|
|
|
|
<p class="small" v-html="$t('users.exposedLdap.secret.description', { userDN: 'cn=admin,ou=system,dc=cloudron' })"></p>
|
|
|
|
|
<PasswordInput id="secretInput" v-model="secret" />
|
|
|
|
|
<div class="has-error" v-show="editError.secret">{{ editError.secret }}</div>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
|
|
<FormGroup>
|
|
|
|
|
<label for="allowlistInput">{{ $t('users.exposedLdap.ipRestriction.label') }}</label>
|
|
|
|
|
<p class="small" v-html="$t('users.exposedLdap.ipRestriction.description')"></p>
|
|
|
|
|
<textarea id="allowlistInput" v-model="allowlist" :placeholder="$t('users.exposedLdap.ipRestriction.placeholder')" rows="4"></textarea>
|
|
|
|
|
<div class="has-error" v-show="editError.allowlist">{{ editError.allowlist }}</div>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
</fieldset>
|
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
<br/>
|
|
|
|
|
|
|
|
|
|
<p class="has-error" v-show="editError.generic">{{ editError.generic }}</p>
|
2025-03-03 11:34:45 +01:00
|
|
|
|
2025-03-07 10:28:49 +01:00
|
|
|
<div class="button-bar">
|
2025-03-03 11:34:45 +01:00
|
|
|
<Button :loading="busy" :disabled="!isValid || busy" @click="onSubmit()">{{ $t('users.settings.saveAction') }}</Button>
|
|
|
|
|
</div>
|
2025-01-19 19:12:00 +01:00
|
|
|
</Section>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|