diff --git a/custom/CHANGELOG b/custom/CHANGELOG index bb3f9db8f..f1664a3db 100644 --- a/custom/CHANGELOG +++ b/custom/CHANGELOG @@ -20,3 +20,5 @@ Re-designed the user interface somewhat, and converted all code to use the new W When commands are shown in a table and no parameters are needed, the names now link directly to run the command. ---- Changes since 1.400 ---- Added a popup progress tracker to commands with file upload fields. +---- Changes since 1.410 ---- +All links to commands are via an ID number rather than an index, which makes them easier to link to from other web pages. diff --git a/custom/custom-lib.pl b/custom/custom-lib.pl index a2be39d4f..e9b768a47 100644 --- a/custom/custom-lib.pl +++ b/custom/custom-lib.pl @@ -101,6 +101,22 @@ closedir(DIR); return @rv; } +# get_command(id) +# Returns the command with some ID +sub get_command +{ +local ($id, $idx) = @_; +local @cmds = &list_commands(); +local $cmd; +if ($id) { + ($cmd) = grep { $_->{'id'} eq $id } &list_commands(); + } +else { + $cmd = $cmds[$idx]; + } +return $cmd; +} + # save_command(&command) sub save_command { diff --git a/custom/edit_cmd.cgi b/custom/edit_cmd.cgi index 1ea86b3ef..a762808ab 100755 --- a/custom/edit_cmd.cgi +++ b/custom/edit_cmd.cgi @@ -11,14 +11,13 @@ if ($in{'new'}) { } else { &ui_print_header(undef, $text{'edit_title'}, "", "edit"); - @cmds = &list_commands(); - $cmd = $cmds[$in{'idx'}]; + $cmd = &get_command($in{'id'}, $in{'idx'}); } # Form header print &ui_form_start("save_cmd.cgi", "post"); print &ui_hidden("new", $in{'new'}); -print &ui_hidden("idx", $in{'idx'}); +print &ui_hidden("id", $cmd->{'id'}); print &ui_table_start($text{'edit_details'}, "width=100%", 4); # Command ID diff --git a/custom/edit_file.cgi b/custom/edit_file.cgi index 4871e3b5c..b0d2b5263 100755 --- a/custom/edit_file.cgi +++ b/custom/edit_file.cgi @@ -11,13 +11,12 @@ if ($in{'new'}) { } else { &ui_print_header(undef, $text{'fedit_title'}, "", "fedit"); - @cmds = &list_commands(); - $edit = $cmds[$in{'idx'}]; + $edit = &get_command($in{'id'}, $in{'idx'}); } print &ui_form_start("save_file.cgi", "post"); print &ui_hidden("new", $in{'new'}); -print &ui_hidden("idx", $in{'idx'}); +print &ui_hidden("id", $edit->{'id'}); print &ui_table_start($text{'file_details'}, "width=100%", 2); if (!$in{'new'}) { diff --git a/custom/edit_sql.cgi b/custom/edit_sql.cgi index e7853f964..265c09f62 100755 --- a/custom/edit_sql.cgi +++ b/custom/edit_sql.cgi @@ -26,13 +26,12 @@ if ($in{'new'}) { } else { &ui_print_header(undef, $text{'sql_title2'}, ""); - @cmds = &list_commands(); - $cmd = $cmds[$in{'idx'}]; + $cmd = &get_command($in{'id'}, $in{'idx'}); } print &ui_form_start("save_sql.cgi", "post"); print &ui_hidden("new", $in{'new'}),"\n"; -print &ui_hidden("idx", $in{'idx'}),"\n"; +print &ui_hidden("id", $cmd->{'id'}),"\n"; print &ui_table_start($text{'sql_header'}, "width=100%", 2); # Show command info diff --git a/custom/form.cgi b/custom/form.cgi index 38be4c606..d9855507b 100755 --- a/custom/form.cgi +++ b/custom/form.cgi @@ -4,8 +4,7 @@ require './custom-lib.pl'; &ReadParse(); -@cmds = &list_commands(); -$cmd = $cmds[$in{'idx'}]; +$cmd = &get_command($in{'id'}, $in{'idx'}); &can_run_command($cmd) || &error($text{'form_ecannot'}); # Display form for command parameters @@ -29,7 +28,7 @@ elsif (@a) { else { print &ui_form_start("run.cgi"); } -print &ui_hidden("idx", $in{'idx'}); +print &ui_hidden("id", $cmd->{'id'}); print &ui_table_start(&html_escape($cmd->{'desc'}), "width=100%", 4, [ "width=20%", "width=30%", "width=20%", "width=30%" ]); print &ui_table_row(undef, $cmd->{'html'}, 4) if ($cmd->{'html'}); diff --git a/custom/index.cgi b/custom/index.cgi index 408ba906a..6955f4c64 100755 --- a/custom/index.cgi +++ b/custom/index.cgi @@ -52,7 +52,7 @@ elsif ($config{'display_mode'} == 0) { $html .= &ui_form_start("run.cgi"); } } - $html .= &ui_hidden("idx", $c->{'index'}); + $html .= &ui_hidden("id", $c->{'id'}); $w = $config{'columns'} == 2 ? 2 : 4; $html .= &ui_table_start(undef, undef, $w, $config{'columns'} == 1 ? [ "width=20%", "width=30%" ] @@ -72,13 +72,13 @@ elsif ($config{'display_mode'} == 0) { } if ($access{'edit'}) { if ($c->{'edit'}) { - $link = "$text{'index_fedit'}"; + $link = "$text{'index_fedit'}"; } elsif ($c->{'sql'}) { - $link = "$text{'index_sedit'}"; + $link = "$text{'index_sedit'}"; } else { - $link = "$text{'index_edit'}"; + $link = "$text{'index_edit'}"; } $html .= &ui_table_row(undef, &ui_links_row([ $link ]), $w); @@ -107,42 +107,42 @@ else { local $e = $c->{'edit'} ? "edit_file.cgi" : $c->{'sql'} ? "edit_sql.cgi" : "edit_cmd.cgi"; - push(@links, "". + push(@links, "". "$text{'index_ed'}"); } if ($c->{'edit'} && !@{$c->{'args'}}) { # Open file editor directly, as file is known - push(@cols, "". + push(@cols, "". &html_escape($c->{'desc'}).""); - push(@links, "". + push(@links, "". $text{'index_acted'}.""); } elsif ($c->{'sql'} && !@{$c->{'args'}}) { # Execute SQL directorly, as no args - push(@cols, "". + push(@cols, "". &html_escape($c->{'desc'}).""); - push(@links, "". + push(@links, "". $text{'index_actrun'}.""); } elsif ($c->{'sql'}) { # Link to SQL query form - push(@cols, "". + push(@cols, "". &html_escape($c->{'desc'}).""); - push(@links, "". + push(@links, "". $text{'index_actsql'}.""); } elsif (!@{$c->{'args'}}) { # Link direct to execute page - push(@cols, "". + push(@cols, "". &html_escape($c->{'desc'}).""); - push(@links, "". + push(@links, "". $text{'index_actrun'}.""); } else { # Link to parameters form - push(@cols, "". + push(@cols, "". &html_escape($c->{'desc'}).""); - push(@links, "". + push(@links, "". $text{'index_actform'}.""); } push(@cols, $c->{'html'}); diff --git a/custom/run.cgi b/custom/run.cgi index fd916d9f0..7308455b7 100755 --- a/custom/run.cgi +++ b/custom/run.cgi @@ -13,8 +13,7 @@ else { } $| = 1; &error_setup($text{'run_err'}); -@cmds = &list_commands(); -$cmd = $cmds[$in{'idx'}]; +$cmd = &get_command($in{'id'}, $in{'idx'}); &can_run_command($cmd) || &error($text{'run_ecannot'}); if (&supports_users()) { $user = $cmd->{'user'} eq '*' ? $remote_user : $cmd->{'user'}; diff --git a/custom/save.cgi b/custom/save.cgi index e8c6e665c..ae7fe946b 100755 --- a/custom/save.cgi +++ b/custom/save.cgi @@ -4,8 +4,7 @@ require './custom-lib.pl'; &ReadParseMime(); -@cmds = &list_commands(); -$edit = $cmds[$in{'idx'}]; +$edit = &get_command($in{'id'}, $in{'idx'}); &error_setup($text{'view_err'}); $edit->{'edit'} && &can_run_command($edit) || &error($text{'edit_ecannot'}); diff --git a/custom/save_cmd.cgi b/custom/save_cmd.cgi index 8b2aad1af..3bdf38b7c 100755 --- a/custom/save_cmd.cgi +++ b/custom/save_cmd.cgi @@ -6,16 +6,15 @@ require './custom-lib.pl'; &ReadParse(); $access{'edit'} || &error($text{'save_ecannot'}); -@cmds = &list_commands(); if ($in{'delete'}) { - $cmd = $cmds[$in{'idx'}]; + $cmd = &get_command($in{'id'}, $in{'idx'}); &delete_command($cmd); &webmin_log("delete", "command", $cmd->{'id'}, $cmd); } else { &error_setup($text{'save_err'}); if (!$in{'new'}) { - $cmd = $cmds[$in{'idx'}]; + $cmd = &get_command($in{'id'}, $in{'idx'}); } else { $cmd = { 'id' => time() }; diff --git a/custom/save_file.cgi b/custom/save_file.cgi index 775cfdac3..c282ad0b5 100755 --- a/custom/save_file.cgi +++ b/custom/save_file.cgi @@ -6,16 +6,15 @@ require './custom-lib.pl'; &ReadParse(); $access{'edit'} || &error($text{'file_ecannot'}); -@cmds = &list_commands(); if ($in{'delete'}) { - $edit = $cmds[$in{'idx'}]; + $edit = &get_command($in{'id'}, $in{'idx'}); &delete_command($edit); &webmin_log("delete", "edit", $edit->{'id'}, $edit); } else { &error_setup($text{'file_err'}); if (!$in{'new'}) { - $edit = $cmds[$in{'idx'}]; + $edit = &get_command($in{'id'}, $in{'idx'}); } else { $edit = { 'id' => time() }; diff --git a/custom/save_sql.cgi b/custom/save_sql.cgi index 77af3ec46..588876272 100755 --- a/custom/save_sql.cgi +++ b/custom/save_sql.cgi @@ -5,16 +5,15 @@ require './custom-lib.pl'; &ReadParse(); $access{'edit'} || &error($text{'save_ecannot'}); -@cmds = &list_commands(); if ($in{'delete'}) { - $cmd = $cmds[$in{'idx'}]; + $cmd = &get_command($in{'id'}, $in{'idx'}); &delete_command($cmd); &webmin_log("delete", "command", $cmd->{'id'}, $cmd); } else { &error_setup($text{'sql_err'}); if (!$in{'new'}) { - $cmd = $cmds[$in{'idx'}]; + $cmd = &get_command($in{'id'}, $in{'idx'}); } else { $cmd = { 'id' => time() }; diff --git a/custom/sql.cgi b/custom/sql.cgi index 4086943b6..fc07a6610 100755 --- a/custom/sql.cgi +++ b/custom/sql.cgi @@ -9,8 +9,7 @@ else { &ReadParse(); } &error_setup($text{'srun_err'}); -@cmds = &list_commands(); -$cmd = $cmds[$in{'idx'}]; +$cmd = &get_command($in{'id'}, $in{'idx'}); &can_run_command($cmd) || &error($text{'run_ecannot'}); # Connect to the DB diff --git a/custom/sqlform.cgi b/custom/sqlform.cgi index 6daeede94..4999f5284 100755 --- a/custom/sqlform.cgi +++ b/custom/sqlform.cgi @@ -4,8 +4,7 @@ require './custom-lib.pl'; &ReadParse(); -@cmds = &list_commands(); -$cmd = $cmds[$in{'idx'}]; +$cmd = &get_command($in{'id'}, $in{'idx'}); &can_run_command($cmd) || &error($text{'form_ecannot'}); # Display form for command parameters @@ -21,7 +20,7 @@ elsif (@a) { else { print &ui_form_start("sql.cgi"); } -print &ui_hidden("idx", $in{'idx'}); +print &ui_hidden("id", $cmd->{'id'}); print &ui_table_start(&html_escape($cmd->{'desc'}), "width=100%", 4, [ "width=20%", "width=30%", "width=20%", "width=30%" ]); print &ui_table_row(undef, $cmd->{'html'}, 4); diff --git a/custom/view.cgi b/custom/view.cgi index 594638742..b7330a523 100755 --- a/custom/view.cgi +++ b/custom/view.cgi @@ -4,8 +4,7 @@ require './custom-lib.pl'; &ReadParse(); -@cmds = &list_commands(); -$edit = $cmds[$in{'idx'}]; +$edit = &get_command($in{'id'}, $in{'idx'}); $edit->{'edit'} && &can_run_command($edit) || &error($text{'edit_ecannot'}); # Work out proper filename