4 * This module handles states which are global to the entire server.
23 #include "sysdep_decls.h"
30 struct CitControl CitControl;
32 FILE *control_fp = NULL;
35 * get_control - read the control record into memory.
37 void get_control(void) {
39 /* Zero it out. If the control record on disk is missing or short,
40 * the system functions with all control record fields initialized
43 memset(&CitControl, 0, sizeof(struct CitControl));
44 if (control_fp == NULL)
45 control_fp = fopen("citadel.control", "rb+");
46 if (control_fp == NULL) {
47 control_fp = fopen("citadel.control", "wb+");
48 if (control_fp != NULL) {
49 memset(&CitControl, 0, sizeof(struct CitControl));
50 fwrite(&CitControl, sizeof(struct CitControl),
55 if (control_fp == NULL) {
56 lprintf(1, "ERROR opening citadel.control: %s\n",
62 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
66 * put_control - write the control record to disk.
68 void put_control(void) {
70 if (control_fp != NULL) {
72 fwrite(&CitControl, sizeof(struct CitControl), 1, control_fp);
79 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
81 long get_new_message_number(void) {
82 begin_critical_section(S_CONTROL);
84 ++CitControl.MMhighest;
86 end_critical_section(S_CONTROL);
87 return(CitControl.MMhighest);
92 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
94 long get_new_user_number(void) {
95 begin_critical_section(S_CONTROL);
97 ++CitControl.MMnextuser;
99 end_critical_section(S_CONTROL);
100 return(CitControl.MMnextuser);
106 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
108 long get_new_room_number(void) {
109 begin_critical_section(S_CONTROL);
111 ++CitControl.MMnextroom;
113 end_critical_section(S_CONTROL);
114 return(CitControl.MMnextroom);
120 * Get or set global configuration options
122 void cmd_conf(char *argbuf) {
129 if (!(CC->logged_in)) {
130 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
134 if (CC->usersupp.axlevel < 6) {
135 cprintf("%d Higher access required.\n",
136 ERROR+HIGHER_ACCESS_REQUIRED);
140 extract(cmd, argbuf, 0);
141 if (!strcasecmp(cmd, "GET")) {
142 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
143 cprintf("%s\n", config.c_nodename);
144 cprintf("%s\n", config.c_fqdn);
145 cprintf("%s\n", config.c_humannode);
146 cprintf("%s\n", config.c_phonenum);
147 cprintf("%d\n", config.c_creataide);
148 cprintf("%d\n", config.c_sleeping);
149 cprintf("%d\n", config.c_initax);
150 cprintf("%d\n", config.c_regiscall);
151 cprintf("%d\n", config.c_twitdetect);
152 cprintf("%s\n", config.c_twitroom);
153 cprintf("%s\n", config.c_moreprompt);
154 cprintf("%d\n", config.c_restrict);
155 cprintf("%s\n", config.c_bbs_city);
156 cprintf("%s\n", config.c_sysadm);
157 cprintf("%d\n", config.c_maxsessions);
158 cprintf("%s\n", config.c_net_password);
159 cprintf("%d\n", config.c_userpurge);
160 cprintf("%d\n", config.c_roompurge);
161 cprintf("%s\n", config.c_logpages);
162 cprintf("%d\n", config.c_createax);
163 cprintf("%d\n", config.c_maxmsglen);
164 cprintf("%d\n", config.c_min_workers);
165 cprintf("%d\n", config.c_max_workers);
166 cprintf("%d\n", config.c_pop3_port);
167 cprintf("%d\n", config.c_smtp_port);
168 cprintf("%d\n", config.c_default_filter);
172 else if (!strcasecmp(cmd, "SET")) {
173 cprintf("%d Send configuration...\n", SEND_LISTING);
175 while (client_gets(buf), strcmp(buf, "000")) {
177 case 0: safestrncpy(config.c_nodename, buf,
178 sizeof config.c_nodename);
180 case 1: safestrncpy(config.c_fqdn, buf,
181 sizeof config.c_fqdn);
183 case 2: safestrncpy(config.c_humannode, buf,
184 sizeof config.c_humannode);
186 case 3: safestrncpy(config.c_phonenum, buf,
187 sizeof config.c_phonenum);
189 case 4: config.c_creataide = atoi(buf);
191 case 5: config.c_sleeping = atoi(buf);
193 case 6: config.c_initax = atoi(buf);
194 if (config.c_initax < 1) config.c_initax = 1;
195 if (config.c_initax > 6) config.c_initax = 6;
197 case 7: config.c_regiscall = atoi(buf);
198 if (config.c_regiscall != 0)
199 config.c_regiscall = 1;
201 case 8: config.c_twitdetect = atoi(buf);
202 if (config.c_twitdetect != 0)
203 config.c_twitdetect = 1;
205 case 9: safestrncpy(config.c_twitroom, buf,
206 sizeof config.c_twitroom);
208 case 10: safestrncpy(config.c_moreprompt, buf,
209 sizeof config.c_moreprompt);
211 case 11: config.c_restrict = atoi(buf);
212 if (config.c_restrict != 0)
213 config.c_restrict = 1;
215 case 12: safestrncpy(config.c_bbs_city, buf,
216 sizeof config.c_bbs_city);
218 case 13: safestrncpy(config.c_sysadm, buf,
219 sizeof config.c_sysadm);
221 case 14: config.c_maxsessions = atoi(buf);
222 if (config.c_maxsessions < 1)
223 config.c_maxsessions = 1;
225 case 15: safestrncpy(config.c_net_password, buf,
226 sizeof config.c_net_password);
228 case 16: config.c_userpurge = atoi(buf);
230 case 17: config.c_roompurge = atoi(buf);
232 case 18: safestrncpy(config.c_logpages, buf,
233 sizeof config.c_logpages);
235 case 19: config.c_createax = atoi(buf);
236 if (config.c_createax < 1)
237 config.c_createax = 1;
238 if (config.c_createax > 6)
239 config.c_createax = 6;
241 case 20: if (atoi(buf) >= 8192)
242 config.c_maxmsglen = atoi(buf);
244 case 21: if (atoi(buf) >= 2)
245 config.c_min_workers = atoi(buf);
246 case 22: if (atoi(buf) >= config.c_min_workers)
247 config.c_max_workers = atoi(buf);
248 case 23: config.c_pop3_port = atoi(buf);
250 case 24: config.c_smtp_port = atoi(buf);
252 case 25: config.c_default_filter = atoi(buf);
258 snprintf(buf,sizeof buf,
259 "Global system configuration edited by %s\n",
263 if (strlen(config.c_logpages) > 0)
264 create_room(config.c_logpages, 3, "", 0);
267 else if (!strcasecmp(cmd, "GETSYS")) {
268 extract(confname, argbuf, 1);
269 confptr = CtdlGetSysConfig(confname);
270 if (confptr != NULL) {
271 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
272 client_write(confptr, strlen(confptr));
273 if (confptr[strlen(confptr)-1] != 10)
274 client_write("\n", 1);
279 cprintf("%d No such configuration.\n",
280 ERROR+ILLEGAL_VALUE);
284 else if (!strcasecmp(cmd, "PUTSYS")) {
285 extract(confname, argbuf, 1);
286 cprintf("%d %s\n", SEND_LISTING, confname);
287 confptr = CtdlReadMessageBody("000", config.c_maxmsglen, NULL);
288 CtdlPutSysConfig(confname, confptr);
293 cprintf("%d Illegal option(s) specified.\n",
294 ERROR+ILLEGAL_VALUE);