Skip to content

Commit 6257253

Browse files
author
Vojtěch Frič
committed
feat: add option to disable authentication
1 parent 97d6916 commit 6257253

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Once done, just go to <your host> and login as "admin" with <any password>.
9090
| HOST | Url to OnLogs host from protocol to domain name. | | if `AGENT=true`
9191
| ONLOGS_TOKEN | Token that will use an agent to authorize and connect to HOST | Generates with OnLogs interface | if `AGENT=true`
9292
| MAX_LOGS_SIZE | Maximum allowed total logs size before cleanup triggers. Accepts human-readable formats like 5GB, 500MB, 1.5GB etc. When exceeded, 10% of logs (by count) will be removed proportionally across containers starting from oldest | 10GB | -
93+
| DISABLE_AUTH | Option to completely disable built in authentication in the application. When this option is set to `true` the app will behave like if the Administrator is logged in. The option to manage users will be removed. | false | -
9394

9495
### Docket socket URL
9596
By default the app will connect using the raw unix socket. But this can be overriden via the ENV variable `DOCKER_HOST`. That way you can specify fully qualified URL to the socket or URL of an docker socket proxy.

application/backend/.env example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ PASSWORD=fsadfsadfad
22
ENV_NAME = local
33
PORT=2874
44
ONLOGS_PATH_PREFIX=''
5-
5+
DISABLE_AUTH=false
66
# HOST=onlogs.coposter.me
77
# AGENT=true

application/backend/app/routes/routes.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ func enableCors(w *http.ResponseWriter) {
4343
}
4444

4545
func verifyAdminUser(w *http.ResponseWriter, req *http.Request) bool {
46+
if os.Getenv("DISABLE_AUTH") == "true" {
47+
return true
48+
}
49+
4650
username, err := util.GetUserFromJWT(*req)
4751
if username != os.Getenv("ADMIN_USERNAME") {
4852
(*w).WriteHeader(http.StatusForbidden)
@@ -59,6 +63,10 @@ func verifyAdminUser(w *http.ResponseWriter, req *http.Request) bool {
5963
}
6064

6165
func verifyUser(w *http.ResponseWriter, req *http.Request) bool {
66+
if os.Getenv("DISABLE_AUTH") == "true" {
67+
return true
68+
}
69+
6270
_, err := util.GetUserFromJWT(*req)
6371
if err != nil {
6472
(*w).WriteHeader(http.StatusUnauthorized)
@@ -91,19 +99,30 @@ func (h *RouteController)Frontend(w http.ResponseWriter, req *http.Request) {
9199
if err != nil {
92100
dir = http.Dir("dist")
93101
file, err = dir.Open("index.html")
102+
fileName = "index.html"
94103
}
95104
if err != nil {
96105
return
97106
}
98107
defer file.Close()
99108

109+
stat, _ := file.Stat()
110+
content, _ := io.ReadAll(file)
111+
112+
if fileName == "index.html" {
113+
var disableAuth []byte
114+
if os.Getenv("DISABLE_AUTH") == "true" {
115+
disableAuth = []byte("true")
116+
} else {
117+
disableAuth = []byte("false")
118+
}
119+
120+
content = bytes.Replace(content, []byte("$DISABLE_AUTH$"), disableAuth, 1)
121+
}
122+
100123
w.Header().Set("Cache-Control", "no-store")
101124
w.Header().Set("Content-Type", mime.TypeByExtension(filepath.Ext(fileName)))
102-
103-
stat, _ := file.Stat()
104-
content := make([]byte, stat.Size())
105-
io.ReadFull(file, content)
106-
http.ServeContent(w, req, requestedPath, stat.ModTime(), bytes.NewReader(content))
125+
http.ServeContent(w, req, fileName, stat.ModTime(), bytes.NewReader(content))
107126
}
108127

109128
func (h *RouteController)CheckCookie(w http.ResponseWriter, req *http.Request) {

application/frontend/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626

2727
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
2828
<title>OnLogs</title>
29+
30+
<script>
31+
window.DISABLE_AUTH=$DISABLE_AUTH$ ?? false;
32+
</script>
2933
</head>
3034
<body>
3135
<div id="app"></div>

application/frontend/src/lib/ClientPanel/ClientPanel.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
let localTheme = "";
1515
let api = new fetchApi();
1616
17+
const showUserMenu = window.DISABLE_AUTH ?? true;
18+
1719
//store management
1820
function toggleUserMenu() {
1921
userMenuOpen.update((v) => !v);
@@ -69,6 +71,7 @@
6971
($activeMenuOption === 'view' && 'active')}"
7072
/>
7173
</li>
74+
{#if showUserMenu}
7275
<li
7376
on:click={toggleUserMenu}
7477
class={$activeMenuOption === "users" && "active"}
@@ -78,6 +81,7 @@
7881
class="higlightedOverlay {$activeMenuOption === 'users' && 'active'}"
7982
/>
8083
</li>
84+
{/if}
8185
8286
<!-- <li class={$activeMenuOption === "wheel" && "active"}>
8387
<i class="log log-Wheel" />

0 commit comments

Comments
 (0)