4 * This module handles states which are global to the entire server.
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
24 # include <sys/time.h>
35 #include <sys/types.h>
39 #include "dynloader.h"
40 #include "sysdep_decls.h"
44 #include "citserver.h"
52 struct CitControl CitControl;
54 FILE *control_fp = NULL;
57 * get_control - read the control record into memory.
59 void get_control(void) {
61 /* Zero it out. If the control record on disk is missing or short,
62 * the system functions with all control record fields initialized
65 memset(&CitControl, 0, sizeof(struct CitControl));
66 if (control_fp == NULL) {
67 control_fp = fopen("citadel.control", "rb+");
68 if (control_fp != NULL) {
69 fchown(fileno(control_fp), config.c_bbsuid, -1);
72 if (control_fp == NULL) {
73 control_fp = fopen("citadel.control", "wb+");
74 if (control_fp != NULL) {
75 fchown(fileno(control_fp), config.c_bbsuid, -1);
76 memset(&CitControl, 0, sizeof(struct CitControl));
77 fwrite(&CitControl, sizeof(struct CitControl),
82 if (control_fp == NULL) {
83 lprintf(1, "ERROR opening citadel.control: %s\n",
89 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
93 * put_control - write the control record to disk.
95 void put_control(void) {
97 if (control_fp != NULL) {
99 fwrite(&CitControl, sizeof(struct CitControl), 1, control_fp);
106 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
108 long get_new_message_number(void) {
109 begin_critical_section(S_CONTROL);
111 ++CitControl.MMhighest;
113 end_critical_section(S_CONTROL);
114 return(CitControl.MMhighest);
119 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
121 long get_new_user_number(void) {
122 begin_critical_section(S_CONTROL);
124 ++CitControl.MMnextuser;
126 end_critical_section(S_CONTROL);
127 return(CitControl.MMnextuser);
133 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
135 long get_new_room_number(void) {
136 begin_critical_section(S_CONTROL);
138 ++CitControl.MMnextroom;
140 end_critical_section(S_CONTROL);
141 return(CitControl.MMnextroom);
147 * Get or set global configuration options
149 void cmd_conf(char *argbuf) {
156 if (CtdlAccessCheck(ac_aide)) return;
158 extract(cmd, argbuf, 0);
159 if (!strcasecmp(cmd, "GET")) {
160 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
161 cprintf("%s\n", config.c_nodename);
162 cprintf("%s\n", config.c_fqdn);
163 cprintf("%s\n", config.c_humannode);
164 cprintf("%s\n", config.c_phonenum);
165 cprintf("%d\n", config.c_creataide);
166 cprintf("%d\n", config.c_sleeping);
167 cprintf("%d\n", config.c_initax);
168 cprintf("%d\n", config.c_regiscall);
169 cprintf("%d\n", config.c_twitdetect);
170 cprintf("%s\n", config.c_twitroom);
171 cprintf("%s\n", config.c_moreprompt);
172 cprintf("%d\n", config.c_restrict);
173 cprintf("%s\n", config.c_bbs_city);
174 cprintf("%s\n", config.c_sysadm);
175 cprintf("%d\n", config.c_maxsessions);
176 cprintf("%s\n", config.c_net_password);
177 cprintf("%d\n", config.c_userpurge);
178 cprintf("%d\n", config.c_roompurge);
179 cprintf("%s\n", config.c_logpages);
180 cprintf("%d\n", config.c_createax);
181 cprintf("%ld\n", config.c_maxmsglen);
182 cprintf("%d\n", config.c_min_workers);
183 cprintf("%d\n", config.c_max_workers);
184 cprintf("%d\n", config.c_pop3_port);
185 cprintf("%d\n", config.c_smtp_port);
186 cprintf("%d\n", config.c_default_filter);
187 cprintf("%d\n", config.c_aide_zap);
188 cprintf("%d\n", config.c_imap_port);
189 cprintf("%d\n", config.c_net_freq);
193 else if (!strcasecmp(cmd, "SET")) {
194 cprintf("%d Send configuration...\n", SEND_LISTING);
196 while (client_gets(buf), strcmp(buf, "000")) {
198 case 0: safestrncpy(config.c_nodename, buf,
199 sizeof config.c_nodename);
201 case 1: safestrncpy(config.c_fqdn, buf,
202 sizeof config.c_fqdn);
204 case 2: safestrncpy(config.c_humannode, buf,
205 sizeof config.c_humannode);
207 case 3: safestrncpy(config.c_phonenum, buf,
208 sizeof config.c_phonenum);
210 case 4: config.c_creataide = atoi(buf);
212 case 5: config.c_sleeping = atoi(buf);
214 case 6: config.c_initax = atoi(buf);
215 if (config.c_initax < 1) config.c_initax = 1;
216 if (config.c_initax > 6) config.c_initax = 6;
218 case 7: config.c_regiscall = atoi(buf);
219 if (config.c_regiscall != 0)
220 config.c_regiscall = 1;
222 case 8: config.c_twitdetect = atoi(buf);
223 if (config.c_twitdetect != 0)
224 config.c_twitdetect = 1;
226 case 9: safestrncpy(config.c_twitroom, buf,
227 sizeof config.c_twitroom);
229 case 10: safestrncpy(config.c_moreprompt, buf,
230 sizeof config.c_moreprompt);
232 case 11: config.c_restrict = atoi(buf);
233 if (config.c_restrict != 0)
234 config.c_restrict = 1;
236 case 12: safestrncpy(config.c_bbs_city, buf,
237 sizeof config.c_bbs_city);
239 case 13: safestrncpy(config.c_sysadm, buf,
240 sizeof config.c_sysadm);
242 case 14: config.c_maxsessions = atoi(buf);
243 if (config.c_maxsessions < 1)
244 config.c_maxsessions = 1;
246 case 15: safestrncpy(config.c_net_password, buf,
247 sizeof config.c_net_password);
249 case 16: config.c_userpurge = atoi(buf);
251 case 17: config.c_roompurge = atoi(buf);
253 case 18: safestrncpy(config.c_logpages, buf,
254 sizeof config.c_logpages);
256 case 19: config.c_createax = atoi(buf);
257 if (config.c_createax < 1)
258 config.c_createax = 1;
259 if (config.c_createax > 6)
260 config.c_createax = 6;
262 case 20: if (atoi(buf) >= 8192)
263 config.c_maxmsglen = atoi(buf);
265 case 21: if (atoi(buf) >= 2)
266 config.c_min_workers = atoi(buf);
267 case 22: if (atoi(buf) >= config.c_min_workers)
268 config.c_max_workers = atoi(buf);
269 case 23: config.c_pop3_port = atoi(buf);
271 case 24: config.c_smtp_port = atoi(buf);
273 case 25: config.c_default_filter = atoi(buf);
275 case 26: config.c_aide_zap = atoi(buf);
276 if (config.c_aide_zap != 0)
277 config.c_aide_zap = 1;
279 case 27: config.c_imap_port = atoi(buf);
281 case 28: config.c_net_freq = atol(buf);
287 snprintf(buf,sizeof buf,
288 "Global system configuration edited by %s\n",
292 if (strlen(config.c_logpages) > 0)
293 create_room(config.c_logpages, 3, "", 0, 1);
296 else if (!strcasecmp(cmd, "GETSYS")) {
297 extract(confname, argbuf, 1);
298 confptr = CtdlGetSysConfig(confname);
299 if (confptr != NULL) {
300 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
301 client_write(confptr, strlen(confptr));
302 if (confptr[strlen(confptr)-1] != 10)
303 client_write("\n", 1);
308 cprintf("%d No such configuration.\n",
309 ERROR+ILLEGAL_VALUE);
313 else if (!strcasecmp(cmd, "PUTSYS")) {
314 extract(confname, argbuf, 1);
315 cprintf("%d %s\n", SEND_LISTING, confname);
316 confptr = CtdlReadMessageBody("000", config.c_maxmsglen, NULL);
317 CtdlPutSysConfig(confname, confptr);
322 cprintf("%d Illegal option(s) specified.\n",
323 ERROR+ILLEGAL_VALUE);