OpenWrt Forum Archive

Topic: cannot add new luci menu item

The content of this topic has been archived on 28 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi folks,
I'm struggling to add new menu item to luci for a couple of days, but I'm unsuccesful. Here is what I did:

- downloaded and compiled an own openwrt by doing the things found on http://wiki.openwrt.org/doc/howto/easy.build
I changed the svn command from attitude_adjustment to

svn co -r 42625 svn://svn.openwrt.org/openwrt/branches/barrier_breaker

I skipped the "Disable unnecessary packages" section.
It compiled ok, I was successful to flash the newly compiled firmware, router is working.

===

Then I followed instructions found on http://wiki.openwrt.org/doc/devel/luci character-by-character.
It was unsuccessful, new menu item didn't appeared, nor was it accessible by url.
make menuconfig didn't recognize this new app.
(I think there is an error in the above page, in the "Adding the cbi_tab code" section there is a path saying "/luci-myapplication/model/cbi/myapp-mymodule" - it should be "/luci-myapplication/luasrc/model/cbi/myapp-mymodule". I tried both ways with and without luasrc but none of these was working.)

===

Next I tried to "clone" and simplify the luci-commands application, by putting the following directory structure under feeds/luci/applications (asterisks are for indent only)
*luci-testapp
**luasrc
***controller
****testapp.lua
***view
****testapp.htm

testapp.lua contains:

module("luci.controller.testapp", package.seeall)
function index()
    entry({"admin", "system", "testapp"}, firstchild(), _("TestApp"), 82)
    entry({"admin", "system", "testapp", "base"}, template("testapp"), _("Base"), 1)
end

testapp.htm contains:

<%+header%>
<h1><%:Hello World%></h1> 
<%+footer%>

make menuconfig does not recognize it and there's no any traces of the above stuff in the compiled firmware (no menuitem, no url, file system does not contain anything of testapp).

===

Although http://wiki.openwrt.org/doc/devel/luci does not say anything about Makefile, finally I created a Makefile under feeds/luci/applications/luci-testapp because I saw it in other app dirs:

PO = testapp
include ../../build/config.mk
include ../../build/module.mk

The case was the same as above.

===

What am I missing? What have I do differently to create a new luci menu item?
Thanks a lot!

I will fix this for you if you share your application source with me. You can cleanse any proprietary info from it first if need be.

A zip or Github repository would be preferred. Github might be better so you can see exactly what I changed.

(Last edited by arfett on 24 Feb 2015, 22:33)

Dear arfett,
thank you for your reply.

"if you share your application source" - since this is my first try you can see in my initial post all the things I've done. See the paragraph starting with "Next I tried to" between the three = signs. I have no more source than the directory tree and the two file; you can see the entire contents of the files in the code blocks.
As far as I see, this should be enough for a new menu item and a hello world page in luci.

To save some time for you I've created a little zip containing the above stuff.
The contents of the zip is under feeds/luci/applications.

Thanks again,
ditor

ditor wrote:

Dear arfett,
thank you for your reply.

"if you share your application source" - since this is my first try you can see in my initial post all the things I've done. See the paragraph starting with "Next I tried to" between the three = signs. I have no more source than the directory tree and the two file; you can see the entire contents of the files in the code blocks.
As far as I see, this should be enough for a new menu item and a hello world page in luci.

To save some time for you I've created a little zip containing the above stuff.
The contents of the zip is under feeds/luci/applications.

Thanks again,
ditor

I'll take a look. I just don't like back-and-forth things on forums where some info may not be present and also if there was more to it I could make some other suggested changes. I'll be working on some reverse proxy stuff in the morning and I'll take a look at this too.

Cliff's notes:
I likely have this already fixed and made into a package that will show up on menuconfig but I will test in the morning then upload

(Last edited by arfett on 28 Feb 2015, 01:52)

http://www.mediafire.com/download/22mj9 … app.tar.gz

When you extract the file please use the "extract here" option or be sure to use the innermost folder named luci-app-testapp that has a file called Makefile directly inside of it.

To see in menuconfig:
1. Place the folder luci-app-testapp somewhere in your package dir like barrier_breaker/package/system
2. Run 'make menuconfig' and you'll see your app in LuCI -> Applications

To test first without building a firmware:
1. Transfer the controller file to /usr/lib/lua/luci/controller/ on the router
2. Transfer the testapp folder inside view to /usr/lib/lua/luci/view/ on the router
3. Reboot the router or run 'rm -rf /tmp/luci-indexcache /tmp/luci-modulecache' on the router
4. Go to the system page on LuCI

(Last edited by arfett on 28 Feb 2015, 21:49)

ditor wrote:

Hi folks,
I'm struggling to add new menu item to luci for a couple of days, but I'm unsuccesful. Here is what I did:

- downloaded and compiled an own openwrt by doing the things found on http://wiki.openwrt.org/doc/howto/easy.build
I changed the svn command from attitude_adjustment to

svn co -r 42625 svn://svn.openwrt.org/openwrt/branches/barrier_breaker

I skipped the "Disable unnecessary packages" section.
It compiled ok, I was successful to flash the newly compiled firmware, router is working.

===

Then I followed instructions found on http://wiki.openwrt.org/doc/devel/luci character-by-character.
It was unsuccessful, new menu item didn't appeared, nor was it accessible by url.
make menuconfig didn't recognize this new app.
(I think there is an error in the above page, in the "Adding the cbi_tab code" section there is a path saying "/luci-myapplication/model/cbi/myapp-mymodule" - it should be "/luci-myapplication/luasrc/model/cbi/myapp-mymodule". I tried both ways with and without luasrc but none of these was working.)

===

Next I tried to "clone" and simplify the luci-commands application, by putting the following directory structure under feeds/luci/applications (asterisks are for indent only)
*luci-testapp
**luasrc
***controller
****testapp.lua
***view
****testapp.htm

testapp.lua contains:

module("luci.controller.testapp", package.seeall)
function index()
    entry({"admin", "system", "testapp"}, firstchild(), _("TestApp"), 82)
    entry({"admin", "system", "testapp", "base"}, template("testapp"), _("Base"), 1)
end

testapp.htm contains:

<%+header%>
<h1><%:Hello World%></h1> 
<%+footer%>

make menuconfig does not recognize it and there's no any traces of the above stuff in the compiled firmware (no menuitem, no url, file system does not contain anything of testapp).

===

Although http://wiki.openwrt.org/doc/devel/luci does not say anything about Makefile, finally I created a Makefile under feeds/luci/applications/luci-testapp because I saw it in other app dirs:

PO = testapp
include ../../build/config.mk
include ../../build/module.mk

The case was the same as above.

===

What am I missing? What have I do differently to create a new luci menu item?
Thanks a lot!

At a quick glance ... you need to render the template. Here is how i would do it

/usr/lib/lua/luci/controller/admin/testapp.lua

module("luci.controller.admin.testapp", package.seeall)
function index()
    entry({"admin", "testapp"},alias("admin", "testapp", "base"), _("TestApp"), 82).index= true
    entry({"admin", "testapp", "base"}, call("action_base"), _("Base"), 1)
end

function action_base()
 luci.template.render("admin_testapp/testapp")
end

and your template

/usr/lib/lua/luci/view/admin_testapp/testapp.htm

<%+header%>
<h1><%:Hello World%></h1> 
<%+footer%>

use winscp add the files to the directories above and then reboot or do as arfett suggested and delete the /tmp/luci-indexcache file and the /tmp/luci-modulecahce
directory and the "TestApp" tab will appear with the "Base" sub tab, clicking on either one should render your template.

To add this to the build, untill you get comforable with cutom building i suggest you just add the directory structure and the files to the "files" directory at the root level of the openwrt src (create it if its not there) files in this directory will be added post build wink

hostle19 has some good config suggestions for the controller file. I was going to let you learn more about that on your own but gave you a package that will show up on menuconfig as well as the LuCI display.

To learn more about what is possible on the menus I actually recommend taking a look at the existing modules built into LuCI and base your configurations on those.

Also I maintain a LuCI package for the mwan3 package which I mixed and matched a lot of things I learned from other packages if you want to see how I made my package. If you wanted to do that you would install the luci-app-mwan3 package so you can see it live and then view the code that makes it work here: https://github.com/openwrt/packages/tre … mwan3-luci

(Last edited by arfett on 1 Mar 2015, 22:13)

arfett,
thank you very much, your gz is working! It's a very good point to start from. It's a bit strange anyway that this doc http://wiki.openwrt.org/doc/devel/luci  is quite misleading and misses out some important info.
The test method without building the entire firmware is very useful, saves a lot of time.

hostle19,
these hints also seems to be very handy, thank you!

The discussion might have continued from here.