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