copy smtp to new instance

This commit is contained in:
2025-06-20 14:09:49 +02:00
parent f825bab894
commit 3d4034d6b1
2 changed files with 200 additions and 4 deletions

View File

@@ -172,6 +172,18 @@ function initializeSteps() {
`;
stepsContainer.appendChild(credentialsStep);
// Add Copy SMTP Settings step
const smtpStep = document.createElement('div');
smtpStep.className = 'step-item';
smtpStep.innerHTML = `
<div class="step-icon"><i class="fas fa-envelope-open"></i></div>
<div class="step-content">
<h5>Copy SMTP Settings</h5>
<p class="step-status">Configuring email settings...</p>
</div>
`;
stepsContainer.appendChild(smtpStep);
// Add Send Completion Email step
const emailStep = document.createElement('div');
emailStep.className = 'step-item';
@@ -707,8 +719,78 @@ async function startLaunch(data) {
`;
credentialsStep.querySelector('.step-content').appendChild(credentialsDetails);
// Step 14: Send Completion Email
await updateStep(14, 'Send Completion Email', 'Sending notification to client...');
// Step 14: Copy SMTP Settings
await updateStep(14, 'Copy SMTP Settings', 'Configuring email settings...');
const smtpResult = await copySmtpSettings(`https://${data.webAddresses[0]}`);
if (!smtpResult.success) {
throw new Error(`SMTP settings copy failed: ${smtpResult.error}`);
}
// Update the SMTP step to show success
const smtpStep = document.querySelectorAll('.step-item')[13];
smtpStep.classList.remove('active');
smtpStep.classList.add('completed');
smtpStep.querySelector('.step-status').textContent = 'Successfully copied SMTP settings';
// Add SMTP details
const smtpDetails = document.createElement('div');
smtpDetails.className = 'mt-3';
smtpDetails.innerHTML = `
<div class="card">
<div class="card-body">
<h6 class="card-title mb-3">SMTP Settings Copied</h6>
<div class="table-responsive">
<table class="table table-sm">
<thead>
<tr>
<th>Property</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>SMTP Host</td>
<td>${smtpResult.data.smtp_host || 'Not set'}</td>
</tr>
<tr>
<td>SMTP Port</td>
<td>${smtpResult.data.smtp_port || 'Not set'}</td>
</tr>
<tr>
<td>Security</td>
<td><span class="badge bg-${smtpResult.data.smtp_security === 'ssl' ? 'success' : smtpResult.data.smtp_security === 'tls' ? 'warning' : 'secondary'}">${smtpResult.data.smtp_security || 'None'}</span></td>
</tr>
<tr>
<td>Username</td>
<td>${smtpResult.data.smtp_username || 'Not set'}</td>
</tr>
<tr>
<td>From Email</td>
<td>${smtpResult.data.smtp_from_email || 'Not set'}</td>
</tr>
<tr>
<td>From Name</td>
<td>${smtpResult.data.smtp_from_name || 'Not set'}</td>
</tr>
<tr>
<td>Status</td>
<td><span class="badge bg-success">Copied Successfully</span></td>
</tr>
</tbody>
</table>
</div>
<div class="alert alert-info mt-3">
<i class="fas fa-info-circle me-2"></i>
<strong>Email Configuration Complete!</strong> The launched instance now has the same SMTP settings as the master instance and can send emails independently.
</div>
</div>
</div>
`;
smtpStep.querySelector('.step-content').appendChild(smtpDetails);
// Step 15: Send Completion Email
await updateStep(15, 'Send Completion Email', 'Sending notification to client...');
const emailResult = await sendCompletionEmail(`https://${data.webAddresses[0]}`, data.company, credentialsResult.data);
if (!emailResult.success) {
@@ -716,7 +798,7 @@ async function startLaunch(data) {
}
// Update the email step to show success
const emailStep = document.querySelectorAll('.step-item')[13];
const emailStep = document.querySelectorAll('.step-item')[14];
emailStep.classList.remove('active');
emailStep.classList.add('completed');
emailStep.querySelector('.step-status').textContent = 'Successfully sent completion email';
@@ -901,7 +983,7 @@ Thank you for choosing DocuPulse!
} catch (error) {
console.error('Launch failed:', error);
await updateStep(14, 'Send Completion Email', `Error: ${error.message}`);
await updateStep(15, 'Send Completion Email', `Error: ${error.message}`);
showError(error.message);
}
}
@@ -2028,6 +2110,43 @@ async function updateAdminCredentials(instanceUrl, email) {
}
}
async function copySmtpSettings(instanceUrl) {
try {
console.log('Copying SMTP settings to:', instanceUrl);
const response = await fetch('/api/admin/copy-smtp-settings', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content
},
body: JSON.stringify({
instance_url: instanceUrl
})
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Failed to copy SMTP settings: ${errorText}`);
}
const result = await response.json();
console.log('SMTP settings copied successfully:', result);
return {
success: true,
message: result.message,
data: result.data
};
} catch (error) {
console.error('Error copying SMTP settings:', error);
return {
success: false,
error: error.message
};
}
}
async function sendCompletionEmail(instanceUrl, company, credentials) {
try {
console.log('Sending completion email to:', company.email);