dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit df14eb83bc65e58f08e66d16bb69995cf1368171
parent 1c088f19133b66f73b4296fab6c065b24881f528
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu, 14 Dec 2023 05:55:46 -0500

toggle withdraw enabled setting

Diffstat:
Acmd/dkf/migrations/151.sql | 4++++
Mpkg/actions/actions.go | 1+
Mpkg/config/config.go | 1+
Mpkg/database/tableSettings.go | 25+++++++++++++------------
Mpkg/web/handlers/admin.go | 3+++
Mpkg/web/handlers/data.go | 23++++++++++++-----------
Mpkg/web/handlers/handlers.go | 5+++++
Mpkg/web/public/views/pages/admin/settings.gohtml | 7+++++++
8 files changed, 46 insertions(+), 23 deletions(-)

diff --git a/cmd/dkf/migrations/151.sql b/cmd/dkf/migrations/151.sql @@ -0,0 +1,4 @@ +-- +migrate Up +ALTER TABLE settings ADD COLUMN poker_withdraw_enabled TINYINT(1) NOT NULL DEFAULT 1; + +-- +migrate Down diff --git a/pkg/actions/actions.go b/pkg/actions/actions.go @@ -75,6 +75,7 @@ func Start(c *cli.Context) error { config.SilentSelfKick.Store(settings.SilentSelfKick) config.MaybeAuthEnabled.Store(settings.MaybeAuthEnabled) config.PowEnabled.Store(settings.PowEnabled) + config.PokerWithdrawEnabled.Store(settings.PokerWithdrawEnabled) config.CaptchaDifficulty.Store(settings.CaptchaDifficulty) config.Xmr() diff --git a/pkg/config/config.go b/pkg/config/config.go @@ -72,6 +72,7 @@ var ( SilentSelfKick = atom.NewBool(true) // either or not self kick are silent SignupEnabled = atom.NewBool(true) // either or not people can sign up PowEnabled = atom.NewBool(false) // either or not pow is enabled to signup + PokerWithdrawEnabled = atom.NewBool(true) // either or not poker withdraw is enabled SignupFakeEnabled = atom.NewBool(true) // either or not signup is faked to be enabled ProtectHome = atom.NewBool(true) // enable "dynamic login url" to prevent ddos on the login page HomeUsersList = atom.NewBool(true) // either or not to display the online users on the login page diff --git a/pkg/database/tableSettings.go b/pkg/database/tableSettings.go @@ -4,18 +4,19 @@ import "github.com/sirupsen/logrus" // Settings table, should always be one row type Settings struct { - ID int64 - MaybeAuthEnabled bool // either or not unauthenticated users can access the "maybe auth" pages - SilentSelfKick bool // either or not people can use the forum features - ForumEnabled bool // either or not people can use the forum features - SignupEnabled bool // either or not people can sign up - SignupFakeEnabled bool // either or not signup is faked to be enabled - ProtectHome bool // ... - HomeUsersList bool // ... - ForceLoginCaptcha bool // either or not people are forced to complete captcha at login - DownloadsEnabled bool // either or not people can download files - CaptchaDifficulty int64 // captcha difficulty - PowEnabled bool + ID int64 + MaybeAuthEnabled bool // either or not unauthenticated users can access the "maybe auth" pages + SilentSelfKick bool // either or not people can use the forum features + ForumEnabled bool // either or not people can use the forum features + SignupEnabled bool // either or not people can sign up + SignupFakeEnabled bool // either or not signup is faked to be enabled + ProtectHome bool // ... + HomeUsersList bool // ... + ForceLoginCaptcha bool // either or not people are forced to complete captcha at login + DownloadsEnabled bool // either or not people can download files + PokerWithdrawEnabled bool // either or not poker withdraw is enabled + CaptchaDifficulty int64 // captcha difficulty + PowEnabled bool } // GetSettings get the saved settings from the DB diff --git a/pkg/web/handlers/admin.go b/pkg/web/handlers/admin.go @@ -259,6 +259,7 @@ func AdminSettingsHandler(c echo.Context) error { data.MaybeAuthEnabled = settings.MaybeAuthEnabled data.CaptchaDifficulty = settings.CaptchaDifficulty data.PowEnabled = settings.PowEnabled + data.PokerWithdrawEnabled = settings.PokerWithdrawEnabled if c.Request().Method == http.MethodPost { formName := c.Request().PostFormValue("formName") @@ -280,6 +281,7 @@ func AdminSettingsHandler(c echo.Context) error { settings.MaybeAuthEnabled = utils.DoParseBool(c.Request().PostFormValue("maybeAuthEnabled")) settings.CaptchaDifficulty = utils.DoParseInt64(c.Request().PostFormValue("captchaDifficulty")) settings.PowEnabled = utils.DoParseBool(c.Request().PostFormValue("powEnabled")) + settings.PokerWithdrawEnabled = utils.DoParseBool(c.Request().PostFormValue("pokerWithdrawEnabled")) settings.DoSave(db) config.ProtectHome.Store(settings.ProtectHome) config.HomeUsersList.Store(settings.HomeUsersList) @@ -287,6 +289,7 @@ func AdminSettingsHandler(c echo.Context) error { config.SignupEnabled.Store(settings.SignupEnabled) config.CaptchaDifficulty.Store(settings.CaptchaDifficulty) config.PowEnabled.Store(settings.PowEnabled) + config.PokerWithdrawEnabled.Store(settings.PokerWithdrawEnabled) config.SignupFakeEnabled.Store(settings.SignupFakeEnabled) config.DownloadsEnabled.Store(settings.DownloadsEnabled) config.ForumEnabled.Store(settings.ForumEnabled) diff --git a/pkg/web/handlers/data.go b/pkg/web/handlers/data.go @@ -546,17 +546,18 @@ type adminCaptchaData struct { } type adminSettingsData struct { - ActiveTab string - ProtectHome bool - HomeUsersList bool - ForceLoginCaptcha bool - SignupEnabled bool - SignupFakeEnabled bool - DownloadsEnabled bool - ForumEnabled bool - MaybeAuthEnabled bool - PowEnabled bool - CaptchaDifficulty int64 + ActiveTab string + ProtectHome bool + HomeUsersList bool + ForceLoginCaptcha bool + SignupEnabled bool + SignupFakeEnabled bool + DownloadsEnabled bool + ForumEnabled bool + MaybeAuthEnabled bool + PowEnabled bool + PokerWithdrawEnabled bool + CaptchaDifficulty int64 } type settingsPGPData struct { diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -790,6 +790,11 @@ func PokerHomeHandler(c echo.Context) error { return c.Render(http.StatusOK, "poker", data) } + if config.PokerWithdrawEnabled.IsFalse() { + data.Error = "withdraw temporarily disabled" + return c.Render(http.StatusOK, "poker", data) + } + withdrawAmount := database.Piconero(utils.DoParseUint64(c.Request().PostFormValue("withdraw_amount"))) data.WithdrawAmount = withdrawAmount data.WithdrawAddress = c.Request().PostFormValue("withdraw_address") diff --git a/pkg/web/public/views/pages/admin/settings.gohtml b/pkg/web/public/views/pages/admin/settings.gohtml @@ -87,6 +87,13 @@ </div> <label class="form-check-label" for="powEnabled">Proof of work enabled</label> </div> + <div class="form-check form-check-1"> + <div class="checkbox-wrapper form-check-input"> + <input class="my-cbx" type="checkbox" name="pokerWithdrawEnabled" id="pokerWithdrawEnabled" value="1"{{ if .Data.PokerWithdrawEnabled }} checked{{ end }} /> + <label for="pokerWithdrawEnabled" class="toggle"><span></span></label> + </div> + <label class="form-check-label" for="pokerWithdrawEnabled">Poker withdraw enabled</label> + </div> <div> <label class="form-check-label" for="captchaDifficulty">Captcha difficulty</label> <select name="captchaDifficulty" id="captchaDifficulty">