Implements comprehensive bandwidth management system with QoS traffic shaping, client quotas, and SQM/CAKE integration for OpenWrt. Features: - QoS traffic shaping with rule-based control (application/port/IP/MAC) - Per-rule download/upload limits with 8-level priority system - Time-based scheduling support for rules - Monthly data quotas per client (MAC address) - iptables-based usage tracking with real-time statistics - Configurable quota actions: throttle, block, or notify - Automatic monthly reset with configurable reset day - SQM/CAKE integration with NAT-aware configuration - Link overhead compensation (Ethernet, PPPoE, VLAN) - Alternative FQ_CoDel and HTB qdisc support Components: - RPCD backend (luci.bandwidth-manager): 10 ubus methods * status, list_rules, add_rule, delete_rule * list_quotas, get_quota, set_quota, reset_quota * get_usage_realtime, get_usage_history - 5 JavaScript views: overview, rules, quotas, usage, settings - ACL with read/write permissions for all methods - UCI config with global, SQM, tracking, alerts, rules, and quotas sections - Comprehensive README with API docs and examples Technical implementation: - Traffic tracking via iptables BW_TRACKING chain - Usage database in /tmp/bandwidth_usage.db (pipe-delimited format) - Real-time client usage with 5-second auto-refresh - Historical data with configurable timeframes (1h to 30d) - Per-client quota progress visualization with color-coded bars - TC (traffic control) integration for QoS enforcement Architecture follows SecuBox standards: - RPCD naming convention (luci. prefix) - Menu paths match view file structure - All JavaScript in strict mode - Form-based configuration management - Comprehensive error handling Dependencies: tc, kmod-sched-core, kmod-sched-cake, kmod-ifb, sqm-scripts, iptables, iptables-mod-conntrack-extra, ip-full 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
171 lines
5.3 KiB
JavaScript
171 lines
5.3 KiB
JavaScript
'use strict';
|
|
'require view';
|
|
'require bandwidth-manager/api as API';
|
|
|
|
return L.view.extend({
|
|
load: function() {
|
|
return Promise.all([
|
|
API.getStatus(),
|
|
API.listRules(),
|
|
API.listQuotas()
|
|
]);
|
|
},
|
|
|
|
render: function(data) {
|
|
var status = data[0] || {};
|
|
var rules = data[1] || [];
|
|
var quotas = data[2] || [];
|
|
|
|
var v = E('div', { 'class': 'cbi-map' }, [
|
|
E('h2', {}, _('Bandwidth Manager - Overview')),
|
|
E('div', { 'class': 'cbi-map-descr' }, _('QoS rules, client quotas, and traffic control'))
|
|
]);
|
|
|
|
// System status
|
|
var statusSection = E('div', { 'class': 'cbi-section' }, [
|
|
E('h3', {}, _('System Status')),
|
|
E('div', { 'class': 'table' }, [
|
|
E('div', { 'class': 'tr' }, [
|
|
E('div', { 'class': 'td left', 'width': '25%' }, [
|
|
E('strong', {}, _('QoS Engine: ')),
|
|
status.qos_active ?
|
|
E('span', { 'style': 'color: green' }, '● ' + _('Active')) :
|
|
E('span', { 'style': 'color: red' }, '● ' + _('Inactive'))
|
|
]),
|
|
E('div', { 'class': 'td left', 'width': '25%' }, [
|
|
E('strong', {}, _('Interface: ')),
|
|
E('span', {}, status.interface || 'br-lan')
|
|
]),
|
|
E('div', { 'class': 'td left', 'width': '25%' }, [
|
|
E('strong', {}, _('SQM: ')),
|
|
status.sqm_enabled ?
|
|
E('span', { 'style': 'color: green' }, '✓ ' + _('Enabled')) :
|
|
E('span', {}, '✗ ' + _('Disabled'))
|
|
]),
|
|
E('div', { 'class': 'td left', 'width': '25%' }, [
|
|
E('strong', {}, _('Rules: ')),
|
|
E('span', { 'style': 'font-size: 1.3em; color: #0088cc' }, String(status.rule_count || 0))
|
|
])
|
|
])
|
|
])
|
|
]);
|
|
v.appendChild(statusSection);
|
|
|
|
// Traffic statistics
|
|
if (status.stats) {
|
|
var statsSection = E('div', { 'class': 'cbi-section' }, [
|
|
E('h3', {}, _('Traffic Statistics')),
|
|
E('div', { 'class': 'table' }, [
|
|
E('div', { 'class': 'tr' }, [
|
|
E('div', { 'class': 'td left', 'width': '50%' }, [
|
|
E('strong', {}, '⬇ ' + _('Download: ')),
|
|
E('span', {}, this.formatBytes(status.stats.rx_bytes || 0))
|
|
]),
|
|
E('div', { 'class': 'td left', 'width': '50%' }, [
|
|
E('strong', {}, '⬆ ' + _('Upload: ')),
|
|
E('span', {}, this.formatBytes(status.stats.tx_bytes || 0))
|
|
])
|
|
]),
|
|
E('div', { 'class': 'tr' }, [
|
|
E('div', { 'class': 'td left', 'width': '50%' }, [
|
|
E('strong', {}, _('RX Packets: ')),
|
|
E('span', {}, String(status.stats.rx_packets || 0))
|
|
]),
|
|
E('div', { 'class': 'td left', 'width': '50%' }, [
|
|
E('strong', {}, _('TX Packets: ')),
|
|
E('span', {}, String(status.stats.tx_packets || 0))
|
|
])
|
|
])
|
|
])
|
|
]);
|
|
v.appendChild(statsSection);
|
|
}
|
|
|
|
// Active rules summary
|
|
if (rules.length > 0) {
|
|
var rulesSection = E('div', { 'class': 'cbi-section' }, [
|
|
E('h3', {}, _('Active QoS Rules'))
|
|
]);
|
|
|
|
var rulesTable = E('table', { 'class': 'table' }, [
|
|
E('tr', { 'class': 'tr table-titles' }, [
|
|
E('th', { 'class': 'th' }, _('Name')),
|
|
E('th', { 'class': 'th' }, _('Type')),
|
|
E('th', { 'class': 'th' }, _('Target')),
|
|
E('th', { 'class': 'th' }, _('Download Limit')),
|
|
E('th', { 'class': 'th' }, _('Priority'))
|
|
])
|
|
]);
|
|
|
|
rules.slice(0, 5).forEach(function(rule) {
|
|
if (!rule.enabled)
|
|
return;
|
|
|
|
rulesTable.appendChild(E('tr', { 'class': 'tr' }, [
|
|
E('td', { 'class': 'td' }, rule.name),
|
|
E('td', { 'class': 'td' }, rule.type),
|
|
E('td', { 'class': 'td' }, rule.target),
|
|
E('td', { 'class': 'td' }, rule.limit_down > 0 ? rule.limit_down + ' kbit/s' : _('Unlimited')),
|
|
E('td', { 'class': 'td' }, String(rule.priority))
|
|
]));
|
|
});
|
|
|
|
rulesSection.appendChild(rulesTable);
|
|
v.appendChild(rulesSection);
|
|
}
|
|
|
|
// Client quotas summary
|
|
if (quotas.length > 0) {
|
|
var quotasSection = E('div', { 'class': 'cbi-section' }, [
|
|
E('h3', {}, _('Client Quotas'))
|
|
]);
|
|
|
|
var quotasTable = E('table', { 'class': 'table' }, [
|
|
E('tr', { 'class': 'tr table-titles' }, [
|
|
E('th', { 'class': 'th' }, _('Client')),
|
|
E('th', { 'class': 'th' }, _('MAC')),
|
|
E('th', { 'class': 'th' }, _('Usage')),
|
|
E('th', { 'class': 'th' }, _('Limit')),
|
|
E('th', { 'class': 'th' }, _('Progress'))
|
|
])
|
|
]);
|
|
|
|
quotas.slice(0, 5).forEach(function(quota) {
|
|
var progressColor = quota.percent > 90 ? 'red' : (quota.percent > 75 ? 'orange' : 'green');
|
|
|
|
quotasTable.appendChild(E('tr', { 'class': 'tr' }, [
|
|
E('td', { 'class': 'td' }, quota.name || quota.mac),
|
|
E('td', { 'class': 'td' }, E('code', {}, quota.mac)),
|
|
E('td', { 'class': 'td' }, quota.used_mb + ' MB'),
|
|
E('td', { 'class': 'td' }, quota.limit_mb + ' MB'),
|
|
E('td', { 'class': 'td' }, [
|
|
E('div', { 'style': 'background: #eee; width: 100px; height: 10px; border-radius: 5px;' }, [
|
|
E('div', {
|
|
'style': 'background: ' + progressColor + '; width: ' + Math.min(quota.percent, 100) + '%; height: 100%; border-radius: 5px;'
|
|
})
|
|
]),
|
|
E('small', {}, quota.percent + '%')
|
|
])
|
|
]));
|
|
});
|
|
|
|
quotasSection.appendChild(quotasTable);
|
|
v.appendChild(quotasSection);
|
|
}
|
|
|
|
return v;
|
|
},
|
|
|
|
formatBytes: function(bytes) {
|
|
if (bytes === 0) return '0 B';
|
|
var k = 1024;
|
|
var sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
var i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
|
},
|
|
|
|
handleSaveApply: null,
|
|
handleSave: null,
|
|
handleReset: null
|
|
});
|