make hardcoded values release friendly

This commit is contained in:
itwrx 2025-05-18 10:52:58 -05:00
parent b66c40264f
commit 451492fa20
7 changed files with 18 additions and 56 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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")

View File

@ -6,6 +6,8 @@ See COPYING or <https://www.gnu.org/licenses/> 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

View File

@ -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 <https://www.gnu.org/licenses/> 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

View File

@ -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:

View File

@ -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: