2010年8月14日土曜日

Fonera 2202にWillcom/Emobileを接続 その4

 

今回は、Lua/Luci によるGUIとなります。lua/htmファイルはそのままFonera 2202にコピーします。luaファイルについては開発環境に追加するとbinaryにすることができますが、今回はメンテナンス性も考慮してソースコードのままとします。Binary化してのPackageが便利とは思いますが、まだそこまで構築方法の調査が進んでいません。

その1で安定していると書きましたが、負荷テストをしてみたところ、

  • WSIM IO Data接続の場合には、10MBのファイルのダウンロードにおいて、PPPの取りこぼしが発生することがある。PPPのdisconnect/reconnectになる。
  • H12HWの場合には、10MBのファイルダウンロードは成功しましたが、接続したままの放置状態にしておくと、何度か接続が切れてしまうことがありました。

となりました。WSIMについては、logreadを読むとCPUの性能が足らない可能性があるかと思われます。H12HWについては、(田舎ですので)emobileの通信状態もしくはこのところの暑さで発熱の可能性もありますが、どちらについても原因の追及はできていません。

 

1. GUI概要
TOP画面 
ff1  
「設定」をクリックします。

fon_admin画面
ff2
「ダイヤルアップ」アイコンをクリックします。アイコン自身はフリーのアイコンをダウンロードしているので、他のアイコンのマッチングはとれていません。

ダイヤルアップ画面
ff3 
登録済みの設定が一覧表示れています。各表示について、設定内容の編集ボタンと設定削除のボタンがあります。「編集」ボタンをクリックすると、編集画面が開きます。「削除」ボタンのクリックでは確認画面なしに設定が削除されます。そのうち追加はしたいと考えています。
ここでは、EmobileはOEM元のHuaweiをベンダー名としています。

設定編集画面
ff4 
設定の変更後、「保存」ボタンを押すと/etc/config/ttyusbに登録さている情報を更新します。VIDPIDが更新された場合には、登録されている情報を一旦削除してから、新規に登録します。
設定画面では入力値のチェック(空文字列も含む)は行っていません。/lib/uci/schema/default/ttyusbを参照しての入力値チェックをそのうち追加したいと考えています。Luci / Modelによって記述した画面ならば、何もせずとも入力値のチェックがされるのかもしれませんが。

設定の追加画面
 ff5
設定の追加画面においても、入力値のチェックは行っていません。VIDPIDは必須です。接続速度については、IO Data WSIMの場合には115200(bps)が上限のようです。これ以上の速度では chat scriptに対してWSIMの反応がありません。Foneraにてlogreadの結果を見るとchat scriptにてtime outが発生します。接続コマンドについては、-T<Phone number>の部分を書き換えます。Emobileの場合には、ダイヤル先が *99#なので、接続コマンドは、
/tmp/chat_dialer –s –v –T*99#
となります。

 

 

2. /usr/lib/lua/luci/controller/dialup.lua

--[[
  File: dialup.lua
  Description: dialup configration control file.
  Page transition:
    edit.htm: a html template to edit a ppp configuration
    remove.lua: a lua file to remove a ppp configuration
    addentry.htm: a html template to add a net configuratin
    ttyregsit.lua: a lua file to regist a ppp configuratin.
  Revision history:
    2010-08-14: Initial release
--]]

module("luci.controller.dialup", package.seeall)

function index()
        require("luci.i18n")
        luci.i18n.loadc("dialup")

        local page = entry({"fon_admin", "fon_dialup"}, template("dialup/dialup"),
                     luci.i18n.translate("dialup", "dialup"))
        page.i18n = "dialup_dialup"
        page.sysauth = "root"
        page.icon_path = "/luci-static/resources/icons"
        page.icon = "dialup.png"
        page.page_icon = "dialup.png"

        local epage = entry({"fon_admin", "fon_dialup", "edit"},
                      template("dialup/edit"),
                      luci.i18n.translate("dialup_edit", "Edit"))

        local epage = entry({"fon_admin", "fon_dialup", "remove"},
                      cbi("dialup/remove",
                      {on_success_to = {"fon_admin/fon_dialup"}}), "remove")

        local cpage = entry({"fon_admin", "fon_dialup", "addentry"},
                      template("dialup/addentry"),
                      luci.i18n.translate("dialup_addentry", "Add entry"))

        local rpage = entry({"fon_admin", "fon_dialup", "ttyregist"},
                      cbi("dialup/ttyregist",
                      {on_success_to = {"fon_admin/fon_dialup"}}), "ttyregist")

end

ダイヤルアップ接続のコントロール定義となります。メイン画面(dailup.htm)、編集画面(edit.htm)、追加画面(addentry.htm)、削除処理(remove.lua)、登録処理(ttyregist.lua)を記載します。viewのhtmファイルはtemplate(), model/cbiのluaファイルはcbi()を使います。

 

3. /usr/lib/lua/luci/view/dialup/dialup.htm

<!--
  File: dailup.htm
  Description: PPP dailup configration main.
  Page transition:
     dailup.htm -> edit.htm
                   remvoe.lua
       addentry: -> addentry.htm
       cancel: -> fon_admin

  Revision history:
    2010-08-14: Initial release
-->

<% boxcolor="darkorange" %>
<%+header%>
<h2><%:dialup_title %></h2>
<p><%:dialup_desc %></p>
<%
local uci = require("luci.model.uci").cursor()
local http = require("luci.http")

-- Get a temporary file name for vidpid list file.
local vidpid_list = os.tmpname()
local vendor, product

-- Get the list of vidpids defined in the configuration file. And store it into a temporary file.
local cmdline="/sbin/uci show ttyusb | cut -f2 -d\'.\' | cut -f1 -d\'=\' | uniq > "..vidpid_list
local ret = os.execute(cmdline)

-- Open the vidpid list file.
local fd = io.open(vidpid_list, "r")

-- Prepare FORM/ACTION URLs.
local url_edit     = luci.dispatcher.build_url("fon_admin", "fon_dialup", "edit")
local url_remove   = luci.dispatcher.build_url("fon_admin", "fon_dialup", "remove")
local url_addentry = luci.dispatcher.build_url("fon_admin", "fon_dialup", "addentry")
local url_cancel   = luci.dispatcher.build_url("fon_admin")
%>

<table class="cbi-section-table">
<thead>
<tr class="cbi-section-table-titles">
<th class="cbi-section-table-cell"><%:dialup_vendor %></th>
<th class="cbi-section-table-cell"><%:dialup_product %></th>
<th class="cbi-section-table-cell"><%:dialup_edit %></th>
<th class="cbi-section-table-cell"><%:dialup_remove %></th>
</tr>
</thead>

<%
if (fd ~= nil)
then
  while true
  do
    line = fd:read()
    if (line == nil or line == "") then
      break
    end

    vendor=uci:get("ttyusb."..line..".vendor")
    product=uci:get("ttyusb."..line..".product")
    if (product == nil or product == "") then
      break
    end
%>

<tbody>
<tr>
<td>
<% write (vendor) %>
</td><td>
<% write (product) %>
</td>
<td>
<form method="POST" ACTION="<% write (url_edit) %>">
<button type="submit" name="fon_dialup.edit" value="<% write (line) %>"><%:dialup_edit %></button>
</form>
</td>
<td>
<form method="POST" ACTION="<% write (url_remove) %>">
<button type="submit" name="fon_dialup.remove" value="<% write (line) %>" ><%:dialup_remove %></button>
</form>
</td>
</tr>

<%
  end
end
%>

</tbody>
</table>

<!-- Add edntry and cancel buttons -->
<div>
<form method="POST" ACTION="<% write (url_addentry) %>">
<button type="submit" name="fon_dialup.addentry" value="addentry"><%:dialup_addentry %></button>
<input type="submit" name="fon_dialup.cancel" value="<%:cancel %>"
onclick="document.location='<%=url_cancel%>'; return false;" />
</form>
</div>

<%
fd:close()
os.remove(vidpid_list)
%>
<%+footer%>

ダイヤルアップ設定のメイン画面となります。/etc/config/ttyusb に登録されている各設定の一覧を表示し、「編集」、「削除」ボタンをそれぞれの設定に対して表示します。一覧の作成については、shell commandを起動しています。これはLuci utiliesを利用して書き直しを検討しています。

「編集」、「削除」については、POSTからそれぞれのluaが起動されます。「設定の追加」においては、対応するviewが起動されます。「削除」の場合には、確認のdialogは表示されません。中止(キャンセル)の場合には管理画面(fon_admin)に戻ります。

 

4. /usr/lib/lua/luci/view/dialup/addentry.htm

<!--
  File: addentry.htm
  Description: Add a new ppp configuration.
  Page transition:
      dailup.htm -> addentry.htm
                      save: -> ttyregist.lua
                      cancel: -> fon_admin
  Revision history:
    2010-08-14: Initial release
-->

<% boxcolor="darkorange" %>
<%+header%>
<h2><%:dialup_addentry_title %></h2>
<p><%:dialup_addentry_desc %></p>
<%
local uci = require("luci.model.uci").cursor()

-- Prepare FORM/ACTION URLs.
local url_ttyregist = luci.dispatcher.build_url("fon_admin", "fon_dialup", "ttyregist")
local url_cancel    = luci.dispatcher.build_url("fon_admin")
%>

<form method="POST" ACTION="<% write(url_ttyregist) %>">

<div class="cbi-map" id="cbi-fon">
<fieldset class="cbi-section" id="cbi-fon-dialup-addentry">

<div class="cbi-section-node" id="cbi-fon-dialup-addentry">

<!-- Textbox for Vendor name -->
<div class="cbi-js-loadable line" id="cbi-fon-dialup-addentry-vendor">
<label class="cbi-value-title" for="fon_dialup.tty_vendor"><%:dialup_vendor %></label>
<input type="text" class="textField" onchange="cbi_d_update(this.id)"
  name="fon_dialup.tty_vendor" id="fon_dialup.tty_vendor" value="" />
</div>

<!-- Textbox for Product name -->
<div class="cbi-js-loadable line" id="cbi-fon-dialup-addentry-product">
<label class="cbi-value-title" for="fon_dialup.tty_product"><%:dialup_product %></label>
<input type="text" class="textField" onchange="cbi_d_update(this.id)"
  name="fon_dialup.tty_product" id="fon_dialup.tty_product" value="" />
</div>

<!-- Textbox for VIDPID (Vendor ID/Product ID) -->
<div class="cbi-js-loadable line" id="cbi-fon-dialup-addentry-vidpid">
<label class="cbi-value-title" for="fon_dialup.tty_vidpid"><%:dialup_vidpid %></label>
<input type="text" class="textField" onchange="cbi_d_update(this.id)"
  name="fon_dialup.tty_vidpid" id="fon_dialup.tty_vidpid" value="" />
</div>

<!-- Select List for tty driver -->
<div class="cbi-js-loadable line" id="fon_dialup.tty_driver">
<label class="cbi-value-title" for="fon_dialup.tty_driver"><%:dialup_driver %></label>
<select class="cbi-input-select" onchange="cbi_d_update(this.id)"
  id="fon_dialup.tty_driver" name="fon_dialup.tty_driver" size="1">
<%
  local driver = "pl2303"
  local driver_list = "pl2303 option usbserial"

  for idriver in string.gmatch(driver_list, "%w+") do
    if (idriver == driver) then
%>
      <option id="fon_dialup.tty_driver" selected="<% write (idriver) %>"> <% write (idriver) %>
<%  else %>
      <option id="fon_dialup.tty_driver" value="<% write (idriver) %>" > <% write (idriver) %>
<%
    end
  end
%>
</select>
</div>

<!-- Select list for modem type: dialup or 3gumts -->
<div class="cbi-js-loadable line" id="fon_dialup.tty_modemtype">
<label class="cbi-value-title" for="fon_dialup.tty_modemtype"><%:dialup_modemtype %></label>
<select class="cbi-input-select" onchange="cbi_d_update(this.id)"
  id="fon_dialup.tty_modemtype" name="fon_dialup.tty_modemtype" size="1">
<%
  local modemtype = "dialup"
  local modem_list = "dialup 3gumts"

  for imodem in string.gmatch(modem_list, "%w+") do
    if (imodem == modemtype) then
%>
      <option id="fon_dialup.tty_modemtype" selected="<% write (imodem) %>"> <% write (imodem) %>
<%  else %>
      <option id="fon_dialup.tty_modemtype" value="<% write (imodem) %>" > <% write (imodem) %>
<%
    end
  end
%>
</select>
</div>

<!-- Textbox for PPP account username -->
<div class="cbi-js-loadable line" id="cbi-fon-dialup-addentry-username">
<label class="cbi-value-title" for="fon_dialup.tty_username"><%:username %></label>
<input type="text" class="textField" onchange="cbi_d_update(this.id)"
  name="fon_dialup.tty_username" id="fon_dialup.tty_username" value="" />
</div>

<!-- Textbox for PPP account password -->
<div class="cbi-js-loadable line" id="cbi-fon-dialup-addentry-password">
<label class="cbi-value-title" for="fon_dialup.tty_password"><%:password %></label>
<input type="password" class="textField" onchange="cbi_d_update(this.id)"
  name="fon_dialup.tty_password" id="fon_dialup.tty_password" value="" />
</div>

<!-- Textbox for connection chat command line -->
<div class="cbi-js-loadable line" id="cbi-fon-dialup-addentry-connectcmd">
<label class="cbi-value-title" for="fon_dialup.tty_connectcmd"><%:dialup_connectcmd %></label>
<input type="text" class="textField" onchange="cbi_d_update(this.id)"
  name="fon_dialup.tty_connectcmd" id="fon_dialup.tty_connectcmd"
  value="/tmp/chat_dialer -s -v -T&lt;Phone number&gt;" />
</div>

<!-- Select list for interface speed -->
<div class="cbi-js-loadable line" id="fon_dialup.tty_speed">
<label class="cbi-value-title" for="fon_dialup.tty_speed"><%:dialup_speed %></label>
<select class="cbi-input-select" onchange="cbi_d_update(this.id)"
  id="fon_dialup.tty_speed" name="fon_dialup.tty_speed" size="1">
<%
  local speed = "115200"
  local speed_list = "9600 19200 38400 57600 115200 230400 460800 921600"

  for ispeed in string.gmatch(speed_list, "%w+") do
    if (ispeed == speed) then
%>
      <option id="fon_dialup.tty_speed" selected="<% write (ispeed) %>"> <% write (ispeed) %>
<%  else %>
      <option id="fon_dialup.tty_spped" value="<% write (ispeed) %>" > <% write (ispeed) %>
<%
    end
  end
%>
</select>
</div>

<!-- Textbox for modem inital command -->
<div class="cbi-js-loadable line" id="cbi-fon-dialup-addentry-atinit">
<label class="cbi-value-title" for="fon_dialup.tty_atinit"><%:dialup_atinit %></label>
<input type="text" class="textField" onchange="cbi_d_update(this.id)"
  name="fon_dialup.tty_atinit" id="fon_dialup.tty_atinit" value="" />
</div>

</div>
</fieldset>
</br>
</div>

<!--- Save and cancel buttons -->
<div>
<button type="submit" name="fon_dialup.tty_save" value="save"><%:save %></button>
<input type="submit" name="fon_dialup.cancel" value="<%:cancel %>"
onclick="document.location='<%=url_cancel%>'; return false;" />
</div>

</form>
<br />

<%+footer%>

ダイヤルアップ設定の追加画面となります。既存の自動生成されるhtmlに合わせて header / footerおよびclassを指定します。個々の設定項目を取り込んで、ttyregistにPOSTします。保存の場合には、値は”save”としています。中止(キャンセル)の場合には、JavaScriptにて、admin画面に戻ります

 

5. /usr/lib/lua/luci/view/dialup/edit.htm

<!--
  File: edit.htm
  Description: Edit a ppp configuration.
  Page transition:
    dailup.htm -> edit.htm
                    save: -> ttyregist.lua
                    cancel: -> fon_admin
  Revision history:
      2010-08-14: Initial release
-->

<% boxcolor="darkorange" %>
<%+header%>
<h2><%:dialup_edit_title %></h2>
<p><%:dialup_edit_desc %></p>
<%
local uci = require("luci.model.uci").cursor()
local http = require("luci.http")

-- Get post 'fon_dialup.edit' value.
local post_vidpid = http.formvalue("fon_dialup.edit")

-- Prepare FOM/ACTION URLs.
local url_ttyregist = luci.dispatcher.build_url("fon_admin", "fon_dialup", "ttyregist")
local url_cancel    = luci.dispatcher.build_url("fon_admin")

-- Retrieve config values.
local vidpid     = uci:get("ttyusb", post_vidpid, "vidpid")
local vendor     = uci:get("ttyusb", vidpid, "vendor", vendor)
local product    = uci:get("ttyusb", vidpid, "product", product)
local driver     = uci:get("ttyusb", vidpid, "driver", driver)
local modemtype  = uci:get("ttyusb", vidpid, "modemtype", modemtype)
local username   = uci:get("ttyusb", vidpid, "username", username)
local password   = uci:get("ttyusb", vidpid, "password", password)
local connectcmd = uci:get("ttyusb", vidpid, "connectcmd", connectcmd)
local speed      = uci:get("ttyusb", vidpid, "speed", speed)
local atinit     = uci:get("ttyusb", vidpid, "atinit", atinit)

%>

<form method="POST" ACTION="<% write(url_ttyregist) %>">

<div class="cbi-map" id="cbi-fon">
<fieldset class="cbi-section" id="cbi-fon-dialup-edit">

<div class="cbi-section-node" id="cbi-fon-dialup-edit">

<!-- Textbox for Vendor name -->
<div class="cbi-js-loadable line" id="cbi-fon-dialup-edit-vendor">
<label class="cbi-value-title" for="fon_dialup.tty_vendor"><%:dialup_vendor %></label>
<input type="text" class="textField" onchange="cbi_d_update(this.id)"
  name="fon_dialup.tty_vendor" id="fon_dialup.tty_vendor" value="<% write (vendor) %>" />
</div>

<!-- Textbox for Product name -->
<div class="cbi-js-loadable line" id="cbi-fon-dialup-edit-product">
<label class="cbi-value-title" for="fon_dialup.tty_product"><%:dialup_product %></label>
<input type="text" class="textField" onchange="cbi_d_update(this.id)"
  name="fon_dialup.tty_product" id="fon_dialup.tty_product" value="<% write (product) %>" />
</div>

<!-- Textbox for VIDPID (Vendor ID/Product ID) -->
<div class="cbi-js-loadable line" id="cbi-fon-dialup-edit-vidpid">
<label class="cbi-value-title" for="fon_dialup.tty_vidpid"><%:dialup_vidpid %></label>
<input type="text" class="textField" onchange="cbi_d_update(this.id)"
  name="fon_dialup.tty_vidpid" id="fon_dialup.tty_vidpid" value="<% write (vidpid) %>" />
</div>

<!-- Select List for tty driver -->
<div class="cbi-js-loadable line" id="fon_dialup.tty_driver">
<label class="cbi-value-title" for="fon_dialup.tty_driver"><%:dialup_driver %></label>
<select class="cbi-input-select" onchange="cbi_d_update(this.id)"
  id="fon_dialup.tty_driver" name="fon_dialup.tty_driver" size="1">
<%
  local driver_list = "pl2303 option usbserial"

  for idriver in string.gmatch(driver_list, "%w+") do
    if (idriver == driver) then
%>
      <option id="fon_dialup.tty_driver" selected="<% write (idriver) %>"> <% write (idriver) %>
<%  else %>
      <option id="fon_dialup.tty_driver" value="<% write (idriver) %>" > <% write (idriver) %>
<%
    end
  end
%>
</select>
</div>

<!-- Select List for modem type: dialup or 3gumts -->
<div class="cbi-js-loadable line" id="fon_dialup.tty_modemtype">
<label class="cbi-value-title" for="fon_dialup.tty_modemtype"><%:dialup_modemtype %></label>
<select class="cbi-input-select" onchange="cbi_d_update(this.id)"
  id="fon_dialup.tty_modemtype" name="fon_dialup.tty_modemtype" size="1">
<%
  local modem_list = "dialup 3gumts"

  for imodem in string.gmatch(modem_list, "%w+") do
    if (imodem == modemtype) then
%>
      <option id="fon_dialup.tty_modemtype" selected="<% write (imodem) %>"> <% write (imodem) %>
<%  else %>
      <option id="fon_dialup.tty_modemtype" value="<% write (imodem) %>" > <% write (imodem) %>
<%
    end
  end
%>
</select>
</div>

<!-- Textbox for PPP account username -->
<div class="cbi-js-loadable line" id="cbi-fon-dialup-edit-username">
<label class="cbi-value-title" for="fon_dialup.tty_username"><%:username %></label>
<input type="text" class="textField" onchange="cbi_d_update(this.id)"
  name="fon_dialup.tty_username" id="fon_dialup.tty_username" value="<% write (username) %>" />
</div>

<!-- Textbox for PPP account password -->
<div class="cbi-js-loadable line" id="cbi-fon-dialup-edit-password">
<label class="cbi-value-title" for="fon_dialup.tty_password"><%:password %></label>
<input type="password" class="textField" onchange="cbi_d_update(this.id)"
  name="fon_dialup.tty_password" id="fon_dialup.tty_password" value="<% write (password) %>" />
</div>

<!-- Textbox for connection chat command line -->
<div class="cbi-js-loadable line" id="cbi-fon-dialup-edit-connectcmd">
<label class="cbi-value-title" for="fon_dialup.tty_connectcmd"><%:dialup_connectcmd %></label>
<input type="text" class="textField" onchange="cbi_d_update(this.id)"
  name="fon_dialup.tty_connectcmd" id="fon_dialup.tty_connectcmd"
  value="<% write (connectcmd) %>" />
</div>

<!-- Select List for interface speed -->
<div class="cbi-js-loadable line" id="fon_dialup.tty_speed">
<label class="cbi-value-title" for="fon_dialup.tty_speed"><%:dialup_speed %></label>
<select class="cbi-input-select" onchange="cbi_d_update(this.id)"
  id="fon_dialup.tty_speed" name="fon_dialup.tty_speed" size="1">
<%
  local speed_list = "9600 19200 38400 57600 115200 230400 460800 921600"

  for ispeed in string.gmatch(speed_list, "%w+") do
    if (ispeed == speed) then
%>
      <option id="fon_dialup.tty_speed" selected="<% write (ispeed) %>"> <% write (ispeed) %>
<%  else %>
      <option id="fon_dialup.tty_spped" value="<% write (ispeed) %>" > <% write (ispeed) %>
<%
    end
  end
%>
</select>
</div>

<!-- Textbox for modem inital command -->
<div class="cbi-js-loadable line" id="cbi-fon-dialup-edit-atinit">
<label class="cbi-value-title" for="fon_dialup.tty_atinit"><%:dialup_atinit %></label>
<input type="text" class="textField" onchange="cbi_d_update(this.id)"
  name="fon_dialup.tty_atinit" id="fon_dialup.tty_atinit" value="<% write (atinit) %>" />
</div>

</div>
</fieldset>
</br>
</div>

<!-- Save and cancel buttons -->
<div>
<button type="submit" name="fon_dialup.tty_save" value="save"><%:save %></button>
<input type="submit" name="fon_dialup.cancel" value="<%:cancel %>"
onclick="document.location='<%=url_cancel%>'; return false;" />
</div>

</form>

<br />

<%+footer%>

選択したダイヤルアップ設定の編集画面となります。既存の自動生成されるhtmlに合わせて header / footerおよびclassを指定します。保存を押した場合には、ttyregistにPOSTします。

 

6. /usr/lib/lua/luci/model/cbi/dialup/remove.lua

--[[
  File: remove.lua
  Description: Remove a ppp configuration which has the specified vidpid.
  Page transition:
    dailup.htm -> remove.lua
  Revision history:
    2010-08-14: Initial release
--]]

local uci = require("luci.model.uci").cursor()
local http = require("luci.http")
require("luci.tools.webadmin")

local val = http.formvalue("fon_dialup.remove")
local vidpid = val

-- The value of POST is the vidpid.
if (vidpid ~= nil) then
  uci:delete_all("ttyusb", "ttyusb", {vidpid = vidpid})
  uci:save("ttyusb")
  uci:commit("ttyusb")
  http.redirect(".")
end

return

/etc/config/ttyusbの該当する情報を削除するluaになります。POSTのvalueとして削除対象のvidpidが渡されます。

 

7. /usr/lib/lua/luci/model/cbi/dialup/ttyregist.lua

--[[
  File: ttyregist.lua
  Description: store a ppp configuration
  Page transition:
    dailup.htm -> addentry.htm -> ttyregist.lua
                  edit.htm -> ttyregist.lua
  Revision history:
    2010-08-14: Initial release
--]]

local uci = require("luci.model.uci").cursor()
local http = require("luci.http")

local val = http.formvalue("fon_dialup.tty_cancel")
if (val ~= nil) then
  http.redirect("..")
  return
end

val = http.formvalue("fon_dialup.tty_save")
if (val ~= nil) then
  local vendor     = http.formvalue("fon_dialup.tty_vendor")
  local product    = http.formvalue("fon_dialup.tty_product")
  local vidpid     = http.formvalue("fon_dialup.tty_vidpid")
  local driver     = http.formvalue("fon_dialup.tty_driver")
  local modemtype  = http.formvalue("fon_dialup.tty_modemtype")
  local username   = http.formvalue("fon_dialup.tty_username")
  local password   = http.formvalue("fon_dialup.tty_password")
  local connectcmd = http.formvalue("fon_dialup.tty_connectcmd")
  local speed      = http.formvalue("fon_dialup.tty_speed")
  local atinit     = http.formvalue("fon_dialup.tty_atinit")

--[[ When the vidpid was modifed, old vidpid is passed as the form value.
     POSTed value and 'vidpid' value aren't same.
     First, remove the old vidpid section then create a new vidpid section.
--]]
  if (val ~= vidpid) then
    uci:delete_all("ttyusb", "ttyusb", {vidpid = val})
  end

  uci:set("ttyusb", vidpid, "ttyusb")
  uci:set("ttyusb", vidpid, "vendor", vendor)
  uci:set("ttyusb", vidpid, "product", product)
  uci:set("ttyusb", vidpid, "vidpid", vidpid)
  uci:set("ttyusb", vidpid, "driver", driver)
  uci:set("ttyusb", vidpid, "modemtype", modemtype)
  uci:set("ttyusb", vidpid, "username", username)
  uci:set("ttyusb", vidpid, "password", password)
  uci:set("ttyusb", vidpid, "connectcmd", connectcmd)
  uci:set("ttyusb", vidpid, "speed", speed)
  uci:set("ttyusb", vidpid, "atinit", atinit)
  uci:save("ttyusb")
  uci:commit("ttyusb")
end

http.redirect(".")
return

/etc/config/ttyusbに対して、更新処理を行います。formvalueが”save”のときに更新処理を行います。vidpidが変更されている場合には、先に削除処理を実行します。その後で更新された情報を登録します。

 

9. /usr/lib/lua/luci/i18n/dialup.en.lua

dialup = "Dialup"
dialup_desc = "Configure dialup connection."
dialup_title = "Dialup connection"
dialup_vendor = "Vendor name"
dialup_product = "Product name"
dialup_vidpid = "VIDPID"
dialup_driver = "Device driver"
dialup_modemtype = "Modem type"
dialup_connectcmd = "Connect command"
dialup_speed = "Interface speed"
dialup_atinit = "AT initial command"
dialup_edit = "Edit"
dialup_remove = "Remove"
dialup_edit_title = "Edit"
dialup_edit_desc = "Edit dialup configuration"
dialup_addentry = "Add entry"
dialup_addentry_title = "Add entry"
dialup_addentry_desc = "Add a dialup configration entry"

GUIの英語メッセージとなります。

 

10. /usr/lib/lua/luci/i18n/dialup.ja.lua (UTF-8にします)

dialup = "ダイヤルアップ"
dialup_desc = "ダイヤルアップ接続の設定を行います。"
dialup_title = "ダイヤルアップ接続設定"
dialup_vendor = "ベンダー名"
dialup_product = "製品名"
dialup_vidpid = "VIDPID"
dialup_driver = "デバイスドライバー"
dialup_modemtype = "モデムタイプ"
dialup_connectcmd = "接続コマンド"
dialup_speed = "接続速度"
dialup_atinit = "AT初期コマンド"
dialup_edit = "編集"
dialup_remove = "削除"
dialup_edit_title = "編集"
dialup_edit_desc = "ダイヤルアップ設定の編集"
dialup_addentry = "設定の追加"
dialup_addentry_title = "設定の追加"
dialup_addentry_desc = "ダイヤルアップ接続の追加"

GUIの日本語メッセージとなります。UTF-8にて保存します。

 

10. dialup iconファイルの設定
# cd /www/luci-static/resources/icons
# wget http://www.iconarchive.com/icons/iconica/pastel/48/dialup-networking-icon.png
# mv dialup-networking-icon.png dialup.png

 

 

12. 更新履歴
  • 2010/08/14: Initail release

0 件のコメント:

コメントを投稿