mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Use Laravel for authentication Support legacy auth methods Always create DB entry for users (segregate by auth method) Port api auth to Laravel restrict poller errors to devices the user has access to Run checks on every page load. But set a 5 minute (configurable) timer. Only run some checks if the user is an admin Move toastr down a few pixels so it isn't as annoying. Fix menu not loaded on laravel pages when twofactor is enabled for the system, but disabled for the user. Add two missing menu entries in the laravel menu Rewrite 2FA code Simplify some and verify code before applying Get http-auth working Handle legacy $_SESSION differently. Allows Auth::once(), etc to work. * Fix tests and mysqli extension check * remove duplicate Toastr messages * Fix new items * Rename 266.sql to 267.sql
285 lines
9.6 KiB
PHP
285 lines
9.6 KiB
PHP
<?php
|
|
|
|
use LibreNMS\Authentication\LegacyAuth;
|
|
|
|
$bill_id = mres($vars['bill_id']);
|
|
|
|
if (LegacyAuth::user()->hasGlobalAdmin()) {
|
|
include 'pages/bill/actions.inc.php';
|
|
}
|
|
|
|
if (bill_permitted($bill_id)) {
|
|
$bill_data = dbFetchRow('SELECT * FROM bills WHERE bill_id = ?', array($bill_id));
|
|
|
|
$bill_name = $bill_data['bill_name'];
|
|
|
|
$today = str_replace('-', '', dbFetchCell('SELECT CURDATE()'));
|
|
$yesterday = str_replace('-', '', dbFetchCell('SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY)'));
|
|
$tomorrow = str_replace('-', '', dbFetchCell('SELECT DATE_ADD(CURDATE(), INTERVAL 1 DAY)'));
|
|
$last_month = str_replace('-', '', dbFetchCell('SELECT DATE_SUB(CURDATE(), INTERVAL 1 MONTH)'));
|
|
|
|
$rightnow = $today.date('His');
|
|
$before = $yesterday.date('His');
|
|
$lastmonth = $last_month.date('His');
|
|
|
|
$bill_name = $bill_data['bill_name'];
|
|
$dayofmonth = $bill_data['bill_day'];
|
|
|
|
$day_data = getDates($dayofmonth);
|
|
|
|
$datefrom = $day_data['0'];
|
|
$dateto = $day_data['1'];
|
|
$lastfrom = $day_data['2'];
|
|
$lastto = $day_data['3'];
|
|
|
|
$rate_95th = $bill_data['rate_95th'];
|
|
$dir_95th = $bill_data['dir_95th'];
|
|
$total_data = $bill_data['total_data'];
|
|
$rate_average = $bill_data['rate_average'];
|
|
|
|
if ($rate_95th > $paid_kb) {
|
|
$over = ($rate_95th - $paid_kb);
|
|
$bill_text = $over.'Kbit excess.';
|
|
$bill_color = '#cc0000';
|
|
} else {
|
|
$under = ($paid_kb - $rate_95th);
|
|
$bill_text = $under.'Kbit headroom.';
|
|
$bill_color = '#0000cc';
|
|
}
|
|
|
|
$fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '".$config['dateformat']['mysql']['date']."')");
|
|
$totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '".$config['dateformat']['mysql']['date']."')");
|
|
$unixfrom = dbFetchCell("SELECT UNIX_TIMESTAMP('$datefrom')");
|
|
$unixto = dbFetchCell("SELECT UNIX_TIMESTAMP('$dateto')");
|
|
|
|
$unix_prev_from = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastfrom')");
|
|
$unix_prev_to = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastto')");
|
|
// Speeds up loading for other included pages by setting it before progessing of mysql data!
|
|
$ports = dbFetchRows(
|
|
'SELECT * FROM `bill_ports` AS B, `ports` AS P, `devices` AS D
|
|
WHERE B.bill_id = ? AND P.port_id = B.port_id
|
|
AND D.device_id = P.device_id',
|
|
array($bill_id)
|
|
);
|
|
|
|
if (!$vars['view']) {
|
|
$vars['view'] = 'quick';
|
|
}
|
|
|
|
function print_port_list($ports)
|
|
{
|
|
echo '<div class="panel panel-default">
|
|
<div class="panel-heading">
|
|
<h3 class="panel-title">Billed Ports</h3>
|
|
</div>
|
|
<div class="list-group">';
|
|
|
|
// Collected Earlier
|
|
foreach ($ports as $port) {
|
|
$port = cleanPort($port);
|
|
$portalias = (empty($port['ifAlias']) ? '' : ' - '.$port['ifAlias'].'');
|
|
|
|
echo '<div class="list-group-item">';
|
|
echo generate_port_link($port, $port['ifName'].$portalias).' on '.generate_device_link($port);
|
|
echo '</div>';
|
|
}
|
|
|
|
echo '</div></div>';
|
|
}//end print_port_list
|
|
|
|
?>
|
|
|
|
<h2><?php echo "Bill: ${bill_data['bill_name']}"; ?></h2>
|
|
|
|
<?php
|
|
print_optionbar_start();
|
|
echo "<strong>Bill</strong> » ";
|
|
$menu_options = array(
|
|
'quick' => 'Quick Graphs',
|
|
'accurate' => 'Accurate Graphs',
|
|
'transfer' => 'Transfer Graphs',
|
|
'history' => 'Historical Graphs'
|
|
);
|
|
if (LegacyAuth::user()->hasGlobalAdmin()) {
|
|
$menu_options['edit'] = 'Edit';
|
|
$menu_options['delete'] = 'Delete';
|
|
$menu_options['reset'] = 'Reset';
|
|
}
|
|
$sep = '';
|
|
foreach ($menu_options as $option => $text) {
|
|
echo $sep;
|
|
if ($vars['view'] == $option) {
|
|
echo "<span class='pagemenu-selected'>";
|
|
}
|
|
|
|
echo generate_link($text, $vars, array('view' => $option));
|
|
if ($vars['view'] == $option) {
|
|
echo '</span>';
|
|
}
|
|
|
|
$sep = ' | ';
|
|
}
|
|
|
|
echo '<div style="font-weight: bold; float: right;"><a href="'.generate_url(array('page' => 'bills')).'/"><i class="fa fa-arrow-left fa-lg icon-theme" aria-hidden="true"></i> Back to Bills</a></div>';
|
|
|
|
print_optionbar_end();
|
|
|
|
if ($vars['view'] == 'edit' && LegacyAuth::user()->hasGlobalAdmin()) {
|
|
include 'pages/bill/edit.inc.php';
|
|
} elseif ($vars['view'] == 'delete' && LegacyAuth::user()->hasGlobalAdmin()) {
|
|
include 'pages/bill/delete.inc.php';
|
|
} elseif ($vars['view'] == 'reset' && LegacyAuth::user()->hasGlobalAdmin()) {
|
|
include 'pages/bill/reset.inc.php';
|
|
} elseif ($vars['view'] == 'history') {
|
|
include 'pages/bill/history.inc.php';
|
|
} elseif ($vars['view'] == 'transfer') {
|
|
include 'pages/bill/transfer.inc.php';
|
|
} elseif ($vars['view'] == 'quick' || $vars['view'] == 'accurate') {
|
|
?>
|
|
|
|
<?php if ($bill_data['bill_type'] == 'quota') { ?>
|
|
<h3>Quota Bill</h3>
|
|
<?php } elseif ($bill_data['bill_type'] == 'cdr') { ?>
|
|
<h3>
|
|
CDR / 95th Bill
|
|
</h3>
|
|
<?php } ?>
|
|
<strong>Billing Period from <?php echo $fromtext ?> to <?php echo $totext ?></strong>
|
|
<br /><br />
|
|
|
|
<div class="row">
|
|
<div class="col-lg-6 col-lg-push-6">
|
|
<?php print_port_list($ports) ?>
|
|
</div>
|
|
<div class="col-lg-6 col-lg-pull-6">
|
|
<div class="panel panel-default">
|
|
<div class="panel-heading">
|
|
<h3 class="panel-title">
|
|
Bill Summary
|
|
</h3>
|
|
</div>
|
|
<table class="table">
|
|
<tr>
|
|
<?php if ($bill_data['bill_type'] == 'quota') {
|
|
// The Customer is billed based on a pre-paid quota with overage in xB
|
|
$percent = round((($total_data) / $bill_data['bill_quota'] * 100), 2);
|
|
$unit = 'MB';
|
|
$total_data = round($total_data, 2);
|
|
$background = get_percentage_colours($percent);
|
|
$type = '&ave=yes';
|
|
?>
|
|
<td>
|
|
<?php echo format_bytes_billing($total_data) ?> of <?php echo format_bytes_billing($bill_data['bill_quota']).' ('.$percent.'%)' ?>
|
|
- Average rate <?php echo formatRates($rate_average) ?>
|
|
</td>
|
|
<td style="width: 210px;"><?php echo print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']) ?></td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="2">
|
|
<?php
|
|
echo 'Predicted usage: ' . format_bytes_billing(getPredictedUsage($bill_data['bill_day'], $bill_data['total_data']));
|
|
?>
|
|
</td>
|
|
<?php
|
|
} elseif ($bill_data['bill_type'] == 'cdr') {
|
|
// The customer is billed based on a CDR with 95th%ile overage
|
|
$unit = 'kbps';
|
|
$cdr = $bill_data['bill_cdr'];
|
|
$rate_95th = round($rate_95th, 2);
|
|
$percent = round((($rate_95th) / $cdr * 100), 2);
|
|
$type = '&95th=yes';
|
|
?>
|
|
<td>
|
|
<?php echo format_si($rate_95th) ?> of <?php echo format_si($cdr).'bps ('.$percent.'%)' ?> (95th%ile)
|
|
</td>
|
|
<td style="width: 210px;">
|
|
<?php echo print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']) ?>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="2">
|
|
<?php
|
|
echo 'Predicted usage: ' . format_bytes_billing(getPredictedUsage($bill_data['bill_day'], $bill_data['rate_95th']));
|
|
?>
|
|
</td>
|
|
|
|
<?php }//end if
|
|
?>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php
|
|
|
|
$lastmonth = dbFetchCell('SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))');
|
|
$yesterday = dbFetchCell('SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))');
|
|
$rightnow = date('U');
|
|
|
|
if ($vars['view'] == 'accurate') {
|
|
$bi = "<img src='billing-graph.php?bill_id=".$bill_id.'&bill_code='.$_GET['bill_code'];
|
|
$bi .= '&from='.$unixfrom.'&to='.$unixto;
|
|
$bi .= '&x=1190&y=250';
|
|
$bi .= "$type'>";
|
|
|
|
$li = "<img src='billing-graph.php?bill_id=".$bill_id.'&bill_code='.$_GET['bill_code'];
|
|
$li .= '&from='.$unix_prev_from.'&to='.$unix_prev_to;
|
|
$li .= '&x=1190&y=250';
|
|
$li .= "$type'>";
|
|
|
|
$di = "<img src='billing-graph.php?bill_id=".$bill_id.'&bill_code='.$_GET['bill_code'];
|
|
$di .= '&from='.$config['time']['day'].'&to='.$config['time']['now'];
|
|
$di .= '&x=1190&y=250';
|
|
$di .= "$type'>";
|
|
|
|
$mi = "<img src='billing-graph.php?bill_id=".$bill_id.'&bill_code='.$_GET['bill_code'];
|
|
$mi .= '&from='.$lastmonth.'&to='.$rightnow;
|
|
$mi .= '&x=1190&y=250';
|
|
$mi .= "$type'>";
|
|
} else {
|
|
$bi = "<img src='graph.php?type=bill_bits&id=".$bill_id;
|
|
$bi .= '&from='.$unixfrom.'&to='.$unixto;
|
|
$bi .= "&width=1000&height=200&total=1'>";
|
|
|
|
$li = "<img src='graph.php?type=bill_bits&id=".$bill_id;
|
|
$li .= '&from='.$unix_prev_from.'&to='.$unix_prev_to;
|
|
$li .= "&width=1000&height=200&total=1'>";
|
|
|
|
$di = "<img src='graph.php?type=bill_bits&id=".$bill_id;
|
|
$di .= '&from='.$config['time']['day'].'&to='.$config['time']['now'];
|
|
$di .= "&width=1000&height=200&total=1'>";
|
|
|
|
$mi = "<img src='graph.php?type=bill_bits&id=".$bill_id;
|
|
$mi .= '&from='.$lastmonth.'&to='.$rightnow;
|
|
$mi .= "&width=1000&height=200&total=1'>";
|
|
}//end if
|
|
|
|
?>
|
|
<div class="panel panel-default">
|
|
<div class="panel-heading">
|
|
<h3 class="panel-title">Billing View</h3>
|
|
</div>
|
|
<?php echo $bi ?>
|
|
</div>
|
|
|
|
<div class="panel panel-default">
|
|
<div class="panel-heading">
|
|
<h3 class="panel-title">24 Hour View</h3>
|
|
</div>
|
|
<?php echo $di ?>
|
|
</div>
|
|
|
|
<div class="panel panel-default">
|
|
<div class="panel-heading">
|
|
<h3 class="panel-title">Monthly View</h3>
|
|
</div>
|
|
<?php echo $mi ?>
|
|
</div>
|
|
<?php
|
|
} //end if
|
|
} else {
|
|
include 'includes/error-no-perm.inc.php';
|
|
}//end if
|
|
?>
|