PukiWiki ' . S_VERSION . '' . ' © 2001-2016' . ' PukiWiki Development Team' ); ///////////////////////////////////////////////// // Session security options ini_set('session.use_strict_mode', 1); ini_set('session.use_cookies', 1); ini_set('session.use_only_cookies', 1); ///////////////////////////////////////////////// // Init server variables // Comapat and suppress notices if (!isset($HTTP_SERVER_VARS)) $HTTP_SERVER_VARS = array(); foreach (array('SCRIPT_NAME', 'SERVER_ADMIN', 'SERVER_NAME', 'SERVER_PORT', 'SERVER_SOFTWARE') as $key) { define($key, isset($_SERVER[$key]) ? $_SERVER[$key] : ''); unset(${$key}, $_SERVER[$key], $HTTP_SERVER_VARS[$key]); } ///////////////////////////////////////////////// // Init grobal variables $foot_explain = array(); // Footnotes $related = array(); // Related pages $head_tags = array(); // XHTML tags in ///////////////////////////////////////////////// // Time settings define('LOCALZONE', date('Z')); define('UTIME', time() - LOCALZONE); define('MUTIME', getmicrotime()); ///////////////////////////////////////////////// // Require INI_FILE define('INI_FILE', DATA_HOME . 'pukiwiki.ini.php'); $die = ''; if (! file_exists(INI_FILE) || ! is_readable(INI_FILE)) { $die .= 'File is not found. (INI_FILE)' . "\n"; } else { require(INI_FILE); } if ($die) die_message(nl2br("\n\n" . $die)); ///////////////////////////////////////////////// // INI_FILE: LANG に基づくエンコーディング設定 // MB_LANGUAGE: mb_language (for mbstring extension) // 'uni'(means UTF-8), 'English', or 'Japanese' // SOURCE_ENCODING: Internal content encoding (for mbstring extension) // 'UTF-8', 'ASCII', or 'EUC-JP' // CONTENT_CHARSET: Internal content encoding = Output content charset // (for DTD, htmlsc()) // 'UTF-8', 'iso-8859-1', 'EUC-JP' or ... switch (LANG){ case 'en': define('MB_LANGUAGE', 'English' ); break; case 'ja': define('MB_LANGUAGE', 'Japanese'); break; case 'ko': define('MB_LANGUAGE', 'Korean' ); break; //UTF-8 only // See BugTrack2/13 for all hack about Korean support, //UTF-8 only // and give us your report! //UTF-8 only default: die_message('No such language "' . LANG . '"'); break; } define('PKWK_UTF8_ENABLE', 1); //UTF-8 only if (defined('PKWK_UTF8_ENABLE')) { define('SOURCE_ENCODING', 'UTF-8'); define('CONTENT_CHARSET', 'UTF-8'); } else { switch (LANG){ case 'en': define('SOURCE_ENCODING', 'ASCII'); define('CONTENT_CHARSET', 'iso-8859-1'); break; case 'ja': define('SOURCE_ENCODING', 'EUC-JP'); define('CONTENT_CHARSET', 'EUC-JP'); break; } } mb_language(MB_LANGUAGE); mb_internal_encoding(SOURCE_ENCODING); mb_http_output('pass'); mb_detect_order('auto'); ///////////////////////////////////////////////// // INI_FILE: Require LANG_FILE define('LANG_FILE_HINT', DATA_HOME . LANG . '.lng.php'); // For encoding hint define('LANG_FILE', DATA_HOME . UI_LANG . '.lng.php'); // For UI resource $die = ''; foreach (array('LANG_FILE_HINT', 'LANG_FILE') as $langfile) { if (! file_exists(constant($langfile)) || ! is_readable(constant($langfile))) { $die .= 'File is not found or not readable. (' . $langfile . ')' . "\n"; } else { require_once(constant($langfile)); } } if ($die) die_message(nl2br("\n\n" . $die)); ///////////////////////////////////////////////// // LANG_FILE: Init encoding hint define('PKWK_ENCODING_HINT', isset($_LANG['encode_hint'][LANG]) ? $_LANG['encode_hint'][LANG] : ''); unset($_LANG['encode_hint']); ///////////////////////////////////////////////// // LANG_FILE: Init severn days of the week $weeklabels = $_msg_week; ///////////////////////////////////////////////// // INI_FILE: Init $script if (isset($script)) { get_script_uri($script); // Init manually } else { $script = get_script_uri(); // Init automatically } // INI_FILE: Auth settings if (isset($auth_type) && $auth_type === AUTH_TYPE_SAML) { $auth_external_login_url_base = get_script_uri() . '?//cmd.saml//sso'; } ///////////////////////////////////////////////// // INI_FILE: $agents: UserAgentの識別 $ua = 'HTTP_USER_AGENT'; $user_agent = $matches = array(); $user_agent['agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; unset(${$ua}, $_SERVER[$ua], $HTTP_SERVER_VARS[$ua], $ua); // safety foreach ($agents as $agent) { if (preg_match($agent['pattern'], $user_agent['agent'], $matches)) { $user_agent['profile'] = isset($agent['profile']) ? $agent['profile'] : ''; $user_agent['name'] = isset($matches[1]) ? $matches[1] : ''; // device or browser name $user_agent['vers'] = isset($matches[2]) ? $matches[2] : ''; // 's version break; } } unset($agents, $matches); // Profile-related init and setting define('UA_PROFILE', isset($user_agent['profile']) ? $user_agent['profile'] : ''); define('UA_INI_FILE', DATA_HOME . UA_PROFILE . '.ini.php'); if (! file_exists(UA_INI_FILE) || ! is_readable(UA_INI_FILE)) { die_message('UA_INI_FILE for "' . UA_PROFILE . '" not found.'); } else { require(UA_INI_FILE); // Also manually } define('UA_NAME', isset($user_agent['name']) ? $user_agent['name'] : ''); define('UA_VERS', isset($user_agent['vers']) ? $user_agent['vers'] : ''); unset($user_agent); // Unset after reading UA_INI_FILE ///////////////////////////////////////////////// // ディレクトリのチェック $die = ''; foreach(array('DATA_DIR', 'DIFF_DIR', 'BACKUP_DIR', 'CACHE_DIR') as $dir){ if (! is_writable(constant($dir))) $die .= 'Directory is not found or not writable (' . $dir . ')' . "\n"; } // 設定ファイルの変数チェック $temp = ''; foreach(array('rss_max', 'page_title', 'note_hr', 'related_link', 'show_passage', 'rule_related_str', 'load_template_func') as $var){ if (! isset(${$var})) $temp .= '$' . $var . "\n"; } if ($temp) { if ($die) $die .= "\n"; // A breath $die .= 'Variable(s) not found: (Maybe the old *.ini.php?)' . "\n" . $temp; } $temp = ''; foreach(array('LANG', 'PLUGIN_DIR') as $def){ if (! defined($def)) $temp .= $def . "\n"; } if ($temp) { if ($die) $die .= "\n"; // A breath $die .= 'Define(s) not found: (Maybe the old *.ini.php?)' . "\n" . $temp; } if($die) die_message(nl2br("\n\n" . $die)); unset($die, $temp); ///////////////////////////////////////////////// // 必須のページが存在しなければ、空のファイルを作成する foreach(array($defaultpage, $whatsnew, $interwiki) as $page){ if (! is_page($page)) pkwk_touch_file(get_filename($page)); } ///////////////////////////////////////////////// // 外部からくる変数のチェック // Prohibit $_GET attack foreach (array('msg', 'pass') as $key) { if (isset($_GET[$key])) die_message('Sorry, already reserved: ' . $key . '='); } // Expire risk unset($HTTP_GET_VARS, $HTTP_POST_VARS); //, 'SERVER', 'ENV', 'SESSION', ... unset($_REQUEST); // Considered harmful // Remove null character etc. $_GET = input_filter($_GET); $_POST = input_filter($_POST); $_COOKIE = input_filter($_COOKIE); // 文字コード変換 ($_POST) //
で送信された文字 (ブラウザがエンコードしたデータ) のコードを変換 // POST method は常に form 経由なので、必ず変換する // if (isset($_POST['encode_hint']) && $_POST['encode_hint'] != '') { // do_plugin_xxx() の中で、 に encode_hint を仕込んでいるので、 // encode_hint を用いてコード検出する。 // 全体を見てコード検出すると、機種依存文字や、妙なバイナリ // コードが混入した場合に、コード検出に失敗する恐れがある。 $encode = mb_detect_encoding($_POST['encode_hint']); mb_convert_variables(SOURCE_ENCODING, $encode, $_POST); } else if (isset($_POST['charset']) && $_POST['charset'] != '') { // TrackBack Ping で指定されていることがある // うまくいかない場合は自動検出に切り替え if (mb_convert_variables(SOURCE_ENCODING, $_POST['charset'], $_POST) !== $_POST['charset']) { mb_convert_variables(SOURCE_ENCODING, 'auto', $_POST); } } else if (! empty($_POST)) { // 全部まとめて、自動検出/変換 mb_convert_variables(SOURCE_ENCODING, 'auto', $_POST); } // 文字コード変換 ($_GET) // GET method は form からの場合と、 '&$1;', "\r" => '
' . "\n", /* 行末にチルダは改行 */ ), $line_rules);