0.6.0-1 release
[manu/suphp.git] / src / Application.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_APPLICATION_H
22
23 namespace suPHP {
24     class Application;
25 };
26
27 enum TargetMode {
28     TARGETMODE_PHP,
29     TARGETMODE_SELFEXECUTE
30 };
31
32 #define SUPHP_APPLICATION_H
33
34 #include <string>
35 #include <iostream>
36
37 #include "Environment.hpp"
38 #include "CommandLine.hpp"
39 #include "SystemException.hpp"
40 #include "SoftException.hpp"
41 #include "SecurityException.hpp"
42
43 namespace suPHP {
44     /**
45      * Main application class.
46      * Contains the main() function.
47      */
48     class Application {
49     private:
50         /**
51          * Print message containing version information
52          */
53         void printAboutMessage();
54         
55         /**
56          * Checks wheter process has root privileges
57          * and calling user is webserver user
58          */
59         void checkProcessPermissions(Configuration& config) 
60             throw (SecurityException, LookupException);
61         /**
62          * Checks scriptfile.
63          * Includes check for path, symbollink and permissions
64          */
65         void checkScriptFile(const std::string& scriptFilename, 
66                              const Configuration& config, 
67                              const Environment& environment) const
68             throw (SystemException, SoftException);
69         
70         /**
71          * Changes process permission (user and group).
72          * Uses preprocessor macros to distinguish between modes
73          */
74         void changeProcessPermissions(const std::string& scriptFilename,
75                                       const Configuration& config,
76                                       const Environment& environment) const
77             throw (SystemException, SoftException, SecurityException);
78
79         /**
80          * Prepares the environment before invoking the script
81          */
82         Environment prepareEnvironment(const Environment& sourceEnv,
83                                        const Configuration& config,
84                                        TargetMode mode)
85             throw (KeyNotFoundException);
86
87         /**
88          * Returns interpreter for script being executed
89          */
90         std::string getInterpreter(const Environment& env,
91                                    const Configuration& config)
92             throw (SecurityException);
93         
94         /**
95          * Returns mode interpreter is using
96          */
97         TargetMode getTargetMode(const std::string& interpreter)
98             throw (SecurityException);
99
100         /**
101          * Runs script
102          */
103         void executeScript(const std::string& scriptFilename,
104                            const std::string& interpreter,
105                            TargetMode mode,
106                            const Environment& env,
107                            const Configuration& config) const
108             throw (SoftException);
109
110
111     public:
112         /**
113          * Constructer
114          */
115         Application();
116         
117         /**
118          * Function called by the main() function
119          */
120         int run(CommandLine& cmdline, Environment& env);
121     };
122 };
123
124 int main(int argc, char **argv);
125
126 #endif // SUPHP_APPLICATION_H