<%
local http = require("luci.http")
http.prepare_content("text/html; charset=utf-8")
-%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
 This file is part of YunWebUI.

 YunWebUI is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

 As a special exception, you may use this file as part of a free software
 library without restriction.  Specifically, if other files instantiate
 templates or use macros or inline functions from this file, or you compile
 this file and link it with other files to produce an executable, this
 file does not by itself cause the resulting executable to be covered by
 the GNU General Public License.  This exception does not however
 invalidate any other reasons why the executable file might be covered by
 the GNU General Public License.

 Copyright 2013 Arduino LLC (http://www.arduino.cc/)
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
  <link rel="stylesheet" type="text/css" href="<%= resource %>/arduino/style.ugly.css" />
  <title>Y&uacute;n &#20113;</title>
</head>
<body>
<div id="container">
  <div id="header">
    <div class="wrapper">
      <h1>Y&uacute;n &#20113;</h1>
      <div id="logo"><a href="<%= pcdata(controller .. '/webpanel') %>"><img src="<%= resource %>/arduino/logo.png" alt="Y&uacute;n"/></a></div>
      <div id="logophone"><a href="<%= pcdata(controller .. '/webpanel') %>"><img src="<%= resource %>/arduino/logo_phone.png" alt="Y&uacute;n"/></a></div>
    </div>
  </div>
  <div id="content">
    <div class="wrapper divide">
      <p>For more advanced network configuration features, see the <a href="<%= pcdata(controller .. '/') %>" title="advanced configuration panel">advanced configuration panel (luci)</a></p>
    </div>
    <div class="wrapper divide" id="yun_config">
      <form id="form1" name="form1" method="post" onreset="javascript:formReset(this);" onsubmit="javascript:return formCheck(this) && send_post('<%=pcdata(controller .. "/webpanel/config")%>', this, 'real_form', 'wifi.ssid', 'wifi.encryption', 'wifi.password', 'hostname', 'timezone_desc', 'password');" action="#">

        <div id="error_response" class="hidden">
          <p class="alert">An error has occurred.</p>
        </div>
        <ul>
          <li>
            <label class="title">Y&uacute;n board configuration <a class="info_link" href="http://arduino.cc/en/Guide/ArduinoYun#toc10"><img src="" /></a></label>
          </li>
          <li>
            <label class="desc" for="hostname">
              Y&uacute;n name <span class="req">*</span>
            </label>

            <div class="input_container">
              <input id="hostname" name="hostname" type="text" value="<%= hostname %>" maxlength="255">
            </div>
          </li>

          <li>
            <label class="desc" for="password">
              Password
            </label>

            <div class="input_container">
              <input id="password" name="password" type="password" maxlength="255">
            </div>
          </li>
          <li>
            <label class="desc" for="confpassword">
              Confirm Password
            </label>

            <div class="input_container">
              <input id="confpassword" name="confpassword" type="password" maxlength="255">
              <p id="pass_mismatch" class="hidden error_container input_message">Password mismatch</p>
            </div>
          </li>

          <li>
            <label class="desc" for="timezone_desc">
              Timezone <span class="req">*</span>
            </label>

            <div class="input_container">
              <select id="timezone_desc" name="timezone_desc">
                <% for k, tz in ipairs(timezones_wifi_reg_domains) do %>
                <option value="<%= tz["label"] %>"
                <%if timezone_desc == tz["label"] then %>
                selected="selected"
                <% end %>
                ><%= tz["label"] %></option>
                <% end %>
              </select>
            </div>
          </li>
        </ul>
    </div>
    <div class="wrapper divide">
      <ul>
        <li>
          <label class="title">Wireless parameters <a class="info_link" href="http://arduino.cc/en/Guide/ArduinoYun#toc10"><img src="" /></a></label>
        </li>

        <li>
          <label for="wificheck" class="left">Configure a wireless network</label><div class="input_container checkbox_container"><input checked="checked" type="checkbox" name="wifi" id="wificheck"/></div>
        </li>

        <div id="wifi_container" class="">
          <li>
            <label class="desc" for="detected_wifis">Detected wireless networks</label>

            <div class="input_container">
              <select id="detected_wifis" name="wifi_detected"></select>
              <a id="refresh_detected_wifis" href="#">Refresh</a>
            </div>
          </li>

          <li>
            <label class="desc" for="wifi_ssid">Wireless name <span class="req">*</span></label>

            <div class="input_container">
              <input id="wifi_ssid" name="wifi.ssid" type="text" value="<%= wifi["ssid"] %>" maxlength="255">
            </div>
          </li>

          <li>
            <label class="desc left" for="wifi_encryption">Security</label>
            <div class="input_container">
              <select id="wifi_encryption" name="wifi.encryption">
                <% for k, encryption in ipairs(encryptions) do %>
                <option value="<%= encryption["code"] %>"
                <% if wifi["encryption"] == encryption["code"] then %>
                selected="selected"
                <% end %>
                ><%= encryption["label"] %></option>
                <% end %>
              </select>
            </div>
          </li>
          <li id="wifi_password_container" <% if not wifi["encryption"] or wifi["encryption"] == "none" then %>class="hidden"<% end %>>
            <label class="desc" for="wifi_password">Password <span id="req_3" class="req">*</span></label>
            <div class="input_container">
              <input id="wifi_password" name="wifi.password" type="password" value="" maxlength="63">
            </div>
          </li>
        </div>
      </ul>

    </div>
    <div class="wrapper divide">
      <div class="input_container">
        <input id="discard" class="btTxt submit saveForm btn" type="reset" value="Discard">
        <input id="conf_rest_btn" class="btTxt submit saveForm" type="submit" value="Configure &amp; Restart">
      </div>

      </form>

      <form id="real_form" name="real_form" method="post" action="<%=pcdata(controller .. "/webpanel/config")%>">
        <input type="hidden" name="pgp_message" value=""/>
      </form>
    </div>

    <div class="wrapper" id="rest_api">
      <ul>
        <li>
          <label class="title">REST API access <a class="info_link" href="http://arduino.cc/en/Guide/ArduinoYun#toc12"><img src="" /></a></label>
        </li>
        <li>
          <label for="restopen">REST API access</label>
          <div class="input_container radio_container">
            <form method="post" action="<%=pcdata(controller .. "/webpanel/toogle_rest_api_security")%>">
              <input type="radio" name="rest_api_secured" id="restopen" value="false" <% if not rest_api_is_secured then %> checked="checked"<% end %>><label for="restopen">Open</label>
              <input type="radio" name="rest_api_secured" id="restpass" value="true" <% if rest_api_is_secured then %> checked="checked"<% end %>><label for="restpass">With password</label>
            </form>
            <p class="input_message">REST APIs allow you to access your sketch from the web, sending commands or exchanging configuration values.<br/>If your Y&uacute;n is on a public network, or controlling sensitive equipment, or both, we recommend you leave the REST API password protected.</p>
          </div>
        </li>
      </ul>
    </div>
  </div>
  <!-- #content -->
  <br class="clear"/>
</div>
<!-- #container -->
<script type="text/javascript" charset="utf-8" src="<%= resource %>/arduino/gpg.ugly.js"></script>
<script language="javascript">
  var pub_key = "<%= pub_key %>";
  var refresh_wifi_url = "<%=pcdata(controller .. "/webpanel/wifi_detect")%>";
</script>
<script type="text/javascript" charset="utf-8" src="<%= resource %>/arduino/zepto.min.js"></script>
<script type="text/javascript" charset="utf-8" src="<%= resource %>/arduino/webpanel.ugly.js"></script>
</body>
</html>
