diff --git a/adm/admin.lib.php b/adm/admin.lib.php index ff2b9766c..1d2d70a97 100644 --- a/adm/admin.lib.php +++ b/adm/admin.lib.php @@ -610,6 +610,110 @@ function admin_menu_find_by($call, $search_key) return ''; } +function admin_menu_local_path($url) +{ + $url = (string) $url; + + if (!$url) { + return ''; + } + + $url = preg_replace('/[?#].*$/', '', $url); + + $maps = array( + G5_ADMIN_URL => G5_ADMIN_PATH, + ); + + if (defined('G5_SMS5_ADMIN_URL') && defined('G5_SMS5_ADMIN_PATH')) { + $maps[G5_SMS5_ADMIN_URL] = G5_SMS5_ADMIN_PATH; + } + + foreach ($maps as $base_url => $base_path) { + if (strpos($url, $base_url) !== 0) { + continue; + } + + $path = $base_path.substr($url, strlen($base_url)); + + if (substr($path, -1) === '/') { + $path .= 'index.php'; + } + + return $path; + } + + return ''; +} + +function admin_menu_is_super_only($menu_item) +{ + static $cache = array(); + + $sub_menu = isset($menu_item[0]) ? (string) $menu_item[0] : ''; + if (!$sub_menu) { + return false; + } + + if (isset($cache[$sub_menu])) { + return $cache[$sub_menu]; + } + + // 향후 메뉴 정의에서 명시적으로 최고관리자 전용 표시가 필요할 때 사용한다. + if (isset($menu_item[4]) && $menu_item[4] === 'super') { + return $cache[$sub_menu] = true; + } + + $path = admin_menu_local_path(isset($menu_item[2]) ? $menu_item[2] : ''); + if (!$path || !is_readable($path)) { + return $cache[$sub_menu] = false; + } + + $content = file_get_contents($path, false, null, 0, 12000); + if ($content === false) { + return $cache[$sub_menu] = false; + } + + $pattern = '/if\s*\([^\)]*\$is_admin\s*(?:!==|!=)\s*[\'"]super[\'"][^\)]*\)\s*\{?[\s\S]{0,250}(?:alert|alert_close|die)\s*\([^\;]*(?:최고관리자만|최고관리자로)/u'; + + return $cache[$sub_menu] = (bool) preg_match($pattern, $content); +} + +function admin_get_assignable_auth_menu() +{ + global $menu; + + $assignable_auth_menu = array(); + + if (!isset($menu) || !is_array($menu)) { + return $assignable_auth_menu; + } + + foreach ($menu as $menu_group) { + if (!is_array($menu_group)) { + continue; + } + + for ($i=1; $i @@ -105,8 +107,8 @@ $colspan = 5; $is_continue = true; } - // 메뉴번호가 바뀌는 경우에 현재 없는 저장된 메뉴는 삭제함 - if (!isset($auth_menu[$row['au_menu']])) { + // 메뉴번호가 바뀌거나 권한 부여 대상이 아닌 메뉴는 삭제함 + if (!isset($assignable_auth_menu[$row['au_menu']])) { sql_query(" delete from {$g5['auth_table']} where au_menu = '{$row['au_menu']}' "); $is_continue = true; } @@ -130,7 +132,7 @@ $colspan = 5; - + @@ -205,7 +207,7 @@ echo $pagelist;