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

-%>
<%+header%>

<% require("luci.model.opennet.funcs") %>


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

function check_ugw_status() {
	var run_xhr = new XHR();
	run_xhr.get('<%= on_url("status", "mesh_verbindungen") %>', null,
		function(x) {
			if (x.responseText) document.getElementById("ugw_status_content").innerHTML = x.responseText;
		}
	);
}


<%= register_javascript_function_onload("init") %>
function init() {
	check_ugw_status();
	setInterval('check_ugw_status()', 10000 )
}
//]]></script>

<% if luci.sys.exec("openvpn --help | grep mtu") == "" then
	write(html_error_box(luci.i18n.translate('Openvpn does not support mtu-check, please compile openvpn without "--enable-small" option.')))
end %>

<div class="cbi-map">
  <h2><a id="content" name="content"><%:Sharing your Internet connection%></a></h2>
  <div class="cbi-map-descr"><%:Sharing your internet connection with the Opennet Community usually consists of two distinct parts:%>
    <ul>
      <li><%:Connecting your local neighbourhood with the complete mesh of all Opennet nodes.%></li>
      <li><%:Allowing certain public services to be reachable within your local neighbourhood. The most notable example is the Internet Gateway Service which is used by all people accesing the Internet via Opennet.%></li>
    </ul>
  </div>

  <% if certstatus.on_keycrt_ok then %>
    <fieldset class="cbi-section">
      <legend><%:Internet Sharing Status%></legend>
      <div class="cbi-section-node">
        <div class="cbi-value">
          <label class="cbi-value-title" for="status"><%:Current Status%>:</label>
          <div class="cbi-value-field">
            <%= get_html_loading_spinner("ugw_status_content", "vertical-align:middle;") %>
          </div>
        </div>
        <%
          local vpn_dev_prefix = on_function("get_variable", {"MESH_OPENVPN_DEVICE_PREFIX"})
          local vpn_routes = on_function("get_olsr_route_count_by_device", {vpn_dev_prefix .. "[0-9]*"})
          local all_routes = on_function("get_olsr_route_count_by_device", {".*"})
        %>
        <div class="cbi-value">
          <label class="cbi-value-title" for="mesh-connections-openvpn"><%:Routeable addresses via Mesh VPN%>:</label>
          <div class="cbi-value-field"><%= vpn_routes %></div>
        </div>
        <div class="cbi-value">
          <label class="cbi-value-title" for="mesh-connections-other"><%:Other routeable addresses%>:</label>
          <div class="cbi-value-field"><%= tonumber(all_routes) - tonumber(vpn_routes) %></div>
        </div>
      </div>
    </fieldset>
  <% end %>

</div>
<%+footer%>
