2009-11-17 09:58:49 +09:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
|
|
|
*
|
|
|
|
* Show an OAuth application
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* LICENCE: This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @category Application
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Zach Copley <zach@status.net>
|
|
|
|
* @copyright 2008-2009 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('STATUSNET') && !defined('LACONICA')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show an OAuth application
|
|
|
|
*
|
|
|
|
* @category Application
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Zach Copley <zach@status.net>
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
class ShowApplicationAction extends OwnerDesignAction
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Application to show
|
|
|
|
*/
|
|
|
|
var $application = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* User who owns the app
|
|
|
|
*/
|
|
|
|
var $owner = null;
|
|
|
|
|
|
|
|
var $msg = null;
|
|
|
|
|
|
|
|
var $success = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load attributes based on database arguments
|
|
|
|
*
|
|
|
|
* Loads all the DB stuff
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST array
|
|
|
|
*
|
|
|
|
* @return success flag
|
|
|
|
*/
|
|
|
|
function prepare($args)
|
|
|
|
{
|
|
|
|
parent::prepare($args);
|
|
|
|
|
|
|
|
$id = (int)$this->arg('id');
|
|
|
|
|
|
|
|
$this->application = Oauth_application::staticGet($id);
|
|
|
|
$this->owner = User::staticGet($this->application->owner);
|
|
|
|
|
|
|
|
if (!common_logged_in()) {
|
2011-03-24 19:47:57 +09:00
|
|
|
// TRANS: Client error displayed trying to display an OAuth application while not logged in.
|
2009-11-17 09:58:49 +09:00
|
|
|
$this->clientError(_('You must be logged in to view an application.'));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->application)) {
|
2011-03-24 19:47:57 +09:00
|
|
|
// TRANS: Client error displayed trying to display a non-existing OAuth application.
|
2009-11-17 09:58:49 +09:00
|
|
|
$this->clientError(_('No such application.'), 404);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cur = common_current_user();
|
|
|
|
|
|
|
|
if ($cur->id != $this->owner->id) {
|
2011-03-24 19:47:57 +09:00
|
|
|
// TRANS: Client error displayed trying to display an OAuth application for which the logged in user is not the owner.
|
2009-11-17 09:58:49 +09:00
|
|
|
$this->clientError(_('You are not the owner of this application.'), 401);
|
2010-01-14 06:11:08 +09:00
|
|
|
return false;
|
2009-11-17 09:58:49 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the request
|
|
|
|
*
|
|
|
|
* Shows info about the app
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function handle($args)
|
|
|
|
{
|
|
|
|
parent::handle($args);
|
|
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
|
|
|
|
|
|
// CSRF protection
|
|
|
|
$token = $this->trimmed('token');
|
|
|
|
if (!$token || $token != common_session_token()) {
|
|
|
|
$this->clientError(_('There was a problem with your session token.'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->arg('reset')) {
|
|
|
|
$this->resetKey();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->showPage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Title of the page
|
|
|
|
*
|
|
|
|
* @return string title of the page
|
|
|
|
*/
|
|
|
|
function title()
|
|
|
|
{
|
|
|
|
if (!empty($this->application->name)) {
|
|
|
|
return 'Application: ' . $this->application->name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showPageNotice()
|
|
|
|
{
|
|
|
|
if (!empty($this->msg)) {
|
|
|
|
$this->element('div', ($this->success) ? 'success' : 'error', $this->msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showContent()
|
|
|
|
{
|
|
|
|
$cur = common_current_user();
|
|
|
|
|
|
|
|
$consumer = $this->application->getConsumer();
|
|
|
|
|
2010-01-12 10:02:25 +09:00
|
|
|
$this->elementStart('div', 'entity_profile vcard');
|
2011-03-24 19:47:57 +09:00
|
|
|
// TRANS: Header on the OAuth application page.
|
2010-01-12 08:51:12 +09:00
|
|
|
$this->element('h2', null, _('Application profile'));
|
|
|
|
if (!empty($this->application->icon)) {
|
2010-01-12 10:02:25 +09:00
|
|
|
$this->element('img', array('src' => $this->application->icon,
|
2011-01-15 05:36:06 +09:00
|
|
|
'class' => 'photo logo entity_depiction'));
|
2010-01-12 08:51:12 +09:00
|
|
|
}
|
2010-01-07 18:55:57 +09:00
|
|
|
|
2010-01-12 10:13:36 +09:00
|
|
|
$this->element('a', array('href' => $this->application->source_url,
|
2011-01-15 05:36:06 +09:00
|
|
|
'class' => 'url fn entity_fn'),
|
2010-01-12 10:13:36 +09:00
|
|
|
$this->application->name);
|
2010-01-12 10:02:25 +09:00
|
|
|
|
2010-01-12 10:13:36 +09:00
|
|
|
$this->element('a', array('href' => $this->application->homepage,
|
2011-01-15 05:36:06 +09:00
|
|
|
'class' => 'url entity_org'),
|
2010-01-12 10:13:36 +09:00
|
|
|
$this->application->organization);
|
2009-11-17 09:58:49 +09:00
|
|
|
|
2011-01-15 05:36:06 +09:00
|
|
|
$this->element('div',
|
|
|
|
'note entity_note',
|
|
|
|
$this->application->description);
|
2009-11-17 09:58:49 +09:00
|
|
|
|
2011-01-15 05:36:06 +09:00
|
|
|
$this->elementStart('div', 'entity_statistics');
|
2009-11-17 09:58:49 +09:00
|
|
|
$defaultAccess = ($this->application->access_type & Oauth_application::$writeAccess)
|
|
|
|
? 'read-write' : 'read-only';
|
|
|
|
$profile = Profile::staticGet($this->application->owner);
|
2010-01-14 02:52:25 +09:00
|
|
|
|
|
|
|
$appUsers = new Oauth_application_user();
|
|
|
|
$appUsers->application_id = $this->application->id;
|
|
|
|
$userCnt = $appUsers->count();
|
2009-11-17 09:58:49 +09:00
|
|
|
|
|
|
|
$this->raw(sprintf(
|
2011-03-24 19:47:57 +09:00
|
|
|
// TRANS: Information output on an OAuth application page.
|
|
|
|
// TRANS: %1$s is the application creator, %2$s is "read-only" or "read-write",
|
|
|
|
// TRANS: %3$d is the number of users using the OAuth application.
|
|
|
|
_m('Created by %1$s - %2$s access by default - %3$d user',
|
|
|
|
'Created by %1$s - %2$s access by default - %3$d users',
|
|
|
|
$userCnt),
|
2009-11-17 09:58:49 +09:00
|
|
|
$profile->getBestName(),
|
|
|
|
$defaultAccess,
|
|
|
|
$userCnt
|
|
|
|
));
|
2011-01-15 05:36:06 +09:00
|
|
|
$this->elementEnd('div');
|
|
|
|
|
2010-01-12 08:51:12 +09:00
|
|
|
$this->elementEnd('div');
|
2009-11-17 09:58:49 +09:00
|
|
|
|
2010-01-12 10:02:25 +09:00
|
|
|
$this->elementStart('div', 'entity_actions');
|
2011-03-24 19:47:57 +09:00
|
|
|
// TRANS: Header on the OAuth application page.
|
2010-01-12 10:02:25 +09:00
|
|
|
$this->element('h2', null, _('Application actions'));
|
|
|
|
$this->elementStart('ul');
|
|
|
|
$this->elementStart('li', 'entity_edit');
|
|
|
|
$this->element('a',
|
2010-01-13 16:33:51 +09:00
|
|
|
array('href' => common_local_url('editapplication',
|
|
|
|
array('id' => $this->application->id))),
|
2011-03-24 19:47:57 +09:00
|
|
|
// TRANS: Link text to edit application on the OAuth application page.
|
|
|
|
_m('EDITAPP','Edit'));
|
2010-01-12 10:02:25 +09:00
|
|
|
$this->elementEnd('li');
|
|
|
|
|
|
|
|
$this->elementStart('li', 'entity_reset_keysecret');
|
|
|
|
$this->elementStart('form', array(
|
2010-02-02 15:26:03 +09:00
|
|
|
'id' => 'form_reset_key',
|
2010-01-12 10:02:25 +09:00
|
|
|
'class' => 'form_reset_key',
|
|
|
|
'method' => 'POST',
|
|
|
|
'action' => common_local_url('showapplication',
|
2010-01-14 02:52:25 +09:00
|
|
|
array('id' => $this->application->id))));
|
2010-01-12 10:02:25 +09:00
|
|
|
$this->elementStart('fieldset');
|
|
|
|
$this->hidden('token', common_session_token());
|
2010-02-03 10:43:59 +09:00
|
|
|
|
|
|
|
$this->element('input', array('type' => 'submit',
|
|
|
|
'id' => 'reset',
|
|
|
|
'name' => 'reset',
|
|
|
|
'class' => 'submit',
|
2011-03-24 19:47:57 +09:00
|
|
|
// TRANS: Button text on the OAuth application page.
|
|
|
|
// TRANS: Resets the OAuth consumer key and secret.
|
2010-02-03 10:43:59 +09:00
|
|
|
'value' => _('Reset key & secret'),
|
|
|
|
'onClick' => 'return confirmReset()'));
|
2010-01-12 10:02:25 +09:00
|
|
|
$this->elementEnd('fieldset');
|
|
|
|
$this->elementEnd('form');
|
|
|
|
$this->elementEnd('li');
|
2010-02-02 15:26:03 +09:00
|
|
|
|
|
|
|
$this->elementStart('li', 'entity_delete');
|
|
|
|
$this->elementStart('form', array(
|
|
|
|
'id' => 'form_delete_application',
|
|
|
|
'class' => 'form_delete_application',
|
|
|
|
'method' => 'POST',
|
|
|
|
'action' => common_local_url('deleteapplication',
|
|
|
|
array('id' => $this->application->id))));
|
|
|
|
|
|
|
|
$this->elementStart('fieldset');
|
|
|
|
$this->hidden('token', common_session_token());
|
2011-03-24 19:47:57 +09:00
|
|
|
// TRANS: Submit button text the OAuth application page to delete an application.
|
|
|
|
$this->submit('delete', _m('BUTTON','Delete'));
|
2010-02-02 15:26:03 +09:00
|
|
|
$this->elementEnd('fieldset');
|
|
|
|
$this->elementEnd('form');
|
|
|
|
$this->elementEnd('li');
|
|
|
|
|
2010-01-12 10:02:25 +09:00
|
|
|
$this->elementEnd('ul');
|
|
|
|
$this->elementEnd('div');
|
|
|
|
|
|
|
|
$this->elementStart('div', 'entity_data');
|
2011-03-24 19:47:57 +09:00
|
|
|
// TRANS: Header on the OAuth application page.
|
2010-01-12 08:51:12 +09:00
|
|
|
$this->element('h2', null, _('Application info'));
|
2011-01-15 05:36:06 +09:00
|
|
|
$this->element('div',
|
|
|
|
'entity_consumer_key',
|
|
|
|
$consumer->consumer_key);
|
|
|
|
|
|
|
|
$this->element('div',
|
|
|
|
'entity_consumer_secret',
|
|
|
|
$consumer->consumer_secret);
|
|
|
|
|
|
|
|
$this->element('div',
|
|
|
|
'entity_request_token_url',
|
|
|
|
common_local_url('ApiOauthRequestToken'));
|
|
|
|
|
|
|
|
$this->element('div', 'entity_access_token_url', common_local_url('ApiOauthAccessToken'));
|
|
|
|
|
|
|
|
$this->element('div', 'entity_authorize_url', common_local_url('ApiOauthAuthorize'));
|
2009-11-17 09:58:49 +09:00
|
|
|
|
2010-01-12 10:02:25 +09:00
|
|
|
$this->element('p', 'note',
|
2011-03-24 19:47:57 +09:00
|
|
|
// TRANS: Note on the OAuth application page about signature support.
|
|
|
|
_('Note: HMAC-SHA1 signatures are supported. The plaintext signature method is not supported.'));
|
2009-11-17 09:58:49 +09:00
|
|
|
$this->elementEnd('div');
|
|
|
|
|
2010-01-12 07:54:46 +09:00
|
|
|
$this->elementStart('p', array('id' => 'application_action'));
|
2009-11-17 09:58:49 +09:00
|
|
|
$this->element('a',
|
2010-01-13 16:33:51 +09:00
|
|
|
array('href' => common_local_url('oauthappssettings'),
|
|
|
|
'class' => 'more'),
|
|
|
|
'View your applications');
|
2010-01-12 07:54:46 +09:00
|
|
|
$this->elementEnd('p');
|
2009-11-17 09:58:49 +09:00
|
|
|
}
|
|
|
|
|
2010-02-03 10:43:59 +09:00
|
|
|
/**
|
|
|
|
* Add a confirm script for Consumer key/secret reset
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showScripts()
|
|
|
|
{
|
|
|
|
parent::showScripts();
|
|
|
|
|
2011-03-24 19:47:57 +09:00
|
|
|
// TRANS: Text in confirmation dialog to reset consumer key and secret for an OAuth application.
|
2010-02-03 10:43:59 +09:00
|
|
|
$msg = _('Are you sure you want to reset your consumer key and secret?');
|
|
|
|
|
|
|
|
$js = 'function confirmReset() { ';
|
|
|
|
$js .= ' var agree = confirm("' . $msg . '"); ';
|
|
|
|
$js .= ' return agree;';
|
|
|
|
$js .= '}';
|
|
|
|
|
|
|
|
$this->inlineScript($js);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset an application's Consumer key and secret
|
|
|
|
*
|
|
|
|
* XXX: Should this be moved to its own page with a confirm?
|
|
|
|
*
|
|
|
|
*/
|
2009-11-17 09:58:49 +09:00
|
|
|
function resetKey()
|
|
|
|
{
|
|
|
|
$this->application->query('BEGIN');
|
|
|
|
|
2010-02-03 10:43:59 +09:00
|
|
|
$oauser = new Oauth_application_user();
|
|
|
|
$oauser->application_id = $this->application->id;
|
|
|
|
$result = $oauser->delete();
|
|
|
|
|
|
|
|
if ($result === false) {
|
|
|
|
common_log_db_error($oauser, 'DELETE', __FILE__);
|
|
|
|
$this->success = false;
|
|
|
|
$this->msg = ('Unable to reset consumer key and secret.');
|
|
|
|
$this->showPage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-17 09:58:49 +09:00
|
|
|
$consumer = $this->application->getConsumer();
|
|
|
|
$result = $consumer->delete();
|
|
|
|
|
2010-02-03 10:43:59 +09:00
|
|
|
if ($result === false) {
|
2009-11-17 09:58:49 +09:00
|
|
|
common_log_db_error($consumer, 'DELETE', __FILE__);
|
|
|
|
$this->success = false;
|
|
|
|
$this->msg = ('Unable to reset consumer key and secret.');
|
|
|
|
$this->showPage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$consumer = Consumer::generateNew();
|
|
|
|
|
|
|
|
$result = $consumer->insert();
|
|
|
|
|
2010-02-03 10:43:59 +09:00
|
|
|
if (empty($result)) {
|
2009-11-17 09:58:49 +09:00
|
|
|
common_log_db_error($consumer, 'INSERT', __FILE__);
|
|
|
|
$this->application->query('ROLLBACK');
|
|
|
|
$this->success = false;
|
|
|
|
$this->msg = ('Unable to reset consumer key and secret.');
|
|
|
|
$this->showPage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$orig = clone($this->application);
|
|
|
|
$this->application->consumer_key = $consumer->consumer_key;
|
|
|
|
$result = $this->application->update($orig);
|
|
|
|
|
2010-02-03 10:43:59 +09:00
|
|
|
if ($result === false) {
|
2009-11-17 09:58:49 +09:00
|
|
|
common_log_db_error($application, 'UPDATE', __FILE__);
|
|
|
|
$this->application->query('ROLLBACK');
|
|
|
|
$this->success = false;
|
|
|
|
$this->msg = ('Unable to reset consumer key and secret.');
|
|
|
|
$this->showPage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->application->query('COMMIT');
|
|
|
|
|
|
|
|
$this->success = true;
|
|
|
|
$this->msg = ('Consumer key and secret reset.');
|
|
|
|
$this->showPage();
|
|
|
|
}
|
|
|
|
}
|