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 %s -%s %s -p /tmp/cshark-luci.pid %s > /tmp/cshark-luci.out 2>&1) &" %{
57 luci.util.shellquote(ifname),
58 luci.util.shellquote(flag),
59 luci.util.shellquote(value),
60 luci.util.shellquote(filter)
63 luci.http.write(tostring(res))
66 function cshark_iface_dump_stop()
67 luci.http.prepare_content("text/plain")
69 local f = io.open("/tmp/cshark-luci.pid", "rb")
70 local pid = f:read("*all")
73 local res = os.execute("kill -TERM " .. pid)
74 luci.http.write(tostring(res))
77 function cshark_check_status()
81 local f = io.open("/tmp/cshark-luci.pid","r")
89 f = io.open("/tmp/cshark-luci.out","r")
94 os.remove('/tmp/cshark-luci.out')
98 luci.http.prepare_content("application/json")
101 res["status"] = status;
104 luci.http.write_json(res)
107 function cshark_link_list_get()
108 local uci = require("uci").cursor()
110 luci.http.prepare_content("application/json")
114 local t = uci:get("cshark", "cshark", "entry")
117 luci.http.write("[\"" .. t[i] .. "\"],")
121 luci.http.write("[]]")
124 function cshark_link_list_clear()
125 local uci = require("uci").cursor()
127 uci:delete("cshark", "cshark", "entry")
128 uci:commit("cshark");
130 luci.http.status(200, "OK")