From d0cb158e34c20d0a78dc23cfd5757d10430e121f Mon Sep 17 00:00:00 2001 From: danrl Date: Fri, 17 Feb 2017 11:08:46 +0100 Subject: luci-app-cshark: initial commit Moved over here from the packages repository. Signed-off-by: Dan Luedtke --- applications/luci-app-cshark/Makefile | 17 ++ .../luci-app-cshark/luasrc/controller/cshark.lua | 125 +++++++++ .../luasrc/model/cbi/admin_network/cshark.lua | 30 +++ .../luci-app-cshark/luasrc/view/cshark.htm | 291 +++++++++++++++++++++ 4 files changed, 463 insertions(+) create mode 100644 applications/luci-app-cshark/Makefile create mode 100644 applications/luci-app-cshark/luasrc/controller/cshark.lua create mode 100644 applications/luci-app-cshark/luasrc/model/cbi/admin_network/cshark.lua create mode 100644 applications/luci-app-cshark/luasrc/view/cshark.htm diff --git a/applications/luci-app-cshark/Makefile b/applications/luci-app-cshark/Makefile new file mode 100644 index 0000000000..40b0e9fb7f --- /dev/null +++ b/applications/luci-app-cshark/Makefile @@ -0,0 +1,17 @@ +# +# Copyright (C) 2017 Dan Luedtke +# +# This is free software, licensed under the Apache License, Version 2.0 . +# + +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=Cloudshark capture tool Web UI +LUCI_DEPENDS:=+cshark +LUCI_PKGARCH:=all + +PKG_MAINTAINER:=Luka Perkov + +include ../../luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/applications/luci-app-cshark/luasrc/controller/cshark.lua b/applications/luci-app-cshark/luasrc/controller/cshark.lua new file mode 100644 index 0000000000..4d9bbba290 --- /dev/null +++ b/applications/luci-app-cshark/luasrc/controller/cshark.lua @@ -0,0 +1,125 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright (C) 2014, QA Cafe, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +]]-- + +module("luci.controller.cshark", package.seeall) + +function index() + page = node("admin", "network", "cloudshark") + page.target = cbi("admin_network/cshark") + page.title = _("CloudShark") + page.order = 70 + + page = entry({"admin", "network", "cshark_iface_dump_start"}, call("cshark_iface_dump_start"), nil) + page.leaf = true + + page = entry({"admin", "network", "cshark_iface_dump_stop"}, call("cshark_iface_dump_stop"), nil) + page.leaf = true + + page = entry({"admin", "network", "cshark_check_status"}, call("cshark_check_status"), nil) + page.leaf = true + + page = entry({"admin", "network", "cshark_link_list_get"}, call("cshark_link_list_get"), nil) + page.leaf = true + + page = entry({"admin", "network", "cshark_link_list_clear"}, call("cshark_link_list_clear"), nil) + page.leaf = true +end + +function cshark_iface_dump_start(ifname, value, flag, filter) + if ifname == nil or ifname == '' then + ifname = 'any' + end + if tonumber(value) == nil + then + value = '0' + end + if filter == nil or filter == '' then + filter = '' + end + + if flag == nil or flag == '' then + filter = 'T' + end + + luci.http.prepare_content("text/plain") + + local res = os.execute("(/sbin/cshark -i " .. ifname .. " -" .. flag .. " " .. value .. " -p /tmp/cshark-luci.pid " .. filter .. " > /tmp/cshark-luci.out 2>&1) &") + luci.http.write(tostring(res)) +end + +function cshark_iface_dump_stop() + luci.http.prepare_content("text/plain") + + local f = io.open("/tmp/cshark-luci.pid", "rb") + local pid = f:read("*all") + io.close(f) + + local res = os.execute("kill -TERM " .. pid) + luci.http.write(tostring(res)) +end + +function cshark_check_status() + + local msg = ""; + local status; + local f = io.open("/tmp/cshark-luci.pid","r") + if f ~= nil then + status = 1; + io.close(f) + else + status = 0; + end + + f = io.open("/tmp/cshark-luci.out","r") + if f ~= nil then + msg = f:read("*all") + io.close(f) + if msg ~= '' then + os.remove('/tmp/cshark-luci.out') + end + end + + luci.http.prepare_content("application/json") + + local res = {} + res["status"] = status; + res["msg"] = msg; + + luci.http.write_json(res) +end + +function cshark_link_list_get() + local uci = require("uci").cursor() + + luci.http.prepare_content("application/json") + + luci.http.write("[") + + local t = uci:get("cshark", "cshark", "entry") + if (t ~= nil) then + for i = #t, 1, -1 do + luci.http.write("[\"" .. t[i] .. "\"],") + end + end + + luci.http.write("[]]") +end + +function cshark_link_list_clear() + local uci = require("uci").cursor() + + uci:delete("cshark", "cshark", "entry") + uci:commit("cshark"); + + luci.http.status(200, "OK") +end diff --git a/applications/luci-app-cshark/luasrc/model/cbi/admin_network/cshark.lua b/applications/luci-app-cshark/luasrc/model/cbi/admin_network/cshark.lua new file mode 100644 index 0000000000..8db95596f8 --- /dev/null +++ b/applications/luci-app-cshark/luasrc/model/cbi/admin_network/cshark.lua @@ -0,0 +1,30 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright (C) 2014, QA Cafe, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ +]]-- + +local fs = require "nixio.fs" + +m = Map("cshark", translate("CloudShark")) + +if fs.access("/etc/config/cshark") then + m:section(SimpleSection).template = "cshark" + + s = m:section(TypedSection, "cshark", translate("Options")) + s.anonymous = true + s.addremove = false + + s:option(Value, "url", translate("CloudShark URL")) + s:option(Value, "token", translate("CloudShark API token")) +end + +return m diff --git a/applications/luci-app-cshark/luasrc/view/cshark.htm b/applications/luci-app-cshark/luasrc/view/cshark.htm new file mode 100644 index 0000000000..bc67f806c4 --- /dev/null +++ b/applications/luci-app-cshark/luasrc/view/cshark.htm @@ -0,0 +1,291 @@ +<%# +LuCI - Lua Configuration Interface + +Copyright (C) 2014, QA Cafe, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ + +-%> + +
+ <%:Start network capture%> +
+ + + + + + + + + + + + + +
<%:Interface%><%:seconds, packets, bytes%><%:Filter%><%:Actions%>
+ + + + + + + + +
+
+
+ +
+ +
+ +
+ +
+ <%:Capture links%> +
+ + + + + + +
+
+ +
+ Visit support.cloudshark.org for help. +
+ +
+ + + -- cgit v1.2.3