2010-03-17 06:18:37 +09:00
|
|
|
<?php
|
2019-08-12 23:03:18 +09:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social 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.
|
|
|
|
//
|
|
|
|
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
defined('STATUSNET') || die();
|
2010-03-17 06:18:37 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin enable action.
|
|
|
|
*
|
|
|
|
* (Re)-enables a plugin from the default plugins list.
|
|
|
|
*
|
|
|
|
* Takes parameters:
|
|
|
|
*
|
|
|
|
* - plugin: plugin name
|
|
|
|
* - token: session token to prevent CSRF attacks
|
2019-08-12 23:03:18 +09:00
|
|
|
* - ajax: bool; whether to return Ajax or full-browser results
|
2010-03-17 06:18:37 +09:00
|
|
|
*
|
|
|
|
* Only works if the current user is logged in.
|
|
|
|
*
|
|
|
|
* @category Action
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Brion Vibber <brion@status.net>
|
|
|
|
* @copyright 2010 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
2019-08-12 23:03:18 +09:00
|
|
|
class PluginenableAction extends Action
|
2010-03-17 06:18:37 +09:00
|
|
|
{
|
|
|
|
var $user;
|
|
|
|
var $plugin;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check pre-requisites and instantiate attributes
|
|
|
|
*
|
2019-08-12 23:03:18 +09:00
|
|
|
* @param array $args array of arguments (URL, GET, POST)
|
2010-03-17 06:18:37 +09:00
|
|
|
*
|
2019-08-12 23:03:18 +09:00
|
|
|
* @return bool success flag
|
|
|
|
* @throws ClientException
|
2010-03-17 06:18:37 +09:00
|
|
|
*/
|
2019-08-12 23:03:18 +09:00
|
|
|
function prepare(array $args = [])
|
2010-03-17 06:18:37 +09:00
|
|
|
{
|
|
|
|
parent::prepare($args);
|
|
|
|
|
|
|
|
// @fixme these are pretty common, should a parent class factor these out?
|
|
|
|
|
|
|
|
// Only allow POST requests
|
|
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
|
2011-03-12 01:07:27 +09:00
|
|
|
// TRANS: Client error displayed when trying to use another method than POST.
|
|
|
|
// TRANS: Do not translate POST.
|
2010-03-17 06:18:37 +09:00
|
|
|
$this->clientError(_('This action only accepts POST requests.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// CSRF protection
|
|
|
|
|
|
|
|
$token = $this->trimmed('token');
|
|
|
|
|
|
|
|
if (!$token || $token != common_session_token()) {
|
2011-04-04 06:47:46 +09:00
|
|
|
// TRANS: Client error displayed when the session token does not match or is not given.
|
2019-08-16 23:06:27 +09:00
|
|
|
$this->clientError(_m('There was a problem with your session token.'.
|
2010-03-17 06:18:37 +09:00
|
|
|
' Try again, please.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only for logged-in users
|
|
|
|
|
|
|
|
$this->user = common_current_user();
|
|
|
|
|
|
|
|
if (empty($this->user)) {
|
2011-04-04 07:41:21 +09:00
|
|
|
// TRANS: Error message displayed when trying to perform an action that requires a logged in user.
|
2019-08-16 23:06:27 +09:00
|
|
|
$this->clientError(_m('Not logged in.'));
|
2010-03-17 06:18:37 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!AdminPanelAction::canAdmin('plugins')) {
|
2011-03-12 01:07:27 +09:00
|
|
|
// TRANS: Client error displayed when trying to enable or disable a plugin without access rights.
|
2019-08-16 23:06:27 +09:00
|
|
|
$this->clientError(_m('You cannot administer plugins.'));
|
2010-03-17 06:18:37 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->plugin = $this->arg('plugin');
|
2019-08-16 23:06:27 +09:00
|
|
|
if (!array_key_exists($this->plugin, array_flip(PluginList::grabAllPluginNames()))) {
|
2011-03-12 01:07:27 +09:00
|
|
|
// TRANS: Client error displayed when trying to enable or disable a non-existing plugin.
|
2019-08-16 23:06:27 +09:00
|
|
|
$this->clientError(_m('No such plugin.'));
|
2010-03-17 06:18:37 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle request
|
|
|
|
*
|
|
|
|
* Does the subscription and returns results.
|
|
|
|
*
|
|
|
|
* @return void
|
2019-08-12 23:03:18 +09:00
|
|
|
* @throws ClientException
|
2010-03-17 06:18:37 +09:00
|
|
|
*/
|
2016-06-01 11:05:11 +09:00
|
|
|
function handle()
|
2010-03-17 06:18:37 +09:00
|
|
|
{
|
2019-08-16 23:06:27 +09:00
|
|
|
if (!PluginList::isPluginLoaded($this->plugin)) {
|
|
|
|
$config_file = INSTALLDIR . DIRECTORY_SEPARATOR . 'config.php';
|
|
|
|
$handle = fopen($config_file, 'a');
|
|
|
|
if (!$handle) {
|
|
|
|
$this->clientError(_m('No permissions for writing to config.php'));
|
|
|
|
}
|
|
|
|
$data = PHP_EOL.'addPlugin(\''.$this->plugin.'\'); // Added by sysadmin\'s Plugin UI.';
|
|
|
|
fwrite($handle, $data);
|
|
|
|
fclose($handle);
|
|
|
|
}
|
2010-03-17 06:18:37 +09:00
|
|
|
$key = 'disable-' . $this->plugin;
|
|
|
|
Config::save('plugins', $key, $this->overrideValue());
|
|
|
|
|
|
|
|
// @fixme this is a pretty common pattern and should be refactored down
|
|
|
|
if ($this->boolean('ajax')) {
|
|
|
|
$this->startHTML('text/xml;charset=utf-8');
|
|
|
|
$this->elementStart('head');
|
|
|
|
$this->element('title', null, $this->successShortTitle());
|
|
|
|
$this->elementEnd('head');
|
|
|
|
$this->elementStart('body');
|
|
|
|
$form = $this->successNextForm();
|
|
|
|
$form->show();
|
|
|
|
$this->elementEnd('body');
|
2013-09-24 09:32:17 +09:00
|
|
|
$this->endHTML();
|
2010-03-17 06:18:37 +09:00
|
|
|
} else {
|
|
|
|
$url = common_local_url('pluginsadminpanel');
|
|
|
|
common_redirect($url, 303);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Value to save into $config['plugins']['disable-<name>']
|
|
|
|
*/
|
|
|
|
protected function overrideValue()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function successShortTitle()
|
|
|
|
{
|
|
|
|
// TRANS: Page title for AJAX form return when enabling a plugin.
|
|
|
|
return _m('plugin', 'Enabled');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function successNextForm()
|
|
|
|
{
|
2019-08-12 23:03:18 +09:00
|
|
|
return new PluginDisableForm($this, $this->plugin);
|
2010-03-17 06:18:37 +09:00
|
|
|
}
|
|
|
|
}
|