| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136 |
- package api
- import (
- "encoding/json"
- "net/http"
- "strings"
- "debtik/internal/dynamicrouting"
- )
- // Summary
- func (s *Server) handleDynamicRoutingSummary(w http.ResponseWriter, r *http.Request) {
- summary := s.dynRoutingMgr.GetSummary()
- writeJSON(w, http.StatusOK, summary)
- }
- // -------------------------------------------------------------
- // BGP Handlers
- // -------------------------------------------------------------
- func (s *Server) handleGetBGPInstance(w http.ResponseWriter, r *http.Request) {
- inst := s.dynRoutingMgr.GetBGPInstance()
- writeJSON(w, http.StatusOK, inst)
- }
- func (s *Server) handleUpdateBGPInstance(w http.ResponseWriter, r *http.Request) {
- var inst dynamicrouting.BGPInstance
- if err := json.NewDecoder(r.Body).Decode(&inst); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- if err := s.dynRoutingMgr.UpdateBGPInstance(inst); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, s.dynRoutingMgr.GetBGPInstance())
- }
- func (s *Server) handleListBGPPeers(w http.ResponseWriter, r *http.Request) {
- peers := s.dynRoutingMgr.ListBGPPeers()
- if peers == nil {
- peers = []dynamicrouting.BGPPeer{}
- }
- writeJSON(w, http.StatusOK, peers)
- }
- func (s *Server) handleSaveBGPPeer(w http.ResponseWriter, r *http.Request) {
- var peer dynamicrouting.BGPPeer
- if err := json.NewDecoder(r.Body).Decode(&peer); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- if peer.RemoteAddress == "" || peer.RemoteAS == 0 {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "remote_address and remote_as are required"})
- return
- }
- if err := s.dynRoutingMgr.SaveBGPPeer(&peer); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "peer": peer})
- }
- func (s *Server) handleDeleteBGPPeer(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing peer id"})
- return
- }
- if err := s.dynRoutingMgr.DeleteBGPPeer(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleSetBGPPeerState(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- var req struct {
- Disabled bool `json:"disabled"`
- }
- if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON"})
- return
- }
- if err := s.dynRoutingMgr.SetBGPPeerState(id, req.Disabled); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "disabled": req.Disabled})
- }
- func (s *Server) handleListBGPNetworks(w http.ResponseWriter, r *http.Request) {
- nets := s.dynRoutingMgr.ListBGPNetworks()
- if nets == nil {
- nets = []dynamicrouting.BGPNetwork{}
- }
- writeJSON(w, http.StatusOK, nets)
- }
- func (s *Server) handleSaveBGPNetwork(w http.ResponseWriter, r *http.Request) {
- var net dynamicrouting.BGPNetwork
- if err := json.NewDecoder(r.Body).Decode(&net); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- if net.Network == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "network (CIDR) is required"})
- return
- }
- if err := s.dynRoutingMgr.SaveBGPNetwork(net); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "network": net})
- }
- func (s *Server) handleDeleteBGPNetwork(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing network id"})
- return
- }
- if err := s.dynRoutingMgr.DeleteBGPNetwork(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleGetBGPRoutes(w http.ResponseWriter, r *http.Request) {
- routes := s.dynRoutingMgr.GetBGPRoutes()
- if routes == nil {
- routes = []dynamicrouting.BGPRoute{}
- }
- writeJSON(w, http.StatusOK, routes)
- }
- // -------------------------------------------------------------
- // OSPF Handlers (RouterOS v7 Style OSPF)
- // -------------------------------------------------------------
- func (s *Server) handleListOSPFInstances(w http.ResponseWriter, r *http.Request) {
- insts := s.dynRoutingMgr.ListOSPFInstances()
- if insts == nil {
- insts = []dynamicrouting.OSPFInstance{}
- }
- writeJSON(w, http.StatusOK, insts)
- }
- func (s *Server) handleSaveOSPFInstance(w http.ResponseWriter, r *http.Request) {
- var inst dynamicrouting.OSPFInstance
- if err := json.NewDecoder(r.Body).Decode(&inst); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- if err := s.dynRoutingMgr.SaveOSPFInstance(&inst); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "instance": inst})
- }
- func (s *Server) handleDeleteOSPFInstance(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing instance id"})
- return
- }
- if err := s.dynRoutingMgr.DeleteOSPFInstance(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleSetOSPFInstanceState(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- var req struct {
- Disabled bool `json:"disabled"`
- }
- if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON"})
- return
- }
- if err := s.dynRoutingMgr.SetOSPFInstanceState(id, req.Disabled); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "disabled": req.Disabled})
- }
- func (s *Server) handleGetOSPFInstance(w http.ResponseWriter, r *http.Request) {
- inst := s.dynRoutingMgr.GetOSPFInstance()
- writeJSON(w, http.StatusOK, inst)
- }
- func (s *Server) handleUpdateOSPFInstance(w http.ResponseWriter, r *http.Request) {
- var inst dynamicrouting.OSPFInstance
- if err := json.NewDecoder(r.Body).Decode(&inst); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- if err := s.dynRoutingMgr.UpdateOSPFInstance(inst); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, s.dynRoutingMgr.GetOSPFInstance())
- }
- func (s *Server) handleListOSPFAreas(w http.ResponseWriter, r *http.Request) {
- areas := s.dynRoutingMgr.ListOSPFAreas()
- if areas == nil {
- areas = []dynamicrouting.OSPFArea{}
- }
- writeJSON(w, http.StatusOK, areas)
- }
- func (s *Server) handleSaveOSPFArea(w http.ResponseWriter, r *http.Request) {
- var area dynamicrouting.OSPFArea
- if err := json.NewDecoder(r.Body).Decode(&area); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- if area.AreaID == "" {
- area.AreaID = "0.0.0.0"
- }
- if err := s.dynRoutingMgr.SaveOSPFArea(area); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "area": area})
- }
- func (s *Server) handleDeleteOSPFArea(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing area id"})
- return
- }
- if err := s.dynRoutingMgr.DeleteOSPFArea(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleSetOSPFAreaState(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- var req struct {
- Disabled bool `json:"disabled"`
- }
- if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON"})
- return
- }
- if err := s.dynRoutingMgr.SetOSPFAreaState(id, req.Disabled); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "disabled": req.Disabled})
- }
- // Area Ranges
- func (s *Server) handleListOSPFAreaRanges(w http.ResponseWriter, r *http.Request) {
- ranges := s.dynRoutingMgr.ListOSPFAreaRanges()
- if ranges == nil {
- ranges = []dynamicrouting.OSPFAreaRange{}
- }
- writeJSON(w, http.StatusOK, ranges)
- }
- func (s *Server) handleSaveOSPFAreaRange(w http.ResponseWriter, r *http.Request) {
- var ar dynamicrouting.OSPFAreaRange
- if err := json.NewDecoder(r.Body).Decode(&ar); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- if ar.Prefix == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Prefix is required"})
- return
- }
- if err := s.dynRoutingMgr.SaveOSPFAreaRange(ar); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "area_range": ar})
- }
- func (s *Server) handleDeleteOSPFAreaRange(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing range id"})
- return
- }
- if err := s.dynRoutingMgr.DeleteOSPFAreaRange(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- // Interface Templates
- func (s *Server) handleListOSPFInterfaces(w http.ResponseWriter, r *http.Request) {
- ifaces := s.dynRoutingMgr.ListOSPFInterfaces()
- if ifaces == nil {
- ifaces = []dynamicrouting.OSPFInterface{}
- }
- writeJSON(w, http.StatusOK, ifaces)
- }
- func (s *Server) handleSaveOSPFInterface(w http.ResponseWriter, r *http.Request) {
- var iface dynamicrouting.OSPFInterface
- if err := json.NewDecoder(r.Body).Decode(&iface); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- if err := s.dynRoutingMgr.SaveOSPFInterface(iface); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "interface": iface})
- }
- func (s *Server) handleDeleteOSPFInterface(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing interface id"})
- return
- }
- if err := s.dynRoutingMgr.DeleteOSPFInterface(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleSetOSPFInterfaceState(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- var req struct {
- Disabled bool `json:"disabled"`
- }
- if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON"})
- return
- }
- if err := s.dynRoutingMgr.SetOSPFInterfaceState(id, req.Disabled); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "disabled": req.Disabled})
- }
- // Live Dynamic Interfaces
- func (s *Server) handleGetOSPFInterfacesLive(w http.ResponseWriter, r *http.Request) {
- live := s.dynRoutingMgr.GetOSPFInterfacesLive()
- if live == nil {
- live = []dynamicrouting.OSPFInterfaceLive{}
- }
- writeJSON(w, http.StatusOK, live)
- }
- // Static Neighbors
- func (s *Server) handleListOSPFStaticNeighbors(w http.ResponseWriter, r *http.Request) {
- nbrs := s.dynRoutingMgr.ListOSPFStaticNeighbors()
- if nbrs == nil {
- nbrs = []dynamicrouting.OSPFStaticNeighbor{}
- }
- writeJSON(w, http.StatusOK, nbrs)
- }
- func (s *Server) handleSaveOSPFStaticNeighbor(w http.ResponseWriter, r *http.Request) {
- var nbr dynamicrouting.OSPFStaticNeighbor
- if err := json.NewDecoder(r.Body).Decode(&nbr); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- if nbr.Address == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Address is required"})
- return
- }
- if err := s.dynRoutingMgr.SaveOSPFStaticNeighbor(nbr); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "neighbor": nbr})
- }
- func (s *Server) handleDeleteOSPFStaticNeighbor(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing static neighbor id"})
- return
- }
- if err := s.dynRoutingMgr.DeleteOSPFStaticNeighbor(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleSetOSPFStaticNeighborState(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing static neighbor id"})
- return
- }
- var req struct {
- Disabled bool `json:"disabled"`
- }
- if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- if err := s.dynRoutingMgr.SetOSPFStaticNeighborState(id, req.Disabled); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "disabled": req.Disabled})
- }
- // Live Neighbors
- func (s *Server) handleGetOSPFNeighbors(w http.ResponseWriter, r *http.Request) {
- nbrs := s.dynRoutingMgr.GetOSPFNeighbors()
- if nbrs == nil {
- nbrs = []dynamicrouting.OSPFNeighbor{}
- }
- writeJSON(w, http.StatusOK, nbrs)
- }
- // Live LSA Database
- func (s *Server) handleGetOSPFLSA(w http.ResponseWriter, r *http.Request) {
- lsa := s.dynRoutingMgr.GetOSPFLSA()
- if lsa == nil {
- lsa = []dynamicrouting.OSPFLSA{}
- }
- writeJSON(w, http.StatusOK, lsa)
- }
- func (s *Server) handleGetOSPFRoutes(w http.ResponseWriter, r *http.Request) {
- routes := s.dynRoutingMgr.GetOSPFRoutes()
- if routes == nil {
- routes = []dynamicrouting.OSPFRoute{}
- }
- writeJSON(w, http.StatusOK, routes)
- }
- // -------------------------------------------------------------
- // Routing Filters Handlers (/routing filter)
- // -------------------------------------------------------------
- func (s *Server) handleListRoutingFilters(w http.ResponseWriter, r *http.Request) {
- filters := s.dynRoutingMgr.ListRoutingFilters()
- if filters == nil {
- filters = []dynamicrouting.RoutingFilterRule{}
- }
- writeJSON(w, http.StatusOK, filters)
- }
- func (s *Server) handleSaveRoutingFilter(w http.ResponseWriter, r *http.Request) {
- var rule dynamicrouting.RoutingFilterRule
- if err := json.NewDecoder(r.Body).Decode(&rule); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- if rule.Chain == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Chain name is required"})
- return
- }
- if rule.Action == "" && rule.Rule == "" {
- rule.Action = "accept"
- }
- if err := s.dynRoutingMgr.SaveRoutingFilter(&rule); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "success", "id": rule.ID})
- }
- func (s *Server) handleDeleteRoutingFilter(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing filter rule ID"})
- return
- }
- if err := s.dynRoutingMgr.DeleteRoutingFilter(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleSetRoutingFilterState(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing filter rule ID"})
- return
- }
- var req struct {
- Disabled bool `json:"disabled"`
- }
- if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON"})
- return
- }
- if err := s.dynRoutingMgr.SetRoutingFilterState(id, req.Disabled); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "disabled": req.Disabled})
- }
- // -------------------------------------------------------------
- // Community Lists Handlers (/routing filter community-list)
- // -------------------------------------------------------------
- func (s *Server) handleListCommunityLists(w http.ResponseWriter, r *http.Request) {
- lists := s.dynRoutingMgr.ListCommunityLists()
- if lists == nil {
- lists = []dynamicrouting.RoutingFilterCommunityList{}
- }
- writeJSON(w, http.StatusOK, lists)
- }
- func (s *Server) handleSaveCommunityList(w http.ResponseWriter, r *http.Request) {
- var cl dynamicrouting.RoutingFilterCommunityList
- if err := json.NewDecoder(r.Body).Decode(&cl); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- if strings.TrimSpace(cl.Name) == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "List name is required"})
- return
- }
- if err := s.dynRoutingMgr.SaveCommunityList(&cl); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "success", "id": cl.ID})
- }
- func (s *Server) handleDeleteCommunityList(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing community list ID"})
- return
- }
- if err := s.dynRoutingMgr.DeleteCommunityList(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleSetCommunityListState(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing community list ID"})
- return
- }
- var req struct {
- Disabled bool `json:"disabled"`
- }
- if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON"})
- return
- }
- if err := s.dynRoutingMgr.SetCommunityListState(id, req.Disabled); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "disabled": req.Disabled})
- }
- // -------------------------------------------------------------
- // AS Lists Handlers (/routing filter num-list)
- // -------------------------------------------------------------
- func (s *Server) handleListASLists(w http.ResponseWriter, r *http.Request) {
- lists := s.dynRoutingMgr.ListASLists()
- if lists == nil {
- lists = []dynamicrouting.RoutingFilterASList{}
- }
- writeJSON(w, http.StatusOK, lists)
- }
- func (s *Server) handleSaveASList(w http.ResponseWriter, r *http.Request) {
- var al dynamicrouting.RoutingFilterASList
- if err := json.NewDecoder(r.Body).Decode(&al); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- if strings.TrimSpace(al.Name) == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "List name is required"})
- return
- }
- if err := s.dynRoutingMgr.SaveASList(&al); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "success", "id": al.ID})
- }
- func (s *Server) handleDeleteASList(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing AS list ID"})
- return
- }
- if err := s.dynRoutingMgr.DeleteASList(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleSetASListState(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing AS list ID"})
- return
- }
- var req struct {
- Disabled bool `json:"disabled"`
- }
- if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON"})
- return
- }
- if err := s.dynRoutingMgr.SetASListState(id, req.Disabled); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "disabled": req.Disabled})
- }
- // -------------------------------------------------------------
- // RIP Handlers (/api/routing/rip/*)
- // -------------------------------------------------------------
- func (s *Server) handleListRIPInstances(w http.ResponseWriter, r *http.Request) {
- insts := s.dynRoutingMgr.ListRIPInstances()
- if insts == nil {
- insts = []dynamicrouting.RIPInstance{}
- }
- writeJSON(w, http.StatusOK, insts)
- }
- func (s *Server) handleSaveRIPInstance(w http.ResponseWriter, r *http.Request) {
- var inst dynamicrouting.RIPInstance
- if err := json.NewDecoder(r.Body).Decode(&inst); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- res, err := s.dynRoutingMgr.SaveRIPInstance(inst)
- if err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, res)
- }
- func (s *Server) handleDeleteRIPInstance(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing instance ID"})
- return
- }
- if err := s.dynRoutingMgr.DeleteRIPInstance(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleSetRIPInstanceState(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- var req struct {
- Disabled bool `json:"disabled"`
- }
- if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON"})
- return
- }
- if err := s.dynRoutingMgr.SetRIPInstanceState(id, req.Disabled); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "disabled": req.Disabled})
- }
- func (s *Server) handleListRIPInterfaces(w http.ResponseWriter, r *http.Request) {
- ifaces := s.dynRoutingMgr.ListRIPInterfaces()
- if ifaces == nil {
- ifaces = []dynamicrouting.RIPInterface{}
- }
- writeJSON(w, http.StatusOK, ifaces)
- }
- func (s *Server) handleSaveRIPInterface(w http.ResponseWriter, r *http.Request) {
- var iface dynamicrouting.RIPInterface
- if err := json.NewDecoder(r.Body).Decode(&iface); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- res, err := s.dynRoutingMgr.SaveRIPInterface(iface)
- if err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, res)
- }
- func (s *Server) handleDeleteRIPInterface(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing interface ID"})
- return
- }
- if err := s.dynRoutingMgr.DeleteRIPInterface(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleSetRIPInterfaceState(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- var req struct {
- Disabled bool `json:"disabled"`
- }
- if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON"})
- return
- }
- if err := s.dynRoutingMgr.SetRIPInterfaceState(id, req.Disabled); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "disabled": req.Disabled})
- }
- func (s *Server) handleListRIPNeighbors(w http.ResponseWriter, r *http.Request) {
- nbrs := s.dynRoutingMgr.ListRIPNeighbors()
- if nbrs == nil {
- nbrs = []dynamicrouting.RIPNeighbor{}
- }
- writeJSON(w, http.StatusOK, nbrs)
- }
- func (s *Server) handleSaveRIPNeighbor(w http.ResponseWriter, r *http.Request) {
- var nbr dynamicrouting.RIPNeighbor
- if err := json.NewDecoder(r.Body).Decode(&nbr); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- res, err := s.dynRoutingMgr.SaveRIPNeighbor(nbr)
- if err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, res)
- }
- func (s *Server) handleDeleteRIPNeighbor(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing neighbor ID"})
- return
- }
- if err := s.dynRoutingMgr.DeleteRIPNeighbor(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleGetRIPNeighborsLive(w http.ResponseWriter, r *http.Request) {
- nbrs := s.dynRoutingMgr.GetRIPNeighbors()
- if nbrs == nil {
- nbrs = []dynamicrouting.RIPNeighborLive{}
- }
- writeJSON(w, http.StatusOK, nbrs)
- }
- func (s *Server) handleGetRIPRoutes(w http.ResponseWriter, r *http.Request) {
- rts := s.dynRoutingMgr.GetRIPRoutes()
- if rts == nil {
- rts = []dynamicrouting.RIPRoute{}
- }
- writeJSON(w, http.StatusOK, rts)
- }
- // -------------------------------------------------------------
- // BFD Handlers (/api/routing/bfd/*)
- // -------------------------------------------------------------
- func (s *Server) handleGetBFDInstance(w http.ResponseWriter, r *http.Request) {
- inst := s.dynRoutingMgr.GetBFDInstance()
- writeJSON(w, http.StatusOK, inst)
- }
- func (s *Server) handleSaveBFDInstance(w http.ResponseWriter, r *http.Request) {
- var inst dynamicrouting.BFDInstance
- if err := json.NewDecoder(r.Body).Decode(&inst); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- if err := s.dynRoutingMgr.SaveBFDInstance(inst); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, s.dynRoutingMgr.GetBFDInstance())
- }
- func (s *Server) handleListBFDInterfaces(w http.ResponseWriter, r *http.Request) {
- ifaces := s.dynRoutingMgr.ListBFDInterfaces()
- if ifaces == nil {
- ifaces = []dynamicrouting.BFDInterface{}
- }
- writeJSON(w, http.StatusOK, ifaces)
- }
- func (s *Server) handleSaveBFDInterface(w http.ResponseWriter, r *http.Request) {
- var iface dynamicrouting.BFDInterface
- if err := json.NewDecoder(r.Body).Decode(&iface); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- res, err := s.dynRoutingMgr.SaveBFDInterface(iface)
- if err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, res)
- }
- func (s *Server) handleDeleteBFDInterface(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing interface ID"})
- return
- }
- if err := s.dynRoutingMgr.DeleteBFDInterface(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleSetBFDInterfaceState(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- var req struct {
- Disabled bool `json:"disabled"`
- }
- if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON"})
- return
- }
- if err := s.dynRoutingMgr.SetBFDInterfaceState(id, req.Disabled); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "disabled": req.Disabled})
- }
- func (s *Server) handleListBFDNeighbors(w http.ResponseWriter, r *http.Request) {
- nbrs := s.dynRoutingMgr.ListBFDNeighbors()
- if nbrs == nil {
- nbrs = []dynamicrouting.BFDNeighbor{}
- }
- writeJSON(w, http.StatusOK, nbrs)
- }
- func (s *Server) handleSaveBFDNeighbor(w http.ResponseWriter, r *http.Request) {
- var nbr dynamicrouting.BFDNeighbor
- if err := json.NewDecoder(r.Body).Decode(&nbr); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- res, err := s.dynRoutingMgr.SaveBFDNeighbor(nbr)
- if err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, res)
- }
- func (s *Server) handleDeleteBFDNeighbor(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing neighbor ID"})
- return
- }
- if err := s.dynRoutingMgr.DeleteBFDNeighbor(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleGetBFDSessions(w http.ResponseWriter, r *http.Request) {
- sessions := s.dynRoutingMgr.GetBFDSessions()
- if sessions == nil {
- sessions = []dynamicrouting.BFDSession{}
- }
- writeJSON(w, http.StatusOK, sessions)
- }
- // -------------------------------------------------------------
- // Babel Handlers (/api/routing/babel/*)
- // -------------------------------------------------------------
- func (s *Server) handleListBabelInstances(w http.ResponseWriter, r *http.Request) {
- insts := s.dynRoutingMgr.ListBabelInstances()
- if insts == nil {
- insts = []dynamicrouting.BabelInstance{}
- }
- writeJSON(w, http.StatusOK, insts)
- }
- func (s *Server) handleSaveBabelInstance(w http.ResponseWriter, r *http.Request) {
- var inst dynamicrouting.BabelInstance
- if err := json.NewDecoder(r.Body).Decode(&inst); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- res, err := s.dynRoutingMgr.SaveBabelInstance(inst)
- if err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, res)
- }
- func (s *Server) handleDeleteBabelInstance(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing instance ID"})
- return
- }
- if err := s.dynRoutingMgr.DeleteBabelInstance(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleSetBabelInstanceState(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- var req struct {
- Disabled bool `json:"disabled"`
- }
- if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON"})
- return
- }
- if err := s.dynRoutingMgr.SetBabelInstanceState(id, req.Disabled); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "disabled": req.Disabled})
- }
- func (s *Server) handleListBabelInterfaces(w http.ResponseWriter, r *http.Request) {
- ifaces := s.dynRoutingMgr.ListBabelInterfaces()
- if ifaces == nil {
- ifaces = []dynamicrouting.BabelInterface{}
- }
- writeJSON(w, http.StatusOK, ifaces)
- }
- func (s *Server) handleSaveBabelInterface(w http.ResponseWriter, r *http.Request) {
- var iface dynamicrouting.BabelInterface
- if err := json.NewDecoder(r.Body).Decode(&iface); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- res, err := s.dynRoutingMgr.SaveBabelInterface(iface)
- if err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, res)
- }
- func (s *Server) handleDeleteBabelInterface(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing interface ID"})
- return
- }
- if err := s.dynRoutingMgr.DeleteBabelInterface(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleSetBabelInterfaceState(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- var req struct {
- Disabled bool `json:"disabled"`
- }
- if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON"})
- return
- }
- if err := s.dynRoutingMgr.SetBabelInterfaceState(id, req.Disabled); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "disabled": req.Disabled})
- }
- func (s *Server) handleGetBabelNeighbors(w http.ResponseWriter, r *http.Request) {
- nbrs := s.dynRoutingMgr.GetBabelNeighbors()
- if nbrs == nil {
- nbrs = []dynamicrouting.BabelNeighbor{}
- }
- writeJSON(w, http.StatusOK, nbrs)
- }
- func (s *Server) handleGetBabelRoutes(w http.ResponseWriter, r *http.Request) {
- rts := s.dynRoutingMgr.GetBabelRoutes()
- if rts == nil {
- rts = []dynamicrouting.BabelRoute{}
- }
- writeJSON(w, http.StatusOK, rts)
- }
- // -------------------------------------------------------------
- // RAdv Handlers (/api/routing/radv/*)
- // -------------------------------------------------------------
- func (s *Server) handleListRAdvInstances(w http.ResponseWriter, r *http.Request) {
- insts := s.dynRoutingMgr.ListRAdvInstances()
- if insts == nil {
- insts = []dynamicrouting.RAdvInstance{}
- }
- writeJSON(w, http.StatusOK, insts)
- }
- func (s *Server) handleSaveRAdvInstance(w http.ResponseWriter, r *http.Request) {
- var inst dynamicrouting.RAdvInstance
- if err := json.NewDecoder(r.Body).Decode(&inst); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- res, err := s.dynRoutingMgr.SaveRAdvInstance(inst)
- if err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, res)
- }
- func (s *Server) handleDeleteRAdvInstance(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing instance ID"})
- return
- }
- if err := s.dynRoutingMgr.DeleteRAdvInstance(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleSetRAdvInstanceState(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- var req struct {
- Disabled bool `json:"disabled"`
- }
- if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON"})
- return
- }
- if err := s.dynRoutingMgr.SetRAdvInstanceState(id, req.Disabled); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "disabled": req.Disabled})
- }
- func (s *Server) handleListRAdvInterfaces(w http.ResponseWriter, r *http.Request) {
- ifaces := s.dynRoutingMgr.ListRAdvInterfaces()
- if ifaces == nil {
- ifaces = []dynamicrouting.RAdvInterface{}
- }
- writeJSON(w, http.StatusOK, ifaces)
- }
- func (s *Server) handleSaveRAdvInterface(w http.ResponseWriter, r *http.Request) {
- var iface dynamicrouting.RAdvInterface
- if err := json.NewDecoder(r.Body).Decode(&iface); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON: " + err.Error()})
- return
- }
- res, err := s.dynRoutingMgr.SaveRAdvInterface(iface)
- if err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, res)
- }
- func (s *Server) handleDeleteRAdvInterface(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- if id == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Missing interface ID"})
- return
- }
- if err := s.dynRoutingMgr.DeleteRAdvInterface(id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]string{"status": "deleted"})
- }
- func (s *Server) handleSetRAdvInterfaceState(w http.ResponseWriter, r *http.Request) {
- id := r.PathValue("id")
- var req struct {
- Disabled bool `json:"disabled"`
- }
- if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Invalid JSON"})
- return
- }
- if err := s.dynRoutingMgr.SetRAdvInterfaceState(id, req.Disabled); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
- return
- }
- writeJSON(w, http.StatusOK, map[string]interface{}{"status": "success", "disabled": req.Disabled})
- }
|