mirror of
https://github.com/juanfont/headscale.git
synced 2025-11-20 17:56:02 -05:00
add favicon to webpages (#2858)
Co-authored-by: TeejMcSteez <tjhall047@gmail.com> Co-authored-by: Kristoffer Dalby <kristoffer@dalby.cc>
This commit is contained in:
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
|
|
||||||
|
- Add favicon to webpages
|
||||||
|
[#2858](https://github.com/juanfont/headscale/pull/2858)
|
||||||
- Reclaim IPs from the IP allocator when nodes are deleted
|
- Reclaim IPs from the IP allocator when nodes are deleted
|
||||||
[#2831](https://github.com/juanfont/headscale/pull/2831)
|
[#2831](https://github.com/juanfont/headscale/pull/2831)
|
||||||
|
|
||||||
@@ -138,7 +140,6 @@ the code base over time and make it more correct and efficient.
|
|||||||
starting/ending with hyphen are rejected
|
starting/ending with hyphen are rejected
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
|
|
||||||
- **Database schema migration improvements for SQLite**
|
- **Database schema migration improvements for SQLite**
|
||||||
[#2617](https://github.com/juanfont/headscale/pull/2617)
|
[#2617](https://github.com/juanfont/headscale/pull/2617)
|
||||||
- **IMPORTANT: Backup your SQLite database before upgrading**
|
- **IMPORTANT: Backup your SQLite database before upgrading**
|
||||||
|
|||||||
@@ -476,8 +476,8 @@ func (h *Headscale) createRouter(grpcMux *grpcRuntime.ServeMux) *mux.Router {
|
|||||||
apiRouter := router.PathPrefix("/api").Subrouter()
|
apiRouter := router.PathPrefix("/api").Subrouter()
|
||||||
apiRouter.Use(h.httpAuthenticationMiddleware)
|
apiRouter.Use(h.httpAuthenticationMiddleware)
|
||||||
apiRouter.PathPrefix("/v1/").HandlerFunc(grpcMux.ServeHTTP)
|
apiRouter.PathPrefix("/v1/").HandlerFunc(grpcMux.ServeHTTP)
|
||||||
|
router.HandleFunc("/favicon.ico", FaviconHandler)
|
||||||
router.PathPrefix("/").HandlerFunc(notFoundHandler)
|
router.PathPrefix("/").HandlerFunc(BlankHandler)
|
||||||
|
|
||||||
return router
|
return router
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
hscontrol/assets/favicon.png
Normal file
BIN
hscontrol/assets/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
@@ -1,6 +1,8 @@
|
|||||||
package hscontrol
|
package hscontrol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
_ "embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -8,6 +10,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/chasefleming/elem-go/styles"
|
"github.com/chasefleming/elem-go/styles"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
@@ -98,6 +101,7 @@ func (h *Headscale) handleVerifyRequest(
|
|||||||
|
|
||||||
// Check if any node has the requested NodeKey
|
// Check if any node has the requested NodeKey
|
||||||
var nodeKeyFound bool
|
var nodeKeyFound bool
|
||||||
|
|
||||||
for _, node := range nodes.All() {
|
for _, node := range nodes.All() {
|
||||||
if node.NodeKey() == derpAdmitClientRequest.NodePublic {
|
if node.NodeKey() == derpAdmitClientRequest.NodePublic {
|
||||||
nodeKeyFound = true
|
nodeKeyFound = true
|
||||||
@@ -128,6 +132,7 @@ func (h *Headscale) VerifyHandler(
|
|||||||
httpError(writer, err)
|
httpError(writer, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.Header().Set("Content-Type", "application/json")
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +154,7 @@ func (h *Headscale) KeyHandler(
|
|||||||
resp := tailcfg.OverTLSPublicKeyResponse{
|
resp := tailcfg.OverTLSPublicKeyResponse{
|
||||||
PublicKey: h.noisePrivateKey.Public(),
|
PublicKey: h.noisePrivateKey.Public(),
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.Header().Set("Content-Type", "application/json")
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(writer).Encode(resp)
|
json.NewEncoder(writer).Encode(resp)
|
||||||
|
|
||||||
@@ -171,13 +177,14 @@ func (h *Headscale) HealthHandler(
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writer.WriteHeader(http.StatusInternalServerError)
|
writer.WriteHeader(http.StatusInternalServerError)
|
||||||
|
|
||||||
res.Status = "fail"
|
res.Status = "fail"
|
||||||
}
|
}
|
||||||
|
|
||||||
json.NewEncoder(writer).Encode(res)
|
json.NewEncoder(writer).Encode(res)
|
||||||
}
|
}
|
||||||
|
err := h.state.PingDB(req.Context())
|
||||||
if err := h.state.PingDB(req.Context()); err != nil {
|
if err != nil {
|
||||||
respond(err)
|
respond(err)
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -192,6 +199,7 @@ func (h *Headscale) RobotsHandler(
|
|||||||
) {
|
) {
|
||||||
writer.Header().Set("Content-Type", "text/plain")
|
writer.Header().Set("Content-Type", "text/plain")
|
||||||
writer.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
_, err := writer.Write([]byte("User-agent: *\nDisallow: /"))
|
_, err := writer.Write([]byte("User-agent: *\nDisallow: /"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().
|
log.Error().
|
||||||
@@ -211,7 +219,8 @@ func (h *Headscale) VersionHandler(
|
|||||||
writer.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
versionInfo := types.GetVersionInfo()
|
versionInfo := types.GetVersionInfo()
|
||||||
if err := json.NewEncoder(writer).Encode(versionInfo); err != nil {
|
err := json.NewEncoder(writer).Encode(versionInfo)
|
||||||
|
if err != nil {
|
||||||
log.Error().
|
log.Error().
|
||||||
Caller().
|
Caller().
|
||||||
Err(err).
|
Err(err).
|
||||||
@@ -268,3 +277,21 @@ func (a *AuthProviderWeb) RegisterHandler(
|
|||||||
writer.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
writer.Write([]byte(templates.RegisterWeb(registrationId).Render()))
|
writer.Write([]byte(templates.RegisterWeb(registrationId).Render()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:embed assets/favicon.png
|
||||||
|
var favicon []byte
|
||||||
|
|
||||||
|
func FaviconHandler(writer http.ResponseWriter, req *http.Request) {
|
||||||
|
writer.Header().Set("Content-Type", "image/png")
|
||||||
|
http.ServeContent(writer, req, "favicon.ico", time.Unix(0, 0), bytes.NewReader(favicon))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns a blank page with favicon linked.
|
||||||
|
func BlankHandler(writer http.ResponseWriter, res *http.Request) {
|
||||||
|
writer.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
io.WriteString(writer, `
|
||||||
|
<!doctype html><html><head>
|
||||||
|
<link rel="icon" href="/favicon.ico">
|
||||||
|
</head><body></body></html>
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|||||||
@@ -49,6 +49,10 @@ func HtmlStructure(head, body *elem.Element) *elem.Element {
|
|||||||
attrs.Name: "viewport",
|
attrs.Name: "viewport",
|
||||||
attrs.Content: "width=device-width, initial-scale=1.0",
|
attrs.Content: "width=device-width, initial-scale=1.0",
|
||||||
}),
|
}),
|
||||||
|
elem.Link(attrs.Props{
|
||||||
|
attrs.Rel: "icon",
|
||||||
|
attrs.Href: "/favicon.ico",
|
||||||
|
}),
|
||||||
head,
|
head,
|
||||||
),
|
),
|
||||||
body,
|
body,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func SwaggerUI(
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" type="text/css" href="https://unpkg.com/swagger-ui-dist@3/swagger-ui.css">
|
<link rel="stylesheet" type="text/css" href="https://unpkg.com/swagger-ui-dist@3/swagger-ui.css">
|
||||||
|
<link rel="icon" href="/favicon.ico">
|
||||||
<script src="https://unpkg.com/swagger-ui-dist@3/swagger-ui-standalone-preset.js"></script>
|
<script src="https://unpkg.com/swagger-ui-dist@3/swagger-ui-standalone-preset.js"></script>
|
||||||
<script src="https://unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js" charset="UTF-8"></script>
|
<script src="https://unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js" charset="UTF-8"></script>
|
||||||
</head>
|
</head>
|
||||||
@@ -57,6 +57,7 @@ func SwaggerUI(
|
|||||||
|
|
||||||
writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
writer.WriteHeader(http.StatusInternalServerError)
|
writer.WriteHeader(http.StatusInternalServerError)
|
||||||
|
|
||||||
_, err := writer.Write([]byte("Could not render Swagger"))
|
_, err := writer.Write([]byte("Could not render Swagger"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().
|
log.Error().
|
||||||
@@ -70,6 +71,7 @@ func SwaggerUI(
|
|||||||
|
|
||||||
writer.Header().Set("Content-Type", "text/html; charset=utf-8")
|
writer.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
writer.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
_, err := writer.Write(payload.Bytes())
|
_, err := writer.Write(payload.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().
|
log.Error().
|
||||||
@@ -85,6 +87,7 @@ func SwaggerAPIv1(
|
|||||||
) {
|
) {
|
||||||
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
writer.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
if _, err := writer.Write(apiV1JSON); err != nil {
|
if _, err := writer.Write(apiV1JSON); err != nil {
|
||||||
log.Error().
|
log.Error().
|
||||||
Caller().
|
Caller().
|
||||||
|
|||||||
Reference in New Issue
Block a user