checking portainer connection
This commit is contained in:
@@ -193,7 +193,7 @@ function initializeSteps() {
|
||||
`;
|
||||
stepsContainer.appendChild(nginxStep);
|
||||
|
||||
// Add SSL Certificate generation step (now step 3)
|
||||
// Add SSL Certificate generation step
|
||||
const sslStep = document.createElement('div');
|
||||
sslStep.className = 'step-item';
|
||||
sslStep.innerHTML = `
|
||||
@@ -205,7 +205,7 @@ function initializeSteps() {
|
||||
`;
|
||||
stepsContainer.appendChild(sslStep);
|
||||
|
||||
// Add Proxy Host creation step (now step 4)
|
||||
// Add Proxy Host creation step
|
||||
const proxyStep = document.createElement('div');
|
||||
proxyStep.className = 'step-item';
|
||||
proxyStep.innerHTML = `
|
||||
@@ -216,6 +216,18 @@ function initializeSteps() {
|
||||
</div>
|
||||
`;
|
||||
stepsContainer.appendChild(proxyStep);
|
||||
|
||||
// Add Portainer connection check step (now last)
|
||||
const portainerStep = document.createElement('div');
|
||||
portainerStep.className = 'step-item';
|
||||
portainerStep.innerHTML = `
|
||||
<div class="step-icon"><i class="fab fa-docker"></i></div>
|
||||
<div class="step-content">
|
||||
<h5>Checking Portainer Connection</h5>
|
||||
<p class="step-status">Verifying connection to Portainer...</p>
|
||||
</div>
|
||||
`;
|
||||
stepsContainer.appendChild(portainerStep);
|
||||
}
|
||||
|
||||
async function startLaunch(data) {
|
||||
@@ -234,7 +246,7 @@ async function startLaunch(data) {
|
||||
}
|
||||
|
||||
// Update the step to show success
|
||||
const dnsStep = document.querySelector('.step-item');
|
||||
const dnsStep = document.querySelectorAll('.step-item')[0];
|
||||
dnsStep.classList.remove('active');
|
||||
dnsStep.classList.add('completed');
|
||||
|
||||
@@ -294,7 +306,7 @@ async function startLaunch(data) {
|
||||
nginxStep.classList.add('completed');
|
||||
nginxStep.querySelector('.step-status').textContent = 'Successfully connected to NGINX Proxy Manager';
|
||||
|
||||
// Step 3: Generate SSL Certificate (moved up)
|
||||
// Step 3: Generate SSL Certificate
|
||||
await updateStep(3, 'Generating SSL Certificate', 'Setting up secure HTTPS connection...');
|
||||
const sslResult = await generateSSLCertificate(data.webAddresses);
|
||||
|
||||
@@ -302,7 +314,7 @@ async function startLaunch(data) {
|
||||
throw new Error(sslResult.error || 'Failed to generate SSL certificate');
|
||||
}
|
||||
|
||||
// Step 4: Create Proxy Host (moved down)
|
||||
// Step 4: Create Proxy Host
|
||||
await updateStep(4, 'Creating Proxy Host', 'Setting up NGINX proxy host configuration...');
|
||||
const proxyResult = await createProxyHost(data.webAddresses, data.port, sslResult.data.certificate.id);
|
||||
|
||||
@@ -310,6 +322,20 @@ async function startLaunch(data) {
|
||||
throw new Error(proxyResult.error || 'Failed to create proxy host');
|
||||
}
|
||||
|
||||
// Step 5: Check Portainer connection
|
||||
await updateStep(5, 'Checking Portainer Connection', 'Verifying connection to Portainer...');
|
||||
const portainerResult = await checkPortainerConnection();
|
||||
|
||||
if (!portainerResult.success) {
|
||||
throw new Error(portainerResult.error || 'Failed to connect to Portainer');
|
||||
}
|
||||
|
||||
// Update the step to show success
|
||||
const portainerStep = document.querySelectorAll('.step-item')[4];
|
||||
portainerStep.classList.remove('active');
|
||||
portainerStep.classList.add('completed');
|
||||
portainerStep.querySelector('.step-status').textContent = 'Successfully connected to Portainer';
|
||||
|
||||
} catch (error) {
|
||||
showError(error.message);
|
||||
}
|
||||
@@ -391,6 +417,66 @@ async function checkNginxConnection() {
|
||||
}
|
||||
}
|
||||
|
||||
async function checkPortainerConnection() {
|
||||
try {
|
||||
// Get CSRF token from meta tag
|
||||
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
||||
|
||||
// Get Portainer settings from the template
|
||||
const portainerSettings = {
|
||||
url: '{{ portainer_settings.url if portainer_settings else "" }}',
|
||||
api_key: '{{ portainer_settings.api_key if portainer_settings else "" }}'
|
||||
};
|
||||
|
||||
// Debug log the raw template values
|
||||
console.log('Raw template values:', {
|
||||
url: '{{ portainer_settings.url if portainer_settings else "" }}',
|
||||
api_key: '{{ portainer_settings.api_key if portainer_settings else "" }}'
|
||||
});
|
||||
|
||||
// Debug log the settings (without API key)
|
||||
console.log('Portainer Settings:', {
|
||||
url: portainerSettings.url,
|
||||
hasApiKey: !!portainerSettings.api_key
|
||||
});
|
||||
|
||||
// Check if any required field is missing
|
||||
if (!portainerSettings.url || !portainerSettings.api_key) {
|
||||
console.error('Missing Portainer settings:', portainerSettings);
|
||||
return {
|
||||
success: false,
|
||||
error: 'Portainer settings are not configured. Please configure Portainer settings in the admin panel.'
|
||||
};
|
||||
}
|
||||
|
||||
const testResponse = await fetch('/api/admin/test-portainer-connection', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': csrfToken
|
||||
},
|
||||
body: JSON.stringify(portainerSettings)
|
||||
});
|
||||
|
||||
if (!testResponse.ok) {
|
||||
const error = await testResponse.json();
|
||||
console.error('Portainer connection error:', error);
|
||||
return {
|
||||
success: false,
|
||||
error: error.error || 'Failed to connect to Portainer'
|
||||
};
|
||||
}
|
||||
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error('Error checking Portainer connection:', error);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message || 'Error checking Portainer connection'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function updateStatus(step, message, type = 'info', details = '') {
|
||||
const statusElement = document.getElementById(`${step}Status`);
|
||||
const detailsElement = document.getElementById(`${step}Details`);
|
||||
@@ -508,7 +594,7 @@ async function createProxyHost(domains, port, sslCertificateId) {
|
||||
forward_host: '192.168.68.124',
|
||||
forward_port: parseInt(port),
|
||||
ssl_forced: true,
|
||||
caching_enabled: false,
|
||||
caching_enabled: true,
|
||||
block_exploits: true,
|
||||
allow_websocket_upgrade: true,
|
||||
http2_support: true,
|
||||
|
||||
Reference in New Issue
Block a user