/** * お気にスレをセットする関数 * * $setfav は、'0'(解除), '1'(追加), 'top', 'up', 'down', 'bottom' * * @access public * @return boolean */ function setFav($host, $bbs, $key, $setfav) { global $_conf; if (P2Validate::host($host) || P2Validate::bbs($bbs) || P2Validate::key($key)) { return false; } // スレッド.idx 記録 $data = _setFavToKeyIdx($host, $bbs, $key, $setfav); $newlines = array(); $before_line_num = 0; if (false === FileCtl::make_datafile($_conf['favlist_file'], $_conf['favlist_perm'])) { return false; } if (false === ($favlines = file($_conf['favlist_file']))) { return false; } // 最初に重複要素を削除しておく if (!empty($favlines)) { $i = -1; foreach ($favlines as $line) { $i++; $line = rtrim($line); $lar = explode('<>', $line); // 重複回避 if ($lar[1] == $key && $lar[11] == $bbs) { $before_line_num = $i; // 移動前の行番号をセット continue; // keyのないものは不正データなのでスキップ } elseif (!$lar[1]) { continue; } elseif (P2Validate::host($lar[10]) || P2Validate::bbs($lar[11]) || P2Validate::key($lar[1])) { continue; } else { $newlines[] = $line; } } } if (!empty($GLOBALS['brazil'])) { //$newlines = _removeLargeFavlistData($newlines); } // 記録データ設定 if ($setfav) { $newdata = implode('<>', array(geti($data[0]), $key, geti($data[2]), geti($data[3]), geti($data[4]), geti($data[5]), 1, geti($data[7]), geti($data[8]), geti($data[9]), $host, $bbs)); require_once P2_LIB_DIR . '/getSetPosLines.func.php'; $rec_lines = getSetPosLines($newlines, $newdata, $before_line_num, $setfav); } else { $rec_lines = $newlines; } if (false === file_put_contents($_conf['favlist_file'], $rec_lines ? implode("\n", $rec_lines) . "\n" : '', LOCK_EX)) { trigger_error(sprintf('file_put_contents(%s)', $_conf['favlist_file']), E_USER_WARNING); return false; } // お気にスレ共有 _setFavRank($host, $bbs, $key, $setfav, geti($data[0])); return true; }
exit; } //================================================================== // 変数 //================================================================== $GLOBALS['rnum_all_range'] = $_conf['k_rnum_range']; $GLOBALS['word'] = null; $sb_view = "shinchaku"; $newtime = date("gis"); $host = geti($_GET['host'], geti($_POST['host'])); $bbs = geti($_GET['bbs'], geti($_POST['bbs'])); $spmode = geti($_GET['spmode'], geti($_POST['spmode'])); if ((!$host || !isset($bbs)) && !isset($spmode)) { p2die('必要な引数が指定されていません'); } if ($host && P2Validate::host($host) || $bbs && P2Validate::bbs($bbs) || $spmode && P2Validate::spmode($spmode)) { p2die('不正な引数です'); } $hr = P2View::getHrHtmlK(); //==================================================================== // メイン //==================================================================== register_shutdown_function('saveMatomeCache'); $GLOBALS['_read_new_html'] = ''; ob_start(); $aThreadList = new ThreadList(); // 板とモードのセット if ($spmode) { if ($spmode == "taborn" or $spmode == "soko") { $aThreadList->setIta($host, $bbs, P2Util::getItaName($host, $bbs)); }
/** * スレッドを指定する * * @return array|false */ function _detectThread() { global $_conf; $ls = null; $url = null; // スレURLの直接指定 if (($url = geti($_GET['nama_url'])) || ($url = geti($_GET['url']))) { $url = trim($url); // 2ch or pink http://choco.2ch.net/test/read.cgi/event/1027770702/ if (preg_match('{http://([^/]+\\.(2ch\\.net|bbspink\\.com|machibbs\\.com|machi\\.to))/test/read\\.cgi/([^/]+)/([0-9]+)/?([^/]+)?}', $url, $matches)) { $host = $matches[1]; $bbs = $matches[3]; $key = $matches[4]; $ls = geti($matches[5]); // c-docomo c-au c-other http://c-au.2ch.net/test/--3!mail=sage/operate/1159594301/519-n } elseif (preg_match('{http://((c-docomo|c-au|c-other)\\.2ch\\.net)/test/([^/]+)/([^/]+)/([0-9]+)/?([^/]+)?}', $url, $m)) { require_once P2_LIB_DIR . '/BbsMap.php'; if ($mapped_host = BbsMap::get2chHostByBbs($m[4])) { $host = $mapped_host; $bbs = $m[4]; $key = $m[5]; $ls = geti($m[6]); } // 2ch, pink, vip2ch.com 過去ログhtml - http://pc.2ch.net/mac/kako/1015/10153/1015358199.html } elseif (preg_match('{(http://([^/]+\\.(2ch\\.net|bbspink\\.com|vip2ch\\.com))(/[^/]+)?/([^/]+)/kako/\\d+(/\\d+)?/(\\d+)).html}', $url, $matches)) { $host = $matches[2]; $bbs = $matches[5]; $key = $matches[7]; $kakolog_uri = $matches[1]; $_GET['kakolog'] = $kakolog_uri; // 新まちBBS http://tohoku.machi.to/bbs/read.cgi/touhoku/1179407635/l50 } elseif (preg_match('{http://([^/]+\\.(2ch\\.net|bbspink\\.com|machibbs\\.com|machi\\.to))/bbs/read\\.cgi/([^/]+)/([0-9]+)/?([^/]+)?}', $url, $matches)) { $host = $matches[1]; $bbs = $matches[3]; $key = $matches[4]; $ls = geti($matches[5]); // (旧)まちBBS http://kanto.machibbs.com/bbs/read.pl?BBS=kana&KEY=1034515019 } elseif (preg_match('{http://([^/]+\\.machibbs\\.com|[^/]+\\.machi\\.to)/bbs/read\\.(pl|cgi)\\?BBS=([^&]+)&KEY=([0-9]+)(&START=([0-9]+))?(&END=([0-9]+))?[^\\"]*}', $url, $matches)) { $host = $matches[1]; $bbs = $matches[3]; $key = $matches[4]; $ls = geti($matches[6]) . '-' . geti($matches[8]); // したらばJBBS(旧まちBBSと類似形式) } elseif (preg_match('{http://((jbbs\\.livedoor\\.jp|jbbs\\.livedoor.com|jbbs\\.shitaraba\\.com)(/[^/]+)?)/bbs/read\\.(pl|cgi)\\?BBS=([^&]+)&KEY=([0-9]+)(&START=([0-9]+))?(&END=([0-9]+))?[^"]*}', $url, $matches)) { $host = $matches[1]; $bbs = $matches[5]; $key = $matches[6]; $ls = geti($matches[8]) . '-' . geti($matches[10]); // したらばJBBS(2ch類似形式) http://jbbs.livedoor.com/bbs/read.cgi/computer/2999/1081177036/-100 } elseif (preg_match('{http://(jbbs\\.livedoor\\.jp|jbbs\\.livedoor.com|jbbs\\.shitaraba\\.com)/bbs/read\\.cgi/(\\w+)/(\\d+)/(\\d+)/((\\d+)?-(\\d+)?)?[^"]*}', $url, $matches)) { $host = $matches[1] . '/' . $matches[2]; $bbs = $matches[3]; $key = $matches[4]; $ls = geti($matches[5]); // チャットちゃんねる http://cha2.net/cgi-bin/test/read.cgi/anitoku/1241688251/l50 } elseif (preg_match('{http://(cha2\\.net)/cgi-bin/test/read\\.cgi/(\\w+)/(\\d+)/?([^/]+)?}', $url, $matches)) { $host = $matches[1]; $bbs = $matches[2]; $key = $matches[3]; $ls = geti($matches[4]); // 外部板 read.cgi 形式 http://ex14.vip2ch.com/test/read.cgi/operate/1161701941/ } elseif (preg_match('{http://([^/]+)/test/read\\.cgi/(\\w+)/(\\d+)/?([^/]+)?}', $url, $matches)) { $host = $matches[1]; $bbs = $matches[2]; $key = $matches[3]; $ls = geti($matches[4]); } } else { !empty($_GET['host']) and $host = $_GET['host']; // "pc.2ch.net" !empty($_POST['host']) and $host = $_POST['host']; isset($_GET['bbs']) and $bbs = $_GET['bbs']; // "php" isset($_POST['bbs']) and $bbs = $_POST['bbs']; isset($_GET['key']) and $key = $_GET['key']; // "1022999539" isset($_POST['key']) and $key = $_POST['key']; !empty($_GET['ls']) and $ls = $_GET['ls']; // "all" !empty($_POST['ls']) and $ls = $_POST['ls']; } if (empty($host) || !isset($bbs) || !isset($key)) { $err = $_conf['read_php'] . ' スレッドの指定が変です。'; $msg = null; if ($url) { if (preg_match('/^http/', $url)) { $msg = sprintf('<a href="%1$s">%1$s</a>', hs($url)); } else { $msg = hs($url); } } p2die($err, $msg); } if (P2Validate::host($host) || P2Validate::bbs($bbs) || P2Validate::key($key)) { p2die('不正な引数です'); } return array($host, $bbs, $key, $ls); }
//================================================================ // 変数設定 //================================================================ isset($_GET['host']) and $host = $_GET['host']; // "pc.2ch.net" isset($_GET['bbs']) and $bbs = $_GET['bbs']; // "php" isset($_GET['key']) and $key = $_GET['key']; // "1022999539" $ttitle_en = isset($_GET['ttitle_en']) ? $_GET['ttitle_en'] : null; // $_GET['popup'] 0(false), 1(true), 2(true, クローズタイマー付) // 以下どれか一つがなくてもダメ出し if (!$host || !isset($bbs) || !isset($key)) { p2die('引数が正しくありません。(host or bbs or key)'); } if (P2Validate::host($host) || P2Validate::bbs($bbs) || P2Validate::key($key)) { p2die('不正な引数です。(host or bbs or key)'); } $title_msg = ''; $info_msg = ''; //================================================================ // 特別な前処理 //================================================================ // {{{ 削除 if (!empty($_GET['dele'])) { $r = deleteLogs($host, $bbs, array($key)); if (!$r) { $title_msg = "× ログ削除失敗"; $info_msg = "× ログ削除失敗"; } elseif ($r == 1) { $title_msg = "○ ログ削除完了";
/** * お気に板をセットする関数 * * $setfavita は、0(解除), 1(追加), top, up, down, bottom * * @access public * @return boolean */ function setFavIta() { global $_conf; // {{{ パラメータの設定 if (isset($_GET['setfavita'])) { $setfavita = $_GET['setfavita']; } elseif (isset($_POST['setfavita'])) { $setfavita = $_POST['setfavita']; } $host = isset($_GET['host']) ? $_GET['host'] : NULL; $bbs = isset($_GET['bbs']) ? $_GET['bbs'] : NULL; if (isset($setfavita) && !preg_match('/^[a-zA-Z0-9]+$/', $setfavita)) { P2Util::pushInfoHtml('<p>p2 info: 不正な引数です(setfavita)'); return false; } if (isset($host) && P2Validate::host($host) || isset($bbs) && P2Validate::bbs($bbs)) { P2Util::pushInfoHtml("<p>p2 info: 板の指定が変です</p>"); return false; } if (!empty($_POST['url'])) { if (preg_match("/http:\\/\\/(.+)\\/([^\\/]+)\\/([^\\/]+\\.html?)?/", $_POST['url'], $matches)) { $host = preg_replace('{/test/read\\.cgi$}', '', $matches[1]); $bbs = $matches[2]; } else { P2Util::pushInfoHtml(sprintf("<p>p2 info: 「%s」は板のURLとして無効です。</p>", hs($_POST['url']))); } } $list = isset($_POST['list']) ? $_POST['list'] : ''; // リストで並び替え if (!empty($_POST['submit_listfavita'])) { if (!$list) { P2Util::pushInfoHtml("<p>p2 info: リストの指定が変です</p>"); return false; } } else { // 新規追加 or 一つずつ並び替え if (!$host || !$bbs) { P2Util::pushInfoHtml("<p>p2 info: 板の指定が変です</p>"); return false; } } $itaj = isset($_POST['itaj']) ? $_POST['itaj'] : ''; if (!$itaj && isset($_GET['itaj_en'])) { $itaj = base64_decode($_GET['itaj_en']); } !$itaj and $itaj = $bbs; // }}} //================================================ // 処理 //================================================ if (false === FileCtl::make_datafile($_conf['favita_path'], $_conf['favita_perm'])) { return false; } if (false === ($lines = file($_conf['favita_path']))) { return false; } $neolines = array(); $before_line_num = 0; // 最初に重複要素を消去しておく if ($lines) { $i = -1; $avoided = false; foreach ($lines as $l) { $i++; $l = rtrim($l); // {{{ 旧データ(ver0.6.0以下)移行措置 if (!preg_match("/^\t/", $l)) { $l = "\t" . $l; } // }}} $lar = explode("\t", $l); if (!$avoided and $lar[1] == $host && $lar[2] == $bbs) { // 重複回避 $avoided = true; $before_line_num = $i; continue; } elseif (!$lar[1] || !$lar[2]) { // 不正データ(host, bbsなし)もアウト continue; } elseif (P2Validate::host($lar[1]) || P2Validate::bbs($lar[2])) { continue; } else { $neolines[] = $l; } } } // 記録データ設定 // リスト丸ごとポストして指定 if (!empty($_POST['submit_listfavita']) && $list) { $rec_lines = array(); foreach (explode(',', $list) as $aList) { list($host, $bbs, $itaj_en) = array_map('rawurldecode', explode('@', $aList, 3)); $itaj = base64_decode($itaj_en); $rec_lines[] = "\t{$host}\t{$bbs}\t" . $itaj; } P2Util::pushInfoHtml("<script language=\"javascript\">if (parent.menu) { parent.menu.location.href='{$_conf['menu_php']}?nr=1'; }</script>"); // 一つのデータを指定して操作 } elseif ($setfavita and $host && $bbs && $itaj) { $newdata = "\t{$host}\t{$bbs}\t{$itaj}"; require_once P2_LIB_DIR . '/getSetPosLines.func.php'; $rec_lines = getSetPosLines($neolines, $newdata, $before_line_num, $setfavita); // 解除 } else { $rec_lines = $neolines; } $cont = ''; if (!empty($rec_lines)) { foreach ($rec_lines as $l) { $cont .= $l . "\n"; } } // 書き込む if (false === file_put_contents($_conf['favita_path'], $cont, LOCK_EX)) { trigger_error("file_put_contents(" . $_conf['favita_path'] . ")", E_USER_WARNING); die('Error: cannot write file.'); return false; } return true; }
if (!isset($_POST['csrfid']) or $_POST['csrfid'] != P2Util::getCsrfId()) { p2die('ページ遷移の妥当性を確認できませんでした。(CSRF対策)', '投稿フォームを読み込み直してから、改めて投稿してください。'); } //================================================================ // 変数 //================================================================ $newtime = date('gis'); $post_keys = array('FROM', 'mail', 'MESSAGE', 'bbs', 'key', 'time', 'host', 'popup', 'rescount', 'subject', 'submit', 'sub', 'ttitle_en'); foreach ($post_keys as $pk) { ${$pk} = isset($_POST[$pk]) ? $_POST[$pk] : null; } // 引数エラー if (empty($host)) { p2die('引数の指定が変です'); } if (P2Validate::host($host) || $bbs && P2Validate::bbs($bbs) || $key && P2Validate::host($key)) { p2die('不正な引数です'); } if ($bbs and _isThreTateSugi()) { p2die('スレ立て杉です(しばし待たれよ)'); } $_conf['last_post_time_file'] = $_conf['pref_dir'] . '/last_post_time.txt'; if (P2Util::isHost2chs($host)) { $server_id = preg_replace('{\\.2ch\\.net$}', '', $host); $_conf['last_post_time_file'] = P2Util::idxDirOfHost($host, true) . rawurlencode($server_id) . '_' . 'last_post_time.txt'; } if (!isset($ttitle)) { if ($ttitle_en) { $ttitle = base64_decode($ttitle_en); } elseif ($subject) { $ttitle = $subject;
/** * 2ch●ログインのIDとPASSと自動ログイン設定を保存する * * @access public * @return boolean */ function saveIdPw2ch($login2chID, $login2chPW, $autoLogin2ch = 0) { global $_conf; require_once P2_LIB_DIR . '/md5_crypt.funcs.php'; // 念のため、ここでも不正な文字列は弾いておく require_once P2_LIB_DIR . '/P2Validate.php'; // 2ch ID (メアド) if ($login2chID and $errmsg = P2Validate::mail($login2chID)) { //P2Util::pushInfoHtml('<p>p2 error: 使用できないID文字列が含まれています</p>'); trigger_error($errmsg, E_USER_WARNING); return false; } // 正確な許可文字列は不明 if ($login2chPW and $errmsg = P2Validate::login2chPW($login2chPW)) { //P2Util::pushInfoHtml('<p>p2 error: 使用できないパスワード文字列が含まれています</p>'); trigger_error($errmsg, E_USER_WARNING); return false; } $autoLogin2ch = intval($autoLogin2ch); $crypted_login2chPW = md5_encrypt($login2chPW, P2Util::getMd5CryptPass()); $idpw2ch_cont = <<<EOP <?php \$rec_login2chID = '{$login2chID}'; \$rec_login2chPW = '{$crypted_login2chPW}'; \$rec_autoLogin2ch = '{$autoLogin2ch}'; ?> EOP; FileCtl::make_datafile($_conf['idpw2ch_php'], $_conf['pass_perm']); if (false === file_put_contents($_conf['idpw2ch_php'], $idpw2ch_cont, LOCK_EX)) { p2die('データを更新できませんでした'); return false; } return true; }
require_once P2_LIB_DIR . '/P2Validate.php'; $_login->authorize(); // ユーザ認証 //================================================================ // 変数 //================================================================ $login2chID = geti($_POST['login2chID']); $login2chPW = geti($_POST['login2chPW']); $autoLogin2ch = intval(geti($_POST['autoLogin2ch'])); // 2ch ID (メアド) if ($login2chID and P2Validate::mail($login2chID)) { P2Util::pushInfoHtml('<p>p2 error: 使用できないID文字列が含まれています</p>'); $login2chID = null; } // 正確な許可文字列は不明 if ($login2chPW and P2Validate::login2chPW($login2chPW)) { P2Util::pushInfoHtml('<p>p2 error: 使用できないパスワード文字列が含まれています</p>'); $login2chPW = null; } //=============================================================== // ログインなら、IDとPWを登録保存して、ログインする //=============================================================== if ($login2chID && $login2chPW) { P2Util::saveIdPw2ch($login2chID, $login2chPW, $autoLogin2ch); require_once P2_LIB_DIR . '/login2ch.func.php'; login2ch(); } // (フォーム入力用に)ID, PW設定を読み込む if ($array = P2Util::readIdPw2ch()) { list($login2chID, $login2chPW, $autoLogin2ch) = $array; }