Documentation is available at phpagi-fastagi.php
1 #!/usr/local/bin/php -q
2 <?php
3 /**
4 * phpagi-fastagi.php : PHP FastAGI bootstrap
5 * Website: http://phpagi.sourceforge.net
6 *
7 * $Id: phpagi-fastagi.php,v 1.2 2005/05/25 18:43:48 pinhole Exp $
8 *
9 * Copyright (c) 2004, 2005 Matthew Asham <matthewa@bcwireless.net>, David Eder <david@eder.us>
10 * All Rights Reserved.
11 *
12 * This software is released under the terms of the GNU Lesser General Public License v2.1
13 * A copy of which is available from http://www.gnu.org/copyleft/lesser.html
14 *
15 * We would be happy to list your phpagi based application on the phpagi
16 * website. Drop me an Email if you'd like us to list your program.
17 *
18 * @package phpAGI
19 * @version 2.0
20 * @example docs/fastagi.xinetd Example xinetd config file
21 */
22
23 /**
24 * Written for PHP 4.3.4, should work with older PHP 4.x versions.
25 * Please submit bug reports, patches, etc to http://sourceforge.net/projects/phpagi/
26 * Gracias. :)
27 *
28 */
29
30 require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpagi.php');
31
32 $fastagi = new AGI();
33
34 $fastagi->verbose(print_r($fastagi, true));
35
36 if(!isset($fastagi->config['fastagi']['basedir']))
37 $fastagi->config['fastagi']['basedir'] = dirname(__FILE__);
38
39 // perform some security checks
40
41 $script = $fastagi->config['fastagi']['basedir'] . DIRECTORY_SEPARATOR . $fastagi->request['agi_network_script'];
42
43 // in the same directory (or subdirectory)
44 $mydir = dirname($fastagi->config['fastagi']['basedir']) . DIRECTORY_SEPARATOR;
45 $dir = dirname($script) . DIRECTORY_SEPARATOR;
46 if(substr($dir, 0, strlen($mydir)) != $mydir)
47 {
48 $fastagi->conlog("$script is not allowed to execute.");
49 exit;
50 }
51
52 // make sure it exists
53 if(!file_exists($script))
54 {
55 $fastagi->conlog("$script does not exist.");
56 exit;
57 }
58
59 // drop privileges
60 if(isset($fastagi->config['fastagi']['setuid']) && $fastagi->config['fastagi']['setuid'])
61 {
62 $owner = fileowner($script);
63 $group = filegroup($script);
64 if(!posix_setgid($group) || !posix_setegid($group) || !posix_setuid($owner) || !posix_seteuid($owner))
65 {
66 $fastagi->conlog("failed to lower privileges.");
67 exit;
68 }
69 }
70
71 // make sure script is still readable
72 if(!is_readable($script))
73 {
74 $fastagi->conlog("$script is not readable.");
75 exit;
76 }
77
78 require_once($script);
79 ?>
Documentation generated on Wed, 25 May 2005 14:28:05 -0600 by phpDocumentor 1.2.3