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"
39 #include "citserver.h"
43 struct CitControl CitControl;
45 FILE *control_fp = NULL;
48 * get_control - read the control record into memory.
50 void get_control(void) {
52 /* Zero it out. If the control record on disk is missing or short,
53 * the system functions with all control record fields initialized
56 memset(&CitControl, 0, sizeof(struct CitControl));
57 if (control_fp == NULL) {
58 control_fp = fopen("citadel.control", "rb+");
59 if (control_fp != NULL) {
60 fchown(fileno(control_fp), config.c_bbsuid, -1);
63 if (control_fp == NULL) {
64 control_fp = fopen("citadel.control", "wb+");
65 if (control_fp != NULL) {
66 fchown(fileno(control_fp), config.c_bbsuid, -1);
67 memset(&CitControl, 0, sizeof(struct CitControl));
68 fwrite(&CitControl, sizeof(struct CitControl),
73 if (control_fp == NULL) {
74 lprintf(1, "ERROR opening citadel.control: %s\n",
80 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
84 * put_control - write the control record to disk.
86 void put_control(void) {
88 if (control_fp != NULL) {
90 fwrite(&CitControl, sizeof(struct CitControl), 1, control_fp);
97 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
99 long get_new_message_number(void) {
100 begin_critical_section(S_CONTROL);
102 ++CitControl.MMhighest;
104 end_critical_section(S_CONTROL);
105 return(CitControl.MMhighest);
110 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
112 long get_new_user_number(void) {
113 begin_critical_section(S_CONTROL);
115 ++CitControl.MMnextuser;
117 end_critical_section(S_CONTROL);
118 return(CitControl.MMnextuser);
124 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
126 long get_new_room_number(void) {
127 begin_critical_section(S_CONTROL);
129 ++CitControl.MMnextroom;
131 end_critical_section(S_CONTROL);
132 return(CitControl.MMnextroom);
138 * Get or set global configuration options
140 void cmd_conf(char *argbuf) {
147 if (CtdlAccessCheck(ac_aide)) return;
149 extract(cmd, argbuf, 0);
150 if (!strcasecmp(cmd, "GET")) {
151 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
152 cprintf("%s\n", config.c_nodename);
153 cprintf("%s\n", config.c_fqdn);
154 cprintf("%s\n", config.c_humannode);
155 cprintf("%s\n", config.c_phonenum);
156 cprintf("%d\n", config.c_creataide);
157 cprintf("%d\n", config.c_sleeping);
158 cprintf("%d\n", config.c_initax);
159 cprintf("%d\n", config.c_regiscall);
160 cprintf("%d\n", config.c_twitdetect);
161 cprintf("%s\n", config.c_twitroom);
162 cprintf("%s\n", config.c_moreprompt);
163 cprintf("%d\n", config.c_restrict);
164 cprintf("%s\n", config.c_bbs_city);
165 cprintf("%s\n", config.c_sysadm);
166 cprintf("%d\n", config.c_maxsessions);
167 cprintf("%s\n", config.c_net_password);
168 cprintf("%d\n", config.c_userpurge);
169 cprintf("%d\n", config.c_roompurge);
170 cprintf("%s\n", config.c_logpages);
171 cprintf("%d\n", config.c_createax);
172 cprintf("%d\n", config.c_maxmsglen);
173 cprintf("%d\n", config.c_min_workers);
174 cprintf("%d\n", config.c_max_workers);
175 cprintf("%d\n", config.c_pop3_port);
176 cprintf("%d\n", config.c_smtp_port);
177 cprintf("%d\n", config.c_default_filter);
178 cprintf("%d\n", config.c_aide_zap);
179 cprintf("%d\n", config.c_imap_port);
183 else if (!strcasecmp(cmd, "SET")) {
184 cprintf("%d Send configuration...\n", SEND_LISTING);
186 while (client_gets(buf), strcmp(buf, "000")) {
188 case 0: safestrncpy(config.c_nodename, buf,
189 sizeof config.c_nodename);
191 case 1: safestrncpy(config.c_fqdn, buf,
192 sizeof config.c_fqdn);
194 case 2: safestrncpy(config.c_humannode, buf,
195 sizeof config.c_humannode);
197 case 3: safestrncpy(config.c_phonenum, buf,
198 sizeof config.c_phonenum);
200 case 4: config.c_creataide = atoi(buf);
202 case 5: config.c_sleeping = atoi(buf);
204 case 6: config.c_initax = atoi(buf);
205 if (config.c_initax < 1) config.c_initax = 1;
206 if (config.c_initax > 6) config.c_initax = 6;
208 case 7: config.c_regiscall = atoi(buf);
209 if (config.c_regiscall != 0)
210 config.c_regiscall = 1;
212 case 8: config.c_twitdetect = atoi(buf);
213 if (config.c_twitdetect != 0)
214 config.c_twitdetect = 1;
216 case 9: safestrncpy(config.c_twitroom, buf,
217 sizeof config.c_twitroom);
219 case 10: safestrncpy(config.c_moreprompt, buf,
220 sizeof config.c_moreprompt);
222 case 11: config.c_restrict = atoi(buf);
223 if (config.c_restrict != 0)
224 config.c_restrict = 1;
226 case 12: safestrncpy(config.c_bbs_city, buf,
227 sizeof config.c_bbs_city);
229 case 13: safestrncpy(config.c_sysadm, buf,
230 sizeof config.c_sysadm);
232 case 14: config.c_maxsessions = atoi(buf);
233 if (config.c_maxsessions < 1)
234 config.c_maxsessions = 1;
236 case 15: safestrncpy(config.c_net_password, buf,
237 sizeof config.c_net_password);
239 case 16: config.c_userpurge = atoi(buf);
241 case 17: config.c_roompurge = atoi(buf);
243 case 18: safestrncpy(config.c_logpages, buf,
244 sizeof config.c_logpages);
246 case 19: config.c_createax = atoi(buf);
247 if (config.c_createax < 1)
248 config.c_createax = 1;
249 if (config.c_createax > 6)
250 config.c_createax = 6;
252 case 20: if (atoi(buf) >= 8192)
253 config.c_maxmsglen = atoi(buf);
255 case 21: if (atoi(buf) >= 2)
256 config.c_min_workers = atoi(buf);
257 case 22: if (atoi(buf) >= config.c_min_workers)
258 config.c_max_workers = atoi(buf);
259 case 23: config.c_pop3_port = atoi(buf);
261 case 24: config.c_smtp_port = atoi(buf);
263 case 25: config.c_default_filter = atoi(buf);
265 case 26: config.c_aide_zap = atoi(buf);
266 if (config.c_aide_zap != 0)
267 config.c_aide_zap = 1;
269 case 27: config.c_imap_port = atoi(buf);
275 snprintf(buf,sizeof buf,
276 "Global system configuration edited by %s\n",
280 if (strlen(config.c_logpages) > 0)
281 create_room(config.c_logpages, 3, "", 0, 1);
284 else if (!strcasecmp(cmd, "GETSYS")) {
285 extract(confname, argbuf, 1);
286 confptr = CtdlGetSysConfig(confname);
287 if (confptr != NULL) {
288 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
289 client_write(confptr, strlen(confptr));
290 if (confptr[strlen(confptr)-1] != 10)
291 client_write("\n", 1);
296 cprintf("%d No such configuration.\n",
297 ERROR+ILLEGAL_VALUE);
301 else if (!strcasecmp(cmd, "PUTSYS")) {
302 extract(confname, argbuf, 1);
303 cprintf("%d %s\n", SEND_LISTING, confname);
304 confptr = CtdlReadMessageBody("000", config.c_maxmsglen, NULL);
305 CtdlPutSysConfig(confname, confptr);
310 cprintf("%d Illegal option(s) specified.\n",
311 ERROR+ILLEGAL_VALUE);