function plugin_xbel_convert() { global $script, $vars; global $_xbel_msg; // ユーザ認証されていない $id = auth::check_auth(); if (empty($id)) { return ''; } $argv = func_get_args(); $argc = func_num_args(); $field = array('pref'); for ($i = 0; $i < $argc; $i++) { ${$field}[$i] = $argv[$i]; } if (empty($pref)) { $pref = XBEL_PREF_PAGE; } $page_pref = xbel::get_data_prefix($pref); $rc = <<<EOD <form action="{$script}" method="post"> <input type="hidden" name="plugin" value="xbel" /> <input type="hidden" name="adm" value="list" /> <div> {$_xbel_msg['msg_text']} </div> <table> EOD; $i = 0; foreach ($page_pref as $_page) { $i++; $url = get_page_uri($_page); $rc .= <<<EOD <tr> <td><input type="checkbox" name="{$i}_c" /></td> <td><input type="hidden" name="{$i}_n" value="{$_page}" /><a href="{$url}">{$_page}</a></td> </tr> EOD; } if ($i == 0) { return $_xbel_msg['msg_zero']; } $rc .= <<<EOD </table> <div> <input type="submit" value="{$_xbel_msg['btn_exec']}" /> </div> </form> EOD; return $rc; }
function plugin_brokenlink_action() { global $vars, $_brokenlink_msg; $retval = array('msg' => $_brokenlink_msg['msg_title'], 'body' => ''); if (empty($vars['page'])) { $retval['body'] = $_brokenlink_msg['msg_param_error']; return $retval; } // ユーザ認証されていない $id = auth::check_auth(); if (empty($id)) { $retval['body'] = $_brokenlink_msg['msg_not_access']; return $retval; } if (!exist_plugin('xbel')) { $retval['body'] = $_brokenlink_msg['msg_not_found_xbel']; return $retval; } $links = xbel::get_link_list($vars['page']); $data = ''; foreach ($links as $href => $aname) { $rc = http_request($href, 'HEAD'); switch ($rc['rc']) { case 200: // Ok // Ok case 301: // Moved Permanently // Moved Permanently case 401: // Unauthorized continue; default: $data .= '-[[' . $aname . '>' . $href . ']] (' . $rc['rc'] . ")\n"; } } if ($data == '') { $data = $_brokenlink_msg['msg_all_ok']; } $retval['body'] = convert_html($data); return $retval; }
function passwd_menu($msg = ' ') { global $script, $head_tags, $_passwd_msg, $auth_type, $realm, $vars; $head_tags[] = ' <script type="text/javascript" src="' . SKIN_URI . 'crypt/md5.js"></script>'; $head_tags[] = ' <script type="text/javascript" src="' . SKIN_URI . 'crypt/sha1.js"></script>'; $head_tags[] = ' <script type="text/javascript" src="' . SKIN_URI . 'crypt/des.js"></script>'; $head_tags[] = ' <script type="text/javascript" src="' . SKIN_URI . 'crypt/base64.js"></script>'; $func = 'save'; $role_level = auth::get_role_level(); $old_algorithm = ''; $r_realm = rawurlencode($realm); $checked_md5 = 'checked="checked"'; $checked_sha1 = ''; // adminpass を求める処理の場合か? $is_adminpass = isset($vars['adminpass']); if ($is_adminpass) { $use_pkwk_write_func = false; $auth_type = 1; } else { $use_pkwk_write_func = USE_PKWK_WRITE_FUNC; } // 役割に応じた設定 if ($role_level == 2) { // 管理者 $disabled_user = $user = ''; $msg_pass = $_passwd_msg['msg_pass_admin']; $a1_des = "a1 = objForm.key.value;\n"; $msg_role = <<<EOD <tr> <th>{$_passwd_msg['role']}</th> <td> <select name="role"> <option value="">{$_passwd_msg['role_4']}</option> <option value="3">{$_passwd_msg['role_3']}</option> <option value="2">{$_passwd_msg['role_2']}</option> </select> </td> </tr> EOD; } else { // 一般ユーザ $disabled_user = '******'; // ゲスト時は、admin として一律生成できるようにしておく // $user = ($role_level == 0) ? 'admin' : auth::check_auth(); if ($role_level == 0) { $user = '******'; $msg_pass = $_passwd_msg['msg_pass_none']; $a1_des = "a1 = objForm.key.value;\n"; } else { $user = auth::check_auth(); $msg_pass = $_passwd_msg['msg_pass_old']; $old_algorithm = passwd_get_scheme($user); switch ($old_algorithm) { case 'md5': $checked_md5 = 'checked="checked"'; $checked_sha1 = ''; break; case 'sha1': $checked_md5 = ''; $checked_sha1 = 'checked="checked"'; break; } // $a1_des = 'a1 = objForm.username.value+\':' . $realm . ":'+objForm.key.value;\n"; $a1_des = 'a1 = objForm.username.value+\':\'+decodeURIComponent(objForm.realm.value)+\':\'+objForm.key.value;' . "\n"; } $func = 'update'; $msg_role = <<<EOD <tr> <th>{$_passwd_msg['role']}</th> <td> EOD; $msg_role .= passwd_get_role_name($role_level) . ' (' . $role_level . ')'; $msg_role .= <<<EOD </td> </tr> EOD; } $msg_username = <<<EOD <tr> <th>{$_passwd_msg['UserName']}</th> <td><input type="text" name="username" size="10" value="{$user}" {$disabled_user} /></td> </tr> EOD; switch ($auth_type) { case 1: // basic $pref = 'php'; $submit_sha1 = "objForm.submit.disabled = false;\n"; $a1 = "a1 = objForm.passwd.value;\n"; // basic の場合は上書きする $a1_des = "a1 = objForm.key.value;\n"; $disabled_sha1 = ''; // 書き込み禁止 または ゲスト時は、ユーザ名不要 if (!$use_pkwk_write_func || $role_level == 0) { $msg_username = ''; } break; case 2: default: // digest $pref = 'digest'; $submit_sha1 = ''; // $a1 = 'a1 = objForm.username.value+\':' . $realm . ":'+objForm.passwd.value;\n"; $a1 = 'a1 = objForm.username.value+\':\'+decodeURIComponent(objForm.realm.value)+\':\'+objForm.passwd.value;' . "\n"; $checked_md5 = 'checked="checked"'; $checked_sha1 = ''; $disabled_sha1 = 'disabled="disabled"'; } // プラグインによる書き込み制限の場合 // 使用する場合は、変更させることもコピーさせることも不要なので、抑止する // 更新ボタンすら表示しない if (!$use_pkwk_write_func || $role_level == 0) { $submit_sha1 = $submit_false = $submit_true = ''; $disabled_result = $msg_submit = $msg_role = ''; } else { // $submit_sha1 $submit_false = "objForm.submit.disabled = false;\n"; $submit_true = "objForm.submit.disabled = true;\n"; $disabled_result = 'disabled="disabled"'; $msg_submit = <<<EOD <tr> <td><input type="submit" name="submit" value="{$_passwd_msg['Update']}" disabled="disabled" /></td> </tr> EOD; } $x = <<<EOD <script type="text/javascript"> <!-- <![CDATA[ function set_hash() { var a1,ctr,pref,hash,des_key,hash_view,algorithm; var fn = function(){ switch(algorithm) { case 'sha1': {$submit_sha1} hash = hex_sha1(a1); pref = "{x-{$pref}-sha1}"; break; default: {$submit_false} hash = hex_md5(a1); pref = "{x-{$pref}-md5}"; } }; var objForm = eval("document.passwd"); {$submit_true} if (objForm.passwd.value == "") { objForm.hash.value = ""; objForm.algorithm.value = ""; objForm.key.value = ""; } else { ctr = objForm.scheme.length; for (i=0; i<ctr; i++) { if (objForm.scheme[i].checked) { objForm.algorithm.value = objForm.scheme[i].value; break; } } if (objForm.old_algorithm.value == "") { algorithm = objForm.algorithm.value; } else { algorithm = objForm.old_algorithm.value; } {$a1_des} fn(); des_key = hash; algorithm = objForm.algorithm.value; {$a1} fn(); hash_view = hash; objForm.hash.value = base64encode( des(des_key, hash, 1, 0) ); objForm.passwd.value = ""; objForm.key.value = ""; } if (objForm.hash.value == "") { objForm.hash_view.value = ""; } else { objForm.hash_view.value = pref+hash_view; } } //]]>--> </script> <h2>passwd</h2> <div>{$msg}</div> <form name="passwd" action="{$script}" method="post"> <input type="hidden" name="plugin" value="passwd" /> <input type="hidden" name="func" value="{$func}" /> <input type="hidden" name="algorithm" /> <input type="hidden" name="old_algorithm" value="{$old_algorithm}"/> <input type="hidden" name="hash" /> <input type="hidden" name="realm" value="{$r_realm}"/> <table class="indented"> {$msg_username} <tr> <th>{$_passwd_msg['Passwd']}</th> <td><input type="password" name="passwd" size="10" /> {$_passwd_msg['msg_pass_new']}</td> </tr> <tr> <th>{$_passwd_msg['Crypt']}</th> <td><input type="password" name="key" size="10" /> {$msg_pass}</td> </tr> {$msg_role} <tr> <th>{$_passwd_msg['Calculate']}</th> <td> <input type="radio" name="scheme" value="md5" {$checked_md5} /> <label>MD5</label> <input type="radio" name="scheme" value="sha1" {$checked_sha1} {$disabled_sha1} /> <label>SHA-1</label> <input type="button" onclick="set_hash()" value="{$_passwd_msg['CALC']}" /> </td> </tr> <tr> <th>{$_passwd_msg['Result']}</th> <td><input type="text" name="hash_view" size="80" {$disabled_result} /></td> </tr> {$msg_submit} </table> </form> EOD; return $x; }
function get_existpages($dir = DATA_DIR, $ext = '.txt') { $rc = array(); // ページ名の取得 $pages = get_existpages($dir, $ext); // ユーザ名取得 $uname = auth::check_auth(); // コンテンツ管理者以上は、: のページも閲覧可能 $is_colon = auth::check_role('role_adm_contents'); // 役割の取得 // $now_role = auth::get_role_level(); foreach ($pages as $file => $page) { if (!auth::is_page_readable($uname, $page)) { continue; } if (substr($page, 0, 1) != ':') { $rc[$file] = $page; continue; } // colon page if ($is_colon) { continue; } $rc[$file] = $page; } return $rc; }
function htdigest_menu($msg = ' ') { global $script, $realm, $head_tags, $_htdigest_msg; $head_tags[] = ' <script type="text/javascript" src="' . SKIN_URI . 'crypt/md4.js"></script>'; $head_tags[] = ' <script type="text/javascript" src="' . SKIN_URI . 'crypt/md5.js"></script>'; $head_tags[] = ' <script type="text/javascript" src="' . SKIN_URI . 'crypt/sha1.js"></script>'; $head_tags[] = ' <script type="text/javascript" src="' . SKIN_URI . 'crypt/des.js"></script>'; $head_tags[] = ' <script type="text/javascript" src="' . SKIN_URI . 'crypt/base64.js"></script>'; // 使用する場合は、変更させることもコピーさせることも不要なので、抑止する $disabled = USE_APACHE_WRITE_FUNC ? 'disabled="disabled"' : ''; $func = 'save'; $role_level = auth::get_role_level(); if ($role_level > 2) { $user_disabled = 'disabled="disabled"'; $user = auth::check_auth(); $func = 'update'; $msg_pass = $_htdigest_msg['msg_pass_old']; } else { $user_disabled = $user = ''; $msg_pass = $role_level == 2 ? $_htdigest_msg['msg_pass_admin'] : ''; } $x = <<<EOD <script type="text/javascript"> <!-- <![CDATA[ function set_hash() { var a1,ctr,pref,hash,des_key; var fn = function(){ switch(objForm.algorithm.value) { case 'MD4': hash = hex_md4(a1); break; case 'SHA-1': hash = hex_sha1(a1); break; default: objForm.submit.disabled = false; hash = hex_md5(a1); } }; var objForm = eval("document.htdigest"); objForm.submit.disabled = true; if (objForm.passwd.value == "" || objForm.key.value == "") { objForm.hash.value = ""; objForm.algorithm.value = ""; } else { ctr = objForm.scheme.length; for (i=0; i<ctr; i++) { if (objForm.scheme[i].checked) { objForm.algorithm.value = objForm.scheme[i].value; break; } } EOD; if ($role_level > 2) { // a1 $x .= "a1 = objForm.username.value+':'+objForm.realm.value+':'+objForm.key.value;\n"; } else { // adminpass $x .= "a1 = objForm.key.value;\n"; } $x .= <<<EOD fn(); des_key = hash; a1 = objForm.username.value+':'+objForm.realm.value+':'+objForm.passwd.value; fn(); objForm.hash.value = base64encode( des(des_key, hash, 1, 0) ); objForm.passwd.value = ""; } if (objForm.hash.value == "") { objForm.hash_view.value = ""; } else { objForm.hash_view.value = objForm.username.value+':'+objForm.realm.value+':'+hash; } } //]]>--> </script> <h2>htdigest</h2> <div>{$msg}</div> <form name="htdigest" action="{$script}" method="post"> <input type="hidden" name="plugin" value="htdigest" /> <input type="hidden" name="func" value="{$func}" /> <input type="hidden" name="algorithm" /> <input type="hidden" name="hash" /> <table class="indented"> <tr> <th>{$_htdigest_msg['realm']}</th> <td><input type="text" name="realm" size="30" value="{$realm}" /></td> </tr> <tr> <th>{$_htdigest_msg['UserName']}</th> <td><input type="text" name="username" size="10" value="{$user}" {$user_disabled} /></td> </tr> <tr> <th>{$_htdigest_msg['Passwd']}</th> <td><input type="password" name="passwd" size="10" /> {$_htdigest_msg['msg_pass_new']}</td> </tr> <tr> <th>{$_htdigest_msg['Crypt']}</th> <td><input type="password" name="key" size="10" /> {$msg_pass}</td> </tr> <tr> <th>{$_htdigest_msg['Calculate']}</th> <td> <input type="radio" name="scheme" value="MD5" checked="checked" /> <label>MD5</label> <input type="radio" name="scheme" value="SHA-1" /> <label>SHA-1</label> <input type="radio" name="scheme" value="MD4" /> <label>MD4</label> <input type="button" onclick="set_hash()" value="{$_htdigest_msg['CALC']}" /> </td> </tr> <tr> <th>{$_htdigest_msg['Result']}</th> <td><input type="text" name="hash_view" size="80" {$disabled} /></td> </tr> <tr> <td><input type="submit" name="submit" value="{$_htdigest_msg['Update']}" disabled="disabled" /></td> </tr> </table> </form> EOD; return $x; }
/** * ログの表示指示項目の設定 * @static */ function get_view_field($kind) { global $log; $rc = log::set_fieldname($kind); // 認証済の判定 $user = auth::check_auth(); $kind_view = empty($user) ? 'guest' : 'view'; if ($log[$kind][$kind_view] == 'all') { return $rc; } $tmp = explode(':', $log[$kind][$kind_view]); // 妥当性チェック $chk = array(); foreach ($tmp as $_tmp) { $sw = 0; foreach ($rc as $_name) { if ($_name == $_tmp) { $sw = 1; break; } } if (!$sw) { continue; } $chk[] = $_tmp; } unset($tmp, $sw); return $chk; }
function check_role($func = '') { global $adminpass; switch ($func) { case 'readonly': $chk_role = defined('PKWK_READONLY') ? PKWK_READONLY : ROLE_GUEST; break; case 'safemode': $chk_role = defined('PKWK_SAFE_MODE') ? PKWK_SAFE_MODE : ROLE_GUEST; break; case 'su': $now_role = auth::get_role_level(); if ($now_role == 2 || (int) $now_role == ROLE_ADM_CONTENTS) { return FALSE; } // 既に権限有 $chk_role = ROLE_ADM_CONTENTS; switch ($now_role) { case ROLE_AUTH_TEMP: // FIXME: return TRUE; case ROLE_GUEST: // 未認証者は、単に管理者パスワードを要求 $user = UNAME_ADM_CONTENTS_TEMP; break; case ROLE_ENROLLEE: case ROLE_AUTH: // 認証済ユーザは、ユーザ名を維持しつつ管理者パスワードを要求 $user = auth::check_auth(); break; } $auth_temp = array($user => array($adminpass)); while (1) { if (!auth::auth_pw($auth_temp)) { unset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); header('WWW-Authenticate: Basic realm="USER NAME is ' . $user . '"'); header('HTTP/1.0 401 Unauthorized'); break; } // ESC : 認証失敗 return TRUE; } break; case 'role_adm': $chk_role = ROLE_ADM; break; case 'role_adm_contents': $chk_role = ROLE_ADM_CONTENTS; break; case 'role_enrollee': $chk_role = ROLE_ENROLLEE; break; case 'role_auth': $chk_role = ROLE_AUTH; break; default: $chk_role = ROLE_GUEST; } return auth::is_check_role($chk_role); }
/** * アクションプラグイン処理 */ 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); }