Convert Accesslog and view session to et2. Additionally, add context menu on list instead of legacy actions column

This commit is contained in:
Hadi Nategh 2014-01-20 11:27:23 +00:00
parent ac50def034
commit 9da3e4ca0d
2 changed files with 130 additions and 66 deletions

View File

@ -100,11 +100,16 @@ class admin_accesslog
if ($GLOBALS['egw']->session->sessionid_access_log == $row['sessionid'] && $query['session_list']) if ($GLOBALS['egw']->session->sessionid_access_log == $row['sessionid'] && $query['session_list'])
{ {
$readonlys['kill['.$row['sessionid'].']'] = $readonlys['selected['.$row['sessionid'].']'] = true; $readonlys['kill['.$row['sessionid'].']'] = $readonlys['selected['.$row['sessionid'].']'] = true;
$readonlys["kill[$row[sessionid]]"]= true;
$row['class'] .= ' rowNoDelete ';
} }
// do not allow to delete access log off active sessions // do not allow to delete access log off active sessions
if (!$row['lo'] && $row['session_dla'] > time()-$GLOBALS['egw_info']['server']['sessions_timeout'] && !$query['session_list']) if (!$row['lo'] && $row['session_dla'] > time()-$GLOBALS['egw_info']['server']['sessions_timeout'] && !$query['session_list'])
{ {
$readonlys['delete['.$row['sessionid'].']'] = $readonlys['selected['.$row['sessionid'].']'] = true; $readonlys['delete['.$row['sessionid'].']'] = $readonlys['selected['.$row['sessionid'].']'] = true;
$readonlys["delete[$row[sessionid]]"]= true;
$row['class'] .= ' rowNoDelete ';
} }
unset($row['session_php']); // for security reasons, do NOT give real PHP sessionid to UI unset($row['session_php']); // for security reasons, do NOT give real PHP sessionid to UI
} }
@ -128,7 +133,7 @@ class admin_accesslog
*/ */
function index(array $content=null, $msg='', $sessions_list=false) function index(array $content=null, $msg='', $sessions_list=false)
{ {
//_debug_array($content);
if (is_array($content)) $sessions_list = $content['nm']['session_list']; if (is_array($content)) $sessions_list = $content['nm']['session_list'];
// check if user has access to requested functionality // check if user has access to requested functionality
@ -154,6 +159,8 @@ class admin_accesslog
//'default_cols' => // I columns to use if there's no user or default pref (! as first char uses all but the named columns), default all columns //'default_cols' => // I columns to use if there's no user or default pref (! as first char uses all but the named columns), default all columns
'csv_fields' => false, // I false=disable csv export, true or unset=enable it with auto-detected fieldnames, 'csv_fields' => false, // I false=disable csv export, true or unset=enable it with auto-detected fieldnames,
//or array with name=>label or name=>array('label'=>label,'type'=>type) pairs (type is a eT widget-type) //or array with name=>label or name=>array('label'=>label,'type'=>type) pairs (type is a eT widget-type)
'actions' => $this->get_actions($sessions_list),
'row_id' => 'sessionid',
); );
if ((int)$_GET['account_id']) if ((int)$_GET['account_id'])
{ {
@ -169,48 +176,95 @@ class admin_accesslog
} }
$content['nm']['session_list'] = $sessions_list; $content['nm']['session_list'] = $sessions_list;
} }
elseif(isset($content['nm']['rows']['delete']) || isset($content['delete'])) error_log(__METHOD__. ' accesslog =>' . array2string($content['nm']['selected']));
if ($content['nm']['action'])
{ {
if (isset($content['nm']['rows']['delete']))
if (!count($content['nm']['selected']) && !$content['nm']['select_all'])
{ {
list($sessionid) = each($content['nm']['rows']['delete']); $msg = lang('You need to select some entries first!');
unset($content['nm']['rows']['delete']);
} }
else else
{ {
unset($content['delete']);
$sessionid = $content['nm']['rows']['selected']; if ($this->action($content['nm']['action'],$content['nm']['selected']
} ,$success,$failed,$action_msg,$msg))
$del_msg= $this->so->delete(array('sessionid' => $sessionid)); { // In case of action success
if ($sessionid && $del_msg) switch ($action_msg)
{ {
$msg = lang('%1 log entries deleted.',$del_msg); case'deleted':
$msg = lang('%1 log entries deleted.',$success);
break;
case'killed':
$msg = lang('%1 sessions killed',$success);
} }
else }
elseif($failed) // In case of action failiure
{ {
switch ($action_msg)
{
case'deleted':
$msg = lang('Error deleting log entry!'); $msg = lang('Error deleting log entry!');
break;
case'killed':
$msg = lang('Permission denied!');
} }
} }
elseif(isset($content['nm']['rows']['kill']) || isset($content['kill'])) }
}
$content['msg'] = $msg;
$content['percent'] = 100.0 * $GLOBALS['egw']->db->query(
'SELECT ((SELECT COUNT(*) FROM '.self::TABLE.' WHERE lo != 0) / COUNT(*)) FROM '.self::TABLE,
__LINE__,__FILE__)->fetchColumn();
$tmpl = new etemplate_new('admin.accesslog');
$tmpl->exec('admin.admin_accesslog.index',$content,$sel_options,$readonlys,array(
'nm' => $content['nm'],
));
}
/**
* Apply an action to multiple logs
*
* @param type $action
* @param type $checked
* @param type $use_all
* @param type $success
* @param int $failed
* @param type $action_msg
* @param type $msg
* @return type number of failed
*/
function action($action,$checked,&$success,&$failed,&$action_msg,&$msg)
{ {
if (isset($content['nm']['rows']['kill']))
$success = $failed = 0;
error_log(__METHOD__.'selected:' . array2string($checked). 'action:' . $action);
switch ($action)
{ {
list($sessionid) = each($content['nm']['rows']['kill']); case "delete":
$sessionid = array($sessionid); $action_msg = "deleted";
unset($content['nm']['rows']['kill']); $del_msg= $this->so->delete(array('sessionid' => $checked));
if ($checked && $del_msg)
{
$success = $del_msg;
} }
else else
{ {
unset($content['kill']); $failed ++;
$sessionid = $content['nm']['rows']['selected'];
} }
break;
case "kill":
$action_msg = "killed";
$sessionid = $checked;
if (($key = array_search($GLOBALS['egw']->session->sessionid_access_log, $sessionid))) if (($key = array_search($GLOBALS['egw']->session->sessionid_access_log, $sessionid)))
{ {
unset($sessionid[$key]); // dont allow to kill own sessions unset($sessionid[$key]); // dont allow to kill own sessions
} }
if ($GLOBALS['egw']->acl->check('current_sessions_access',8,'admin')) if ($GLOBALS['egw']->acl->check('current_sessions_access',8,'admin'))
{ {
$msg = lang('Permission denied!'); $failed ++;
} }
else else
{ {
@ -218,21 +272,49 @@ class admin_accesslog
{ {
$GLOBALS['egw']->session->destroy($id); $GLOBALS['egw']->session->destroy($id);
} }
$msg = lang('%1 sessions killed',count($sessionid)); $success= count($sessionid);
} }
break;
}
return !$failed;
} }
$readonlys['kill'] = !$sessions_list;
$readonlys['delete'] = $sessions_list;
$content['msg'] = $msg; /**
$content['percent'] = 100.0 * $GLOBALS['egw']->db->query( * Get actions / context menu for index
'SELECT ((SELECT COUNT(*) FROM '.self::TABLE.' WHERE lo != 0) / COUNT(*)) FROM '.self::TABLE, *
__LINE__,__FILE__)->fetchColumn(); * Changes here, require to log out, as $content['nm'] get stored in session!
*
* @return array see nextmatch_widget::egw_actions()
*/
private static function get_actions($sessions_list)
{
$tmpl = new etemplate('admin.accesslog'); if ($sessions_list)
$tmpl->exec('admin.admin_accesslog.index',$content,$sel_options,$readonlys,array( {
'nm' => $content['nm'], // error_log(__METHOD__. $sessions_list);
)); $actions= array(
'kill' => array(
'caption' => 'Kill',
'confirm' => 'Kill this session',
'confirm_multiple' => 'Kill these sessions',
'group' => $group,
),
);
}
else
{
$actions= array(
'delete' => array(
'caption' => 'Delete',
'confirm' => 'Delete this entry',
'confirm_multiple' => 'Delete these entries',
'group' => $group,
'disableClass' => 'rowNoDelete',
),
);
}
return $actions;
} }
/** /**

View File

@ -13,8 +13,6 @@
<column disabled="@no_total"/> <column disabled="@no_total"/>
<column/> <column/>
<column/> <column/>
<column/>
<column width="1%"/>
</columns> </columns>
<rows> <rows>
<row class="th"> <row class="th">
@ -26,12 +24,7 @@
<nextmatch-sortheader label="Logout" id="lo"/> <nextmatch-sortheader label="Logout" id="lo"/>
<nextmatch-header label="Total" id="total"/> <nextmatch-header label="Total" id="total"/>
<nextmatch-sortheader label="Idle" id="session_dla"/> <nextmatch-sortheader label="Idle" id="session_dla"/>
<nextmatch-sortheader label="Last action" id="session_action"/>
<nextmatch-sortheader label="User-Agent" id="user_agent"/> <nextmatch-sortheader label="User-Agent" id="user_agent"/>
<hbox>
<description align="center" value="Actions"/>
<buttononly label="Select all" onclick="toggle_all(this.form,form::name('selected[]')); return false;" options="check"/>
</hbox>
</row> </row>
<row class="row"> <row class="row">
<menulist> <menulist>
@ -44,13 +37,7 @@
<date-time id="${row}[lo]" readonly="true"/> <date-time id="${row}[lo]" readonly="true"/>
<date-duration id="${row}[total]" readonly="true" options=",hm,24"/> <date-duration id="${row}[total]" readonly="true" options=",hm,24"/>
<date-since id="${row}[session_dla]" readonly="true"/> <date-since id="${row}[session_dla]" readonly="true"/>
<description id="${row}[session_action]"/>
<description statustext="$row_cont[user_agent]" id="{$row}[user_agent]" class="userAgent"/> <description statustext="$row_cont[user_agent]" id="{$row}[user_agent]" class="userAgent"/>
<hbox align="center" options="0,0">
<button statustext="Delete this log entry" label="Delete" id="delete[$row_cont[sessionid]]" onclick="et2_dialog.confirm(widget,'Delete this log entry','Delete');" image="delete"/>
<button label="Kill" id="kill[$row_cont[sessionid]]" onclick="et2_dialog.confirm(widget,'Are you sure you want to kill this session ?','Kill');" image="close"/>
<checkbox align="right" id="selected[]" options="$row_cont[sessionid]"/>
</hbox>
</row> </row>
</rows> </rows>
</grid> </grid>
@ -74,11 +61,6 @@
<description value="Percent of users that logged out" readonly="true"/> <description value="Percent of users that logged out" readonly="true"/>
<textbox type="float" label=": %s %" id="percent" precision="1" readonly="true"/> <textbox type="float" label=": %s %" id="percent" precision="1" readonly="true"/>
</hbox> </hbox>
<hbox align="right">
<button statustext="Delete selected entries" label="Delete" id="delete" onclick="et2_dialog.confirm(widget,'Delete the selected entries','Delete')" image="delete"/>
<button label="Kill" id="kill" onclick="et2_dialog.confirm(widget,'Are you sure you want to kill this session ?','Kill')" image="close"/>
<buttononly label="Select all" onclick="toggle_all(this.form,form::name('selected[]')); return false;" options="arrow_ltr"/>
</hbox>
</row> </row>
</rows> </rows>
</grid> </grid>