File size: 5,392 Bytes
7566eb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env python3
"""
Deployment Verification Script
Verifies that the ISUP 5.0 server is running correctly after deployment
"""

import requests
import socket
import time
import sys
from datetime import datetime

def check_web_interface(base_url="http://localhost:7860"):
    """Check if web interface is accessible"""
    print("🌐 Checking web interface...")
    
    try:
        # Health check
        response = requests.get(f"{base_url}/api/health", timeout=10)
        if response.status_code == 200:
            health = response.json()
            print(f"βœ… Health check: {health['status']}")
            print(f"βœ… ISUP server: {health['isup_server']}")
        else:
            print(f"❌ Health check failed: {response.status_code}")
            return False
        
        # Protocol info
        response = requests.get(f"{base_url}/api/protocol/info", timeout=5)
        if response.status_code == 200:
            protocol = response.json()
            print(f"βœ… Protocol: {protocol['protocol']} {protocol['version']}")
            print(f"βœ… Binary protocol: {protocol['binary_protocol']}")
        else:
            print(f"❌ Protocol info failed: {response.status_code}")
            return False
        
        # Dashboard
        response = requests.get(base_url, timeout=5)
        if response.status_code == 200:
            print("βœ… Dashboard accessible")
        else:
            print(f"❌ Dashboard failed: {response.status_code}")
            return False
        
        return True
        
    except requests.exceptions.ConnectionError:
        print("❌ Cannot connect to web interface")
        return False
    except Exception as e:
        print(f"❌ Web interface error: {e}")
        return False

def check_isup_port(host="localhost", port=7660):
    """Check if ISUP TCP port is open"""
    print(f"πŸ“‘ Checking ISUP port {host}:{port}...")
    
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(5)
        result = sock.connect_ex((host, port))
        sock.close()
        
        if result == 0:
            print(f"βœ… ISUP port {port} is open and accepting connections")
            return True
        else:
            print(f"❌ ISUP port {port} is not accessible")
            return False
            
    except Exception as e:
        print(f"❌ ISUP port check error: {e}")
        return False

def check_docker_deployment():
    """Check if running in Docker"""
    print("🐳 Checking Docker deployment...")
    
    try:
        # Check if we're in a container
        with open('/proc/1/cgroup', 'r') as f:
            content = f.read()
            if 'docker' in content or 'containerd' in content:
                print("βœ… Running in Docker container")
                return True
            else:
                print("ℹ️ Not running in Docker (local deployment)")
                return False
    except FileNotFoundError:
        print("ℹ️ Cannot determine if running in Docker")
        return False
    except Exception as e:
        print(f"⚠️ Docker check error: {e}")
        return False

def main():
    """Main verification function"""
    print("πŸ” ISUP 5.0 Deployment Verification")
    print("=" * 50)
    print(f"πŸ“… Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
    print()
    
    # Determine base URL
    base_url = "http://localhost:7860"
    if len(sys.argv) > 1:
        base_url = sys.argv[1]
        print(f"🌐 Using custom URL: {base_url}")
    
    # Check Docker deployment
    is_docker = check_docker_deployment()
    print()
    
    # Check web interface
    web_ok = check_web_interface(base_url)
    print()
    
    # Check ISUP port
    host = "localhost"
    if "hf.space" in base_url:
        # Extract hostname for HuggingFace Spaces
        host = base_url.replace("http://", "").replace("https://", "")
    
    isup_ok = check_isup_port(host, 7660)
    print()
    
    # Summary
    print("=" * 50)
    print("πŸ“‹ DEPLOYMENT VERIFICATION SUMMARY")
    print("=" * 50)
    
    if web_ok and isup_ok:
        print("πŸŽ‰ DEPLOYMENT SUCCESSFUL!")
        print("βœ… Web interface is accessible")
        print("βœ… ISUP 5.0 TCP server is running")
        print("βœ… Ready for device connections")
        print()
        print("πŸ”§ DEVICE CONFIGURATION:")
        print(f"   Server Address: {host}")
        print("   Port: 7660")
        print("   Protocol: ISUP 5.0")
        print("   Device ID: 255")
        print("   EHome Key: hikvision123")
        print()
        print(f"🌐 Dashboard: {base_url}")
        
        if "hf.space" in base_url:
            print("πŸš€ HuggingFace Spaces deployment detected")
            print("   Your server is publicly accessible!")
        
        return True
    else:
        print("❌ DEPLOYMENT ISSUES DETECTED")
        if not web_ok:
            print("❌ Web interface not accessible")
        if not isup_ok:
            print("❌ ISUP TCP port not accessible")
        print()
        print("πŸ”§ TROUBLESHOOTING:")
        print("1. Check if server is running")
        print("2. Verify port forwarding (7860, 7660)")
        print("3. Check firewall settings")
        print("4. Review server logs")
        
        return False

if __name__ == "__main__":
    success = main()
    sys.exit(0 if success else 1)