2 * Citadel/UX setup program
4 * see copyright.txt for copyright information
6 * *** YOU MUST EDIT sysconfig.h >BEFORE< COMPILING SETUP ***
15 #include <sys/types.h>
33 #define UI_TEXT 0 /* Default setup type -- text only */
34 #define UI_DIALOG 1 /* Use the 'dialog' program */
35 #define UI_CURSES 2 /* Use curses */
37 #define SERVICE_NAME "citadel"
38 #define PROTO_NAME "tcp"
41 char setup_directory[128];
44 char *setup_titles[] = {
47 "Fully Qualified Domain Name (FQDN)",
48 "Human-readable node name",
51 "System Administrator",
53 "Password encryption seed",
54 "'Room Creator = Room Aide' flag",
55 "Server timeout period",
56 "Initial access level",
57 "Registration requirements",
59 "Twit Detect target room",
60 "Maximum concurrent sessions",
62 "Restrict Internet mail flag",
64 "Name of bit bucket subdirectory",
65 "System net password",
70 char *setup_text[] = {
73 "Enter the full pathname of the directory in which the BBS you are",
74 "creating or updating resides. If you specify a directory other than the",
75 "default, you will need to specify the -h flag to the server when you start",
79 "This is the name your system is known by on a Citadel/UX network. It",
80 "should be 8 characters or less, and should generally be comprised only of",
81 "letters. You can also use numbers and hyphens if necessary.",
84 "This is the name your system is known by on the Internet.",
85 "If you're not on the Internet, simply set this to your",
86 "node name followed by '.UUCP'.",
89 "This is a longer description of your system, readable by",
90 "us mere humans. It can be up to 20 characters long and it",
91 "can have spaces in it. Note that if you are part of a",
92 "Cit86Net, this is the name your system will be known by on",
96 "This is the main dialup number for your system. If yours",
97 "can not be dialed into, then make one up! It should be in",
98 "the format 'US 000 000 0000' - the US is your country code",
99 "(look it up if you're not in the United States) and the",
100 "rest is, of course, your area code and phone number.",
101 "This doesn't have any use in Citadel/UX, but gateways to",
102 "other networks may require it, and someday we may use this",
103 "to have the networker automatically build a BBS list.",
106 "Enter the city and state your system is located in.",
109 "Enter the name of the system administrator (which is probably you).",
110 "When an account is created with this name, it will automatically be",
111 "assigned the highest access level.",
114 "You should create a user called 'bbs', 'guest', 'citadel', or something",
115 "similar, that will allow users a way into your BBS. The server will run",
116 "under this user ID. Please specify that (numeric) user ID here.",
119 "Citadel uses a (very) simple password encryption scheme",
120 "to thwart breakins that could occur if someone snatched",
121 "a copy of your userlog. This parameter is part of the",
122 "algorithm, so that the code can be different on each",
123 "system. Once it has been set, DO NOT change it --",
124 "otherwise no one will be able to log in!",
127 "This is a boolean value. If you set it to 1, anyone who",
128 "creates a class 3 (passworded) or class 4 (invitation",
129 "only) room will automatically become the Room Aide for",
130 "that room, allowing them to edit it, delete/move messages,",
131 "etc. This is an administrative decision: it works well on",
132 "some systems, and not so well on others. Set this to 0 to",
133 "disable this function.",
136 "This setting specifies how long a server session may sit idle before it is",
137 "automatically terminated. The recommended value is 900 seconds (15",
138 "minutes). Note that this has *nothing* to do with any watchdog timer that",
139 "is presented to the user. The server's timeout is intended to kill idle or",
140 "zombie sessions running on a network, etc. ",
141 "You MUST set this to a reasonable value. Setting it to zero will cause",
142 "the server to malfunction.",
145 "This is the access level new users are assigned.",
147 "The most common settings for this will be either 1, for",
148 "systems which require new user validation by the system",
149 "administrator ('sysop' is a word for people who run DOS",
150 "boards!), or 4, for systems which give instant access.",
151 "The current access levels available are:",
154 "'Registration' refers to the boring part of logging into a BBS for the first",
155 "time: typing your name, address, and telephone number. Set this value to 1",
156 "to automatically do registration for new users, or 0 to not auto-register.",
157 "Optionally, you could set it to, say, 2, to auto-register on a user's second",
158 "call, but there really isn't much point to doing this. The recommended",
159 "value is 1 if you've set your inital access level to 1, or 0 if you've set",
160 "your initial access level to something higher.",
163 "Every BBS has its share of problem users. This is one",
164 "good way to deal with them: if you enable this option,",
165 "anyone you flag as a 'problem user' (access level 2) can",
166 "post anywhere they want, but their messages will all be",
167 "automatically moved to a room of your choosing. Set this",
168 "value to 1 to enable Twit Detect, or 0 to disable it.",
171 "This is the name of the room that problem user messages",
172 "get moved to if you have Twit Detect enabled.",
173 "(Note: don't forget to *create* this room!)",
176 "This is the maximum number of concurrent Citadel sessions which may be",
177 "running at any given time. Use this to keep very busy systems from being",
179 " Set this value to 0 to allow an unlimited number of sessions.",
182 "This is the prompt that appears after each screenful of",
183 "text - for users that have chosen that option. Usually",
184 "a simple '<more>' will do, but some folks like to be",
188 "If you have a gateway set up to allow Citadel users to",
189 "send Internet mail, with sendmail, qmail, or whatever, and",
190 "you wish to restrict this to only users to whom you have",
191 "given this privilege, set this flag to 1. Otherwise, set",
192 "it to 0 to allow everyone to send Internet mail.",
193 "(Obviously, if your system doesn't have the ability to",
194 "send mail to the outside world, this is all irrelevant.)",
197 "This parameter is meaningless and should be removed.",
200 "Select the name of a subdirectory (relative to the main",
201 "Citadel directory - do not type an absolute pathname!) in",
202 "which to place arriving file transfers that otherwise",
203 "don't have a home.",
206 "If you use Citadel client/server sessions to transport network spool data",
207 "between systems, this is the password other systems will use to authenticate",
208 "themselves as network nodes rather than regular callers.",
211 "Specify the TCP port number on which your server will run. Normally, this",
212 "will be port 504, which is the official port assigned by the IANA for",
213 "Citadel servers. You'll only need to specify a different port number if",
214 "you run multiple BBS's on the same computer and there's something else",
215 "already using port 504.",
226 "DO NOT re-create files that you wish to keep intact!",
227 "They will be permanently ERASED if you do so!",
228 "(Obviously, if this is the first time you are setting up the BBS,",
229 "then you will want to create all of the files.)",
232 "Setup has detected that you currently have data files from a Citadel/UX",
233 "version 3.2x installation. The program 'conv_32_40' can upgrade your",
234 "files to version 4.0x format.",
235 " Setup will now exit. Please either run 'conv_32_40' or delete your data",
236 "files, and run setup again.",
245 struct config config;
248 void cleanup(int exitcode) {
250 if (setup_type == UI_CURSES) {
257 /* Do an 'init q' if we need to. When we hit the right one, init
258 * will take over and setup won't come back because we didn't do a
259 * fork(). If init isn't found, we fall through the bottom of the
260 * loop and setup exits quietly.
263 execlp("/sbin/init", "init", "q", NULL);
264 execlp("/usr/sbin/init", "init", "q", NULL);
265 execlp("/bin/init", "init", "q", NULL);
266 execlp("/usr/bin/init", "init", "q", NULL);
267 execlp("init", "init", "q", NULL);
275 void getlin(yp,xp,string,lim) /* Gets a line from the terminal */
276 int yp,xp; /* Where on the screen to start */
277 char string[]; /* Pointer to string buffer */
278 int lim; /* Maximum length - if negative, no-show */
283 if (lim<0) { lim=(0-lim); flag=1; }
286 for (a=0; a<lim; ++a) addch('-');
289 for (a=0; a<lim; ++a) addch(' ');
291 printw("%s", string);
292 GLA: move(yp,xp+strlen(string));
298 if ((a==8)&&(strlen(string)==0)) goto GLA;
299 if ((a!=13)&&(a!=8)&&(strlen(string)==lim)) goto GLA;
300 if ((a==8)&&(string[0]!=0)) {
301 string[strlen(string)-1]=0;
302 move(yp,xp+strlen(string));
306 if ((a==13)||(a==10)) {
309 for (a=0; a<lim; ++a) addch(' ');
310 mvprintw(yp,xp,"%s",string);
317 if (flag==0) addch(a);
318 if (flag==1) addch('*');
327 if (setup_type == UI_TEXT) {
328 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n",text);
337 if (setup_type == UI_CURSES) {
338 mvprintw(20, 0, "Press any key to continue... ");
344 printf("Press return to continue...");
345 fgets(junk, 5, stdin);
357 printf("%s\nYes/No --> ",question);
358 fgets(buf, 4096, stdin);
359 answer=tolower(buf[0]);
360 if (answer=='y') answer=1;
361 else if (answer=='n') answer=0;
362 } while ((answer<0)||(answer>1));
366 sprintf(buf, "dialog --yesno \"%s\" 7 80", question);
367 answer = ( (system(buf)==0) ? 1 : 0);
374 mvprintw(1, 20, "Question");
376 mvprintw(10, 0, "%-80s", question);
377 mvprintw(20, 0, "%80s", "");
378 mvprintw(20, 0, "Yes/No -> ");
381 answer=tolower(answer);
382 if (answer=='y') answer=1;
383 else if (answer=='n') answer=0;
384 } while ((answer<0)||(answer>1));
394 void dump_access_levels() {
396 for (a=0; a<=6; ++a) printf("%d %s\n",a,axdefs[a]);
399 void get_setup_msg(char *dispbuf, int msgnum) {
404 while (atol(setup_text[a]) != msgnum) ++a;
408 strcat(dispbuf, setup_text[a++]);
409 strcat(dispbuf, "\n");
410 } while(atol(setup_text[a])!=(msgnum+1));
413 void print_setup(msgnum) {
416 get_setup_msg(dispbuf, msgnum);
417 printf("\n\n%s\n\n", dispbuf);
421 void important_message(char *title, char *msgtext) {
427 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
428 printf(" %s \n\n%s\n\n", title, msgtext);
433 sprintf(buf, "dialog --title \"%s\" --msgbox \"\n%s\" 20 80",
442 printw(" Important Message ");
445 printw("%s", msgtext);
454 void important_msgnum(int msgnum) {
457 get_setup_msg(dispbuf, msgnum);
458 important_message("Important Message", dispbuf);
461 void display_error(char *error_message) {
462 important_message("Error", error_message);
465 void progress(text,curr,cmax)
469 static long dots_printed;
472 static FILE *gauge = NULL;
480 printf("..........................");
481 printf("..........................");
482 printf("..........................\r");
486 else if (curr==cmax) {
487 printf("\r%79s\n","");
490 a=(curr * 100) / cmax;
492 while (dots_printed < a) {
507 printf("..........................");
508 printf("..........................");
509 printf("..........................\r");
513 else if (curr==cmax) {
518 a=(curr * 100) / cmax;
522 while (dots_printed < a) {
532 if ( (curr == 0) && (gauge == NULL) ) {
533 sprintf(gcmd, "dialog --guage \"%s\" 7 80 0",
535 gauge = (FILE *) popen(gcmd, "w");
538 else if (curr==cmax) {
539 fprintf(gauge, "100\n");
544 a=(curr * 100) / cmax;
546 fprintf(gauge, "%ld\n", a);
558 * check_services_entry() -- Make sure "citadel" is in /etc/services
561 void check_services_entry() {
566 "There is no '%s' entry in /etc/services. Would you like to add one?",
569 if (getservbyname(SERVICE_NAME, PROTO_NAME) == NULL) {
570 if (yesno(question)==1) {
571 sfp = fopen("/etc/services", "a");
573 display_error(strerror(errno));
576 fprintf(sfp, "%s 504/tcp\n",
587 * check_inittab_entry() -- Make sure "citadel" is in /etc/inittab
590 void check_inittab_entry() {
593 char looking_for[256];
599 /* Determine the fully qualified path name of citserver */
600 sprintf(looking_for, "%s/citserver ", BBSDIR);
602 /* Pound through /etc/inittab line by line. Set have_entry to 1 if
603 * an entry is found which we believe starts citserver.
605 infp = fopen("/etc/inittab", "r");
607 display_error(strerror(errno));
610 while (fgets(buf, 256, infp) != NULL) {
611 buf[strlen(buf) - 1] = 0;
612 ptr = strtok(buf, ":");
613 ptr = strtok(NULL, ":");
614 ptr = strtok(NULL, ":");
615 ptr = strtok(NULL, ":");
617 if (!strncmp(ptr, looking_for, strlen(looking_for))) {
625 /* If there's already an entry, then we have nothing left to do. */
626 if (have_entry > 0) return;
628 /* Otherwise, prompt the user to create an entry. */
630 "There is no '%s' entry in /etc/inittab.\nWould you like to add one?",
632 if (yesno(question)==0) return;
634 /* Generate a unique entry name for /etc/inittab */
635 sprintf(entryname, "c0");
638 if (entryname[1] > '9') {
641 if (entryname[0] > 'z') {
643 "Can't generate a unique entry name");
648 "grep %s: /etc/inittab >/dev/null 2>&1", entryname);
649 } while(system(buf)==0);
651 /* Now write it out to /etc/inittab */
652 infp = fopen("/etc/inittab", "a");
654 display_error(strerror(errno));
657 fprintf(infp, "# Start the Citadel/UX server...\n");
658 fprintf(infp,"%s:2345:respawn:%s -h%s\n",
659 entryname, looking_for, setup_directory);
668 * Create a blank call log
672 struct calllog calllog;
674 calllog.CLfullname[0]=0;
679 file=creat("calllog.pos",0666);
680 chmod("calllog.pos",0666);
681 write(file,&a,sizeof(int));
684 file=creat("calllog",0666);
685 chmod("calllog",0666);
686 for (a=0; a<CALLLOG; ++a) {
687 progress("Creating call log file",
691 write(file,&calllog,sizeof(struct calllog));
697 void set_str_val(int msgpos, char str[]) {
703 sprintf(tempfile, "/tmp/setup.%d", getpid());
705 switch (setup_type) {
707 title(setup_titles[msgpos]);
709 if (msgpos==11) dump_access_levels();
710 printf("This is currently set to:\n%s\n",str);
711 printf("Enter new value or press return to leave unchanged:\n");
712 fgets(buf, 4096, stdin);
713 buf[strlen(buf)-1] = 0;
714 if (strlen(buf)!=0) strcpy(str,buf);
717 get_setup_msg(setupmsg, msgpos);
719 "dialog --title \"%s\" --inputbox \"\n%s\n\" 20 80 \"%s\" 2>%s",
720 setup_titles[msgpos],
723 if (system(buf)==0) {
724 fp = fopen(tempfile, "rb");
725 fgets(str, 4095, fp);
728 if (str[strlen(str)-1]==10)
729 str[strlen(str)-1]=0;
735 move(1, ((80-strlen(setup_titles[msgpos]))/2) );
737 printw("%s", setup_titles[msgpos]);
740 get_setup_msg(setupmsg, msgpos);
741 printw("%s", setupmsg);
743 getlin(20, 0, str, 80);
749 void set_int_val(msgpos, ip)
753 sprintf(buf,"%d",(int)*ip);
754 set_str_val(msgpos, buf);
759 void set_char_val(msgpos, ip)
763 sprintf(buf,"%d",(int)*ip);
764 set_str_val(msgpos, buf);
765 *ip = (char)atoi(buf);
769 void set_long_val(msgpos, ip)
773 sprintf(buf,"%ld",*ip);
774 set_str_val(msgpos, buf);
779 int yesno_s(question) {
785 sprintf(tempfile, "/tmp/setup.%d", getpid());
786 switch (setup_type) {
790 if (a==1) a=yesno("Are you SURE you want to reinitialize this file? ");
796 if (a==1) a=yesno("Are you SURE you want to reinitialize this file? ");
803 sprintf(buf, "dialog --title \"Confirm file overwrite\" --menu \"\nAre you SURE you want to reinitialize this file?\n\" 13 80 2 NO \"No, don't overwrite\" YES \"Yes, overwrite the existing file\" 2>%s", tempfile);
805 if (a != 0) return(0);
806 fp = fopen(tempfile, "rb");
807 fgets(buf, 4095, fp);
810 if (buf[strlen(buf)-1]==10)
811 buf[strlen(buf)-1]=0;
812 return( (!strcmp(buf, "YES")) ? 1 : 0 );
817 return(0); /* just in case */
821 void edit_value(curr)
828 set_str_val(curr, config.c_nodename);
832 set_str_val(curr, config.c_fqdn);
836 set_str_val(curr, config.c_humannode);
840 set_str_val(curr, config.c_phonenum);
844 set_str_val(curr, config.c_bbs_city);
848 set_str_val(curr, config.c_sysadm);
852 set_int_val(curr, &config.c_bbsuid);
856 set_int_val(curr, &config.c_pwcrypt);
860 set_char_val(curr, &config.c_creataide);
864 set_int_val(curr, &config.c_sleeping);
868 set_char_val(curr, &config.c_initax);
872 set_char_val(curr, &config.c_regiscall);
876 set_char_val(curr, &config.c_twitdetect);
880 set_str_val(curr, config.c_twitroom);
884 set_int_val(curr, &config.c_maxsessions);
888 set_str_val(curr, config.c_moreprompt);
892 set_char_val(curr, &config.c_restrict);
896 set_long_val(curr, &config.c_msgbase);
900 set_str_val(curr, config.c_bucket_dir);
901 config.c_bucket_dir[14] = 0;
902 for (a=0; a<strlen(config.c_bucket_dir); ++a)
903 if (!isalpha(config.c_bucket_dir[a]))
904 strcpy(&config.c_bucket_dir[a],
905 &config.c_bucket_dir[a+1]);
909 set_str_val(curr, config.c_net_password);
913 set_int_val(curr, &config.c_port_number);
921 * (re-)write the config data to disk
923 void write_config_to_disk() {
926 fp=fopen("citadel.config","wb");
928 display_error("setup: cannot open citadel.config");
931 fwrite((char *)&config,sizeof(struct config),1,fp);
939 * Figure out what type of user interface we're going to use
947 if (system("dialog -h </dev/null 2>&1 |grep Savio")==0) {
958 void main(int argc, char *argv[]) {
963 int old_setup_level = 0;
966 /* set an invalid setup type */
969 /* parse command line args */
970 for (a=0; a<argc; ++a) {
971 if (!strncmp(argv[a], "-u", 2)) {
972 strcpy(aaa, argv[a]);
973 strcpy(aaa, &aaa[2]);
974 setup_type = atoi(aaa);
976 if (!strcmp(argv[a], "-i")) {
982 /* If a setup type was not specified, try to determine automatically
983 * the best one to use out of all available types.
985 if (setup_type < 0) {
986 setup_type = discover_ui();
990 if (setup_type == UI_CURSES) {
997 if (info_only == 1) {
998 important_message("Citadel/UX Setup", CITADEL);
1002 strcpy(setup_directory, BBSDIR);
1003 set_str_val(0, setup_directory);
1004 if (chdir(setup_directory) != 0) {
1005 important_message("Citadel/UX Setup",
1006 "The directory you specified does not exist.");
1011 switch(setup_type) {
1014 printf("\n\n\n *** Citadel/UX setup program ***\n\n");
1018 system("exec clear");
1024 * What we're going to try to do here is append a whole bunch of
1025 * nulls to the citadel.config file, so we can keep the old config
1026 * values if they exist, but if the file is missing or from an
1027 * earlier version with a shorter config structure, when setup tries
1028 * to read the old config parameters, they'll all come up zero.
1029 * The length of the config file will be set to what it's supposed
1030 * to be when we rewrite it, because we replace the old file with a
1031 * completely new copy. (Neat, eh?)
1034 fp=fopen("citadel.config","ab");
1036 display_error("setup: cannot append citadel.config");
1039 for (a=0; a<sizeof(struct config); ++a) putc(0,fp);
1042 /* now we re-open it, and read the old or blank configuration */
1043 fp=fopen("citadel.config","rb");
1045 display_error("setup: cannot open citadel.config");
1048 fread((char *)&config,sizeof(struct config),1,fp);
1052 /* set some sample/default values in place of blanks... */
1053 if (strlen(config.c_nodename)==0)
1054 strcpy(config.c_nodename,"mysystem");
1055 if (strlen(config.c_fqdn)==0)
1056 sprintf(config.c_fqdn,"%s.UUCP",config.c_nodename);
1057 if (strlen(config.c_humannode)==0)
1058 strcpy(config.c_humannode,"My System");
1059 if (strlen(config.c_phonenum)==0)
1060 strcpy(config.c_phonenum,"US 800 555 1212");
1061 if (config.c_initax == 0)
1062 config.c_initax = 1;
1063 if (strlen(config.c_moreprompt)==0)
1064 strcpy(config.c_moreprompt,"<more>");
1065 if (strlen(config.c_twitroom)==0)
1066 strcpy(config.c_twitroom,"Trashcan");
1067 if (strlen(config.c_bucket_dir)==0)
1068 strcpy(config.c_bucket_dir,"bitbucket");
1069 if (strlen(config.c_net_password)==0)
1070 strcpy(config.c_net_password,"netpassword");
1071 if (config.c_port_number == 0) {
1072 config.c_port_number = 504;
1074 if (config.c_ipgm_secret == 0) {
1076 config.c_ipgm_secret = rand();
1078 if (config.c_sleeping == 0) {
1079 config.c_sleeping = 900;
1082 /* Go through a series of dialogs prompting for config info */
1083 for (curr = 1; curr <= MAXSETUP; ++curr) {
1088 if (setuid(config.c_bbsuid) != 0) {
1089 important_message("Citadel/UX Setup",
1090 "Failed to change the user ID to your BBS user.");
1095 /***** begin version update section ***** */
1096 /* take care of any updating that is necessary */
1098 old_setup_level = config.c_setup_level;
1100 if (old_setup_level == 0) goto NEW_INST;
1102 if (old_setup_level < 323) {
1103 important_message("Citadel/UX Setup",
1104 "This Citadel/UX installation is too old to be upgraded.");
1108 write_config_to_disk();
1110 if ((config.c_setup_level / 10) == 32) {
1111 important_msgnum(31);
1115 if (config.c_setup_level < 400) {
1116 config.c_setup_level = 400;
1119 /* end of 3.23 -> 4.00 update section */
1121 /* end of 4.00 -> 4.02 update section */
1123 old_setup_level = config.c_setup_level;
1125 /* end of version update section */
1128 config.c_setup_level = REV_LEVEL;
1129 write_config_to_disk();
1131 system("mkdir info 2>/dev/null"); /* Create these */
1132 system("mkdir bio 2>/dev/null");
1133 system("mkdir userpics 2>/dev/null");
1134 system("mkdir messages 2>/dev/null");
1135 system("mkdir help 2>/dev/null");
1136 system("mkdir images 2>/dev/null");
1137 sprintf(aaa,"mkdir %s 2>/dev/null",config.c_bucket_dir);
1141 system("rm -fr ./chatpipes 2>/dev/null"); /* Don't need these */
1142 system("rm -fr ./expressmsgs 2>/dev/null");
1145 important_msgnum(30);
1149 fp=fopen("calllog","r");
1155 if (yesno_s("Create call log?")==1) cre8clog();
1158 check_services_entry(); /* Check /etc/services */
1159 check_inittab_entry(); /* Check /etc/inittab */
1161 progress("Setting file permissions", 0, 3);
1162 chown(".", config.c_bbsuid, getgid());
1163 progress("Setting file permissions", 1, 3);
1164 chown("citadel.config", config.c_bbsuid, getgid());
1165 progress("Setting file permissions", 2, 3);
1166 sprintf(aaa, "find . -exec chown %d {} \\; 2>/dev/null",
1169 progress("Setting file permissions", 3, 3);
1171 important_message("Setup finished",
1172 "Setup is finished. You may now start the Citadel server.");