From 167fc07c8aab4b6b40f61b7f49eb94ab75e39388 Mon Sep 17 00:00:00 2001 From: ThomasTJdev Date: Fri, 23 Feb 2024 09:19:40 +0100 Subject: [PATCH 1/5] Fix backward compability from PR145 --- nimwc.nim | 3 ++- nimwc.nimble | 7 +++++-- nimwcpkg/nimwc_main.nim | 5 ++++- nimwcpkg/webs/routes.nim | 12 +++++++++--- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/nimwc.nim b/nimwc.nim index 7abfd933f..2f38b174e 100644 --- a/nimwc.nim +++ b/nimwc.nim @@ -225,8 +225,9 @@ proc startupCheck(cfg: Config) = if not fileExists(appPath) or defined(rc): # Ensure that the DB tables are created echo compile_start_msg & userArgs & "\n\n" + let nimv2 = if NimMajor >= 2: " --mm:orc " else: "" - let (output, exitCode) = execCmdEx("nim c --out:" & appPath & " " & compileOptions & " " & getAppDir() & "/nimwcpkg/nimwc_main.nim") + let (output, exitCode) = execCmdEx("nim c --out:" & appPath & " " & compileOptions & " " & nimv2& " " & getAppDir() & "/nimwcpkg/nimwc_main.nim") if exitCode != 0: styledEcho(fgRed, bgBlack, compile_fail_msg) echo output diff --git a/nimwc.nimble b/nimwc.nimble index cb295efd9..e80a4f616 100644 --- a/nimwc.nimble +++ b/nimwc.nimble @@ -12,15 +12,18 @@ installDirs = @["config", "nimwcpkg", "plugins", "public"] when NimMajor >= 2: requires "db_connector >= 0.1.0" requires "smtp >= 0.1.0" + requires "https://github.com/ThomasTJdev/otp.nim == 0.3.3" + requires "https://github.com/ThomasTJdev/jester_fork >= 1.0.0" +else: + requires "https://github.com/ThomasTJdev/otp.nim == 0.1.5" + requires "jester >= 0.4.3" # Dependencies requires "nim >= 1.6.0" -requires "jester >= 0.4.3" requires "bcrypt >= 0.2.1" requires "datetime2human >= 0.2.5" requires "firejail >= 0.5.0" -requires "otp >= 0.1.1" requires "recaptcha >= 1.0.3" requires "webp >= 0.2.5" requires "packedjson >= 0.1.0" diff --git a/nimwcpkg/nimwc_main.nim b/nimwcpkg/nimwc_main.nim index 87a98ab55..9e983fe6e 100644 --- a/nimwcpkg/nimwc_main.nim +++ b/nimwcpkg/nimwc_main.nim @@ -316,7 +316,10 @@ proc login(c: var TData, email, pass, totpRaw: string): tuple[isLoginOk: bool, s if totp in [000000, 111111, 222222, 333333, 444444, 555555, 666666, 777777, 888888, 999999]: return (false, "2 Factor Authentication Number must not be 6 identical digits") - let totpServerSide = $(Totp.init(row[7]).now()) + when NimMajor >= 2: + let totpServerSide = $(Totp.init(row[7]).now()) + else: + let totpServerSide = $(newTotp(row[7]).now()) when not defined(release): echo "TOTP SERVER: " & totpServerSide echo "TOTP USER : " & $totp diff --git a/nimwcpkg/webs/routes.nim b/nimwcpkg/webs/routes.nim index d34ecd38d..05cb6d6f3 100644 --- a/nimwcpkg/webs/routes.nim +++ b/nimwcpkg/webs/routes.nim @@ -556,10 +556,16 @@ routes: restrictTestuser(HttpGet) if unlikely(not c.loggedIn): redirect("/") try: - if $(Totp.init(@"twofakey").now()) == @"testcode": - resp("Success, the code matched") + when NimMajor >= 2: + if $(Totp.init(@"twofakey").now()) == @"testcode": + resp("Success, the code matched") + else: + resp("Error, code did not match") else: - resp("Error, code did not match") + if $(newTotp(@"twofakey").now()) == @"testcode": + resp("Success, the code matched") + else: + resp("Error, code did not match") except: resp("Error generating 2FA") From 0d1418d6e9997a65dd97934bbe4e9d1838707c62 Mon Sep 17 00:00:00 2001 From: ThomasTJdev Date: Fri, 23 Feb 2024 09:19:56 +0100 Subject: [PATCH 2/5] GH actions: Full build --- .github/workflows/build.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 94b77d10e..999cc6c5b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,7 +41,10 @@ jobs: run: nimble build - name: Compile RELEASE Mode - run: nimble build -d:release + run: | + nimble build -d:release + cp config/config_default.cfg config/config.cfg + ./nimwc - name: Nimble install run: nimble install \ No newline at end of file From e9b1b7c917ba87b177a0f13e361ee4e6a7c5008d Mon Sep 17 00:00:00 2001 From: ThomasTJdev Date: Fri, 23 Feb 2024 09:23:22 +0100 Subject: [PATCH 3/5] Fix jester import --- nimwcpkg/nimwc_main.nim | 6 +++++- nimwcpkg/sessions/sessions.nim | 6 +++++- nimwcpkg/webs/routes.nim | 5 ++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/nimwcpkg/nimwc_main.nim b/nimwcpkg/nimwc_main.nim index 9e983fe6e..06bb3fbae 100644 --- a/nimwcpkg/nimwc_main.nim +++ b/nimwcpkg/nimwc_main.nim @@ -24,9 +24,13 @@ import import bcrypt, datetime2human, - jester, otp +when NimMajor > 2: + import jester_fork +else: + import jester + import constants/constants, enums/enums, databases/databases, emails/emails, files/files, passwords/passwords, sessions/sessions, utils/loggers, plugins/plugins, webs/html_utils diff --git a/nimwcpkg/sessions/sessions.nim b/nimwcpkg/sessions/sessions.nim index 7d4f69d8c..1463c7f8e 100644 --- a/nimwcpkg/sessions/sessions.nim +++ b/nimwcpkg/sessions/sessions.nim @@ -1,6 +1,10 @@ -from jester import Request +when NimMajor > 2: + from jester_fork import Request +else: + from jester import Request + type Rank* = enum ## Rank for the User. User diff --git a/nimwcpkg/webs/routes.nim b/nimwcpkg/webs/routes.nim index 05cb6d6f3..dae3ed9c8 100644 --- a/nimwcpkg/webs/routes.nim +++ b/nimwcpkg/webs/routes.nim @@ -26,7 +26,10 @@ routes: let (loginB, loginS) = login(c, replace(toLowerAscii(@"email"), " ", ""), replace(@"password", " ", ""), replace(@"totp", " ", "")) when defined(dev): echo("\nMail: ", @"email", "\nPassword2 (HoneyPot): ", @"password2", "\n(loginB, loginS): ", (loginB, loginS)) if loginB: - jester.setCookie("sid", loginS, daysForward(7)) + when NimMajor > 2: + jester_fork.setCookie("sid", loginS, daysForward(7)) + else: + jester.setCookie("sid", loginS, daysForward(7)) redirect("/settings") else: redirect("/login?msg=" & encodeUrl(loginS)) From 76c51f952c08308e24590054ef4ef53cef542a4a Mon Sep 17 00:00:00 2001 From: ThomasTJdev Date: Fri, 23 Feb 2024 09:23:36 +0100 Subject: [PATCH 4/5] Only build on 1.6 - not supporting v2 yet --- .github/workflows/build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 999cc6c5b..a197a8063 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,8 @@ jobs: #- windows-latest #- macOS-latest version: - - stable + - 1.6.18 + # - stable steps: - uses: actions/checkout@v1 From 3b8e71e18778a1a824d44ebaac932142f8a10925 Mon Sep 17 00:00:00 2001 From: ThomasTJdev Date: Fri, 23 Feb 2024 09:32:19 +0100 Subject: [PATCH 5/5] Quit after compile for GH actions compliance --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 8 ++++++-- nimwc.nim | 11 +++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a197a8063..6b792df53 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,7 +45,7 @@ jobs: run: | nimble build -d:release cp config/config_default.cfg config/config.cfg - ./nimwc + ./nimwc --quitAfterCompile - name: Nimble install run: nimble install \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 659deb90b..10fabb74c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,7 +16,8 @@ jobs: #- windows-latest #- macOS-latest version: - - stable + - 1.6.18 + # - stable steps: - uses: actions/checkout@v2 @@ -37,7 +38,10 @@ jobs: run: nimble -y install --depsOnly - name: Build binaries - run: nimble build -d:release + run: | + nimble build -d:release + cp config/config_default.cfg config/config.cfg + ./nimwc --quitAfterCompile - name: Archive Release uses: papeloto/action-zip@v1 diff --git a/nimwc.nim b/nimwc.nim index 2f38b174e..883fb850b 100644 --- a/nimwc.nim +++ b/nimwc.nim @@ -227,7 +227,7 @@ proc startupCheck(cfg: Config) = echo compile_start_msg & userArgs & "\n\n" let nimv2 = if NimMajor >= 2: " --mm:orc " else: "" - let (output, exitCode) = execCmdEx("nim c --out:" & appPath & " " & compileOptions & " " & nimv2& " " & getAppDir() & "/nimwcpkg/nimwc_main.nim") + let (output, exitCode) = execCmdEx("nim c --out:" & appPath & " " & compileOptions & " " & nimv2 & " " & getAppDir() & "/nimwcpkg/nimwc_main.nim") if exitCode != 0: styledEcho(fgRed, bgBlack, compile_fail_msg) echo output @@ -248,6 +248,8 @@ when isMainModule: when defined(dev): echo($compileOptions, "\n\n") + var quitAfterCompile = false + for keysType, keys, values in getopt(): case keysType of cmdShortOption, cmdLongOption: @@ -280,6 +282,8 @@ when isMainModule: echo backupDb(cfg.getSectionValue("Database", when defined(postgres): "name" else: "host"), checksum=false, sign=false, targz=false) of "backuplogs": echo backupOldLogs(splitPath(cfg.getSectionValue("Logging", when defined(release): "logfile" else: "logfiledev")).head) + of "quitAfterCompile": + quitAfterCompile = true of cmdArgument: discard @@ -287,8 +291,11 @@ when isMainModule: of cmdEnd: quit("Wrong arguments, please see help with: --help", 1) - if keys.len != 0: + if keys.len != 0 and not quitAfterCompile: quit("Run again with no arguments, please see help with: --help", 0) startupCheck(cfg) + if quitAfterCompile: + sleep(1000) launcherActivated(cfg) +