0.6.1.20061108-1 release
[manu/suphp.git] / src / Configuration.hpp
1 /*
2     suPHP - (c)2002-2005 Sebastian Marsching <sebastian@marsching.com>
3
4     This file is part of suPHP.
5
6     suPHP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     suPHP 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     You should have received a copy of the GNU General Public License
17     along with suPHP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #ifndef SUPHP_CONFIGURATION_H
22
23 namespace suPHP {
24     class Configuration;
25 };
26
27 #define SUPHP_CONFIGURATION_H
28
29 #include <string>
30 #include <map>
31
32 #include "ParsingException.hpp"
33 #include "IOException.hpp"
34 #include "File.hpp"
35 #include "KeyNotFoundException.hpp"
36 #include "Logger.hpp"
37
38 namespace suPHP {
39     /**
40      * Class encapsulating run-time configuration.
41      */
42     class Configuration {
43     private:
44         std::string logfile;
45         std::string webserver_user;
46         std::string docroot;
47         bool allow_file_group_writeable;
48         bool allow_directory_group_writeable;
49         bool allow_file_others_writeable;
50         bool allow_directory_others_writeable;
51         bool check_vhost_docroot;
52         bool errors_to_browser;
53         std::string env_path;
54         std::map<std::string, std::string> handlers;
55         LogLevel loglevel;
56         int min_uid;
57         int min_gid;
58         int umask;
59         std::string chroot_path;
60
61         /**
62          * Converts string to bool
63          */
64         bool strToBool(const std::string& str) const throw (ParsingException);
65
66         /**
67          * Converts string to LogLevel
68          */
69         LogLevel strToLogLevel(const std::string& str) const
70             throw (ParsingException);
71
72     public:
73         /**
74          * Constructor, initializes configuration with default values.
75          */
76         Configuration();
77         
78         /**
79          * Reads values from INI file
80          */
81         void readFromFile(File& file) throw (IOException, ParsingException);
82         
83         /**
84          * Return path to logfile;
85          */
86         std::string getLogfile() const;
87
88         /**
89            Return log level
90         */
91         LogLevel getLogLevel() const;
92
93         /**
94          * Return username of user the webserver is running as
95          */
96         std::string getWebserverUser() const;
97
98         /**
99          * Return document root (directory, all script have to be in)
100          */
101         std::string getDocroot() const;
102
103         /**
104          * Returns wheter suPHP should check if scripts in within the 
105          * document root of the VHost
106          */
107         bool getCheckVHostDocroot() const;
108         
109         /**
110          * Returns wheter suPHP should ignore the group write bit of
111          * the script file
112          */
113         bool getAllowFileGroupWriteable() const;
114
115         /**
116          * Returns wheter suPHP should ignore the group write bit of
117          * the directory the is script in
118          */
119         bool getAllowDirectoryGroupWriteable() const;
120         
121         /**
122          * Returns wheter suPHP should ignore the others write bit of the
123          * script file
124          */
125         bool getAllowFileOthersWriteable() const;
126
127         /**
128          * Returns wheter suPHP should ignore the others write bit of
129          * the directory the is script in
130          */
131         bool getAllowDirectoryOthersWriteable() const;
132
133         /**
134          * Returns whether (minor) error message should be sent to browser
135          */
136         bool getErrorsToBrowser() const;
137         
138         /**
139          * Returns the content for the PATH environment variable
140          */
141         std::string getEnvPath() const;
142
143         /**
144          * Returns interpreter string for specified handler
145          */
146         std::string getInterpreter(std::string handler) const
147             throw (KeyNotFoundException);
148
149         /**
150          * Returns minimum UID allowed for scripts
151          */
152         int getMinUid() const;
153         
154         /**
155          * Returns minimum GID allowed for scripts
156          */
157         int getMinGid() const;
158
159         /**
160          * Returns umask to set
161          */
162         int getUmask() const;
163
164         /**
165          * Return chroot path
166          */
167         std::string getChrootPath() const;
168     };
169 };
170
171 #endif // SUPHP_CONFIGURATION_H