2 LuCI - Lua Configuration Interface
4 Copyright (C) 2014, QA Cafe, Inc.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
14 module("luci.controller.cshark", package.seeall)
17 page = node("admin", "network", "cloudshark")
18 page.target = cbi("admin_network/cshark")
19 page.title = _("CloudShark")
22 page = entry({"admin", "network", "cshark_iface_dump_start"}, call("cshark_iface_dump_start"), nil)
25 page = entry({"admin", "network", "cshark_iface_dump_stop"}, call("cshark_iface_dump_stop"), nil)
28 page = entry({"admin", "network", "cshark_check_status"}, call("cshark_check_status"), nil)
31 page = entry({"admin", "network", "cshark_link_list_get"}, call("cshark_link_list_get"), nil)
34 page = entry({"admin", "network", "cshark_link_list_clear"}, call("cshark_link_list_clear"), nil)
38 function cshark_iface_dump_start(ifname, value, flag, filter)
39 if ifname == nil or ifname == '' then
42 if tonumber(value) == nil
46 if filter == nil or filter == '' then
50 if flag == nil or flag == '' then
54 luci.http.prepare_content("text/plain")
56 local res = os.execute("(/sbin/cshark -i " .. ifname .. " -" .. flag .. " " .. value .. " -p /tmp/cshark-luci.pid " .. filter .. " > /tmp/cshark-luci.out 2>&1) &")
57 luci.http.write(tostring(res))
60 function cshark_iface_dump_stop()
61 luci.http.prepare_content("text/plain")
63 local f = io.open("/tmp/cshark-luci.pid", "rb")
64 local pid = f:read("*all")
67 local res = os.execute("kill -TERM " .. pid)
68 luci.http.write(tostring(res))
71 function cshark_check_status()
75 local f = io.open("/tmp/cshark-luci.pid","r")
83 f = io.open("/tmp/cshark-luci.out","r")
88 os.remove('/tmp/cshark-luci.out')
92 luci.http.prepare_content("application/json")
95 res["status"] = status;
98 luci.http.write_json(res)
101 function cshark_link_list_get()
102 local uci = require("uci").cursor()
104 luci.http.prepare_content("application/json")
108 local t = uci:get("cshark", "cshark", "entry")
111 luci.http.write("[\"" .. t[i] .. "\"],")
115 luci.http.write("[]]")
118 function cshark_link_list_clear()
119 local uci = require("uci").cursor()
121 uci:delete("cshark", "cshark", "entry")
122 uci:commit("cshark");
124 luci.http.status(200, "OK")