From 7baae58c613f232322c3104ed54c2d32791c6cc5 Mon Sep 17 00:00:00 2001
From: Jo-Philipp Wich
Date: Sat, 12 Oct 2013 20:25:45 +0000
Subject: [PATCH] luci2: add network diagnostics view
---
.../htdocs/luci2/template/network.diagnostics.htm | 18 +++++++
luci2/htdocs/luci2/view/network.diagnostics.js | 55 ++++++++++++++++++++++
luci2/share/acl.d/luci2.json | 15 ++++++
luci2/share/menu.d/network.json | 6 +++
4 files changed, 94 insertions(+)
create mode 100644 luci2/htdocs/luci2/template/network.diagnostics.htm
create mode 100644 luci2/htdocs/luci2/view/network.diagnostics.js
diff --git a/luci2/htdocs/luci2/template/network.diagnostics.htm b/luci2/htdocs/luci2/template/network.diagnostics.htm
new file mode 100644
index 0000000..4c82c7f
--- /dev/null
+++ b/luci2/htdocs/luci2/template/network.diagnostics.htm
@@ -0,0 +1,18 @@
+<%:Select the utility to run and click "Test" to perform the requested operation.%>
+
+
+
+
+
diff --git a/luci2/htdocs/luci2/view/network.diagnostics.js b/luci2/htdocs/luci2/view/network.diagnostics.js
new file mode 100644
index 0000000..99f185a
--- /dev/null
+++ b/luci2/htdocs/luci2/view/network.diagnostics.js
@@ -0,0 +1,55 @@
+L.ui.view.extend({
+ title: L.tr('Diagnostics'),
+
+ execute: function() {
+ var self = this;
+ var tools = [ ];
+
+ $.when(
+ L.network.runPing('?').then(function(rv) {
+ if (rv.code != -1) tools.push(['runPing', L.tr('IPv4 Ping')]);
+ }),
+ L.network.runPing6('?').then(function(rv) {
+ if (rv.code != -1) tools.push(['runPing6', L.tr('IPv6 Ping')]);
+ }),
+ L.network.runTraceroute('?').then(function(rv) {
+ if (rv.code != -1) tools.push(['runTraceroute', L.tr('IPv4 Traceroute')]);
+ }),
+ L.network.runTraceroute6('?').then(function(rv) {
+ if (rv.code != -1) tools.push(['runTraceroute6', L.tr('IPv6 Tracroute')]);
+ }),
+ L.network.runNslookup('?').then(function(rv) {
+ if (rv.code != -1) tools.push(['runNslookup', L.tr('DNS Lookup')]);
+ })
+ ).then(function() {
+ tools.sort(function(a, b) {
+ if (a[0] < b[0])
+ return -1;
+ else if (a[0] > b[0])
+ return 1;
+ else
+ return 0;
+ });
+
+ for (var i = 0; i < tools.length; i++)
+ $('#tool').append($('').attr('value', tools[i][0]).text(tools[i][1]));
+
+ $('#tool').val('runPing');
+
+ $('#run').click(function() {
+ L.ui.loading(true);
+ L.network[$('#tool').val()]($('#host').val()).then(function(rv) {
+ $('#output').empty().show();
+
+ if (rv.stdout)
+ $('#output').text(rv.stdout);
+
+ if (rv.stderr)
+ $('#output').append($('').css('color', 'red').text(rv.stderr));
+
+ L.ui.loading(false);
+ });
+ });
+ });
+ }
+});
diff --git a/luci2/share/acl.d/luci2.json b/luci2/share/acl.d/luci2.json
index 62057f3..e8e6949 100644
--- a/luci2/share/acl.d/luci2.json
+++ b/luci2/share/acl.d/luci2.json
@@ -294,5 +294,20 @@
"network"
]
}
+ },
+
+ "diagnostics": {
+ "description": "Network diagnostic tools",
+ "read": {
+ "ubus": {
+ "luci2.network": [
+ "ping",
+ "ping6",
+ "traceroute",
+ "traceroute6",
+ "nslookup"
+ ]
+ }
+ }
}
}
diff --git a/luci2/share/menu.d/network.json b/luci2/share/menu.d/network.json
index 94078e0..fc6f236 100644
--- a/luci2/share/menu.d/network.json
+++ b/luci2/share/menu.d/network.json
@@ -8,5 +8,11 @@
"acls": [ "switch" ],
"view": "network/switch",
"index": 30
+ },
+ "network/diagnostics": {
+ "title": "Diagnostics",
+ "acls": [ "diagnostics" ],
+ "view": "network/diagnostics",
+ "index": 80
}
}
--
2.11.0