4 * This module handles states which are global to the entire server.
15 #if TIME_WITH_SYS_TIME
16 # include <sys/time.h>
20 # include <sys/time.h>
31 #include <sys/types.h>
35 #include "sysdep_decls.h"
42 struct CitControl CitControl;
44 FILE *control_fp = NULL;
47 * get_control - read the control record into memory.
49 void get_control(void) {
51 /* Zero it out. If the control record on disk is missing or short,
52 * the system functions with all control record fields initialized
55 memset(&CitControl, 0, sizeof(struct CitControl));
56 if (control_fp == NULL) {
57 control_fp = fopen("citadel.control", "rb+");
58 if (control_fp != NULL) {
59 fchown(fileno(control_fp), config.c_bbsuid, -1);
62 if (control_fp == NULL) {
63 control_fp = fopen("citadel.control", "wb+");
64 if (control_fp != NULL) {
65 fchown(fileno(control_fp), config.c_bbsuid, -1);
66 memset(&CitControl, 0, sizeof(struct CitControl));
67 fwrite(&CitControl, sizeof(struct CitControl),
72 if (control_fp == NULL) {
73 lprintf(1, "ERROR opening citadel.control: %s\n",
79 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
83 * put_control - write the control record to disk.
85 void put_control(void) {
87 if (control_fp != NULL) {
89 fwrite(&CitControl, sizeof(struct CitControl), 1, control_fp);
96 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
98 long get_new_message_number(void) {
99 begin_critical_section(S_CONTROL);
101 ++CitControl.MMhighest;
103 end_critical_section(S_CONTROL);
104 return(CitControl.MMhighest);
109 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
111 long get_new_user_number(void) {
112 begin_critical_section(S_CONTROL);
114 ++CitControl.MMnextuser;
116 end_critical_section(S_CONTROL);
117 return(CitControl.MMnextuser);
123 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
125 long get_new_room_number(void) {
126 begin_critical_section(S_CONTROL);
128 ++CitControl.MMnextroom;
130 end_critical_section(S_CONTROL);
131 return(CitControl.MMnextroom);
137 * Get or set global configuration options
139 void cmd_conf(char *argbuf) {
146 if (!(CC->logged_in)) {
147 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
151 if (CC->usersupp.axlevel < 6) {
152 cprintf("%d Higher access required.\n",
153 ERROR+HIGHER_ACCESS_REQUIRED);
157 extract(cmd, argbuf, 0);
158 if (!strcasecmp(cmd, "GET")) {
159 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
160 cprintf("%s\n", config.c_nodename);
161 cprintf("%s\n", config.c_fqdn);
162 cprintf("%s\n", config.c_humannode);
163 cprintf("%s\n", config.c_phonenum);
164 cprintf("%d\n", config.c_creataide);
165 cprintf("%d\n", config.c_sleeping);
166 cprintf("%d\n", config.c_initax);
167 cprintf("%d\n", config.c_regiscall);
168 cprintf("%d\n", config.c_twitdetect);
169 cprintf("%s\n", config.c_twitroom);
170 cprintf("%s\n", config.c_moreprompt);
171 cprintf("%d\n", config.c_restrict);
172 cprintf("%s\n", config.c_bbs_city);
173 cprintf("%s\n", config.c_sysadm);
174 cprintf("%d\n", config.c_maxsessions);
175 cprintf("%s\n", config.c_net_password);
176 cprintf("%d\n", config.c_userpurge);
177 cprintf("%d\n", config.c_roompurge);
178 cprintf("%s\n", config.c_logpages);
179 cprintf("%d\n", config.c_createax);
180 cprintf("%d\n", config.c_maxmsglen);
181 cprintf("%d\n", config.c_min_workers);
182 cprintf("%d\n", config.c_max_workers);
183 cprintf("%d\n", config.c_pop3_port);
184 cprintf("%d\n", config.c_smtp_port);
185 cprintf("%d\n", config.c_default_filter);
186 cprintf("%d\n", config.c_aide_zap);
187 cprintf("%d\n", config.c_imap_port);
191 else if (!strcasecmp(cmd, "SET")) {
192 cprintf("%d Send configuration...\n", SEND_LISTING);
194 while (client_gets(buf), strcmp(buf, "000")) {
196 case 0: safestrncpy(config.c_nodename, buf,
197 sizeof config.c_nodename);
199 case 1: safestrncpy(config.c_fqdn, buf,
200 sizeof config.c_fqdn);
202 case 2: safestrncpy(config.c_humannode, buf,
203 sizeof config.c_humannode);
205 case 3: safestrncpy(config.c_phonenum, buf,
206 sizeof config.c_phonenum);
208 case 4: config.c_creataide = atoi(buf);
210 case 5: config.c_sleeping = atoi(buf);
212 case 6: config.c_initax = atoi(buf);
213 if (config.c_initax < 1) config.c_initax = 1;
214 if (config.c_initax > 6) config.c_initax = 6;
216 case 7: config.c_regiscall = atoi(buf);
217 if (config.c_regiscall != 0)
218 config.c_regiscall = 1;
220 case 8: config.c_twitdetect = atoi(buf);
221 if (config.c_twitdetect != 0)
222 config.c_twitdetect = 1;
224 case 9: safestrncpy(config.c_twitroom, buf,
225 sizeof config.c_twitroom);
227 case 10: safestrncpy(config.c_moreprompt, buf,
228 sizeof config.c_moreprompt);
230 case 11: config.c_restrict = atoi(buf);
231 if (config.c_restrict != 0)
232 config.c_restrict = 1;
234 case 12: safestrncpy(config.c_bbs_city, buf,
235 sizeof config.c_bbs_city);
237 case 13: safestrncpy(config.c_sysadm, buf,
238 sizeof config.c_sysadm);
240 case 14: config.c_maxsessions = atoi(buf);
241 if (config.c_maxsessions < 1)
242 config.c_maxsessions = 1;
244 case 15: safestrncpy(config.c_net_password, buf,
245 sizeof config.c_net_password);
247 case 16: config.c_userpurge = atoi(buf);
249 case 17: config.c_roompurge = atoi(buf);
251 case 18: safestrncpy(config.c_logpages, buf,
252 sizeof config.c_logpages);
254 case 19: config.c_createax = atoi(buf);
255 if (config.c_createax < 1)
256 config.c_createax = 1;
257 if (config.c_createax > 6)
258 config.c_createax = 6;
260 case 20: if (atoi(buf) >= 8192)
261 config.c_maxmsglen = atoi(buf);
263 case 21: if (atoi(buf) >= 2)
264 config.c_min_workers = atoi(buf);
265 case 22: if (atoi(buf) >= config.c_min_workers)
266 config.c_max_workers = atoi(buf);
267 case 23: config.c_pop3_port = atoi(buf);
269 case 24: config.c_smtp_port = atoi(buf);
271 case 25: config.c_default_filter = atoi(buf);
273 case 26: config.c_aide_zap = atoi(buf);
274 if (config.c_aide_zap != 0)
275 config.c_aide_zap = 1;
277 case 27: config.c_imap_port = atoi(buf);
283 snprintf(buf,sizeof buf,
284 "Global system configuration edited by %s\n",
288 if (strlen(config.c_logpages) > 0)
289 create_room(config.c_logpages, 3, "", 0, 1);
292 else if (!strcasecmp(cmd, "GETSYS")) {
293 extract(confname, argbuf, 1);
294 confptr = CtdlGetSysConfig(confname);
295 if (confptr != NULL) {
296 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
297 client_write(confptr, strlen(confptr));
298 if (confptr[strlen(confptr)-1] != 10)
299 client_write("\n", 1);
304 cprintf("%d No such configuration.\n",
305 ERROR+ILLEGAL_VALUE);
309 else if (!strcasecmp(cmd, "PUTSYS")) {
310 extract(confname, argbuf, 1);
311 cprintf("%d %s\n", SEND_LISTING, confname);
312 confptr = CtdlReadMessageBody("000", config.c_maxmsglen, NULL);
313 CtdlPutSysConfig(confname, confptr);
318 cprintf("%d Illegal option(s) specified.\n",
319 ERROR+ILLEGAL_VALUE);