2 * Main entry point for the program.
4 * Copyright (c) 1996-2017 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include "webcit.h" // All other headers are included from this header.
17 char *ctdlhost = CTDLHOST;
18 char *ctdlport = CTDLPORT;
21 * Main entry point for the web server.
23 int main(int argc, char **argv)
25 int webserver_port = WEBSERVER_PORT;
26 char *webserver_interface = WEBSERVER_INTERFACE;
27 int running_as_daemon = 0;
28 int webserver_protocol = WEBSERVER_HTTP;
30 char *pid_file = NULL;
32 /* Parse command line */
33 while ((a = getopt(argc, argv, "u:h:i:p:t:T:B:x:g:dD:G:cfsS:Z:v:")) != EOF) switch(a) {
40 running_as_daemon = 1;
43 running_as_daemon = 1;
44 pid_file = strdup(optarg);
47 // FIXME set up the default landing page
54 /* The above options are no longer used, but ignored so old scripts don't break */
57 webserver_interface = optarg;
60 webserver_port = atoi(optarg);
63 // FIXME when gzip is added, disable it if this flag is set
72 webserver_protocol = WEBSERVER_HTTPS;
76 webserver_protocol = WEBSERVER_HTTPS;
77 //ssl_cipher_list = strdup(optarg);
80 //DumpTemplateI18NStrings = 1;
81 //I18nDump = NewStrBufPlain(HKEY("int templatestrings(void)\n{\n"));
82 //I18nDumpFile = optarg;
85 fprintf(stderr, "usage:\nwebcit "
86 "[-i ip_addr] [-p http_port] "
88 "[-d] [-Z] [-G i18ndumpfile] "
89 "[-u uid] [-h homedirectory] "
90 "[-D daemonizepid] [-v] "
91 "[-g defaultlandingpage] [-B basesize] "
92 "[-s] [-S cipher_suites]"
93 "[remotehost [remoteport]]\n");
98 ctdlhost = argv[optind];
100 ctdlport = argv[optind];
103 /* Start the logger */
104 openlog("webcit", ( running_as_daemon ? (LOG_PID) : (LOG_PID | LOG_PERROR) ), LOG_DAEMON);
106 /* Tell 'em who's in da house */
107 syslog(LOG_NOTICE, "MAKE WEBCIT GREAT AGAIN!");
108 syslog(LOG_NOTICE, "Copyright (C) 1996-2017 by the citadel.org team");
109 syslog(LOG_NOTICE, " ");
110 syslog(LOG_NOTICE, "This program is open source software: you can redistribute it and/or");
111 syslog(LOG_NOTICE, "modify it under the terms of the GNU General Public License, version 3.");
112 syslog(LOG_NOTICE, " ");
113 syslog(LOG_NOTICE, "This program is distributed in the hope that it will be useful,");
114 syslog(LOG_NOTICE, "but WITHOUT ANY WARRANTY; without even the implied warranty of");
115 syslog(LOG_NOTICE, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the");
116 syslog(LOG_NOTICE, "GNU General Public License for more details.");
117 syslog(LOG_NOTICE, " ");
119 /* Ensure that we are linked to the correct version of libcitadel */
120 if (libcitadel_version_number() < LIBCITADEL_VERSION_NUMBER) {
121 syslog(LOG_INFO, " You are running libcitadel version %d", libcitadel_version_number() );
122 syslog(LOG_INFO, "WebCit was compiled against version %d", LIBCITADEL_VERSION_NUMBER );
126 /* Go into the background if we were asked to run as a daemon */
127 if (running_as_daemon) {
129 if (pid_file != NULL) {
130 FILE *pfp = fopen(pid_file, "w");
132 fprintf(pfp, "%d\n", getpid());
138 return webserver(webserver_interface, webserver_port, webserver_protocol);