Init
This commit is contained in:
75
backend/resources/plugins/fritzbox/api/v1/status.php
Normal file
75
backend/resources/plugins/fritzbox/api/v1/status.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
if (!defined('PICONTROL')) exit();
|
||||
|
||||
(include_once LIBRARY_PATH.'main/main.function.php') or die('Error: 0x0000');
|
||||
(include_once LIBRARY_PATH.'plugin/plugin.function.php') or die('Error: 0x0001');
|
||||
|
||||
initPluginConstants();
|
||||
(include_once PLUGIN_PATH.'resources/library/main/main.function.php') or die('Error: 9x0001');
|
||||
|
||||
if (isset($_POST['data']))
|
||||
{
|
||||
$fritzboxAddress = getPluginConfig('main:address', 'http://fritz.box');
|
||||
$fritzboxVersion = getPluginConfig('main:version', '5');
|
||||
$fritzboxUnit = getPluginConfig('main:unit', 'mbit');
|
||||
|
||||
$connectionFritzbox = checkConnectionToFritzbox($fritzboxAddress, $fritzboxVersion);
|
||||
|
||||
if ($connectionFritzbox == true)
|
||||
{
|
||||
|
||||
$currentBandwidth = getCurrentBandwidth($fritzboxAddress, $fritzboxVersion);
|
||||
$maxBandwidth = getMaxBandwidth($fritzboxAddress, $fritzboxVersion);
|
||||
|
||||
$datas = explode(';', $_POST['data']);
|
||||
|
||||
foreach ($datas as $data)
|
||||
{
|
||||
switch ($data)
|
||||
{
|
||||
case 'connection':
|
||||
$connectionStatus = getConnectionStatus($fritzboxAddress, $fritzboxVersion);
|
||||
$api->addData('connection', _t($connectionStatus['status']));
|
||||
break;
|
||||
case 'uptime':
|
||||
$connectionStatus = getConnectionStatus($fritzboxAddress, $fritzboxVersion);
|
||||
$api->addData('uptime', formatTime(time() - $connectionStatus['uptime']));
|
||||
break;
|
||||
case 'publicIP':
|
||||
$api->addData('publicIP', getPublicIP($fritzboxAddress, $fritzboxVersion));
|
||||
break;
|
||||
case 'totalSent':
|
||||
$traffic = getNetworkTraffic($fritzboxAddress, $fritzboxVersion);
|
||||
$api->addData('totalSent', sizeUnit($traffic['sent']));
|
||||
break;
|
||||
case 'totalReceived':
|
||||
$traffic = getNetworkTraffic($fritzboxAddress, $fritzboxVersion);
|
||||
$api->addData('totalReceived', sizeUnit($traffic['received']));
|
||||
break;
|
||||
case 'bandwidthDown':
|
||||
$currentBandwidth = getCurrentBandwidth($fritzboxAddress, $fritzboxVersion);
|
||||
$maxBandwidth = getMaxBandwidth($fritzboxAddress, $fritzboxVersion);
|
||||
|
||||
$api->addData('current', convertToUnit($currentBandwidth['down'], $fritzboxUnit, 'byte'));
|
||||
$api->addData('max', convertToUnit($maxBandwidth['down'], $fritzboxUnit));
|
||||
$api->addData('percentage', getPercentageFromBandwidth($currentBandwidth['down'], $maxBandwidth['down']).'%');
|
||||
break;
|
||||
case 'bandwidthUp':
|
||||
$currentBandwidth = getCurrentBandwidth($fritzboxAddress, $fritzboxVersion);
|
||||
$maxBandwidth = getMaxBandwidth($fritzboxAddress, $fritzboxVersion);
|
||||
|
||||
$api->addData('current', convertToUnit($currentBandwidth['up'], $fritzboxUnit, 'byte'));
|
||||
$api->addData('max', convertToUnit($maxBandwidth['up'], $fritzboxUnit));
|
||||
$api->addData('percentage', getPercentageFromBandwidth($currentBandwidth['up'], $maxBandwidth['up']).'%');
|
||||
break;
|
||||
default:
|
||||
$api->setError('error', 'Data for "'.$data.'" are not available.');
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
$api->setError('error', 'No connection.');
|
||||
}
|
||||
else
|
||||
$api->setError('error', 'No data set.');
|
||||
?>
|
||||
16
backend/resources/plugins/fritzbox/plugin.config.php
Normal file
16
backend/resources/plugins/fritzbox/plugin.config.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
if (!defined('PICONTROL')) exit();
|
||||
|
||||
$pluginConfig = array(
|
||||
'name' => 'Fritz!Box',
|
||||
'id' => 'fritzbox',
|
||||
'version' => array(
|
||||
'code' => 4,
|
||||
'name' => '2.0',
|
||||
'require' => 23
|
||||
),
|
||||
'languages' => array('de', 'en'),
|
||||
'author' => 'Willy Fritzsche',
|
||||
'description' => 'Zusammen mit einer Fritz!Box kannst du über dieses Plugin die aktuelle IP, die Download-/Uploadrate und die Gesamtdaten ermitteln.'
|
||||
);
|
||||
?>
|
||||
105
backend/resources/plugins/fritzbox/plugin.statistic.config.php
Normal file
105
backend/resources/plugins/fritzbox/plugin.statistic.config.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
if (!defined('PICONTROL')) exit();
|
||||
|
||||
(include_once LIBRARY_PATH.'main/main.function.php') or die('Error: 0x0001');
|
||||
(include_once LIBRARY_PATH.'plugin/plugin.function.php') or die('Error: 0x0002');
|
||||
|
||||
initPluginConstants();
|
||||
(include_once PLUGIN_PATH.'resources/library/main/main.function.php') or die('Error: 9x0001');
|
||||
|
||||
$fritzboxUnit = getPluginConfig('main:unit', 'mbit');
|
||||
$units = getOptionsForConfigFromUnit($fritzboxUnit);
|
||||
|
||||
$statisticConfig = array(
|
||||
'fritzbox.traffic-download' => array(
|
||||
'title' => 'Auslastung Download',
|
||||
'label' => 'Traffic ('.$units['unit'].')',
|
||||
'unit' => $units['unit'],
|
||||
'cycle' => 10,
|
||||
'columns' => array(
|
||||
array(
|
||||
'label' => 'Zeit',
|
||||
'type' => 'datetime',
|
||||
'downloadTitle' => 'Datum'
|
||||
),
|
||||
array(
|
||||
'label' => 'Maximal',
|
||||
'type' => 'number',
|
||||
'downloadTitle' => 'Maximal in Byte/s',
|
||||
'division' => $units['division'],
|
||||
'style' => array(
|
||||
'color' => '#3366cc',
|
||||
'type' => 'line',
|
||||
'lineDashStyle' => 10
|
||||
)
|
||||
),
|
||||
array(
|
||||
'label' => 'Download',
|
||||
'type' => 'number',
|
||||
'downloadTitle' => 'Auslastung Download in Byte/s',
|
||||
'division' => $units['division'],
|
||||
'style' => array(
|
||||
'color' => '#3366cc'
|
||||
)
|
||||
)
|
||||
),
|
||||
'limits' => array(
|
||||
'min' => array(
|
||||
'value' => 0.01,
|
||||
'use' => 'fix',
|
||||
'fix' => true
|
||||
),
|
||||
'max' => array(
|
||||
'value' => 1.10,
|
||||
'use' => 'multiply',
|
||||
'fix' => false
|
||||
)
|
||||
)
|
||||
),
|
||||
'fritzbox.traffic-upload' => array(
|
||||
'title' => 'Auslastung Upload',
|
||||
'label' => 'Traffic ('.$units['unit'].')',
|
||||
'unit' => $units['unit'],
|
||||
'cycle' => 10,
|
||||
'columns' => array(
|
||||
array(
|
||||
'label' => 'Zeit',
|
||||
'type' => 'datetime',
|
||||
'downloadTitle' => 'Datum'
|
||||
),
|
||||
array(
|
||||
'label' => 'Maximal',
|
||||
'type' => 'number',
|
||||
'downloadTitle' => 'Maximal in Byte/s',
|
||||
'division' => $units['division'],
|
||||
'style' => array(
|
||||
'color' => '#3366cc',
|
||||
'type' => 'line',
|
||||
'lineDashStyle' => 10
|
||||
)
|
||||
),
|
||||
array(
|
||||
'label' => 'Upload',
|
||||
'type' => 'number',
|
||||
'downloadTitle' => 'Auslastung Upload in Byte/s',
|
||||
'division' => $units['division'],
|
||||
'style' => array(
|
||||
'color' => '#3366cc'
|
||||
)
|
||||
)
|
||||
),
|
||||
'limits' => array(
|
||||
'min' => array(
|
||||
'value' => 0.01,
|
||||
'use' => 'fix',
|
||||
'fix' => true
|
||||
),
|
||||
'max' => array(
|
||||
'value' => 1.10,
|
||||
'use' => 'multiply',
|
||||
'fix' => false
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
?>
|
||||
55
backend/resources/plugins/fritzbox/public_html/css/style.css
Normal file
55
backend/resources/plugins/fritzbox/public_html/css/style.css
Normal file
@@ -0,0 +1,55 @@
|
||||
@charset "utf-8";
|
||||
/* CSS Document */
|
||||
|
||||
.refresh {
|
||||
width: 100%;
|
||||
display: table;
|
||||
}
|
||||
|
||||
.refresh > div {
|
||||
display: table-cell;
|
||||
width: 100%;
|
||||
vertical-align: middle;
|
||||
padding-right: 15px;
|
||||
}
|
||||
|
||||
.refresh .refresh-bar {
|
||||
height: 2px;
|
||||
overflow: hidden;
|
||||
width: 0%;
|
||||
}
|
||||
|
||||
.refresh > a {
|
||||
text-decoration: none;
|
||||
display: table-cell;
|
||||
font-size: 0px;
|
||||
}
|
||||
|
||||
.refresh > a > img {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
.custom-progressbar {
|
||||
width: 100%;
|
||||
position: relative;
|
||||
height: 17px;
|
||||
background: #DDDDDD;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.custom-progressbar > div {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.custom-progressbar::after {
|
||||
content: attr(data-text);
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
line-height: 17px;
|
||||
font-size: 11px;
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
var is_loding = false;
|
||||
|
||||
function statusRefreshEffect(element)
|
||||
{
|
||||
var background = element.css('background-color');
|
||||
|
||||
element.css({'transition': 'background-color 0.5s', 'background-color': 'rgba(243, 255, 164, 1)'});
|
||||
setTimeout(function()
|
||||
{
|
||||
element.css({'background-color': background});
|
||||
}, 800);
|
||||
}
|
||||
|
||||
function showError()
|
||||
{
|
||||
jQuery('.error-msg-refresh-bar').remove();
|
||||
jQuery('.refresh div:eq(0)').after('<div class="red error-msg-refresh-bar" style="vertical-align: bottom; font-weight: bold;">' + _t('Fehler!') + '</div>');
|
||||
jQuery('.refresh-bar').stop(false, true).css('width', 0);
|
||||
jQuery('a[href=#refresh] img').removeClass('rotate-icon');
|
||||
|
||||
setTimeout('statusRefresh()', 3000);
|
||||
}
|
||||
|
||||
function statusRefresh()
|
||||
{
|
||||
jQuery('.error-msg-refresh-bar').remove();
|
||||
jQuery('.refresh-bar').animate({width: '100%'}, 30000, 'linear', function(e)
|
||||
{
|
||||
var this_ = jQuery(this);
|
||||
var connection = jQuery('.table tr:eq(1)');
|
||||
var uptime = jQuery('.table tr:eq(2)');
|
||||
var publicIP = jQuery('.table tr:eq(3)');
|
||||
var totalReceived = jQuery('.table tr:eq(4)');
|
||||
var totalSent = jQuery('.table tr:eq(5)');
|
||||
var bandwidthDown = jQuery('.table tr:eq(6)');
|
||||
var bandwidthUp = jQuery('.table tr:eq(7)');
|
||||
|
||||
jQuery('a[href=#refresh] img').addClass('rotate-icon');
|
||||
|
||||
this_.animate({width: '87.5%'}, 300, 'linear');
|
||||
jQuery.post('api/v1/plugins.php', { id: 'fritzbox', action: 'v1/status', data: 'connection' }, function(data)
|
||||
{
|
||||
if (connection.find('td:eq(1)').html() != data.data.connection)
|
||||
{
|
||||
statusRefreshEffect(connection);
|
||||
connection.find('td:eq(1)').html(data.data.connection);
|
||||
}
|
||||
|
||||
this_.animate({width: '75%'}, 300, 'linear');
|
||||
jQuery.post('api/v1/plugins.php', { id: 'fritzbox', action: 'v1/status', data: 'uptime' }, function(data)
|
||||
{
|
||||
if (uptime.find('td:eq(1)').html() != data.data.uptime)
|
||||
{
|
||||
statusRefreshEffect(uptime);
|
||||
uptime.find('td:eq(1)').html(data.data.uptime);
|
||||
}
|
||||
|
||||
this_.animate({width: '62.5%'}, 300, 'linear');
|
||||
jQuery.post('api/v1/plugins.php', { id: 'fritzbox', action: 'v1/status', data: 'publicIP' }, function(data)
|
||||
{
|
||||
if (publicIP.find('td:eq(1) a').text() != data.data.publicIP)
|
||||
{
|
||||
statusRefreshEffect(publicIP);
|
||||
publicIP.find('td:eq(1) a').text(data.data.publicIP).attr('href', 'http://'+data.data.publicIP);
|
||||
}
|
||||
|
||||
this_.animate({width: '50%'}, 300, 'linear');
|
||||
jQuery.post('api/v1/plugins.php', { id: 'fritzbox', action: 'v1/status', data: 'totalReceived' }, function(data)
|
||||
{
|
||||
if (totalReceived.find('td:eq(1)').html() != data.data.totalReceived)
|
||||
{
|
||||
statusRefreshEffect(totalReceived);
|
||||
totalReceived.find('td:eq(1)').html(data.data.totalReceived);
|
||||
}
|
||||
|
||||
this_.animate({width: '37.5%'}, 300, 'linear');
|
||||
jQuery.post('api/v1/plugins.php', { id: 'fritzbox', action: 'v1/status', data: 'totalSent' }, function(data)
|
||||
{
|
||||
if (totalSent.find('td:eq(1)').html() != data.data.totalSent)
|
||||
{
|
||||
statusRefreshEffect(totalSent);
|
||||
totalSent.find('td:eq(1)').html(data.data.totalSent);
|
||||
}
|
||||
|
||||
this_.animate({width: '25%'}, 300, 'linear');
|
||||
jQuery.post('api/v1/plugins.php', { id: 'fritzbox', action: 'v1/status', data: 'bandwidthDown' }, function(data)
|
||||
{
|
||||
if (bandwidthDown.find('td:eq(1) .custom-progressbar').attr('data-text') != data.data.current + ' / ' + data.data.max)
|
||||
{
|
||||
statusRefreshEffect(bandwidthDown);
|
||||
bandwidthDown.find('td:eq(1) .custom-progressbar').attr('data-text', data.data.current + ' / ' + data.data.max).find('div').css('width', data.data.percentage);
|
||||
}
|
||||
|
||||
this_.animate({width: '12.5%'}, 300, 'linear');
|
||||
jQuery.post('api/v1/plugins.php', { id: 'fritzbox', action: 'v1/status', data: 'bandwidthUp' }, function(data)
|
||||
{
|
||||
if (bandwidthUp.find('td:eq(1) .custom-progressbar').attr('data-text') != data.data.current + ' / ' + data.data.max)
|
||||
{
|
||||
statusRefreshEffect(bandwidthUp);
|
||||
bandwidthUp.find('td:eq(1) .custom-progressbar').attr('data-text', data.data.current + ' / ' + data.data.max).find('div').css('width', data.data.percentage);
|
||||
}
|
||||
|
||||
this_.animate({width: '0%'}, 300, 'linear', function(e)
|
||||
{
|
||||
is_loding = false;
|
||||
jQuery('a[href=#refresh] img').removeClass('rotate-icon');
|
||||
});
|
||||
|
||||
statusRefresh();
|
||||
}).fail(function(e) { showError(); });
|
||||
}).fail(function(e) { showError(); });
|
||||
}).fail(function(e) { showError(); });
|
||||
}).fail(function(e) { showError(); });
|
||||
}).fail(function(e) { showError(); });
|
||||
}).fail(function(e) { showError(); });
|
||||
}).fail(function(e) { showError(); });
|
||||
});
|
||||
}
|
||||
|
||||
jQuery(document).on('click', 'a[href=#refresh]', function(e)
|
||||
{
|
||||
if (is_loding == false)
|
||||
jQuery('.refresh-bar').stop(false, true);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery(document).ready(function(e)
|
||||
{
|
||||
statusRefresh();
|
||||
});
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php if (!defined('PICONTROL')) exit(); ?>
|
||||
<link rel="stylesheet" type="text/css" href="<?php echo PLUGIN_PUBLIC_PATH; ?>public_html/css/style.css" />
|
||||
<script type="text/javascript" src="<?php echo PLUGIN_PUBLIC_PATH; ?>public_html/js/status_refresh.js"></script>
|
||||
<div class="sidebar">
|
||||
<div class="box">
|
||||
<div class="inner-header">
|
||||
<span><?php _e('Benutzeroberfläche'); ?></span>
|
||||
</div>
|
||||
<div class="inner">
|
||||
<a href="<?php echo $data['address']; ?>" target="_blank" class="button" style="width: 100%; box-sizing: border-box; text-align: center;"><?php _e('Zur Benutzeroberfläche'); ?></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-600">
|
||||
<div class="box">
|
||||
<div class="inner-header">
|
||||
<span><?php _e('Fritz!Box'); ?></span>
|
||||
<?php showSettingsIcon('?s=plugins&id=fritzbox&settings'); ?>
|
||||
</div>
|
||||
<?php if ($data['connectionFritzbox'] == true) { ?>
|
||||
<div class="inner-table">
|
||||
<div>
|
||||
<div class="refresh">
|
||||
<div>
|
||||
<div class="refresh-bar background-color-7"></div>
|
||||
</div>
|
||||
<a href="#refresh"><img src="public_html/img/refresh-icon.svg" title="<?php _e('Aktualisieren'); ?>" /></a>
|
||||
</div>
|
||||
</div>
|
||||
<table class="table table-borderless table-form">
|
||||
<tr>
|
||||
<td style="width: 40%;"><?php _e('Modell'); ?></td>
|
||||
<td><?php echo $data['model']; ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?php _e('Status'); ?></td>
|
||||
<td><?php echo $data['connection']; ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?php _e('Verbunden seit'); ?></td>
|
||||
<td><?php echo $data['uptime']; ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?php _e('Öffentliche IP-Adresse'); ?></td>
|
||||
<td><a href="http://<?php echo $data['publicIP']; ?>" target="_blank"><?php echo $data['publicIP']; ?></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?php _e('Datenvolumen empfangen'); ?></td>
|
||||
<td><?php echo sizeUnit($data['totalReceived']); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?php _e('Datenvolumen gesendet'); ?></td>
|
||||
<td><?php echo sizeUnit($data['totalSent']); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?php _e('Auslastung Download'); ?></td>
|
||||
<td><div class="custom-progressbar" data-text="<?php echo $data['currentBandwidthDown']; ?> / <?php echo $data['maxBandwidthDown']; ?>">
|
||||
<div class="background-color-3" style="width: <?php echo $data['percentageBandwidthDown']; ?>%;"></div>
|
||||
</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?php _e('Auslastung Upload'); ?></td>
|
||||
<td><div class="custom-progressbar" data-text="<?php echo $data['currentBandwidthUp']; ?> / <?php echo $data['maxBandwidthUp']; ?>">
|
||||
<div class="background-color-3" style="width: <?php echo $data['percentageBandwidthUp']; ?>%;"></div>
|
||||
</div></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="inner-info">
|
||||
<div><?php _e('Momentan besteht keine Verbindung zu einer Fritz!Box!'); ?></div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clear-both"></div>
|
||||
<div>
|
||||
<?php foreach ($data['statistics'] as $statistic) { ?>
|
||||
<div class="box google-controls" id="dashboard_log_<?php echo $statistic['array']['id']; ?>">
|
||||
<div class="inner-header">
|
||||
<span><?php _e($statistic['array']['title']); ?></span>
|
||||
</div>
|
||||
<div class="inner text-center padding-0" id="chart_log_<?php echo $statistic['array']['id']; ?>">
|
||||
<img src="public_html/img/loader.svg" style="margin: 20px;" />
|
||||
</div>
|
||||
<div class="inner text-center" id="chart_control_log_<?php echo $statistic['array']['id']; ?>">
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
||||
<script type="text/javascript" src="public_html/js/statistic_builder.js"></script>
|
||||
<script type="text/javascript">
|
||||
google.load('visualization', '1', {packages:['controls']});
|
||||
google.setOnLoadCallback(createTable);
|
||||
|
||||
function createTable()
|
||||
{
|
||||
<?php foreach ($data['statistics'] as $statistic) { ?>
|
||||
statisticBuilder(<?php echo $statistic['json']; ?>, 'fritzbox');
|
||||
<?php } ?>
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php if (!defined('PICONTROL')) exit(); ?>
|
||||
<div>
|
||||
<div class="box">
|
||||
<div class="inner-header">
|
||||
<span><?php _e('Einstellungen zu Fritz!Box'); ?></span>
|
||||
<?php showGoBackIcon('?s=plugins&id=fritzbox'); ?>
|
||||
</div>
|
||||
<form action="?s=plugins&id=fritzbox&settings" method="post">
|
||||
<div class="inner-table">
|
||||
<table class="table table-borderless table-form">
|
||||
<tr>
|
||||
<td><?php _e('Adresse zur Fritz!Box'); ?></td>
|
||||
<td><input type="text" name="address" value="<?php echo $data['address']; ?>" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?php _e('Fritz!OS'); ?></td>
|
||||
<td><input type="radio" name="version" value="5" id="rb-5"<?php if ($data['version'] == '5') echo ' checked="checked"'; ?> /><label for="rb-5" class="radio"><?php _e('5 und niedriger'); ?></label><br />
|
||||
<input type="radio" name="version" value="6" id="rb-6"<?php if ($data['version'] == '6') echo ' checked="checked"'; ?> /><label for="rb-6" class="radio"><?php _e('6 und höher'); ?></label></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?php _e('Geschwindigkeitsangaben'); ?></td>
|
||||
<td><select name="unit">
|
||||
<option value="mbit"<?php if ($data['unit'] == 'mbit') echo ' selected="selected"'; ?>>MBit/s</option>
|
||||
<option value="mbyte"<?php if ($data['unit'] == 'mbyte') echo ' selected="selected"'; ?>>MByte/s</option>
|
||||
</select></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="inner-end">
|
||||
<input type="submit" name="submit-main" value="<?php _e('Speichern'); ?>" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="box">
|
||||
<div class="inner-header">
|
||||
<span><?php _e('Statistik'); ?></span>
|
||||
</div>
|
||||
<form action="?s=plugins&id=fritzbox&settings" method="post">
|
||||
<div class="inner-table">
|
||||
<table class="table table-borderless table-form">
|
||||
<tr>
|
||||
<td><?php _e('Aktivieren'); ?></td>
|
||||
<td><input type="checkbox" name="activation" value="checked" id="cb-activiation"<?php if ($data['activation'] == true) echo ' checked="checked"'; ?>><label for="cb-activiation" class="checkbox only-checkbox"> </label></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="inner-table">
|
||||
<table class="table table-borderless">
|
||||
<tr>
|
||||
<th style="width: 80%;"><?php _e('Name'); ?></th>
|
||||
<th style="width: 10%;" class="table-center"><?php _e('Download'); ?></th>
|
||||
<th style="width: 10%;"></th>
|
||||
</tr>
|
||||
<?php foreach ($data['statistics'] as $id => $statistic) { ?>
|
||||
<tr>
|
||||
<td><?php echo $statistic['array']['title'] ?></td>
|
||||
<td class="table-center"><a href="api/v1/statistic_download.php?id=<?php echo $id; ?>&plugin=fritzbox" class="text-decoration-none"><span class="button button-small">CSV</span></a></td>
|
||||
<td class="table-right"><a href="?s=plugins&id=fritzbox&settings&reset=<?php echo $id; ?>" class="text-decoration-none"><span class="button button-small"><?php _e('Zurücksetzen'); ?></span></a></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</table>
|
||||
</div>
|
||||
<div class="inner-end">
|
||||
<input type="submit" name="submit-statistic" value="<?php _e('Speichern'); ?>" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php if (!defined('PICONTROL')) exit(); ?>
|
||||
<div>
|
||||
<div class="box">
|
||||
<div class="inner-header">
|
||||
<span><?php _e('Einstellungen zu Fritz!Box - Verlauf zurücksetzen'); ?></span>
|
||||
<?php showGoBackIcon('?s=plugins&id=fritzbox&settings'); ?>
|
||||
</div>
|
||||
<form action="?s=plugins&id=fritzbox&settings&reset=<?php echo $data['log']; ?>&confirm" method="post">
|
||||
<div class="inner">
|
||||
<?php _e('Möchtest du den Verlauf von %s wirklich zurücksetzen?', '<strong>'.$data['label'].'</strong>'); ?>
|
||||
</div>
|
||||
<div class="inner-end">
|
||||
<input type="submit" name="submit" value="<?php _e('Zurücksetzen'); ?>" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
if (!defined('PICONTROL')) exit();
|
||||
|
||||
(include_once LIBRARY_PATH.'statistic/statistic.class.php') or die('Error: 9x0001');
|
||||
(include_once PLUGIN_PATH.'resources/library/main/main.function.php') or die('Error: 9x0002');
|
||||
|
||||
$fritzboxAddress = getPluginConfig('main:address', 'http://fritz.box');
|
||||
$fritzboxVersion = getPluginConfig('main:version', '5');
|
||||
$fritzboxUnit = getPluginConfig('main:unit', 'mbit');
|
||||
|
||||
$connectionFritzbox = checkConnectionToFritzbox($fritzboxAddress, $fritzboxVersion);
|
||||
|
||||
$tpl->assign('address', $fritzboxAddress);
|
||||
$tpl->assign('connectionFritzbox', $connectionFritzbox);
|
||||
|
||||
if ($connectionFritzbox == true)
|
||||
{
|
||||
$connectionStatus = getConnectionStatus($fritzboxAddress, $fritzboxVersion);
|
||||
$traffic = getNetworkTraffic($fritzboxAddress, $fritzboxVersion);
|
||||
$currentBandwidth = getCurrentBandwidth($fritzboxAddress, $fritzboxVersion);
|
||||
$maxBandwidth = getMaxBandwidth($fritzboxAddress, $fritzboxVersion);
|
||||
|
||||
$statistics = array();
|
||||
|
||||
$controller = new StatisticController($tpl);
|
||||
$controller->loadStatistics('plugin/');
|
||||
|
||||
if ($controller->checkStatistic('plugin/fritzbox.traffic-download') === true)
|
||||
{
|
||||
$builder = new StatisticBuilder();
|
||||
$builder->loadFromFile('plugin/fritzbox.traffic-download', 'fritzbox');
|
||||
$statistics[] = array('array' => $builder->getArray(), 'json' => $builder->getJSON());
|
||||
}
|
||||
|
||||
if ($controller->checkStatistic('plugin/fritzbox.traffic-upload') === true)
|
||||
{
|
||||
$builder = new StatisticBuilder();
|
||||
$builder->loadFromFile('plugin/fritzbox.traffic-upload', 'fritzbox');
|
||||
$statistics[] = array('array' => $builder->getArray(), 'json' => $builder->getJSON());
|
||||
}
|
||||
|
||||
$tpl->assign('model', getModelName($fritzboxAddress, $fritzboxVersion));
|
||||
$tpl->assign('connection', _t($connectionStatus['status']));
|
||||
$tpl->assign('uptime', formatTime(time() - $connectionStatus['uptime']));
|
||||
$tpl->assign('publicIP', getPublicIP($fritzboxAddress, $fritzboxVersion));
|
||||
$tpl->assign('totalSent', $traffic['sent']);
|
||||
$tpl->assign('totalReceived', $traffic['received']);
|
||||
$tpl->assign('currentBandwidthUp', convertToUnit($currentBandwidth['up'], $fritzboxUnit, 'byte'));
|
||||
$tpl->assign('currentBandwidthDown', convertToUnit($currentBandwidth['down'], $fritzboxUnit, 'byte'));
|
||||
$tpl->assign('maxBandwidthUp', convertToUnit($maxBandwidth['up'], $fritzboxUnit));
|
||||
$tpl->assign('maxBandwidthDown', convertToUnit($maxBandwidth['down'], $fritzboxUnit));
|
||||
$tpl->assign('percentageBandwidthUp', getPercentageFromBandwidth($currentBandwidth['up'], $maxBandwidth['up']));
|
||||
$tpl->assign('percentageBandwidthDown', getPercentageFromBandwidth($currentBandwidth['down'], $maxBandwidth['down']));
|
||||
$tpl->assign('statistics', $statistics);
|
||||
}
|
||||
|
||||
$tpl->draw('index');
|
||||
?>
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
if (!defined('PICONTROL')) exit();
|
||||
|
||||
(include_once PLUGIN_PATH.'resources/library/main/main.function.php') or die('Error: 9x0001');
|
||||
(include_once LIBRARY_PATH.'statistic/statistic.class.php') or die('Error: 9x0002');
|
||||
(include_once LIBRARY_PATH.'cron/cron.class.php') or die('Error: 9x0003');
|
||||
|
||||
$statistics = array();
|
||||
|
||||
$controller = new StatisticController();
|
||||
$controller->loadStatistics('plugin/');
|
||||
|
||||
if ($controller->checkStatistic('plugin/fritzbox.traffic-download') === true)
|
||||
{
|
||||
$builder = new StatisticBuilder();
|
||||
$builder->loadFromFile('plugin/fritzbox.traffic-download', 'fritzbox');
|
||||
$statistics[$builder->getId()] = array('array' => $builder->getArray());
|
||||
}
|
||||
|
||||
if ($controller->checkStatistic('plugin/fritzbox.traffic-upload') === true)
|
||||
{
|
||||
$builder = new StatisticBuilder();
|
||||
$builder->loadFromFile('plugin/fritzbox.traffic-upload', 'fritzbox');
|
||||
$statistics[$builder->getId()] = array('array' => $builder->getArray());
|
||||
}
|
||||
|
||||
if (!isset($_GET['reset']))
|
||||
{
|
||||
$cron = new Cron;
|
||||
$cron->setName('traffic');
|
||||
|
||||
if (isset($_POST['submit-main']))
|
||||
{
|
||||
if (isset($_POST['address'], $_POST['version'], $_POST['unit']) && ($pAddress = trim($_POST['address'])) && ($pVersion = trim($_POST['version'])) && ($pUnit = trim($_POST['unit'])) && in_array($_POST['version'], array('5', '6')) && in_array($_POST['unit'], array('mbit', 'mbyte')))
|
||||
{
|
||||
$tpl->msg('success', _t('Einstellungen gespeichert'), _t('Die Einstellungen wurden erfolgreich gespeichert.'), true, 10);
|
||||
|
||||
if (preg_match('#http[s]?:\/\/.*#i', $pAddress) !== 1)
|
||||
$pAddress = 'http://'.$pAddress;
|
||||
|
||||
setPluginConfig('main:address', $pAddress) or $tpl->msg('error', _t('Fehler'), _t('Die Einstellungen konnten nicht gespeichert werden!'), true, 10);
|
||||
setPluginConfig('main:version', $pVersion) or $tpl->msg('error', _t('Fehler'), _t('Die Einstellungen konnten nicht gespeichert werden!'), true, 10);
|
||||
setPluginConfig('main:unit', $pUnit) or $tpl->msg('error', _t('Fehler'), _t('Die Einstellungen konnten nicht gespeichert werden!'), true, 10);
|
||||
}
|
||||
}
|
||||
elseif (isset($_POST['submit-statistic']))
|
||||
{
|
||||
if (isset($_POST['activation']) && $_POST['activation'] == 'checked')
|
||||
{
|
||||
if ($cron->isExists() === false)
|
||||
{
|
||||
$cron->setInterval(10);
|
||||
$cron->setSource(PLUGIN_PATH.'resources/templates/traffic_monitoring.tmp.php');
|
||||
|
||||
if ($cron->save() === true)
|
||||
$tpl->msg('success', _t('Statistik aktiviert'), _t('Die Statistik wurde aktiviert.'));
|
||||
else
|
||||
$tpl->msg('error', _t('Fehler'), _t('Konnte die Statistik nicht aktivieren!'));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($cron->isExists() === true)
|
||||
{
|
||||
$cron->getInterval();
|
||||
|
||||
if ($cron->delete() === true)
|
||||
$tpl->msg('success', _t('Statistik deaktiviert'), _t('Die Statistik wurde deaktiviert.'));
|
||||
else
|
||||
$tpl->msg('error', _t('Fehler'), _t('Konnte die Statistik nicht deaktivieren!'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tpl->assign('address', getPluginConfig('main:address', 'http://fritz.box'));
|
||||
$tpl->assign('version', getPluginConfig('main:version', '5'));
|
||||
$tpl->assign('unit', getPluginConfig('main:unit', 'mbit'));
|
||||
$tpl->assign('activation', $cron->isExists());
|
||||
$tpl->assign('statistics', $statistics);
|
||||
|
||||
$tpl->draw('settings/settings');
|
||||
}
|
||||
elseif (isset($_GET['reset']))
|
||||
{
|
||||
if (!isset($statistics[$_GET['reset']]))
|
||||
$tpl->msg('error', _t('Fehler'), _t('Der Verlauf konnte nicht gefunden werden: %s', $_GET['reset']));
|
||||
|
||||
if (isset($_GET['confirm']) && $_GET['confirm'] == '')
|
||||
{
|
||||
if (isset($statistics[$_GET['reset']]))
|
||||
{
|
||||
if (($logFile = fopen(LOG_PATH.$statistics[$_GET['reset']]['array']['raw'].'.csv', 'w')) !== false)
|
||||
{
|
||||
$tpl->msg('success', _t('Verlauf zurückgesetzt'), _t('Verlauf wurde erfolgreich zurückgesetzt.'));
|
||||
fclose($logFile);
|
||||
}
|
||||
else
|
||||
$tpl->msg('error', _t('Fehler'), _t('Verlauf konnte nicht zurückgesetzt werden.'));
|
||||
}
|
||||
}
|
||||
|
||||
$tpl->assign('log', $_GET['reset']);
|
||||
$tpl->assign('label', $statistics[$_GET['reset']]['array']['title']);
|
||||
|
||||
$tpl->draw('settings/statistic_reset');
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
if (!defined('PICONTROL')) exit();
|
||||
|
||||
// English
|
||||
$langArray = array(
|
||||
'4694c564' => 'Fault!',
|
||||
'2f79edc7' => 'Settings for Fritz!Box',
|
||||
'0c7f3870' => 'Address to Fritz!Box',
|
||||
'e43dec7e' => 'Fritz!OS',
|
||||
'0f8654bd' => '5 and lower',
|
||||
'bd26ae3d' => '6 and higher',
|
||||
'5132311z' => 'View of speed',
|
||||
'b97d23bf' => 'Save',
|
||||
'9ba4b588' => 'Statistics',
|
||||
'2958e45z' => 'Activate',
|
||||
'49ee3087' => 'Name',
|
||||
'801ab246' => 'Download',
|
||||
'9b151bfe' => 'Reset',
|
||||
'f5ef8fd1' => 'Settings for Fritz!Box - Reset history',
|
||||
'9d266f6d' => 'Do you really want to reset the history of %s?',
|
||||
'bc028ee8' => 'User interface',
|
||||
'e1aeb5f1' => 'Go to user interface',
|
||||
'e2f04879' => 'Fritz!Box',
|
||||
'bf3cfcc6' => 'Update',
|
||||
'd490a3ea' => 'Model',
|
||||
'ec53a8c4' => 'Status',
|
||||
'e9bac601' => 'Connected since',
|
||||
'cbf40b3b' => 'Public IP address',
|
||||
'927da3c1' => 'Data volume received',
|
||||
'0eebe29d' => 'Data volume sent',
|
||||
'97b6ed19' => 'Load download',
|
||||
'7ce1502c' => 'Load upload',
|
||||
'a790b938' => 'Currently, there is no connection to a Fritz!Box!',
|
||||
'62c128cf' => 'Settings saved',
|
||||
'8e2b9292' => 'The settings have been successfully saved.',
|
||||
'52e5304c' => 'Fault',
|
||||
'e2db5207' => 'The settings could not be saved!',
|
||||
'd7a644a9' => 'Statistic activated',
|
||||
'938cc1fd' => 'The statistic was activated.',
|
||||
'e2e19e39' => 'Could not activate the statistic!',
|
||||
'90f601a7' => 'Statistic deactivated',
|
||||
'af3a796b' => 'The statistic was deactivated.',
|
||||
'bab5fef7' => 'Could not deactivate the statistic!',
|
||||
'e815ef70' => 'The history could not be found: %s',
|
||||
'58876dbf' => 'History reseted',
|
||||
'707a0c9b' => 'History has been reset successfully.',
|
||||
'b11d776d' => 'History could not be reset.',
|
||||
'b7ad3ac5' => 'Unconfigured',
|
||||
'7c87b201' => 'Connecting',
|
||||
'5a6b9647' => 'Authenticating',
|
||||
'2ec18699' => 'Pending disconnect',
|
||||
'a29ebc5e' => 'Disconnecting',
|
||||
'ab8a70de' => 'Disconnected',
|
||||
'62cfb21c' => 'Connected',
|
||||
'7182718z' => 'Time',
|
||||
'9ba51734' => 'Date',
|
||||
'c2f49325' => 'Maximum',
|
||||
'df16238b' => 'Maximum in Byte/s',
|
||||
'bf0373bd' => 'Load download in Byte/s',
|
||||
'3b07d168' => 'Load upload in Byte/s',
|
||||
'291bf9ed' => 'Together with a Fritz!Box you can get the current IP, the load of download and upload and the total sent data.'
|
||||
);
|
||||
?>
|
||||
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
if (!defined('PICONTROL')) exit();
|
||||
|
||||
function checkConnectionToFritzbox($address, $version)
|
||||
{
|
||||
if (!class_exists('cURL'))
|
||||
(include_once LIBRARY_PATH.'curl/curl.class.php') or die('Error: 9x1001');
|
||||
|
||||
$curl = new cURL($address.':49000/'.(($version == 5) ? 'tr64desc' : 'igddesc').'.xml');
|
||||
$curl->execute();
|
||||
|
||||
if ($curl->getStatusCode() == 200)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function getURLFromVersion($version)
|
||||
{
|
||||
switch ($version)
|
||||
{
|
||||
case 5:
|
||||
return 'upnp';
|
||||
case 6:
|
||||
return 'igdupnp';
|
||||
default:
|
||||
return 'upnp';
|
||||
}
|
||||
}
|
||||
|
||||
function getNameFromConnectionStatus($status)
|
||||
{
|
||||
switch ($status)
|
||||
{
|
||||
case 'Unconfigured':
|
||||
return 'Nicht konfiguriert';
|
||||
case 'Connecting':
|
||||
return 'Verbinde';
|
||||
case 'Authenticating':
|
||||
return 'Authentifizierung';
|
||||
case 'PendingDisconnect':
|
||||
return 'Ausstehende Trennung';
|
||||
case 'Disconnecting':
|
||||
return 'Trenne';
|
||||
case 'Disconnected':
|
||||
return 'Getrennt';
|
||||
case 'Connected':
|
||||
return 'Verbunden';
|
||||
default:
|
||||
return 'Nicht konfiguriert';
|
||||
}
|
||||
}
|
||||
|
||||
function getOptionsForConfigFromUnit($unit)
|
||||
{
|
||||
switch ($unit)
|
||||
{
|
||||
case 'mbyte':
|
||||
return array(
|
||||
'unit' => 'MB/s',
|
||||
'division' => 1048576
|
||||
);
|
||||
case 'mbit':
|
||||
default:
|
||||
return array(
|
||||
'unit' => 'MBit/s',
|
||||
'division' => 125000
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function getPublicIP($address, $version)
|
||||
{
|
||||
$ip = trim(shell_exec('curl "'.$address.':49000/'.getURLFromVersion($version).'/control/WANIPConn1" -H "Content-Type: text/xml; charset="utf-8"" -H "SoapAction:urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress" -d "<?xml version=\'1.0\' encoding=\'utf-8\'?> <s:Envelope s:encodingStyle=\'http://schemas.xmlsoap.org/soap/encoding/\' xmlns:s=\'http://schemas.xmlsoap.org/soap/envelope/\'> <s:Body> <u:GetExternalIPAddress xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1" /> </s:Body> </s:Envelope>" -s | grep -Eo \'\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>\''));
|
||||
|
||||
if (!filter_var($ip, FILTER_VALIDATE_IP))
|
||||
return false;
|
||||
|
||||
return $ip;
|
||||
}
|
||||
|
||||
function getConnectionStatus($address, $version)
|
||||
{
|
||||
exec('curl "'.$address.':49000/'.getURLFromVersion($version).'/control/WANIPConn1" -H "Content-Type: text/xml; charset="utf-8"" -H "SoapAction:urn:schemas-upnp-org:service:WANIPConnection:1#GetStatusInfo" -d "<?xml version=\'1.0\' encoding=\'utf-8\'?> <s:Envelope s:encodingStyle=\'http://schemas.xmlsoap.org/soap/encoding/\' xmlns:s=\'http://schemas.xmlsoap.org/soap/envelope/\'> <s:Body> <u:GetStatusInfo xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1" /> </s:Body> </s:Envelope>" -s | sed -e \'s/<[^>]*>//g;/^$/d\'', $status);
|
||||
|
||||
if (!is_array($status) || !is_numeric($status[2]))
|
||||
return false;
|
||||
|
||||
$output = array('status' => getNameFromConnectionStatus($status[0]),
|
||||
'uptime' => $status[2]);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
function getNetworkTraffic($address, $version)
|
||||
{
|
||||
exec('curl "'.$address.':49000/'.getURLFromVersion($version).'/control/WANCommonIFC1" -H "Content-Type: text/xml; charset="utf-8"" -H "SoapAction:urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1#GetAddonInfos" -d "<?xml version=\'1.0\' encoding=\'utf-8\'?> <s:Envelope s:encodingStyle=\'http://schemas.xmlsoap.org/soap/encoding/\' xmlns:s=\'http://schemas.xmlsoap.org/soap/envelope/\'> <s:Body> <u:GetAddonInfos xmlns:u="urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1" /> </s:Body> </s:Envelope>" -s | sed -e \'s/<[^>]*>//g;/^$/d\'', $traffic);
|
||||
|
||||
if (!is_array($traffic) || !is_numeric($traffic[4]) || !is_numeric($traffic[5]))
|
||||
return false;
|
||||
|
||||
$output = array('sent' => $traffic[4],
|
||||
'received' => $traffic[5]);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
function getCurrentBandwidth($address, $version)
|
||||
{
|
||||
exec('curl "'.$address.':49000/'.getURLFromVersion($version).'/control/WANCommonIFC1" -H "Content-Type: text/xml; charset="utf-8"" -H "SoapAction:urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1#GetAddonInfos" -d "<?xml version=\'1.0\' encoding=\'utf-8\'?> <s:Envelope s:encodingStyle=\'http://schemas.xmlsoap.org/soap/encoding/\' xmlns:s=\'http://schemas.xmlsoap.org/soap/envelope/\'> <s:Body> <u:GetAddonInfos xmlns:u="urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1" /> </s:Body> </s:Envelope>" -s | sed -e \'s/<[^>]*>//g;/^$/d\'', $bandwidth);
|
||||
|
||||
if (!is_array($bandwidth) || !is_numeric($bandwidth[0]) || !is_numeric($bandwidth[1]))
|
||||
return false;
|
||||
|
||||
$output = array('up' => $bandwidth[0],
|
||||
'down' => $bandwidth[1]);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
function getMaxBandwidth($address, $version)
|
||||
{
|
||||
exec('curl "'.$address.':49000/'.getURLFromVersion($version).'/control/WANCommonIFC1" -H "Content-Type: text/xml; charset="utf-8"" -H "SoapAction:urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1#GetCommonLinkProperties" -d "<?xml version=\'1.0\' encoding=\'utf-8\'?> <s:Envelope s:encodingStyle=\'http://schemas.xmlsoap.org/soap/encoding/\' xmlns:s=\'http://schemas.xmlsoap.org/soap/envelope/\'> <s:Body> <u:GetCommonLinkProperties xmlns:u="urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1" /> </s:Body> </s:Envelope>" -s | sed -e \'s/<[^>]*>//g;/^$/d\'', $bandwidth);
|
||||
|
||||
if (!is_array($bandwidth) || !is_numeric($bandwidth[1]) || !is_numeric($bandwidth[2]))
|
||||
return false;
|
||||
|
||||
$output = array('up' => $bandwidth[1],
|
||||
'down' => $bandwidth[2]);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
function getModelName($address, $version)
|
||||
{
|
||||
$modelName = trim(shell_exec('curl "'.$address.':49000/'.(($version == 5) ? 'tr64desc' : 'igddesc').'.xml" -s | grep modelName | sed -n 1p | sed -e \'s/<[^>]*>//g;/^$/d\''));
|
||||
|
||||
if (!is_string($modelName))
|
||||
return false;
|
||||
|
||||
return $modelName;
|
||||
}
|
||||
|
||||
function convertToUnit($size, $unit, $current = 'bit')
|
||||
{
|
||||
if ($unit == 'mbit')
|
||||
{
|
||||
if ($current == 'byte')
|
||||
$size *= 8;
|
||||
|
||||
return number_format(round($size/1000/1000, 2), 2, ',', '').' MBit/s';
|
||||
}
|
||||
elseif ($unit == 'mbyte')
|
||||
{
|
||||
if ($current == 'bit')
|
||||
$size /= 8;
|
||||
|
||||
return number_format(round($size/1024/1024, 2), 2, ',', '').' MB/s';
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function getPercentageFromBandwidth($current, $max)
|
||||
{
|
||||
if ($max == 0)
|
||||
return 0;
|
||||
|
||||
$percentage = round(($current*8) / $max, 2) * 100;
|
||||
|
||||
if ($percentage > 100)
|
||||
return 100;
|
||||
|
||||
return $percentage;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
if (PHP_SAPI != 'cli') exit();
|
||||
define('PICONTROL', true);
|
||||
|
||||
$doNotCheckForAuthentification = true;
|
||||
(include_once realpath(dirname(__FILE__)).'/../../../../init.php') or die('Error: 0x0000');
|
||||
(include_once LIBRARY_PATH.'main/main.function.php') or die('Error: 0x0001');
|
||||
(include_once LIBRARY_PATH.'statistic/statistic.class.php') or die('Error: 0x0002');
|
||||
(include_once LIBRARY_PATH.'plugin/plugin.function.php') or die('Error: 0x0003');
|
||||
|
||||
initPluginConstants();
|
||||
(include_once PLUGIN_PATH.'resources/library/main/main.function.php') or die('Error: 9x0001');
|
||||
|
||||
$fritzboxAddress = getPluginConfig('main:address', 'http://fritz.box');
|
||||
$fritzboxVersion = getPluginConfig('main:version', '5');
|
||||
|
||||
$currentBandwidth = getCurrentBandwidth($fritzboxAddress, $fritzboxVersion);
|
||||
$maxBandwidth = getMaxBandwidth($fritzboxAddress, $fritzboxVersion);
|
||||
|
||||
if (is_array($currentBandwidth) && is_array($maxBandwidth))
|
||||
{
|
||||
$log = new LogStatistic();
|
||||
$log->setFile(LOG_PATH.'plugin/fritzbox.traffic-download.csv');
|
||||
$log->setLimit(1008);
|
||||
$log->add(array(time(), round($maxBandwidth['down']/8), $currentBandwidth['down']));
|
||||
$log->close();
|
||||
|
||||
$log = new LogStatistic();
|
||||
$log->setFile(LOG_PATH.'plugin/fritzbox.traffic-upload.csv');
|
||||
$log->setLimit(1008);
|
||||
$log->add(array(time(), round($maxBandwidth['up']/8), $currentBandwidth['up']));
|
||||
$log->close();
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user