#!/bin/bash # Deploy blockchain explorer directly on ns3 server set -e echo "🔍 Deploying Blockchain Explorer on ns3" echo "======================================" # Colors GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' print_status() { echo -e "${GREEN}[INFO]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARN]${NC} $1" } # Check if we're on the right server if [ "$(hostname)" != "ns3" ] && [ "$(hostname)" != "aitbc" ]; then print_warning "This script should be run on ns3 server" exit 1 fi # Create directory print_status "Creating blockchain explorer directory..." mkdir -p /opt/blockchain-explorer cd /opt/blockchain-explorer # Create a simple HTML-based explorer (no build needed) print_status "Creating web-based explorer..." cat > index.html << 'EOF' AITBC Blockchain Explorer

AITBC Blockchain Explorer

Network: ait-devnet

Current Height

-

Latest Block

-

Node Status

-

Latest Blocks

Height Hash Timestamp Transactions Actions
Loading blocks...
EOF # Install a simple web server print_status "Installing web server..." apt-get install -y nginx # Configure nginx to serve the explorer print_status "Configuring nginx..." cat > /etc/nginx/sites-available/blockchain-explorer << EOL server { listen 3000; server_name _; root /opt/blockchain-explorer; index index.html; location / { try_files \$uri \$uri/ =404; } # CORS headers for API access location /rpc/ { proxy_pass http://localhost:8082; proxy_set_header Host \$host; proxy_set_header X-Real-IP \$remote_addr; proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; } } EOL # Enable the site ln -sf /etc/nginx/sites-available/blockchain-explorer /etc/nginx/sites-enabled/ rm -f /etc/nginx/sites-enabled/default # Test and reload nginx nginx -t systemctl reload nginx # Setup port forwarding if in container if [ "$(hostname)" = "aitbc" ]; then print_status "Setting up port forwarding..." iptables -t nat -A PREROUTING -p tcp --dport 3000 -j DNAT --to-destination 192.168.100.10:3000 iptables -t nat -A POSTROUTING -p tcp -d 192.168.100.10 --dport 3000 -j MASQUERADE iptables-save > /etc/iptables/rules.v4 fi print_status "Checking nginx status..." systemctl status nginx --no-pager | head -10 print_success "✅ Blockchain explorer deployed!" echo "" echo "Explorer URL: http://localhost:3000" if [ "$(hostname)" = "aitbc" ]; then echo "External URL: http://aitbc.keisanki.net:3000" else echo "External URL: http://aitbc.keisanki.net:3000" fi echo "" echo "The explorer is a static HTML site served by nginx."