root/config.cc

Revision 92c18c14e163e2ab3200ccad6c6c0e6ee5c3e1a6, 5.6 KB (checked in by Antti-Juhani Kaijanaho <antti-juhani@…>, 18 months ago)

Make Alue self-identity in emails configurable

Fixes #52

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>

  • Property mode set to 100644
Line 
1/*  This file is part of Alue, the multiprotocol Internet discussion daemon
2
3    Copyright © 2009, 2010 Antti-Juhani Kaijanaho
4
5    Alue is free software: you can redistribute it and/or modify it
6    under the terms of the GNU General Public License as published by
7    the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9
10    Alue is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with Alue.  If not, see <http://www.gnu.org/licenses/>.
17
18 */
19
20#include "config.hh"
21
22#include <cerrno>
23#include <cstdlib>
24#include <fstream>
25#include <iostream>
26#include <sys/resource.h>
27#include <sys/utsname.h>
28#include <unistd.h>
29
30
31boost::program_options::variables_map config;
32
33void configure(int argc, char *argv[], rlimit &rlim)
34{
35        namespace po = boost::program_options;
36
37        if (getrlimit(RLIMIT_AS, &rlim) == -1)
38        {
39                std::cerr << "getrlimit failed: " << strerror(errno)
40                          << std::endl;
41                std::exit(1);
42        }
43
44        struct utsname uts;
45        if (uname(&uts) == -1)
46        {
47                std::cerr << "uname failed: " << strerror(errno) << std::endl;
48                std::exit(1);
49        }
50
51
52        po::options_description opts;
53        opts.add_options()
54                ( "help", "show this help message")
55                ( "executable",
56                  po::value<std::string>()->default_value(argv[0]),
57                  "the location of a debuggable executable (for backtraces)" )
58                ( "daemon",
59                  po::value<bool>()->default_value(true),
60                  "create a daemon process and exit immediately afterward")
61                ( "user", po::value<std::string>(),
62                  "the user to run as (if started as root)")
63                ( "canonical-name",
64                  po::value<std::string>()->default_value(uts.nodename),
65                  "the canonical name of this host" )
66                ("nntp-port",
67                 po::value<std::string>()->default_value("119"),
68                 "the port to listen on for NNTP clients")
69                ("nntps-port",
70                 po::value<std::string>()->default_value("563"),
71                 "the port to listen on for NNTP/SSL clients")
72                ("https-port",
73                 po::value<std::string>()->default_value("443"),
74                 "the port to listen on for HTTPS clients")
75                ("unix-socket",
76                 po::value<std::string>()->default_value("alue-socket"),
77                 "the Unix socket (in the home directory) to listen for"
78                 " email injections")
79                ("key-file",
80                 po::value<std::string>()->default_value("key.pem"),
81                 "the file containing the SSL/TLS private key")
82                ("cert-file",
83                 po::value<std::string>()->default_value("cert.pem"),
84                 "the file containing the SSL/TLS certificate")
85                ("log-smtp",
86                 po::value<bool>()->default_value(false),
87                 "log SMTP extensively")
88                ("log-http",
89                 po::value<bool>()->default_value(false),
90                 "log HTTP extensively (warning - user privacy invasive)")
91                ("log-nntp",
92                 po::value<bool>()->default_value(false),
93                 "log HTTP extensively (warning - user privacy invasive)")
94                ("logfile",
95                 po::value<std::string>()->default_value("alue.log"),
96                 "the name of the logfile")
97                ("vm-limit",
98                 po::value<rlim_t>(&rlim.rlim_cur)->default_value(rlim.rlim_cur),
99                 "the AS (virtual memory) resource limit for this process")
100                ("include-dir",
101                 po::value<std::string>()->default_value("templates/"),
102                 "include directory name")
103                ("files-dir",
104                 po::value<std::string>()->default_value("templates/"),
105                 "verbatim HTTPS file directory name")
106                ("config-file",
107                 po::value<std::string>()->default_value(CONFFILE),
108                 "name of the the configuration file")
109                ("db-file",
110                 po::value<std::string>()->default_value("alue.db2"),
111                 "name of the database file")
112                ("pw-file",
113                 po::value<std::string>()->default_value("passwds"),
114                 "name of the passwords file")
115                ("home",
116                 po::value<std::string>()->default_value("/"),
117                 "name of the daemon home directory")
118                ("alue-name",
119                 po::value<std::string>()->default_value("Alue"),
120                 "the 'real name' Alue should use of itself")
121                ("operator-email",
122                 po::value<std::string>(),
123                 "a human operator's email address");
124        po::store(po::parse_command_line(argc, argv, opts), config);
125        {
126                std::string config_file_name =
127                        config["config-file"].as<std::string>();
128                std::ifstream config_file(config_file_name.c_str());
129                if (config_file)
130                        po::store(po::parse_config_file(config_file, opts),
131                                  config);
132        }
133        po::notify(config);
134
135        if (config.count("help") > 0)
136        {
137                std::cout << opts << std::endl;
138                std::exit(0);
139        }
140}
Note: See TracBrowser for help on using the browser.