// Copyright 2017 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 vhost
import (
"bytes"
"io/ioutil"
"net/http"
frpLog "github.com/fatedier/frp/utils/log"
"github.com/fatedier/frp/utils/version"
)
var (
ServiceUnavailablePagePath = ""
)
const (
ServiceUnavailable = `
503 Service Unavailable
503 Service Unavailable
您访问的网站或服务暂时不可用
如果您是隧道所有者,造成无法访问的原因可能有:
- 您访问的网站使用了内网穿透,但是对应的客户端没有运行。
- 该网站或隧道已被管理员临时或永久禁止连接。
- 域名解析更改还未生效或解析错误,请检查设置是否正确。
如果您是普通访问者,您可以:
- 稍等一段时间后再次尝试访问此站点。
- 尝试与该网站的所有者取得联系。
- 刷新您的 DNS 缓存或在其他网络环境访问。
Powered by Sakura Panel | Based on Frp
`
)
func getServiceUnavailablePageContent() []byte {
var (
buf []byte
err error
)
if ServiceUnavailablePagePath != "" {
buf, err = ioutil.ReadFile(ServiceUnavailablePagePath)
if err != nil {
frpLog.Warn("read custom 503 page error: %v", err)
buf = []byte(ServiceUnavailable)
}
} else {
buf = []byte(ServiceUnavailable)
}
return buf
}
func notFoundResponse() *http.Response {
header := make(http.Header)
header.Set("server", "frp/" + version.Full() + "-sakurapanel")
header.Set("Content-Type", "text/html")
res := &http.Response{
Status: "Service Unavailable",
StatusCode: 503,
Proto: "HTTP/1.0",
ProtoMajor: 1,
ProtoMinor: 0,
Header: header,
Body: ioutil.NopCloser(bytes.NewReader(getServiceUnavailablePageContent())),
}
return res
}
func noAuthResponse() *http.Response {
header := make(map[string][]string)
header["WWW-Authenticate"] = []string{`Basic realm="Restricted"`}
res := &http.Response{
Status: "401 Not authorized",
StatusCode: 401,
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
Header: header,
}
return res
}