1 // Main entry point for the program.
3 // Copyright (c) 1996-2022 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 *ctdl_dir = CTDL_DIR;
19 // Main entry point for the web server.
20 int main(int argc, char **argv) {
21 int webserver_port = WEBSERVER_PORT;
22 char *webserver_interface = WEBSERVER_INTERFACE;
23 int running_as_daemon = 0;
24 int webserver_protocol = WEBSERVER_HTTP;
26 char *pid_file = NULL;
29 while ((a = getopt(argc, argv, "u:h:i:p:t:T:B:x:g:dD:G:cfsS:Z:v:")) != EOF)
37 running_as_daemon = 1;
40 running_as_daemon = 1;
41 pid_file = strdup(optarg);
44 // FIXME set up the default landing page
51 // The above options are no longer used, but ignored so old scripts don't break
54 webserver_interface = optarg;
57 webserver_port = atoi(optarg);
60 // FIXME when gzip is added, disable it if this flag is set
69 webserver_protocol = WEBSERVER_HTTPS;
73 webserver_protocol = WEBSERVER_HTTPS;
74 //ssl_cipher_list = strdup(optarg);
77 //DumpTemplateI18NStrings = 1;
78 //I18nDump = NewStrBufPlain(HKEY("int templatestrings(void)\n{\n"));
79 //I18nDumpFile = optarg;
82 fprintf(stderr, "usage:\nwebcit "
83 "[-i ip_addr] [-p http_port] "
85 "[-d] [-Z] [-G i18ndumpfile] "
86 "[-u uid] [-h homedirectory] "
87 "[-D daemonizepid] [-v] "
88 "[-g defaultlandingpage] [-B basesize] "
89 "[-s] [-S cipher_suites]"
90 "[citadel_directory]\n"
95 while (optind < argc) {
96 ctdl_dir = strdup(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-2022 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);