OpenWrt Open Source system Luci Configuration Interface

Source: Internet
Author: User

Transferred from: http://www.right.com.cn/forum/thread-131035-1-1.html

I rookie, recently in the study of this knowledge, on the basis of reference materials to summarize the following content.
This article is for how to configure the Luci interface of OPENWRT open source system!

The main three points are as follows:

First, the main introduction of how to modify the Luci source code, where to modify;

Second, in the Luci How to write a module of their own;

Third, Luci implements script commands such as launching applications.


First, how to modify the Luci source code
How to modify the source code of the Luci, you first need to understand the basic knowledge of Luci, including its module how to write, using the Lua language, Luci implement script commands such as launching the application, and then know how to compile Luci into the firmware: input./scripts/feeds/ Install Luci. This way you will find feeds folder under the Luci, but in addition to the folder has nothing, back to menuconfig back to find Luci, you can choose DDNS and other modules, you can choose the Chinese language, you can compile into the firmware. So let's compile it and try it.
In the DL folder, we see the luci-0.10+svn7976.tar.gz, which proves that the source is actually here, we went into build_dir/target-mips_ uClibc-0.9.30.1 This folder below to find out about the pressure of the above file, in fact, this is the compilation of folders, there are theme and so on, find a theme inside the header.htm changed to look after, found in the new firmware has been changed, here to explain the success of the change. I imitated the application folder under some programs, such as Luci-ddns wrote a Luci-smustar configuration program interface placed under this folder, back to Menuconfig found no, how to do? Go back to Feeds/luci/luci and find makefile to join $ (eval $ (call Application,smustar,smustar for 802.1x,\+package_luci-app-smustar: smustar-scipts) ^_^, and then back to Menuconfig saw, decisive choice, and then compiled into the firmware went, toss me a few days of Luci finally found in Bulder_dir source can be modified, but it is best not to modify here, To change the makefile and DL under the source bar, save sometimes buldr_dir below the source will be DL under the compressed file extracted past, the file will be lost.

Ii. How to write a module in Luci
Play OpenWrt people will know Luci, because every time you enter the system will have big words show Luci interface configuration, with this interface is really good, convenient to configure our interface fool-like. The main references are as follows:
Official information: http://luci.subsignal.org/
In the resource of the official website, you can find a
Documentation:references and HowTos
Don't say anything else, just go ahead and run our theme.

Howto:write Modules
Just want to translate, is how to write a module, OK, I just want to write 802.1x authentication module

According to the official, it takes two things to complete a module and use it inside.

First, we'll find Usr/lib/lua/luci/controller. Create a folder inside, that is, our module name Smustar

Write the main file of our module under Smustar Smumodule.lua

Reference website, our module should be written in this way

Module ("Luci.controller.smustar.smumodule", Package.seeall)

Function index ()
Entry ({"admin", "Network", "802.1x"}, CBI ("Smustar-smumodule/netifaces"), "network Interfaces", +). Dependent=false
End

The first sentence is to declare the module.

The second sentence is the main function of our module, which is to tell it our entrance, rather than the entrance, it is to tell it is to be admin login to use, is in the network this menu, the name is called 802.1x. The module executes the program at smustar-smumodule/netifaces here.
What is Smustar-smumodule/netifaces? This is another file that we are going to build.
We found the path/usr/lib/lua/luci/module.

Create a folder below Smustar-smmodule create a file Netfaces.lua

OK next is to write our program in Netfaces.lua, refer to the official website that what Luci the coolest place, that is, modify the config file

Do not say you do not understand what is the config file, the simplest such as the network.

We set up a configuration file under/etc/config called Smuset

So this is how a config file is written.

Config ' interface ' Smustar '

Option ' user ' ' Youruser '
Option ' Pass ' ' Yourpass '

Ok this config file is like this, then write Netfaces.lua

m = Map ("Smuset", "Smustar")-we want to edit the UCI config File/etc/config/smustar here is the file we want to configure, the default path it has been able to distinguish, no tube
s = m:section (typedsection, "interface", "Smustar")-especially the "interface"-sections read out the interface area inside
S.addremove = true-allow The user to create and remove the interfaces

Sption (Value, "User", "Youruser") This can be an input box that reads the user item in the Smuset. Youruser is the tip of the language Luo

Key=sption (Value, "Pass", "Your password")

Key.password=true; Password input box set to asterisk

Return M-returns the Map
Okay, the file is done, and then we go into the Luci configuration interface.

You can see the 802.1X option under the network

After entering the account and password input box after changing

save&apply, found the password has been modified. Our 802.1X configuration interface is ready!

Iii. Luci Implement script commands such as launching applications
When we click on this button, Luci can run an application or script, you need to know Luci developed a function luci.http.formvalue, this function is used to get our post past the value of the form, Suppose you configure the page is an account and password, and then you need to click on the button "Save and apply" When you start our application (I here is Smustar), then you just check whether the value of the key is passed, if passed is the user submitted after the page, if not this value, So it is only the first time users enter this page, and WordPress how similar. The code is as follows:
Local REBOOT = Luci.http.formvalue ("cbi.apply")

If reboot Then
Sption (Dummyvalue, "Xiugai", "account number and password modified successfully!") Authentication is turned on, if you are not connected to the Internet, please confirm that the account still has a balance or not logged in elsewhere. ”)
Luci.sys.call ("Killall Smustar")
Luci.sys.call ("Smustarlogout &")
Luci.sys.call ("Smustar &")

End

If you need more than one key, and these buttons are different, you need to add a button, the same as long as the detection of this button to know if the user clicked on the button to submit the past page, such as click on a button restart, the code is as follows:

Sption (Button, "logout", "restart")

Local Logout=luci.http.formvalue ("Cbid.smuset.smustar.logout")
If Logout Then
Sption (Dummyvalue, "Tuichu", "Reboot!") ”)
Luci.sys.call ("reboot")
End

Luci provides this function Luci.sys.call allows you to invoke any Linux script or execution program, such as the shell, you can use it for more program exchange, that is, the implementation of the Web configuration and Linux execution program between the interaction. If you need more complex interaction, you can use the Luci file function to get communication with the program, of course, the program also has to communicate through the file, if it is their own program that good, if not then expect it to provide command calls, but generally supported.

Reference: http://chaochaoblog.com/

OpenWrt Open Source system Luci Configuration Interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.