224 lines
7.6 KiB
Python
224 lines
7.6 KiB
Python
import os
|
|
import sys
|
|
import requests
|
|
import json
|
|
import base64
|
|
|
|
def check_server_status():
|
|
print("=== Checking Server Status ===")
|
|
try:
|
|
response = requests.get("http://localhost:3015/health", timeout=5)
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
print("✅ Server is running")
|
|
print(f" Auth mode: {data.get('auth_mode', 'Unknown')}")
|
|
print(f" LLM Host: {data.get('configuration', {}).get('llm_binding_host')}")
|
|
return True
|
|
else:
|
|
print(f"❌ Server health check failed: {response.status_code}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ Server not accessible: {e}")
|
|
return False
|
|
|
|
def check_env_file():
|
|
print("\n=== Checking Environment Configuration ===")
|
|
|
|
env_path = "LightRAG-main/.env"
|
|
if os.path.exists(env_path):
|
|
print(f"✅ .env file exists at {env_path}")
|
|
with open(env_path, 'r') as f:
|
|
content = f.read()
|
|
if "AUTH_ACCOUNTS=jleu3482:jleu1212" in content:
|
|
print("✅ AUTH_ACCOUNTS configured correctly")
|
|
else:
|
|
print("❌ AUTH_ACCOUNTS not found or incorrect")
|
|
|
|
if "LIGHTRAG_API_KEY=jleu1212" in content:
|
|
print("✅ LIGHTRAG_API_KEY configured correctly")
|
|
else:
|
|
print("❌ LIGHTRAG_API_KEY not found or incorrect")
|
|
|
|
if "OPENAI_BASE_URL=https://api.deepseek.com/v1" in content:
|
|
print("✅ DeepSeek API URL configured correctly")
|
|
else:
|
|
print("❌ DeepSeek API URL not found or incorrect")
|
|
else:
|
|
print(f"❌ .env file not found at {env_path}")
|
|
return False
|
|
|
|
return True
|
|
|
|
def test_login_directly():
|
|
print("\n=== Testing Login Directly ===")
|
|
|
|
# Test 1: Direct login with form data
|
|
login_data = {
|
|
"username": "jleu3482",
|
|
"password": "jleu1212"
|
|
}
|
|
|
|
try:
|
|
response = requests.post(
|
|
"http://localhost:3015/login",
|
|
data=login_data,
|
|
timeout=10
|
|
)
|
|
|
|
print(f"Login response: {response.status_code}")
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
print("✅ Login successful!")
|
|
print(f" Token type: {data.get('token_type')}")
|
|
print(f" Auth mode: {data.get('auth_mode')}")
|
|
return True
|
|
else:
|
|
print(f"❌ Login failed: {response.status_code}")
|
|
print(f" Response: {response.text}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ Login error: {e}")
|
|
return False
|
|
|
|
def test_basic_auth():
|
|
print("\n=== Testing Basic Auth ===")
|
|
|
|
credentials = "jleu3482:jleu1212"
|
|
encoded_credentials = base64.b64encode(credentials.encode()).decode()
|
|
|
|
headers = {
|
|
'Authorization': f'Basic {encoded_credentials}'
|
|
}
|
|
|
|
try:
|
|
response = requests.get("http://localhost:3015/webui/", headers=headers, timeout=10)
|
|
print(f"Basic Auth response: {response.status_code}")
|
|
|
|
if response.status_code == 200:
|
|
print("✅ Basic Auth successful!")
|
|
return True
|
|
else:
|
|
print(f"❌ Basic Auth failed: {response.status_code}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ Basic Auth error: {e}")
|
|
return False
|
|
|
|
def test_auth_status():
|
|
print("\n=== Testing Auth Status Endpoint ===")
|
|
|
|
try:
|
|
response = requests.get("http://localhost:3015/auth-status", timeout=10)
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
print(f"Auth configured: {data.get('auth_configured')}")
|
|
print(f"Auth mode: {data.get('auth_mode')}")
|
|
print(f"Message: {data.get('message', 'No message')}")
|
|
return data.get('auth_configured', False)
|
|
else:
|
|
print(f"❌ Auth status failed: {response.status_code}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ Auth status error: {e}")
|
|
return False
|
|
|
|
def check_process_status():
|
|
print("\n=== Checking Process Status ===")
|
|
|
|
try:
|
|
# Check if any Python process is running LightRAG
|
|
import subprocess
|
|
result = subprocess.run(['tasklist', '/fi', 'imagename eq python.exe'],
|
|
capture_output=True, text=True, timeout=10)
|
|
|
|
if "python.exe" in result.stdout:
|
|
print("✅ Python processes are running")
|
|
# Check if LightRAG process is running
|
|
result2 = subprocess.run(['wmic', 'process', 'where', "name='python.exe'", 'get', 'commandline'],
|
|
capture_output=True, text=True, timeout=10)
|
|
if "lightrag" in result2.stdout.lower():
|
|
print("✅ LightRAG process is running")
|
|
return True
|
|
else:
|
|
print("⚠️ Python running but no LightRAG process found")
|
|
return False
|
|
else:
|
|
print("❌ No Python processes found")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ Process check error: {e}")
|
|
return False
|
|
|
|
def check_port_status():
|
|
print("\n=== Checking Port Status ===")
|
|
|
|
try:
|
|
import socket
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
result = sock.connect_ex(('localhost', 3015))
|
|
sock.close()
|
|
|
|
if result == 0:
|
|
print("✅ Port 3015 is open and listening")
|
|
return True
|
|
else:
|
|
print("❌ Port 3015 is not open")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ Port check error: {e}")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
print("LightRAG Authentication Diagnostic Tool")
|
|
print("=" * 50)
|
|
|
|
# Check if server is running
|
|
server_running = check_server_status()
|
|
|
|
if not server_running:
|
|
print("\n⚠️ Server is not running. Let me check why...")
|
|
check_process_status()
|
|
check_port_status()
|
|
print("\n💡 Solution: Start the server with: cd LightRAG-main && .\\zrun.bat")
|
|
exit(1)
|
|
|
|
# Check environment configuration
|
|
env_ok = check_env_file()
|
|
|
|
# Test authentication
|
|
auth_configured = test_auth_status()
|
|
|
|
# Test login
|
|
login_success = test_login_directly()
|
|
|
|
# Test basic auth
|
|
basic_auth_success = test_basic_auth()
|
|
|
|
print("\n" + "="*50)
|
|
print("DIAGNOSTIC SUMMARY")
|
|
print("="*50)
|
|
|
|
if login_success:
|
|
print("🎉 LOGIN IS WORKING!")
|
|
print("You can now use:")
|
|
print(" URL: http://localhost:3015/webui/")
|
|
print(" Username: jleu3482")
|
|
print(" Password: jleu1212")
|
|
else:
|
|
print("❌ LOGIN IS FAILING")
|
|
|
|
if not auth_configured:
|
|
print("\n🔍 Root Cause: Authentication is not configured on the server")
|
|
print("💡 Solution: Ensure AUTH_ACCOUNTS environment variable is set")
|
|
else:
|
|
print("\n🔍 Root Cause: Credentials mismatch or authentication issue")
|
|
print("💡 Possible Solutions:")
|
|
print(" 1. Check that credentials exactly match: jleu3482 / jleu1212")
|
|
print(" 2. Restart the server after updating .env file")
|
|
print(" 3. Check server logs for authentication errors")
|
|
|
|
print("\n📋 Next Steps:")
|
|
print(" 1. Stop the server: taskkill /f /im python.exe")
|
|
print(" 2. Start fresh: cd LightRAG-main && .\\zrun.bat")
|
|
print(" 3. Test again with this diagnostic tool") |