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" src="<%=resource%>/cbi.js"></script>
86 <script type="text/javascript">//<![CDATA[
88 var capture_running = 0;
90 var bt_action = document.getElementById('bt_action');
91 var a_clear_links = document.getElementById('a_clear_links');
92 var output = document.getElementById('cshark-rc-output');
93 var loader = '<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" width="16" height="16" style="vertical-align:middle" /> ';
94 var msg = { 'start' : '<%:Waiting for capture to complete...%>', 'stop' : '<%:Waiting for upload to complete...%>' };
95 var status_msg = msg['start'];
97 function get_date(timestamp)
101 return (str < 10) ? "0" + str : str;
104 var current_date = new Date(timestamp * 1000);
105 return current_date.getFullYear() + "-" +
106 pad_str(current_date.getMonth() + 1) + "-" +
107 pad_str(current_date.getDate()) + " " +
108 pad_str(current_date.getHours()) + ":" +
109 pad_str(current_date.getMinutes()) + ":" +
110 pad_str(current_date.getSeconds());
113 bt_action.onclick = function()
115 var action = this.getAttribute("data-action");
116 var csxhr = new XHR();
118 if (action == "stop")
120 update_status(action);
122 bt_action.disabled = true;
124 csxhr.get('<%=luci.dispatcher.build_url("admin", "network")%>/cshark_iface_dump_stop', null,
127 if (!x || x.responseText.trim() != "0")
129 update_status("failed", "Invalid response on stop.");
134 else if (action == "start")
137 var s_interfaces = document.getElementById('s_interfaces');
138 var s_value_type = document.getElementById('s_value_type');
139 var i_filter = document.getElementById('i_filter');
141 var if_n = s_interfaces.selectedIndex;
142 var t_n = s_value_type.selectedIndex;
143 var ifname = s_interfaces.options[if_n].value.trim();
144 var filter_val = i_filter.value.trim();
145 var tx_val = document.getElementById('tx_value').value.trim();
146 var type_val = s_value_type.options[t_n].value.trim();
148 if (type_val != 'P' && type_val != 'T' && type_val != 'S') type_val = 'T';
150 if (!ifname || !type_val) return;
152 if (isNaN(tx_val)) return alert("<%:value for [seconds, packets, bytes] must be Integer%>");
154 update_status(action);
156 csxhr.get('<%=luci.dispatcher.build_url("admin", "network")%>/cshark_iface_dump_start/' + ifname + '/' + tx_val + '/' + type_val + '/'+ filter_val, null,
160 update_status("failed", "Invalid response on start.");
162 update_status("running");
167 function update_status(status, message)
173 status_msg = msg[status];
174 output.innerHTML = loader + status_msg;
178 if (capture_running) break;;
180 output.innerHTML = loader + status_msg;
182 bt_action.value = '<%:Stop capture%>';
183 bt_action.setAttribute('data-action', 'stop');
189 if (!capture_running) break;
191 if (status == "completed")
196 output.innerHTML = "<pre>" + message + "</pre>";
197 bt_action.value = '<%:Start capture%>';
198 bt_action.setAttribute('data-action', 'start');
199 bt_action.disabled = false;
206 function check_status()
209 XHR.poll(3, '<%=luci.dispatcher.build_url("admin", "network")%>/cshark_check_status', null,
215 update_status("failed", "Invalid response when fetching status.");
221 update_status( (data.status == 1) && "running" || "completed", data.msg);
225 function link_list_clear()
227 var csxhr_del = new XHR();
228 csxhr_del.get('<%=luci.dispatcher.build_url("admin", "network")%>/cshark_link_list_clear', null,
239 function link_list_update()
241 var t_link = document.getElementById("t_link_list");
244 var row_count = t_link.rows.length;
245 while(--row_count) t_link.deleteRow(row_count);
247 var cell = t_link.insertRow(-1).insertCell(0);
249 cell.innerHTML = loader;
251 var csxhr_link = new XHR();
252 csxhr_link.get('<%=luci.dispatcher.build_url("admin", "network")%>/cshark_link_list_get', null,
255 var row = t_link.deleteRow(1);
259 if (!entries || !entries.length)
261 var cell = t_link.insertRow(-1).insertCell(0);
263 cell.innerHTML = '<em><br />There are no captures available yet.</em>';
268 for (var i = 0, len = entries.length; i < len ; i++)
270 var entry = entries[i][0];
271 if (!entry) continue;
273 var data = entry.split(",");
275 var timestamp = data[1];
277 var row = t_link.insertRow(-1);
278 row.insertCell(0).innerHTML = '<a href="'+url+'" target="_blank">'+url+'</a>';
279 row.insertCell(1).innerHTML = get_date(timestamp);
282 var cell = t_link.insertRow(-1).insertCell(0);
284 cell.style.textAlign="center";
285 cell.innerHTML = '<input type="button" onclick="link_list_clear()" class="cbi-button" value ="<%:Clear list%>" />';