relay: remove usage of secret placeholder

This commit is contained in:
Girish Ramakrishnan
2025-10-08 20:01:18 +02:00
parent 9226baa63c
commit 2ad8ed5550
2 changed files with 132 additions and 123 deletions
@@ -1,7 +1,7 @@
<script setup>
import { ref, useTemplateRef, computed } from 'vue';
import { Button, Dialog, FormGroup, SingleSelect, TextInput, NumberInput, Checkbox, PasswordInput } from '@cloudron/pankow';
import { Button, Dialog, FormGroup, SingleSelect, TextInput, NumberInput, Checkbox, MaskedInput } from '@cloudron/pankow';
import SettingsItem from './SettingsItem.vue';
import MailModel from '../models/MailModel.js';
@@ -63,6 +63,12 @@ function usesPasswordAuth(provider) {
|| provider === 'mailjet-smtp';
}
const form = useTemplateRef('form');
const isFormValid = ref(false);
function checkValidity() {
isFormValid.value = form.value.checkValidity();
}
function onProviderChange() {
// reset the form
host.value = '';
@@ -98,6 +104,8 @@ async function onShowDialog() {
serverApiToken.value = result.relay.serverApiToken;
dialog.value.open();
setTimeout(checkValidity, 100); // update state of the confirm button
}
async function onSubmit() {
@@ -110,7 +118,7 @@ async function onSubmit() {
if (usesExternalServer(data.provider)) {
data.username = username.value;
data.password = password.value;
if (password.value) data.password = password.value;
data.host = host.value;
data.port = parseInt(port.value);
data.acceptSelfSignedCerts = acceptSelfSignedCerts.value;
@@ -119,15 +127,15 @@ async function onSubmit() {
// fill in provider specific username/password usage
if (data.provider === 'postmark-smtp') {
data.username = serverApiToken.value;
data.password = serverApiToken.value;
if (serverApiToken.value) data.username = serverApiToken.value;
if (serverApiToken.value) data.password = serverApiToken.value;
data.forceFromAddress = true; // postmark requires the "From:" in mail to be a Sender Signature
} else if (data.provider === 'sendgrid-smtp') {
data.username = 'apikey';
data.password = serverApiToken.value;
if (serverApiToken.value) data.password = serverApiToken.value;
} else if (data.provider === 'sparkpost-smtp') {
data.username = 'SMTP_Injection';
data.password = serverApiToken.value;
if (serverApiToken.value) data.password = serverApiToken.value;
}
const [error] = await mailModel.setMailRelay(props.domain, data);
@@ -151,7 +159,7 @@ async function onSubmit() {
:confirm-label="$t('main.dialog.save')"
:confirm-busy="busy"
:reject-label="$t('main.dialog.cancel')"
:reject-active="!busy"
:reject-active="!busy && isFormValid"
reject-style="secondary"
@confirm="onSubmit()"
>
@@ -165,9 +173,9 @@ async function onSubmit() {
<div class="text-danger" v-if="formError">{{ formError }}</div>
<form @submit.prevent="onSubmit()" autocomplete="off" v-if="usesExternalServer(provider)">
<form ref="form" @submit.prevent="onSubmit()" autocomplete="off" v-if="usesExternalServer(provider)" @input="checkValidity()">
<fieldset :disabled="busy">
<input type="submit" style="display: none"/>
<input type="submit" style="display: none" :disabled="busy || !isFormValid"/>
<FormGroup>
<label for="hostInput">{{ $t('email.outbound.mailRelay.host') }}</label>
@@ -184,7 +192,7 @@ async function onSubmit() {
<!-- Postmark, Sendgrid, SparkPost -->
<FormGroup v-if="usesTokenAuth(provider)">
<label for="serverApiTokenInput">{{ $t('email.outbound.mailRelay.apiTokenOrKey') }}</label>
<TextInput id="serverApiTokenInput" v-model="serverApiToken" required />
<MaskedInput id="serverApiTokenInput" v-model="serverApiToken" required />
</FormGroup>
<!-- Other -->
@@ -195,7 +203,7 @@ async function onSubmit() {
<FormGroup v-if="usesPasswordAuth(provider)">
<label for="passwordInput">{{ $t('email.outbound.mailRelay.password') }}</label>
<TextInput id="passwordInput" v-model="password" required />
<MaskedInput id="passwordInput" v-model="password" required />
</FormGroup>
</fieldset>
</form>