Menu

#5188 DHCP server edit_host.cgi fails to populate subnet list

1.890
closed-fixed
nobody
None
5
2018-09-08
2018-09-07
Will
No

tl;dr: DHCP module's edit_host.cgi uses javascript to reference form objects by ID but those HTML ID values are never created. Changing setparent() to reference the objects by name seems to fix it, but probably isn't the "right" way to do it.

The longer version:

When adding a new host under the DHCP module, there is a "Host assigned to..." dropdown. In past versions, when you select something from this list (I normally use "Subnet"), it then populates a selection box to the right listing all the possible options (e.g., the subnets you have defined). Then you select the parent from there and the new host is created in that section in the config.

However, somewhere between our old version (1.760) and our new version (1.890), this broke. After a bit of debugging, the "Host assigned to" drop-down calls setparent(0) onChange, which fails by trying to reference document.forms[0].assign and later document.forms[0].parent. The older version of Webmin was adding an HTML "id" field to the "Host assigned to" dropdown ("assign") and to the parent selection list ("parent"). It looks like this HTML is generated by Webmin's ui_select function, which I didn't want to mess with. But editing the DHCP module's edit_host.cgi, at the bottom is the javascript for setparent().

I changed it from this:

function setparent(sel)
{
var idx = document.forms[0].assign.selectedIndex;
var v = document.forms[0].assign.options[idx].value;
var vv = v.split(";");
var parent = document.forms[0].parent;
parent.length = 0;

if (v==1) {
$script1
}
if (v==2) {
$script2
}
if (v==3) {
$script3
}
if (parent.length > 0) {
        parent.options[sel].selected = true;
        }
}
setparent($sel_parent);

To this:

function setparent(sel)
{
//var idx = document.forms[0].assign.selectedIndex;
var idx = document.getElementsByName("assign")[0].selectedIndex;
//var v = document.forms[0].assign.options[idx].value;
var v = document.getElementsByName("assign")[0].options[idx].value;
var vv = v.split(";");
//var parent = document.forms[0].parent;
var parent = document.getElementsByName("parent")[0];
parent.length = 0;

if (v==1) {
$script1
}
if (v==2) {
$script2
}
if (v==3) {
$script3
}
if (parent.length > 0) {
        parent.options[sel].selected = true;
        }
}
setparent($sel_parent);

And that seems to fix the problem. I do not know if this is the preferred way of referencing the form objects, but it seems get the job done.

Discussion

  • Jamie Cameron

    Jamie Cameron - 2018-09-08
    • status: open --> closed-fixed
     
  • Jamie Cameron

    Jamie Cameron - 2018-09-08

    Thanks for reporting this - it looks like fallout from some UI changes we made recently. I will include your fix in the next Webmin release.

     

Log in to post a comment.