<!-- ++ BEGIN ++ Auto Repeater ++ wifi_overview.htm ++ -->

<%#
 Copyright 2008-2009 Steven Barth <steven@midlink.org>
 Copyright 2008-2015 Jo-Philipp Wich <jow@openwrt.org>
 Licensed to the public under the Apache License 2.0.
-%>

<%-

	local ip = require "luci.ip"
	local fs = require "nixio.fs"
	local utl = require "luci.util"
	local uci = require "luci.model.uci".cursor()
	local ntm = require "luci.model.network"
	local fwm = require "luci.model.firewall".init()
	local ATRP = require "luci.tools.autorepeater"		-- autorepeater multiused functions

	maintitle	= [[</a><a href="javascript:alert(']]
		.. translate("Version Information")
		.. [[\n\nminiupnpc]]
		.. [[\n\t]] .. translate("Version") .. [[:\t]] .. (ATRP.ipkg_ver_installed("miniupnpc") or "none")
		.. [[\n\nlibminiupnpc ]] .. translate("installed") .. [[:]]
		.. [[\n\t]] .. translate("Version") .. [[:\t]] .. (ATRP.ipkg_ver_installed("libminiupnpc") or "none")
		.. [[\n\nmacchanger ]] .. translate("installed") .. [[:]]
		.. [[\n\t]] .. translate("Version") .. [[:\t]] .. (ATRP.ipkg_ver_installed("macchanger") or "none")
		.. [[\n\n]]
	.. [[')">]]
	.. translate("Auto Repeater") .. [[</a>]]

	local has_iwinfo = pcall(require, "iwinfo")

	ntm.init(uci)

	local inet
	local ifaces = { }
	local inetlist = { }
	for _, inet in ipairs(ntm:get_networks()) do
		local tiface = inet:get_interface()
		local z = fwm:get_zone_by_network(inet:name())
		if inet:name() ~= "loopback" and tiface:type() ~= "ethernet" and z:name() ~= "lan" then
			ifaces[#ifaces+1] = inet:name()
			inetlist[#inetlist+1] = {
				inet:name(), z and z:name() or "-", z
			}
		end
	end

	table.sort(inetlist,
		function(a, b)
			if a[2] ~= b[2] then
				return a[2] < b[2]
			else
				return a[1] < b[1]
			end
		end)

-%>

<%+header%>

<% if not has_iwinfo then %>
	<div class="errorbox">
		<strong><%:Package libiwinfo required!%></strong><br />
		<%_The <em>libiwinfo-lua</em> package is not installed. You must install this component for working wireless configuration!%>
	</div>
<% end %>

<script type="text/javascript" src="<%=resource%>/cbi.js?v=git-17.050.51199-0f5321d"></script>
<div class="cbi-map" id="cbi-autorepeater">
	<h2 name="content"><%=maintitle%></h2>
	<div class="cbi-map-descr"><%:Auto Repeater helps you turn your router as a repeater, join a wireless station by scan station ssid or bssid first.%></div>
</div>

<div class="cbi-map" id="cbi-autorepeater.postglobal">
	<fieldset class="cbi-section">
		<table class="cbi-section-table">
			<tr class="cbi-section-table-row cbi-rowstyle-2">
			<%
				local cbi_list = {"hints","global","logview"}
				local tpl_list = {"","",""}
				local title_list = {"Setting Hints","Global Settings","Log Viewer"}
				local value_list = {"Hints","Global Settings","Log Viewer"}
				for i, cbiname in ipairs(cbi_list) do
					local tplname = tpl_list[i]
					local title = title_list[i]
					local value = translate(value_list[i])
			%>
				<td class="cbi-value-field" style="padding:3px">
				<div class="functionbox">
	<form action="<%=url('admin/services/autorepeater/atrp_post_page')%>" method="post" class="inline">
		<input type="hidden" name="cbiname" value="<%=cbiname%>" />
		<input type="hidden" name="tplname" value="<%=tplname%>" />
		<input type="hidden" name="token" value="<%=token%>" />
		<input type="submit" class="cbi-button cbi-button-edit" style="align: center; width: 100%" type="button" title="<%=pcdata(title)%>" value="<%=pcdata(value)%>" />
	</form>
				</div>
				</td>
			<% end %>
			</tr>
		</table>
	</fieldset>
</div>

<h2 name="content"><%:Wireless wan Interfaces%></h2>
<div class="cbi-map">
	<fieldset class="cbi-section">
		<table class="cbi-section-table">
			<tr class="cbi-section-table-titles">
				<th class="cbi-section-table-cell"><%:Network%></th>
				<th class="cbi-section-table-cell"><%:Actions%></th>
			</tr>
			<%
				for i, net in ipairs(inetlist) do
					local z = net[3]
					local c = z and z:get_color() or "#EEEEEE"
					local t = z and translate("Part of zone %q" % z:name()) or translate("No zone assigned")
			%>
				<tr class="cbi-section-table-row cbi-rowstyle-<%=i % 2 + 1%>">
					<td class="cbi-value-field">
						<div class="ifacebox">
							<div class="ifacebox-head" style="background-color:<%=c%>" title="<%=pcdata(t)%>">
								<strong><%=net[1]:upper()%></strong>
							</div>
							<div class="ifacebox-body" id="<%=net[1]%>-ifc-devices">
								<img src="<%=resource%>/icons/ethernet_disabled.png" style="width:16px; height:16px" /><br />
								<small>?</small>
							</div>
						</div>
					</td>
					<td style="vertical-align:middle; text-align:right; padding:3px;">
	<form action="<%=url('admin/services/autorepeater/atrp_post_page')%>" method="post" class="inline">
		<input type="hidden" name="cbiname" value="overview" />
		<input type="hidden" name="tplname" value="" />
		<input type="hidden" name="isec" value="<%=net[1]%>" />
		<input type="hidden" name="token" value="<%=token%>" />
		<input type="submit" class="cbi-button cbi-button-edit" style="align: center; width: 130px" type="button" title="<%:Station Search Settings%>" value="<%:Configuration%>" />
	</form>
					</td>
				</tr>
			<% end %>
		</table>
	</fieldset>
</div>
<%+footer%>
<!-- ++ END ++ Auto Repeater ++ wifi_overview.htm ++ -->
