Skip to content

Commit 1ed3f71

Browse files
Fixes
1 parent 95c3cd8 commit 1ed3f71

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

app/directadmin_api.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def _make_request(self, endpoint, data=None, method='POST'):
2525
if data:
2626
print(f"Request data: {data}")
2727

28+
print(f"Starting HTTP request with 10 second timeout...")
29+
2830
# Common headers
2931
headers = {
3032
'User-Agent': 'DirectAdmin Email Forwarder'
@@ -50,6 +52,7 @@ def _make_request(self, endpoint, data=None, method='POST'):
5052
headers=headers
5153
)
5254

55+
print(f"HTTP request completed successfully!")
5356
print(f"Response status: {response.status_code}")
5457
print(f"Response headers: {dict(response.headers)}")
5558

@@ -157,8 +160,28 @@ def test_connection(self):
157160
print(f"Username: {self.username}")
158161
print(f"Domain: {self.domain}")
159162

160-
# Try CMD_API_SHOW_DOMAINS first
163+
# First try a simple HTTP request test
164+
print(f"Testing basic HTTP connectivity...")
165+
import requests
166+
test_url = f"{self.server}/CMD_API_SHOW_DOMAINS"
167+
168+
try:
169+
basic_response = requests.get(
170+
test_url,
171+
auth=(self.username, self.password),
172+
verify=False,
173+
timeout=5 # Shorter timeout for basic test
174+
)
175+
print(f"Basic HTTP test: status={basic_response.status_code}")
176+
if basic_response.status_code != 200:
177+
return False, f"HTTP request failed with status {basic_response.status_code}"
178+
except Exception as e:
179+
print(f"Basic HTTP test failed: {e}")
180+
return False, f"Basic connectivity test failed: {str(e)}"
181+
182+
# Try CMD_API_SHOW_DOMAINS with our parser
161183
endpoint = '/CMD_API_SHOW_DOMAINS'
184+
print(f"Making test request to: {self.server}{endpoint}")
162185
response = self._make_request(endpoint, method='GET')
163186

164187
if response is not None:

app/settings.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,28 +100,40 @@ def update_da_config():
100100
def test_connection():
101101
"""Test DirectAdmin connection"""
102102
try:
103+
print(f"\n=== Test Connection Request Received ===")
103104
data = request.get_json()
105+
print(f"Request data: {data}")
104106

105107
# Use provided or saved credentials
106108
server = data.get('da_server') or current_user.da_server
107109
username = data.get('da_username') or current_user.da_username
108110
password = data.get('da_password') or current_user.get_da_password()
111+
domain = data.get('da_domain') or current_user.da_domain
112+
113+
print(f"Test connection with server: {server}, username: {username}, domain: {domain}")
109114

110115
if not all([server, username, password]):
111-
return jsonify({'error': 'Missing credentials'}), 400
116+
print(f"Missing credentials - server: {bool(server)}, username: {bool(username)}, password: {bool(password)}")
117+
return jsonify({'error': 'Missing credentials', 'success': False}), 200
112118

113119
# Ensure proper URL format
114120
if not server.startswith(('http://', 'https://')):
115121
server = 'https://' + server
116122

117-
# Test connection
118-
api = DirectAdminAPI(server, username, password)
123+
# Test connection with domain if available
124+
print(f"Creating DirectAdminAPI instance...")
125+
api = DirectAdminAPI(server, username, password, domain)
126+
127+
print(f"Calling test_connection()...")
119128
success, message = api.test_connection()
129+
print(f"Test connection result: success={success}, message={message}")
120130

121-
return jsonify({
131+
result = {
122132
'success': success,
123133
'message': message
124-
})
134+
}
135+
print(f"Sending response: {result}")
136+
return jsonify(result)
125137

126138
except Exception as e:
127139
error_msg = str(e)

static/settings.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,10 @@ async function testConnection() {
286286
try {
287287
// Add timeout to prevent hanging
288288
const controller = new AbortController();
289-
const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 second timeout
289+
const timeoutId = setTimeout(() => {
290+
console.log('Connection test timeout reached, aborting...');
291+
controller.abort();
292+
}, 15000); // 15 second timeout for faster debugging
290293

291294
const response = await fetch('/settings/api/test-connection', {
292295
method: 'POST',

0 commit comments

Comments
 (0)