- Moved access log over to 3 tier design\n- edit / view account hooks now support 3 tier design\n- Added view account access history to view account (via hook)\n- Added nexmatchs to access log\n

This commit is contained in:
jengo 2001-07-13 07:02:34 +00:00
parent 608b620212
commit 68577e4d12
15 changed files with 441 additions and 191 deletions

View File

@ -1,108 +0,0 @@
<?php
/**************************************************************************\
* phpGroupWare - administration *
* http://www.phpgroupware.org *
* -------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
$phpgw_info['flags'] = array(
'currentapp' => 'admin',
'enable_nextmatchs_class' => True
);
include('../header.inc.php');
$p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
$p->set_file(array('current' => 'currentusers.tpl'));
$p->set_block('current','list','list');
$p->set_block('current','row','row');
if (! $start)
{
$start = 0;
}
$phpgw->db->query("select count(*) from phpgw_sessions where session_flags != 'A'",__LINE__,__FILE__);
$phpgw->db->next_record();
$total = $phpgw->db->f(0);
$p->set_var('lang_current_users',lang('List of current users'));
$p->set_var('bg_color',$phpgw_info['theme'][bg_color]);
$p->set_var('left_next_matchs',$phpgw->nextmatchs->left('/admin/currentusers.php',$start,$total));
$p->set_var('right_next_matchs',$phpgw->nextmatchs->right('/admin/currentusers.php',$start,$total));
$p->set_var('th_bg',$phpgw_info['theme']['th_bg']);
$p->set_var('sort_loginid',$phpgw->nextmatchs->show_sort_order($sort,'session_lid',$order,
'/admin/currentusers.php',lang('LoginID')));
$p->set_var('sort_ip',$phpgw->nextmatchs->show_sort_order($sort,'session_ip',$order,
'/admin/currentusers.php',lang('IP')));
$p->set_var('sort_login_time',$phpgw->nextmatchs->show_sort_order($sort,'session_logintime',$order,
'/admin/currentusers.php',lang('Login Time')));
$p->set_var('sort_action',$phpgw->nextmatchs->show_sort_order($sort,'session_action',$order,
'/admin/currentusers.php',lang('Action')));
$p->set_var('sort_idle',$phpgw->nextmatchs->show_sort_order($sort,'session_dla',$order,
'/admin/currentusers.php',lang('idle')));
$p->set_var('lang_kill',lang('Kill'));
if ($order)
{
$ordermethod = "order by $order $sort";
}
else
{
$ordermethod = 'order by session_dla asc';
}
$phpgw->db->limit_query("select * from phpgw_sessions where session_flags != 'A' $ordermethod ",$start,__LINE__,__FILE__);
$i = 0;
while ($phpgw->db->next_record())
{
$tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color);
$p->set_var('tr_color',$tr_color);
if (ereg('@',$phpgw->db->f('session_lid')))
{
$t = split('@',$phpgw->db->f('session_lid'));
$loginid = $t[0];
}
else
{
$loginid = $phpgw->db->f('session_lid');
}
$p->set_var('row_loginid',$loginid);
$p->set_var('row_ip',$phpgw->db->f('session_ip'));
$p->set_var('row_logintime',$phpgw->common->show_date($phpgw->db->f('session_logintime')));
if($phpgw->db->f('session_action'))
{
$p->set_var('row_action',$phpgw->strip_html($phpgw->db->f('session_action')));
}
else
{
$p->set_var('row_action','&nbsp;');
}
$p->set_var('row_idle',gmdate('G:i:s',(time() - $phpgw->db->f('session_dla'))));
if ($phpgw->db->f('session_id') != $phpgw_info['user']['sessionid'])
{
$p->set_var('row_kill','<a href="' . $phpgw->link('/admin/killsession.php','ksession='
. $phpgw->db->f('session_id') . '&kill=true') . '">' . lang('Kill').'</a>');
}
else
{
$p->set_var('row_kill','&nbsp;');
}
$p->parse('rows','row',True);
}
$p->pparse('out','list');
$phpgw->common->phpgw_footer();
?>

View File

@ -403,29 +403,43 @@
}
}
function display_section($appname,$title,$file)
{
global $phpgw, $phpgw_info, $account_id;
$i = 0;
$color[1] = $phpgw_info['theme']['row_off'];
$color[0] = $phpgw_info['theme']['row_on'];
while(list($text,$url) = each($file))
{
$url = $phpgw->link($url,"account_id=$account_id");
section_item($url,lang($text),$color[$i%2]);
$i++;
}
}
function section_item($pref_link='',$pref_text='', $bgcolor)
{
global $phpgw, $phpgw_info, $t;
$t->set_var('pref_link',$pref_link);
$t->set_var('pref_text',$pref_text);
$t->set_var('tr_color',$bgcolor);
$t->parse('rows','link_row',True);
}
function section_item($pref_link='',$pref_text='', $bgcolor)
{
global $phpgw, $phpgw_info, $t;
$t->set_var('row_link',$pref_link);
$t->set_var('row_text',$pref_text);
$t->set_var('tr_color',$bgcolor);
$t->parse('rows','link_row',True);
}
// $file must be in the follow format:
// $file = Array(
// 'Login History' => array('/index.php','menuaction=admin.uiaccess_history.list')
// );
// This allows extra data to be sent along
function display_section($appname,$title,$file)
{
global $phpgw, $phpgw_info, $account_id;
$i = 0;
$color[1] = $phpgw_info['theme']['row_off'];
$color[0] = $phpgw_info['theme']['row_on'];
while(list($text,$_url) = each($file))
{
list($url,$extra_data) = $_url;
if ($extra_data)
{
$link = $phpgw->link($url,'account_id=' . $account_id . '&' . $extra_data);
}
else
{
$link = $phpgw->link($url,'account_id=' . $account_id);
}
section_item($link,lang($text),$color[$i%2]);
$i++;
}
}
// todo
// not needed if i use the same file for new users too

View File

@ -0,0 +1,79 @@
<?php
class boaccess_history
{
function boaccess_history()
{
$this->so = createobject('admin.soaccess_history');
}
function list_history($account_id,$start,$order,$sort)
{
global $phpgw;
$records = $this->so->list_history($account_id,$start,$order,$sort);
while (is_array($records) && list(,$record) = each($records))
{
if ($record['li'] && $record['lo'])
{
$total = ($record['lo'] - $record['li']);
if ($total > 86400 && $total > 172800)
{
$total = gmdate('z \d\a\y\s - G:i:s',$total);
}
else if ($total > 172800)
{
$total = gmdate('z \d\a\y - G:i:s',$total);
}
else
{
$total = gmdate('G:i:s',$total);
}
}
if ($record['li'])
{
$record['li'] = $phpgw->common->show_date($record['li']);
}
if ($record['lo'] != '')
{
$record['lo'] = $phpgw->common->show_date($record['lo']);
}
if (ereg('@',$record['loginid']))
{
$t = split('@',$record['loginid']);
$record['loginid'] = $t[0];
}
$_records[] = array(
'loginid' => $record['loginid'],
'ip' => $record['ip'],
'li' => $record['li'],
'lo' => $record['lo'],
'account_id' => $record['account_id'],
'total' => $total
);
}
return $_records;
}
function grab_fullname($account_id)
{
global $phpgw;
$acct = createobject('phpgwapi.accounts',$account_id);
$acct->read_repository();
return $phpgw->common->display_fullname($acct->data['account_lid'],$acct->data['firstname'],$acct->data['lastname']);
}
function total($account_id)
{
return $this->so->total($account_id);
}
function return_logged_out($account_id)
{
return $this->so->return_logged_out($account_id);
}
}

View File

@ -0,0 +1,62 @@
<?php
class soaccess_history
{
var $db;
function soaccess_history()
{
global $phpgw;
$this->db = $phpgw->db;
}
function test_account_id($account_id)
{
if ($account_id)
{
return " where account_id='$account_id'";
}
}
function list_history($account_id,$start,$order,$sort)
{
$where = $this->test_account_id($account_id);
$this->db->limit_query("select loginid,ip,li,lo,account_id from phpgw_access_log $where order by li desc",$start,__LINE__,__FILE__);
while ($this->db->next_record())
{
$records[] = array(
'loginid' => $this->db->f('loginid'),
'ip' => $this->db->f('ip'),
'li' => $this->db->f('li'),
'lo' => $this->db->f('lo'),
'account_id' => $this->db->f('account_id')
);
}
return $records;
}
function total($account_id)
{
$where = $this->test_account_id($account_id);
$this->db->query("select count(*) from phpgw_access_log $where");
$this->db->next_record();
return $this->db->f(0);
}
function return_logged_out($account_id)
{
if ($account_id)
{
$where = "and account_id='$account_id'";
}
$this->db->query("select count(*) from phpgw_access_log where lo!='' $where");
$this->db->next_record();
return $this->db->f(0);
}
}

View File

@ -0,0 +1,101 @@
<?php
class uiaccess_history
{
var $template;
var $public_functions = array(
'list_history' => True
);
function uiaccess_history()
{
global $phpgw;
$this->bo = createobject('admin.boaccess_history');
$this->nextmatchs = createobject('phpgwapi.nextmatchs');
$this->template = $phpgw->template;
$this->template->set_file(array(
'accesslog' => 'accesslog.tpl'
));
$this->template->set_block('accesslog','list');
$this->template->set_block('accesslog','row');
$this->template->set_block('accesslog','row_empty');
}
function list_history()
{
global $account_id, $phpgw, $phpgw_info, $start, $sort, $order;
$phpgw->common->phpgw_header();
echo parse_navbar();
$total_records = $this->bo->total($account_id);
$this->template->set_var('th_bg',$phpgw_info['theme']['th_bg']);
$this->template->set_var('nextmatchs_left',$this->nextmatchs->left('/index.php',$start,$total_records,'&menuaction=admin.uiaccess_history.list_history&account_id=' . $account_id));
$this->template->set_var('nextmatchs_right',$this->nextmatchs->right('/index.php',$start,$total_records,'&menuaction=admin.uiaccess_history.list_history&account_id=' . $account_id));
if ($account_id)
{
$this->template->set_var('link_return_to_view_account','<a href="' . $phpgw->link('/admin/viewaccount.php','account_id=' . $account_id) . '">' . lang('Return to view account') . '</a>');
$fullname = $this->bo->grab_fullname($account_id);
$this->template->set_var('lang_last_x_logins',lang('Last %1 logins for %2',$total_records,$fullname));
}
else
{
$this->template->set_var('lang_last_x_logins',lang('Last x logins',$total_records));
}
$this->template->set_var('showing',$this->nextmatchs->show_hits($total_records,$start));
$this->template->set_var('lang_loginid',lang('LoginID'));
$this->template->set_var('lang_ip',lang('IP'));
$this->template->set_var('lang_login',lang('Login'));
$this->template->set_var('lang_logout',lang('Logout'));
$this->template->set_var('lang_total',lang('Total'));
$records = $this->bo->list_history($account_id,$start,$order,$sort);
while (is_array($records) && list(,$record) = each($records))
{
$this->nextmatchs->template_alternate_row_color(&$this->template);
$this->template->set_var('row_loginid',$record['loginid']);
$this->template->set_var('row_ip',$record['ip']);
$this->template->set_var('row_li',$record['li']);
$this->template->set_var('row_lo',$record['lo']);
$this->template->set_var('row_total',$record['total']);
$this->template->fp('rows','row',True);
}
if (! $total_records && $account_id)
{
$this->nextmatchs->template_alternate_row_color(&$this->template);
$this->template->set_var('row_message',lang('No login history exists for this user'));
$this->template->fp('rows','row_empty',True);
}
$loggedout = $this->bo->return_logged_out($account_id);
if ($total_records)
{
$percent = round((10000 * ($loggedout / $total_records)) / 100);
}
else
{
$percent = '0';
}
$this->template->set_var('bg_color',$phpgw_info['themes']['bg_color']);
$this->template->set_var('footer_total',lang('Total records') . ': ' . $total_records);
if ($account_id)
{
$this->template->set_var('lang_percent',lang('Percent this user has logged out') . ': ' . $percent . '%');
}
else
{
$this->template->set_var('lang_percent',lang('Percent of users that logged out') . ': ' . $percent . '%');
}
$this->template->pfp('out','list');
}
}

View File

@ -15,17 +15,17 @@
// Only Modify the $file and $title variables.....
$title = $appname;
$file = Array(
'Site Configuration' => $phpgw->link('/admin/config.php','appname=' . $appname),
'User Accounts' => $phpgw->link('/admin/accounts.php'),
'User Groups' => $phpgw->link('/admin/groups.php'),
'Applications' => $phpgw->link('/admin/applications.php'),
'Global Categories' => $phpgw->link('/admin/categories.php'),
'Change Main Screen Message' => $phpgw->link('/admin/mainscreen_message.php'),
'View Sessions' => $phpgw->link('/admin/currentusers.php'),
'View Access Log' => $phpgw->link('/admin/accesslog.php'),
'phpInfo' => $phpgw->link('/admin/phpinfo.php')
'Site Configuration' => $phpgw->link('/admin/config.php','appname=' . $appname),
'User Accounts' => $phpgw->link('/admin/accounts.php'),
'User Groups' => $phpgw->link('/admin/groups.php'),
'Applications' => $phpgw->link('/admin/applications.php'),
'Global Categories' => $phpgw->link('/admin/categories.php'),
'Change Main Screen Message' => $phpgw->link('/admin/mainscreen_message.php'),
'View Sessions' => $phpgw->link('/admin/currentusers.php'),
'View Access Log' => $phpgw->link('/index.php','menuaction=admin.uiaccess_history.list_history'),
'phpInfo' => $phpgw->link('/admin/phpinfo.php')
);
//Do not modify below this line
display_section($appname,$title,$file);
}
?>
?>

View File

@ -3,7 +3,7 @@
// Only Modify the $file and $title variables.....
$title = $appname;
$file = Array(
'userdata' => '/admin/editaccount.php'
'userdata' => array('/admin/editaccount.php','')
);
//Do not modify below this line
display_section($appname,$title,$file);

View File

@ -0,0 +1,8 @@
<?php
$title = $appname;
$file = Array(
'Login History' => array('/index.php','menuaction=admin.uiaccess_history.list_history')
);
display_section($appname,$title,$file);
?>

View File

@ -1,10 +1,25 @@
<!-- BEGIN list -->
<p>
{link_return_to_view_account}
<table border="0" align="center" width="75%">
<tr>
<td bgcolor="{th_bg}" align="center" colspan="5">
<td align="left">
{lang_last_x_logins}
</td>
<td align="center" colspan="3">
{showing}
</td>
<td align="right">
<table border="0">
<tr>
{nextmatchs_left}
&nbsp;
{nextmatchs_right}
</tr>
</table>
</td>
</tr>
<tr bgcolor="{th_bg}">
<td>{lang_loginid}</td>
@ -34,4 +49,10 @@
<td>{row_lo}</td>
<td>{row_total}</td>
</tr>
<!-- END row -->
<!-- END row -->
<!-- BEGIN row_empty -->
<tr bgcolor="{tr_color}">
<td align="center" colspan="5">{row_message}</td>
</tr>
<!-- END row_empty -->

View File

@ -6,53 +6,56 @@
<table border="0" width="95%">
<tr>
<td valign="top">
<table border="0" width="100%">
<tr bgcolor="{th_bg}">
<td colspan="4">&nbsp;</td>
<td>&nbsp;</td>
</tr>
{rows}
{rows}
</table>
</td>
<td>
<table border=0 width=100%>
<tr bgcolor="{th_bg}">
<td colspan="4"><b>{lang_action}</b></td>
</tr>
<tr bgcolor="{tr_color1}">
<td width="25%">{lang_loginid}</td>
<td width="25%">{account_lid}&nbsp;</td>
<td width="25%">{lang_account_active}:</td>
<td width="25%">{account_status}</td>
</tr>
<tr bgcolor="{tr_color2}">
<td>{lang_firstname}</td>
<td>{account_firstname}&nbsp;</td>
<td>{lang_lastname}</td>
<td>{account_lastname}&nbsp;</td>
</tr>
{password_fields}
<tr bgcolor="{tr_color2}">
<td>{lang_groups}</td>
<td>{groups_select}&nbsp;</td>
<td>{lang_file_space}</td>
<td>{account_file_space}{account_file_space_select}</td>
</tr>
<tr bgcolor="{tr_color1}">
<td>{lang_expires}</td>
<td colspan=3>{input_expires}&nbsp;</td>
</tr>
{permissions_list}
{form_buttons}
</table>
<table border=0 width=100%>
<tr bgcolor="{th_bg}">
<td colspan="4"><b>{lang_action}</b></td>
</tr>
<tr bgcolor="{tr_color1}">
<td width="25%">{lang_loginid}</td>
<td width="25%">{account_lid}&nbsp;</td>
<td width="25%">{lang_account_active}:</td>
<td width="25%">{account_status}</td>
</tr>
<tr bgcolor="{tr_color2}">
<td>{lang_firstname}</td>
<td>{account_firstname}&nbsp;</td>
<td>{lang_lastname}</td>
<td>{account_lastname}&nbsp;</td>
</tr>
{password_fields}
<tr bgcolor="{tr_color2}">
<td>{lang_groups}</td>
<td>{groups_select}&nbsp;</td>
<td>{lang_file_space}</td>
<td>{account_file_space}{account_file_space_select}</td>
</tr>
<tr bgcolor="{tr_color1}">
<td>{lang_expires}</td>
<td colspan=3>{input_expires}&nbsp;</td>
</tr>
{permissions_list}
{form_buttons}
</table>
</td>
</tr>
</table>
@ -87,6 +90,6 @@
<!-- BEGIN link_row -->
<tr bgcolor="{tr_color}">
<td colspan="2">&nbsp;&nbsp;<a href="{pref_link}">{pref_text}</a></td>
<td>&nbsp;<a href="{row_link}">{row_text}</a></td>
</tr>
<!-- END link_row -->

View File

@ -31,11 +31,50 @@
Header('Location: ' . $phpgw->link('/admin/accounts.php'));
}
function section_item($pref_link='',$pref_text='', $bgcolor)
{
global $phpgw, $phpgw_info, $t;
$t->set_var('row_link',$pref_link);
$t->set_var('row_text',$pref_text);
$t->set_var('tr_color',$bgcolor);
$t->parse('rows','link_row',True);
}
// $file must be in the follow format:
// $file = Array(
// 'Login History' => array('/index.php','menuaction=admin.uiaccess_history.list')
// );
// This allows extra data to be sent along
function display_section($appname,$title,$file)
{
global $phpgw, $phpgw_info, $account_id;
$i = 0;
$color[1] = $phpgw_info['theme']['row_off'];
$color[0] = $phpgw_info['theme']['row_on'];
while(list($text,$_url) = each($file))
{
list($url,$extra_data) = $_url;
if ($extra_data)
{
$link = $phpgw->link($url,'account_id=' . $account_id . '&' . $extra_data);
}
else
{
$link = $phpgw->link($url,'account_id=' . $account_id);
}
section_item($link,lang($text),$color[$i%2]);
$i++;
}
}
$t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
$t->set_unknowns('remove');
$t->set_file(array('account' => 'account_form.tpl'));
$t->set_block('account','form','form');
$t->set_block('account','form_logininfo','form_logininfo');
$t->set_block('account','form_logininfo');
$t->set_block('account','link_row');
$t->set_var('th_bg',$phpgw_info['theme']['th_bg']);
$t->set_var('tr_color1',$phpgw_info['theme']['row_on']);
@ -186,7 +225,7 @@
$t->set_var('permissions_list',$appRightsOutput);
$phpgw->common->hook('view_account');
$t->pfp('out','form');
$phpgw->common->phpgw_footer();
?>

View File

@ -276,7 +276,7 @@
. "')",__LINE__,__FILE__);
$phpgw->db->query("insert into phpgw_access_log values ('" . $this->sessionid . "','"
. "$login','" . $user_ip . "','$now','') ",__LINE__,__FILE__);
. "$login','" . $user_ip . "','$now','','" . $this->account_id . "')",__LINE__,__FILE__);
$this->appsession('account_previous_login','phpgwapi',$phpgw->auth->previous_login);
$phpgw->auth->update_lastlogin($this->account_id,$user_ip);

View File

@ -14,7 +14,7 @@
/* Basic information about this app */
$setup_info['phpgwapi']['name'] = 'phpgwapi';
$setup_info['phpgwapi']['title'] = 'phpgwapi';
$setup_info['phpgwapi']['version'] = '0.9.13.004';
$setup_info['phpgwapi']['version'] = '0.9.13.005';
$setup_info['phpgwapi']['versions']['current_header'] = '1.16';
$setup_info['phpgwapi']['enable'] = 3;
$setup_info['phpgwapi']['app_order'] = 1;

View File

@ -116,7 +116,8 @@
'loginid' => array('type' => 'varchar', 'precision' => 30),
'ip' => array('type' => 'varchar', 'precision' => 30),
'li' => array('type' => 'int', 'precision' => 4),
'lo' => array('type' => 'varchar', 'precision' => 255)
'lo' => array('type' => 'varchar', 'precision' => 255),
'account_id' => array('type' => 'int', 'precision' => 4, 'default' => 0, 'nullable' => False)
),
'pk' => array(),
'fk' => array(),

View File

@ -1898,4 +1898,34 @@
return $setup_info['phpgwapi']['currentver'];
}
?>
$test[] = '0.9.13.004';
function phpgwapi_upgrade0_9_13_004()
{
global $setup_info, $phpgw_setup;
$phpgw_setup->oProc->AddColumn('phpgw_access_log','account_id',array('type' => 'int', 'precision' => 4, 'default' => 0, 'nullable' => False));
// !! NOTE !!
// This does NOT work with LDAP, if they have fully moved there accounts over
// they will not be able to use the new features for old records.
// This is why I decied to do this now, instead of later.
// If you have a better soultion, let me know. (jengo)
$db2 = $phpgw_setup->db;
$phpgw_setup->oProc->query("select * from phpgw_access_log");
while ($phpgw_setup->oProc->next_record())
{
$lid = explode('@',$phpgw_setup->oProc->f('loginid'));
$account_lid = $lid[0];
$db2->query("select account_id from phpgw_accounts where account_lid='$account_lid'");
$db2->next_record();
$db2->query("update phpgw_access_log set account_id='" . $db2->f('account_id')
. "' where sessionid='" . $phpgw_setup->oProc->f('sessionid') . "'");
}
$setup_info['phpgwapi']['currentver'] = '0.9.13.005';
return $setup_info['phpgwapi']['currentver'];
}
?>