<%#
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 $

-%>
<%
require ("luci.model.opennet.on_status")
require("luci.model.opennet.urls")
local i18n = luci.i18n.translate
%>

<%+header%>

<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 Zelle mit neuem Inhalt fuellen (und das "loading"-Icon ueberschreiben
				cell.innerHTML = x.responseText;
			} else {
				// keine Antwort - die ganze Zeile verstecken
				cell.parentNode.style.display = "none";
			}
	});
}

//]]></script>


<h2><a id="content" name="content"><%=get_firmware_title() %></a></h2>
<div class="cbi-map">
	<h3 class="on_title"><%:This is an Access-Point with Opennet-Firmware, a modification of OpenWrt to the requirements of the Opennet Initiative e.V.%></h3>
	<div id="status_opennet_logo" /><div id="status_openwrt_logo" />
</div>
<h3><%:Status Information%></h3>
<div class="cbi-map"><fieldset class="cbi-section">
	<table class="cbi-section-table" id="status_table">
		<%
		local hardware_info = luci.sys.exec("echo -e \"Model: \$(cat /proc/diag/model 2>/dev/null)\\n\$(cat /proc/cpuinfo)\" | awk 'BEGIN {FS=\":\"; no=0} /Processor|Hardware|system type|machine|Model|vendor_id/ {gsub(\"[\\t]\", \"\"); if (no > 0) printf \" | \"; if (\$2) { no=1; printf \$1\":\"\$2}} END {printf \"\\n\";}'")

		for _, item in ipairs({
				  {"networks_section", i18n("Networks"), url="network"},
				  {"wireless_section", i18n("Wireless"), url="wireless"},
				  {"neighbor_section", i18n("Neighbors"), url="neighbors"},
				  {"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"), content=hardware_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 %>
				<tr class="cbi-section-table-titles">
					<td class="cbi-section-table-cell"><%=item[2]%>:</td>
					<td class="cbi-section-table-cell" 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] .. "_spinnr", "vertical-align:middle;") %>
						<script type="text/javascript">
							fill_result_row("<%=item[1]%>", "<%=item.url%>")
						</script>
					<% else %>
						<%=luci.util.pcdata(item.content)%>
					<% end %>
					</td>
				</tr>
			<% end %>
		<% end %>
	</table>
</fieldset></div>
<%+footer%>
