2023-05-23 08:39:25 +00:00
|
|
|
package v2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/IceWhaleTech/CasaOS-Common/utils"
|
|
|
|
"github.com/IceWhaleTech/CasaOS/codegen"
|
|
|
|
"github.com/IceWhaleTech/CasaOS/common"
|
|
|
|
"github.com/IceWhaleTech/CasaOS/pkg/utils/httper"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *CasaOS) SetZerotierNetworkStatus(ctx echo.Context, networkId string) error {
|
2023-11-09 06:04:45 +00:00
|
|
|
|
|
|
|
return ctx.JSON(http.StatusOK, nil)
|
2023-05-23 08:39:25 +00:00
|
|
|
}
|
|
|
|
func (s *CasaOS) GetZerotierInfo(ctx echo.Context) error {
|
|
|
|
info := codegen.GetZTInfoOK{}
|
|
|
|
respBody, err := httper.ZTGet("/controller/network")
|
|
|
|
if err != nil {
|
|
|
|
return ctx.JSON(http.StatusInternalServerError, codegen.BaseResponse{Message: utils.Ptr(err.Error())})
|
|
|
|
}
|
|
|
|
|
|
|
|
networkNames := gjson.ParseBytes(respBody).Array()
|
|
|
|
for _, v := range networkNames {
|
|
|
|
res, err := httper.ZTGet("/controller/network/" + v.Str)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return ctx.JSON(http.StatusInternalServerError, codegen.BaseResponse{Message: utils.Ptr(err.Error())})
|
|
|
|
}
|
|
|
|
name := gjson.GetBytes(res, "name").Str
|
|
|
|
if name == common.RANW_NAME {
|
|
|
|
via := gjson.GetBytes(res, "routes.0.via").Str
|
|
|
|
info.Id = utils.Ptr(gjson.GetBytes(res, "id").Str)
|
|
|
|
info.Name = &name
|
2023-06-01 02:22:04 +00:00
|
|
|
if len(via) == 0 {
|
2023-05-23 08:39:25 +00:00
|
|
|
info.Status = utils.Ptr("online")
|
|
|
|
} else {
|
|
|
|
info.Status = utils.Ptr("offline")
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ctx.JSON(http.StatusOK, info)
|
|
|
|
}
|