| 1 | /* |
| 2 | suPHP - (c)2002-2008 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 | #include <vector> |
| 32 | |
| 33 | #include "ParsingException.hpp" |
| 34 | #include "IOException.hpp" |
| 35 | #include "File.hpp" |
| 36 | #include "KeyNotFoundException.hpp" |
| 37 | #include "Logger.hpp" |
| 38 | |
| 39 | namespace suPHP { |
| 40 | /** |
| 41 | * Class encapsulating run-time configuration. |
| 42 | */ |
| 43 | class Configuration { |
| 44 | private: |
| 45 | std::string logfile; |
| 46 | std::string webserver_user; |
| 47 | std::vector<std::string> docroots; |
| 48 | bool allow_file_group_writeable; |
| 49 | bool allow_directory_group_writeable; |
| 50 | bool allow_file_others_writeable; |
| 51 | bool allow_directory_others_writeable; |
| 52 | bool check_vhost_docroot; |
| 53 | bool errors_to_browser; |
| 54 | std::string env_path; |
| 55 | std::map<std::string, std::string> handlers; |
| 56 | LogLevel loglevel; |
| 57 | int min_uid; |
| 58 | int min_gid; |
| 59 | int umask; |
| 60 | std::string chroot_path; |
| 61 | |
| 62 | /** |
| 63 | * Converts string to bool |
| 64 | */ |
| 65 | bool strToBool(const std::string& str) const throw (ParsingException); |
| 66 | |
| 67 | /** |
| 68 | * Converts string to LogLevel |
| 69 | */ |
| 70 | LogLevel strToLogLevel(const std::string& str) const |
| 71 | throw (ParsingException); |
| 72 | |
| 73 | public: |
| 74 | /** |
| 75 | * Constructor, initializes configuration with default values. |
| 76 | */ |
| 77 | Configuration(); |
| 78 | |
| 79 | /** |
| 80 | * Reads values from INI file |
| 81 | */ |
| 82 | void readFromFile(File& file) throw (IOException, ParsingException); |
| 83 | |
| 84 | /** |
| 85 | * Return path to logfile; |
| 86 | */ |
| 87 | std::string getLogfile() const; |
| 88 | |
| 89 | /** |
| 90 | Return log level |
| 91 | */ |
| 92 | LogLevel getLogLevel() const; |
| 93 | |
| 94 | /** |
| 95 | * Return username of user the webserver is running as |
| 96 | */ |
| 97 | std::string getWebserverUser() const; |
| 98 | |
| 99 | /** |
| 100 | * Return document root (list of directories, scripts may be within) |
| 101 | */ |
| 102 | const std::vector<std::string>& getDocroots() const; |
| 103 | |
| 104 | /** |
| 105 | * Returns wheter suPHP should check if scripts in within the |
| 106 | * document root of the VHost |
| 107 | */ |
| 108 | bool getCheckVHostDocroot() const; |
| 109 | |
| 110 | /** |
| 111 | * Returns wheter suPHP should ignore the group write bit of |
| 112 | * the script file |
| 113 | */ |
| 114 | bool getAllowFileGroupWriteable() const; |
| 115 | |
| 116 | /** |
| 117 | * Returns wheter suPHP should ignore the group write bit of |
| 118 | * the directory the is script in |
| 119 | */ |
| 120 | bool getAllowDirectoryGroupWriteable() const; |
| 121 | |
| 122 | /** |
| 123 | * Returns wheter suPHP should ignore the others write bit of the |
| 124 | * script file |
| 125 | */ |
| 126 | bool getAllowFileOthersWriteable() const; |
| 127 | |
| 128 | /** |
| 129 | * Returns wheter suPHP should ignore the others write bit of |
| 130 | * the directory the is script in |
| 131 | */ |
| 132 | bool getAllowDirectoryOthersWriteable() const; |
| 133 | |
| 134 | /** |
| 135 | * Returns whether (minor) error message should be sent to browser |
| 136 | */ |
| 137 | bool getErrorsToBrowser() const; |
| 138 | |
| 139 | /** |
| 140 | * Returns the content for the PATH environment variable |
| 141 | */ |
| 142 | std::string getEnvPath() const; |
| 143 | |
| 144 | /** |
| 145 | * Returns interpreter string for specified handler |
| 146 | */ |
| 147 | std::string getInterpreter(std::string handler) const |
| 148 | throw (KeyNotFoundException); |
| 149 | |
| 150 | /** |
| 151 | * Returns minimum UID allowed for scripts |
| 152 | */ |
| 153 | int getMinUid() const; |
| 154 | |
| 155 | /** |
| 156 | * Returns minimum GID allowed for scripts |
| 157 | */ |
| 158 | int getMinGid() const; |
| 159 | |
| 160 | /** |
| 161 | * Returns umask to set |
| 162 | */ |
| 163 | int getUmask() const; |
| 164 | |
| 165 | /** |
| 166 | * Return chroot path |
| 167 | */ |
| 168 | std::string getChrootPath() const; |
| 169 | }; |
| 170 | }; |
| 171 | |
| 172 | #endif // SUPHP_CONFIGURATION_H |