-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor UI: Allow to override built-in assets and provide i18n capab…
…ilities (#229)
- Loading branch information
Showing
18 changed files
with
160 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Layout Customization | ||
|
||
openvpn-auth-oauth2 supports custom templates for the login page. The template must be a valid HTML file. | ||
|
||
The default template is here: | ||
[index.gohtml](https://github.com/jkroepke/openvpn-auth-oauth2/blob/main/internal/ui/index.gohtml) | ||
|
||
Available variables: | ||
|
||
- `{{.title}}`: `Access denied` or `Access granted` | ||
- `{{.message}}`: Potential error message or success message | ||
- `{{.errorID}}`: ErrorID of an error, if present | ||
|
||
The [go template engine](https://pkg.go.dev/text/template) is used to render the HTML file. | ||
|
||
## Overriding the default assets | ||
|
||
To override the default assets, you can configure `http.assets-path` with the path to the directory containing the assets. | ||
|
||
The default assets are here: | ||
|
||
- `style.css`: CSS file to enrich the default layout. By default, it is empty. | ||
- `mvp.css`: [MVP](https://github.com/andybrewer/mvp) css framework | ||
- `favicon.png`: Favicon of the login page | ||
- `i18n.js`: Localization script | ||
- `i18n/<lang>.json`: Language specific localization file. <lang> is the language code, e.g., `en` for English. | ||
See [de.json](https://github.com/jkroepke/openvpn-auth-oauth2/blob/main/internal/ui/static/i18n/de.json) for an example. | ||
|
||
## Custom localization | ||
|
||
If you want to provide custom localization, you have to configure `http.assets-path` first. In the assets directory, | ||
create a new directory named `i18n` and put your localization files in there. The file name must be the language code | ||
followed by `.json`. For example, `en.json` for English. | ||
|
||
Instead providing a custom localization file locally, think about to submit a pull request to the project to provide | ||
the localization for everyone. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(async () => { | ||
const response = await fetch(`../assets/i18n/${navigator.language.split('-')[0]}.json`); | ||
if (!response.ok) return | ||
|
||
const json = await response.json(); | ||
|
||
document.querySelectorAll("[data-i18n]").forEach(el => { | ||
if (el.innerText in json) { | ||
el.innerText = json[el.innerText]; | ||
} | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"Access denied": "Zugriff verweigert", | ||
"Access granted": "Zugriff gewährt", | ||
"Error ID": "Fehler ID", | ||
"Please contact your administrator.": "Bitte kontaktieren Sie Ihren Administrator." | ||
} |
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package utils | ||
|
||
import "io/fs" | ||
|
||
type OverlayFS struct { | ||
fs fs.FS | ||
over fs.FS | ||
} | ||
|
||
func NewOverlayFS(fs, over fs.FS) *OverlayFS { return &OverlayFS{fs, over} } | ||
|
||
func (f *OverlayFS) Open(name string) (fs.File, error) { | ||
fi, err := fs.Stat(f.over, name) | ||
if err == nil && !fi.IsDir() { | ||
if f, err := f.over.Open(name); err == nil { | ||
return f, nil | ||
} | ||
} | ||
|
||
return f.fs.Open(name) //nolint:wrapcheck | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package utils_test | ||
|
||
import ( | ||
"io/fs" | ||
"testing" | ||
"testing/fstest" | ||
|
||
"github.com/jkroepke/openvpn-auth-oauth2/internal/utils" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewOverlayFS(t *testing.T) { | ||
t.Parallel() | ||
|
||
baseFS := fstest.MapFS{ | ||
"base": &fstest.MapFile{ | ||
Data: []byte("base"), | ||
}, | ||
"overlay": &fstest.MapFile{ | ||
Data: []byte("base"), | ||
}, | ||
} | ||
overlayFS := fstest.MapFS{ | ||
"overlay": &fstest.MapFile{ | ||
Data: []byte("overlay"), | ||
}, | ||
} | ||
|
||
ofs := utils.NewOverlayFS(baseFS, overlayFS) | ||
|
||
content, err := fs.ReadFile(ofs, "overlay") | ||
require.NoError(t, err) | ||
assert.Equal(t, []byte("overlay"), content) | ||
|
||
content, err = fs.ReadFile(ofs, "base") | ||
require.NoError(t, err) | ||
assert.Equal(t, []byte("base"), content) | ||
|
||
_, err = fs.ReadFile(ofs, "nonexistent") | ||
require.Error(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM ubuntu:23.10 | ||
FROM debian:12 | ||
|
||
RUN groupadd openvpn-auth-oauth2 | ||
RUN apt update && apt install ca-certificates systemd openvpn apparmor apparmor-easyprof apparmor-profiles apparmor-profiles-extra -y |