Advertisement
jfrog

Untitled

Dec 16th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.90 KB | None | 0 0
  1. <%#
  2. Copyright 2008 Steven Barth <steven@midlink.org>
  3. Copyright 2008-2011 Jo-Philipp Wich <jow@openwrt.org>
  4. Licensed to the public under the Apache License 2.0.
  5. -%>
  6.  
  7. <%
  8. local fs = require "nixio.fs"
  9. local ipc = require "luci.ip"
  10. local util = require "luci.util"
  11. local stat = require "luci.tools.status"
  12. local ver = require "luci.version"
  13.  
  14. local has_ipv6 = fs.access("/proc/net/ipv6_route")
  15. local has_dhcp = fs.access("/etc/config/dhcp")
  16. local has_wifi = ((fs.stat("/etc/config/wireless", "size") or 0) > 0)
  17.  
  18. local sysinfo = luci.util.ubus("system", "info") or { }
  19. local boardinfo = luci.util.ubus("system", "board") or { }
  20. local unameinfo = nixio.uname() or { }
  21.  
  22. function file_exists(name)
  23. local f=io.open(name,"r")
  24. if f~=nil then io.close(f) return true else return false end
  25. end
  26.  
  27. if file_exists("/etc/custom") then
  28. file = io.open("/etc/custom", "r")
  29. customboard = file:read("*line")
  30. custommodel = file:read("*line")
  31. hostname = file:read("*line")
  32. file:close()
  33. else
  34. customboard = boardinfo.model
  35. custommodel = boardinfo.model
  36. end
  37.  
  38. if file_exists("/tmp/customdata") then
  39. file = io.open("/tmp/customdata", "r")
  40. customattr = file:read("*line")
  41. customval = file:read("*line")
  42. file:close()
  43. else
  44.  
  45. end
  46.  
  47. local meminfo = sysinfo.memory or {
  48. total = 0,
  49. free = 0,
  50. buffered = 0,
  51. shared = 0
  52. }
  53.  
  54. local swapinfo = sysinfo.swap or {
  55. total = 0,
  56. free = 0
  57. }
  58.  
  59. local has_dsl = fs.access("/etc/init.d/dsl_control")
  60.  
  61. if luci.http.formvalue("status") == "1" then
  62. local ntm = require "luci.model.network".init()
  63. local wan = ntm:get_wannet()
  64. local wan6 = ntm:get_wan6net()
  65.  
  66. local conn_count = tonumber(
  67. fs.readfile("/proc/sys/net/netfilter/nf_conntrack_count") or "") or 0
  68.  
  69. local conn_max = tonumber(luci.sys.exec(
  70. "sysctl -n -e net.nf_conntrack_max net.ipv4.netfilter.ip_conntrack_max"
  71. ):match("%d+")) or 4096
  72.  
  73. local rv = {
  74. uptime = sysinfo.uptime or 0,
  75. localtime = os.date(),
  76. loadavg = sysinfo.load or { 0, 0, 0 },
  77. memory = meminfo,
  78. swap = swapinfo,
  79. connmax = conn_max,
  80. conncount = conn_count,
  81. customdata = customval,
  82. wifinets = stat.wifi_networks()
  83. }
  84.  
  85. if wan then
  86. local dev = wan:get_interface()
  87. local link = dev and ipc.link(dev:name())
  88. rv.wan = {
  89. ipaddr = wan:ipaddr(),
  90. gwaddr = wan:gwaddr(),
  91. netmask = wan:netmask(),
  92. dns = wan:dnsaddrs(),
  93. expires = wan:expires(),
  94. uptime = wan:uptime(),
  95. proto = wan:proto(),
  96. i18n = wan:get_i18n(),
  97. ifname = wan:ifname(),
  98. link = wan:adminlink(),
  99. mac = dev and dev:mac(),
  100. type = dev and dev:type(),
  101. name = dev and dev:get_i18n(),
  102. ether = link and link.type == 1
  103. }
  104. end
  105.  
  106. if wan6 then
  107. local dev = wan6:get_interface()
  108. local link = dev and ipc.link(dev:name())
  109. rv.wan6 = {
  110. ip6addr = wan6:ip6addr(),
  111. gw6addr = wan6:gw6addr(),
  112. dns = wan6:dns6addrs(),
  113. ip6prefix = wan6:ip6prefix(),
  114. uptime = wan6:uptime(),
  115. proto = wan6:proto(),
  116. i18n = wan6:get_i18n(),
  117. ifname = wan6:ifname(),
  118. link = wan6:adminlink(),
  119. mac = dev and dev:mac(),
  120. type = dev and dev:type(),
  121. name = dev and dev:get_i18n(),
  122. ether = link and link.type == 1
  123. }
  124. end
  125.  
  126. if has_dsl then
  127. local dsl_stat = luci.sys.exec("/etc/init.d/dsl_control lucistat")
  128. local dsl_func = loadstring(dsl_stat)
  129. if dsl_func then
  130. rv.dsl = dsl_func()
  131. end
  132. end
  133.  
  134. luci.http.prepare_content("application/json")
  135. luci.http.write_json(rv)
  136.  
  137. return
  138. end
  139. -%>
  140.  
  141. <%+header%>
  142.  
  143. <script type="text/javascript">//<![CDATA[
  144. function progressbar(v, m)
  145. {
  146. var vn = parseInt(v) || 0;
  147. var mn = parseInt(m) || 100;
  148. var pc = Math.floor((100 / mn) * vn);
  149.  
  150. return String.format(
  151. '<div style="width:100%%; max-width:200px; position:relative; border:1px solid #999999">' +
  152. '<div style="background-color:#CCCCCC; width:%d%%; height:15px">' +
  153. '<div style="position:absolute; left:0; top:0; text-align:center; width:100%%; color:#000000">' +
  154. '<small>%s / %s (%d%%)</small>' +
  155. '</div>' +
  156. '</div>' +
  157. '</div>', pc, v, m, pc
  158. );
  159. }
  160.  
  161. function labelList(items, offset) {
  162. var rv = [ ];
  163.  
  164. for (var i = offset || 0; i < items.length; i += 2) {
  165. var label = items[i],
  166. value = items[i+1];
  167.  
  168. if (value === undefined || value === null)
  169. continue;
  170.  
  171. if (label)
  172. rv.push(E('strong', [label, ': ']));
  173.  
  174. rv.push(value, E('br'));
  175. }
  176.  
  177. return rv;
  178. }
  179.  
  180. function renderBox(title, active, childs) {
  181. childs = childs || [];
  182. childs.unshift(E('span', labelList(arguments, 3)));
  183.  
  184. return E('div', { class: 'ifacebox' }, [
  185. E('div', { class: 'ifacebox-head center ' + (active ? 'active' : '') },
  186. E('strong', title)),
  187. E('div', { class: 'ifacebox-body left' }, childs)
  188. ]);
  189. }
  190.  
  191. function renderBadge(icon, title) {
  192. return E('span', { class: 'ifacebadge' }, [
  193. E('img', { src: icon, title: title || '' }),
  194. E('span', labelList(arguments, 2))
  195. ]);
  196. }
  197.  
  198. XHR.poll(5, '<%=REQUEST_URI%>', { status: 1 },
  199. function(x, info)
  200. {
  201. var us = document.getElementById('upstream_status_table');
  202.  
  203. while (us.lastElementChild)
  204. us.removeChild(us.lastElementChild);
  205.  
  206. var ifc = info.wan || {};
  207.  
  208. us.appendChild(renderBox(
  209. '<%:IPv4 Upstream%>',
  210. (ifc.ifname && ifc.proto != 'none'),
  211. [ E('div', {}, renderBadge(
  212. '<%=resource%>/icons/%s.png'.format((ifc && ifc.type) ? ifc.type : 'ethernet_disabled'), null,
  213. '<%:Device%>', ifc ? (ifc.name || ifc.ifname || '-') : '-',
  214. '<%:MAC-Address%>', (ifc && ifc.ether) ? ifc.mac : null)) ],
  215. '<%:Protocol%>', ifc.i18n || E('em', '<%:Not connected%>'),
  216. '<%:Address%>', (ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0',
  217. '<%:Netmask%>', (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255',
  218. '<%:Gateway%>', (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0',
  219. '<%:DNS%> 1', (ifc.dns) ? ifc.dns[0] : null,
  220. '<%:DNS%> 2', (ifc.dns) ? ifc.dns[1] : null,
  221. '<%:DNS%> 3', (ifc.dns) ? ifc.dns[2] : null,
  222. '<%:DNS%> 4', (ifc.dns) ? ifc.dns[3] : null,
  223. '<%:DNS%> 5', (ifc.dns) ? ifc.dns[4] : null,
  224. '<%:Expires%>', (ifc.expires > -1) ? '%t'.format(ifc.expires) : null,
  225. '<%:Connected%>', (ifc.uptime > 0) ? '%t'.format(ifc.uptime) : null));
  226.  
  227. <% if has_ipv6 then %>
  228. var ifc6 = info.wan6 || {};
  229.  
  230. us.appendChild(renderBox(
  231. '<%:IPv6 Upstream%>',
  232. (ifc6.ifname && ifc6.proto != 'none'),
  233. [ E('div', {}, renderBadge(
  234. '<%=resource%>/icons/%s.png'.format(ifc6.type || 'ethernet_disabled'), null,
  235. '<%:Device%>', ifc6 ? (ifc6.name || ifc6.ifname || '-') : '-',
  236. '<%:MAC-Address%>', (ifc6 && ifc6.ether) ? ifc6.mac : null)) ],
  237. '<%:Protocol%>', ifc6.i18n ? (ifc6.i18n + (ifc6.proto === 'dhcp' && ifc6.ip6prefix ? '-PD' : '')) : E('em', '<%:Not connected%>'),
  238. '<%:Prefix Delegated%>', ifc6.ip6prefix,
  239. '<%:Address%>', (ifc6.ip6prefix) ? (ifc6.ip6addr || null) : (ifc6.ipaddr || '::'),
  240. '<%:Gateway%>', (ifc6.gw6addr) ? ifc6.gw6addr : '::',
  241. '<%:DNS%> 1', (ifc6.dns) ? ifc6.dns[0] : null,
  242. '<%:DNS%> 2', (ifc6.dns) ? ifc6.dns[1] : null,
  243. '<%:DNS%> 3', (ifc6.dns) ? ifc6.dns[2] : null,
  244. '<%:DNS%> 4', (ifc6.dns) ? ifc6.dns[3] : null,
  245. '<%:DNS%> 5', (ifc6.dns) ? ifc6.dns[4] : null,
  246. '<%:Connected%>', (ifc6.uptime > 0) ? '%t'.format(ifc6.uptime) : null));
  247. <% end %>
  248.  
  249. <% if has_dsl then %>
  250. var ds = document.getElementById('dsl_status_table');
  251.  
  252. while (ds.lastElementChild)
  253. ds.removeChild(ds.lastElementChild);
  254.  
  255. ds.appendChild(renderBox(
  256. '<%:DSL Status%>',
  257. (info.dsl.line_state === 'UP'), [ ],
  258. '<%:Line State%>', '%s [0x%x]'.format(info.dsl.line_state, info.dsl.line_state_detail),
  259. '<%:Line Mode%>', info.dsl.line_mode_s || '-',
  260. '<%:Line Uptime%>', info.dsl.line_uptime_s || '-',
  261. '<%:Annex%>', info.dsl.annex_s || '-',
  262. '<%:Profile%>', info.dsl.profile_s || '-',
  263. '<%:Data Rate%>', '%s/s / %s/s'.format(info.dsl.data_rate_down_s, info.dsl.data_rate_up_s),
  264. '<%:Max. Attainable Data Rate (ATTNDR)%>', '%s/s / %s/s'.format(info.dsl.max_data_rate_down_s, info.dsl.max_data_rate_up_s),
  265. '<%:Latency%>', '%s / %s'.format(info.dsl.latency_num_down, info.dsl.latency_num_up),
  266. '<%:Line Attenuation (LATN)%>', '%.1f dB / %.1f dB'.format(info.dsl.line_attenuation_down, info.dsl.line_attenuation_up),
  267. '<%:Signal Attenuation (SATN)%>', '%.1f dB / %.1f dB'.format(info.dsl.signal_attenuation_down, info.dsl.signal_attenuation_up),
  268. '<%:Noise Margin (SNR)%>', '%.1f dB / %.1f dB'.format(info.dsl.noise_margin_down, info.dsl.noise_margin_up),
  269. '<%:Aggregate Transmit Power(ACTATP)%>', '%.1f dB / %.1f dB'.format(info.dsl.actatp_down, info.dsl.actatp_up),
  270. '<%:Forward Error Correction Seconds (FECS)%>', '%d / %d'.format(info.dsl.errors_fec_near, info.dsl.errors_fec_far),
  271. '<%:Errored seconds (ES)%>', '%d / %d'.format(info.dsl.errors_es_near, info.dsl.errors_es_far),
  272. '<%:Severely Errored Seconds (SES)%>', '%d / %d'.format(info.dsl.errors_ses_near, info.dsl.errors_ses_far),
  273. '<%:Loss of Signal Seconds (LOSS)%>', '%d / %d'.format(info.dsl.errors_loss_near, info.dsl.errors_loss_far),
  274. '<%:Unavailable Seconds (UAS)%>', '%d / %d'.format(info.dsl.errors_uas_near, info.dsl.errors_uas_far),
  275. '<%:Header Error Code Errors (HEC)%>', '%d / %d'.format(info.dsl.errors_hec_near, info.dsl.errors_hec_far),
  276. '<%:Non Pre-emtive CRC errors (CRC_P)%>', '%d / %d'.format(info.dsl.errors_crc_p_near, info.dsl.errors_crc_p_far),
  277. '<%:Pre-emtive CRC errors (CRCP_P)%>', '%d / %d'.format(info.dsl.errors_crcp_p_near, info.dsl.errors_crcp_p_far),
  278. '<%:ATU-C System Vendor ID%>', info.dsl.atuc_vendor_id,
  279. '<%:Power Management Mode%>', info.dsl.power_mode_s));
  280. <% end %>
  281.  
  282. <% if has_wifi then %>
  283. var ws = document.getElementById('wifi_status_table');
  284. if (ws)
  285. {
  286. while (ws.lastElementChild)
  287. ws.removeChild(ws.lastElementChild);
  288.  
  289. for (var didx = 0; didx < info.wifinets.length; didx++)
  290. {
  291. var dev = info.wifinets[didx];
  292. var net0 = (dev.networks && dev.networks[0]) ? dev.networks[0] : {};
  293. var vifs = [];
  294.  
  295. for (var nidx = 0; nidx < dev.networks.length; nidx++)
  296. {
  297. var net = dev.networks[nidx];
  298. var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel && !net.disabled);
  299.  
  300. var icon;
  301. if (net.disabled)
  302. icon = "<%=resource%>/icons/signal-none.png";
  303. else if (net.quality <= 0)
  304. icon = "<%=resource%>/icons/signal-0.png";
  305. else if (net.quality < 25)
  306. icon = "<%=resource%>/icons/signal-0-25.png";
  307. else if (net.quality < 50)
  308. icon = "<%=resource%>/icons/signal-25-50.png";
  309. else if (net.quality < 75)
  310. icon = "<%=resource%>/icons/signal-50-75.png";
  311. else
  312. icon = "<%=resource%>/icons/signal-75-100.png";
  313.  
  314. vifs.push(renderBadge(
  315. icon,
  316. '<%:Signal%>: %d dBm / <%:Quality%>: %d%%'.format(net.signal, net.quality),
  317. '<%:SSID%>', E('a', { href: net.link }, [ net.ssid || '?' ]),
  318. '<%:Mode%>', net.mode,
  319. '<%:BSSID%>', is_assoc ? (net.bssid || '-') : null,
  320. '<%:Encryption%>', is_assoc ? net.encryption : null,
  321. '<%:Associations%>', is_assoc ? (net.num_assoc || '-') : null,
  322. null, is_assoc ? null : E('em', net.disabled ? '<%:Wireless is disabled%>' : '<%:Wireless is not associated%>')));
  323. }
  324.  
  325. ws.appendChild(renderBox(
  326. dev.device, dev.up || net0.up,
  327. [ E('div', vifs) ],
  328. '<%:Type%>', dev.name.replace(/^Generic | Wireless Controller .+$/g, ''),
  329. '<%:Channel%>', net0.channel ? '%d (%.3f <%:GHz%>)'.format(net0.channel, net0.frequency) : '-',
  330. '<%:Bitrate%>', net0.bitrate ? '%d <%:Mbit/s%>'.format(net0.bitrate) : '-'));
  331. }
  332.  
  333. if (!ws.lastElementChild)
  334. ws.appendChild(E('<em><%:No information available%></em>'));
  335. }
  336. <% end %>
  337.  
  338. var e;
  339.  
  340. if (e = document.getElementById('localtime'))
  341. e.innerHTML = info.localtime;
  342.  
  343. if (e = document.getElementById('uptime'))
  344. e.innerHTML = String.format('%t', info.uptime);
  345.  
  346. if (e = document.getElementById('customdata'))
  347. e.innerHTML = info.customdata;
  348.  
  349. if (e = document.getElementById('loadavg'))
  350. e.innerHTML = String.format(
  351. '%.02f, %.02f, %.02f',
  352. info.loadavg[0] / 65535.0,
  353. info.loadavg[1] / 65535.0,
  354. info.loadavg[2] / 65535.0
  355. );
  356.  
  357. if (e = document.getElementById('memtotal'))
  358. e.innerHTML = progressbar(
  359. ((info.memory.free + info.memory.buffered) / 1024) + " <%:kB%>",
  360. (info.memory.total / 1024) + " <%:kB%>"
  361. );
  362.  
  363. if (e = document.getElementById('memfree'))
  364. e.innerHTML = progressbar(
  365. (info.memory.free / 1024) + " <%:kB%>",
  366. (info.memory.total / 1024) + " <%:kB%>"
  367. );
  368.  
  369. if (e = document.getElementById('membuff'))
  370. e.innerHTML = progressbar(
  371. (info.memory.buffered / 1024) + " <%:kB%>",
  372. (info.memory.total / 1024) + " <%:kB%>"
  373. );
  374.  
  375. if (e = document.getElementById('swaptotal'))
  376. e.innerHTML = progressbar(
  377. (info.swap.free / 1024) + " <%:kB%>",
  378. (info.swap.total / 1024) + " <%:kB%>"
  379. );
  380.  
  381. if (e = document.getElementById('swapfree'))
  382. e.innerHTML = progressbar(
  383. (info.swap.free / 1024) + " <%:kB%>",
  384. (info.swap.total / 1024) + " <%:kB%>"
  385. );
  386.  
  387. if (e = document.getElementById('conns'))
  388. e.innerHTML = progressbar(info.conncount, info.connmax);
  389.  
  390. }
  391. );
  392. //]]></script>
  393.  
  394. <h2 name="content"><%:Status%></h2>
  395.  
  396. <div class="cbi-section">
  397. <h3><%:System%></h3>
  398.  
  399. <div class="table" width="100%">
  400. <div class="tr"><div class="td left" width="33%"><%:Hostname%></div><div class="td left"><%=luci.sys.hostname() or "?"%></div></div>
  401. <div class="tr"><div class="td left" width="33%"><%:Model%></div><div class="td left"><%=pcdata(custommodel or "?")%></div></div>
  402. <div class="tr"><div class="td left" width="33%"><%:Architecture%></div><div class="td left"><%=pcdata(boardinfo.system or "?")%></div></div>
  403. <div class="tr"><div class="td left" width="33%"><%:Firmware Version%></div><div class="td left">
  404. <%=pcdata(ver.distname)%> <%=pcdata(ver.distversion)%>
  405. </div></div>
  406. <div class="tr"><div class="td left" width="33%"><%:Kernel Version%></div><div class="td left"><%=unameinfo.release or "?"%></div></div>
  407. <div class="tr"><div class="td left" width="33%"><%:Local Time%></div><div class="td left" id="localtime">-</div></div>
  408. <div class="tr"><div class="td left" width="33%"><%:Uptime%></div><div class="td left" id="uptime">-</div></div>
  409. <div class="tr"><div class="td left" width="33%"><%:Load Average%></div><div class="td left" id="loadavg">-</div></div>
  410. <div class="tr"><div class="td left" width="33%"><%=customattr%></div><div class="td left" id="customdata">-</div></div>
  411. </div>
  412. </div>
  413.  
  414. <div class="cbi-section">
  415. <h3><%:Memory%></h3>
  416.  
  417. <div class="table" width="100%">
  418. <div class="tr"><div class="td left" width="33%"><%:Total Available%></div><div class="td left" id="memtotal">-</div></div>
  419. <div class="tr"><div class="td left" width="33%"><%:Free%></div><div class="td left" id="memfree">-</div></div>
  420. <div class="tr"><div class="td left" width="33%"><%:Buffered%></div><div class="td left" id="membuff">-</div></div>
  421. </div>
  422. </div>
  423.  
  424. <% if swapinfo.total > 0 then %>
  425. <div class="cbi-section">
  426. <h3><%:Swap%></h3>
  427.  
  428. <div class="table" width="100%">
  429. <div class="tr"><div class="td left" width="33%"><%:Total Available%></div><div class="td left" id="swaptotal">-</div></div>
  430. <div class="tr"><div class="td left" width="33%"><%:Free%></div><div class="td left" id="swapfree">-</div></div>
  431. </div>
  432. </div>
  433. <% end %>
  434.  
  435. <div class="cbi-section">
  436. <h3><%:Network%></h3>
  437.  
  438. <div id="upstream_status_table" class="network-status-table">
  439. <p><em><%:Collecting data...%></em></p>
  440. </div>
  441.  
  442. <div class="table" width="100%">
  443. <div class="tr"><div class="td left" width="33%"><%:Active Connections%></div><div class="td left" id="conns">-</div></div>
  444. </div>
  445. </div>
  446.  
  447. <%
  448. if has_dhcp then
  449. include("admin_network/lease_status")
  450. end
  451. %>
  452.  
  453. <% if has_dsl then %>
  454. <div class="cbi-section">
  455. <h3><%:DSL%></h3>
  456.  
  457. <div id="dsl_status_table" class="network-status-table">
  458. <p><em><%:Collecting data...%></em></p>
  459. </div>
  460. </div>
  461. <% end %>
  462.  
  463. <% if has_wifi then %>
  464. <div class="cbi-section">
  465. <h3><%:Wireless%></h3>
  466.  
  467. <div id="wifi_status_table" class="network-status-table">
  468. <p><em><%:Collecting data...%></em></p>
  469. </div>
  470. </div>
  471.  
  472. <div class="cbi-section">
  473. <h3><%:Associated Stations%></h3>
  474.  
  475. <%+admin_network/wifi_assoclist%>
  476. </div>
  477. <% end %>
  478.  
  479. <%-
  480. local incdir = util.libpath() .. "/view/admin_status/index/"
  481. if fs.access(incdir) then
  482. local inc
  483. for inc in fs.dir(incdir) do
  484. if inc:match("%.htm$") then
  485. include("admin_status/index/" .. inc:gsub("%.htm$", ""))
  486. end
  487. end
  488. end
  489. -%>
  490.  
  491. <%+footer%>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement