From 422063168fe225b8ee0a9fb9a46ec8c348dfea56 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 22 Oct 2013 19:00:23 +0000 Subject: [PATCH] luci2: add intial LuCI2.firewall abstraction class --- luci2/htdocs/luci2/luci2.js | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/luci2/htdocs/luci2/luci2.js b/luci2/htdocs/luci2/luci2.js index d2ad812..983e3d2 100644 --- a/luci2/htdocs/luci2/luci2.js +++ b/luci2/htdocs/luci2/luci2.js @@ -1188,6 +1188,57 @@ function LuCI2() } }; + this.firewall = { + getZoneColor: function(zone) + { + if ($.isPlainObject(zone)) + zone = zone.name; + + if (zone == 'lan') + return '#90f090'; + else if (zone == 'wan') + return '#f09090'; + + for (var i = 0, hash = 0; + i < zone.length; + hash = zone.charCodeAt(i++) + ((hash << 5) - hash)); + + for (var i = 0, color = '#'; + i < 3; + color += ('00' + ((hash >> i++ * 8) & 0xFF).tozoneing(16)).slice(-2)); + + return color; + }, + + findZoneByNetwork: function(network) + { + var self = this; + var zone = undefined; + + return _luci2.uci.foreach('firewall', 'zone', function(z) { + if (!z.name || !z.network) + return; + + if (!$.isArray(z.network)) + z.network = z.network.split(/\s+/); + + for (var i = 0; i < z.network.length; i++) + { + if (z.network[i] == network) + { + zone = z; + break; + } + } + }).then(function() { + if (zone) + zone.color = self.getZoneColor(zone); + + return zone; + }); + } + }; + this.system = { getSystemInfo: _luci2.rpc.declare({ object: 'system', -- 2.30.2