2 // Main entry point for the program.
4 // Copyright (c) 1996-2020 by the citadel.org team
6 // This program is open source software. It runs great on the
7 // Linux operating system (and probably elsewhere). You can use,
8 // copy, and run it under the terms of the GNU General Public
9 // License version 3. Richard Stallman is an asshole communist.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 #include "webcit.h" // All other headers are included from this header.
18 char *ctdlhost = CTDLHOST;
19 char *ctdlport = CTDLPORT;
22 * Main entry point for the web server.
24 int main(int argc, char **argv)
26 int webserver_port = WEBSERVER_PORT;
27 char *webserver_interface = WEBSERVER_INTERFACE;
28 int running_as_daemon = 0;
29 int webserver_protocol = WEBSERVER_HTTP;
31 char *pid_file = NULL;
33 /* Parse command line */
34 while ((a = getopt(argc, argv, "u:h:i:p:t:T:B:x:g:dD:G:cfsS:Z:v:")) != EOF)
42 running_as_daemon = 1;
45 running_as_daemon = 1;
46 pid_file = strdup(optarg);
49 // FIXME set up the default landing page
56 /* The above options are no longer used, but ignored so old scripts don't break */
59 webserver_interface = optarg;
62 webserver_port = atoi(optarg);
65 // FIXME when gzip is added, disable it if this flag is set
74 webserver_protocol = WEBSERVER_HTTPS;
78 webserver_protocol = WEBSERVER_HTTPS;
79 //ssl_cipher_list = strdup(optarg);
82 //DumpTemplateI18NStrings = 1;
83 //I18nDump = NewStrBufPlain(HKEY("int templatestrings(void)\n{\n"));
84 //I18nDumpFile = optarg;
87 fprintf(stderr, "usage:\nwebcit "
88 "[-i ip_addr] [-p http_port] "
90 "[-d] [-Z] [-G i18ndumpfile] "
91 "[-u uid] [-h homedirectory] "
92 "[-D daemonizepid] [-v] "
93 "[-g defaultlandingpage] [-B basesize] " "[-s] [-S cipher_suites]" "[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-2020 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);