svnno****@sourc*****
svnno****@sourc*****
2010年 1月 3日 (日) 02:13:28 JST
Revision: 761 http://sourceforge.jp/projects/p2-php/svn/view?view=rev&revision=761 Author: rsk Date: 2010-01-03 02:13:28 +0900 (Sun, 03 Jan 2010) Log Message: ----------- expack: - å ¬å¼p2ã使ã£ãæ¸ãè¾¼ã¿ã§ãCookie確èªããã£ãå ´åã®å¦çãæ¹åã - ãBEã§æ¸ãè¾¼ããæ©è½ã使ããªããªã£ã¦ããã®ãä¿®æ£ã -- èªåã®rep2ã¨å ¬å¼p2ã®ä¸¡æ¹ã«BEã®è¨å®ããã¦ããã°ãå ¬å¼p2+BE㧠æ¸ãè¾¼ããã¨ãã§ããããã®éãBEã¢ã«ã¦ã³ãã¯å ¬å¼p2ã«ç»é²ã㦠ãããã®ã使ãããã - GETãªã¯ã¨ã¹ãã«ããRSSãªã¹ãã®ç·¨éãã§ããªãã£ãã®ãä¿®æ£ã Modified Paths: -------------- p2ex/trunk/editrss.php p2ex/trunk/lib/P2Client.php p2ex/trunk/lib/P2Util.php p2ex/trunk/lib/ThreadRead.php p2ex/trunk/lib/expack/rss/common.inc.php p2ex/trunk/lib/expack/rss/parser.inc.php p2ex/trunk/lib/expack/rss/setrss.inc.php p2ex/trunk/lib/post_form.inc.php p2ex/trunk/read_rss.php p2ex/trunk/subject_rss.php -------------- next part -------------- Modified: p2ex/trunk/editrss.php =================================================================== --- p2ex/trunk/editrss.php 2010-01-02 07:46:50 UTC (rev 760) +++ p2ex/trunk/editrss.php 2010-01-02 17:13:28 UTC (rev 761) @@ -10,6 +10,7 @@ // Ï ============= $_info_msg_ht = ''; +$editrss_php_ht = htmlspecialchars($_SERVER['SCRIPT_NAME'], ENT_QUOTES); //================================================================ //ÁêÈOu @@ -25,7 +26,7 @@ // RSSÇÁtH[ $add_rss_form_ht = <<<EOFORM <hr> -<form method="POST" action="{$_SERVER['SCRIPT_NAME']}" accept-charset="{$_conf['accept_charset']}" target="_self"> +<form method="POST" action="{$editrss_php_ht}" accept-charset="{$_conf['accept_charset']}" target="_self"> <input type="hidden" id="setrss" name="setrss" value="1"> <table border="0" cellspacing="1" cellpadding="0"> <tr> @@ -239,7 +240,7 @@ $script_enable_html .= <<<EOP RSSÌÀÑÖ¦ihbOAhhbvj <div class="itas"> -<form id="form" name="form" method="post" action="{$_SERVER['SCRIPT_NAME']}" accept-charset="{$_conf['accept_charset']}" target="_self"> +<form id="form" name="form" method="post" action="{$editrss_php_ht}" accept-charset="{$_conf['accept_charset']}" target="_self"> <table border="0"> <tr> @@ -299,6 +300,7 @@ if (count($p) > 1) { $site = $p[0]; $xml = $p[1]; + $xml_en = rawurlencode($xml); if (isset($p[2]) && $p[2] == 1) { $atom = 1; $atom_ht = '&atom=1'; @@ -310,18 +312,16 @@ $type_ht = 'RSS'; $cngtype_ht = '&setrss=atom'; } - $site_en = rawurlencode(base64_encode($site)); - $site_ht = "&site_en=".$site_en; - $xml_en = rawurlencode($xml); + $site_ht = '&site_en=' . rawurlencode(base64_encode($site)); echo <<<EOP <tr> - <td><a href="{$_SERVER['SCRIPT_NAME']}?xml={$xml_en}&setrss=0" class="fav"></a></td> + <td><a href="{$editrss_php_ht}?xml={$xml_en}&setrss=0" class="fav"></a></td> <td><a href="subject_rss.php?xml={$xml_en}{$site_ht}{$atom_ht}">{$site}</a></td> - <td>(<a class="te" href="{$_SERVER['SCRIPT_NAME']}?xml={$xml_en}{$site_ht}{$cngtype_ht}">{$type_ht}</a>)</td> - <td>[ <a class="te" href="{$_SERVER['SCRIPT_NAME']}?xml={$xml_en}{$site_ht}{$atom_ht}&setrss=top">£</a></td> - <td><a class="te" href="{$_SERVER['SCRIPT_NAME']}?xml={$xml_en}{$site_ht}{$atom_ht}&setrss=up">ª</a></td> - <td><a class="te" href="{$_SERVER['SCRIPT_NAME']}?xml={$xml_en}{$site_ht}{$atom_ht}&setrss=down">«</a></td> - <td><a class="te" href="{$_SERVER['SCRIPT_NAME']}?xml={$xml_en}{$site_ht}{$atom_ht}&setrss=bottom">¥</a> ]</td> + <td>(<a class="te" href="{$editrss_php_ht}?xml={$xml_en}{$site_ht}{$cngtype_ht}">{$type_ht}</a>)</td> + <td>[ <a class="te" href="{$editrss_php_ht}?xml={$xml_en}{$site_ht}{$atom_ht}&setrss=top">£</a></td> + <td><a class="te" href="{$editrss_php_ht}?xml={$xml_en}{$site_ht}{$atom_ht}&setrss=up">ª</a></td> + <td><a class="te" href="{$editrss_php_ht}?xml={$xml_en}{$site_ht}{$atom_ht}&setrss=down">«</a></td> + <td><a class="te" href="{$editrss_php_ht}?xml={$xml_en}{$site_ht}{$atom_ht}&setrss=bottom">¥</a> ]</td> </tr>\n EOP; } Modified: p2ex/trunk/lib/P2Client.php =================================================================== --- p2ex/trunk/lib/P2Client.php 2010-01-02 07:46:50 UTC (rev 760) +++ p2ex/trunk/lib/P2Client.php 2010-01-02 17:13:28 UTC (rev 761) @@ -45,8 +45,14 @@ const REQUEST_PARAMETER_MESSAGE = 'MESSAGE'; const REQUEST_PARAMETER_POPUP = 'popup'; const REQUEST_PARAMETER_BERES = 'submit_beres'; + const REQUEST_PARAMETER_CHARACTER_SET_DETECTION_HINT = 'detect_hint'; /** + * HTTPNGXgÌÅèp[^ + */ + const REQUEST_DATA_CHARACTER_SET_DETECTION_HINT = ''; + + /** * ÇÝݳۻè̽ß̶ñ */ const NEEDLE_READ_NO_THREAD = '<b>p2 info - ÂT[o©çÅVÌXbhîñðæ¾Å«Ü¹ñŵ½B</b>'; @@ -159,11 +165,13 @@ * @param array $data * @param P2DOM $dom * @param DOMElement $form - * @return array HTTPX|X + * @param mixed &$response + * @return bool * @throws P2Exception */ public function login($uri = null, array $data = array(), - P2DOM $dom = null, DOMElement $form = null) + P2DOM $dom = null, DOMElement $form = null, + &$response = null) { if ($uri === null) { $uri = self::P2_ROOT_URI; @@ -172,6 +180,7 @@ if ($dom === null) { $response = $this->httpGet($uri); $dom = new P2DOM($response['body']); + $form = null; } if ($form === null) { @@ -189,7 +198,9 @@ $postData[self::REQUEST_PARAMETER_LOGIN_ID] = rawurlencode($this->_loginId); $postData[self::REQUEST_PARAMETER_LOGIN_PASS] = rawurlencode($this->_loginPass); - return $this->httpPost($uri, $postData, true); + $response = $this->httpPost($uri, $postData, true); + + return $this->getLoginForm(new P2DOM($response['body'])) === null; } // }}} @@ -219,9 +230,7 @@ $dom = new P2DOM($response['body']); if ($form = $this->getLoginForm($dom)) { - $response = $this->login($uri, $getData, $dom, $form); - $dom = new P2DOM($response['body']); - if ($this->getLoginForm($dom)) { + if (!$this->login($uri, $getData, $dom, $form, $response)) { throw new P2Exception('Login failed.'); } } @@ -327,16 +336,18 @@ // CookiemFãÌPOSTÅ̶»¯\hÌ½ß // URLGR[hÏÝÌlðpӵĨ¢ÄÄãü·éB + $hintEncoded = rawurlencode(self::REQUEST_DATA_CHARACTER_SET_DETECTION_HINT); $nameEncoded = rawurlencode($name); $mailEncoded = rawurlencode($mail); $messageEncoded = rawurlencode($message); // POST·éf[^ðpÓB $postData = $this->getFormValues($dom, $form); - $postData[self::REQUEST_PARAMETER_POPUP] = '1'; + $postData[self::REQUEST_PARAMETER_CHARACTER_SET_DETECTION_HINT] = $hintEncoded; $postData[self::REQUEST_PARAMETER_NAME] = $nameEncoded; $postData[self::REQUEST_PARAMETER_MAIL] = $mailEncoded; $postData[self::REQUEST_PARAMETER_MESSAGE] = $messageEncoded; + $postData[self::REQUEST_PARAMETER_POPUP] = '1'; if ($beRes) { $postData[self::REQUEST_PARAMETER_BERES] = '1'; } elseif (array_key_exists(self::REQUEST_PARAMETER_BERES, $postData)) { @@ -348,15 +359,21 @@ // CookiemFÌêÍÄPOSTB if (preg_match(self::REGEX_POST_COOKIE, $response['body'])) { - $dom = new P2DOM($response['body']); + $html = str_replace('<META http-equiv="Content-Type" content="text/html; charset=x-sjis">', + '<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">', + $response['body']); + $dom = new P2DOM($html); $expression = './/form[contains(@action, "' . self::SCRIPT_NAME_POST . '")]'; $result = $dom->query($expression); if ($result instanceof DOMNodeList && $result->length > 0) { $postData = $this->getFormValues($dom, $result->item(0)); + $postData[self::REQUEST_PARAMETER_CHARACTER_SET_DETECTION_HINT] = $hintEncoded; $postData[self::REQUEST_PARAMETER_NAME] = $nameEncoded; $postData[self::REQUEST_PARAMETER_MAIL] = $mailEncoded; $postData[self::REQUEST_PARAMETER_MESSAGE] = $messageEncoded; $response = $this->httpPost($uri, $postData, true); + } else { + return false; } } @@ -381,8 +398,8 @@ { $code = $this->_httpClient->get($uri, $data, $preEncoded, $headers); P2Exception::pearErrorToP2Exception($code); - if ($code < 200 || $code >= 300) { - throw new P2Exception('HTTP Error: '. $code); + if ($code != 200) { + throw new P2Exception('HTTP '. $code); } return $this->_httpClient->currentResponse(); } @@ -406,8 +423,8 @@ { $code = $this->_httpClient->post($uri, $data, $preEncoded, $files, $headers); P2Exception::pearErrorToP2Exception($code); - if ($code < 200 || $code >= 300) { - throw new P2Exception('HTTP Error: '. $code); + if ($code != 200) { + throw new P2Exception('HTTP '. $code); } return $this->_httpClient->currentResponse(); } Modified: p2ex/trunk/lib/P2Util.php =================================================================== --- p2ex/trunk/lib/P2Util.php 2010-01-02 07:46:50 UTC (rev 760) +++ p2ex/trunk/lib/P2Util.php 2010-01-02 17:13:28 UTC (rev 761) @@ -62,7 +62,7 @@ /** * t@Cð_E[hÛ¶·é */ - static public function fileDownload($url, $localfile, $disp_error = 1) + static public function fileDownload($url, $localfile, $disp_error = true) { global $_conf, $_info_msg_ht; @@ -91,6 +91,12 @@ if ($wap_res->isError() && $disp_error) { $url_t = self::throughIme($wap_req->url); $_info_msg_ht .= "<div>Error: {$wap_res->code} {$wap_res->message}<br>"; + if ($wap_res->isRedirect() && array_key_exists('Location', $wap_res->headers)) { + $location = $wap_res->headers['Location']; + $location_ht = htmlspecialchars($location, ENT_QUOTES); + $location_t = P2Util::throughIme($location); + $_info_msg_ht .= "Location: <a href=\"{$location_t}\"{$_conf['ext_win_target_at']}>{$location_ht}</a><br>"; + } $_info_msg_ht .= "p2 info: <a href=\"{$url_t}\"{$_conf['ext_win_target_at']}>{$wap_req->url}</a> Éڱūܹñŵ½B</div>"; } Modified: p2ex/trunk/lib/ThreadRead.php =================================================================== --- p2ex/trunk/lib/ThreadRead.php 2010-01-02 07:46:50 UTC (rev 760) +++ p2ex/trunk/lib/ThreadRead.php 2010-01-02 17:13:28 UTC (rev 761) @@ -88,6 +88,9 @@ } elseif (P2Util::isHost2chs($this->host) && !empty($_GET['moritapodat']) && $_conf['p2_2ch_mail'] && $_conf['p2_2ch_pass']) { + if (!array_key_exists('csrfid', $_GET) || P2Util::getCsrfId() != $_GET['csrfid']) { + p2die('s³ÈNGXgÅ·'); + } $this->_downloadDat2chMoritapo(); // 2chÌßOqÉÇÝ @@ -1352,7 +1355,12 @@ global $_conf; if ($_conf['p2_2ch_mail'] && $_conf['p2_2ch_pass']) { - return " [<a href=\"{$_conf['read_php']}?host={$this->host}&bbs={$this->bbs}&key={$this->key}&ls={$this->ls}&moritapodat=true\">^|Åp2ÉæèÞ</a>]"; + $query = htmlspecialchars('host=' . rawurldecode($this->host) + . '&bbs=' . rawurldecode($this->bbs) + . '&key=' . rawurldecode($this->key) + . '&ls=' . rawurldecode($this->ls) + . '&moritapodat=true&csrfid=' . P2Util::getCsrfId(), ENT_QUOTES); + return " [<a href=\"{$_conf['read_php']}?{$query}\">^|Åp2ÉæèÞ</a>]"; } else { return ''; } @@ -1440,6 +1448,8 @@ { global $_conf; + $csrfid = P2Util::getCsrfId(); + $marutori_ht = " [<a href=\"{$_conf['read_php']}?host={$this->host}&bbs={$this->bbs}&key={$this->key}&ls={$this->ls}&maru=true\">IDÅp2ÉæèÞ</a>]"; if ($hosts = $this->scanOriginalHosts()) { @@ -1461,6 +1471,7 @@ <input type="hidden" name="ls" value="{$this->ls}"> ÉÏ¦Ä <input type="submit" name="moritapodat" value="^|Åp2ÉæèñÅÝé"> + <input type="hidden" name="csrfid" value="{$csrfid}"> {$hosts_ht} </form>\n EOF; Modified: p2ex/trunk/lib/expack/rss/common.inc.php =================================================================== --- p2ex/trunk/lib/expack/rss/common.inc.php 2010-01-02 07:46:50 UTC (rev 760) +++ p2ex/trunk/lib/expack/rss/common.inc.php 2010-01-02 17:13:28 UTC (rev 761) @@ -14,19 +14,19 @@ function rss_get_save_path($remotefile) { global $_conf, $_info_msg_ht; - static $done = array(); + static $finished = array(); $remotefile = preg_replace('|^feed://|', 'http://', $remotefile); - if (isset($done[$remotefile])) { - return $done[$remotefile]; + if (array_key_exists($remotefile, $finished)) { + return $finished[$remotefile]; } $pURL = @parse_url($remotefile); if (!$pURL || !isset($pURL['scheme']) || $pURL['scheme'] != 'http' || !isset($pURL['host'])) { $errmsg = 'p2 error: s³ÈRSSÌURL (' . htmlspecialchars($remotefile, ENT_QUOTES) . ')'; - $error = &PEAR::raiseError($errmsg); - return ($done[$remotefile] = $error); + $error = PEAR::raiseError($errmsg); + return ($finished[$remotefile] = $error); } $localname = ''; @@ -53,7 +53,7 @@ $localpath = $_conf['dat_dir'] . '/p2_rss/' . $pURL['host'] . '/' . $localname; - return ($done[$remotefile] = $localpath); + return ($finished[$remotefile] = $localpath); } // }}} Modified: p2ex/trunk/lib/expack/rss/parser.inc.php =================================================================== --- p2ex/trunk/lib/expack/rss/parser.inc.php 2010-01-02 07:46:50 UTC (rev 760) +++ p2ex/trunk/lib/expack/rss/parser.inc.php 2010-01-02 17:13:28 UTC (rev 761) @@ -3,6 +3,7 @@ * rep2expack - RSS Parser */ +require_once P2_LIB_DIR . '/FileCtl.php'; require_once P2EX_LIB_DIR . '/rss/common.inc.php'; require_once 'XML/RSS.php'; @@ -12,9 +13,13 @@ ((!$GLOBALS['_conf']['ktai'] && $GLOBALS['_conf']['expack.ic2.enabled'] % 2 == 1) || ($GLOBALS['_conf']['ktai'] && $GLOBALS['_conf']['expack.ic2.enabled'] >= 2))) { - require_once P2EX_LIB_DIR . '/ic2/Switch.php'; + if (!class_exists('IC2_Switch', false)) { + require P2EX_LIB_DIR . '/ic2/Switch.php'; + } if (IC2_Switch::get($GLOBALS['_conf']['ktai'])) { - require_once P2EX_LIB_DIR . '/rss/getimage.inc.php'; + if (!function_exists('rss_get_image')) { + require P2EX_LIB_DIR . '/rss/getimage.inc.php'; + } define('P2_RSS_IMAGECACHE_AVAILABLE', 1); } else { define('P2_RSS_IMAGECACHE_AVAILABLE', 0); @@ -43,7 +48,6 @@ // Û¶pfBNgªÈ¯êÎÂé if (!is_dir(dirname($localpath))) { - require_once P2_LIB_DIR . '/FileCtl.php'; FileCtl::mkdir_for($localpath); } @@ -62,7 +66,7 @@ if ($atom) { $atom = (isset($dl) && $dl->code == 200) ? 2 : 1; } - $rss = &p2ParseRSS($localpath, $atom); + $rss = p2ParseRSS($localpath, $atom); return $rss; } else { return $dl; @@ -166,7 +170,6 @@ // Û¶pfBNgªÈ¯êÎÂé if (!is_dir(dirname($output))) { - require_once P2_LIB_DIR . '/FileCtl.php'; FileCtl::mkdir_for($output); } Modified: p2ex/trunk/lib/expack/rss/setrss.inc.php =================================================================== --- p2ex/trunk/lib/expack/rss/setrss.inc.php 2010-01-02 07:46:50 UTC (rev 760) +++ p2ex/trunk/lib/expack/rss/setrss.inc.php 2010-01-02 17:13:28 UTC (rev 761) @@ -50,19 +50,14 @@ unset($site, $xml, $atom, $m, $matches, $fp); return; } - - $setrss = isset($_POST['setrss']) ? trim($_POST['setrss']) : ''; - $xml = isset($_POST['xml']) ? trim($_POST['xml']) : ''; - $site = isset($_POST['site']) ? trim($_POST['site']) : ''; - $site_en = isset($_POST['site_en']) ? trim($_POST['site_en']) : ''; - $atom = empty($_POST['atom']) ? 0 : 1; -} else { - $setrss = isset($_POST['setrss']) ? trim($_GET['setrss']) : ''; - $xml = isset($_POST['xml']) ? trim($_GET['xml']) : ''; - $site = isset($_POST['site']) ? trim($_GET['site']) : ''; - $site_en = isset($_POST['site_en']) ? trim($_GET['site_en']) : ''; - $atom = empty($_GET['atom']) ? 0 : 1; } + +$setrss = isset($_REQUEST['setrss']) ? trim($_REQUEST['setrss']) : ''; +$xml = isset($_REQUEST['xml']) ? trim($_REQUEST['xml']) : ''; +$site = isset($_REQUEST['site']) ? trim($_REQUEST['site']) : ''; +$site_en = isset($_REQUEST['site_en']) ? trim($_REQUEST['site_en']) : ''; +$atom = empty($_REQUEST['atom']) ? 0 : 1; + // RSSÌ^CgÝè if ($site === '') { if ($site_en !== '') { @@ -72,6 +67,9 @@ } } +// feedXL[ðhttpXL[Åu· +$xml = preg_replace('|^feed://|', 'http://', $xml); + // OÉL^·éÏðÅáÀÌTj^CY $xml = preg_replace_callback('/\\s/', 'rawurlencode', $xml); $site = preg_replace('/\\s/', ' ', $site); Modified: p2ex/trunk/lib/post_form.inc.php =================================================================== --- p2ex/trunk/lib/post_form.inc.php 2010-01-02 07:46:50 UTC (rev 760) +++ p2ex/trunk/lib/post_form.inc.php 2010-01-02 17:13:28 UTC (rev 761) @@ -92,7 +92,7 @@ {$htm['block_submit']} {$htm['table_break2']} <input id="kakiko_submit" type="submit" name="submit" value="{$submit_value}"{$htm['kaiko_set_hidden_js']}{$htm['submit_extra_at']}> -{$htm['be2ch']} +{$htm['beres']} {$htm['p2res']} {$htm['table_end']} Modified: p2ex/trunk/read_rss.php =================================================================== --- p2ex/trunk/read_rss.php 2010-01-02 07:46:50 UTC (rev 760) +++ p2ex/trunk/read_rss.php 2010-01-02 17:13:28 UTC (rev 761) @@ -6,6 +6,7 @@ // {{{ p2î{ÝèÇÝÝ&FØ require_once './conf/conf.inc.php'; +require_once P2EX_LIB_DIR . '/rss/parser.inc.php'; $_login->authorize(); @@ -40,7 +41,6 @@ //============================================================ if ($xml) { - require_once P2EX_LIB_DIR . '/rss/parser.inc.php'; $rss = p2GetRSS($xml, $atom); if ($rss instanceof XML_Parser) { clearstatcache(); Modified: p2ex/trunk/subject_rss.php =================================================================== --- p2ex/trunk/subject_rss.php 2010-01-02 07:46:50 UTC (rev 760) +++ p2ex/trunk/subject_rss.php 2010-01-02 17:13:28 UTC (rev 761) @@ -6,6 +6,7 @@ // {{{ p2î{ÝèÇÝÝ&FØ require_once './conf/conf.inc.php'; +require_once P2EX_LIB_DIR . '/rss/parser.inc.php'; $_login->authorize(); @@ -37,7 +38,6 @@ //============================================================ if ($xml) { - require_once P2EX_LIB_DIR . '/rss/parser.inc.php'; $rss = p2GetRSS($xml, $atom); if ($rss instanceof XML_Parser) { clearstatcache();