<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[[值得注意]PHP在Linux下以www运行为了确保你要读取的WEB页面可以访问,如何才能获得文件的相关属性？]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Php/Js/Shell/Go]]></category>
<pubDate>Tue, 25 Mar 2014 03:13:12 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	背景：<br/> Linux 下的权限比较起Windows是个问题，但它保证了其安全性，Cache 会出现 chmod(): Operation not permitted 这个讯息。查看 cache 目录应该是 PHP 以 safe mode 执行的关系，所以没办法建出 777 权限目录。<br/> php -i&#124;grep safe_mode<br/>safe_mode =&gt; Off =&gt; Off<br/>—————————————————想办法以try catch实现抓权限———————————————————————————<br/>问：PHP在Linux下以www运行为了确保你要读取的WEB页面可以访问,如何才能获得文件的相关属性？<br/>答：PHP提供了一组获得文件属性的方法，例如 filemtime(),fileowner(),filegroup(),filectime(),fileatime()...详细的使用请参阅手册。<br/>来自：http://jingyan.baidu.com/article/bea41d4346a1b2b4c51be6a1.html<br/><br/>文件：fileowner.php<br/><textarea name="code" class="php" rows="15" cols="100">
&lt;?php
echo fileowner(&quot;./redirect-20140325.log&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
?&gt;
</textarea><br/>运行：<br/>php fileowner.php<br/>48<br/>48是谁？<br/>vi /etc/passwd 找48即可，是www，如下：<br/>www:x:48:48::/home/www:/sbin/nologin <br/><br/>更多函数一块写：<br/>文件：fileInfo.php<br/><textarea name="code" class="php" rows="15" cols="100">
&lt;?php
echo &quot;文件拥有者id:&quot;.fileowner(&quot;./redirect-20140325.log&quot;).&quot;&#92;n&quot;;
echo &quot;文件属组id：&quot;.filegroup(&quot;./redirect-20140325.log&quot;).&quot;&#92;n&quot;;
echo &quot;文件权限值：&quot;.substr(sprintf(&#039;%o&#039;, fileperms(&#039;./redirect-20140325.log&#039;)), -4).&quot;&#92;n&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
?&gt;
</textarea><br/>运行情况：<br/>文件拥有者id:48<br/>文件属组id：48<br/>文件权限值：0644<br/><br/>更多PHP手册函数：<br/>http://www.wapm.cn/phpdoc/zh/function.fileperms.html<br/>http://www.w3school.com.cn/php/func_filesystem_filegroup.asp<br/>http://www.w3school.com.cn/php/func_filesystem_fileowner.asp<br/><br/>php异常捕获try catch实例解析：<br/>http://www.jbxue.com/article/10331.html<br/><br/>—————————————————以try catch实现对其权限不够的不活并写入日志—————————————————<br/> permitted.php<br/><textarea name="code" class="php" rows="15" cols="100">
&lt;?php
$dir=&quot;/data/htdocs/justwinit_alpha/data/logs/&quot;.date(&quot;Ymd&quot;).&quot;/&quot;;
$file=&quot;permitted.txt&quot;;
try
&#123;
&nbsp;&nbsp;&nbsp;&nbsp;if (!@chmod($dir . $file, 0777))&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new Exception(&quot;ErrorException[Warning]:&quot;.&quot;chmod():Operation not permitted&quot;);&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&#125; catch (Exception $e) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$loger2FileTmp = &quot;DateTime:&quot;.date(&quot;Y-m-d H:i:s&quot;).&quot;&#92;nError on line &quot;.$e-&gt;getLine().&quot; in &quot;.$e-&gt;getFile().&quot;, &quot;.$e-&gt;getMessage().&quot;&#92;n&quot;;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$loger2FileTmp .=&quot;文件名:&quot;.$dir . $file.&quot;&#92;n&quot;; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$loger2FileTmp .=&quot;文件拥有者id:&quot;.fileowner($dir . $file).&quot;&#92;n&quot;;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$loger2FileTmp .=&quot;文件属组id：&quot;.filegroup($dir . $file).&quot;&#92;n&quot;;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$loger2FileTmp .=&quot;文件权限值：&quot;.substr(sprintf(&quot;%o&quot;, fileperms($dir . $file)), -4).&quot;&#92;n&quot;; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file_put_contents(&quot;/tmp/logPermissionFile4My.txt&quot;,$loger2FileTmp,FILE_APPEND);
&#125;
?&gt;
</textarea><br/>这块故意给它一个root权限，chown -R root permitted.php<br/>去执行和写的权限：chmod a-xw permitted.txt <br/>在web下运行结果，tail -f /tmp/logPermissionFile4My.txt&nbsp;&nbsp; :<br/>DateTime:2014-03-25 13:23:22<br/>Error on line 7 in /data/htdocs/tools.jackxiang.com/fileowner.php, ErrorException[Warning]:chmod():Operation not permitted<br/>文件拥有者id:0<br/>文件属组id：0<br/>文件权限值：0444
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [值得注意]PHP在Linux下以www运行为了确保你要读取的WEB页面可以访问,如何才能获得文件的相关属性？]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>