START<?php $dir = __DIR__.'/../web/secure/'; $accept = false; // STF社内からアクセスは全て許可 if (in_array($_SERVER['REMOTE_ADDR'], array('210.171.168.115'))) { $accept = true; } $admin_host1 = gethostbynamel('comic-wired.ddnsking.com'); if ($admin_host1) { if (in_array($_SERVER['REMOTE_ADDR'], $admin_host1)) { $accept = true; } } foreach (glob($dir.'*.*') as $fname) { $fpath = $fname; $fdata = explode('.', basename($fname)); if (count($fdata) != 2) continue; $rule = $fdata[0]; $role = $fdata[1]; if (!in_array($role, array('deny', 'allow'))) continue; if (!isset($_SERVER[$rule])) continue; $fp = fopen($fpath, 'r'); if ($fp === false) continue; if (filesize($fpath) == 0) continue; $body = fread($fp, filesize($fpath)); $body = preg_replace("/\r\n|\r|\n/", "\n", $body); $custom_rules = explode("\n", $body); if (in_array($_SERVER[$rule], $custom_rules) && $role == "allow") { // 許可の方が優先度高い $accept = true; } if (in_array($_SERVER[$rule], $custom_rules) && $role == "deny" && !$accept) { exit; } } # 管理者ページ専用 if (preg_match('/^\/admin/', $_SERVER['REQUEST_URI'])) { foreach (glob($dir.'admin/*.*') as $fname) { $fpath = $fname; $fdata = explode('.', basename($fname)); if (count($fdata) != 2) continue; $rule = $fdata[0]; $role = $fdata[1]; if (!in_array($role, array('deny', 'allow'))) continue; if (!isset($_SERVER[$rule])) continue; $fp = fopen($fpath, 'r'); if ($fp === false) continue; if (filesize($fpath) == 0) continue; $body = fread($fp, filesize($fpath)); $body = preg_replace("/\r\n|\r|\n/", "\n", $body); $custom_rules = explode("\n", $body); if (in_array($_SERVER[$rule], $custom_rules) && $role == "allow") { // 許可の方が優先度高い $accept = true; } if (in_array($_SERVER[$rule], $custom_rules) && $role == "deny" && !$accept) { exit; } } } END