Mailing list header changes (fuck you Google)
[citadel.git] / webcit-ng / main.c
1 //
2 // Main entry point for the program.
3 //
4 // Copyright (c) 1996-2020 by the citadel.org team
5 //
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.
10 //
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.
15
16 #include "webcit.h"             // All other headers are included from this header.
17
18 char *ctdlhost = CTDLHOST;
19 char *ctdlport = CTDLPORT;
20
21 /*
22  * Main entry point for the web server.
23  */
24 int main(int argc, char **argv)
25 {
26         int webserver_port = WEBSERVER_PORT;
27         char *webserver_interface = WEBSERVER_INTERFACE;
28         int running_as_daemon = 0;
29         int webserver_protocol = WEBSERVER_HTTP;
30         int a;
31         char *pid_file = NULL;
32
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)
35                 switch (a) {
36                 case 'u':
37                         setuid(atoi(optarg));
38                         break;
39                 case 'h':
40                         break;
41                 case 'd':
42                         running_as_daemon = 1;
43                         break;
44                 case 'D':
45                         running_as_daemon = 1;
46                         pid_file = strdup(optarg);
47                         break;
48                 case 'g':
49                         // FIXME set up the default landing page
50                         break;
51                 case 'B':
52                 case 't':
53                 case 'x':
54                 case 'T':
55                 case 'v':
56                         /* The above options are no longer used, but ignored so old scripts don't break */
57                         break;
58                 case 'i':
59                         webserver_interface = optarg;
60                         break;
61                 case 'p':
62                         webserver_port = atoi(optarg);
63                         break;
64                 case 'Z':
65                         // FIXME when gzip is added, disable it if this flag is set
66                         break;
67                 case 'f':
68                         //follow_xff = 1;
69                         break;
70                 case 'c':
71                         break;
72                 case 's':
73                         is_https = 1;
74                         webserver_protocol = WEBSERVER_HTTPS;
75                         break;
76                 case 'S':
77                         is_https = 1;
78                         webserver_protocol = WEBSERVER_HTTPS;
79                         //ssl_cipher_list = strdup(optarg);
80                         break;
81                 case 'G':
82                         //DumpTemplateI18NStrings = 1;
83                         //I18nDump = NewStrBufPlain(HKEY("int templatestrings(void)\n{\n"));
84                         //I18nDumpFile = optarg;
85                         break;
86                 default:
87                         fprintf(stderr, "usage:\nwebcit "
88                                 "[-i ip_addr] [-p http_port] "
89                                 "[-c] [-f] "
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");
94                         return 1;
95                 }
96
97         if (optind < argc) {
98                 ctdlhost = argv[optind];
99                 if (++optind < argc)
100                         ctdlport = argv[optind];
101         }
102
103         /* Start the logger */
104         openlog("webcit", (running_as_daemon ? (LOG_PID) : (LOG_PID | LOG_PERROR)), LOG_DAEMON);
105
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, " ");
118
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);
123                 return (1);
124         }
125
126         /* Go into the background if we were asked to run as a daemon */
127         if (running_as_daemon) {
128                 daemon(1, 0);
129                 if (pid_file != NULL) {
130                         FILE *pfp = fopen(pid_file, "w");
131                         if (pfp) {
132                                 fprintf(pfp, "%d\n", getpid());
133                                 fclose(pfp);
134                         }
135                 }
136         }
137
138         return webserver(webserver_interface, webserver_port, webserver_protocol);
139 }