Location: PHPKode > scripts > PHP AGI > phpagi-2.20/api-docs/__filesource/fsource_phpAGI__phpagi-fastagi.php.html
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<!-- template designed by Marco Von Ballmoos -->
			<title>File Source for phpagi-fastagi.php</title>
			<link rel="stylesheet" href="../media/stylesheet.css" />
			<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
		</head>
		<body>
						<h1>Source for file phpagi-fastagi.php</h1>
<p>Documentation is available at <a href="../phpAGI/_phpagi-fastagi.php.html">phpagi-fastagi.php</a></p>
<div class="src-code">
<div class="src-code"><ol><li><div class="src-line"><a name="a1"></a>#!/usr/local/bin/php&nbsp;-q</div></li>
<li><div class="src-line"><a name="a2"></a><span class="src-php">&lt;?php</span></div></li>
<li><div class="src-line"><a name="a3"></a>&nbsp;<span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a4"></a><span class="src-doc">&nbsp;&nbsp;*&nbsp;phpagi-fastagi.php&nbsp;:&nbsp;PHP&nbsp;FastAGI&nbsp;bootstrap</span></div></li>
<li><div class="src-line"><a name="a5"></a><span class="src-doc">&nbsp;&nbsp;*&nbsp;Website:&nbsp;http://phpagi.sourceforge.net</span></div></li>
<li><div class="src-line"><a name="a6"></a><span class="src-doc">&nbsp;&nbsp;*</span></div></li>
<li><div class="src-line"><a name="a7"></a><span class="src-doc">&nbsp;&nbsp;*&nbsp;$Id:&nbsp;phpagi-fastagi.php,v&nbsp;1.2&nbsp;2005/05/25&nbsp;18:43:48&nbsp;pinhole&nbsp;Exp&nbsp;$</span></div></li>
<li><div class="src-line"><a name="a8"></a><span class="src-doc">&nbsp;&nbsp;*</span></div></li>
<li><div class="src-line"><a name="a9"></a><span class="src-doc">&nbsp;&nbsp;*&nbsp;Copyright&nbsp;(c)&nbsp;2004,&nbsp;2005&nbsp;Matthew&nbsp;Asham&nbsp;&lt;hide@address.com&gt;,&nbsp;David&nbsp;Eder&nbsp;&lt;hide@address.com&gt;</span></div></li>
<li><div class="src-line"><a name="a10"></a><span class="src-doc">&nbsp;&nbsp;*&nbsp;All&nbsp;Rights&nbsp;Reserved.</span></div></li>
<li><div class="src-line"><a name="a11"></a><span class="src-doc">&nbsp;&nbsp;*</span></div></li>
<li><div class="src-line"><a name="a12"></a><span class="src-doc">&nbsp;&nbsp;*&nbsp;This&nbsp;software&nbsp;is&nbsp;released&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;the&nbsp;GNU&nbsp;Lesser&nbsp;General&nbsp;Public&nbsp;License&nbsp;v2.1</span></div></li>
<li><div class="src-line"><a name="a13"></a><span class="src-doc">&nbsp;&nbsp;*&nbsp;A&nbsp;copy&nbsp;of&nbsp;which&nbsp;is&nbsp;available&nbsp;from&nbsp;http://www.gnu.org/copyleft/lesser.html</span></div></li>
<li><div class="src-line"><a name="a14"></a><span class="src-doc">&nbsp;&nbsp;*</span></div></li>
<li><div class="src-line"><a name="a15"></a><span class="src-doc">&nbsp;&nbsp;*&nbsp;We&nbsp;would&nbsp;be&nbsp;happy&nbsp;to&nbsp;list&nbsp;your&nbsp;phpagi&nbsp;based&nbsp;application&nbsp;on&nbsp;the&nbsp;phpagi</span></div></li>
<li><div class="src-line"><a name="a16"></a><span class="src-doc">&nbsp;&nbsp;*&nbsp;website.&nbsp;&nbsp;Drop&nbsp;me&nbsp;an&nbsp;Email&nbsp;if&nbsp;you'd&nbsp;like&nbsp;us&nbsp;to&nbsp;list&nbsp;your&nbsp;program.</span></div></li>
<li><div class="src-line"><a name="a17"></a><span class="src-doc">&nbsp;&nbsp;*</span></div></li>
<li><div class="src-line"><a name="a18"></a><span class="src-doc">&nbsp;&nbsp;*&nbsp;</span><span class="src-doc-coretag">@package</span><span class="src-doc">&nbsp;phpAGI</span></div></li>
<li><div class="src-line"><a name="a19"></a><span class="src-doc">&nbsp;&nbsp;*&nbsp;</span><span class="src-doc-coretag">@version</span><span class="src-doc">&nbsp;2.0</span></div></li>
<li><div class="src-line"><a name="a20"></a><span class="src-doc">&nbsp;&nbsp;*&nbsp;</span><span class="src-doc-coretag">@example</span><span class="src-doc">&nbsp;docs/fastagi.xinetd&nbsp;Example&nbsp;xinetd&nbsp;config&nbsp;file</span></div></li>
<li><div class="src-line"><a name="a21"></a><span class="src-doc">&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a22"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a23"></a>&nbsp;<span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a24"></a><span class="src-doc">&nbsp;&nbsp;*&nbsp;Written&nbsp;for&nbsp;PHP&nbsp;4.3.4,&nbsp;should&nbsp;work&nbsp;with&nbsp;older&nbsp;PHP&nbsp;4.x&nbsp;versions.</span></div></li>
<li><div class="src-line"><a name="a25"></a><span class="src-doc">&nbsp;&nbsp;*&nbsp;Please&nbsp;submit&nbsp;bug&nbsp;reports,&nbsp;patches,&nbsp;etc&nbsp;to&nbsp;http://sourceforge.net/projects/phpagi/</span></div></li>
<li><div class="src-line"><a name="a26"></a><span class="src-doc">&nbsp;&nbsp;*&nbsp;Gracias.&nbsp;:)</span></div></li>
<li><div class="src-line"><a name="a27"></a><span class="src-doc">&nbsp;&nbsp;*</span></div></li>
<li><div class="src-line"><a name="a28"></a><span class="src-doc">&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a29"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a30"></a>&nbsp;&nbsp;<span class="src-inc">require_once</span><span class="src-sym">(</span><span class="src-id">dirname</span><span class="src-sym">(</span>__FILE__<span class="src-sym">)&nbsp;</span>.&nbsp;<span class="src-id">DIRECTORY_SEPARATOR&nbsp;</span>.&nbsp;<span class="src-str">'phpagi.php'</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a31"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a32"></a>&nbsp;&nbsp;<span class="src-var">$fastagi&nbsp;</span>=&nbsp;<span class="src-key">new&nbsp;</span><span class="src-id"><a href="../phpAGI/AGI.html">AGI</a></span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a33"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a34"></a>&nbsp;&nbsp;<span class="src-var">$fastagi</span><span class="src-sym">-&gt;</span><span class="src-id">verbose</span><span class="src-sym">(</span><a href="http://www.php.net/print_r">print_r</a><span class="src-sym">(</span><span class="src-var">$fastagi</span><span class="src-sym">,&nbsp;</span><span class="src-id">true</span><span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a35"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a36"></a>&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$fastagi</span><span class="src-sym">-&gt;</span><span class="src-id">config</span><span class="src-sym">[</span><span class="src-str">'fastagi'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'basedir'</span><span class="src-sym">]</span><span class="src-sym">))</span></div></li>
<li><div class="src-line"><a name="a37"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$fastagi</span><span class="src-sym">-&gt;</span><span class="src-id">config</span><span class="src-sym">[</span><span class="src-str">'fastagi'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'basedir'</span><span class="src-sym">]&nbsp;</span>=&nbsp;<a href="http://www.php.net/dirname">dirname</a><span class="src-sym">(</span>__FILE__<span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a38"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a39"></a>&nbsp;&nbsp;<span class="src-comm">//&nbsp;perform&nbsp;some&nbsp;security&nbsp;checks</span></div></li>
<li><div class="src-line"><a name="a40"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a41"></a>&nbsp;&nbsp;<span class="src-var">$script&nbsp;</span>=&nbsp;<span class="src-var">$fastagi</span><span class="src-sym">-&gt;</span><span class="src-id">config</span><span class="src-sym">[</span><span class="src-str">'fastagi'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'basedir'</span><span class="src-sym">]&nbsp;</span>.&nbsp;<span class="src-id">DIRECTORY_SEPARATOR&nbsp;</span>.&nbsp;<span class="src-var">$fastagi</span><span class="src-sym">-&gt;</span><span class="src-id">request</span><span class="src-sym">[</span><span class="src-str">'agi_network_script'</span><span class="src-sym">]</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a42"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a43"></a>&nbsp;&nbsp;<span class="src-comm">//&nbsp;in&nbsp;the&nbsp;same&nbsp;directory&nbsp;(or&nbsp;subdirectory)</span></div></li>
<li><div class="src-line"><a name="a44"></a>&nbsp;&nbsp;<span class="src-var">$mydir&nbsp;</span>=&nbsp;<a href="http://www.php.net/dirname">dirname</a><span class="src-sym">(</span><span class="src-var">$fastagi</span><span class="src-sym">-&gt;</span><span class="src-id">config</span><span class="src-sym">[</span><span class="src-str">'fastagi'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'basedir'</span><span class="src-sym">]</span><span class="src-sym">)&nbsp;</span>.&nbsp;<span class="src-id">DIRECTORY_SEPARATOR</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a45"></a>&nbsp;&nbsp;<span class="src-var">$dir&nbsp;</span>=&nbsp;<a href="http://www.php.net/dirname">dirname</a><span class="src-sym">(</span><span class="src-var">$script</span><span class="src-sym">)&nbsp;</span>.&nbsp;<span class="src-id">DIRECTORY_SEPARATOR</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a46"></a>&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><a href="http://www.php.net/substr">substr</a><span class="src-sym">(</span><span class="src-var">$dir</span><span class="src-sym">,&nbsp;</span><span class="src-num">0</span><span class="src-sym">,&nbsp;</span><a href="http://www.php.net/strlen">strlen</a><span class="src-sym">(</span><span class="src-var">$mydir</span><span class="src-sym">))&nbsp;</span>!=&nbsp;<span class="src-var">$mydir</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a47"></a>&nbsp;&nbsp;<span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a48"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$fastagi</span><span class="src-sym">-&gt;</span><span class="src-id">conlog</span><span class="src-sym">(</span><span class="src-str">&quot;</span><span class="src-str"><span class="src-var">$script</span>&nbsp;is&nbsp;not&nbsp;allowed&nbsp;to&nbsp;execute.</span><span class="src-str">&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a49"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">exit</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a50"></a>&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a51"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a52"></a>&nbsp;&nbsp;<span class="src-comm">//&nbsp;make&nbsp;sure&nbsp;it&nbsp;exists</span></div></li>
<li><div class="src-line"><a name="a53"></a>&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/file_exists">file_exists</a><span class="src-sym">(</span><span class="src-var">$script</span><span class="src-sym">))</span></div></li>
<li><div class="src-line"><a name="a54"></a>&nbsp;&nbsp;<span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a55"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$fastagi</span><span class="src-sym">-&gt;</span><span class="src-id">conlog</span><span class="src-sym">(</span><span class="src-str">&quot;</span><span class="src-str"><span class="src-var">$script</span>&nbsp;does&nbsp;not&nbsp;exist.</span><span class="src-str">&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a56"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">exit</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a57"></a>&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a58"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a59"></a>&nbsp;&nbsp;<span class="src-comm">//&nbsp;drop&nbsp;privileges</span></div></li>
<li><div class="src-line"><a name="a60"></a>&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$fastagi</span><span class="src-sym">-&gt;</span><span class="src-id">config</span><span class="src-sym">[</span><span class="src-str">'fastagi'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'setuid'</span><span class="src-sym">]</span><span class="src-sym">)&nbsp;</span>&amp;&amp;&nbsp;<span class="src-var">$fastagi</span><span class="src-sym">-&gt;</span><span class="src-id">config</span><span class="src-sym">[</span><span class="src-str">'fastagi'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'setuid'</span><span class="src-sym">]</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a61"></a>&nbsp;&nbsp;<span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a62"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$owner&nbsp;</span>=&nbsp;<a href="http://www.php.net/fileowner">fileowner</a><span class="src-sym">(</span><span class="src-var">$script</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a63"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$group&nbsp;</span>=&nbsp;<a href="http://www.php.net/filegroup">filegroup</a><span class="src-sym">(</span><span class="src-var">$script</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a64"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/posix_setgid">posix_setgid</a><span class="src-sym">(</span><span class="src-var">$group</span><span class="src-sym">)&nbsp;</span>||&nbsp;<span class="src-sym">!</span><a href="http://www.php.net/posix_setegid">posix_setegid</a><span class="src-sym">(</span><span class="src-var">$group</span><span class="src-sym">)&nbsp;</span>||&nbsp;<span class="src-sym">!</span><a href="http://www.php.net/posix_setuid">posix_setuid</a><span class="src-sym">(</span><span class="src-var">$owner</span><span class="src-sym">)&nbsp;</span>||&nbsp;<span class="src-sym">!</span><a href="http://www.php.net/posix_seteuid">posix_seteuid</a><span class="src-sym">(</span><span class="src-var">$owner</span><span class="src-sym">))</span></div></li>
<li><div class="src-line"><a name="a65"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a66"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$fastagi</span><span class="src-sym">-&gt;</span><span class="src-id">conlog</span><span class="src-sym">(</span><span class="src-str">&quot;failed&nbsp;to&nbsp;lower&nbsp;privileges.&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a67"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">exit</span><span class="src-sym">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div></li>
<li><div class="src-line"><a name="a68"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a69"></a>&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a70"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a71"></a>&nbsp;&nbsp;<span class="src-comm">//&nbsp;make&nbsp;sure&nbsp;script&nbsp;is&nbsp;still&nbsp;readable</span></div></li>
<li><div class="src-line"><a name="a72"></a>&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_readable">is_readable</a><span class="src-sym">(</span><span class="src-var">$script</span><span class="src-sym">))</span></div></li>
<li><div class="src-line"><a name="a73"></a>&nbsp;&nbsp;<span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a74"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$fastagi</span><span class="src-sym">-&gt;</span><span class="src-id">conlog</span><span class="src-sym">(</span><span class="src-str">&quot;</span><span class="src-str"><span class="src-var">$script</span>&nbsp;is&nbsp;not&nbsp;readable.</span><span class="src-str">&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a75"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">exit</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a76"></a>&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a77"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a78"></a>&nbsp;&nbsp;<span class="src-inc">require_once</span><span class="src-sym">(</span><span class="src-var">$script</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a79"></a><span class="src-php">?&gt;</span></div></li>
</ol></div>
</div>
	<p class="notes" id="credit">
		Documentation generated on Thu, 30 Sep 2010 02:21:49 -0700 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.4.2</a>
	</p>
	</body>
</html>
Return current item: PHP AGI