Skip to content

Commit 237d979

Browse files
committed
Modernize old bill graph links
1 parent 7091373 commit 237d979

5 files changed

Lines changed: 67 additions & 171 deletions

File tree

html/bandwidth-graph.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

html/billing-graph.php

Lines changed: 0 additions & 52 deletions
This file was deleted.

includes/html/pages/bill.inc.php

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22

3+
use App\Facades\LibrenmsConfig;
34
use App\Models\Bill;
45
use Illuminate\Support\Facades\Gate;
56
use LibreNMS\Billing;
67
use LibreNMS\Util\Html;
78
use LibreNMS\Util\Number;
9+
use LibreNMS\Util\Url;
810

911
$bill_id = (int) ($vars['bill_id'] ?? 0);
1012
$bill = Bill::find($bill_id);
@@ -57,8 +59,8 @@
5759
$bill_color = '#0000cc';
5860
}
5961

60-
$fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '" . \App\Facades\LibrenmsConfig::get('dateformat.mysql.date') . "')");
61-
$totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '" . \App\Facades\LibrenmsConfig::get('dateformat.mysql.date') . "')");
62+
$fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '" . LibrenmsConfig::get('dateformat.mysql.date') . "')");
63+
$totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '" . LibrenmsConfig::get('dateformat.mysql.date') . "')");
6264
$unixfrom = dbFetchCell("SELECT UNIX_TIMESTAMP('$datefrom')");
6365
$unixto = dbFetchCell("SELECT UNIX_TIMESTAMP('$dateto')");
6466

@@ -175,7 +177,7 @@ function print_port_list($ports)
175177
$percent = Number::calculatePercent($total_data, $bill_data['bill_quota']);
176178
$unit = 'MB';
177179
$total_data = round($total_data, 2);
178-
$type = '&amp;ave=yes'; ?>
180+
$graph_type = ['ave' => 'yes']; ?>
179181
<td>
180182
<?php echo Billing::formatBytes($total_data) ?> of <?php echo Billing::formatBytes($bill_data['bill_quota']) . ' (' . $percent . '%)' ?>
181183
- Average rate <?php echo Number::formatSi($rate_average, 2, 0, 'bps') ?>
@@ -194,7 +196,7 @@ function print_port_list($ports)
194196
$cdr = $bill_data['bill_cdr'];
195197
$rate_95th = round($rate_95th, 2);
196198
$percent = Number::calculatePercent($rate_95th, $cdr);
197-
$type = '&amp;95th=yes'; ?>
199+
$graph_type = ['95th' => 'yes']; ?>
198200
<td>
199201
<?php echo Number::formatSi($rate_95th, 2, 0, '') . 'bps' ?> of <?php echo Number::formatSi($cdr, 2, 0, '') . 'bps (' . $percent . '%)' ?> (95th%ile)
200202
</td>
@@ -222,65 +224,51 @@ function print_port_list($ports)
222224
$yesterday = dbFetchCell('SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))');
223225
$rightnow = date('U');
224226

227+
$graph_args = [
228+
'id' => $bill_id,
229+
'width' => 1190,
230+
'height' => 250,
231+
];
232+
if (isset($graph_type)) {
233+
$graph_args = array_merge($graph_args, $graph_type);
234+
}
235+
225236
if ($vars['view'] == 'accurate') {
226-
$bill_code = (string) ($_GET['bill_code'] ?? '');
227-
$bi = "<img src='billing-graph.php?bill_id=" . $bill_id . '&amp;bill_code=' . htmlspecialchars($bill_code);
228-
$bi .= '&amp;from=' . $unixfrom . '&amp;to=' . $unixto;
229-
$bi .= '&amp;x=1190&amp;y=250';
230-
$bi .= "$type'>";
231-
232-
$li = "<img src='billing-graph.php?bill_id=" . $bill_id . '&amp;bill_code=' . htmlspecialchars($bill_code);
233-
$li .= '&amp;from=' . $unix_prev_from . '&amp;to=' . $unix_prev_to;
234-
$li .= '&amp;x=1190&amp;y=250';
235-
$li .= "$type'>";
236-
237-
$di = "<img src='billing-graph.php?bill_id=" . $bill_id . '&amp;bill_code=' . htmlspecialchars($bill_code);
238-
$di .= '&amp;from=' . \App\Facades\LibrenmsConfig::get('time.day') . '&amp;to=' . \App\Facades\LibrenmsConfig::get('time.now');
239-
$di .= '&amp;x=1190&amp;y=250';
240-
$di .= "$type'>";
241-
242-
$mi = "<img src='billing-graph.php?bill_id=" . $bill_id . '&amp;bill_code=' . htmlspecialchars($bill_code);
243-
$mi .= '&amp;from=' . $lastmonth . '&amp;to=' . $rightnow;
244-
$mi .= '&amp;x=1190&amp;y=250';
245-
$mi .= "$type'>";
237+
$graph_args['type'] = 'bill_historicbits';
238+
$graph_args['bill_code'] = (string) ($_GET['bill_code'] ?? '');
246239
} else {
247-
$bi = "<img src='graph.php?type=bill_bits&amp;id=" . $bill_id;
248-
$bi .= '&amp;from=' . $unixfrom . '&amp;to=' . $unixto;
249-
$bi .= '&amp;width=1000&amp;height=200&amp;total=1&amp;dir=' . $dir_95th . "'>";
250-
251-
$li = "<img src='graph.php?type=bill_bits&amp;id=" . $bill_id;
252-
$li .= '&amp;from=' . $unix_prev_from . '&amp;to=' . $unix_prev_to;
253-
$li .= '&amp;width=1000&amp;height=200&amp;total=1&amp;dir=' . $dir_95th . "'>";
254-
255-
$di = "<img src='graph.php?type=bill_bits&amp;id=" . $bill_id;
256-
$di .= '&amp;from=' . \App\Facades\LibrenmsConfig::get('time.day') . '&amp;to=' . \App\Facades\LibrenmsConfig::get('time.now');
257-
$di .= '&amp;width=1000&amp;height=200&amp;total=1&amp;dir=' . $dir_95th . "'>";
240+
$graph_args['type'] = 'bill_bits';
241+
$graph_args['width'] = 1000;
242+
$graph_args['height'] = 200;
243+
$graph_args['total'] = 1;
244+
$graph_args['dir'] = $dir_95th;
245+
}
258246

259-
$mi = "<img src='graph.php?type=bill_bits&amp;id=" . $bill_id;
260-
$mi .= '&amp;from=' . $lastmonth . '&amp;to=' . $rightnow;
261-
$mi .= '&amp;width=1000&amp;height=200&amp;total=1&amp;dir=' . $dir_95th . "'>";
262-
}//end if
247+
$bi = array_merge($graph_args, ['from' => $unixfrom, 'to' => $unixto]);
248+
$li = array_merge($graph_args, ['from' => $unix_prev_from, 'to' => $unix_prev_to]);
249+
$di = array_merge($graph_args, ['from' => LibrenmsConfig::get('time.day'), 'to' => LibrenmsConfig::get('time.now')]);
250+
$mi = array_merge($graph_args, ['from' => $lastmonth, 'to' => $rightnow]);
263251

264252
?>
265253
<div class="panel panel-default">
266254
<div class="panel-heading">
267255
<h3 class="panel-title">Billing View</h3>
268256
</div>
269-
<?php echo $bi ?>
257+
<?php echo Url::graphTag($bi) ?>
270258
</div>
271259

272260
<div class="panel panel-default">
273261
<div class="panel-heading">
274262
<h3 class="panel-title">24 Hour View</h3>
275263
</div>
276-
<?php echo $di ?>
264+
<?php echo Url::graphTag($di) ?>
277265
</div>
278266

279267
<div class="panel panel-default">
280268
<div class="panel-heading">
281269
<h3 class="panel-title">Monthly View</h3>
282270
</div>
283-
<?php echo $mi ?>
271+
<?php echo Url::graphTag($mi) ?>
284272
</div>
285273
<?php
286274
} //end if

includes/html/pages/bill/history.inc.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
// $url = $PHP_SELF."/bill/".$bill_id."/history/";
88
$i = 0;
99

10-
$img['his'] = '<img src="graph.php?id=' . $bill_id;
11-
$img['his'] .= '&amp;type=bill_historicmonthly';
12-
$img['his'] .= '&amp;width=1190&amp;height=250';
13-
$img['his'] .= '" style="margin: 15px 5px 25px 5px;" />';
10+
$graph_args = [
11+
'id' => $bill_id,
12+
'type' => 'bill_historicmonthly',
13+
'width' => 1190,
14+
'height' => 250,
15+
];
16+
$img['his'] = '<img src="' . route('graph', $graph_args) . '" style="margin: 15px 5px 25px 5px;" />';
1417
?>
1518

1619
<h3>Historical Usage</h3>
@@ -26,21 +29,24 @@
2629

2730
function showDetails($bill_id, $imgtype, $bill_hist_id)
2831
{
29-
$res = '<img src="graph.php?id=' . $bill_id;
32+
$graph_args = [
33+
'id' => $bill_id,
34+
'width' => 1190,
35+
'height' => 250,
36+
];
3037

3138
if ($imgtype == 'bitrate') {
32-
$res .= '&amp;type=bill_historicbits';
39+
$graph_args['type'] = 'bill_historicbits';
3340
} else {
34-
$res .= '&amp;type=bill_historictransfer';
35-
$res .= '&amp;imgtype=' . $imgtype;
41+
$graph_args['type'] = 'bill_historictransfer';
42+
$graph_args['imgtype'] = $imgtype;
3643
}
37-
$res .= '&amp;width=1190&amp;height=250';
44+
3845
if (is_numeric($bill_hist_id)) {
39-
$res .= '&amp;bill_hist_id=' . $bill_hist_id;
46+
$graph_args['bill_hist_id'] = $bill_hist_id;
4047
}
41-
$res .= '" style="margin: 15px 5px 25px 5px;" />';
4248

43-
return $res;
49+
return '<img src="' . route('graph', $graph_args) . '" style="margin: 15px 5px 25px 5px;" />';
4450
}//end showDetails()
4551

4652
// $url = generate_url($vars, array('detail' => 'yes'));

includes/html/pages/bill/transfer.inc.php

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22

3+
use App\Facades\LibrenmsConfig;
34
use LibreNMS\Billing;
45
use LibreNMS\Util\Number;
6+
use LibreNMS\Util\Url;
57

68
$pagetitle[] = 'Bandwidth Graphs';
79

@@ -23,8 +25,8 @@
2325
$in_data = $bill_data['total_data_in'];
2426
$out_data = $bill_data['total_data_out'];
2527

26-
$fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '" . \App\Facades\LibrenmsConfig::get('dateformat.mysql.date') . "')");
27-
$totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '" . \App\Facades\LibrenmsConfig::get('dateformat.mysql.date') . "')");
28+
$fromtext = dbFetchCell("SELECT DATE_FORMAT($datefrom, '" . LibrenmsConfig::get('dateformat.mysql.date') . "')");
29+
$totext = dbFetchCell("SELECT DATE_FORMAT($dateto, '" . LibrenmsConfig::get('dateformat.mysql.date') . "')");
2830
$unixfrom = dbFetchCell("SELECT UNIX_TIMESTAMP('$datefrom')");
2931
$unixto = dbFetchCell("SELECT UNIX_TIMESTAMP('$dateto')");
3032
$unix_prev_from = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastfrom')");
@@ -71,7 +73,7 @@
7173
$ousage = [];
7274
$ousage['over'] = ($bill_data['total_data'] - ($bill_data['bill_quota']));
7375
$ousage['over'] = (($ousage['over'] < 0) ? '0' : $ousage['over']);
74-
$ousage['data'] = \LibreNMS\Util\Number::formatBase($ousage['over'], \App\Facades\LibrenmsConfig::get('billing.base'), 2, 0, '');
76+
$ousage['data'] = Number::formatBase($ousage['over'], LibrenmsConfig::get('billing.base'), 2, 0, '');
7577
$ousage['allow'] = $total['allow'];
7678
$ousage['ave'] = Billing::formatBytes(($ousage['over'] / $cur_days));
7779
$ousage['est'] = Billing::formatBytes(($ousage['over'] / $cur_days * $total_days));
@@ -167,31 +169,25 @@ function showPercent($per)
167169

168170

169171
<?php
170-
$bi = "<img src='graph.php?type=bill_historictransfer&id=" . $bill_id;
171-
$bi .= '&amp;from=' . $unixfrom . '&amp;to=' . $unixto;
172-
$bi .= '&amp;imgtype=day';
173-
$bi .= '&amp;width=1190&amp;height=250';
174-
$bi .= "'>";
175-
176-
$di = "<img src='graph.php?type=bill_historictransfer&id=" . $bill_id;
177-
$di .= '&amp;from=' . \App\Facades\LibrenmsConfig::get('time.day') . '&amp;to=' . \App\Facades\LibrenmsConfig::get('time.now');
178-
$di .= '&amp;imgtype=hour';
179-
$di .= '&amp;width=1190&amp;height=250';
180-
$di .= "'>";
181-
182-
$mi = "<img src='graph.php?type=bill_historictransfer&id=" . $bill_id;
183-
$mi .= '&amp;from=' . $lastmonth . '&amp;to=' . $rightnow;
184-
$mi .= '&amp;&imgtype=day';
185-
$mi .= '&amp;width=1190&amp;height=250';
186-
$mi .= "'>";
172+
$graph_args = [
173+
'type' => 'bill_historictransfer',
174+
'id' => $bill_id,
175+
'width' => 1190,
176+
'height' => 250,
177+
];
178+
179+
$bi = array_merge($graph_args, ['from' => $unixfrom, 'to' => $unixto, 'imgtype' => 'day']);
180+
$di = array_merge($graph_args, ['from' => LibrenmsConfig::get('time.day'), 'to' => LibrenmsConfig::get('time.now'), 'imgtype' => 'hour']);
181+
$mi = array_merge($graph_args, ['from' => $lastmonth, 'to' => $rightnow, 'imgtype' => 'day']);
182+
187183
?>
188184

189185
<div class="panel panel-default">
190186
<div class="panel-heading">
191187
<h3 class="panel-title">Billing Period View</h3>
192188
</div>
193189
<div class="panel-body">
194-
<?php echo $bi ?>
190+
<?php echo Url::graphTag($bi) ?>
195191
</div>
196192
</div>
197193

@@ -200,7 +196,7 @@ function showPercent($per)
200196
<h3 class="panel-title">Rolling 24 Hour View</h3>
201197
</div>
202198
<div class="panel-body">
203-
<?php echo $di ?>
199+
<?php echo Url::graphTag($di) ?>
204200
</div>
205201
</div>
206202

@@ -209,6 +205,6 @@ function showPercent($per)
209205
<h3 class="panel-title">Rolling Monthly View</h3>
210206
</div>
211207
<div class="panel-body">
212-
<?php echo $mi ?>
208+
<?php echo Url::graphTag($mi) ?>
213209
</div>
214210
</div>

0 commit comments

Comments
 (0)