Grammar change in the license declaration.
[citadel.git] / webcit-ng / server / main.c
1 // Main entry point for the program.
2 //
3 // Copyright (c) 1996-2023 by the citadel.org team
4 //
5 // This program is open source software.  Use, duplication, or
6 // disclosure is subject to the GNU General Public License v3.
7
8 #include "webcit.h"             // All other headers are included from this header.
9
10 char *ctdl_dir = CTDL_DIR;
11
12 // Main entry point for the web server.
13 int main(int argc, char **argv) {
14         int webserver_port = WEBSERVER_PORT;
15         char *webserver_interface = WEBSERVER_INTERFACE;
16         int running_as_daemon = 0;
17         int webserver_protocol = WEBSERVER_HTTP;
18         int a;
19         char *pid_file = NULL;
20
21         // Parse command line
22         while ((a = getopt(argc, argv, "u:h:i:p:t:T:B:x:g:dD:G:cfsS:Z:v:")) != EOF)
23                 switch (a) {
24                 case 'u':
25                         setuid(atoi(optarg));
26                         break;
27                 case 'h':
28                         ctdl_dir = strdup(optarg);
29                         break;
30                 case 'd':
31                         running_as_daemon = 1;
32                         break;
33                 case 'D':
34                         running_as_daemon = 1;
35                         pid_file = strdup(optarg);
36                         break;
37                 case 'g':
38                         // FIXME set up the default landing page
39                         break;
40                 case 'B':
41                 case 't':
42                 case 'x':
43                 case 'T':
44                 case 'v':
45                         // The above options are no longer used, but ignored so old scripts don't break
46                         break;
47                 case 'i':
48                         webserver_interface = optarg;
49                         break;
50                 case 'p':
51                         webserver_port = atoi(optarg);
52                         break;
53                 case 'Z':
54                         // FIXME when gzip is added, disable it if this flag is set
55                         break;
56                 case 'f':
57                         //follow_xff = 1;
58                         break;
59                 case 'c':
60                         break;
61                 case 's':
62                         is_https = 1;
63                         webserver_protocol = WEBSERVER_HTTPS;
64                         break;
65                 case 'S':
66                         is_https = 1;
67                         webserver_protocol = WEBSERVER_HTTPS;
68                         //ssl_cipher_list = strdup(optarg);
69                         break;
70                 case 'G':
71                         //DumpTemplateI18NStrings = 1;
72                         //I18nDump = NewStrBufPlain(HKEY("int templatestrings(void)\n{\n"));
73                         //I18nDumpFile = optarg;
74                         break;
75                 default:
76                         fprintf(stderr, "usage:\nwebcit "
77                                 "[-i ip_addr] [-p http_port] "
78                                 "[-c] [-f] "
79                                 "[-d] [-Z] [-G i18ndumpfile] "
80                                 "[-u uid] [-h homedirectory] "
81                                 "[-D daemonizepid] [-v] "
82                                 "[-g defaultlandingpage] [-B basesize] "
83                                 "[-s] [-S cipher_suites]"
84                                 "[-h citadel_server_directory]\n"
85                         );
86                         return 1;
87                 }
88
89         while (optind < argc) {
90                 ctdl_dir = strdup(argv[optind++]);
91         }
92
93         // Start the logger
94         openlog("webcit", (running_as_daemon ? (LOG_PID) : (LOG_PID | LOG_PERROR)), LOG_DAEMON);
95
96         // Tell 'em who's in da house
97         syslog(LOG_NOTICE, "MAKE WEBCIT GREAT AGAIN!");
98         syslog(LOG_NOTICE, "Copyright (C) 1996-2023 by the citadel.org team");
99         syslog(LOG_NOTICE, " ");
100         syslog(LOG_NOTICE, "This program is open source software: you can redistribute it and/or");
101         syslog(LOG_NOTICE, "modify it under the terms of the GNU General Public License, version 3.");
102         syslog(LOG_NOTICE, " ");
103         syslog(LOG_NOTICE, "This program is distributed in the hope that it will be useful,");
104         syslog(LOG_NOTICE, "but WITHOUT ANY WARRANTY; without even the implied warranty of");
105         syslog(LOG_NOTICE, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the");
106         syslog(LOG_NOTICE, "GNU General Public License for more details.");
107         syslog(LOG_NOTICE, " ");
108
109         // Ensure that we are linked to the correct version of libcitadel
110         if (libcitadel_version_number() < LIBCITADEL_VERSION_NUMBER) {
111                 syslog(LOG_INFO, " You are running libcitadel version %d", libcitadel_version_number());
112                 syslog(LOG_INFO, "WebCit was compiled against version %d", LIBCITADEL_VERSION_NUMBER);
113                 return (1);
114         }
115
116         // Go into the background if we were asked to run as a daemon
117         if (running_as_daemon) {
118                 daemon(1, 0);
119                 if (pid_file != NULL) {
120                         FILE *pfp = fopen(pid_file, "w");
121                         if (pfp) {
122                                 fprintf(pfp, "%d\n", getpid());
123                                 fclose(pfp);
124                         }
125                 }
126         }
127
128         return webserver(webserver_interface, webserver_port, webserver_protocol);
129 }