#30 adminpanel userlogs

This commit is contained in:
Ulrich Block 2014-09-21 14:22:48 +02:00
parent 3ace626e57
commit a05c99b73b
4 changed files with 65 additions and 174 deletions

View File

@ -74,7 +74,10 @@ if ($ui->smallletters('w', 9, 'get') == 'datatable') {
$sSortDir = ($ui->smallletters('sSortDir_0', 4, 'get') == 'desc') ? 'DESC' : 'ASC';
$sSearch = (strlen($ui->escaped('sSearch', 'get')) > 0) ? $ui->escaped('sSearch', 'get') : false;
if ($ui->smallletters('d', 7, 'get') == 'userlog' and isset($user_id) and $pa['log']) {
// Userlog
if (($ui->smallletters('d', 7, 'get') == 'userlog' and isset($user_id)) or ($ui->smallletters('d', 12, 'get') =='adminuserlog' and isset($admin_id)) and $pa['log']) {
$adminLookup = ($ui->smallletters('d', 12, 'get') =='adminuserlog' and isset($admin_id)) ? true : false;
require_once(EASYWIDIR . '/stuff/ajax/datatable_userlog.php');

View File

@ -39,136 +39,9 @@ if ((!isset($admin_id) or $main != 1) or (isset($admin_id) and !$pa['log'])) {
header('Location: admin.php');
die('No acces');
}
$sprache = getlanguagefile('logs', $user_language,$reseller_id);
$gssprache = getlanguagefile('gserver', $user_language,$reseller_id);
$table = array();
if (!isset($amount)) {
$amount = 20;
}
if (!isset($start)) {
$start = 0;
}
configureDateTables('', '0, "desc"', 'ajax.php?w=datatable&d=adminuserlog');
if ($reseller_id == 0) {
$query = $sql->prepare("SELECT `userid`,`subuser`,`reseller`,`username`,`usertype`,`useraction`,`ip`,`hostname`,`logdate` FROM `userlog` WHERE `usertype` LIKE :usertype AND (`resellerid`=:reseller_id OR `resellerid`=`userid`) ORDER BY `id` DESC LIMIT $start,$amount");
} else if ($reseller_id != 0 and $admin_id != $reseller_id) {
$query = $sql->prepare("SELECT `userid`,`subuser`,`reseller`,`username`,`usertype`,`useraction`,`ip`,`hostname`,`logdate` FROM `userlog` WHERE `usertype` LIKE :usertype AND `resellerid`=:reseller_id GROUP BY `userid`,`subuser`,`reseller`,`username`,`usertype`,`useraction`,`ip`,`logdate` ORDER BY `id` DESC LIMIT $start,$amount");
} else {
$query = $sql->prepare("SELECT l.`userid`,l.`subuser`,l.`reseller`,l.`username`,l.`usertype`,l.`useraction`,l.`ip`,l.`hostname`,l.`logdate` FROM `userdata` u LEFT JOIN `userlog` l ON u.`id`=l.`resellerid` OR u.`resellerid`=l.`resellerid` WHERE l.`usertype` LIKE :usertype AND u.`resellerid`=:reseller_id GROUP BY l.`userid`,l.`subuser`,l.`reseller`,l.`username`,l.`usertype`,l.`useraction`,l.`ip`,l.`logdate` ORDER BY l.`id` DESC LIMIT $start,$amount");
}
$query2 = $sql->prepare("SELECT `cname`,`resellerid` FROM `userdata` WHERE `id`=? LIMIT 1");
if ($reseller_id != 0 and $admin_id != $reseller_id) {
$reseller_id = $admin_id;
}
if (empty($where)) {
$query->execute(array(':usertype' => "%", ':reseller_id' => $reseller_id));
} else {
$query->execute(array(':usertype' => $where, ':reseller_id' => $reseller_id));
}
foreach ($query->fetchall() as $row) {
$usertype = $row['usertype'];
$userid = $row['userid'];
$subuser = $row['subuser'];
$reseller = $row['reseller'];
if ($usertype == 'admin') {
if ($subuser==0) {
$username = $row['username'];
} else {
$query2->execute(array($subuser));
$username = $row['username'] . ' ↔ ' . $query2->fetchColumn();
}
if ($reseller_id == 0) {
$ip = $row['ip'];
$hostname = $row['hostname'];
} else if ($reseller_id==$admin_id) {
if ($subuser==0) {
$ip = $row['ip'];
$hostname = $row['hostname'];
} else {
$ip = '';
$hostname = '';
}
} else if ($reseller_id != 0 and $reseller_id != $admin_id and $subuser==0) {
$ip = $row['ip'];
$hostname = $row['hostname'];
} else {
$ip = '';
$hostname = '';
}
} else {
$ip = $row['ip'];
$hostname = $row['hostname'];
if ($subuser == 0) {
$username = $row['username'];
} else {
$query2->execute(array($subuser));
$username = $row['username'] . ' ↔ ' . $query2->fetchColumn();
}
}
$useraction = $row['useraction'];
$placeholders=array('%%', '%add%', '%dl%', '%del%', '%mod%', '%start%', '%restart%', '%stop%', '%upd%', '%fail%', '%ok%', '%psw%', '%cfg%', '%import%', '%reinstall%', '%backup%', '%use%');
$replace=array('', $gsprache->add.': ', $gsprache->del.': ', $gsprache->del.': ', $gsprache->mod.': ', $gsprache->start.': ', $gsprache->start.': ', $gsprache->stop.': ', $gsprache->update.': ','','', $gssprache->password.': ', $gssprache->config.': ', $gsprache->import.': ', $gssprache->reinstall.': ', $gsprache->backup, $gsprache->use.': ');
$replacedpics = str_replace($placeholders,$replace,$useraction);
$placeholders=array('%modules%', '%voserver%', '%gserver%', '%user%', '%group%', '%fastdl%', '%master%', '%user%', '%root%', '%addon%', '%settings%', '%vserver%', '%ticket_subject%', '%reseller%', '%virtual%', '%eac%', '%resync%', '%virtualimage%', '%template%', '%voserver%', '%emailsettings%', '%dns%', '%tsdns%', '%pmode%', '%comment%');
$replace=array($gsprache->modules, $gsprache->voiceserver, $gsprache->gameserver, $gsprache->user, $gsprache->groups, $gsprache->fastdownload, $gsprache->master, $gsprache->user, $gsprache->root, $gsprache->addon2, $gsprache->settings, $gsprache->virtual, $gsprache->support, $gsprache->reseller, $gsprache->hostsystem, 'Easy Anti Cheat', $gssprache->resync, $gsprache->virtual . ' ' . $gsprache->template, $gsprache->template, $gsprache->voiceserver, 'E-Mail '.$gsprache->settings, 'TSDNS', 'TSDNS', $gssprache->protect, $gsprache->comments);
$replacedwords=str_replace($placeholders,$replace,$replacedpics);
$logdate=explode(' ', $row['logdate']);
$table[] = array('logday' => $logdate[0], 'loghour' => $logdate[1], 'ip' => $ip,'hostname' => $hostname, 'username' => $username, 'useraction' => $replacedwords);
}
$next = $start + $amount;
if ($reseller_id == 0) {
$query = $sql->prepare("SELECT COUNT(`id`) AS `amount` FROM `userlog` WHERE `usertype` LIKE :usertype AND (`resellerid`=:reseller_id OR `resellerid`=`userid`)");
$requestid = $reseller_id;
} else if ($reseller_id != 0 and $admin_id != $reseller_id) {
$query = $sql->prepare("SELECT COUNT(`id`) AS `amount` FROM `userlog` WHERE `usertype` LIKE :usertype AND `resellerid`=:reseller_id");
$requestid = $admin_id;
} else {
$query = $sql->prepare("SELECT COUNT(l.`id`) AS `amount` FROM `userdata` u LEFT JOIN `userlog` l ON u.`id`=l.`resellerid` OR u.`resellerid`=l.`resellerid` WHERE l.`usertype` LIKE :usertype AND u.`resellerid`=:reseller_id GROUP BY l.`userid`,l.`subuser`,l.`reseller`,l.`username`,l.`usertype`,l.`useraction`,l.`ip`,l.`logdate`");
$requestid = $reseller_id;
}
if (empty($where)) {
$query->execute(array(':usertype' => "%", ':reseller_id' => $requestid));
} else {
$query->execute(array(':usertype' => $where, ':reseller_id' => $requestid));
}
$colcount = $query->fetchColumn();
$vor = ($colcount>$next) ? $start + $amount : $start;
$back = $start - $amount;
$zur = ($back >= 0) ? $start - $amount : $start;
$pageamount = ceil($colcount / $amount);
$link = '<a href="admin.php?w=lo&amp;a=' . $amount;
$link .= ($start == 0) ? '&amp;p=0" class="bold">1</a>' : '&amp;p=0">1</a>';
$pages[] = $link;
$i = 2;
while ($i <= $pageamount) {
$selectpage = ($i - 1) * $amount;
$pages[] = ($start == $selectpage) ? '<a href="admin.php?w=lo&amp;a=' . $amount . '&p=' . $selectpage . '" class="bold">' . $i . '</a>' : '<a href="admin.php?w=lo&amp;a=' . $amount . '&p=' . $selectpage . '">' . $i . '</a>';
$i++;
}
$pages = implode(',', $pages);
$template_file = 'admin_logs.tpl';

View File

@ -53,14 +53,27 @@ if ($sSearch) {
$sSearch = str_replace($replace, $placeholders, str_replace($replace2, $placeholders2, $sSearch));
}
$query = $sql->prepare("SELECT COUNT(1) AS `amount` FROM `userlog` WHERE `usertype`='user' AND `userid`=? AND `resellerid`=?");
$query->execute(array($user_id, $reseller_id));
if ($adminLookup) {
$query = $sql->prepare("SELECT COUNT(1) AS `amount` FROM `userlog` WHERE `resellerid`=?");
$query->execute(array($resellerLockupID));
} else {
$query = $sql->prepare("SELECT COUNT(1) AS `amount` FROM `userlog` WHERE `usertype`='user' AND `userid`=? AND `resellerid`=?");
$query->execute(array($user_id, $reseller_id));
}
$array['iTotalRecords'] = $query->fetchColumn();
if ($sSearch) {
$query = $sql->prepare("SELECT COUNT(1) AS `amount` FROM `userlog` AS l LEFT JOIN `userdata` AS s ON s.`id`=l.`subuser` AND l.`subuser`!=0 WHERE l.`usertype`='user' AND l.`userid`=:userid AND l.`resellerid`=:resellerid AND (`username` LIKE :search OR `cname` LIKE :search OR `ip` LIKE :search OR `logdate` LIKE :search OR `useraction` LIKE :search)");
$query->execute(array(':search' => '%' . $sSearch . '%', ':userid' => $user_id, ':resellerid' => $reseller_id));
if ($adminLookup) {
$query = $sql->prepare("SELECT COUNT(1) AS `amount` FROM `userlog` AS l LEFT JOIN `userdata` AS s ON s.`id`=l.`subuser` AND l.`subuser`!=0 WHERE l.`resellerid`=:resellerid AND (`username` LIKE :search OR `cname` LIKE :search OR `ip` LIKE :search OR `logdate` LIKE :search OR `useraction` LIKE :search)");
$query->execute(array(':search' => '%' . $sSearch . '%', ':resellerid' => $resellerLockupID));
} else {
$query = $sql->prepare("SELECT COUNT(1) AS `amount` FROM `userlog` AS l LEFT JOIN `userdata` AS s ON s.`id`=l.`subuser` AND l.`subuser`!=0 WHERE l.`usertype`='user' AND l.`userid`=:userid AND l.`resellerid`=:resellerid AND (`username` LIKE :search OR `cname` LIKE :search OR `ip` LIKE :search OR `logdate` LIKE :search OR `useraction` LIKE :search)");
$query->execute(array(':search' => '%' . $sSearch . '%', ':userid' => $user_id, ':resellerid' => $reseller_id));
}
$array['iTotalDisplayRecords'] = $query->fetchColumn();
} else {
$array['iTotalDisplayRecords'] = $array['iTotalRecords'];
}
@ -76,16 +89,29 @@ if (isset($orderFields[$iSortCol]) and is_array($orderFields[$iSortCol])) {
}
if ($sSearch) {
$query = $sql->prepare("SELECT `subuser`,`username`,`useraction`,`ip`,`logdate`,`cname` FROM `userlog` AS l LEFT JOIN `userdata` AS s ON s.`id`=l.`subuser` AND l.`subuser`!=0 WHERE l.`usertype` IN ('user','cron') AND l.`userid`=:userid AND l.`resellerid`=:resellerid AND (`username` LIKE :search OR `cname` LIKE :search OR `ip` LIKE :search OR `logdate` LIKE :search OR `useraction` LIKE :search) ORDER BY {$orderBy} LIMIT {$iDisplayStart},{$iDisplayLength}");
$query->execute(array(':search' => '%' . $sSearch . '%', ':userid' => $user_id, ':resellerid' => $reseller_id));
if ($adminLookup) {
$query = $sql->prepare("SELECT `subuser`,`username`,`useraction`,`ip`,`logdate`,`cname` FROM `userlog` AS l LEFT JOIN `userdata` AS s ON s.`id`=l.`subuser` AND l.`subuser`!=0 WHERE l.`resellerid`=:resellerid AND (`username` LIKE :search OR `cname` LIKE :search OR `ip` LIKE :search OR `logdate` LIKE :search OR `useraction` LIKE :search) ORDER BY {$orderBy} LIMIT {$iDisplayStart},{$iDisplayLength}");
$query->execute(array(':search' => '%' . $sSearch . '%', ':resellerid' => $resellerLockupID));
} else {
$query = $sql->prepare("SELECT `subuser`,`username`,`useraction`,`ip`,`logdate`,`cname` FROM `userlog` AS l LEFT JOIN `userdata` AS s ON s.`id`=l.`subuser` AND l.`subuser`!=0 WHERE l.`usertype` IN ('user','cron') AND l.`userid`=:userid AND l.`resellerid`=:resellerid AND (`username` LIKE :search OR `cname` LIKE :search OR `ip` LIKE :search OR `logdate` LIKE :search OR `useraction` LIKE :search) ORDER BY {$orderBy} LIMIT {$iDisplayStart},{$iDisplayLength}");
$query->execute(array(':search' => '%' . $sSearch . '%', ':userid' => $user_id, ':resellerid' => $reseller_id));
}
} else {
$query = $sql->prepare("SELECT `subuser`,`username`,`useraction`,`ip`,`logdate`,`cname` FROM `userlog` AS l LEFT JOIN `userdata` AS s ON s.`id`=l.`subuser` AND l.`subuser`!=0 WHERE l.`usertype` IN ('user','cron') AND l.`userid`=? AND l.`resellerid`=? ORDER BY {$orderBy} LIMIT {$iDisplayStart},{$iDisplayLength}");
$query->execute(array($user_id, $reseller_id));
if ($adminLookup) {
$query = $sql->prepare("SELECT `subuser`,`username`,`useraction`,`ip`,`logdate`,`cname` FROM `userlog` AS l LEFT JOIN `userdata` AS s ON s.`id`=l.`subuser` AND l.`subuser`!=0 WHERE l.`resellerid`=? ORDER BY {$orderBy} LIMIT {$iDisplayStart},{$iDisplayLength}");
$query->execute(array($resellerLockupID));
} else {
$query = $sql->prepare("SELECT `subuser`,`username`,`useraction`,`ip`,`logdate`,`cname` FROM `userlog` AS l LEFT JOIN `userdata` AS s ON s.`id`=l.`subuser` AND l.`subuser`!=0 WHERE l.`usertype` IN ('user','cron') AND l.`userid`=? AND l.`resellerid`=? ORDER BY {$orderBy} LIMIT {$iDisplayStart},{$iDisplayLength}");
$query->execute(array($user_id, $reseller_id));
}
}
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row) {
if ($row['subuser'] == 0) {
if ($row['subuser'] == 0 or $adminLookup) {
$username = $row['username'];
$ip = $row['ip'];
} else {

View File

@ -6,42 +6,31 @@
</ol>
</section>
<!-- Main Content -->
<section class="content">
<div class="box-footer clearfix">
<ul class="pagination pagination-sm no-margin pull-right">
<li><a href="admin.php?w=lo&amp;a=<?php if(!isset($amount)) echo "20"; else echo $amount; ?>&amp;p=<?php echo $zur; ?>"><i class="fa fa-step-backward"></i></a></li>
<li><a href="admin.php?w=lo&amp;a=20&amp;p=<?php echo $start; ?>">20</a></li>
<li><a href="admin.php?w=lo&amp;a=50&amp;p=<?php echo $start; ?>">50</a></li>
<li><a href="admin.php?w=lo&amp;a=100&amp;p=<?php echo $start; ?>">100</a></li>
<li><a href="admin.php?w=lo&amp;a=<?php if(!isset($amount)) echo "20"; else echo $amount; ?>&amp;p=<?php echo $vor; ?>"><i class="fa fa-step-forward"></i></a></li>
</ul>
</div>
<br/>
<div class="box box-info">
<div class="box-body table-responsive no-padding">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th data-class="expand"><?php echo $sprache->date;?></th>
<th data-hide="phone"><?php echo $sprache->account;?></th>
<th><?php echo $sprache->action;?></th>
<th data-hide="phone,tablet"><?php echo $sprache->ip;?></th>
<th data-hide="phone,tablet"><?php echo $sprache->hostname;?></th>
</tr>
</thead>
<tbody>
<?php foreach ($table as $table_row) { ?>
<tr>
<td><?php echo $table_row['logday'].' '.$table_row['loghour']; ?></td>
<td><?php echo $table_row['username']; ?></td>
<td><?php echo $table_row['useraction']; ?></td>
<td><?php echo $table_row['ip']; ?></td>
<td><?php echo $table_row['hostname']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="row">
<div class="col-md-11">
<div class="box box-info">
<div class="box-body table-responsive">
<table id="dataTable" class="table table-bordered table-hover">
<thead>
<tr>
<th><?php echo $sprache->date;?></th>
<th><?php echo $sprache->account;?></th>
<th><?php echo $sprache->action;?></th>
<th><?php echo $sprache->ip;?></th>
</tr>
</thead>
<tfoot>
<tr>
<th><?php echo $sprache->date;?></th>
<th><?php echo $sprache->account;?></th>
<th><?php echo $sprache->action;?></th>
<th><?php echo $sprache->ip;?></th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
</section>