mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-22 21:47:16 +02:00
dashboard: inline svgs + css for better forward auth (#771)
This commit is contained in:
parent
727d4bed9d
commit
7b96d2de66
6 changed files with 50 additions and 8 deletions
|
@ -17,7 +17,7 @@
|
||||||
{{else}}
|
{{else}}
|
||||||
<img
|
<img
|
||||||
class="icon"
|
class="icon"
|
||||||
src="/.pomerium/assets/img/account_circle-24px.svg"
|
src="{{dataURL "/.pomerium/assets/img/account_circle-24px.svg"}}"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
/>
|
/>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -198,7 +198,7 @@
|
||||||
<h2>Sign-in-as</h2>
|
<h2>Sign-in-as</h2>
|
||||||
<img
|
<img
|
||||||
class="icon"
|
class="icon"
|
||||||
src="/.pomerium/assets/img/supervised_user_circle-24px.svg"
|
src="{{dataURL "/.pomerium/assets/img/supervised_user_circle-24px.svg"}}"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<img
|
<img
|
||||||
class="icon"
|
class="icon"
|
||||||
src="/.pomerium/assets/img/error-24px.svg"
|
src="{{dataURL "/.pomerium/assets/img/error-24px.svg"}}"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
/>
|
/>
|
||||||
<h2>{{.StatusText}}</h2>
|
<h2>{{.StatusText}}</h2>
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<a href="https://www.pomerium.io">
|
<a href="https://www.pomerium.io">
|
||||||
<img
|
<img
|
||||||
src="/.pomerium/assets/img/pomerium_circle_96.svg"
|
src="{{dataURL "/.pomerium/assets/img/pomerium_circle_96.svg"}}"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
class="icon"
|
class="icon"
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -6,6 +6,11 @@
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
type="text/css"
|
type="text/css"
|
||||||
href="/.pomerium/assets/style/main.css"
|
href="{{dataURL "/.pomerium/assets/style/main.css"}}"
|
||||||
|
/>
|
||||||
|
<link
|
||||||
|
rel="icon"
|
||||||
|
type="image/png"
|
||||||
|
href="{{dataURL "/.pomerium/assets/img/account_circle-24px.svg"}}"
|
||||||
/>
|
/>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -5,11 +5,15 @@
|
||||||
package frontend
|
package frontend
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/rakyll/statik/fs"
|
"github.com/rakyll/statik/fs"
|
||||||
|
|
||||||
|
@ -20,12 +24,45 @@ const statikNamespace = "web"
|
||||||
|
|
||||||
// NewTemplates loads pomerium's templates. Panics on failure.
|
// NewTemplates loads pomerium's templates. Panics on failure.
|
||||||
func NewTemplates() (*template.Template, error) {
|
func NewTemplates() (*template.Template, error) {
|
||||||
t := template.New("pomerium-templates")
|
|
||||||
statikFS, err := fs.NewWithNamespace(statikNamespace)
|
statikFS, err := fs.NewWithNamespace(statikNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("internal/frontend: error creating new file system: %w", err)
|
return nil, fmt.Errorf("internal/frontend: error creating new file system: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dataURLs := map[string]template.URL{}
|
||||||
|
|
||||||
|
err = fs.Walk(statikFS, "/", func(filePath string, fileInfo os.FileInfo, _ error) error {
|
||||||
|
if fileInfo.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := statikFS.Open(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("internal/frontend: error opening %s: %w", filePath, err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
bs, err := ioutil.ReadAll(file)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("internal/frontend: error reading %s: %w", filePath, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
encoded := base64.StdEncoding.EncodeToString(bs)
|
||||||
|
dataURLs[filePath] = template.URL(fmt.Sprintf(
|
||||||
|
"data:%s;base64,%s", mime.TypeByExtension(path.Ext(filePath)), encoded))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
t := template.New("pomerium-templates").Funcs(map[string]interface{}{
|
||||||
|
"dataURL": func(p string) template.URL {
|
||||||
|
return dataURLs[strings.TrimPrefix(p, "/.pomerium/assets")]
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
err = fs.Walk(statikFS, "/html", func(filePath string, fileInfo os.FileInfo, err error) error {
|
err = fs.Walk(statikFS, "/html", func(filePath string, fileInfo os.FileInfo, err error) error {
|
||||||
if !fileInfo.IsDir() {
|
if !fileInfo.IsDir() {
|
||||||
file, err := statikFS.Open(filePath)
|
file, err := statikFS.Open(filePath)
|
||||||
|
|
|
@ -18,7 +18,7 @@ const (
|
||||||
// by default includes profile photo exceptions for supported identity providers.
|
// by default includes profile photo exceptions for supported identity providers.
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src
|
||||||
var HeadersContentSecurityPolicy = map[string]string{
|
var HeadersContentSecurityPolicy = map[string]string{
|
||||||
"Content-Security-Policy": "default-src 'none'; style-src 'self'; img-src *;",
|
"Content-Security-Policy": "default-src 'none'; style-src 'self' data:; img-src * data:;",
|
||||||
"Referrer-Policy": "Same-origin",
|
"Referrer-Policy": "Same-origin",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue