]> code.citadel.org Git - citadel.git/blobdiff - webcit/setup.c
* inetconf.c: fixed memory management problem that was causing all
[citadel.git] / webcit / setup.c
index 5d08633b66b21cd9ecd23db0c8fa7f50b7b43258..e139514ecd7a52f3a21ab7eac8781a3d978125e6 100644 (file)
@@ -31,6 +31,7 @@
 
 
 #define UI_TEXT                0       /* Default setup type -- text only */
+#define UI_DIALOG      2       /* Use the 'dialog' program */
 #define UI_SILENT      3       /* Silent running, for use in scripts */
 #define UI_NEWT                4       /* Use the "newt" window library */
 
@@ -108,7 +109,7 @@ void shutdown_service(void) {
        strcpy(init_entry, "");
 
        /* Determine the fully qualified path name of webserver */
-       snprintf(looking_for, sizeof looking_for, "%s/webserver ", WEBCITDIR);
+       snprintf(looking_for, sizeof looking_for, "%s/webserver ", setup_directory);
 
        /* Pound through /etc/inittab line by line.  Set have_entry to 1 if
         * an entry is found which we believe starts webserver.
@@ -175,8 +176,8 @@ int yesno(char *question)
        newtComponent form = NULL;
        newtComponent yesbutton = NULL;
        newtComponent nobutton = NULL;
-       int i = 0;
 #endif
+       int i = 0;
        int answer = 0;
        char buf[SIZ];
 
@@ -194,6 +195,19 @@ int yesno(char *question)
                } while ((answer < 0) || (answer > 1));
                break;
 
+       case UI_DIALOG:
+               sprintf(buf, "exec %s --yesno '%s' 10 72",
+                       getenv("CTDL_DIALOG"),
+                       question);
+               i = system(buf);
+               if (i == 0) {
+                       answer = 1;
+               }
+               else {
+                       answer = 0;
+               }
+               break;
+
 #ifdef HAVE_NEWT
        case UI_NEWT:
                newtCenteredWindow(76, 10, "Question");
@@ -230,7 +244,9 @@ void set_value(char *prompt, char str[])
        int i;
 #endif
        char buf[SIZ];
+       char *dialog_result;
        char setupmsg[SIZ];
+       FILE *fp;
 
        strcpy(setupmsg, "");
 
@@ -245,6 +261,27 @@ void set_value(char *prompt, char str[])
                if (strlen(buf) != 0)
                        strcpy(str, buf);
                break;
+
+       case UI_DIALOG:
+               dialog_result = tmpnam(NULL);
+               sprintf(buf, "exec %s --backtitle '%s' --inputbox '%s' 19 72 '%s' 2>%s",
+                       getenv("CTDL_DIALOG"),
+                       "WebCit setup",
+                       prompt,
+                       str,
+                       dialog_result);
+               system(buf);
+               fp = fopen(dialog_result, "r");
+               if (fp != NULL) {
+                       fgets(str, sizeof buf, fp);
+                       if (str[strlen(str)-1] == 10) {
+                               str[strlen(str)-1] = 0;
+                       }
+                       fclose(fp);
+                       unlink(dialog_result);
+               }
+               break;
+
 #ifdef HAVE_NEWT
        case UI_NEWT:
 
@@ -284,6 +321,14 @@ void important_message(char *title, char *msgtext)
                fgets(buf, sizeof buf, stdin);
                break;
 
+       case UI_DIALOG:
+               sprintf(buf, "exec %s --backtitle '%s' --msgbox '%s' 19 72",
+                       getenv("CTDL_DIALOG"),
+                       title,
+                       msgtext);
+               system(buf);
+               break;
+
 #ifdef HAVE_NEWT
        case UI_NEWT:
                newtCenteredWindow(76, 10, title);
@@ -322,6 +367,8 @@ void progress(char *text, long int curr, long int cmax)
 #endif
        static long dots_printed = 0L;
        long a = 0;
+       char buf[SIZ];
+       static FILE *fp = NULL;
 
        switch (setup_type) {
 
@@ -347,6 +394,33 @@ void progress(char *text, long int curr, long int cmax)
                }
                break;
 
+       case UI_DIALOG:
+               if (curr == 0) {
+                       sprintf(buf, "exec %s --gauge '%s' 7 72 0",
+                               getenv("CTDL_DIALOG"),
+                               text);
+                       fp = popen(buf, "w");
+                       if (fp != NULL) {
+                               fprintf(fp, "0\n");
+                               fflush(fp);
+                       }
+               } 
+               else if (curr == cmax) {
+                       if (fp != NULL) {
+                               fprintf(fp, "100\n");
+                               pclose(fp);
+                               fp = NULL;
+                       }
+               }
+               else {
+                       a = (curr * 100) / cmax;
+                       if (fp != NULL) {
+                               fprintf(fp, "%ld\n", a);
+                               fflush(fp);
+                       }
+               }
+               break;
+
 #ifdef HAVE_NEWT
        case UI_NEWT:
                if (curr == 0) {
@@ -386,12 +460,15 @@ void check_inittab_entry(void)
        char looking_for[SIZ];
        char question[SIZ];
        char entryname[5];
-       char listenport[128];
+       char http_port[128];
+#ifdef HAVE_OPENSSL
+       char https_port[128];
+#endif
        char hostname[128];
        char portname[128];
 
        /* Determine the fully qualified path name of webserver */
-       snprintf(looking_for, sizeof looking_for, "%s/webserver ", WEBCITDIR);
+       snprintf(looking_for, sizeof looking_for, "%s/webserver", setup_directory);
 
        /* If there's already an entry, then we have nothing left to do. */
        if (strlen(init_entry) > 0) {
@@ -411,8 +488,18 @@ void check_inittab_entry(void)
                "requests?\n\nYou can use the standard port (80) if you are "
                "not running another\nweb server (such as Apache), otherwise "
                "select another port.");
-       sprintf(listenport, "2000");
-       set_value(question, listenport);
+       sprintf(http_port, "2000");
+       set_value(question, http_port);
+
+#ifdef HAVE_OPENSSL
+       snprintf(question, sizeof question,
+               "On which port do you want WebCit to listen for HTTPS "
+               "requests?\n\nYou can use the standard port (443) if you are "
+               "not running another\nweb server (such as Apache), otherwise "
+               "select another port.");
+       sprintf(https_port, "443");
+       set_value(question, https_port);
+#endif
 
        /* Find out where Citadel is. */
        if ( (using_web_installer) && (getenv("CITADEL") != NULL) ) {
@@ -437,7 +524,7 @@ void check_inittab_entry(void)
                }
        }
 
-       /* Generate a unique entry name for /etc/inittab */
+       /* Generate unique entry names for /etc/inittab */
        snprintf(entryname, sizeof entryname, "c0");
        do {
                ++entryname[1];
@@ -453,6 +540,7 @@ void check_inittab_entry(void)
                snprintf(buf, sizeof buf,
                     "grep %s: /etc/inittab >/dev/null 2>&1", entryname);
        } while (system(buf) == 0);
+       
 
        /* Now write it out to /etc/inittab */
        infp = fopen("/etc/inittab", "a");
@@ -460,9 +548,14 @@ void check_inittab_entry(void)
                display_error(strerror(errno));
        } else {
                fprintf(infp, "# Start the WebCit server...\n");
-               fprintf(infp, "%s:2345:respawn:%s -p%s %s %s\n",
+               fprintf(infp, "h%s:2345:respawn:%s -p%s %s %s\n",
                        entryname, looking_for,
-                       listenport, hostname, portname);
+                       http_port, hostname, portname);
+#ifdef HAVE_OPENSSL
+               fprintf(infp, "s%s:2345:respawn:%s -p%s -s %s %s\n",
+                       entryname, looking_for,
+                       https_port, hostname, portname);
+#endif
                fclose(infp);
                strcpy(init_entry, entryname);
        }
@@ -477,6 +570,11 @@ void check_inittab_entry(void)
 int discover_ui(void)
 {
 
+       /* Use "dialog" if we have it */
+       if (getenv("CTDL_DIALOG") != NULL) {
+               return UI_DIALOG;
+       }
+               
 #ifdef HAVE_NEWT
        newtInit();
        newtCls();