1 // This module handles the loading/saving and maintenance of the
2 // system's Internet configuration. It's not an optional component; I
3 // wrote it as a module merely to keep things as clean and loosely coupled
6 // Copyright (c) 1987-2024 by the citadel.org team
8 // This program is open source software. Use, duplication, or disclosure
9 // is subject to the terms of the GNU General Public License version 3.
11 #include "../../sysdep.h"
19 #include <sys/types.h>
24 #include <libcitadel.h>
25 #include "../../citadel_defs.h"
26 #include "../../server.h"
27 #include "../../citserver.h"
28 #include "../../support.h"
29 #include "../../config.h"
30 #include "../../user_ops.h"
31 #include "../../database.h"
32 #include "../../msgbase.h"
33 #include "../../internet_addressing.h"
34 #include "../../genstamp.h"
35 #include "../../domain.h"
36 #include "../../ctdl_module.h"
37 #include "../smtp/smtp_util.h"
40 void inetcfg_setTo(struct CtdlMessage *msg) {
44 if (CM_IsEmpty(msg, eMessageText)) return;
45 conf = strdup(msg->cm_fields[eMessageText]);
49 extract_token(buf, conf, 0, '\n', sizeof buf);
50 strcpy(conf, &conf[strlen(buf)+1]);
51 } while ( (!IsEmptyStr(conf)) && (!IsEmptyStr(buf)) );
53 if (inetcfg != NULL) free(inetcfg);
55 dkim_check_advisory(inetcfg); // this will check to see if we have to advise the admin about dkim
60 // This handler detects changes being made to the system's Internet configuration.
61 int inetcfg_aftersave(struct CtdlMessage *msg, struct recptypes *recp) {
65 // If this isn't the configuration room, or if this isn't a MIME message ... don't bother.
66 if ((msg->cm_fields[eOriginalRoom]) && (strcasecmp(msg->cm_fields[eOriginalRoom], SYSCONFIGROOM))) {
69 if (msg->cm_format_type != 4) {
73 ptr = msg->cm_fields[eMessageText];
76 linelen = strcspn(ptr, "\n");
78 return(0); // end of headers
81 if (!strncasecmp(ptr, "Content-type: ", 14)) {
82 if (!strncasecmp(&ptr[14], INTERNETCFG, strlen(INTERNETCFG))) {
83 inetcfg_setTo(msg); // changing configs
87 ptr = strchr((char *)ptr, '\n');
88 if (ptr != NULL) ++ptr;
95 void inetcfg_init_backend(long msgnum, void *userdata) {
96 struct CtdlMessage *msg;
98 msg = CtdlFetchMessage(msgnum, 1);
99 syslog(LOG_DEBUG, "inetcfg: config msg %ld is %s", msgnum, msg ? "not null" : "null");
107 void inetcfg_init(void) {
108 syslog(LOG_DEBUG, "inetcfg: inetcfg_init() started");
109 if (CtdlGetRoom(&CC->room, SYSCONFIGROOM) != 0) {
110 syslog(LOG_WARNING, "inetcfg: could not find <%s>", SYSCONFIGROOM);
113 CtdlForEachMessage(MSGS_LAST, 1, NULL, INTERNETCFG, NULL, inetcfg_init_backend, NULL);
114 syslog(LOG_DEBUG, "inetcfg: inetcfg_init() completed");
118 // Initialization function, called from modules_init.c
119 char *ctdl_module_init_inetcfg(void) {
121 CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);
125 // return our module name for the log