<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>Topic awstats | Hey, ruX is here.</title>
	<atom:link href="https://rux.vc/tags/awstats/feed/" rel="self" type="application/rss+xml" />
	<link>https://rux.vc</link>
	<description>Delivering things - from code to product</description>
	<lastBuildDate>Thu, 06 Jan 2011 13:36:52 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.8</generator>
<site xmlns="com-wordpress:feed-additions:1">162978439</site>	<item>
		<title>php trick: вариант обхда open_basedir restriction</title>
		<link>https://rux.vc/2011.01/bypass-open_basedir-restriction/</link>
					<comments>https://rux.vc/2011.01/bypass-open_basedir-restriction/#respond</comments>
		
		<dc:creator><![CDATA[ruX]]></dc:creator>
		<pubDate>Thu, 06 Jan 2011 13:36:52 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[awstats]]></category>
		<category><![CDATA[directory]]></category>
		<category><![CDATA[enum]]></category>
		<category><![CDATA[exec]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[folder]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[trick]]></category>
		<guid isPermaLink="false">http://rux.pp.ru/blog/?p=720</guid>

					<description><![CDATA[<p>Задача: нужно перечислить файлы не в директории сайта Проблема: действуют ограничения, например: Warning: dir() [function.dir]: open_basedir restriction in effect. File(/etc/awstats) is not within the allowed path(s): (.) in /var/www/site/path/index.php on line 22 Warning: dir(/etc/awstats/) [function.dir]: failed to open dir: Operation not permitted in /var/www/site/path/index.php on line 22 Есть вариант обойти это, при условии что разрешенно ... <a title="php trick: вариант обхда open_basedir restriction" class="read-more" href="https://rux.vc/2011.01/bypass-open_basedir-restriction/" aria-label="More on php trick: вариант обхда open_basedir restriction">Read more</a></p>
The post <a href="https://rux.vc/2011.01/bypass-open_basedir-restriction/">php trick: вариант обхда open_basedir restriction</a> first appeared on <a href="https://rux.vc">Hey, ruX is here.</a>.]]></description>
										<content:encoded><![CDATA[<p><span style="color: #ccffcc;">Задача:</span> нужно перечислить файлы <strong>не</strong> в директории сайта</p>
<p><span style="color: #ccffff;">Проблема:</span> действуют ограничения, например:<br />
<code lang="php"><br />
Warning: dir() [function.dir]: open_basedir restriction in effect.<br />
     File(/etc/awstats) is not within the allowed path(s): (.) in /var/www/site/path/index.php on line 22<br />
Warning: dir(/etc/awstats/) [function.dir]: failed to open dir: Operation not permitted<br />
     in /var/www/site/path/index.php on line 22<br />
</code></p>
<p>Есть вариант обойти это, при условии что разрешенно выполнять приложения через <strong>exec()</strong> и это unix-система</p>
<p><span id="more-720"></span></p>
<p><strong><span style="color: #ccffcc;">Решение:</span></strong><br />
Есть консольная утилита, которая выводит список файлов - <strong>ls</strong>, она есть на всех юникс системах, воспользуемся этим. Если dir() или open_dir() вернули null, значит не удаётся открыть директорию для перечисления. Такая же реакция когда её не существует. Но мы то знаем куда ломимся :)</p>
<p>Функция, которая получает список файлов (НЕ РЕКУРСИВНО) в папке:<br />
<code lang="php"><br />
function listFiles($folder) {<br />
	$result = array();</p>
<p>	if ($d = @dir($folder)) {<br />
		while (false !== ($entry = $d-&gt;read()))<br />
			$result[] = $entry;<br />
		$d-&gt;close();<br />
	} else {<br />
		exec(&quot;ls -a {$folder}&quot;, $output);<br />
		$output = implode(&quot; &quot;, $output);<br />
		$result = explode(&quot; &quot;, $output);<br />
		foreach($result as &amp;$r) $r = trim($r);<br />
	}<br />
	return $result;</p>
<p>}<br />
</code><br />
Хороший такой костыль получился :)
</p>
<p>И теперь примерчик применения (вывести все хосты, которые мониторит awstats):<br />
<code lang="php"><br />
&lt;?php<br />
$awstatsDir = &quot;/etc/awstats/&quot;;<br />
?&gt;</p>
<p>&lt;html&gt;<br />
&lt;head&gt;&lt;/head&gt;<br />
&lt;body link=&quot;green&quot; vlink=&quot;green&quot;&gt;</p>
<p>&lt;h4 style=&quot;margin-bottom:0&quot;&gt;awstats sites&lt;/h4&gt;<br />
&lt;ul style=&quot;margin-top:0&quot;&gt;<br />
&lt;?php</p>
<p>ini_set(&#039;display_errors&#039;, true);<br />
error_reporting(E_ALL);</p>
<p>$files = listFiles($awstatsDir);<br />
foreach($files as $file) {<br />
	if (!preg_match(&quot;/^awstats\.(.*)\.conf$/&quot;, $file, $matches)) continue;<br />
	echo &quot;&lt;li&gt;&lt;a href=\&quot;http://{$matches[1]}/awstats/awstats.pl\&quot;&gt;{$matches[1]}&lt;/a&gt;&lt;/li&gt;&quot;;<br />
}</p>
<p>?&gt;<br />
&lt;/ul&gt;<br />
&lt;/body&gt;</p>
<p>&lt;?php<br />
function listFiles($folder) {<br />
	$result = array();</p>
<p>	if ($d = @dir($folder)) {<br />
		while (false !== ($entry = $d-&gt;read()))<br />
			$result[] = $entry;<br />
		$d-&gt;close();<br />
	} else {<br />
		exec(&quot;ls -a {$folder}&quot;, $output);<br />
		$output = implode(&quot; &quot;, $output);<br />
		$result = explode(&quot; &quot;, $output);<br />
		foreach($result as &amp;$r) $r = trim($r);<br />
	}<br />
	return $result;</p>
<p>}<br />
?&gt;<br />
</code></p>The post <a href="https://rux.vc/2011.01/bypass-open_basedir-restriction/">php trick: вариант обхда open_basedir restriction</a> first appeared on <a href="https://rux.vc">Hey, ruX is here.</a>.]]></content:encoded>
					
					<wfw:commentRss>https://rux.vc/2011.01/bypass-open_basedir-restriction/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">720</post-id>	</item>
	</channel>
</rss>
