2016-05-19 00:04:19 +08:00
|
|
|
// Copyright 2016 fatedier, fatedier@gmail.com
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2016-06-03 17:51:45 +08:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2016-08-10 20:18:36 +08:00
|
|
|
"net/http"
|
2016-06-03 17:51:45 +08:00
|
|
|
|
2016-07-17 21:42:21 +08:00
|
|
|
"frp/models/metric"
|
2016-06-03 17:51:45 +08:00
|
|
|
"frp/utils/log"
|
2016-05-19 00:04:19 +08:00
|
|
|
)
|
|
|
|
|
2016-06-03 17:51:45 +08:00
|
|
|
type GeneralResponse struct {
|
|
|
|
Code int64 `json:"code"`
|
|
|
|
Msg string `json:"msg"`
|
|
|
|
}
|
|
|
|
|
2016-08-10 20:18:36 +08:00
|
|
|
func apiReload(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var buf []byte
|
2016-06-03 17:51:45 +08:00
|
|
|
res := &GeneralResponse{}
|
|
|
|
defer func() {
|
|
|
|
log.Info("Http response [/api/reload]: %s", string(buf))
|
|
|
|
}()
|
|
|
|
|
|
|
|
log.Info("Http request: [/api/reload]")
|
|
|
|
err := ReloadConf(ConfigFile)
|
|
|
|
if err != nil {
|
|
|
|
res.Code = 2
|
|
|
|
res.Msg = fmt.Sprintf("%v", err)
|
|
|
|
log.Error("frps reload error: %v", err)
|
|
|
|
}
|
2016-08-10 20:18:36 +08:00
|
|
|
|
|
|
|
buf, _ = json.Marshal(res)
|
|
|
|
w.Write(buf)
|
2016-05-19 00:04:19 +08:00
|
|
|
}
|
2016-07-17 21:42:21 +08:00
|
|
|
|
|
|
|
type ProxiesResponse struct {
|
|
|
|
Code int64 `json:"code"`
|
|
|
|
Msg string `json:"msg"`
|
|
|
|
Proxies []*metric.ServerMetric `json:"proxies"`
|
|
|
|
}
|
|
|
|
|
2016-08-10 20:18:36 +08:00
|
|
|
func apiProxies(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var buf []byte
|
2016-07-17 21:42:21 +08:00
|
|
|
res := &ProxiesResponse{}
|
|
|
|
defer func() {
|
|
|
|
log.Info("Http response [/api/proxies]: code [%d]", res.Code)
|
|
|
|
}()
|
|
|
|
|
|
|
|
log.Info("Http request: [/api/proxies]")
|
2016-07-18 00:18:40 +08:00
|
|
|
res.Proxies = metric.GetAllProxyMetrics()
|
2016-08-10 20:18:36 +08:00
|
|
|
buf, _ = json.Marshal(res)
|
|
|
|
w.Write(buf)
|
2016-07-17 21:42:21 +08:00
|
|
|
}
|