package api import ( "encoding/json" "net/http" "proxmox-router/internal/aerotun" ) func (s *Server) handleListAeroTUNTunnels(w http.ResponseWriter, r *http.Request) { tunnels := s.vpnMgr.AeroTUN.List() w.Header().Set("Content-Type", "application/json") _ = json.NewEncoder(w).Encode(tunnels) } func (s *Server) handleGetAeroTUNStats(w http.ResponseWriter, r *http.Request) { stats := s.vpnMgr.AeroTUN.GetSummaryStats() w.Header().Set("Content-Type", "application/json") _ = json.NewEncoder(w).Encode(stats) } func (s *Server) handleGenerateAeroTUNKey(w http.ResponseWriter, r *http.Request) { key, err := aerotun.GenerateSecureKey() if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json") _ = json.NewEncoder(w).Encode(map[string]string{"key": key}) } func (s *Server) handleSaveAeroTUNTunnel(w http.ResponseWriter, r *http.Request) { var inst aerotun.TunnelInstance if err := json.NewDecoder(r.Body).Decode(&inst); err != nil { http.Error(w, "invalid request body", http.StatusBadRequest) return } saved, err := s.vpnMgr.AeroTUN.Save(inst) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json") _ = json.NewEncoder(w).Encode(saved) } func (s *Server) handleDeleteAeroTUNTunnel(w http.ResponseWriter, r *http.Request) { id := r.PathValue("id") if id == "" { http.Error(w, "missing tunnel ID", http.StatusBadRequest) return } if err := s.vpnMgr.AeroTUN.Delete(id); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json") _ = json.NewEncoder(w).Encode(map[string]bool{"success": true}) } func (s *Server) handleSetAeroTUNTunnelState(w http.ResponseWriter, r *http.Request) { id := r.PathValue("id") if id == "" { http.Error(w, "missing tunnel ID", http.StatusBadRequest) return } var req struct { Disabled bool `json:"disabled"` } if err := json.NewDecoder(r.Body).Decode(&req); err != nil { http.Error(w, "invalid JSON", http.StatusBadRequest) return } if err := s.vpnMgr.AeroTUN.ToggleState(id, req.Disabled); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json") _ = json.NewEncoder(w).Encode(map[string]bool{"success": true}) } func (s *Server) handleStartAeroTUNTunnel(w http.ResponseWriter, r *http.Request) { id := r.PathValue("id") if id == "" { http.Error(w, "missing tunnel ID", http.StatusBadRequest) return } if err := s.vpnMgr.AeroTUN.StartTunnel(id); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json") _ = json.NewEncoder(w).Encode(map[string]bool{"success": true}) } func (s *Server) handleStopAeroTUNTunnel(w http.ResponseWriter, r *http.Request) { id := r.PathValue("id") if id == "" { http.Error(w, "missing tunnel ID", http.StatusBadRequest) return } if err := s.vpnMgr.AeroTUN.StopTunnel(id); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json") _ = json.NewEncoder(w).Encode(map[string]bool{"success": true}) }