<%#
Opennet Firmware

Copyright 2010 Rene Ejury <opennet@absorb.it>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

$Id: index.htm 5448 2009-10-31 15:54:11Z jow $

-%>

<%+header%>

<%
local onstatus=require "luci.model.opennet.on_status"
local onurls=require "luci.model.opennet.urls"
local i18n = luci.i18n.translate
%>

<script type="text/javascript">//<![CDATA[

function fill_result_row(table_cell_name, request_url_suffix) {
	var xhr_request = new XHR();
	xhr_request.get('<%= on_url("status")%>/' + request_url_suffix, null,
		function(x) {
			var cell = document.getElementById(table_cell_name);
			if (!cell) {
				// die Zeile wurde nicht gefunden?
				return;
			// leider liefert luci in jedem Fall einen Text aus - notfalls "No page is registered at ..." :(
			} else if ((x.responseText) && (x.responseText.indexOf('No page is registered at') == 0)) {
				// die Quelle (anderes Modul?) ist nicht verfuegbar - verstecke die Zeile
				cell.parentNode.style.display = "none";
			} else if (x.responseText) {
				// die Zelle mit neuem Inhalt fuellen (und das "loading"-Icon ueberschreiben
				cell.innerHTML = x.responseText;
			} else {
				// leere/keine Antwort (Fehler?)
				cell.innerHTML = '<%:No response%>';
			}
	});
}

//]]></script>

<%
	local on_hints = {}

	local usable_memory = tonumber(on_function("get_memory_size"))
	local real_memory = math.pow(2, math.floor(math.log(usable_memory) / math.log(2) + 0.99))
	if real_memory <= 32 then
		local message = luci.i18n.translate("This router offers 32 Megabyte RAM (or less). Only firmware versions up to v0.5.3 are known to run stable on such limited hardware. You should seriously consider downgrading the firmware to v0.5.3 in order to avoid frustrating instability issues.")
		table.insert(on_hints, message)
	end
%>

<h2 id="content" name="content"><%=onstatus.get_firmware_title() %></h2>
<div class="cbi-map-descr">
	<p><%:This is an Access-Point with Opennet-Firmware, a modification of OpenWrt to the requirements of the Opennet Initiative e.V.%></p>
	<div id="status_opennet_logo" /><div id="status_openwrt_logo" />
</div>

<%= html_display_message_list(on_hints, "info") %>

<div id="view">
 <div class="cbi-section fade-in" style="">
  <h3><%:Status Information%></h3>
  <div>
   <div class="table">

		<%
		local boardinfo = luci.util.ubus("system", "board") or { }
		local boardinfo_formatted = pcdata(boardinfo.model or boardinfo.system or "?")
		local hardare_info = luci.i18n.translatef("Model: %s", boardinfo_formatted) .. "<br/>"
			.. luci.i18n.translatef("Memory: %d MB", real_memory)
		local wireless_info = "<table><tr>"
			.. luci.sys.exec("iwinfo"
				.. " | grep -vE '(TX power offset|Frequency offset|Hardware|Type|Supports VAP):'"
				.. " | grep -vE 'Encryption: (none|unknown)'"
				.. " | grep -v 'Supports VAPs:'"
				.. " | sed 's/^.* ESSID:/<td><tt>ESSID:/; s/^ *//; s#$#<br/>#; s#^<br/>$#</tt></td>#'")
			.. "</tr></table>"
		local netgraph_olsr2_link = [[<a href="/olsr2.html" target="_blank">]]
			.. luci.i18n.translate("Network Graph Visualization")
			.. [[</a>]]

		for _, item in ipairs({
				  {"networks_section", i18n("Networks"), url="network"},
				  {"wireless_section", i18n("Wireless"), rawcontent=wireless_info},
				  {"neighbor_section", i18n("Neighbors (OLSRv1)"), url="neighbors"},
				  {"neighbor_olsr2_section", i18n("Neighbors (OLSRv2)"), url="neighbors_olsr2", mod_name="on-olsr2"},
				  {"netgraph_olsr2", i18n("Network Graph (OLSRv2)"), rawcontent=netgraph_olsr2_link, mod_name="on-olsr2-netjsongraph"},
				  {"mig_connection_section", i18n("OpenVPN"), url="mig_openvpn", mod_name="on-openvpn"},
				  {"ugw_connection_section", i18n("Internet Sharing"), url="mesh_verbindungen", mod_name="on-usergw"},
				  {"captive_portal_section", i18n("Public Hotspot"), url="zugangspunkt", mod_name="on-captive-portal"},
				  {"modules_section", i18n("Opennet Modules"), url="modules"},
				  {"issues_section", i18n("Issue Indicators"), url="issues"},
				  {"hardware_section", i18n("Hardware Information"), rawcontent=hardare_info},
				  {"latest_firmware", i18n("Firmware Update"), url="firmware_update_info"},
				  {"uptime_section", i18n("Uptime"), content=luci.sys.exec("uptime")},
				  {"system_section", i18n("System"), content=luci.sys.exec("uname -a")},
			  }) do
			-- skip missing modules (test only if they are installed - ignore "enabled")
			if not item.mod_name or on_bool_function("is_package_installed", {item.mod_name}) then %>
				<div class="tr">
					<div class="td left"><%=item[2]%>:</div>
					<div class="td left" id="<%=item[1]%>">
					<% if item.mod_name and not on_bool_function("is_on_module_installed_and_enabled", {item.mod_name}) then %>
						<%= luci.i18n.translatef('disabled (see <a href="%s">Modules</a>)', on_url("basis", "module")) %>
					<% elseif item.url then %>
						<%= get_html_loading_spinner(item[1] .. "_spinner", "vertical-align:middle;") %>
						<script type="text/javascript">
							fill_result_row("<%=item[1]%>", "<%=item.url%>")
						</script>
					<% elseif item.rawcontent then %>
						<%=item.rawcontent%>
					<% else %>
						<%=luci.xml.pcdata(item.content)%>
					<% end %>
					</div>
				</div>
			<% end %>
		<% end %>

   </div> <!--table-->
  </div>
 </div> <!--cbi-section fade-in-->
</div> <!--view-->

<%+footer%>
