1. 程式人生 > >openwrt ---Luci

openwrt ---Luci

luci 參考資料 http://luci.subsignal.org/trac/wiki/Documentation http://wiki.openwrt.org/doc/techref/preinit_mount?#first.boot http://www.google.com.hk/search?q=Luci&hl=en&safe=strict&domains=openwrt.org&sitesearch=openwrt.org&prmd=ivnsl&ei=kDCrTc6UGI-WvAO63LH_CQ&start=0&sa=N http://wiki.openwrt.org/doc/techref/luci http://wiki.openwrt.org/doc/uci http://wiki.openwrt.org/doc/techref/uci LuCI作為“FFLuCI”誕生於2008年3月份,目的是為OpenWrt韌體從 Whiterussian 到 Kamikaze實現快速配置介面。 Lua是一個小巧的指令碼語言,很容易嵌入其它語言。輕量級. LUA語言的官方版本只包括一個精簡的核心和最基本的庫。這使得LUA體積小、啟動速度快,從而適合嵌入在別的程式裡。 UCI是OpenWrt中為實現所有系統配置的一個統一介面,英文名Unified Configuration Interface,即統一配置介面。LuCI,即是這兩個專案的合體,可以實現路由的網頁配置介面。 最初開發這個專案的原因是沒有一個應用於嵌入式的免費,乾淨,可擴充套件以及維護簡單的網頁使用者介面介面。大部分相似的配置介面太依賴於大量的Shell指令碼語言的應用,但是LuCi使用的是Lua程式語言,並將介面分為邏輯部分,如模板和檢視。 LuCI使用的是面向物件的庫和模板,確保了高效的執行,輕量的安裝體積,更快的執行速度以及最重要的一個特性————更好的可維護性。 與此同時,LuCI從MVC-Webframework衍生出一個包含了很多庫、程式以及Lua程式使用者介面的集合,但是LuCI仍然專注於實現網頁使用者介面併成為OpenWrt Kamikaze官方的一份子。 /www/index.html: <meta http-equiv="refresh" content="0; URL=/cgi-bin/luci" /> <a style="color: white; text-decoration: none" href="/cgi-bin/luci">LuCI - Lua Configuration Interface 在 web server 中的 cgi-bin 目錄下,執行 luci 檔案(許可權一般是 755 ) , luci 的程式碼如下: 1 #!/usr/bin/lua -- 執行命令的路徑 2 require"luci.cacheloader" -- 匯入 cacheloader 包 3 require"luci.sgi.cgi"  -- 匯入 sgi.cgi 包 4 luci.dispatcher.indexcache = "/tmp/luci-indexcache" --cache 快取路徑地址 5 luci.sgi.cgi.run()  -- 執 行 run 方法,此方法位於 /usr/lib/lua/luci/sgi/cgi.lua中, 內容如下: --[[ LuCI - SGI-Module for CGI Description: Server Gateway Interface for CGI ]]-- exectime = os.clock() module("luci.sgi.cgi", package.seeall) local ltn12 = require("luci.ltn12") require("nixio.util") require("luci.http") require("luci.sys") require("luci.dispatcher") -- Limited source to avoid endless blocking local function limitsource(handle, limit) limit = limit or 0 local BLOCKSIZE = ltn12.BLOCKSIZE return function() if limit < 1 then handle:close() return nil else local read = (limit > BLOCKSIZE) and BLOCKSIZE or limit limit = limit - read local chunk = handle:read(read) if not chunk then handle:close() end return chunk end end end function run() local r = luci.http.Request( luci.sys.getenv(), limitsource(io.stdin, tonumber(luci.sys.getenv("CONTENT_LENGTH"))), ltn12.sink.file(io.stderr) ) local x = coroutine.create(luci.dispatcher.httpdispatch) local hcache = "" local active = true while coroutine.status(x) ~= "dead" do local res, id, data1, data2 = coroutine.resume(x, r) if not res then print("Status: 500 Internal Server Error") print("Content-Type: text/plain\n") print(id) break; end if active then if id == 1 then io.write("Status: " .. tostring(data1) .. " " .. data2 .. "\r\n") elseif id == 2 then hcache = hcache .. data1 .. ": " .. data2 .. "\r\n" elseif id == 3 then io.write(hcache) io.write("\r\n") elseif id == 4 then io.write(tostring(data1 or "")) elseif id == 5 then io.flush() io.close() active = false elseif id == 6 then data1:copyz(nixio.stdout, data2) data1:close() end end end end openwrt源: 1.轉到OpenWrt根目錄。 2.輸入 ./scripts/feeds update 3.輸入 ./scripts/feeds install -a -p luci 4.輸入 make menuconfig 5.在”LuCI”選單下你將找到所有的元件。 OpenWrt 安裝包版本庫: 1.新增一行文字到你的/etc/opkg.conf中,即將LuCI新增到版本庫中: src luci http://downloads.openwrt/kamikaze/8.09.2/YOUR_ARCHITECTURE/packages 2.輸入 opkg update 3.LuCI 簡版輸入: opkg install luci-light   LuCI 普通版: opkg install luci   自定義模組的安裝: opkg install luci-app-* 4.為了實現HTTPS支援,需要安裝luci-ssl meta安裝包 也許你想修改一下openWrt那個路由配置的醜陋介面,也許你想事項自己軟體的一些功能。但是卻沒有辦法去修改LuCI。在路由器上直接修改那就算了,我想說的是如何修改該LuCI的原始碼,這樣子你編譯好的bin映象檔案直接刷入路由器中就ok了。你先得了解一下LuCI,包括它的模組怎麼寫的,用的是lua語言等:LuCI實現啟動應用程式等指令碼命令, 然後你想知道怎麼將LuCI編譯進韌體中去: 輸入./scripts/feeds/ install LuCI 這樣子你會發現feeds資料夾下面有LuCI了,但是裡面除了資料夾一無所有,但是回到menuconfig中去回發現有LuCI了,還可以選擇ddns等模組,還可以選擇中文語言了,可以編譯到韌體中去了。那麼我們就編譯一下試試吧。在dl資料夾中,我們看到了LuCI-0.10+svn7976.tar.gz, 這證明原始碼其實是在這裡的 我們又進入build_dir/target-mips_uClibc-0.9.30.1這個資料夾下面發現瞭解壓的上述檔案了,好了,其實這個就是編譯的資料夾啦。看看裡面有什麼?theme啊什麼的,找個theme裡面的header.htm改改編譯後看看,發現在新的韌體中已經出現了改動了。 好我再模仿application資料夾下面的一些程式 如LuCI-ddns寫了一個LuCI-smustar的配置程式介面放到這個資料夾下面,回頭到menuconfig中發現沒有啊,怎麼辦?別急 回到feeds/LuCI/LuCI中找到makefile加入 $(eval $(call application,smustar,smustar for 802.1x,+PACKAGE_LuCI-app-smustar:smustar-scipts)) ^_^,再回到menuconfig中就看到了,果斷的選了,然後就編譯到韌體中去了 乎,折騰了我幾天的LuCI終於在bulder_dir下找到原始碼可以修改,不過最好別該這裡要改就makefile和dl下的原始碼吧,省的有時候buldr_dir下面的原始碼會唄dl下的那個壓縮檔案解壓過去,扔在裡面的檔案就會丟失,小心! 自用修改:

--[[
luci 封裝好的html控制元件類可以在以下檔案檢視:./host/usr/lib/lua/luci/cbi.lua

Diagnostics 頁面相關檔案: controller/admin/network.lua, view/admin_network/diagnostics.htm
HTM 頁面的變數和lua互動, html中: name="ping", this.form.ping, lua中: diag_ping
<input style="width: 50%" type="text" value="openwrt.org" name="ping" />
<input type="button" value="<%:Ping%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.ping,this.form.proto)" />
page = entry({"admin", "network", "diag_ping"}, call("diag_ping"), nil)

#只修改 name="pingxu", this.form.pingxu, 頁面也執行, 出現如下錯誤:
No page is registered at '/admin/network/diag_pingxu/openwrt.org'.
If this url belongs to an extension, make sure it is properly installed.
If the extension was recently installed, try removing the /tmp/luci-indexcache file.
--- 再修改 diag_pingxu 則OK, page = entry({"admin", "network", "diag_pingxu"}, call("diag_ping"), nil)

在已有的lua檔案中修改, 網頁上可以直接看到介面; 增加或刪除lua檔案, 則必須重啟路由器才可以看到介面

#lua中增加頁面: view/xutest/web-cgi.htm, 字尾名必須為htm, 不能為html.
page.target = template("xutest/web-cgi")
/usr/lib/lua/luci/template.lua:81: Failed to load template 'xutest/web-cgi'.
Error while parsing template '/usr/lib/lua/luci/view/xutest/web-cgi.htm'.

#htm 中直接跳轉
<a href="http://www.w3school.com.cn/index.html">W3School web

#/www/xutest/web-cgi.html, uhttp預設的跟目錄和luci中的目錄不同. 192.168.1.1 換成localhost 則錯誤
<a href="http://192.168.1.1/xutest/web-cgi.html">web-cgi

#index.html中 直接執行luci命令
<a style="color: white; text-decoration: none" href="/cgi-bin/luci">LuCI - Lua Configuration Interface


]]--

page = node("admin", "network", "diagnostics")
-- 直接連結到 view 相應目錄下面的 htm 頁面
page.target = template("admin_network/diagnostics")
page.title  = _("Diagnostics")
page.order  = 60

參考: 
1.  luci線上API: http://luci.subsignal.org/api/luci/
2. luci實現框架: http://www.cnblogs.com/zmkeil/archive/2013/05/14/3078774.html

BusyBox v1.19.4 (2013-09-27 00:16:27 EDT) built-in shell (ash)
Enter 'help' for a list of built-in commands.


  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 BARRIER BREAKER (Attitude Adjustment 12.09.1-qiushui007 test)
 -----------------------------------------------------
  * 1/2 oz Galliano         Pour all ingredients into
  * 4 oz cold Coffee        an irish coffee mug filled
  * 1 1/2 oz Dark Rum       with crushed ice. Stir.
  * 2 tsp. Creme de Cacao
 -----------------------------------------------------

[email protected]
:~# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    5.3M    272.0K      5.0M   5% /
/dev/root                 1.8M      1.8M         0 100% /rom
tmpfs                    30.2M     88.0K     30.1M   0% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
root                     30.2M     48.0K     30.1M   0% /tmp/root
overlayfs:/tmp/root      30.2M     48.0K     30.1M   0% /tmp/root
/dev/mtdblock3            5.3M    272.0K      5.0M   5% /overlay
overlayfs:/overlay        5.3M    272.0K      5.0M   5% /

[email protected]
:/xutest# opkg update
Downloading http://192.168.2.224/packages-ar71xx-AA/Packages.gz.
Updated list of available packages in /var/opkg-lists/snapshots.

[email protected]:/xutest# opkg install luci
Installing luci (0.11.1-1) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/luci_0.11.1-1_ar71xx.ipk.
Installing uhttpd (2012-10-30-e57bf6d8bfa465a50eea2c30269acdfe751a46fd) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/uhttpd_2012-10-30-e57bf6d8bfa465a50eea2c30269acdfe751a46fd_ar71xx.ipk.
Installing luci-mod-admin-full (0.11.1-1) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/luci-mod-admin-full_0.11.1-1_ar71xx.ipk.
Installing luci-mod-admin-core (0.11.1-1) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/luci-mod-admin-core_0.11.1-1_ar71xx.ipk.
Installing luci-lib-web (0.11.1-1) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/luci-lib-web_0.11.1-1_ar71xx.ipk.
Installing luci-lib-core (0.11.1-1) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/luci-lib-core_0.11.1-1_ar71xx.ipk.
Installing lua (5.1.4-8) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/lua_5.1.4-8_ar71xx.ipk.
Installing liblua (5.1.4-8) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/liblua_5.1.4-8_ar71xx.ipk.
Installing libuci-lua (2013-01-04.1-1) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/libuci-lua_2013-01-04.1-1_ar71xx.ipk.
Installing libubus-lua (2013-01-13-bf566871bd6a633e4504c60c6fc55b2a97305a50) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/libubus-lua_2013-01-13-bf566871bd6a633e4504c60c6fc55b2a97305a50_ar71xx.ipk.
Installing luci-lib-sys (0.11.1-1) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/luci-lib-sys_0.11.1-1_ar71xx.ipk.
Installing luci-lib-nixio (0.11.1-1) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/luci-lib-nixio_0.11.1-1_ar71xx.ipk.
Installing luci-sgi-cgi (0.11.1-1) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/luci-sgi-cgi_0.11.1-1_ar71xx.ipk.
Installing luci-proto-core (0.11.1-1) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/luci-proto-core_0.11.1-1_ar71xx.ipk.
Installing luci-i18n-english (0.11.1-1) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/luci-i18n-english_0.11.1-1_ar71xx.ipk.
Installing luci-lib-ipkg (0.11.1-1) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/luci-lib-ipkg_0.11.1-1_ar71xx.ipk.
Installing luci-theme-openwrt (0.11.1-1) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/luci-theme-openwrt_0.11.1-1_ar71xx.ipk.
Installing luci-theme-base (0.11.1-1) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/luci-theme-base_0.11.1-1_ar71xx.ipk.
Installing luci-app-firewall (0.11.1-1) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/luci-app-firewall_0.11.1-1_ar71xx.ipk.
Installing luci-proto-ppp (0.11.1-1) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/luci-proto-ppp_0.11.1-1_ar71xx.ipk.
Installing libiwinfo-lua (36) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/libiwinfo-lua_36_ar71xx.ipk.
Installing libiwinfo (36) to root...
Downloading http://192.168.2.224/packages-ar71xx-AA/libiwinfo_36_ar71xx.ipk.
Configuring luci-lib-sys.
Configuring liblua.
Configuring libuci-lua.
Configuring lua.
Configuring libubus-lua.
Configuring luci-lib-core.
Configuring luci-lib-nixio.
Configuring luci-sgi-cgi.
Configuring luci-lib-web.
Configuring luci-proto-core.
Configuring luci-i18n-english.
Configuring luci-mod-admin-core.
Configuring libiwinfo.
Configuring libiwinfo-lua.
Configuring luci-theme-base.
Configuring luci-theme-openwrt.
Configuring luci-app-firewall.
Configuring luci-lib-ipkg.
Configuring luci-proto-ppp.
Configuring luci-mod-admin-full.
Configuring uhttpd.
Configuring luci.
Collected errors:
 * resolve_conffiles: Existing conffile /etc/config/luci is different from the conffile in the new package. The new conffile will be placed at /etc/config/luci-opkg.

[email protected]:/xutest# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    5.3M    944.0K      4.4M  17% /
/dev/root                 1.8M      1.8M         0 100% /rom
tmpfs                    30.2M    388.0K     29.8M   1% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
root                     30.2M     48.0K     30.1M   0% /tmp/root
overlayfs:/tmp/root      30.2M     48.0K     30.1M   0% /tmp/root
/dev/mtdblock3            5.3M    944.0K      4.4M  17% /overlay
overlayfs:/overlay        5.3M    944.0K      4.4M  17% /

相關推薦

openwrt luci中文漢化

版權宣告:本文為博主原創文章,未經博主允許不得轉載。    https://blog.csdn.net/u011007991/article/details/70230916 前言 OpenWRT 的多語言支援此處只介紹中英文支援,首先OpenWRT的多語言支援其實就是

openwrt luci web解析

路由器:newifi mini 硬體資訊:mt7620a +mt7612e+128M DDR+16M flash 韌體: Pandorabox luci theme:lafite 主介面: winSCP登入 securieCRT 串列埠登

openwrt ---Luci

luci 參考資料 http://luci.subsignal.org/trac/wiki/Documentation http://wiki.openwrt.org/doc/techref/preinit_mount?#first.boot http://www.

Openwrt Luci介面開發

Openwrt已經提供了一個很強大的web管理介面Luci,可以方便的管理路由器。我們在開發智慧路由器時,一般就需要在OpenWrt的WEB介面增加內容。 1.Luci簡介 LuCI是OpenWrt上的Web管理介面,LuCI採用了MVC三層架構,使用Lua指令碼開發,所以

openwrt luci

一、如何修改LUCI原始碼如何修改該LuCI的原始碼,你首先需要了解一下LuCI基本知識,包括它的模組怎麼寫的,用的是lua語言等,LuCI實現啟動應用程式等指令碼命令,然後知道怎麼將luci編譯進韌體中去:輸入./scripts/feeds/ install luci。這樣子你就會發現feeds資料夾下面有

openwrt luci管理的Web介面例項

第一部分:template的方式實現網頁顯示hello world,如圖顯示:第一步:/usr/lib/lua/luci/controller/admin/system.lua中註冊選項:entry({

Openwrt系統中luci學習

1.Luci採用的是MCV框架,即是model,controller,view.在燒錄了編譯了luci的openwrt系統中,可以找到lua/luci陌路下的MCV三個目錄.其中model是抽象層,可以通過cbi開發基於框架下的介面;controller是控制層;而view則是介面層用來存放htm檔

openWRT學習之LUCI之一helloworld示例

備註1:本文 講述的是原生的openWRT環境下的LUCI 備註2:本文參考了諸多資料,感謝網友分享,參考資料: 文章開篇:新增一個選項,該選項處理結果:顯示hello world字串的網頁 注:我們先將頁面添加出來,然後我將分析如何為什麼這麼新增的。 目的:在s

openWRT學習之LUCI之二訪問controller下lua檔案的函式

備註:請關注之前的兩篇文章在做下面的工作 entry({"admin", "system", "heyg3"}, call("heyg3"), _("heyg3"), 5).dependent=false 同時在system.lua檔案中新增函式: --adde by h

OpenWrt新增LuCI的模組

【一、LuCI配置介面開發的框架】 LuCI是OpenWrt上的Web管理介面,LuCI採用了MVC三層架構,同時其使用Lua指令碼開發,所以開發LuCI的配置介面不需要編輯任何的Html程式碼,除非想自己單獨去建立網頁(View層),否則我們基本上只需要修改Model

Openwrt配置小記

穩定版 ann server mod ssh連接 dport port 固定ip lan 手中有臺Netgear WNR2000v3,一直想嘗試Openwrt,於是刷機。官方最新固件的穩定版本為15.05.1,該版本自帶luci,BUT,不能保存配置,上網查了很久,得出結論

OPENWRT中SSH免密鑰登陸(具體步驟)

文件 登陸 如果 roo article 能夠 -m zed track 通過使用ssh-keygen生成公鑰,在兩臺機器之間互相建立新人通道極客。 如果本地機器是client,遠程機器為server。 1、使用ssh-keygen生成rsa k

netgear 網件R6250路由 從OpenWrt或者DD-WRT系統恢復到默認系統 適合小白

openwrt恢復原廠固件 原文在這個連接,適合R6250。我順便把步驟詳細化,免得下次有小白遇到這個問題,耽誤太多的時間。 http://www.right.com.cn/forum/thread-155203-1-1.html 1.下載相關的固件 Version 1.0.0.62全名:R6250-V1.0

[無線路由] “免費”斐訊K2路由器刷OpenWRT(實戰MWAN多寬帶網速疊加)

blank balance -s 標準 理財 生效 數字 lin left (阿財首發於什麽值得買)斐訊K2可以算是一個非常另類的跨界數碼產品,其產品完全的醉翁之意不在酒。最多值99元的 MT7260硬件架構和用料,售價399元,金額激活K碼後自動轉入合作理財P2P平臺,等

初玩OpenWRT之編譯TP-Link WR841N V8固件

lan targe 分享 .com log 編輯 nwr 技術 blog 占坑,待編輯,先放一張圖 初玩OpenWRT之編譯TP-Link WR841N V8固件

集群 Ricci&&luci   Fence機制

ha一 Ricci&&luciServer1和server4做同樣的操作, (1)配置yum 源[HighAvailability]name=HighAvailabilitybaseurl=http://172.25.21.250/rhel6.5/HighAvailabilitygpgchec

我的openwrt開發相關文章

strac wid ng- tail 大小端 能夠 light fig csdn openwrt學習筆記: 在openwrt的學習過程中,走了非常多的彎路。一直以來有個期盼。希望能夠出個簡易教程,希望openwrt的同仁們能夠更加高速的入手。 、

智能小車十五《安裝openwrt虛擬機》

sata 發現 虛擬硬盤 幫助 ads 硬盤 麥克風 generic 路由 小車要實現智能,單靠它上面的arduino uno單片機,計算能力實在不能滿足要求。比如要放個攝像頭或放點音樂,它基本不能實現。我先讓它長上"眼鏡",給他裝個攝像頭。 我找了下實現方案,發現現在已經

openwrt 添加 802.1x客戶端njit

git 執行 修改 fault 位置 all http 配置文件 com 1、修改feed的配置文件 feeds.conf.default 添加下面兩句: src-svn njit https://github.com/liuqun/openwrt-c

Openwrt 路由器上 安裝 svn server

ont span conf 功能 tel nbsp 介紹 all svnadmin Openwrt 上也可以搭建 svn 服務了,這樣就不用開著 ubuntu 了,省電。 在後臺打開 ssh 服務,或者使用 telnet 服務,使用 putty 登錄路由器。 如下圖所示,這