From efa5fb9fec5cfaa4db5e893565d00fae04198f24 Mon Sep 17 00:00:00 2001 From: LbP22 Date: Wed, 1 Nov 2023 13:43:44 +0200 Subject: [PATCH 01/26] DOCKER_SOCKET_PATH usage, better env vars defaults/errors handling --- application/backend/app/daemon/daemon.go | 9 ++++--- application/backend/app/util/util.go | 1 - application/backend/main.go | 31 +++++++++++++++++------- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/application/backend/app/daemon/daemon.go b/application/backend/app/daemon/daemon.go index 451e2dd..da48735 100644 --- a/application/backend/app/daemon/daemon.go +++ b/application/backend/app/daemon/daemon.go @@ -41,7 +41,7 @@ func validateMessage(message string) (string, bool) { } func createConnection(containerName string) net.Conn { - connection, _ := net.Dial("unix", "/var/run/docker.sock") + connection, _ := net.Dial("unix", os.Getenv("DOCKER_SOCKET_PATH")) fmt.Fprintf( connection, "GET /containers/"+containerName+"/logs?stdout=true&stderr=true×tamps=true&follow=true&since="+strconv.FormatInt(time.Now().Add(-5*time.Second).Unix(), 10)+" HTTP/1.0\r\n\r\n", @@ -146,7 +146,7 @@ func CreateDaemonToDBStream(containerName string) { } if time.Now().Unix()-lastSleep > 1 { - time.Sleep(5 * time.Millisecond) + time.Sleep(10 * time.Millisecond) lastSleep = time.Now().Unix() } } @@ -154,7 +154,10 @@ func CreateDaemonToDBStream(containerName string) { // make request to docker socket func makeSocketRequest(path string) []byte { - connection, _ := net.Dial("unix", "/var/run/docker.sock") + connection, err := net.Dial("unix", os.Getenv("DOCKER_SOCKET_PATH")) + if err != nil { + panic(err) + } fmt.Fprintf(connection, "GET /"+path+" HTTP/1.0\r\n\r\n") body, _ := ioutil.ReadAll(connection) diff --git a/application/backend/app/util/util.go b/application/backend/app/util/util.go index 116964d..0c28013 100644 --- a/application/backend/app/util/util.go +++ b/application/backend/app/util/util.go @@ -55,7 +55,6 @@ func ReplacePrefixVariableForFrontend() { fmt.Println("INFO: unable to find 'dist' folder") return } - fmt.Println("INFO: base onlogs prefix is: ", "\""+os.Getenv("ONLOGS_PATH_PREFIX")+"\"") for _, file := range files { if file.IsDir() { dir_files, _ := os.ReadDir("dist/" + file.Name()) diff --git a/application/backend/main.go b/application/backend/main.go index e65c136..4eb84d7 100644 --- a/application/backend/main.go +++ b/application/backend/main.go @@ -12,8 +12,29 @@ import ( "github.com/joho/godotenv" ) +func init_config() { + if os.Getenv("PORT") == "" { + os.Setenv("PORT", "2874") + } + + if os.Getenv("JWT_SECRET") == "" { + token, err := os.ReadFile("leveldb/JWT_secret") + if err != nil { + os.WriteFile("leveldb/JWT_secret", []byte(os.Getenv("JWT_SECRET")), 0700) + token, _ = os.ReadFile("leveldb/JWT_secret") + } + os.Setenv("JWT_SECRET", string(token)) + } + + if os.Getenv("DOCKER_SOCKET_PATH") == "" { + os.Setenv("DOCKER_SOCKET_PATH", "/var/run/docker.sock") + } + fmt.Println("INFO: OnLogs configs done!") +} + func main() { godotenv.Load(".env") + init_config() if os.Getenv("AGENT") != "" { streamer.StreamLogs() } @@ -24,15 +45,6 @@ func main() { util.ReplacePrefixVariableForFrontend() util.CreateInitUser() - if os.Getenv("JWT_SECRET") == "" { - token, err := os.ReadFile("leveldb/JWT_secret") - if err != nil { - os.WriteFile("leveldb/JWT_secret", []byte(os.Getenv("JWT_SECRET")), 0700) - token, _ = os.ReadFile("leveldb/JWT_secret") - } - os.Setenv("JWT_SECRET", string(token)) - } - pathPrefix := os.Getenv("ONLOGS_PATH_PREFIX") http.HandleFunc(pathPrefix+"/", routes.Frontend) http.HandleFunc(pathPrefix+"/api/v1/addHost", routes.AddHost) @@ -65,5 +77,6 @@ func main() { http.HandleFunc(pathPrefix+"/api/v1/logout", routes.Logout) http.HandleFunc(pathPrefix+"/api/v1/updateUserSettings", routes.UpdateUserSettings) + fmt.Println("Listening on port:", string(os.Getenv("PORT"))+"...") fmt.Println("ONLOGS: ", http.ListenAndServe(":"+string(os.Getenv("PORT")), nil)) } From 8e7c91ede7033d341f386395c1d67ed2ed33ac35 Mon Sep 17 00:00:00 2001 From: LbP22 Date: Thu, 2 Nov 2023 08:21:20 +0200 Subject: [PATCH 02/26] fix for tests --- application/backend/app/routes/routes_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/application/backend/app/routes/routes_test.go b/application/backend/app/routes/routes_test.go index 0c141c0..c85e2b0 100644 --- a/application/backend/app/routes/routes_test.go +++ b/application/backend/app/routes/routes_test.go @@ -76,6 +76,7 @@ func TestGetHosts(t *testing.T) { Name: "onlogs-cookie", Value: util.CreateJWT("testuser"), }) + os.Setenv("DOCKER_SOCKET_PATH", "/var/run/docker.sock") userdb.CreateUser("testuser", "testuser") rr1 := httptest.NewRecorder() From 668761436118d336999c29b6bdeb7948115e9e37 Mon Sep 17 00:00:00 2001 From: LbP22 Date: Thu, 2 Nov 2023 08:23:02 +0200 Subject: [PATCH 03/26] upd for builds --- application/Dockerfile | 2 +- application/{backend => }/build.sh | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) rename application/{backend => }/build.sh (98%) diff --git a/application/Dockerfile b/application/Dockerfile index c3603ea..be8a233 100644 --- a/application/Dockerfile +++ b/application/Dockerfile @@ -3,7 +3,7 @@ FROM node:16-alpine AS frontbuilder WORKDIR /code/ ADD frontend/package-lock.json . ADD frontend/package.json . -RUN npm install -g npm@latest && npm ci +RUN npm install -g npm:16 && npm ci ADD frontend/. . diff --git a/application/backend/build.sh b/application/build.sh similarity index 98% rename from application/backend/build.sh rename to application/build.sh index 22b37a5..9ae4de2 100644 --- a/application/backend/build.sh +++ b/application/build.sh @@ -1,3 +1,2 @@ docker build . -t devforth/onlogs docker push devforth/onlogs - From 6ef79bad1ef59ac4a674b5c9ecb2ed93adb683d3 Mon Sep 17 00:00:00 2001 From: LbP22 <69319256+LbP22@users.noreply.github.com> Date: Thu, 2 Nov 2023 11:44:48 +0200 Subject: [PATCH 04/26] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bd7e7e6..065302d 100644 --- a/README.md +++ b/README.md @@ -83,3 +83,4 @@ Once done, just go to and login as "admin" with . | AGENT | Toggles agent mode. If enabled, there will be no web interface available and all logs will be sent and stored on HOST | `false` | - | HOST | Url to OnLogs host from protocol to domain name. | | if `AGENT=true` | ONLOGS_TOKEN | Token that will use agent to authorize and connect to HOST | Generates with OnLogs interface | if `AGENT=true` +| DOCKER_SOCKET_PATH | Path to docker.sock | /var/run/docker.sock | may be needed if you have docker desktop From bdb06e357d5ad706d13f225c50616a3a380cf504 Mon Sep 17 00:00:00 2001 From: LbP22 <69319256+LbP22@users.noreply.github.com> Date: Thu, 2 Nov 2023 12:40:03 +0200 Subject: [PATCH 05/26] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 065302d..bd7e7e6 100644 --- a/README.md +++ b/README.md @@ -83,4 +83,3 @@ Once done, just go to and login as "admin" with . | AGENT | Toggles agent mode. If enabled, there will be no web interface available and all logs will be sent and stored on HOST | `false` | - | HOST | Url to OnLogs host from protocol to domain name. | | if `AGENT=true` | ONLOGS_TOKEN | Token that will use agent to authorize and connect to HOST | Generates with OnLogs interface | if `AGENT=true` -| DOCKER_SOCKET_PATH | Path to docker.sock | /var/run/docker.sock | may be needed if you have docker desktop From 3709ff948c637473dfcdc81ee0d04ae9097a8f36 Mon Sep 17 00:00:00 2001 From: LbP22 Date: Wed, 8 Nov 2023 10:06:17 +0200 Subject: [PATCH 06/26] better debug --- application/backend/app/streamer/streamer.go | 5 +++++ application/backend/app/vars/vars.go | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/application/backend/app/streamer/streamer.go b/application/backend/app/streamer/streamer.go index db61ee1..b66e0ee 100644 --- a/application/backend/app/streamer/streamer.go +++ b/application/backend/app/streamer/streamer.go @@ -46,6 +46,11 @@ func createStreams(containers []string) { } func StreamLogs() { + if vars.FavsDBErr != nil || vars.StateDBErr != nil || vars.UsersDBErr != nil { + fmt.Println("ERROR: unable to open leveldb", vars.FavsDBErr, vars.StateDBErr, vars.UsersDBErr) + return + } + vars.DockerContainers = daemon.GetContainersList() if os.Getenv("AGENT") != "" { agent.SendInitRequest(vars.DockerContainers) diff --git a/application/backend/app/vars/vars.go b/application/backend/app/vars/vars.go index a8332e4..16c12ca 100644 --- a/application/backend/app/vars/vars.go +++ b/application/backend/app/vars/vars.go @@ -21,9 +21,9 @@ var ( Connections = map[string][]websocket.Conn{} Counters_For_Hosts_Last_30_Min = map[string]map[string]uint64{} Counters_For_Containers_Last_30_Min = map[string]map[string]uint64{} - FavsDB, _ = leveldb.OpenFile("leveldb/favourites", nil) - StateDB, _ = leveldb.OpenFile("leveldb/state", nil) - UsersDB, _ = leveldb.OpenFile("leveldb/users", nil) // should i ever close it? + FavsDB, FavsDBErr = leveldb.OpenFile("leveldb/favourites", nil) + StateDB, StateDBErr = leveldb.OpenFile("leveldb/state", nil) + UsersDB, UsersDBErr = leveldb.OpenFile("leveldb/users", nil) // should i ever close it? Year = strconv.Itoa(time.Now().UTC().Year()) ) From ff794abd18086bf8cddecb4c7490576bf7870e0f Mon Sep 17 00:00:00 2001 From: LbP22 Date: Wed, 8 Nov 2023 10:06:34 +0200 Subject: [PATCH 07/26] increase sleeps --- application/backend/app/daemon/daemon.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/application/backend/app/daemon/daemon.go b/application/backend/app/daemon/daemon.go index da48735..cb1a281 100644 --- a/application/backend/app/daemon/daemon.go +++ b/application/backend/app/daemon/daemon.go @@ -113,7 +113,6 @@ func CreateDaemonToDBStream(containerName string) { host := util.GetHost() createLogMessage(current_db, host, containerName, "ONLOGS: Container listening started!") - lastSleep := time.Now().Unix() defer current_db.Close() for { // reading body logLine, get_string_error := reader.ReadString('\n') @@ -145,10 +144,7 @@ func CreateDaemonToDBStream(containerName string) { c.WriteMessage(1, to_send) } - if time.Now().Unix()-lastSleep > 1 { - time.Sleep(10 * time.Millisecond) - lastSleep = time.Now().Unix() - } + time.Sleep(70 * time.Microsecond) } } @@ -175,7 +171,10 @@ func GetContainersList() []string { json.Unmarshal([]byte(body), &result) var names []string - containersDB, _ := leveldb.OpenFile("leveldb/hosts/"+util.GetHost()+"/containersMeta", nil) + containersDB, err := leveldb.OpenFile("leveldb/hosts/"+util.GetHost()+"/containersMeta", nil) + if err != nil { + panic(err) + } defer containersDB.Close() for i := 0; i < len(result); i++ { name := fmt.Sprintf("%v", result[i]["Names"].([]interface{})[0].(string))[1:] From d4364538b62c6bd5426c6d93082cfba3e41e1891 Mon Sep 17 00:00:00 2001 From: LbP22 Date: Wed, 8 Nov 2023 12:17:50 +0200 Subject: [PATCH 08/26] filtering by click on "Top 6 levels" item --- application/frontend/src/lib/Stats/Stats.scss | 4 ++++ application/frontend/src/lib/Stats/Stats.svelte | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/application/frontend/src/lib/Stats/Stats.scss b/application/frontend/src/lib/Stats/Stats.scss index 1810f78..394be2f 100644 --- a/application/frontend/src/lib/Stats/Stats.scss +++ b/application/frontend/src/lib/Stats/Stats.scss @@ -2,6 +2,10 @@ padding: 0; margin: 0 0 6px 0; font-size: $main-font-s; + cursor: pointer; + & :hover { + transform: scale(1.02); + } } .statsTittle { diff --git a/application/frontend/src/lib/Stats/Stats.svelte b/application/frontend/src/lib/Stats/Stats.svelte index bb11296..2c85f7f 100644 --- a/application/frontend/src/lib/Stats/Stats.svelte +++ b/application/frontend/src/lib/Stats/Stats.svelte @@ -3,6 +3,7 @@ lastChosenHost, lastChosenService, lastStatsPeriod, + chosenStatus } from "../../Stores/stores.js"; import fetchApi from "../../utils/fetch"; import { navigate } from "svelte-routing"; @@ -90,7 +91,14 @@ return 1; } }) as [key, name]} -
  • +
  • { + if ($chosenStatus !== key) { + chosenStatus.set(key); + } else { + chosenStatus.set(""); + } + }}>

    {key.charAt(0).toUpperCase() + key.slice(1)}

    {name}

  • From 4af49e38d2ba9301707a93fd0261997af30067f9 Mon Sep 17 00:00:00 2001 From: LbP22 Date: Thu, 9 Nov 2023 09:41:12 +0200 Subject: [PATCH 09/26] typo fixed --- application/backend/app/agent/agent.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/backend/app/agent/agent.go b/application/backend/app/agent/agent.go index 8c2a97b..224e852 100644 --- a/application/backend/app/agent/agent.go +++ b/application/backend/app/agent/agent.go @@ -46,7 +46,7 @@ func SendLogMessage(token string, container string, message_item []string) bool } func TryResend() { - token := os.Getenv("ONLOGS_TOKRN") + token := os.Getenv("ONLOGS_TOKEN") containers, _ := os.ReadDir("leveldb/hosts/" + util.GetHost() + "/containers/") for _, container := range containers { tmpDB := vars.BrokenLogs_DBs[container.Name()] From 8dc076e424a8e37dfc0c59daebf50887bffe7095 Mon Sep 17 00:00:00 2001 From: LbP22 Date: Thu, 9 Nov 2023 10:45:00 +0200 Subject: [PATCH 10/26] more debug --- application/backend/app/util/util.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/application/backend/app/util/util.go b/application/backend/app/util/util.go index 0c28013..378076d 100644 --- a/application/backend/app/util/util.go +++ b/application/backend/app/util/util.go @@ -90,9 +90,13 @@ func GetDB(host string, container string, dbType string) *leveldb.DB { path := "leveldb/hosts/" + host + "/containers/" + container + "/" + dbType res_db, err = leveldb.OpenFile(path, nil) if err != nil { - res_db, _ = leveldb.RecoverFile(path, nil) + res_db, err = leveldb.RecoverFile(path, nil) } } + if err != nil { + fmt.Println("ERROR: unable to open db for "+host+"/"+container+"/"+dbType, err) + } + return res_db } From d5949e9de65d2e5d7c88b6464b0a15686d54c1e3 Mon Sep 17 00:00:00 2001 From: LbP22 Date: Thu, 9 Nov 2023 10:45:12 +0200 Subject: [PATCH 11/26] hotfix for scrolling down --- application/frontend/src/Views/Logs/NewLogsV2.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/frontend/src/Views/Logs/NewLogsV2.svelte b/application/frontend/src/Views/Logs/NewLogsV2.svelte index 6292d7e..0748c5f 100644 --- a/application/frontend/src/Views/Logs/NewLogsV2.svelte +++ b/application/frontend/src/Views/Logs/NewLogsV2.svelte @@ -611,10 +611,10 @@ if (logsContEl) { logsContEl.addEventListener("scroll", function () { - let st = window.pageYOffset || logsContEl.scrollTop; + let st = window.scrollY || logsContEl.scrollTop; if (st > lastScrollTop) { scrollDirection = "down"; - } else { + } else if (st != lastScrollTop) { scrollDirection = "up"; } lastScrollTop = st <= 0 ? 0 : st; // For Mobile or negative scrolling From e97944fffc24fec0ce2347b205c9bda3be8de5c5 Mon Sep 17 00:00:00 2001 From: Ivan Borshchov Date: Wed, 13 Dec 2023 14:21:29 +0200 Subject: [PATCH 12/26] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index bd7e7e6..7af3eee 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,11 @@ ![Passing Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/LbP22/7a0933f8cba0bddbcc95c8b850e32663/raw/onlogs_passing__heads_main.json) ![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/LbP22/7a0933f8cba0bddbcc95c8b850e32663/raw/onlogs_units_coverage__heads_main.json) ![License Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/LbP22/7a0933f8cba0bddbcc95c8b850e32663/raw/license_MIT.json) +![image](https://github.com/devforth/OnLogs/assets/1838656/6742579c-a108-465f-9d97-0635a435c8a2) + + + + ### Benefits - πŸ”‘ Secure and simple way to access logs without server/ssh accession From 19521bb22a58ef88c3db8fce84a5b019cdd75f62 Mon Sep 17 00:00:00 2001 From: Ivan Borshchov Date: Wed, 13 Dec 2023 14:51:22 +0200 Subject: [PATCH 13/26] Update README.md --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7af3eee..f4e76c1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# OnLogs +# OnLogs - Logs accsess for any docker containers ![Passing Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/LbP22/7a0933f8cba0bddbcc95c8b850e32663/raw/onlogs_passing__heads_main.json) ![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/LbP22/7a0933f8cba0bddbcc95c8b850e32663/raw/onlogs_units_coverage__heads_main.json) ![License Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/LbP22/7a0933f8cba0bddbcc95c8b850e32663/raw/license_MIT.json) @@ -10,33 +10,33 @@ ### Benefits -- πŸ”‘ Secure and simple way to access logs without server/ssh accession -- πŸ—οΈ Built with Golang & Svelte.js to extract maximum performance and tiny bundle. Logs storage implemented on top of LevelDB -- 🧸 Setup is easy as docker run command/compose snippet +- πŸ”‘ Simple and secure way to access logs of any Docker containers without server/SSH connection +- πŸ—οΈ Built with Golang & Svelte.js to extract maximum performance and keep the image and RAM footprint as small as possible. Logs storage implemented on top of lightweight LevelDB +- 🧸 Installation is easy as docker runs command/compose snippet. HTTP port exposed and could be routed from Nginx/Traefik/Directly - πŸ–± Get every service realtime logs stream with 1 click -- πŸ“± Check logs from smartphone (insane, but we know it happens that you need it) -- 🧾 Open-Source commercial friendly MIT license +- πŸ“± Check logs from your smartphone (insane, but we know it happens that you need it) +- 🧾 Open-source, commercial-friendly MIT license - πŸ’Ύ Small size of Docker image (~ 13 MB) - πŸ‘₯ Share access to logs with team members, revoke any time ### Features -- πŸ’» One host can be used to view logs from all other hosts in case if you are running Cluster -- πŸ”— Share log messages to collegues via link +- πŸ’» One host can be used to view logs from all other hosts in case you are running Cluster +- πŸ”— Share log messages to colleagues via link - πŸ’½ Clear original docker logs to keep your storage size. - πŸ“Š Error/Info/Debug Statistics -- πŸ”Ž Search through logs (configurable case sensetivity) -- πŸ‘ View parameters (parsing JSON, show local/UTC time for every logline) +- πŸ”Ž Search through logs (configurable case sensitivity) +- πŸ‘ View parameters (parsing JSON, showing local/UTC time for every logline) - πŸ”΄ Realtime logs updating ### Roadmap - πŸ—‚ Grouping hosts -- 🏷 Search & Filter by tags (log status, time) +- 🏷 Search and filter by tags (log status, time) - πŸ”ŒPlugins and internal ability to notify about some event (e.g. notify when Error happens) - πŸ“Š Improved statistics -## Hello world & ussage +## Hello world & usage ### Docker Compose example with traefik ```sh onlogs: From 84ebb19650c136d8d9f9c54c0f212c19bcdc0665 Mon Sep 17 00:00:00 2001 From: Ivan Borshchov Date: Wed, 13 Dec 2023 14:52:03 +0200 Subject: [PATCH 14/26] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f4e76c1..ff8ff07 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -# OnLogs - Logs accsess for any docker containers +# OnLogs - Lightweight docker logs web viewer + ![Passing Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/LbP22/7a0933f8cba0bddbcc95c8b850e32663/raw/onlogs_passing__heads_main.json) ![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/LbP22/7a0933f8cba0bddbcc95c8b850e32663/raw/onlogs_units_coverage__heads_main.json) ![License Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/LbP22/7a0933f8cba0bddbcc95c8b850e32663/raw/license_MIT.json) From 88e37362db90fa5cb07882146cf80b43d3628a9b Mon Sep 17 00:00:00 2001 From: Ivan Borshchov Date: Wed, 13 Dec 2023 15:07:45 +0200 Subject: [PATCH 15/26] Update README.md --- README.md | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index ff8ff07..e80aeb7 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,7 @@ ![Passing Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/LbP22/7a0933f8cba0bddbcc95c8b850e32663/raw/onlogs_passing__heads_main.json) ![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/LbP22/7a0933f8cba0bddbcc95c8b850e32663/raw/onlogs_units_coverage__heads_main.json) ![License Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/LbP22/7a0933f8cba0bddbcc95c8b850e32663/raw/license_MIT.json) -![image](https://github.com/devforth/OnLogs/assets/1838656/6742579c-a108-465f-9d97-0635a435c8a2) - +![image](https://github.com/devforth/OnLogs/assets/1838656/38d0f184-3810-4389-a5af-2488b3a51276) @@ -44,20 +43,19 @@ image: devforth/onlogs restart: always environment: - - PASSWORD= - - PORT= - # - ONLOGS_PATH_PREFIX=/ if using with path prefix + - ADMIN_USERNAME=admin + - ADMIN_PASSWORD= + - PORT=8798 + # - ONLOGS_PATH_PREFIX=/onlogs if want to use with path prefix - ports: - - : labels: - "traefik.enable=true" - - "traefik.http.routers.onlogs.rule=Host(``)" # if using on subdomain - # - traefik.http.routers.onlogs.rule=PathPrefix(``) # if using with path prefix - - "traefik.http.services.onlogs.loadbalancer.server.port=" + - "traefik.http.routers.onlogs.rule=Host(``)" # if using on subdomain, e.g. https://onlogs.yourdomain.com + # - traefik.http.routers.onlogs.rule=PathPrefix(`/onlogs`) # if want to use with a path prefix, e.g. https://yourdomain.com/onlogs + - "traefik.http.services.onlogs.loadbalancer.server.port=8798" volumes: - /var/run/docker.sock:/var/run/docker.sock - - /var/lib/docker/containers:/var/lib/docker/containers # if you want to delete dublicating logs from docker + - /var/lib/docker/containers:/var/lib/docker/containers # if you want to delete duplicating logs from docker - /etc/hostname:/etc/hostname - onlogs-volume:/leveldb @@ -67,14 +65,14 @@ volumes: ### Docker Run example with traefik ```sh -docker run --restart always -e PASSWORD= -e PORT= \ +docker run --restart always -e ADMIN_USERNAME=admin -e PASSWORD= -e PORT=8798 \ -v /var/run/docker.sock:/var/run/docker.sock:ro \ -v /var/lib/docker/containers:/var/lib/docker/containers \ -v /etc/hostname:/etc/hostname \ -v onlogs-volume:/leveldb \ --label traefik.enable=true \ --label traefik.http.routers.onlogs.rule=Host\(\`\`\) \ - --label traefik.http.services.onlogs.loadbalancer.server.port=2874 devforth/onlogs + --label traefik.http.services.onlogs.loadbalancer.server.port=8798 devforth/onlogs ``` Once done, just go to and login as "admin" with . @@ -82,10 +80,11 @@ Once done, just go to and login as "admin" with . ## Available Environment Options: | Environment Variable | Description | Defaults | Required | |----------------------------|---------------------------------|--------|-----------------| -| PASSWORD | Password for default user | | if `AGENT=false` +| ADMIN_USERNAME | Username for initial user | `admin` | if `AGENT=false` +| ADMIN_PASSWORD | Password for initial user | | if `AGENT=false` | PORT | Port to listen on | `2874` | if `AGENT=false` | JWT_SECRET | Secret for JWT tokens for users | Generates randomly | - | ONLOGS_PATH_PREFIX | Base path if you using OnLogs not on subdomain | | only if using on path prefix -| AGENT | Toggles agent mode. If enabled, there will be no web interface available and all logs will be sent and stored on HOST | `false` | - +| AGENT | Toggles agent mode. If enabled, there will be no web interface available, and all logs will be sent and stored on HOST | `false` | - | HOST | Url to OnLogs host from protocol to domain name. | | if `AGENT=true` -| ONLOGS_TOKEN | Token that will use agent to authorize and connect to HOST | Generates with OnLogs interface | if `AGENT=true` +| ONLOGS_TOKEN | Token that will use an agent to authorize and connect to HOST | Generates with OnLogs interface | if `AGENT=true` From 36be539ff8722cf3f2df8048d8c77267f4f65d50 Mon Sep 17 00:00:00 2001 From: LbP22 Date: Tue, 26 Dec 2023 11:07:47 +0200 Subject: [PATCH 16/26] ADMIN_USERNAME usage with default as "admin" --- application/backend/app/routes/routes.go | 4 ++-- application/backend/app/util/util.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/application/backend/app/routes/routes.go b/application/backend/app/routes/routes.go index 6eb5c08..a125940 100644 --- a/application/backend/app/routes/routes.go +++ b/application/backend/app/routes/routes.go @@ -40,7 +40,7 @@ func enableCors(w *http.ResponseWriter) { func verifyAdminUser(w *http.ResponseWriter, req *http.Request) bool { username, err := util.GetUserFromJWT(*req) - if username != "admin" { + if username != os.Getenv("ADMIN_USERNAME") { (*w).WriteHeader(http.StatusForbidden) json.NewEncoder(*w).Encode(map[string]string{"error": "Only admin can perform this request"}) return false @@ -736,7 +736,7 @@ func DeleteUser(w http.ResponseWriter, req *http.Request) { } decoder := json.NewDecoder(req.Body) decoder.Decode(&loginData) - if loginData.Login == "admin" { + if loginData.Login == os.Getenv("ADMIN_USERNAME") { w.Header().Add("Content-Type", "application/json") json.NewEncoder(w).Encode(map[string]string{"error": "Can't delete admin"}) return diff --git a/application/backend/app/util/util.go b/application/backend/app/util/util.go index 378076d..a9e66e4 100644 --- a/application/backend/app/util/util.go +++ b/application/backend/app/util/util.go @@ -46,7 +46,12 @@ func Contains(a string, list []string) bool { } func CreateInitUser() { - vars.UsersDB.Put([]byte("admin"), []byte(os.Getenv("PASSWORD")), nil) + admin_username := os.Getenv("ADMIN_USERNAME") + if admin_username == "" { + admin_username = "admin" + os.Setenv("ADMIN_USERNAME", admin_username) + } + vars.UsersDB.Put([]byte(admin_username), []byte(os.Getenv("ADMIN_PASSWORD")), nil) } func ReplacePrefixVariableForFrontend() { From 54bc46158195f589bb3026d96fa748e3be68c0b8 Mon Sep 17 00:00:00 2001 From: LbP22 Date: Tue, 26 Dec 2023 15:50:47 +0200 Subject: [PATCH 17/26] using buildx --- application/build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/build.sh b/application/build.sh index 9ae4de2..a79e1a8 100644 --- a/application/build.sh +++ b/application/build.sh @@ -1,2 +1,2 @@ -docker build . -t devforth/onlogs -docker push devforth/onlogs +docker buildx create --use +docker buildx build --platform=linux/amd64,linux/arm64 --tag "devforth/onlogs:latest" --tag "devforth/onlogs:1.0.1" --push . From 15ed33e149ed623b1511b2f707794626aa487fc1 Mon Sep 17 00:00:00 2001 From: LbP22 Date: Tue, 26 Dec 2023 15:50:53 +0200 Subject: [PATCH 18/26] using buildx --- application/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/build.sh b/application/build.sh index a79e1a8..f2c7f59 100644 --- a/application/build.sh +++ b/application/build.sh @@ -1,2 +1,2 @@ docker buildx create --use -docker buildx build --platform=linux/amd64,linux/arm64 --tag "devforth/onlogs:latest" --tag "devforth/onlogs:1.0.1" --push . +docker buildx build --platform=linux/amd64,linux/arm64 --tag "devforth/onlogs:latest" --tag "devforth/onlogs:1.0.0" --push . From 539fb7e918afb3ab367a3f4ff8c3022460c80ca5 Mon Sep 17 00:00:00 2001 From: LbP22 Date: Wed, 27 Dec 2023 13:20:54 +0200 Subject: [PATCH 19/26] removed expose --- application/Dockerfile | 2 -- application/build.sh | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/application/Dockerfile b/application/Dockerfile index be8a233..d1cb6d5 100644 --- a/application/Dockerfile +++ b/application/Dockerfile @@ -29,8 +29,6 @@ FROM alpine RUN apk add bash curl # tmp -EXPOSE 2874 - COPY --from=frontbuilder /code/dist/ /dist/ COPY --from=backendbuilder /backend/main /backend/main CMD ["/backend/main"] diff --git a/application/build.sh b/application/build.sh index f2c7f59..a79e1a8 100644 --- a/application/build.sh +++ b/application/build.sh @@ -1,2 +1,2 @@ docker buildx create --use -docker buildx build --platform=linux/amd64,linux/arm64 --tag "devforth/onlogs:latest" --tag "devforth/onlogs:1.0.0" --push . +docker buildx build --platform=linux/amd64,linux/arm64 --tag "devforth/onlogs:latest" --tag "devforth/onlogs:1.0.1" --push . From 522f1fc85665606bb1a6c65b41b6cfe307eead31 Mon Sep 17 00:00:00 2001 From: LbP22 Date: Wed, 27 Dec 2023 15:54:49 +0200 Subject: [PATCH 20/26] can't edit admin user --- application/backend/app/routes/routes.go | 6 ++++++ application/build.sh | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/application/backend/app/routes/routes.go b/application/backend/app/routes/routes.go index a125940..086d160 100644 --- a/application/backend/app/routes/routes.go +++ b/application/backend/app/routes/routes.go @@ -634,6 +634,12 @@ func EditUser(w http.ResponseWriter, req *http.Request) { decoder := json.NewDecoder(req.Body) decoder.Decode(&loginData) + if loginData.Login == os.Getenv("ADMIN_USERNAME") { + w.Header().Add("Content-Type", "application/json") + json.NewEncoder(w).Encode(map[string]string{"error": "Can't edit admin. Use env variables to change admin username and password"}) + return + } + if !userdb.IsUserExists(loginData.Login) { json.NewEncoder(w).Encode(map[string]string{"error": "No such user"}) return diff --git a/application/build.sh b/application/build.sh index a79e1a8..79221de 100644 --- a/application/build.sh +++ b/application/build.sh @@ -1,2 +1,2 @@ docker buildx create --use -docker buildx build --platform=linux/amd64,linux/arm64 --tag "devforth/onlogs:latest" --tag "devforth/onlogs:1.0.1" --push . +docker buildx build --platform=linux/amd64,linux/arm64 --tag "devforth/onlogs:latest" --tag "devforth/onlogs:1.0.2" --push . From 65566d7e6f26b4a552f6995333b47b626927f1de Mon Sep 17 00:00:00 2001 From: LbP22 Date: Thu, 28 Dec 2023 09:29:09 +0200 Subject: [PATCH 21/26] don't return main user to front, because it can't be edited --- application/backend/app/userdb/userdb.go | 4 ++++ application/build.sh | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/application/backend/app/userdb/userdb.go b/application/backend/app/userdb/userdb.go index 6a86324..c5b6139 100644 --- a/application/backend/app/userdb/userdb.go +++ b/application/backend/app/userdb/userdb.go @@ -3,6 +3,7 @@ package userdb import ( "encoding/json" "errors" + "os" "strings" "github.com/devforth/OnLogs/app/vars" @@ -27,6 +28,9 @@ func GetUsers() []string { users := []string{} iter := vars.UsersDB.NewIterator(nil, nil) for iter.Next() { + if string(iter.Key()) == os.Getenv("ADMIN_USERNAME") { + continue + } users = append(users, string(iter.Key())) } defer iter.Release() diff --git a/application/build.sh b/application/build.sh index 79221de..c10ea9c 100644 --- a/application/build.sh +++ b/application/build.sh @@ -1,2 +1,2 @@ docker buildx create --use -docker buildx build --platform=linux/amd64,linux/arm64 --tag "devforth/onlogs:latest" --tag "devforth/onlogs:1.0.2" --push . +docker buildx build --platform=linux/amd64,linux/arm64 --tag "devforth/onlogs:latest" --tag "devforth/onlogs:1.0.3" --push . From 025b4eed6850d5a1ae5b09c31d4a3f54f0505df0 Mon Sep 17 00:00:00 2001 From: LbP22 Date: Thu, 28 Dec 2023 15:53:05 +0200 Subject: [PATCH 22/26] styling, texts upd --- application/build.sh | 2 +- .../frontend/src/Views/Main/Main.svelte | 2 +- .../ConfirmationMenu/ConfirmationMenu.scss | 5 +- .../ConfirmationMenu/ConfirmationMenu.svelte | 34 +++++----- application/frontend/src/lib/Modal/Modal.scss | 4 +- .../frontend/src/lib/UserMenu/UserMenu.scss | 2 +- .../frontend/src/lib/UserMenu/UserMenu.svelte | 64 ++++++++++--------- 7 files changed, 59 insertions(+), 54 deletions(-) diff --git a/application/build.sh b/application/build.sh index c10ea9c..16d4006 100644 --- a/application/build.sh +++ b/application/build.sh @@ -1,2 +1,2 @@ docker buildx create --use -docker buildx build --platform=linux/amd64,linux/arm64 --tag "devforth/onlogs:latest" --tag "devforth/onlogs:1.0.3" --push . +docker buildx build --platform=linux/amd64,linux/arm64 --tag "devforth/onlogs:latest" --tag "devforth/onlogs:1.0.4" --push . diff --git a/application/frontend/src/Views/Main/Main.svelte b/application/frontend/src/Views/Main/Main.svelte index bbaaa71..eee4938 100644 --- a/application/frontend/src/Views/Main/Main.svelte +++ b/application/frontend/src/Views/Main/Main.svelte @@ -262,7 +262,7 @@
    diff --git a/application/frontend/src/lib/ConfirmationMenu/ConfirmationMenu.scss b/application/frontend/src/lib/ConfirmationMenu/ConfirmationMenu.scss index 8e6902d..84c2858 100644 --- a/application/frontend/src/lib/ConfirmationMenu/ConfirmationMenu.scss +++ b/application/frontend/src/lib/ConfirmationMenu/ConfirmationMenu.scss @@ -27,9 +27,6 @@ .boldText { font-weight: 800; } - .confirmationText { - margin: 20px 0 0 0; - } .deleteModalTitle { margin-top: 16px; @@ -41,7 +38,7 @@ display: flex; flex-direction: column; margin-top: 24px; - margin-bottom: 48px; + margin-bottom: 24px; align-items: center; } diff --git a/application/frontend/src/lib/ConfirmationMenu/ConfirmationMenu.svelte b/application/frontend/src/lib/ConfirmationMenu/ConfirmationMenu.svelte index b494fe6..a7cda00 100644 --- a/application/frontend/src/lib/ConfirmationMenu/ConfirmationMenu.svelte +++ b/application/frontend/src/lib/ConfirmationMenu/ConfirmationMenu.svelte @@ -14,7 +14,7 @@ import Checkbox from "../CheckBox/Checkbox.svelte"; import fetchApi from "../../utils/fetch.js"; - let confirmationWord = "I understand that data will be lost"; + let confirmationWord = "I understand that logs will be lost"; let tipsIsVisible = false; let inputValue = ""; let error = false; @@ -79,10 +79,9 @@ /> {#if tipsIsVisible}
    - Delete Docker logs - when the option is - disabled - you can only delete duplicates of logs, that onLogs uses to present logs - to you. Logs will be available in docker containers, but not for onLogs. + Delete Docker logs - when the option is set to + "OFF" + logs will be deleted only from onLogs. Logs will be available in docker containers, but not for onLogs. When enabled , each deletion of logs will clear logs from both onLogs and the @@ -101,22 +100,25 @@
    -

    - {`You want to delete logs. Host: ${ +

    + {`Host: ${ $lastChosenHost ? $lastChosenHost : "host" - } service:${ - $lastChosenService ? $lastChosenService : "service" - } from: `} - - {$confirmationObj.message} + }`}

    -

    This data will be lost. This action cannot be undone.

    +

    + {`Service: ${ + $lastChosenService ? $lastChosenService : "service" + }, from: `} + + {$confirmationObj.message} +

    +

    This data will be lost. This action cannot be undone.

    - Please type:" {confirmationWord}" to confirm.
    diff --git a/application/frontend/src/lib/Modal/Modal.scss b/application/frontend/src/lib/Modal/Modal.scss index 234e6a5..f87bbed 100644 --- a/application/frontend/src/lib/Modal/Modal.scss +++ b/application/frontend/src/lib/Modal/Modal.scss @@ -1,5 +1,7 @@ .modalContainer { - min-width: 450px; +// min-width: 40vw; + max-width: 86vw; +// min-width: 40vw; min-height: min-content; background-color: $background-color; diff --git a/application/frontend/src/lib/UserMenu/UserMenu.scss b/application/frontend/src/lib/UserMenu/UserMenu.scss index 8e0083f..c4610bd 100644 --- a/application/frontend/src/lib/UserMenu/UserMenu.scss +++ b/application/frontend/src/lib/UserMenu/UserMenu.scss @@ -112,7 +112,7 @@ table { box-sizing: border-box; font-size: $main-font-m; border: 1px solid $lines-color; - margin-top: 42px; + margin-top: 20px; border: 1px solid $text-placeholder-color; color: $text-dark-color; diff --git a/application/frontend/src/lib/UserMenu/UserMenu.svelte b/application/frontend/src/lib/UserMenu/UserMenu.svelte index 22452f4..bd58321 100644 --- a/application/frontend/src/lib/UserMenu/UserMenu.svelte +++ b/application/frontend/src/lib/UserMenu/UserMenu.svelte @@ -161,15 +161,15 @@ class="buttonSpan" on:click={() => { setChosenUserLogin(user); - showUserDeleting(); - }}>