From 1a7dc5842ca06c325f06abb7f276a6621df1b1b8 Mon Sep 17 00:00:00 2001 From: Nawawi Jamili Date: Wed, 18 Dec 2013 21:11:14 +0800 Subject: [PATCH 1/8] ui-lib conversion -> dhcpd --- dhcpd/edit_group.cgi | 111 ++++++++++++++----------------- dhcpd/edit_host.cgi | 147 +++++++++++++++++++---------------------- dhcpd/edit_iface.cgi | 21 +++--- dhcpd/edit_keys.cgi | 36 +++++----- dhcpd/edit_options.cgi | 104 ++++++++++++++--------------- dhcpd/edit_shared.cgi | 86 +++++++++++------------- dhcpd/edit_subnet.cgi | 4 +- dhcpd/edit_text.cgi | 12 ++-- dhcpd/edit_zones.cgi | 58 ++++++---------- dhcpd/index.cgi | 12 ++-- dhcpd/list_leases.cgi | 8 +-- dhcpd/params-lib.pl | 46 ++++++------- 12 files changed, 291 insertions(+), 354 deletions(-) diff --git a/dhcpd/edit_group.cgi b/dhcpd/edit_group.cgi index b1d5ab862..115fcf0b6 100755 --- a/dhcpd/edit_group.cgi +++ b/dhcpd/edit_group.cgi @@ -80,19 +80,19 @@ foreach $s (@shar) { } } -print "
\n"; -print "\n"; -print "\n"; -print "\n"; -print "
$text{'egroup_tblhdr'}
\n"; +print &ui_form_start("save_group.cgi", "post"); +print &ui_hidden("ret",$in{'ret'}); +print &ui_table_start($text{'egroup_tblhdr'}, "width=100%", 4); -print "\n"; -printf "\n", - &html_escape($group->{'comment'}); +print "\n"; +print ""; +print ""; -$rws = "rowspan=2" if (defined($in{'ret'})); -print "\n"; -print "$text{'egroup_hosts'}\n"; +print ""; foreach $h (&find("host", $mems)) { push(@host, $h); # if &can('r', \%access, $h); @@ -105,20 +105,19 @@ foreach $g (&find("group", $mems)) { } } @host = sort { $a->{'values'}->[0] cmp $b->{'values'}->[0] } @host; +my @hosts_sel; foreach $h (@host) { next if !&can('r', \%access, $h); - printf "\n", - $h->{'index'}, $ingroup{$h}, - (!$in{'new'}) && $ingroup{$h} eq $group->{'index'} ? "selected" : "", - $h->{'values'}->[0]; + push(@hosts_sel, ["$h->{'index'},$ingroup{$h}", $h->{'values'}->[0], ((!$in{'new'}) && $ingroup{$h} eq $group->{'index'} ? "selected" : "") ] ); } -print "\n"; +print &ui_select("hosts", undef, \@hosts_sel, 5, 1); +print "\n"; if (!$in{'new'}) { # inaccessible hosts in this group foreach $h (@host) { if (!&can('r', \%access, $h) && $ingroup{$h} eq $group->{'index'}) { - print "{'index'},$group->{'index'}\" type=hidden>\n"; + print &ui_hidden("hosts","$h->{'index'},$group->{'index'}"); } } } @@ -126,7 +125,7 @@ if (!$in{'new'}) { $assign = $in{'uidx'} ne "" ? "2" : $in{'sidx'} ne "" ? "1" : "0"; if (!defined($in{'ret'})) { - local @labels = ( $text{'ehost_toplevel'}, $text{'ehost_inshared'}, + my @labels = ( $text{'ehost_toplevel'}, $text{'ehost_inshared'}, $text{'ehost_insubnet'} ); print "\n"; - print "\n"; + print "\n"; } else { - print "\n", - print "\n"; + print &ui_hidden("assign",$assign); + print &ui_hidden("parent",$currpar); } print &choice_input($text{'egroup_nchoice'}, "use-host-decl-names", @@ -184,30 +179,26 @@ print &choice_input($text{'egroup_nchoice'}, "use-host-decl-names", print "\n" if (defined($in{'ret'})); &display_params($gconf, "group"); -print "
$text{'egroup_desc'}
$text{'egroup_desc'}"; +print &ui_textbox("desc", &html_escape($group->{'comment'}), 60); +print "
$text{'egroup_hosts'}
"; print "\n" if ($in{'assign'}); @@ -134,48 +133,44 @@ if (!defined($in{'ret'})) { if ($in{'assign'}) { $assign = $in{'assign'}; print "$labels[$assign]\n"; - print "\n"; - print "\n"; + print &ui_hidden("assign",$assign); + print &ui_hidden("jsquirk",1); } else { - print "\n"; + print &ui_select("assign", undef, \@assign_sel, 1, undef, undef, undef, "onChange='setparent(0)'" ); + print ""; } - print "\n"; + print &ui_select("parent", undef, \@parent_sel, 5, undef, undef, undef, "width=120"); + print "\n"; print "
$text{'ehost_nojavascr'}
"; + my @parent_sel; if ($assign == 2) { $iu = 0; foreach $u (@subn) { - printf "\n", - defined($shared{$u}) ? "$shared{$u},$u->{'index'}" : $u->{'index'}, - $iu == $sel_parent ? "selected" : "", - $subn_desc[$iu] - if &can('rw', \%access, $u); - $iu ++; + my $val1 = defined($shared{$u}) ? "$shared{$u},$u->{'index'}" : $u->{'index'}; + my $txt1 = $subn_desc[$iu] if &can('rw', \%access, $u); + push(@parent_sel, [$val1, $txt1, ($iu == $sel_parent ? "selected" : "") ] ); + $iu++; } } elsif ($assign == 1) { $is = 0; foreach $s (@shar) { - printf "\n", - $s->{'index'}, - $is == $sel_parent ? "selected" : "", - $shar_desc[$is] - if &can('rw', \%access, $s); - $is ++; + my $txt2 = $shar_desc[$is] if &can('rw', \%access, $s); + push(@parent_sel, [$s->{'index'}, $txt1, ($is == $sel_parent ? "selected" : "") ] ); + $is++; } } - print "
\n"; -print "\n"; -print "\n"; +print ""; +print &ui_table_end(); + +print &ui_hidden("sidx",$in{'sidx'}); +print &ui_hidden("uidx",$in{'uidx'}); + if (!$in{'new'}) { - print "\n"; + print &ui_hidden("idx",$in{'idx'}); print "\n"; - print "\n" - if &can('rw', \%access, $group); - print "\n"; - print "\n" - if &can('rw', \%access, $group, 1); + print "" if &can('rw', \%access, $group); + print ""; + print "" if &can('rw', \%access, $group, 1); print "
".&ui_submit($text{'save'})."".&ui_submit(( &can('rw', \%access, $group) ? $text{'butt_eco'} : $text{'butt_vco'} ),"options")."".&ui_submit($text{'delete'},"delete")."
\n"; - print "" - .$text{'index_addhst'}."

\n" if &can('rw', \%access, $group); + print &ui_link("edit_host.cgi?new=1&sidx=".$in{'sidx'}."&uidx=".$in{'uidx'}."&gidx=".$in{'idx'}."&ret=group",$text{'index_addhst'}) if &can('rw', \%access, $group); } else { - print "\n"; - print "\n"; + print &ui_hidden("new",1); + print &ui_submit($text{'create'}); } -print "

\n"; +print &ui_form_end(); print &script_fn() if (!defined($in{'ret'})); if ($in{'ret'} eq "subnet") { &ui_print_footer("edit_subnet.cgi?sidx=$in{'sidx'}&idx=$in{'uidx'}", diff --git a/dhcpd/edit_host.cgi b/dhcpd/edit_host.cgi index 2a68bb8f9..a0355b5d7 100755 --- a/dhcpd/edit_host.cgi +++ b/dhcpd/edit_host.cgi @@ -23,7 +23,7 @@ else { # display if ($in{'uidx'} ne '') { - local $s = $in{'sidx'} eq '' ? $conf->[$in{'uidx'}] : + my $s = $in{'sidx'} eq '' ? $conf->[$in{'uidx'}] : $conf->[$in{'sidx'}]->{'members'}->[$in{'uidx'}]; $desc = &text('ehost_subnet', $s->{'values'}->[0], $s->{'values'}->[2]); } @@ -153,132 +153,122 @@ foreach $s (@shar) { } $is ++; } +print &ui_form_start("save_host.cgi", "post"); +print &ui_hidden("ret",$in{'ret'}); +print &ui_table_start($text{'ehost_tabhdr'}, "width=100%", 4); -print "
\n"; -print "\n"; -print "\n"; -print "\n"; -print "
$text{'ehost_tabhdr'}
\n"; +print "\n"; +print ""; +print ""; -print "\n"; -printf "\n", - &html_escape($host->{'comment'}); +print "\n"; +print "\n"; -print "\n"; -printf "\n", - $host ? $host->{'values'}->[0] : ""; $assign = $in{'gidx'} ne "" ? "3" : $in{'uidx'} ne "" ? "2" : $in{'sidx'} ne "" ? "1" : "0"; if (!defined($in{'ret'})) { - local @labels = ( $text{'ehost_toplevel'}, $text{'ehost_inshared'}, + my @labels = ( $text{'ehost_toplevel'}, $text{'ehost_inshared'}, $text{'ehost_insubnet'}, $text{'ehost_ingroup'} ); - print "
$text{'ehost_desc'}"; +print &ui_textbox("desc", &html_escape($host->{'comment'}), 60); +print "
$text{'ehost_desc'}
$text{'ehost_hname'}"; +print &ui_textbox("name", ( $host ? $host->{'values'}->[0] : "" ), 20); +print "
$text{'ehost_hname'}"; + print "\n"; - - print "\n"; + print "\n"; } else { - print "\n"; - print "\n"; + print &ui_hidden("assign",$assign); + print &ui_hidden("parent",$currpar); } $hard = $hconf ? &find("hardware", $hconf) : undef; -print "\n"; -print "\n", - $hard ? $hard->{'values'}->[1] : ""; +print "\n"; +print "\n"; $fixed = $host ? &find("fixed-address", $hconf) : ""; -print "\n", - $fixed ? join(" ", grep { $_ ne "," } @{$fixed->{'values'}}) : ""; +print "\n"; &display_params($hconf, "host"); -print "
"; print "\n" if ($in{'assign'}); print "\n"; - print "\n"; - print "\n"; + print &ui_hidden("assign",$assign); + print &ui_hidden("jsquirk",1); } else { - print "\n"; + print &ui_select("assign", undef, \@assign_sel, 1, undef, undef, undef, "onChange='setparent(0)'" ); + print "\n"; } - print "\n"; + print &ui_select("parent", undef, \@parent_sel, 5, undef, undef, undef, "width=120"); + print "\n"; print "
$text{'ehost_nojavascr'}
$text{'ehost_assign'}
\n"; if ($in{'assign'}) { $assign = $in{'assign'}; print "$labels[$assign]
"; + my @parent_sel; if ($assign == 3) { $ig = 0; foreach $g (@group) { - printf "\n", - (defined($shared{$g}) ? "$shared{$g}," : ""). - (defined($subnet{$g}) ? "$subnet{$g}," : ""). - $g->{'index'}, - $ig == $sel_parent ? "selected" : "", - $group_desc[$ig] - if &can('rw', \%access, $g); - $ig ++; + my $val = (defined($shared{$g}) ? "$shared{$g}," : "").(defined($subnet{$g}) ? "$subnet{$g}," : "").$g->{'index'}; + my $txt = $group_desc[$ig] if &can('rw', \%access, $g); + push(@parent_sel, [$val, $txt, ($ig == $sel_parent ? "selected" : "") ] ); + $ig++; } } elsif ($assign == 2) { $iu = 0; foreach $u (@subn) { - printf "\n", - defined($shared{$u}) ? "$shared{$u},$u->{'index'}" : $u->{'index'}, - $iu == $sel_parent ? "selected" : "", - $subn_desc[$iu] - if &can('rw', \%access, $u); - $iu ++; + my $val1 = defined($shared{$u}) ? "$shared{$u},$u->{'index'}" : $u->{'index'}; + my $txt1 = $subn_desc[$iu] if &can('rw', \%access, $u); + push(@parent_sel, [$val1, $txt1, ($iu == $sel_parent ? "selected" : "") ] ); + $iu++; } } elsif ($assign == 1) { $is = 0; foreach $s (@shar) { - printf "\n", - $s->{'index'}, - $is == $sel_parent ? "selected" : "", - $shar_desc[$is] - if &can('rw', \%access, $s); - $is ++; + my $txt2 = $shar_desc[$is] if &can('rw', \%access, $s); + push(@parent_sel, [$s->{'index'}, $txt1, ($is == $sel_parent ? "selected" : "") ] ); + $is++; } } - print "
$text{'ehost_hwaddr'}"; -printf "
$text{'ehost_hwaddr'}"; +my @hardware_type_sel; +my @hardware = ("ethernet","token-ring","fddi"); +foreach my $hv (@hardware) { + push(@hardware_type_sel, [$hv,$hv, ($hard && $hard->{'values'}->[0] eq $hv ? "selected" : "")] ); +} +print &ui_select("hardware_type", undef, \@hardware_type_sel, 1); +print &ui_textbox("hardware", ( $hard ? $hard->{'values'}->[1] : "" ), 18); +print "
$text{'ehost_fixedip'} \n"; -printf "
$text{'ehost_fixedip'}\n"; +print &ui_textbox("fixed-address", ( $fixed ? join(" ", grep { $_ ne "," } @{$fixed->{'values'}}) : "" ), 20); +print "
\n"; -print "\n"; -print "\n"; -print "\n"; +print &ui_table_end(); + +print &ui_hidden("gidx",$in{'gidx'}); +print &ui_hidden("uidx",$in{'uidx'}); +print &ui_hidden("sidx",$in{'sidx'}); + if (!$in{'new'}) { - print "\n"; + print &ui_hidden("idx",$in{'idx'}); print "\n"; - print "\n" - if &can('rw', \%access, $host); - print "\n"; - print "\n" - if &can('rw', \%access, $host, 1); + print "" if &can('rw', \%access, $host); + print ""; + print "" if &can('rw', \%access, $host, 1); print "
".&ui_submit($text{'save'})."".&ui_submit(( &can('rw', \%access, $host) ? $text{'butt_eco'} : $text{'butt_vco'} ),"options")."".&ui_submit($text{'delete'},"delete")."
\n"; } else { - print "\n"; - print "\n"; + print &ui_hidden("new",1); + print &ui_submit($text{'butt_create'}); } -print "\n"; + +print &ui_form_end(); + print &script_fn() if (!defined($in{'ret'})); if ($in{'ret'} eq "group") { &ui_print_footer("edit_group.cgi?sidx=$in{'sidx'}&uidx=$in{'uidx'}&idx=$in{'gidx'}", @@ -298,7 +288,7 @@ else { sub script_fn { return < +