From 451492fa20f772a28982bdec180bdd1b2a2d6404 Mon Sep 17 00:00:00 2001 From: itwrx Date: Sun, 18 May 2025 10:52:58 -0500 Subject: [PATCH] make hardcoded values release friendly --- fmn_gs.nim | 4 +- helpers/datetime.nim | 2 - helpers/global.nim | 13 +++---- helpers/reminder.nim | 13 ++++--- models/human_checker.nim | 38 ------------------- post_handlers/send_reminders_post_handler.nim | 2 +- post_handlers/user_session_post_handler.nim | 2 +- 7 files changed, 18 insertions(+), 56 deletions(-) delete mode 100644 models/human_checker.nim diff --git a/fmn_gs.nim b/fmn_gs.nim index d442f74..874a358 100644 --- a/fmn_gs.nim +++ b/fmn_gs.nim @@ -85,6 +85,6 @@ proc handlePost() = let getserver = newHttpServer(handleGet, headerfields = ["cookie", "cookie"]) let postserver = newHttpServer(handlePost, loglevel = INFO, headerfields = ["origin", "cookie", "referer"]) -if not epolldispatcher.start(getserver, 8096): quit() -if not epolldispatcher.start(postserver, 8097, threadpoolsize = 20): quit() +if not epolldispatcher.start(getserver, 5050): quit() +if not epolldispatcher.start(postserver, 5051, threadpoolsize = 20): quit() joinThreads(getserver.thread, postserver.thread) diff --git a/helpers/datetime.nim b/helpers/datetime.nim index 57af835..8597d30 100644 --- a/helpers/datetime.nim +++ b/helpers/datetime.nim @@ -69,12 +69,10 @@ proc nextMonthlyOnWeekdayOfWeek*(weekdayString: string, ocurrence: string): Date let nextMonthsDate = now() + 1.months let weekNumStrings = @["1", "2", "3"] if ocurrence in weekNumStrings: - #nextSendDate = nthWeekdayInMonth(year(nextMonthsDate), month(now()), weekdayString, parseInt(ocurrence)) nextSendDate = nthWeekdayInMonth(year(now()), month(now()), weekdayString, parseInt(ocurrence)) if format(nextSendDate, "yyyy-MM-dd") <= format(now(), "yyyy-MM-dd"): nextSendDate = nthWeekdayInMonth(year(nextMonthsDate), month(nextMonthsDate), weekdayString, parseInt(ocurrence)) else: - #nextSendDate = lastWeekdayInMonth(year(nextMonthsDate), month(now()), weekdayString) nextSendDate = lastWeekdayInMonth(year(now()), month(now()), weekdayString) if format(nextSendDate, "yyyy-MM-dd") <= format(now(), "yyyy-MM-dd"): nextSendDate = lastWeekdayInMonth(year(nextMonthsDate), month(nextMonthsDate), weekdayString) diff --git a/helpers/global.nim b/helpers/global.nim index 1a8113d..380a872 100644 --- a/helpers/global.nim +++ b/helpers/global.nim @@ -7,22 +7,21 @@ import std/[times, strutils, re, uri, paths, random, strtabs] #universal const APP_PATH* = "/var/www/forget-me-not-gs" -const ASSETS_PATH* = "/var/www/forget-me-not-gs/app/assets" +const ASSETS_PATH* = "/var/www/forget-me-not-gs/assets" const APP_NAME* = "Forget-Me-Not" -#set to 'dev' or 'prod' +#set to 'dev' or 'prod'. changes how cookies are created and possibly paths, if using two environments. Maybe other stuff i'm forgetting. const APP_MODE* = "dev" #dev +#using paths config'd in /etc/hosts for local dev. const APP_URL* = "http://fmn-gs" -#const SITE_URL* = "http://" const ASSETS_URL* = "http://assets.fmn-gs" #prod -#const APP_URL* = "https://ssm.itwrx.org" -#const SITE_URL* = "https://itwrx.org" -#const ASSETS_URL* = "https://assets.itwrx.org" +#const APP_URL* = "https://my-fmn-url.com" +#const ASSETS_URL* = "https://assets.my-fmn-url.com" var frStrTab* = newStringTable() -#TODO: implement logging or remove logging code. +#TODO: implement logging or remove logging code. Remove SSM code not used in FMN. #Guildensterns logger is conflicting with my, evidently incorrect, usage of the std lib logger so i'll just write some lines to a file for now. #var logger* = newFileLogger("errors.log") diff --git a/helpers/reminder.nim b/helpers/reminder.nim index fccd928..e018dea 100644 --- a/helpers/reminder.nim +++ b/helpers/reminder.nim @@ -6,6 +6,8 @@ See COPYING or for details.]# import std/[times, osproc], smtp import ../models/reminder, ../models/user, datetime +#TODO: use comnfig file for creds and other comms settings instead of hardcoding. + proc setFutureSendDate(reminderId: int) = var reminder: Reminder reminder = getReminderById(reminderId) @@ -53,23 +55,24 @@ proc setFutureSendDate(reminderId: int) = echo "Invalid value for reminder.repeatFreq in setFutureSendDate()" proc sendEmail(reminderMsg: string) = + ##Warning: hardcoded userId expects one user with id of 1. let userEmailAddress = getEmailByUserId("1") - let headers = @[("From", "mailer@itwrx.org")] + let headers = @[("From", "mymaileraccount@mydomain.org")] let msg = createMessage("Reminder from Forget-Me-Not", reminderMsg, @[userEmailAddress], mCc = @[""], otherHeaders = headers) {.cast(raises: []).}: let smtpConn = newSmtp(debug=false) - smtpConn.connect("email.itwrx.org", Port 587) + smtpConn.connect("mail.mydomain.org", Port 587) smtpConn.startTls() - smtpConn.auth("mailer@itwrx.org", ".AQ8u((xB(AgZh^a`jEJ~W~{0Eq?fd$") + smtpConn.auth("mymaileraccount@mydomain.org", "mymaileraccount-password-goes-here") #loop through email messages and send to reuse connection? - smtpConn.sendmail("mailer@itwrx.org", @[userEmailAddress], $msg) + smtpConn.sendmail("mymaileraccount@mydomain.org", @[userEmailAddress], $msg) #manually closing not necessary? smtpConn.close() proc sendXMPP(reminderMsg: string) = var output: string var status: int - (output, status) = execCmdEx("xmppc -m message chat itwrx@sec-chat.itwrx.org \"" & reminderMsg & "\"") + (output, status) = execCmdEx("xmppc -m message chat receiving-xmpp-user@myxmppserverdomain.org \"" & reminderMsg & "\"") if status != 0: #log this later instead. echo output diff --git a/models/human_checker.nim b/models/human_checker.nim deleted file mode 100644 index 11a6aed..0000000 --- a/models/human_checker.nim +++ /dev/null @@ -1,38 +0,0 @@ -#[Copyright 2025 ITwrx. -This file is part of Forget-Me-Not. -Forget-Me-Not is released under the GNU Affero General Public License 3.0. -See COPYING or for details.]# - -#TODO: Use a human checker in login form or remove from project. - -import std/random - -type - HumanChecker* = object - question*: string - id*, answer*: int - -var humanCheckers: seq[HumanChecker] -humanCheckers = @[ - HumanChecker(id: 1, question: "26 + four, minus 10", answer: 20), - HumanChecker(id: 2, question: "10 minus 2, + 14", answer: 22), - HumanChecker(id: 3, question: "15 + five, minus 3", answer: 17), - HumanChecker(id: 4, question: "9 + nine, minus 6", answer: 12), - HumanChecker(id: 5, question: "13 - three, plus 5", answer: 15), - HumanChecker(id: 6, question: "7 + six, plus one", answer: 14), - HumanChecker(id: 7, question: "22 + 8, - 2", answer: 28), - HumanChecker(id: 8, question: "4 - four, + ten", answer: 10), - HumanChecker(id: 9, question: "16 + four, minus three", answer: 17), - HumanChecker(id: 10, question: "twelve minus four, plus 8", answer: 16) - ] - -proc getHumanChecker*(): HumanChecker = - {.gcsafe.}: - randomize() - return sample(humancheckers) - -proc getHCById*(id: int): HumanChecker = - {.gcsafe.}: - for hc in humanCheckers: - if hc.id == id: - return hc diff --git a/post_handlers/send_reminders_post_handler.nim b/post_handlers/send_reminders_post_handler.nim index 1970e62..1dad1d8 100644 --- a/post_handlers/send_reminders_post_handler.nim +++ b/post_handlers/send_reminders_post_handler.nim @@ -7,7 +7,7 @@ import guildenstern/httpserver, "../helpers/reminder", "../helpers/form" proc sendRemindersPostHandler*() = try: - if formInput("send_reminders_key") == "wpsU5CY1Tn5PkMjN6OBC7cdPVZbaW3x": + if formInput("send_reminders_key") == "your-key-string-goes-here": sendReminders() reply(Http200) else: diff --git a/post_handlers/user_session_post_handler.nim b/post_handlers/user_session_post_handler.nim index 718aa78..a3f1284 100644 --- a/post_handlers/user_session_post_handler.nim +++ b/post_handlers/user_session_post_handler.nim @@ -7,7 +7,7 @@ import guildenstern/httpserver, "../models/user_session", "../helpers/form" proc userSessionDeletePostHandler*() = try: - if formInput("delete_user_sessions_key") == "XR5yLeigb4PFXOZBh3PBOuQXc8d7NE6": + if formInput("delete_user_sessions_key") == "your-key-string-goes-here": deleteUserSessions() reply(Http200) else: