]> code.citadel.org Git - citadel.git/blobdiff - citadel/setup.c
* Replaced all "Citadel/UX" references with "Citadel"
[citadel.git] / citadel / setup.c
index b32e6f68e6034cd625dfd630ed932f068282c2c5..038c5c3e225cafaf70baa7baeca3574ac2005327 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * $Id$
  *
- * Citadel/UX setup utility
+ * Citadel setup utility
  *
  */
 
@@ -32,7 +32,7 @@
 #endif
 
 
-#define MAXSETUP 3     /* How many setup questions to ask */
+#define MAXSETUP 4     /* How many setup questions to ask */
 
 #define UI_TEXT                0       /* Default setup type -- text only */
 #define UI_SILENT      3       /* Silent running, for use in scripts */
 int setup_type;
 char setup_directory[SIZ];
 char init_entry[SIZ];
+int using_web_installer = 0;
 
 char *setup_titles[] =
 {
        "Citadel Home Directory",
        "System Administrator",
        "Citadel User ID",
+       "Server IP address",
        "Server port number",
 };
 
@@ -71,13 +73,18 @@ char *setup_text[] =
 "user ID.  Please specify that user ID here.  You may specify either a\n"
 "user name or a numeric UID.\n",
 
+"Specify the IP address on which your server will run.  If you leave this\n"
+"blank, or if you specify 0.0.0.0, Citadel will listen on all addresses.\n"
+"You can usually skip this unless you're running multiple instances of\n"
+"Citadel on the same computer.\n",
+
 "Specify the TCP port number on which your server will run.  Normally, this\n"
 "will be port 504, which is the official port assigned by the IANA for\n"
 "Citadel servers.  You'll only need to specify a different port number if\n"
 "you run multiple instances of Citadel on the same computer and there's\n"
 "something else already using port 504.\n",
 
-"Setup has detected that you currently have data files from a Citadel/UX\n"
+"Setup has detected that you currently have data files from a Citadel\n"
 "version 3.2x installation.  The program 'conv_32_40' can upgrade your\n"
 "files to version 4.0x format.\n"
 " Setup will now exit.  Please either run 'conv_32_40' or delete your data\n"
@@ -460,8 +467,8 @@ void check_inittab_entry(void)
        if (infp == NULL) {
                display_error(strerror(errno));
        } else {
-               fprintf(infp, "# Start the Citadel/UX server...\n");
-               fprintf(infp, "%s:2345:respawn:%s -h%s\n",
+               fprintf(infp, "# Start the Citadel server...\n");
+               fprintf(infp, "%s:2345:respawn:%s -h%s -x3 -llocal4\n",
                        entryname, looking_for, setup_directory);
                fclose(infp);
                strcpy(init_entry, entryname);
@@ -492,7 +499,7 @@ void check_xinetd_entry(void) {
        snprintf(buf, sizeof buf,
                "Setup can configure the 'xinetd' service to automatically\n"
                "connect incoming telnet sessions to Citadel, bypassing the\n"
-               "host system's login prompt.  Would you like to do this?"
+               "host system's login prompt.  Would you like to do this?\n"
        );
        if (yesno(buf) == 0)
                return;
@@ -521,6 +528,84 @@ void check_xinetd_entry(void) {
 
 
 
+/*
+ * Offer to disable other MTA's
+ */
+void disable_other_mta(char *mta) {
+       char buf[SIZ];
+       FILE *fp;
+       int lines = 0;
+
+       sprintf(buf, "/bin/ls -l /etc/rc*.d/S*%s 2>/dev/null", mta);
+       fp = popen(buf, "r");
+       if (fp == NULL) return;
+
+       while (fgets(buf, sizeof buf, fp) != NULL) {
+               ++lines;
+       }
+       fclose(fp);
+       if (lines == 0) return;         /* Nothing to do. */
+
+       /* Offer to replace other MTA with the vastly superior Citadel :)  */
+       snprintf(buf, sizeof buf,
+               "You appear to have the '%s' email program\n"
+               "running on your system.  Would you like to disable it,\n"
+               "allowing Citadel to handle your system's Internet mail\n"
+               "instead?\n",
+               mta
+       );
+       if (yesno(buf) == 0)
+               return;
+
+       sprintf(buf, "for x in /etc/rc*.d/S*%s; do mv $x `echo $x |sed s/S/K/g`; done >/dev/null 2>&1", mta);
+       system(buf);
+       sprintf(buf, "/etc/init.d/%s stop >/dev/null 2>&1", mta);
+       system(buf);
+}
+
+
+
+
+/* 
+ * Check to see if our server really works.  Returns 0 on success.
+ */
+int test_server(void) {
+       char cmd[256];
+       char cookie[256];
+       FILE *fp;
+       char buf[4096];
+       int found_it = 0;
+
+       /* Generate a silly little cookie.  We're going to write it out
+        * to the server and try to get it back.  The cookie does not
+        * have to be secret ... just unique.
+        */
+       sprintf(cookie, "%ld.%d", time(NULL), getpid());
+
+       sprintf(cmd, "%s/sendcommand -h%s ECHO %s 2>&1",
+               setup_directory,
+               setup_directory,
+               cookie);
+
+       fp = popen(cmd, "r");
+       if (fp == NULL) return(errno);
+
+       while (fgets(buf, sizeof buf, fp) != NULL) {
+               if ( (buf[0]=='2')
+                  && (strstr(buf, cookie) != NULL) ) {
+                       ++found_it;
+               }
+       }
+       pclose(fp);
+
+       if (found_it) {
+               return(0);
+       }
+       return(-1);
+}
+
+
+
 
 
 
@@ -532,10 +617,8 @@ void set_str_val(int msgpos, char str[])
        int i;
 #endif
        char buf[SIZ];
-       char tempfile[PATH_MAX];
        char setupmsg[SIZ];
 
-       strcpy(tempfile, tmpnam(NULL));
        strcpy(setupmsg, "");
 
        switch (setup_type) {
@@ -634,6 +717,10 @@ void edit_value(int curr)
                break;
 
        case 3:
+               set_str_val(curr, &config.c_ip_addr);
+               break;
+
+       case 4:
                set_int_val(curr, &config.c_port_number);
                break;
 
@@ -674,7 +761,7 @@ int discover_ui(void)
 #ifdef HAVE_NEWT
        newtInit();
        newtCls();
-       newtDrawRootText(0, 0, "Citadel/UX Setup");
+       newtDrawRootText(0, 0, "Citadel Setup");
        return UI_NEWT;
 #endif
        return UI_TEXT;
@@ -700,6 +787,11 @@ int main(int argc, char *argv[])
        /* set an invalid setup type */
        setup_type = (-1);
 
+        /* Check to see if we're running the web installer */
+       if (getenv("CITADEL_INSTALLER") != NULL) {
+               using_web_installer = 1;
+       }
+
        /* parse command line args */
        for (a = 0; a < argc; ++a) {
                if (!strncmp(argv[a], "-u", 2)) {
@@ -723,15 +815,21 @@ int main(int argc, char *argv[])
                setup_type = discover_ui();
        }
        if (info_only == 1) {
-               important_message("Citadel/UX Setup", CITADEL);
+               important_message("Citadel Setup", CITADEL);
                cleanup(0);
        }
 
        /* Get started in a valid setup directory. */
        strcpy(setup_directory, BBSDIR);
-       set_str_val(0, setup_directory);
+       if ( (using_web_installer) && (getenv("CITADEL") != NULL) ) {
+               strcpy(setup_directory, getenv("CITADEL"));
+       }
+       else {
+               set_str_val(0, setup_directory);
+       }
+
        if (chdir(setup_directory) != 0) {
-               important_message("Citadel/UX Setup",
+               important_message("Citadel Setup",
                          "The directory you specified does not exist.");
                cleanup(errno);
        }
@@ -746,12 +844,21 @@ int main(int argc, char *argv[])
                sleep(1);
        }
 
+       /* Make sure it's stopped. */
+       if (test_server() == 0) {
+               important_message("Citadel Setup",
+                       "The Citadel service is still running.\n"
+                       "Please stop the service manually and run "
+                       "setup again.");
+               cleanup(1);
+       }
+
        /* Now begin. */
        switch (setup_type) {
 
        case UI_TEXT:
                printf("\n\n\n"
-                       "               *** Citadel/UX setup program ***\n\n");
+                       "               *** Citadel setup program ***\n\n");
                break;
 
        }
@@ -814,8 +921,6 @@ int main(int argc, char *argv[])
                strcpy(config.c_moreprompt, "<more>");
        if (strlen(config.c_twitroom) == 0)
                strcpy(config.c_twitroom, "Trashcan");
-       if (strlen(config.c_net_password) == 0)
-               strcpy(config.c_net_password, "netpassword");
        if (strlen(config.c_baseroom) == 0)
                strcpy(config.c_baseroom, "Lobby");
        if (strlen(config.c_aideroom) == 0)
@@ -874,7 +979,7 @@ int main(int argc, char *argv[])
 
        /*
           if (setuid(config.c_bbsuid) != 0) {
-          important_message("Citadel/UX Setup",
+          important_message("Citadel Setup",
           "Failed to change the user ID to your Citadel user.");
           cleanup(errno);
           }
@@ -885,28 +990,18 @@ int main(int argc, char *argv[])
 
        old_setup_level = config.c_setup_level;
 
-       if (old_setup_level == 0)
+       if (old_setup_level == 0) {
                goto NEW_INST;
+       }
 
-       if (old_setup_level < 323) {
-               important_message("Citadel/UX Setup",
-                                 "This Citadel/UX installation is too old "
+       if (old_setup_level < 555) {
+               important_message("Citadel Setup",
+                                 "This Citadel installation is too old "
                                  "to be upgraded.");
                cleanup(1);
        }
        write_config_to_disk();
 
-       if ((config.c_setup_level / 10) == 32) {
-               important_msgnum(31);
-               cleanup(0);
-       }
-       if (config.c_setup_level < 400) {
-               config.c_setup_level = 400;
-       }
-       /* end of 3.23 -> 4.00 update section */
-
-       /* end of 4.00 -> 4.02 update section */
-
        old_setup_level = config.c_setup_level;
 
        /* end of version update section */
@@ -919,23 +1014,49 @@ NEW_INST:
        write_config_to_disk();
 
        mkdir("info", 0700);
+       chmod("info", 0700);
        mkdir("bio", 0700);
+       chmod("bio", 0700);
        mkdir("userpics", 0700);
+       chmod("userpics", 0700);
        mkdir("messages", 0700);
+       chmod("messages", 0700);
        mkdir("help", 0700);
+       chmod("help", 0700);
        mkdir("images", 0700);
+       chmod("images", 0700);
        mkdir("netconfigs", 0700);
+       chmod("netconfigs", 0700);
 
-       /* Delete a bunch of old files from Citadel v4; don't need anymore */
-       system("rm -fr ./chatpipes ./expressmsgs ./sessions 2>/dev/null");
-
-       /* Delete the old citadel.log file; this facility has been removed */
+       /* Delete files and directories used by older Citadel versions */
+       system("exec /bin/rm -fr ./rooms ./chatpipes ./expressmsgs ./sessions 2>/dev/null");
        unlink("citadel.log");
+       unlink("weekly");
 
        check_services_entry(); /* Check /etc/services */
 #ifndef __CYGWIN__
        check_inittab_entry();  /* Check /etc/inittab */
        check_xinetd_entry();   /* Check /etc/xinetd.d/telnet */
+
+       /* Offer to disable other MTA's on the system. */
+       disable_other_mta("sendmail");
+       disable_other_mta("postfix");
+       disable_other_mta("qmail");
+       disable_other_mta("cyrus");
+       disable_other_mta("cyrmaster");
+       disable_other_mta("saslauthd");
+       disable_other_mta("mta");
+       disable_other_mta("courier-imap");
+       disable_other_mta("courier-imap-ssl");
+       disable_other_mta("courier-authdaemon");
+       disable_other_mta("courier-pop3");
+       disable_other_mta("courier-pop3d");
+       disable_other_mta("courier-pop");
+       disable_other_mta("vmailmgrd");
+       disable_other_mta("imapd");
+       disable_other_mta("popd");
+       disable_other_mta("pop3d");
+       disable_other_mta("exim");
 #endif
 
        if ((pw = getpwuid(config.c_bbsuid)) == NULL)
@@ -963,8 +1084,16 @@ NEW_INST:
                        if (a == 0) start_the_service();
                        sleep(1);
                }
-               important_message("Setup finished",
-                       "Setup is finished.  You may now log in.");
+               if (test_server() == 0) {
+                       important_message("Setup finished",
+                               "Setup is finished.  You may now log in.");
+               }
+               else {
+                       important_message("Setup finished",
+                               "Setup is finished, but the Citadel service "
+                               "failed to start.\n"
+                               "Go back and check your configuration.");
+               }
        }
        else {
                important_message("Setup finished",