]> 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 3c7eb7fa1d7bc53dbb914308a9a008fdae9d2daf..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) {
@@ -387,12 +461,14 @@ void check_inittab_entry(void)
        char question[SIZ];
        char entryname[5];
        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) {
@@ -448,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];
@@ -464,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");
@@ -471,14 +548,13 @@ void check_inittab_entry(void)
                display_error(strerror(errno));
        } else {
                fprintf(infp, "# Start the WebCit server...\n");
-#ifdef HAVE_OPENSSL
-               fprintf(infp, "%s:2345:respawn:%s -p%s -s%s %s %s\n",
-                       entryname, looking_for,
-                       http_port, https_port, hostname, portname);
-#else
-               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,
                        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);
@@ -494,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();