/*
- * Citadel/UX setup program
* $Id$
*
- * *** YOU MUST EDIT sysconfig.h >BEFORE< COMPILING SETUP ***
+ * Citadel/UX setup utility
+ *
*/
#include <stdlib.h>
#include "config.h"
#include "tools.h"
-#ifdef HAVE_CURSES_H
-#ifdef OK
-#undef OK
-#endif
+#if defined(HAVE_CURSES_H) || defined(HAVE_NCURSES_H)
+
+#ifdef HAVE_NCURSES_H
+#include <ncurses.h>
+#else
#include <curses.h>
#endif
+#endif
+
#define MAXSETUP 5
#define UI_TEXT 0 /* Default setup type -- text only */
-#define UI_DIALOG 1 /* Use the 'dialog' program */
+#define UI_DIALOG 1 /* Use the 'dialog' program (REMOVED) */
#define UI_CURSES 2 /* Use curses */
+#define UI_SILENT 3 /* Silent running, for use in scripts */
#define SERVICE_NAME "citadel"
#define PROTO_NAME "tcp"
return;
}
#endif
- printf("Press return to continue...");
- fgets(junk, 5, stdin);
+ if (setup_type == UI_TEXT) {
+ printf("Press return to continue...");
+ fgets(junk, 5, stdin);
+ }
}
int yesno(char *question)
} while ((answer < 0) || (answer > 1));
break;
- case UI_DIALOG:
- sprintf(buf, "dialog --yesno \"%s\" 7 80", question);
- answer = ((system(buf) == 0) ? 1 : 0);
- break;
#ifdef HAVE_CURSES_H
case UI_CURSES:
do {
-void dump_access_levels(void)
-{
- int a;
- for (a = 0; a <= 6; ++a)
- printf("%d %s\n", a, axdefs[a]);
-}
-
void get_setup_msg(char *dispbuf, int msgnum)
{
int a, b;
void important_message(char *title, char *msgtext)
{
- char buf[4096];
switch (setup_type) {
hit_any_key();
break;
- case UI_DIALOG:
- sprintf(buf, "dialog --title \"%s\" --msgbox \"\n%s\" 20 80",
- title, msgtext);
- system(buf);
- break;
#ifdef HAVE_CURSES_H
case UI_CURSES:
clear();
{
static long dots_printed;
long a;
- static long prev;
- static FILE *gauge = NULL;
- char gcmd[256];
switch (setup_type) {
break;
#endif
- case UI_DIALOG:
- if ((curr == 0) && (gauge == NULL)) {
- sprintf(gcmd, "dialog --guage \"%s\" 7 80 0",
- text);
- gauge = (FILE *) popen(gcmd, "w");
- prev = 0;
- } else if (curr == cmax) {
- fprintf(gauge, "100\n");
- pclose(gauge);
- gauge = NULL;
- } else {
- a = (curr * 100) / cmax;
- if (a != prev) {
- fprintf(gauge, "%ld\n", a);
- fflush(gauge);
- }
- prev = a;
- }
- break;
}
}
char question[128];
FILE *sfp;
- sprintf(question,
+ snprintf(question, sizeof question,
"There is no '%s' entry in /etc/services. Would you like to add one?",
SERVICE_NAME);
void check_inittab_entry(void)
{
FILE *infp;
- char buf[256];
- char looking_for[256];
+ char buf[SIZ];
+ char looking_for[SIZ];
char question[128];
char *ptr;
int have_entry = 0;
- char entryname[3];
+ char entryname[5];
/* Determine the fully qualified path name of citserver */
- sprintf(looking_for, "%s/citserver ", BBSDIR);
+ snprintf(looking_for, sizeof looking_for, "%s/citserver ", BBSDIR);
/* Pound through /etc/inittab line by line. Set have_entry to 1 if
* an entry is found which we believe starts citserver.
if (infp == NULL) {
return;
} else {
- while (fgets(buf, 256, infp) != NULL) {
+ while (fgets(buf, sizeof buf, infp) != NULL) {
buf[strlen(buf) - 1] = 0;
ptr = strtok(buf, ":");
ptr = strtok(NULL, ":");
ptr = strtok(NULL, ":");
ptr = strtok(NULL, ":");
if (ptr != NULL) {
- if (!strncmp(ptr, looking_for, strlen(looking_for))) {
+ if (!strncmp(ptr, looking_for,
+ strlen(looking_for))) {
++have_entry;
}
}
return;
/* Otherwise, prompt the user to create an entry. */
- sprintf(question,
- "There is no '%s' entry in /etc/inittab.\nWould you like to add one?",
+ snprintf(question, sizeof question,
+ "There is no '%s' entry in /etc/inittab.\n"
+ "Would you like to add one?",
looking_for);
if (yesno(question) == 0)
return;
/* Generate a unique entry name for /etc/inittab */
- sprintf(entryname, "c0");
+ snprintf(entryname, sizeof entryname, "c0");
do {
++entryname[1];
if (entryname[1] > '9') {
return;
}
}
- sprintf(buf,
+ snprintf(buf, sizeof buf,
"grep %s: /etc/inittab >/dev/null 2>&1", entryname);
} while (system(buf) == 0);
void set_str_val(int msgpos, char str[])
{
char buf[4096];
- char setupmsg[4096];
char tempfile[64];
- FILE *fp;
+ char setupmsg[SIZ];
- sprintf(tempfile, "/tmp/setup.%ld", (long) getpid());
+ strcpy(tempfile, tmpnam(NULL));
+ strcpy(setupmsg, "");
switch (setup_type) {
case UI_TEXT:
title(setup_titles[msgpos]);
print_setup(msgpos);
- if (msgpos == 11)
- dump_access_levels();
printf("This is currently set to:\n%s\n", str);
printf("Enter new value or press return to leave unchanged:\n");
fgets(buf, 4096, stdin);
if (strlen(buf) != 0)
strcpy(str, buf);
break;
- case UI_DIALOG:
- get_setup_msg(setupmsg, msgpos);
- sprintf(buf,
- "dialog --title \"%s\" --inputbox \"\n%s\n\" 20 80 \"%s\" 2>%s",
- setup_titles[msgpos],
- setupmsg,
- str, tempfile);
- if (system(buf) == 0) {
- fp = fopen(tempfile, "rb");
- fgets(str, 4095, fp);
- fclose(fp);
- if (strlen(str) > 0)
- if (str[strlen(str) - 1] == 10)
- str[strlen(str) - 1] = 0;
- }
- break;
#ifdef HAVE_CURSES_H
case UI_CURSES:
clear();
void set_int_val(int msgpos, int *ip)
{
char buf[16];
- sprintf(buf, "%d", (int) *ip);
+ snprintf(buf, sizeof buf, "%d", (int) *ip);
set_str_val(msgpos, buf);
*ip = atoi(buf);
}
void set_char_val(int msgpos, char *ip)
{
char buf[16];
- sprintf(buf, "%d", (int) *ip);
+ snprintf(buf, sizeof buf, "%d", (int) *ip);
set_str_val(msgpos, buf);
*ip = (char) atoi(buf);
}
void set_long_val(int msgpos, long int *ip)
{
char buf[16];
- sprintf(buf, "%ld", *ip);
+ snprintf(buf, sizeof buf, "%ld", *ip);
set_str_val(msgpos, buf);
*ip = atol(buf);
}
void edit_value(int curr)
{
int a;
+ long l;
switch (curr) {
break;
case 2:
- set_int_val(curr, &config.c_bbsuid);
+ l = config.c_bbsuid;
+ set_long_val(curr, &l);
+ config.c_bbsuid = l;
break;
case 3:
#ifdef HAVE_CURSES_H
return UI_CURSES;
#endif
-
- if (system("dialog -h </dev/null 2>&1 |grep Savio") == 0) {
- return UI_DIALOG;
- }
return UI_TEXT;
}
if (!strcmp(argv[a], "-i")) {
info_only = 1;
}
+ if (!strcmp(argv[a], "-q")) {
+ setup_type = UI_SILENT;
+ }
}
switch (setup_type) {
case UI_TEXT:
- printf("\n\n\n *** Citadel/UX setup program ***\n\n");
- break;
-
- case UI_DIALOG:
- system("exec clear");
+ printf("\n\n\n"
+ " *** Citadel/UX setup program ***\n\n");
break;
}
strcpy(config.c_humannode, "My System");
if (strlen(config.c_phonenum) == 0)
strcpy(config.c_phonenum, "US 800 555 1212");
- if (config.c_initax == 0)
- config.c_initax = 1;
+ if (config.c_initax == 0) {
+ config.c_initax = 4;
+ }
if (strlen(config.c_moreprompt) == 0)
strcpy(config.c_moreprompt, "<more>");
if (strlen(config.c_twitroom) == 0)
config.c_ep.expire_mode = EXPIRE_NUMMSGS;
config.c_ep.expire_value = 150;
}
+
+ /*
+ * Default port numbers for various services
+ */
+ if (config.c_smtp_port == 0) config.c_smtp_port = 25;
+ if (config.c_pop3_port == 0) config.c_pop3_port = 110;
+ if (config.c_imap_port == 0) config.c_imap_port = 143;
+
+
/* Go through a series of dialogs prompting for config info */
- for (curr = 1; curr <= MAXSETUP; ++curr) {
- edit_value(curr);
+ if (setup_type != UI_SILENT) {
+ for (curr = 1; curr <= MAXSETUP; ++curr) {
+ edit_value(curr);
+ }
}
/*
if (old_setup_level < 323) {
important_message("Citadel/UX Setup",
- "This Citadel/UX installation is too old to be upgraded.");
+ "This Citadel/UX installation is too old "
+ "to be upgraded.");
cleanup(1);
}
write_config_to_disk();
/* end of version update section */
- NEW_INST:
+NEW_INST:
config.c_setup_level = REV_LEVEL;
/******************************************/
write_config_to_disk();
- system("mkdir info 2>/dev/null"); /* Create these */
- system("mkdir bio 2>/dev/null");
- system("mkdir userpics 2>/dev/null");
- system("mkdir messages 2>/dev/null");
- system("mkdir help 2>/dev/null");
- system("mkdir images 2>/dev/null");
- sprintf(aaa, "mkdir %s 2>/dev/null", config.c_bucket_dir);
- system(aaa);
+ mkdir("info", 0700);
+ mkdir("bio", 0700);
+ mkdir("userpics", 0700);
+ mkdir("messages", 0700);
+ mkdir("help", 0700);
+ mkdir("images", 0700);
+ mkdir("netconfigs", 0700);
+ mkdir(config.c_bucket_dir, 0700);
/* Delete a bunch of old files from Citadel v4; don't need anymore */
system("rm -fr ./chatpipes ./expressmsgs sessions 2>/dev/null");
else
gid = pw->pw_gid;
- progress("Setting file permissions", 0, 4);
+ progress("Setting file permissions", 0, 5);
chown(".", config.c_bbsuid, gid);
- progress("Setting file permissions", 1, 4);
+ progress("Setting file permissions", 1, 5);
chown("citadel.config", config.c_bbsuid, gid);
- progress("Setting file permissions", 2, 4);
- sprintf(aaa, "find . -exec chown %d:%d {} \\; 2>/dev/null",
- config.c_bbsuid, gid);
+ progress("Setting file permissions", 2, 5);
+ snprintf(aaa, sizeof aaa,
+ "find . | grep -v chkpwd | xargs chown %ld:%ld 2>/dev/null",
+ (long)config.c_bbsuid, (long)gid);
system(aaa);
- progress("Setting file permissions", 2, 4);
- system("chmod 600 citadel.config");
- progress("Setting file permissions", 3, 4);
+ progress("Setting file permissions", 3, 5);
+ chmod("citadel.config", S_IRUSR | S_IWUSR);
+ progress("Setting file permissions", 4, 5);
important_message("Setup finished",
"Setup is finished. You may now start the Citadel server.");
-
cleanup(0);
return 0;
}