특정 디텍토리 퍼미션 검사 */ function permission_check($file) { $open = @is_writable($file); if (!$open) { return "N"; } else { return "Y"; } } function permission_txt($val) { if ($val == "Y") { return "<span style='color:blue;font-size:11px;letter-spacing:-1px;padding-left:10px;'>변경 완료됨</span>"; } else { return "<span style='color:red;font-size:11px;letter-spacing:-1px;padding-left:10px;'>퍼미션 변경되지 않음</span>"; } } /* 템플릿 치환 */ if (permission_check(__DIR_PATH__ . "modules/board/upload") == "Y") { $tpl->skin_modeling_hideArea("[{installBtn_start}]", "[{installBtn_end}]", "show"); $tpl->skin_modeling_hideArea("[{recheckBtn_start}]", "[{recheckBtn_end}]", "hide"); } else { $tpl->skin_modeling_hideArea("[{installBtn_start}]", "[{installBtn_end}]", "hide"); $tpl->skin_modeling_hideArea("[{recheckBtn_start}]", "[{recheckBtn_end}]", "show"); } $tpl->skin_modeling("[permissionCheck_upload]", permission_txt(permission_check(__DIR_PATH__ . "modules/board/upload"))); echo $tpl->skin_echo();
function permission_check($name, $args, $verbose = True) { global $passed_icon, $error_icon, $warning_icon, $is_windows; //echo "<p>permision_check('$name',".print_r($args,True).",'$verbose')</p>\n"; if (substr($name, 0, 3) != '../') { $name = '../' . $name; } $rel_name = substr($name, 3); if (!file_exists($name) && isset($args['only_if_exists']) && $args['only_if_exists']) { return True; } $perms = $checks = ''; if (file_exists($name)) { $owner = function_exists('posix_getpwuid') ? posix_getpwuid(@fileowner($name)) : array('name' => 'nn'); $group = function_exists('posix_getgrgid') ? posix_getgrgid(@filegroup($name)) : array('name' => 'nn'); $perms = "{$owner['name']}/{$group['name']} " . verbosePerms(@fileperms($name)); } $checks = array(); if (isset($args['is_readable'])) { $checks[] = (!$args['is_readable'] ? 'not ' : '') . lang('readable by the webserver'); } if (isset($args['is_writable'])) { $checks[] = (!$args['is_writable'] ? 'not ' : '') . lang('writable by the webserver'); } if (isset($args['is_world_readable'])) { $checks[] = (!$args['is_world_readable'] ? lang('not') . ' ' : '') . lang('world readable'); } if (isset($args['is_world_writable'])) { $checks[] = (!$args['is_world_writable'] ? lang('not') . ' ' : '') . lang('world writable'); } $checks = implode(', ', $checks); $icon = $passed_icon; $msg = lang('Checking file-permissions of %1 for %2: %3', $rel_name, $checks, $perms) . "<br>\n"; if (!file_exists($name)) { echo $error_icon . $msg . lang('%1 does not exist !!!', $rel_name) . "</span><br/>\n"; return False; } $warning = False; if (!$GLOBALS['run_by_webserver'] && (@$args['is_readable'] || @$args['is_writable'])) { echo $warning_icon . ' ' . $msg . lang('Check can only be performed, if called via a webserver, as the user-id/-name of the webserver is not known.') . "</span><br/>\n"; unset($args['is_readable']); unset($args['is_writable']); $warning = True; } $Ok = True; if (isset($args['is_writable']) && is_writable($name) != $args['is_writable']) { echo "{$error_icon} {$msg} " . lang('%1 is %2%3 !!!', $rel_name, $args['is_writable'] ? lang('not') . ' ' : '', lang('writable by the webserver')) . "</span><br/>\n"; $Ok = False; } if (isset($args['is_readable']) && is_readable($name) != $args['is_readable']) { echo "{$error_icon} {$msg} " . lang('%1 is %2%3 !!!', $rel_name, $args['is_readable'] ? lang('not') . ' ' : '', lang('readable by the webserver')) . "</span><br/>\n"; $Ok = False; } if (!$is_windows && isset($args['is_world_readable']) && !(fileperms($name) & 04) == $args['is_world_readable']) { echo "{$error_icon} {$msg}" . lang('%1 is %2%3 !!!', $rel_name, $args['is_world_readable'] ? lang('not') . ' ' : '', lang('world readable')) . "</span><br/>\n"; $Ok = False; } if (!$is_windows && isset($args['is_world_writable']) && !(fileperms($name) & 02) == $args['is_world_writable']) { echo "{$error_icon} {$msg} " . lang('%1 is %2%3 !!!', $rel_name, $args['is_world_writable'] ? lang('not') . ' ' : '', lang('world writable')) . "</span><br/>\n"; $Ok = False; } if ($Ok && !$warning && $verbose) { echo $passed_icon . ' ' . $msg; } if ($Ok && @$args['recursiv'] && is_dir($name)) { if ($verbose) { echo "<div id='setup_info'>" . lang('This might take a while, please wait ...') . "</div>\n"; flush(); } @set_time_limit(0); $handle = @opendir($name); while ($handle && ($file = readdir($handle))) { if ($file != '.' && $file != '..') { $Ok = $Ok && permission_check(($name != '.' ? $name . '/' : '') . $file, $args, False); } } if ($handle) { closedir($handle); } } if ($verbose) { echo "\n"; } return $Ok; }