forked from extern/egroupware
277 lines
6.9 KiB
PHP
277 lines
6.9 KiB
PHP
<?php
|
|
/**
|
|
* EGgroupware admin - UI for the command queue
|
|
*
|
|
* @link http://www.egroupware.org
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
* @package admin
|
|
* @copyright (c) 2007-18 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
*/
|
|
|
|
use EGroupware\Api;
|
|
use EGroupware\Api\Etemplate;
|
|
|
|
/**
|
|
* UI for the admin comand queue
|
|
*/
|
|
class admin_cmds
|
|
{
|
|
var $public_functions = array(
|
|
'index' => true,
|
|
'remotes' => true,
|
|
);
|
|
|
|
/**
|
|
* calling get_rows of our static Api\Storage\Base instance
|
|
*
|
|
* @param array $query
|
|
* @param array &$rows
|
|
* @param array &$readonlys
|
|
* @return int
|
|
*/
|
|
static function get_rows(array $query,&$rows,&$readonlys)
|
|
{
|
|
Api\Cache::setSession('admin', 'cmds', $query);
|
|
|
|
$total = admin_cmd::get_rows($query,$rows,$readonlys);
|
|
|
|
if (!$rows) return array();
|
|
|
|
$async = new Api\Asyncservice();
|
|
foreach($rows as &$row)
|
|
{
|
|
try {
|
|
$cmd = admin_cmd::instanciate($row);
|
|
$row['title'] = $cmd->__tostring(); // we call __tostring explicit, as a cast to string requires php5.2+
|
|
}
|
|
catch (Exception $e) {
|
|
$row['title'] = $e->getMessage();
|
|
}
|
|
|
|
$row['value'] = $cmd->value;
|
|
|
|
if(method_exists($cmd, 'summary'))
|
|
{
|
|
$row['data'] = $cmd->summary();
|
|
}
|
|
else
|
|
{
|
|
$row['data'] = !($data = json_php_unserialize($row['data'])) ? '' :
|
|
json_encode($data+(empty($row['rrule'])?array():array('rrule' => $row['rrule'])),
|
|
JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
|
|
}
|
|
if($row['rrule'])
|
|
{
|
|
$rrule = calendar_rrule::event2rrule(calendar_rrule::parseRrule($row['rrule'],true)+array(
|
|
'start' => time(),
|
|
'tzid'=> Api\DateTime::$server_timezone->getName()
|
|
));
|
|
$row['rrule'] = ''.$rrule;
|
|
}
|
|
if(!$row['scheduled'] && $cmd && $cmd->async_job_id)
|
|
{
|
|
$job = $async->read($cmd->async_job_id);
|
|
|
|
$row['scheduled'] = $job ? $job[$cmd->async_job_id]['next'] : null;
|
|
}
|
|
if ($row['status'] == admin_cmd::scheduled)
|
|
{
|
|
$row['class'] = 'AllowDelete';
|
|
}
|
|
}
|
|
//_debug_array($rows);
|
|
return $total;
|
|
}
|
|
|
|
/**
|
|
* Showing the command history and the scheduled commands
|
|
*
|
|
* @param array $content =null
|
|
*/
|
|
static function index(array $content=null)
|
|
{
|
|
$tpl = new Etemplate('admin.cmds');
|
|
|
|
if (!is_array($content))
|
|
{
|
|
$content['nm'] = Api\Cache::getSession('admin', 'cmds');
|
|
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',
|
|
'row_id' => 'id',
|
|
'default_cols' => 'title,created,creator,status',
|
|
'actions' => self::cmd_actions(),
|
|
);
|
|
}
|
|
}
|
|
elseif ($content['nm']['rows']['delete'])
|
|
{
|
|
list($id) = each($content['nm']['rows']['delete']);
|
|
unset($content['nm']['rows']);
|
|
|
|
if (($cmd = admin_cmd::read($id)))
|
|
{
|
|
$cmd->delete();
|
|
}
|
|
unset($cmd);
|
|
}
|
|
$periodic = array(
|
|
0 => 'no',
|
|
1 => 'yes'
|
|
);
|
|
$sel_options = array(
|
|
'periodic' => $periodic,
|
|
'status' => admin_cmd::$stati,
|
|
'remote_id' => admin_cmd::remote_sites(),
|
|
'type' => admin_cmd::get_cmd_labels()
|
|
);
|
|
|
|
$tpl->exec('admin.admin_cmds.index',$content,$sel_options,array(),$content);
|
|
}
|
|
|
|
/**
|
|
* 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(
|
|
|
|
);
|
|
}
|
|
|
|
/**
|
|
* get_rows for remote instances
|
|
*
|
|
* @param array $query
|
|
* @param array &$rows
|
|
* @param array &$readonlys
|
|
* @return int
|
|
*/
|
|
static function get_remotes(array $query,&$rows,&$readonlys)
|
|
{
|
|
return admin_cmd::get_remotes($query,$rows,$readonlys);
|
|
}
|
|
|
|
/**
|
|
* Showing remote administration instances
|
|
*
|
|
* @param array $content =null
|
|
*/
|
|
static function remotes(array $content=null)
|
|
{
|
|
$tpl = new Etemplate('admin.remotes');
|
|
|
|
if (!is_array($content))
|
|
{
|
|
$content['nm'] = Api\Cache::getSession('admin', 'remotes');
|
|
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',
|
|
'row_id' => 'remote_id',
|
|
'actions' => self::remote_actions(),
|
|
);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//_debug_array($content);
|
|
unset($content['msg']);
|
|
|
|
if ($content['nm']['action'])
|
|
{
|
|
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']);
|
|
}
|
|
elseif($content['remote']['button'])
|
|
{
|
|
list($button) = each($content['remote']['button']);
|
|
unset($content['remote']['button']);
|
|
switch($button)
|
|
{
|
|
case 'save':
|
|
case 'apply':
|
|
if ($content['remote']['install_id'] && !$content['remote']['config_passwd'] ||
|
|
!$content['remote']['install_id'] && $content['remote']['config_passwd'] ||
|
|
!$content['remote']['remote_hash'] && !$content['remote']['install_id'] && !$content['remote']['config_passwd'])
|
|
{
|
|
$content['msg'] = lang('You need to enter Install ID AND Password!');
|
|
break;
|
|
}
|
|
try {
|
|
$content['remote']['remote_id'] = admin_cmd::save_remote($content['remote']);
|
|
$content['msg'] = lang('Remote instance saved');
|
|
} catch (Exception $e) {
|
|
$content['msg'] = lang('Error saving').': '.$e->getMessage().' ('.$e->getCode().')';
|
|
break;
|
|
}
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* 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,
|
|
),*/
|
|
);
|
|
}
|
|
}
|