1 // Main entry point for the program.
3 // Copyright (c) 1996-2021 by the citadel.org team
5 // This program is open source software. It runs great on the
6 // Linux operating system (and probably elsewhere). You can use,
7 // copy, and run it under the terms of the GNU General Public
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // 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;
20 // Main entry point for the web server.
21 int main(int argc, char **argv) {
22 int webserver_port = WEBSERVER_PORT;
23 char *webserver_interface = WEBSERVER_INTERFACE;
24 int running_as_daemon = 0;
25 int webserver_protocol = WEBSERVER_HTTP;
27 char *pid_file = NULL;
30 while ((a = getopt(argc, argv, "u:h:i:p:t:T:B:x:g:dD:G:cfsS:Z:v:")) != EOF)
38 running_as_daemon = 1;
41 running_as_daemon = 1;
42 pid_file = strdup(optarg);
45 // FIXME set up the default landing page
52 // The above options are no longer used, but ignored so old scripts don't break
55 webserver_interface = optarg;
58 webserver_port = atoi(optarg);
61 // FIXME when gzip is added, disable it if this flag is set
70 webserver_protocol = WEBSERVER_HTTPS;
74 webserver_protocol = WEBSERVER_HTTPS;
75 //ssl_cipher_list = strdup(optarg);
78 //DumpTemplateI18NStrings = 1;
79 //I18nDump = NewStrBufPlain(HKEY("int templatestrings(void)\n{\n"));
80 //I18nDumpFile = optarg;
83 fprintf(stderr, "usage:\nwebcit "
84 "[-i ip_addr] [-p http_port] "
86 "[-d] [-Z] [-G i18ndumpfile] "
87 "[-u uid] [-h homedirectory] "
88 "[-D daemonizepid] [-v] "
89 "[-g defaultlandingpage] [-B basesize] " "[-s] [-S cipher_suites]" "[remotehost [remoteport]]\n");
94 ctdlhost = argv[optind];
96 ctdlport = argv[optind];
100 openlog("webcit", (running_as_daemon ? (LOG_PID) : (LOG_PID | LOG_PERROR)), LOG_DAEMON);
102 // Tell 'em who's in da house
103 syslog(LOG_NOTICE, "MAKE WEBCIT GREAT AGAIN!");
104 syslog(LOG_NOTICE, "Copyright (C) 1996-2021 by the citadel.org team");
105 syslog(LOG_NOTICE, " ");
106 syslog(LOG_NOTICE, "This program is open source software: you can redistribute it and/or");
107 syslog(LOG_NOTICE, "modify it under the terms of the GNU General Public License, version 3.");
108 syslog(LOG_NOTICE, " ");
109 syslog(LOG_NOTICE, "This program is distributed in the hope that it will be useful,");
110 syslog(LOG_NOTICE, "but WITHOUT ANY WARRANTY; without even the implied warranty of");
111 syslog(LOG_NOTICE, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the");
112 syslog(LOG_NOTICE, "GNU General Public License for more details.");
113 syslog(LOG_NOTICE, " ");
115 // Ensure that we are linked to the correct version of libcitadel
116 if (libcitadel_version_number() < LIBCITADEL_VERSION_NUMBER) {
117 syslog(LOG_INFO, " You are running libcitadel version %d", libcitadel_version_number());
118 syslog(LOG_INFO, "WebCit was compiled against version %d", LIBCITADEL_VERSION_NUMBER);
122 // Go into the background if we were asked to run as a daemon
123 if (running_as_daemon) {
125 if (pid_file != NULL) {
126 FILE *pfp = fopen(pid_file, "w");
128 fprintf(pfp, "%d\n", getpid());
134 return webserver(webserver_interface, webserver_port, webserver_protocol);