Merge commit 'jeff-themovie/private-rss' into 0.8.x

This commit is contained in:
Craig Andrews 2009-07-22 10:25:22 -04:00
commit a54b809778
3 changed files with 40 additions and 2 deletions

View File

@ -165,7 +165,8 @@ function main()
if (!$user && common_config('site', 'private') && if (!$user && common_config('site', 'private') &&
!in_array($action, array('login', 'openidlogin', 'finishopenidlogin', !in_array($action, array('login', 'openidlogin', 'finishopenidlogin',
'recoverpassword', 'api', 'doc', 'register'))) { 'recoverpassword', 'api', 'doc', 'register')) &&
!preg_match('/rss$/', $action)) {
common_redirect(common_local_url('login')); common_redirect(common_local_url('login'));
return; return;
} }

View File

@ -19,7 +19,7 @@
if (!defined('LACONICA')) { exit(1); } if (!defined('LACONICA')) { exit(1); }
define('LACONICA_VERSION', '0.8.1dev'); define('LACONICA_VERSION', '0.9.0dev');
define('AVATAR_PROFILE_SIZE', 96); define('AVATAR_PROFILE_SIZE', 96);
define('AVATAR_STREAM_SIZE', 48); define('AVATAR_STREAM_SIZE', 48);

View File

@ -97,6 +97,31 @@ class Rss10Action extends Action
{ {
// Parent handling, including cache check // Parent handling, including cache check
parent::handle($args); parent::handle($args);
if (common_config('site', 'private')) {
if (!isset($_SERVER['PHP_AUTH_USER'])) {
# This header makes basic auth go
header('WWW-Authenticate: Basic realm="Laconica RSS"');
# If the user hits cancel -- bam!
$this->show_basic_auth_error();
return;
} else {
$nickname = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
if (!common_check_user($nickname, $password)) {
# basic authentication failed
list($proxy, $ip) = common_client_ip();
common_log(LOG_WARNING, "Failed RSS auth attempt, nickname = $nickname, proxy = $proxy, ip = $ip.");
$this->show_basic_auth_error();
return;
}
}
}
// Get the list of notices // Get the list of notices
if (empty($this->tag)) { if (empty($this->tag)) {
$this->notices = $this->getNotices($this->limit); $this->notices = $this->getNotices($this->limit);
@ -106,6 +131,18 @@ class Rss10Action extends Action
$this->showRss(); $this->showRss();
} }
function show_basic_auth_error()
{
header('HTTP/1.1 401 Unauthorized');
header('Content-Type: application/xml; charset=utf-8');
$this->startXML();
$this->elementStart('hash');
$this->element('error', null, 'Could not authenticate you.');
$this->element('request', null, $_SERVER['REQUEST_URI']);
$this->elementEnd('hash');
$this->endXML();
}
/** /**
* Get the notices to output in this stream * Get the notices to output in this stream
* *