OpenWrt Forum Archive

Topic: need help with cbi

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

how can I use a formvalue in a Namedsection name eg..


I need to use the value of "name"(the username) as the name of the NamedSection to write to the config

s = m:section(NamedSection, <username> , "user")
s.anonymous = true
s.addremove = true
name = s:option(Value, "name", translate("User Name"))
name.rmempty = false

the resulting config needs to be in this format

config user '<username>'
    option some_option '1'
    option another_option '0'
...

I can not seem to find the documentation for this maneuver

(Last edited by hostle19 on 20 Jan 2016, 00:40)

...bump

Anyone ?

can someone please throw me a bone here ... set me off in the right direction and I will figure it out. I have been studying the way it works in the interfaces menus but I think this is overkill for what i need to accomplish.

There is no standard way for this as there is no support for renaming sections in cbi. Cann't you just use the normal add/remove functionality of named sections?

Thanks for the response Jow, The problem with using the normal add/remove functionality is that the name of the section should be the name of the user being added, which when creating the user this value is obviously not present in the config, for editing purposes this works fine if the username as supplied as an argument when calling the model...

 ... url("admin/users/users", "foo")

then in the model

s = m:section(NamedSection, arg[1], "user")

I am thinking the only way to achieve this before the user/section is created is to add a text box to input the new username and use the  "Add New User" button to submit the name as an argument to the model as shown above. I think this the cleanest method even though it a little unorthodox 

the another method tough of is just add the user as a typed section first,resulting in a section like ..

config user
   option name 'foo'
   option shell '1'
    ...

then fire a function to rename the section to a
NamedSection with the desired format using the on_after_submit call to fire the function.

uci:rename("users.@user[0]=foo")
uci:commit("users")

resulting in the properly formated section

config user 'foo'
    option name 'foo'
    option shell '1'
        ...

(Last edited by hostle19 on 3 Feb 2016, 20:35)

Here is a screen shot from the new purposed layout, perhaps this will give you a better idea of what i am trying to accomplish..

http://fire-wrt.com/forums/attachment.php?attachmentid=23&amp;d=1454528997

http://fire-wrt.com/forums/attachment.php?attachmentid=22&amp;d=1454528997

The save and apply buttons will be removed from the overview page and the add button remove from the add/edit users page.

The overview page has an overview on the non root users, with 2 button options, the edit button redirects to the edit user model providing the username as an argument. The delete user button remove the user from the system and from the config file and redirects back to the overview

the adduser button redirects to the add user model but at this point does not supply the username as an argument ...hence the problem outlined in my previous post.


What would you consider the best, cleanest option to accomplish what I discussed in my previous post ? Can you think of a better way to go about it ?

Thanks for your input Jow

(Last edited by hostle19 on 3 Feb 2016, 21:11)

I have got it working the way I want now, basically I went with option 2, I simply create a named section like so..

s = m:section(NamedSection, "new", "user")

then on_after_submit a renaming function is called to rename the section properly...

function new_user()
  uci:rename("users.new="..uci:get("users", "new", "name"))
  uci:commit("users")
 return
end

problem solved smile

Thank you for the updates.

Hey no problem, its funny how when explaining the problem, one often finds a solution

cheers

The discussion might have continued from here.