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
16 <fieldset class=
"cbi-section">
17 <legend><%:Start network capture%
></legend>
18 <div class=
"cbi-section-node">
19 <table class=
"cbi-section-table">
21 <th><%:Interface%
></th>
22 <th colspan='
2'
><%:seconds, packets, bytes%
></th>
28 <select title=
"<%:Interface%>" style=
"width:auto" id=
"s_interfaces">
30 local nixio = require
"nixio"
31 for k, v in ipairs(nixio.getifaddrs()) do
32 if v.family ==
"packet" then
34 <option value=
"<%=v.name%>"><%=v.name%
> </option>
39 <option value=
"any"><%:any%
></option>
43 <input id=
"tx_value" type=
"text" value=
"0" />
44 <select title=
"<%:timeout, bytes, seconds%>" id=
"s_value_type" style=
"width:auto">
45 <option value=
"T"><%:seconds%
></option>
46 <option value=
"P"><%:packets%
></option>
47 <option value=
"S"><%:bytes%
></option>
51 <input style=
"margin: 5px 0" type=
"text" title=
"<%:Filter%>" placeholder=
"filter" id=
"i_filter" />
54 <input type=
"button" id=
"bt_action" data-action=
"start" value=
"<%:Start capture%>" class=
"cbi-button" />
61 <fieldset class=
"cbi-section">
62 <span id=
"cshark-rc-output"></span>
67 <fieldset class=
"cbi-section">
68 <legend><%:Capture links%
></legend>
69 <div class=
"cbi-section-node">
70 <table id=
"t_link_list" class=
"cbi-section-table">
71 <tr class=
"cbi-section-table-titles">
72 <th class=
"cbi-section-table-cell"><%:Capture URL%
></th>
73 <th class=
"cbi-section-table-cell"><%:Capture time%
></th>
79 <fieldset class=
"cbi-section">
80 <a href=
"https://support.cloudshark.org/openwrt/openwrt-cloudshark.html" target=
"_blank">Visit support.cloudshark.org for help.
</a>
85 <script type=
"text/javascript">//<![CDATA[
87 var capture_running =
0;
89 var bt_action = document.getElementById('bt_action');
90 var a_clear_links = document.getElementById('a_clear_links');
91 var output = document.getElementById('cshark-rc-output');
92 var loader = '
<img src=
"<%=resource%>/icons/loading.gif" alt=
"<%:Loading%>" width=
"16" height=
"16" style=
"vertical-align:middle" /> ';
93 var msg = { 'start' : '<%:Waiting for capture to complete...%
>', 'stop' : '<%:Waiting for upload to complete...%
>' };
94 var status_msg = msg['start'];
96 function get_date(timestamp)
100 return (str <
10) ?
"0" + str : str;
103 var current_date = new Date(timestamp *
1000);
104 return current_date.getFullYear() +
"-" +
105 pad_str(current_date.getMonth() +
1) +
"-" +
106 pad_str(current_date.getDate()) +
" " +
107 pad_str(current_date.getHours()) +
":" +
108 pad_str(current_date.getMinutes()) +
":" +
109 pad_str(current_date.getSeconds());
112 bt_action.onclick = function()
114 var action = this.getAttribute(
"data-action");
115 var csxhr = new XHR();
117 if (action ==
"stop")
119 update_status(action);
121 bt_action.disabled = true;
123 csxhr.get('<%=luci.dispatcher.build_url(
"admin",
"network")%
>/cshark_iface_dump_stop', null,
126 if (!x || x.responseText.trim() !=
"0")
128 update_status(
"failed",
"Invalid response on stop.");
133 else if (action ==
"start")
136 var s_interfaces = document.getElementById('s_interfaces');
137 var s_value_type = document.getElementById('s_value_type');
138 var i_filter = document.getElementById('i_filter');
140 var if_n = s_interfaces.selectedIndex;
141 var t_n = s_value_type.selectedIndex;
142 var ifname = s_interfaces.options[if_n].value.trim();
143 var filter_val = i_filter.value.trim();
144 var tx_val = document.getElementById('tx_value').value.trim();
145 var type_val = s_value_type.options[t_n].value.trim();
147 if (type_val != 'P' && type_val != 'T' && type_val != 'S') type_val = 'T';
149 if (!ifname || !type_val) return;
151 if (isNaN(tx_val)) return alert(
"<%:value for [seconds, packets, bytes] must be Integer%>");
153 update_status(action);
155 csxhr.get('<%=luci.dispatcher.build_url(
"admin",
"network")%
>/cshark_iface_dump_start/' + ifname + '/' + tx_val + '/' + type_val + '/'+ filter_val, null,
159 update_status(
"failed",
"Invalid response on start.");
161 update_status(
"running");
166 function update_status(status, message)
172 status_msg = msg[status];
173 output.innerHTML = loader + status_msg;
177 if (capture_running) break;;
179 output.innerHTML = loader + status_msg;
181 bt_action.value = '<%:Stop capture%
>';
182 bt_action.setAttribute('data-action', 'stop');
188 if (!capture_running) break;
190 if (status ==
"completed")
195 output.innerHTML =
"<pre>" + message +
"</pre>";
196 bt_action.value = '<%:Start capture%
>';
197 bt_action.setAttribute('data-action', 'start');
198 bt_action.disabled = false;
205 function check_status()
208 XHR.poll(
3, '<%=luci.dispatcher.build_url(
"admin",
"network")%
>/cshark_check_status', null,
214 update_status(
"failed",
"Invalid response when fetching status.");
220 update_status( (data.status ==
1) &&
"running" ||
"completed", data.msg);
224 function link_list_clear()
226 var csxhr_del = new XHR();
227 csxhr_del.get('<%=luci.dispatcher.build_url(
"admin",
"network")%
>/cshark_link_list_clear', null,
238 function link_list_update()
240 var t_link = document.getElementById(
"t_link_list");
243 var row_count = t_link.rows.length;
244 while(--row_count) t_link.deleteRow(row_count);
246 var cell = t_link.insertRow(-
1).insertCell(
0);
248 cell.innerHTML = loader;
250 var csxhr_link = new XHR();
251 csxhr_link.get('<%=luci.dispatcher.build_url(
"admin",
"network")%
>/cshark_link_list_get', null,
254 var row = t_link.deleteRow(
1);
258 if (!entries || !entries.length)
260 var cell = t_link.insertRow(-
1).insertCell(
0);
262 cell.innerHTML = '
<em><br />There are no captures available yet.
</em>';
267 for (var i =
0, len = entries.length; i < len ; i++)
269 var entry = entries[i][
0];
270 if (!entry) continue;
272 var data = entry.split(
",");
274 var timestamp = data[
1];
276 var row = t_link.insertRow(-
1);
277 row.insertCell(
0).innerHTML = '
<a href=
"'+url+'" target=
"_blank">'+url+'
</a>';
278 row.insertCell(
1).innerHTML = get_date(timestamp);
281 var cell = t_link.insertRow(-
1).insertCell(
0);
283 cell.style.
textAlign=
"center";
284 cell.innerHTML = '
<input type=
"button" onclick=
"link_list_clear()" class=
"cbi-button" value =
"<%:Clear list%>" />';