'; $reval = false; if (empty($rootDir)) $rootDir = DEDEROOT; if (TestWriteable($d)) { @file_put_contents($d . '/' . $filename, $testStr); $remoteUrl = $siteuRL . '/' . str_replace($rootDir, '', str_replace("\\", '/', realpath($d))) . '/' . $filename; $tempStr = @PostHost($remoteUrl); $reval = (md5($d) == trim($tempStr)) ? true : false; unlink($d . '/' . $filename); return $reval; } else { return -1; } } } if (!function_exists('PostHost')) { function PostHost($host, $data = '', $method = 'GET', $showagent = null, $port = null, $timeout = 30) { $parse = @parse_url($host); if (empty($parse)) return false; if ((int)$port > 0) { $parse['port'] = $port; } elseif (!@$parse['port']) { $parse['port'] = '80'; } $parse['host'] = str_replace(array('http://', 'https://'), array('', 'ssl://'), "$parse[scheme]://") . $parse['host']; if (!$fp = @fsockopen($parse['host'], $parse['port'], $errnum, $errstr, $timeout)) { return false; } $method = strtoupper($method); $wlength = $wdata = $responseText = ''; $parse['path'] = str_replace(array('\\', '//'), '/', @$parse['path']) . "?" . @$parse['query']; if ($method == 'GET') { $separator = @$parse['query'] ? '&' : ''; substr($data, 0, 1) == '&' && $data = substr($data, 1); $parse['path'] .= $separator . $data; } elseif ($method == 'POST') { $wlength = "Content-length: " . strlen($data) . "\r\n"; $wdata = $data; } $write = "$method $parse[path] HTTP/1.0\r\nHost: $parse[host]\r\nContent-type: application/x-www-form-urlencoded\r\n{$wlength}Connection: close\r\n\r\n$wdata"; @fwrite($fp, $write); while ($data = @fread($fp, 4096)) { $responseText .= $data; } @fclose($fp); empty($showagent) && $responseText = trim(stristr($responseText, "\r\n\r\n"), "\r\n"); return $responseText; } } $allPath = array(); $needDir = "$cfg_medias_dir| $cfg_image_dir| $ddcfg_image_dir| $cfg_user_dir| $cfg_soft_dir| $cfg_other_medias| $cfg_medias_dir/flink| $cfg_cmspath/data| $cfg_cmspath/data/$cfg_backup_dir| $cfg_cmspath/data/textdata| $cfg_cmspath/data/sessions| $cfg_cmspath/data/tplcache| $cfg_cmspath/data/admin| $cfg_cmspath/data/enums| $cfg_cmspath/data/mark| $cfg_cmspath/data/module| $cfg_cmspath/data/rss| $cfg_special| $cfg_cmspath$cfg_arcdir"; $needDir = explode('|', $needDir); foreach ($needDir as $key => $val) { $allPath[trim($val)] = array( 'read' => true, // 读取 'write' => true, // 写入 'execute' => false // 执行 ); } // 所有栏目目录 $sql = "SELECT typedir FROM #@__arctype ORDER BY id DESC"; $dsql->SetQuery($sql); $dsql->Execute('al', $sql); while ($row = $dsql->GetArray('al')) { $typedir = str_replace($cfg_basehost, '', $row['typedir']); if (preg_match("/^http:|^ftp:/i", $row['typedir'])) continue; $typedir = str_replace("{cmspath}", $cfg_cmspath, $row['typedir']); $allPath[trim($typedir)] = array( 'read' => true, // 读取 'write' => true, // 写入 'execute' => false // 执行 ); } // 只允许读取,不允许写入的目录 $needDir = array( 'include', 'member', 'plus', ); // 获取子目录 function GetSondir($d, &$dirname = array()) { $dh = dir($d); while ($filename = $dh->read()) { if ( substr($filename, 0, 1) == '.' || is_file($d . '/' . $filename) || preg_match("#^(svn|bak-)#i", $filename) ) { continue; } if (is_dir($d . '/' . $filename)) { $dirname[] = $d . '/' . $filename; GetSondir($d . '/' . $filename, $dirname); } } $dh->close(); return $dirname; } //获取所有文件列表 function preg_ls($path = ".", $rec = FALSE, $pat = "/.*/", $ignoredir = '') { while (substr($path, -1, 1) == "/") { $path = substr($path, 0, -1); } if (!is_dir($path)) { $path = dirname($path); } if ($rec !== TRUE) { $rec = FALSE; } $d = dir($path); $ret = array(); while (FALSE !== ($e = $d->read())) { if (($e == ".") || ($e == "..")) { continue; } if ($rec && is_dir($path . "/" . $e) && ($ignoredir == '' || strpos($ignoredir, $e) === FALSE)) { $ret = array_merge($ret, preg_ls($path . "/" . $e, $rec, $pat, $ignoredir)); continue; } if (!preg_match($pat, $e)) { continue; } $ret[] = $path . "/" . $e; } return (empty($ret) && preg_match($pat, basename($path))) ? array($path . "/") : $ret; } foreach ($needDir as $key => $val) { $allPath[trim('/' . $val)] = array( 'read' => true, // 读取 'write' => false, // 写入 'execute' => true // 执行 ); $sonDir = GetSondir(DEDEROOT . '/' . $val); foreach ($sonDir as $kk => $vv) { $vv = trim(str_replace(DEDEROOT, '', $vv)); $allPath[$vv] = array( 'read' => true, // 读取 'write' => false, // 写入 'execute' => true // 执行 ); } } // 不需要执行的 $needDir = array( '/images', '/templets' ); foreach ($needDir as $key => $val) { $allPath[trim('/' . $val)] = array( 'read' => true, // 读取 'write' => false, // 写入 'execute' => false // 执行 ); $sonDir = GetSondir(DEDEROOT . '/' . $val); foreach ($sonDir as $kk => $vv) { $vv = trim(str_replace(DEDEROOT . '/', '', $vv)); $allPath[$vv] = array( 'read' => true, // 读取 'write' => false, // 写入 'execute' => false // 执行 ); } } // 所有js建议只读 $jsDir = array( '/images', '/templets', '/include' ); foreach ($jsDir as $k => $v) { $jsfiles = preg_ls(DEDEROOT . $v, TRUE, "/.*\.(js)$/i"); foreach ($jsfiles as $k => $v) { $vv = trim(str_replace(DEDEROOT . '/', '/', $v)); $allPath[$vv] = array( 'read' => true, // 读取 'write' => false, // 写入 'execute' => false // 执行 ); } } ?>
系统运行目录权限检测返回主页帮助说明
说明:本程序用于检测DedeCMSV6站点所涉及的目录权限,并且提供一个全面的检测说明,您可以根据检测报告来配置站点以保证站点更为安全。
目录 执行 读取 写入