/** * アクションプラグイン処理 */ function plugin_logview_action() { global $vars, $_logview_msg, $_logview_logname; global $sortable_tracker, $_LANG, $vars; static $count = 0; $kind = isset($vars['kind']) ? $vars['kind'] : null; $title = $kind !== null ? sprintf($_logview_msg['msg_title'], $kind) : $_LANG['skin']['log']; // タイトルを設定 $page = isset($vars['page']) ? $vars['page'] : null; $ajax = isset($vars['ajax']) ? $vars['ajax'] : null; $is_role_adm = Auth::check_role('role_adm'); // 設定を読む $log = Utility::loadConfig('config-log.ini.php'); // ゲスト表示ができない場合は、認証を要求する if ($kind !== null && empty($log[$kind]['guest'])) { $obj = new Auth(); $user = $obj->check_auth(); if (empty($user)) { PluginRenderer::executePluginAction('login'); unset($obj); return array('msg' => $title, 'body' => '<p class="alert-warning">' . $_logview_msg['msg_not_auth'] . '</p>'); } } unset($obj); if (empty($page)) { return array('msg' => 'Page name is missing', 'body' => '<p class="alert-warning">Page name is missing.</p>'); } $wiki = Factory::Wiki($page); if (!$wiki->isReadable()) { return array('msg' => 'not readable', 'body' => '<p class="alert-warning">You have no permission to read this log.</p>'); } if ($kind === null) { if (!IS_MOBILE) { $body = '<div class="tabs" role="application">' . "\n"; $body .= '<ul role="tablist">'; $cnt = 0; foreach ($log as $key => $val) { $link_text = isset($_logview_logname[$key]) ? $_logview_logname[$key] : $key; if ($val['use'] === 1) { $body .= '<li role="tab"><a href="' . $wiki->uri('logview', array('kind' => $key)) . '">' . $link_text . '</a></li>'; } /* else { $body .= '<li><a href="'.get_cmd_uri('logview',$page,null,array('kind'=>$key)).'" data-ajax="raw" data-disabled="true">'.$link_text.'</a></li>'; } */ } $body .= '</ul></div>' . "\n"; if ($kind === null) { return array('msg' => $title, 'body' => $body); } $body .= '<div class="no-js" role="tabpanel">'; $nodata = $body . '<p>' . $_logview_msg['msg_nodata'] . '</p></div></div>'; } else { $body = '<div data-role="controlgroup" data-type="horizontal">' . "\n"; $cnt = 0; foreach ($log as $key => $val) { $link_text = isset($_LANG['skin']['log_' . $key]) ? $_LANG['skin']['log_' . $key] : $key; if ($val['use'] === 1) { $body .= '<a href="' . $wiki->uri('logview', array('kind' => $key)) . '" data-role="button">' . $link_text . '</a>'; } /* else { $body .= '<a href="'.get_cmd_uri('logview',$page,null,array('kind'=>$key)).'" data-ajax="raw" data-disabled="true">'.$link_text.'</a>'; } */ } $body .= '</div>' . "\n" . '<div class="ui-body ui-body-c"></div>'; if ($kind === null) { return array('msg' => $title, 'body' => $body); } } } else { $body = ''; } // 保存データの項目名を取得 $logfile = LogFactory::factory($kind, $page); $view = $logfile->get_view_field(); // 表示したい項目設定 $count++; $body[] = '<div class="table_wrapper">'; $body[] = '<table class="table table-bordered table_logview" data-pagenate="true">'; $body[] = '<thead>'; $body[] = '<tr>'; $cols = 0; // タイトルの処理 foreach ($view as $_view) { if ($_view === 'local_id' && $is_role_adm) { continue; } $body[] = '<th>' . $_logview_msg[$_view] . '</th>'; $cols++; } $body[] = '</tr>'; $body[] = '</thead>'; $body[] = '<tbody>'; $nodata = '<p class="alert alert-warning">' . $_logview_msg['msg_nodata'] . '</p>'; // USER-AGENT クラス $obj_ua = new UserAgent(USE_UA_OPTION); $guess = $log['guess_user']['use'] ? LogFactory::factory('guess_user')->get() : LogFactory::factory('update', $page)->getSigunature(); $ctr = 0; // データの編集 $lines = $logfile->get(); if (!$lines) { return array('msg' => $title, 'body' => $nodata); } foreach ($lines as $data) { if (!VIEW_ROBOTS && $obj_ua->is_robots($data['ua'])) { continue; } // ロボットは対象外 $body[] = '<tr>'; foreach ($view as $field) { switch ($field) { case 'ts': // タイムスタンプ (UTIME) $body[] = '<td>' . get_date('Y-m-d H:i:s', $data['ts']) . ' ' . get_passage($data['ts']) . '</td>'; break; case '@guess_diff': case '@diff': // 差分内容 $update = $field == '@diff' ? true : false; // FIXME: バックアップ/差分 なしの新規の場合 // バックアップデータの確定 $body[] = '<td class="style_td">'; $age = $logfile->get_backup_age($data['ts'], $update); switch ($age) { case -1: // データなし $body[] = '<a href="' . $wiki->uri() . '" rel="nofollow">none</a>'; break; case 0: // diff $body[] = '<a href="' . ($logfile->diff_exist() ? $wiki->uri('diff') : $wiki->uri()) . '" rel="nofollow">now</a>'; break; default: // あり $body[] = '<a class="ext" href="' . $wiki->uri('backup', null, array('age' => $age, 'action' => 'visualdiff')) . '" rel="nofollow">' . $age . '</a>'; break; } $body[] = '</td>'; break; case 'host': // ホスト名 (FQDN) $body[] = ' <td>'; if ($data['ip'] != $data['host']) { // 国名取得 list($flag_icon, $flag_name) = $obj_ua->get_icon_flag($data['host']); if (!empty($flag_icon) && $flag_icon != 'jp') { $body[] = '<span class="flag flag-' . $flag_icon . '" title="' . $flag_name . '" ></span>'; } // ドメイン取得 $domain = $obj_ua->get_icon_domain($data['host']); if (!empty($domain)) { // $body .= '<img src="'.$path_domain.$domain.'.png"'. // ' alt="'.$data['host'].'" title="'.$data['host'].'" />'; $body[] = '<span class="flag flag-' . $domain . '" title="' . $data['host'] . '" ></span>'; } } if ($data['ip'] !== '::1') { $body[] = '<a href="http://robtex.com/ip/' . $data['ip'] . '.html" rel="external nofollow">' . $data['host'] . '</a></td>'; } else { $body[] = $data['host'] . '</td>'; } break; case '@guess': // 推測 $body[] = '<td>' . Utility::htmlsc(logview_guess_user($data, $guess), ENT_QUOTES) . '</td>'; break; case 'ua': // ブラウザ情報 (USER-AGENT) $body[] = ' <td>'; $os = $obj_ua->get_icon_os($data['ua']); if (!empty($os)) { $body[] = '<span class="os os-' . $os . '" title="' . $os . '"></span>'; } $browser = $obj_ua->get_icon_broeswes($data['ua']); if (!empty($browser)) { $body[] = '<span class="browser browser-' . $browser . '" title="' . Utility::htmlsc($data['ua'], ENT_QUOTES) . '"></span>'; } $body[] = '</td>'; break; case 'local_id': if ($is_role_adm) { continue; } default: $body[] = '<td>' . Utility::htmlsc($data[$field], ENT_QUOTES) . '</td>'; } } $body[] = '</tr>'; $ctr++; } unset($obj_ua); if ($ctr == 0) { return array('msg' => $title, 'body' => $nodata); } $body[] = '</tbody>'; $body[] = '</table>'; $body[] = '</div>'; switch ($kind) { case 'login': case 'check': $body .= logview_user_list($fld, $page, $kind); break; } if ($ajax !== 'raw') { $body[] = '</div>'; $body[] = '</div>'; } else { echo join("\n", $body); exit; } return array('msg' => $title, 'body' => join("\n", $body)); }
/** * アクションプラグイン処理 */ function plugin_logview_action() { global $vars, $_logview_msg; global $log, $sortable_tracker; static $count = 0; $kind = isset($vars['kind']) ? $vars['kind'] : 'update'; $title = sprintf($_logview_msg['msg_title'], $kind); // タイトルを設定 $page = isset($vars['page']) ? $vars['page'] : ''; // ゲスト表示ができない場合は、認証を要求する if ($log[$kind]['guest'] == '') { $obj = new auth(); $user = $obj->check_auth(); if (empty($user)) { if (exist_plugin('login')) { do_plugin_action('login'); } unset($obj); return array('msg' => $title, 'body' => $_logview_msg['msg_not_auth']); } } unset($obj); check_readable($page, false); // 保存データの項目名を取得 $name = log::get_log_field($kind); $view = log::get_view_field($kind); // 表示したい項目設定 if ($sortable_tracker && $count == 0) { global $head_tags; $head_tags[] = ' <script type="text/javascript" charset="utf-8" src="' . SKIN_URI . 'sortabletable.js"></script>'; } $count++; $body = <<<EOD <table id="logview{$count}" class="style_table" cellspacing="1" border="0"> <thead> <tr> EOD; $cols = 0; $is_role_adm = auth::check_role('role_adm'); // タイトルの処理 foreach ($view as $_view) { if ($_view === 'local_id' && $is_role_adm) { continue; } $body .= '<td class="style_td">' . $_logview_msg[$_view] . '</td>' . "\n"; $cols++; } $body .= <<<EOD </tr> </thead> <tbody> EOD; // データを取得 $fld = logview_get_data(log::set_filename($kind, $page), $name); if (empty($fld)) { return array('msg' => $title, 'body' => 'no data'); } // USER-AGENT クラス $obj_ua = new user_agent(USE_UA_OPTION); $path_flag = IMAGE_URI . 'icon/flags/'; $path_browser = IMAGE_URI . 'icon/browser/'; $path_os = IMAGE_URI . 'icon/os/'; $path_domain = IMAGE_URI . 'icon/option/domain/'; $guess = $log['guess_user']['use'] ? log::read_guess() : log::summary_signature(); $ctr = 0; // データの編集 foreach ($fld as $data) { if (!VIEW_ROBOTS && $obj_ua->is_robots($data['ua'])) { continue; } // ロボットは対象外 $body .= "<tr>\n"; foreach ($view as $field) { switch ($field) { case 'ts': // タイムスタンプ (UTIME) $body .= ' <td class="style_td">' . get_date('Y-m-d H:i:s', $data['ts']) . ' ' . get_passage($data['ts']) . "</td>\n"; break; case '@guess_diff': case '@diff': // 差分内容 $update = $field == '@diff' ? true : false; // FIXME: バックアップ/差分 なしの新規の場合 // バックアップデータの確定 $body .= ' <td class="style_td">'; $age = log::get_backup_age($page, $data['ts'], $update); switch ($age) { case -1: // データなし $body .= '<a class="ext" href="' . get_page_uri($page) . '" rel="nofollow">none</a>'; break; case 0: // diff $body .= '<a class="ext" href="'; $body .= log::diff_exist($page) ? get_cmd_uri('diff', $page) : get_page_uri($page); $body .= '" rel="nofollow">now</a>'; break; default: // あり $body .= '<a class="ext" href="' . get_cmd_uri('backup', $page, '', array('age' => $age, 'action' => 'visualdiff')) . '"' . ' rel="nofollow">' . $age . '</a>'; break; } $body .= "</td>\n"; break; case 'host': // ホスト名 (FQDN) $body .= ' <td class="style_td">'; if ($data['ip'] != $data['host']) { // 国名取得 list($flag_icon, $flag_name) = $obj_ua->get_icon_flag($data['host']); if (!empty($flag_icon) && $flag_icon != 'jp') { $body .= '<img src="' . $path_flag . $flag_icon . '.png"' . ' alt="' . $flag_name . '" title="' . $flag_name . '" />'; } // ドメイン取得 $domain = $obj_ua->get_icon_domain($data['host']); if (!empty($domain)) { $body .= '<img src="' . $path_domain . $domain . '.png"' . ' alt="' . $data['host'] . '" title="' . $data['host'] . '" />'; } } $body .= $data['host'] . "</td>\n"; break; case '@guess': // 推測 $body .= ' <td class="style_td">' . htmlspecialchars(logview_guess_user($data, $guess), ENT_QUOTES) . "</td>\n"; break; case 'ua': // ブラウザ情報 (USER-AGENT) $body .= ' <td class="style_td">'; $os = $obj_ua->get_icon_os($data['ua']); if (!empty($os)) { $body .= '<img src="' . $path_os . $os . '.png"' . ' alt="' . $os . '" title="' . $os . '" />'; } $browser = $obj_ua->get_icon_broeswes($data['ua']); if (!empty($browser)) { $body .= '<img src="' . $path_browser . $browser . '.png"' . ' alt="' . htmlspecialchars($data['ua'], ENT_QUOTES) . '" title="' . htmlspecialchars($data['ua'], ENT_QUOTES) . '" />'; } $body .= "</td>\n"; break; case 'local_id': if ($is_role_adm) { continue; } default: $body .= ' <td class="style_td">' . htmlspecialchars($data[$field], ENT_QUOTES) . "</td>\n"; } } $body .= "</tr>\n"; $ctr++; } unset($obj_ua); if ($ctr == 0) { return array('msg' => $title, 'body' => 'no data'); } $body .= <<<EOD </tbody> </table> EOD; switch ($kind) { case 'login': case 'check': $body .= logview_user_list($fld, $page, $kind); break; } if ($sortable_tracker) { $logviewso = join(',', array_fill(0, $cols, '"String"')); $body .= <<<EOD <script type="text/javascript"> <!-- <![CDATA[ var st = new SortableTable(document.getElementById('logview{$count}'),[{$logviewso}]); //]]>--> </script> EOD; } return array('msg' => $title, 'body' => $body); }