1
0

dashboard_api.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2016 fatedier, fatedier@gmail.com
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package server
  15. /*
  16. import (
  17. "encoding/json"
  18. "fmt"
  19. "net/http"
  20. "github.com/fatedier/frp/src/models/metric"
  21. "github.com/fatedier/frp/src/utils/log"
  22. )
  23. type GeneralResponse struct {
  24. Code int64 `json:"code"`
  25. Msg string `json:"msg"`
  26. }
  27. func apiReload(w http.ResponseWriter, r *http.Request) {
  28. var buf []byte
  29. res := &GeneralResponse{}
  30. defer func() {
  31. log.Info("Http response [/api/reload]: %s", string(buf))
  32. }()
  33. log.Info("Http request: [/api/reload]")
  34. err := ReloadConf(ConfigFile)
  35. if err != nil {
  36. res.Code = 2
  37. res.Msg = fmt.Sprintf("%v", err)
  38. log.Error("frps reload error: %v", err)
  39. }
  40. buf, _ = json.Marshal(res)
  41. w.Write(buf)
  42. }
  43. type ProxiesResponse struct {
  44. Code int64 `json:"code"`
  45. Msg string `json:"msg"`
  46. Proxies []*metric.ServerMetric `json:"proxies"`
  47. }
  48. func apiProxies(w http.ResponseWriter, r *http.Request) {
  49. var buf []byte
  50. res := &ProxiesResponse{}
  51. defer func() {
  52. log.Info("Http response [/api/proxies]: code [%d]", res.Code)
  53. }()
  54. log.Info("Http request: [/api/proxies]")
  55. res.Proxies = metric.GetAllProxyMetrics()
  56. buf, _ = json.Marshal(res)
  57. w.Write(buf)
  58. }
  59. */