分类 openwrt开发 下的文章

openwrt web管理页面 LuCI 要点

在uHTTPd上安装LuCI

这是安装Web用户界面LuCI的要点。运行"opkg update && opkg list luci-*"命令查找所有可用的能通过LuCI管理OpenWrt的软件包。

安装

  1. 在软件库中检索可用软件包的最新列表:

    opkg update

◾ 完整安装一个不需要HTTPS支持的LuCI:

opkg install luci

◾ 完整安装一个需要HTTPS支持的LuCI:

opkg install luci-ssl

OPKG 安装 luci
本地语言支持
基本的LuCI Web用户界面是英文的。但是,志愿者们正积极的把它翻译成许多语言。参见http://i18n.luci.subsignal.org/pootle/ 可以参与!有关可用包的列表,运行

opkg list | grep luci-i18n-

您会看到一个可用语言包的列表。要安装你的母语,例如运行

opkg install luci-i18n-chinese 

您还可以通过网页界面安装语言包,你可以同时安装多个LuCI语言包,要在它们之间切换可通过网页界面或编辑这个文件 → /etc/config/luci

开始使用Web服务器(uHTTPd)
Web服务器uHTTPd是LuCI安装包的一个依赖软件,它会在你安装LuCI时自动安装。 安装后,Web服务器是未运行的!你需要手动开启它。你还应该使能Web服务器,以使它在你重启路由器时自动启动。 下面的第一个命令启动Web服务器,第二个使它在重启时启动。

/etc/init.d/uhttpd start
/etc/init.d/uhttpd enable

现在,你应该能够连接到Web服务器 http://192.168.1.1 享受LuCI提供的服务了。

详细资料
LuCI做为“元包”安装,它同时安装了其他几个被定义为依赖关系的包。 尤其是,它安装了uHTTPd Web服务器,配置为供LuCI使用。 安装的依赖包如下(更多信息参见LuCI技术参考):

◾ uhttpd
◾ uhttpd-mod-ubus
◾ luci-mod-admin-full
◾ luci-theme-bootstrap
◾ luci-app-firewall
◾ luci-proto-core
◾ luci-proto-ppp
◾ libiwinfo-lua

要使用uHTTPd做Web界面,你仅需要很少的配置就行,因为uHTTPd配置了CGI以使LuCI可以使用Lua解释器来工作。 默认配置如下。默认情况下/www是标准的文档根目录。 因此,通过请求该文档根目录(在浏览器中输入设备IP地址)可以找到一个如index.html的索引文件(uHTTPd设置)。 配备的/www/index.html(与LuCI一起安装)文件会在收到请求时把你重定向到/cgi-bin/luci目录, 这是LuCI的默认CGI通道。这仅是一个脚本,它主要是在/usr/bin/lua中调用Lua。 uHTTPd默认配置为用CGI加载/cgi-bin路径下的页面,从而通过/cgi-bin/luci 脚本为这些网页开启服务。

另外,也可以把Lua作为嵌入式进程来运行LuCI。uHTTPd支持这一点; 可以参考uHTTPd Web服务器配置上uHTTPd的UCI配置的相关文章和章节 。

本文章由http://www.wifidog.pro/2015/08/11/openwrt-luci%E8%A6%81%E7%82%B9.html整理编辑,转载请注明出处

openwrt ubus (OpenWrt micro bus 架构)

为了在OpenWrt中提供守护进程和应用程序间的通讯,开发了ubus项目工程。它包含了守护进程、库以及一些额外的帮助程序。

核心部分是ubusd守护进程,它提供了其他守护进程将自己注册以及发送消息的接口。因为这个,接口通过使用Unix socket来实现,并使用TLV(type-length-value)消息。

为了简化软件的开发,可以使用已有的libubus库来使用ubus(连接ubus)。

每个守护进程在自己的名称空间中注册自有的路径。每个路径可以提供多个带有不定数量参数的方法,方法可以通过消息回复调用。

代码在LGPL 2.1授权方法下发布,你可以通过git在git://nbd.name/luci2/ubus.git或通过http在http://nbd.name/gitweb.cgi?p=luci2/ubus.git;a=summary获取。 ubus从r28499起被包含在OpenWrt中。

ubus命令行工具

ubus可以和ubusd服务器交互(和当前所有已经注册的服务). 它对研究和调试注册的命名空间以及编写脚本非常有用。对于调用带参数和返回信息的方法,它使用友好的JSON格式。下面是它的命令说明。

list
缺省列出所有通过RPC服务器注册的命名空间:

root@uplink:~# ubus list
network
network.device
network.interface.lan
network.interface.loopback
network.interface.wan
root@uplink:~#

如果调用时包含参数-v,将会显示指定命名空间更多方法参数等信息:

root@uplink:~# ubus -v list network.interface.lan
'network.interface.lan' @099f0c8b
    "up": {  }
    "down": {  }
    "status": {  }
    "prepare": {  }
    "add_device": { "name": "String" }
    "remove_device": { "name": "String" }
    "notify_proto": {  }
    "remove": {  }
    "set_data": {  }
root@uplink:~#

call
调用指定命名空间中指定的方法,并且通过消息传递给它:

root@uplink:~# ubus call network.interface.wan status
{
    "up": true,
    "pending": false,
    "available": true,
    "autostart": true,
    "uptime": 86017,
    "l3_device": "eth1",
    "device": "eth1",
    "address": [
        {
            "address": "178.25.65.236",
            "mask": 21
        }
    ],
    "route": [
        {
            "target": "0.0.0.0",
            "mask": 0,
            "nexthop": "178.25.71.254"
        }
    ],
    "data": {

    }
}
root@uplink:~#

消息参数必须是有效的JSON字符串,并且携带函数所要求的键及值:

root@uplink:~# ubus call network.device status '{ "name": "eth0" }'
{
    "type": "Network device",
    "up": true,
    "link": true,
    "mtu": 1500,
    "macaddr": "c6:3d:c7:90:aa:da",
    "txqueuelen": 1000,
    "statistics": {
        "collisions": 0,
        "rx_frame_errors": 0,
        "tx_compressed": 0,
        "multicast": 0,
        "rx_length_errors": 0,
        "tx_dropped": 0,
        "rx_bytes": 0,
        "rx_missed_errors": 0,
        "tx_errors": 0,
        "rx_compressed": 0,
        "rx_over_errors": 0,
        "tx_fifo_errors": 0,
        "rx_crc_errors": 0,
        "rx_packets": 0,
        "tx_heartbeat_errors": 0,
        "rx_dropped": 0,
        "tx_aborted_errors": 0,
        "tx_packets": 184546,
        "rx_errors": 0,
        "tx_bytes": 17409452,
        "tx_window_errors": 0,
        "rx_fifo_errors": 0,
        "tx_carrier_errors": 0
    }
}
root@uplink:~#

listen
设置一个监听socket并观察进入的事件:

root@uplink:~# ubus listen &
root@uplink:~# ubus call network.interface.wan down
{ "network.interface": { "action": "ifdown", "interface": "wan" } }
root@uplink:~# ubus call network.interface.wan up
{ "network.interface": { "action": "ifup", "interface": "wan" } }
{ "network.interface": { "action": "ifdown", "interface": "he" } }
{ "network.interface": { "action": "ifdown", "interface": "v6" } }
{ "network.interface": { "action": "ifup", "interface": "he" } }
{ "network.interface": { "action": "ifup", "interface": "v6" } }
root@uplink:~# 

send
发送一个事件提醒:

root@uplink:~# ubus listen &
root@uplink:~# ubus send foo '{ "bar": "baz" }'
{ "foo": { "bar": "baz" } }
root@uplink:~# 

本文章由http://www.wifidog.pro/2015/08/10/openwrt-ubus%E6%9E%B6%E6%9E%84.html整理编辑,转载请注明出处

OpenWrt Buildroot – About 编译过程

OpenWrt Buildroot is a set of Makefiles and patches that allows users to easily generate both a cross-compilation toolchain and a root filesystem for embedded systems. It is a heavily modified Buildroot. The cross-compilation toolchain uses uClibc, a tiny C standard library.

A compilation toolchain is the set of tools used to compile code for your system. It consists of:

◾ a compiler (in our case, gcc / deb: gcc)
◾ binary utils like assembler and linker (in our case, binutils / deb: binutils )
◾ a C standard library (for example GNU Libc, uClibc or dietlibc).

Using a PC, the compilation toolchain runs on an x86 processor and generates code for a x86 processor. On most Linux systems, the compilation toolchain uses the GNU libc as C standard library. It is called the "host compilation toolchain", and the machine it is running on is called the "host system". The compilation toolchain is provided by the distribution, and has nothing to do with OpenWrt Buildroot.

Embedded systems use a different processor and require a cross-compilation toolchain - a compilation toolchain that runs on a host system but that generates code for a target system (and target processor's instruction set architecture (ISA)). For example, if your host system uses x86 and your target system uses MIPS32, the regular compilation toolchain of your host runs on x86 and generates code for x86, while the cross-compilation toolchain runs on x86 and generates code for MIPS32.

While it is possible to manually configure and compile your own software, OpenWrt Buildroot automates this process to work on the instruction set architecture of most embedded systems.

While the OpenWrt Buildroot was designed for developers, inexperienced users can also use it to easily build their own custom firmware!

The OpenWrt Makefile has its own syntax, different from the conventional Makefile of Linux make tool. The OpenWrt Makefile defines the meta information of the package, where to download the package, how to compile, where to install the compiled binaries, etc. See How to Build OpenWrt Application Package for more detail.

OpenWrt Buildroot – Features
◾ Makes it easy to port software
◾ Uses kconfig (Linux Kernel menuconfig) for configuration of features
◾ Provides integrated cross-compiler toolchain (gcc, ld, …)
◾ Provides abstraction for autotools (automake, autoconf), cmake, scons
◾ Handles standard download, patch, configure, compile and packaging workflow
◾ Provides a number of common fixups for badly behaving packages

OpenWrt Buildroot – Make Targets
◾ Offers a number of high level make targets for standard package workflows
◾ Targets always in the format "component/name/action", e.g. "toolchain/gdb/compile" or "package/mtd/install"
◾ Prepare a package source tree: package/foo/prepare
◾ Compile a package: package/foo/compile
◾ Clean a package: package/foo/clean

OpenWrt Buildroot – Build sequence

  1. tools – automake, autoconf, sed, cmake
  2. toolchain/binutils – as, ld, …
  3. toolchain/gcc – gcc, g++, cpp, …
  4. target/linux – kernel modules
  5. package – core and feed packages
  6. target/linux – kernel image
  7. target/linux/image – firmware image file generation

Patch management
◾ Many packages will not work as-is and need patches to work on the target or to even compile
◾ OpenWrt Buildroot integrates quilt for easy patch management
◾ Turn package patches into quilt series: make package/foo/prepare QUILT=1
◾ Update patches from modified series: make package/foo/update
◾ Automatically rebase patches after an update: make package/foo/refresh

Packaging considerations
◾ Main objective is small memory and size footprint
◾ Features that make no sense on embedded systems get disabled through configure or are patched out
◾ Packages must be compilable regardless of the host system, should be self contained
◾ Shipped "configure" scripts are often faulty or unusable in a cross-compile setting, autoreconf or patching needed
◾ Build variants and kconfig includes allow for configurable compile-time settings
◾ There is no standard way for porting software, in many cases it "just works" but often the package build process needs tweaks

本文章由http://www.wifidog.pro/2015/08/07/openwrt-%E7%BC%96%E8%AF%91%E8%BF%87%E7%A8%8B.html整理编辑,转载请注明出处

openwrt 配置文件功能简介

配置文件

文件位置 描述
基本配置

/etc/config/dhcp    dnsmasq和DHCP的配置
/etc/config/dropbear    SSH服务端选项
/etc/config/firewall    中央防火墙配置
/etc/config/network 交换,接口和路由配置
/etc/config/system  杂项与系统配置
/etc/config/timeserver  rdate的时间服务器列表
/etc/config/wireless    无线设置和无线网络的定义

IPv6

/etc/config/ahcpd   Ad-Hoc配置协议(AHCP) 服务端配置以及转发器配置
/etc/config/aiccu   AICCU 客户端配置
/etc/config/dhcp6c  WIDE-DHCPv6 客户端配置
/etc/config/dhcp6s  WIDE-DHCPv6 服务端配置
/etc/config/gw6c    GW6c 客户端配置
/etc/config/radvd   路由通告 (radvd) 配置

其他

/etc/config/etherwake   以太网唤醒: etherwake
/etc/config/fstab   挂载点及swap
/etc/config/hd-idle 另一个可选的硬盘空闲休眠进程(需要路由器支持usb硬盘)
/etc/config/httpd   网页服务器配置选项(Busybox 自带httpd, 已被舍弃)
/etc/config/luci    基础 LuCI 配置
/etc/config/luci_statistics 包统计配置
/etc/config/mini_snmpd  mini_snmpd 配置
/etc/config/mountd  OpenWrt 自动挂载进程(类似autofs)
/etc/config/multiwan    简单多WAN出口配置
/etc/config/ntpclient   ntp客户端配置,用以获取正确时间
/etc/config/pure-ftpd   Pure-FTPd 服务端配置
/etc/config/qos QoS配置(流量限制与整形)
/etc/config/samba   samba配置(Microsoft文件共享)
/etc/config/snmpd   SNMPd(snmp服务进程) 配置
/etc/config/sshtunnel   sshtunnel配置
/etc/config/stund   STUN 服务端配置
/etc/config/transmission    BitTorrent配置
/etc/config/uhttpd  Web服务器配置(uHTTPd)
/etc/config/upnpd   miniupnpd UPnP服务器配置
/etc/config/ushare  uShare UPnP 服务器配置
/etc/config/vblade  vblade 用户空间AOE(ATA over Ethernet)配置
/etc/config/vnstat  vnstat 下载器配置
/etc/config/wifitoogle  使用按钮来开关WiFi的脚本
/etc/config/wol Wake-on-Lan: wol
/etc/config/znc ZNC 配置

本文章由http://www.wifidog.pro/2015/08/05/openwrt%E9%85%8D%E7%BD%AE.html整理编辑,转载请注明出处