]> code.citadel.org Git - citadel.git/blobdiff - webcit/setup.c
* Header file adjustments to make it work on FreeBSD
[citadel.git] / webcit / setup.c
index e139514ecd7a52f3a21ab7eac8781a3d978125e6..f392011122142b9e2e29a90ad90bcf19f1848a82 100644 (file)
@@ -7,23 +7,39 @@
  *
  */
 
+
+#include <ctype.h>
 #include <stdlib.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <stdio.h>
-#include <string.h>
-#include <ctype.h>
+#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
+#endif
+#include <signal.h>
 #include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/utsname.h>
 #include <sys/wait.h>
-#include <signal.h>
-#include <netdb.h>
-#include <errno.h>
+#include <sys/socket.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_LIMITS_H
 #include <limits.h>
+#endif
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <string.h>
 #include <pwd.h>
-
+#include <errno.h>
+#include <stdarg.h>
+#include <pthread.h>
+#include <signal.h>
+#include <sys/utsname.h>
 #include "webcit.h"
+#include "webserver.h"
+
 
 #ifdef HAVE_NEWT
 #include <newt.h>
@@ -39,7 +55,7 @@ int setup_type;
 char setup_directory[SIZ];
 char init_entry[SIZ];
 int using_web_installer = 0;
-
+char suggested_url[SIZ];
 
 /*
  * Set an entry in inittab to the desired state
@@ -62,10 +78,10 @@ void set_init_entry(char *which_entry, char *new_state) {
        while(fgets(buf, sizeof buf, fp) != NULL) {
 
                if (num_tokens(buf, ':') == 4) {
-                       extract_token(entry, buf, 0, ':');
-                       extract_token(levels, buf, 1, ':');
-                       extract_token(state, buf, 2, ':');
-                       extract_token(prog, buf, 3, ':'); /* includes 0x0a LF */
+                       extract_token(entry, buf, 0, ':', sizeof entry);
+                       extract_token(levels, buf, 1, ':', sizeof levels);
+                       extract_token(state, buf, 2, ':', sizeof state);
+                       extract_token(prog, buf, 3, ':', sizeof prog); /* includes 0x0a LF */
 
                        if (!strcmp(entry, which_entry)) {
                                strcpy(state, new_state);
@@ -120,8 +136,8 @@ void shutdown_service(void) {
        } else {
                while (fgets(buf, sizeof buf, infp) != NULL) {
                        buf[strlen(buf) - 1] = 0;
-                       extract_token(entry, buf, 0, ':');      
-                       extract_token(prog, buf, 3, ':');
+                       extract_token(entry, buf, 0, ':', sizeof entry);
+                       extract_token(prog, buf, 3, ':', sizeof prog);
                        if (!strncasecmp(prog, looking_for,
                           strlen(looking_for))) {
                                ++have_entry;
@@ -213,7 +229,7 @@ int yesno(char *question)
                newtCenteredWindow(76, 10, "Question");
                form = newtForm(NULL, NULL, 0);
                for (i=0; i<num_tokens(question, '\n'); ++i) {
-                       extract_token(buf, question, i, '\n');
+                       extract_token(buf, question, i, '\n', sizeof buf);
                        newtFormAddComponent(form, newtLabel(1, 1+i, buf));
                }
                yesbutton = newtButton(10, 5, "Yes");
@@ -288,7 +304,7 @@ void set_value(char *prompt, char str[])
                newtCenteredWindow(76, 10, "WebCit setup");
                form = newtForm(NULL, NULL, 0);
                for (i=0; i<num_tokens(prompt, '\n'); ++i) {
-                       extract_token(buf, prompt, i, '\n');
+                       extract_token(buf, prompt, i, '\n', sizeof buf);
                        newtFormAddComponent(form, newtLabel(1, 1+i, buf));
                }
                newtFormAddComponent(form, newtEntry(1, 8, str, 74, &result,
@@ -334,7 +350,7 @@ void important_message(char *title, char *msgtext)
                newtCenteredWindow(76, 10, title);
                form = newtForm(NULL, NULL, 0);
                for (i=0; i<num_tokens(msgtext, '\n'); ++i) {
-                       extract_token(buf, msgtext, i, '\n');
+                       extract_token(buf, msgtext, i, '\n', sizeof buf);
                        newtFormAddComponent(form, newtLabel(1, 1+i, buf));
                }
                newtFormAddComponent(form, newtButton(35, 5, "OK"));
@@ -466,6 +482,7 @@ void check_inittab_entry(void)
 #endif
        char hostname[128];
        char portname[128];
+       struct utsname my_utsname;
 
        /* Determine the fully qualified path name of webserver */
        snprintf(looking_for, sizeof looking_for, "%s/webserver", setup_directory);
@@ -490,6 +507,8 @@ void check_inittab_entry(void)
                "select another port.");
        sprintf(http_port, "2000");
        set_value(question, http_port);
+       uname(&my_utsname);
+       sprintf(suggested_url, "http://%s:%s/", my_utsname.nodename, http_port);
 
 #ifdef HAVE_OPENSSL
        snprintf(question, sizeof question,
@@ -591,8 +610,9 @@ int discover_ui(void)
 int main(int argc, char *argv[])
 {
        int a;
-       char aaa[128];
+       char aaa[256];
        int info_only = 0;
+       strcpy(suggested_url, "http://<your_host_name>:<port>/");
 
        /* set an invalid setup type */
        setup_type = (-1);
@@ -670,8 +690,10 @@ int main(int argc, char *argv[])
                        if (a == 0) start_the_service();
                        sleep(1);
                }
-               important_message("Setup finished",
-                       "Setup is finished.  You may now log in.");
+               sprintf(aaa,
+                       "Setup is finished.  You may now log in.\n"
+                       "Point your web browser at %s\n", suggested_url);
+               important_message("Setup finished", aaa);
        }
        else {
                important_message("Setup finished",