2007-11-22 01:57:12 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2016-04-27 21:12:20 +02:00
|
|
|
* EGgroupware admin - UI for the command queue
|
2007-11-22 01:57:12 +01:00
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @package admin
|
2019-03-14 18:57:07 +01:00
|
|
|
* @copyright (c) 2007-19 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2007-11-22 01:57:12 +01:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
*/
|
|
|
|
|
2016-04-27 21:12:20 +02:00
|
|
|
use EGroupware\Api;
|
2016-05-07 18:57:18 +02:00
|
|
|
use EGroupware\Api\Etemplate;
|
2016-04-27 21:12:20 +02:00
|
|
|
|
2007-11-22 01:57:12 +01:00
|
|
|
/**
|
|
|
|
* UI for the admin comand queue
|
|
|
|
*/
|
|
|
|
class admin_cmds
|
|
|
|
{
|
|
|
|
var $public_functions = array(
|
|
|
|
'index' => true,
|
2007-11-24 20:56:58 +01:00
|
|
|
'remotes' => true,
|
2007-11-22 01:57:12 +01:00
|
|
|
);
|
2016-04-27 21:12:20 +02:00
|
|
|
|
2007-11-22 01:57:12 +01:00
|
|
|
/**
|
2016-04-27 21:12:20 +02:00
|
|
|
* calling get_rows of our static Api\Storage\Base instance
|
2007-11-22 01:57:12 +01:00
|
|
|
*
|
|
|
|
* @param array $query
|
|
|
|
* @param array &$rows
|
2007-11-24 20:56:58 +01:00
|
|
|
* @param array &$readonlys
|
2007-11-22 01:57:12 +01:00
|
|
|
* @return int
|
|
|
|
*/
|
2007-11-27 04:20:28 +01:00
|
|
|
static function get_rows(array $query,&$rows,&$readonlys)
|
2007-11-22 01:57:12 +01:00
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
Api\Cache::setSession('admin', 'cmds', $query);
|
2007-11-24 20:56:58 +01:00
|
|
|
|
2019-03-14 18:57:07 +01:00
|
|
|
// show also old api
|
|
|
|
if ($query['col_filter']['app'] === 'api')
|
|
|
|
{
|
|
|
|
$query['col_filter']['app'] = ['api', 'phpgwapi'];
|
|
|
|
}
|
|
|
|
|
2019-01-14 15:26:04 +01:00
|
|
|
return admin_cmd::get_rows($query,$rows,$readonlys);
|
2007-11-22 01:57:12 +01:00
|
|
|
}
|
2016-04-27 21:12:20 +02:00
|
|
|
|
2007-11-24 20:56:58 +01:00
|
|
|
/**
|
|
|
|
* Showing the command history and the scheduled commands
|
|
|
|
*
|
2016-04-27 21:12:20 +02:00
|
|
|
* @param array $content =null
|
2007-11-24 20:56:58 +01:00
|
|
|
*/
|
|
|
|
static function index(array $content=null)
|
2007-11-22 01:57:12 +01:00
|
|
|
{
|
2016-05-07 18:57:18 +02:00
|
|
|
$tpl = new Etemplate('admin.cmds');
|
2007-11-24 20:56:58 +01:00
|
|
|
|
2007-11-22 01:57:12 +01:00
|
|
|
if (!is_array($content))
|
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
$content['nm'] = Api\Cache::getSession('admin', 'cmds');
|
2007-11-22 01:57:12 +01:00
|
|
|
if (!is_array($content['nm']))
|
|
|
|
{
|
|
|
|
$content['nm'] = array(
|
|
|
|
'get_rows' => 'admin.admin_cmds.get_rows', // I method/callback to request the data for the rows eg. 'notes.bo.get_rows'
|
|
|
|
'no_filter' => true, // I disable the 1. filter
|
|
|
|
'no_filter2' => true, // I disable the 2. filter (params are the same as for filter)
|
|
|
|
'no_cat' => true, // I disable the cat-selectbox
|
|
|
|
'order' => 'cmd_created',
|
|
|
|
'sort' => 'DESC',
|
2016-05-07 18:57:18 +02:00
|
|
|
'row_id' => 'id',
|
|
|
|
'default_cols' => 'title,created,creator,status',
|
2016-04-27 21:12:20 +02:00
|
|
|
);
|
2007-11-22 01:57:12 +01:00
|
|
|
}
|
2019-03-14 18:57:07 +01:00
|
|
|
$content['nm']['actions'] = self::cmd_actions();
|
2007-11-22 01:57:12 +01:00
|
|
|
}
|
2021-10-06 16:07:47 +02:00
|
|
|
elseif (!empty($content['nm']['rows']['delete']))
|
2007-11-24 20:56:58 +01:00
|
|
|
{
|
2019-02-12 22:13:45 +01:00
|
|
|
$id = key($content['nm']['rows']['delete']);
|
2007-11-24 20:56:58 +01:00
|
|
|
unset($content['nm']['rows']);
|
2016-04-27 21:12:20 +02:00
|
|
|
|
2007-11-24 20:56:58 +01:00
|
|
|
if (($cmd = admin_cmd::read($id)))
|
|
|
|
{
|
|
|
|
$cmd->delete();
|
|
|
|
}
|
|
|
|
unset($cmd);
|
|
|
|
}
|
2018-09-25 21:17:52 +02:00
|
|
|
$periodic = array(
|
|
|
|
0 => 'no',
|
|
|
|
1 => 'yes'
|
|
|
|
);
|
2018-10-09 19:13:06 +02:00
|
|
|
$sel_options = array(
|
2018-09-25 21:17:52 +02:00
|
|
|
'periodic' => $periodic,
|
2007-11-22 01:57:12 +01:00
|
|
|
'status' => admin_cmd::$stati,
|
2007-11-24 20:56:58 +01:00
|
|
|
'remote_id' => admin_cmd::remote_sites(),
|
2018-10-09 19:13:06 +02:00
|
|
|
'type' => admin_cmd::get_cmd_labels()
|
|
|
|
);
|
|
|
|
|
|
|
|
$tpl->exec('admin.admin_cmds.index',$content,$sel_options,array(),$content);
|
2007-11-24 20:56:58 +01:00
|
|
|
}
|
2016-04-27 21:12:20 +02:00
|
|
|
|
2016-05-07 18:57:18 +02:00
|
|
|
/**
|
|
|
|
* Acctions for command list/index
|
|
|
|
*
|
|
|
|
* As we only allow to delete scheduled command, which we currently can only create via admin-cli,
|
|
|
|
* I have not (yet) implemented delete of scheduled commands.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
static function cmd_actions()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-11-24 20:56:58 +01:00
|
|
|
/**
|
|
|
|
* get_rows for remote instances
|
|
|
|
*
|
|
|
|
* @param array $query
|
|
|
|
* @param array &$rows
|
|
|
|
* @param array &$readonlys
|
|
|
|
* @return int
|
|
|
|
*/
|
2007-11-27 04:20:28 +01:00
|
|
|
static function get_remotes(array $query,&$rows,&$readonlys)
|
2007-11-24 20:56:58 +01:00
|
|
|
{
|
|
|
|
return admin_cmd::get_remotes($query,$rows,$readonlys);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Showing remote administration instances
|
|
|
|
*
|
2016-04-27 21:12:20 +02:00
|
|
|
* @param array $content =null
|
2007-11-24 20:56:58 +01:00
|
|
|
*/
|
|
|
|
static function remotes(array $content=null)
|
|
|
|
{
|
2016-05-07 18:57:18 +02:00
|
|
|
$tpl = new Etemplate('admin.remotes');
|
2007-11-24 20:56:58 +01:00
|
|
|
|
|
|
|
if (!is_array($content))
|
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
$content['nm'] = Api\Cache::getSession('admin', 'remotes');
|
2007-11-24 20:56:58 +01:00
|
|
|
if (!is_array($content['nm']))
|
|
|
|
{
|
|
|
|
$content['nm'] = array(
|
|
|
|
'get_rows' => 'admin.admin_cmds.get_remotes', // I method/callback to request the data for the rows eg. 'notes.bo.get_rows'
|
|
|
|
'no_filter' => true, // I disable the 1. filter
|
|
|
|
'no_filter2' => true, // I disable the 2. filter (params are the same as for filter)
|
|
|
|
'no_cat' => true, // I disable the cat-selectbox
|
|
|
|
'order' => 'remote_name',
|
|
|
|
'sort' => 'ASC',
|
2016-05-07 18:57:18 +02:00
|
|
|
'row_id' => 'remote_id',
|
|
|
|
'actions' => self::remote_actions(),
|
2007-11-24 20:56:58 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//_debug_array($content);
|
|
|
|
unset($content['msg']);
|
|
|
|
|
2016-05-07 18:57:18 +02:00
|
|
|
if ($content['nm']['action'])
|
2007-11-24 20:56:58 +01:00
|
|
|
{
|
2016-05-07 18:57:18 +02:00
|
|
|
switch($content['nm']['action'])
|
|
|
|
{
|
|
|
|
case 'edit':
|
|
|
|
$content['remote'] = admin_cmd::read_remote($content['nm']['selected'][0]);
|
|
|
|
break;
|
|
|
|
case 'add':
|
|
|
|
$content['remote'] = array('remote_domain' => 'default');
|
|
|
|
}
|
|
|
|
unset($content['nm']['action']);
|
2007-11-24 20:56:58 +01:00
|
|
|
}
|
|
|
|
elseif($content['remote']['button'])
|
|
|
|
{
|
2019-02-12 22:13:45 +01:00
|
|
|
$button = key($content['remote']['button']);
|
2007-11-24 20:56:58 +01:00
|
|
|
unset($content['remote']['button']);
|
|
|
|
switch($button)
|
|
|
|
{
|
|
|
|
case 'save':
|
|
|
|
case 'apply':
|
2016-04-27 21:12:20 +02:00
|
|
|
if ($content['remote']['install_id'] && !$content['remote']['config_passwd'] ||
|
|
|
|
!$content['remote']['install_id'] && $content['remote']['config_passwd'] ||
|
2007-11-24 20:56:58 +01:00
|
|
|
!$content['remote']['remote_hash'] && !$content['remote']['install_id'] && !$content['remote']['config_passwd'])
|
|
|
|
{
|
|
|
|
$content['msg'] = lang('You need to enter Install ID AND Password!');
|
|
|
|
break;
|
|
|
|
}
|
2007-12-05 03:27:49 +01:00
|
|
|
try {
|
|
|
|
$content['remote']['remote_id'] = admin_cmd::save_remote($content['remote']);
|
2007-11-24 20:56:58 +01:00
|
|
|
$content['msg'] = lang('Remote instance saved');
|
2007-12-05 03:27:49 +01:00
|
|
|
} catch (Exception $e) {
|
|
|
|
$content['msg'] = lang('Error saving').': '.$e->getMessage().' ('.$e->getCode().')';
|
|
|
|
break;
|
2007-11-24 20:56:58 +01:00
|
|
|
}
|
|
|
|
if ($button == 'apply') break;
|
|
|
|
// fall through for save
|
|
|
|
case 'cancel':
|
|
|
|
unset($content['remote']);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif ($content['nm']['add'])
|
|
|
|
{
|
|
|
|
$content['remote'] = array('remote_domain' => 'default');
|
|
|
|
unset($content['nm']['add']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$tpl->exec('admin.admin_cmds.remotes',$content,array(),array(),$content);
|
2016-05-07 18:57:18 +02:00
|
|
|
}
|
2016-04-27 21:12:20 +02:00
|
|
|
|
2016-05-07 18:57:18 +02:00
|
|
|
/**
|
|
|
|
* Actions for remotes list
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
static function remote_actions()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'edit' => array(
|
|
|
|
'caption' => 'Edit',
|
|
|
|
'default' => true,
|
|
|
|
'allowOnMultiple' => false,
|
|
|
|
'nm_action' => 'submit',
|
|
|
|
'group' => $group=0,
|
|
|
|
),
|
|
|
|
'add' => array(
|
|
|
|
'caption' => 'Add',
|
|
|
|
'nm_action' => 'submit',
|
|
|
|
'group' => ++$group,
|
|
|
|
),
|
|
|
|
/* not (yet) implemented
|
|
|
|
'delete' => array(
|
|
|
|
'caption' => 'Delete',
|
|
|
|
'nm_action' => 'submit',
|
|
|
|
'group' => ++$group,
|
|
|
|
),*/
|
|
|
|
);
|
2007-11-22 01:57:12 +01:00
|
|
|
}
|
|
|
|
}
|