2 // Main entry point for the program.
4 // Copyright (c) 1996-2021 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
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;
21 // Main entry point for the web server.
22 int main(int argc, char **argv) {
23 int webserver_port = WEBSERVER_PORT;
24 char *webserver_interface = WEBSERVER_INTERFACE;
25 int running_as_daemon = 0;
26 int webserver_protocol = WEBSERVER_HTTP;
28 char *pid_file = NULL;
31 while ((a = getopt(argc, argv, "u:h:i:p:t:T:B:x:g:dD:G:cfsS:Z:v:")) != EOF)
39 running_as_daemon = 1;
42 running_as_daemon = 1;
43 pid_file = strdup(optarg);
46 // FIXME set up the default landing page
53 // The above options are no longer used, but ignored so old scripts don't break
56 webserver_interface = optarg;
59 webserver_port = atoi(optarg);
62 // FIXME when gzip is added, disable it if this flag is set
71 webserver_protocol = WEBSERVER_HTTPS;
75 webserver_protocol = WEBSERVER_HTTPS;
76 //ssl_cipher_list = strdup(optarg);
79 //DumpTemplateI18NStrings = 1;
80 //I18nDump = NewStrBufPlain(HKEY("int templatestrings(void)\n{\n"));
81 //I18nDumpFile = optarg;
84 fprintf(stderr, "usage:\nwebcit "
85 "[-i ip_addr] [-p http_port] "
87 "[-d] [-Z] [-G i18ndumpfile] "
88 "[-u uid] [-h homedirectory] "
89 "[-D daemonizepid] [-v] "
90 "[-g defaultlandingpage] [-B basesize] " "[-s] [-S cipher_suites]" "[remotehost [remoteport]]\n");
95 ctdlhost = argv[optind];
97 ctdlport = argv[optind];
101 openlog("webcit", (running_as_daemon ? (LOG_PID) : (LOG_PID | LOG_PERROR)), LOG_DAEMON);
103 // Tell 'em who's in da house
104 syslog(LOG_NOTICE, "MAKE WEBCIT GREAT AGAIN!");
105 syslog(LOG_NOTICE, "Copyright (C) 1996-2021 by the citadel.org team");
106 syslog(LOG_NOTICE, " ");
107 syslog(LOG_NOTICE, "This program is open source software: you can redistribute it and/or");
108 syslog(LOG_NOTICE, "modify it under the terms of the GNU General Public License, version 3.");
109 syslog(LOG_NOTICE, " ");
110 syslog(LOG_NOTICE, "This program is distributed in the hope that it will be useful,");
111 syslog(LOG_NOTICE, "but WITHOUT ANY WARRANTY; without even the implied warranty of");
112 syslog(LOG_NOTICE, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the");
113 syslog(LOG_NOTICE, "GNU General Public License for more details.");
114 syslog(LOG_NOTICE, " ");
116 // Ensure that we are linked to the correct version of libcitadel
117 if (libcitadel_version_number() < LIBCITADEL_VERSION_NUMBER) {
118 syslog(LOG_INFO, " You are running libcitadel version %d", libcitadel_version_number());
119 syslog(LOG_INFO, "WebCit was compiled against version %d", LIBCITADEL_VERSION_NUMBER);
123 // Go into the background if we were asked to run as a daemon
124 if (running_as_daemon) {
126 if (pid_file != NULL) {
127 FILE *pfp = fopen(pid_file, "w");
129 fprintf(pfp, "%d\n", getpid());
135 return webserver(webserver_interface, webserver_port, webserver_protocol);