@H_403_0@由于刚毕业的穷大学生,和朋友合租了一台服务器开了多个端口提供 ss 服务,懒得配置 ss-panel,就使用了 ss-bash 来监控不同端口的流量,但每次都要等上服务器才能看到流量使用情况,很麻烦,于是就写了个简单的页面来提供 WEB 访问。
@H_4030@
JavaScript 版本
@H403_0@用 crontab 定时把流量记录文件复制到 WEB 目录下,写个 JS 脚本作数据处理。
<div class="jb51code">
<pre class="brush:js;">
function successFunction(data) {
var allRows = data.split(/\r?\n|\r/);
var table = '<table class="table table-hover" style="width: 50%; margin: auto;">';
for (var singleRow = 0; singleRow < allRows.length; singleRow++) {
if (singleRow === 0) {
table += '';
table += '<tr>';
} else {
table += '<tr>';
}
var rowCells = allRows[singleRow].split(',');
for (var rowCell = 0; rowCell < rowCells.length; rowCell++) {
if (singleRow === 0) {
table += '<th class="text-right">';
table += rowCells[rowCell];
table += '';
} else {
table += '<td class="text-right">';
table += rowCells[rowCell];
table += '</td>';
}
}
if (singleRow === 0) {
table += '</tr>';
table += '';
table += '';
} else {
table += '</tr>';
}
}
table += '';
table += '</table>';
$('body').append(table);
}