mirror of
https://github.com/webmin/webmin.git
synced 2026-02-03 14:13:29 +00:00
Link by ids rather than indexes
This commit is contained in:
@@ -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.
|
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 ----
|
---- Changes since 1.400 ----
|
||||||
Added a popup progress tracker to commands with file upload fields.
|
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.
|
||||||
|
|||||||
@@ -101,6 +101,22 @@ closedir(DIR);
|
|||||||
return @rv;
|
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)
|
# save_command(&command)
|
||||||
sub save_command
|
sub save_command
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,14 +11,13 @@ if ($in{'new'}) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
&ui_print_header(undef, $text{'edit_title'}, "", "edit");
|
&ui_print_header(undef, $text{'edit_title'}, "", "edit");
|
||||||
@cmds = &list_commands();
|
$cmd = &get_command($in{'id'}, $in{'idx'});
|
||||||
$cmd = $cmds[$in{'idx'}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Form header
|
# Form header
|
||||||
print &ui_form_start("save_cmd.cgi", "post");
|
print &ui_form_start("save_cmd.cgi", "post");
|
||||||
print &ui_hidden("new", $in{'new'});
|
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);
|
print &ui_table_start($text{'edit_details'}, "width=100%", 4);
|
||||||
|
|
||||||
# Command ID
|
# Command ID
|
||||||
|
|||||||
@@ -11,13 +11,12 @@ if ($in{'new'}) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
&ui_print_header(undef, $text{'fedit_title'}, "", "fedit");
|
&ui_print_header(undef, $text{'fedit_title'}, "", "fedit");
|
||||||
@cmds = &list_commands();
|
$edit = &get_command($in{'id'}, $in{'idx'});
|
||||||
$edit = $cmds[$in{'idx'}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print &ui_form_start("save_file.cgi", "post");
|
print &ui_form_start("save_file.cgi", "post");
|
||||||
print &ui_hidden("new", $in{'new'});
|
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);
|
print &ui_table_start($text{'file_details'}, "width=100%", 2);
|
||||||
|
|
||||||
if (!$in{'new'}) {
|
if (!$in{'new'}) {
|
||||||
|
|||||||
@@ -26,13 +26,12 @@ if ($in{'new'}) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
&ui_print_header(undef, $text{'sql_title2'}, "");
|
&ui_print_header(undef, $text{'sql_title2'}, "");
|
||||||
@cmds = &list_commands();
|
$cmd = &get_command($in{'id'}, $in{'idx'});
|
||||||
$cmd = $cmds[$in{'idx'}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print &ui_form_start("save_sql.cgi", "post");
|
print &ui_form_start("save_sql.cgi", "post");
|
||||||
print &ui_hidden("new", $in{'new'}),"\n";
|
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);
|
print &ui_table_start($text{'sql_header'}, "width=100%", 2);
|
||||||
|
|
||||||
# Show command info
|
# Show command info
|
||||||
|
|||||||
@@ -4,8 +4,7 @@
|
|||||||
|
|
||||||
require './custom-lib.pl';
|
require './custom-lib.pl';
|
||||||
&ReadParse();
|
&ReadParse();
|
||||||
@cmds = &list_commands();
|
$cmd = &get_command($in{'id'}, $in{'idx'});
|
||||||
$cmd = $cmds[$in{'idx'}];
|
|
||||||
&can_run_command($cmd) || &error($text{'form_ecannot'});
|
&can_run_command($cmd) || &error($text{'form_ecannot'});
|
||||||
|
|
||||||
# Display form for command parameters
|
# Display form for command parameters
|
||||||
@@ -29,7 +28,7 @@ elsif (@a) {
|
|||||||
else {
|
else {
|
||||||
print &ui_form_start("run.cgi");
|
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,
|
print &ui_table_start(&html_escape($cmd->{'desc'}), "width=100%", 4,
|
||||||
[ "width=20%", "width=30%", "width=20%", "width=30%" ]);
|
[ "width=20%", "width=30%", "width=20%", "width=30%" ]);
|
||||||
print &ui_table_row(undef, $cmd->{'html'}, 4) if ($cmd->{'html'});
|
print &ui_table_row(undef, $cmd->{'html'}, 4) if ($cmd->{'html'});
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ elsif ($config{'display_mode'} == 0) {
|
|||||||
$html .= &ui_form_start("run.cgi");
|
$html .= &ui_form_start("run.cgi");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$html .= &ui_hidden("idx", $c->{'index'});
|
$html .= &ui_hidden("id", $c->{'id'});
|
||||||
$w = $config{'columns'} == 2 ? 2 : 4;
|
$w = $config{'columns'} == 2 ? 2 : 4;
|
||||||
$html .= &ui_table_start(undef, undef, $w,
|
$html .= &ui_table_start(undef, undef, $w,
|
||||||
$config{'columns'} == 1 ? [ "width=20%", "width=30%" ]
|
$config{'columns'} == 1 ? [ "width=20%", "width=30%" ]
|
||||||
@@ -72,13 +72,13 @@ elsif ($config{'display_mode'} == 0) {
|
|||||||
}
|
}
|
||||||
if ($access{'edit'}) {
|
if ($access{'edit'}) {
|
||||||
if ($c->{'edit'}) {
|
if ($c->{'edit'}) {
|
||||||
$link = "<a href='edit_file.cgi?idx=$c->{'index'}'>$text{'index_fedit'}</a>";
|
$link = "<a href='edit_file.cgi?id=$c->{'id'}'>$text{'index_fedit'}</a>";
|
||||||
}
|
}
|
||||||
elsif ($c->{'sql'}) {
|
elsif ($c->{'sql'}) {
|
||||||
$link = "<a href='edit_sql.cgi?idx=$c->{'index'}'>$text{'index_sedit'}</a>";
|
$link = "<a href='edit_sql.cgi?id=$c->{'id'}'>$text{'index_sedit'}</a>";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$link = "<a href='edit_cmd.cgi?idx=$c->{'index'}'>$text{'index_edit'}</a>";
|
$link = "<a href='edit_cmd.cgi?id=$c->{'id'}'>$text{'index_edit'}</a>";
|
||||||
}
|
}
|
||||||
$html .= &ui_table_row(undef,
|
$html .= &ui_table_row(undef,
|
||||||
&ui_links_row([ $link ]), $w);
|
&ui_links_row([ $link ]), $w);
|
||||||
@@ -107,42 +107,42 @@ else {
|
|||||||
local $e = $c->{'edit'} ? "edit_file.cgi" :
|
local $e = $c->{'edit'} ? "edit_file.cgi" :
|
||||||
$c->{'sql'} ? "edit_sql.cgi" :
|
$c->{'sql'} ? "edit_sql.cgi" :
|
||||||
"edit_cmd.cgi";
|
"edit_cmd.cgi";
|
||||||
push(@links, "<a href='$e?idx=$c->{'index'}'>".
|
push(@links, "<a href='$e?id=$c->{'id'}'>".
|
||||||
"$text{'index_ed'}</a>");
|
"$text{'index_ed'}</a>");
|
||||||
}
|
}
|
||||||
if ($c->{'edit'} && !@{$c->{'args'}}) {
|
if ($c->{'edit'} && !@{$c->{'args'}}) {
|
||||||
# Open file editor directly, as file is known
|
# Open file editor directly, as file is known
|
||||||
push(@cols, "<a href='view.cgi?idx=$c->{'index'}'>".
|
push(@cols, "<a href='view.cgi?id=$c->{'id'}'>".
|
||||||
&html_escape($c->{'desc'})."</a>");
|
&html_escape($c->{'desc'})."</a>");
|
||||||
push(@links, "<a href='view.cgi?idx=$c->{'index'}'>".
|
push(@links, "<a href='view.cgi?id=$c->{'id'}'>".
|
||||||
$text{'index_acted'}."</a>");
|
$text{'index_acted'}."</a>");
|
||||||
}
|
}
|
||||||
elsif ($c->{'sql'} && !@{$c->{'args'}}) {
|
elsif ($c->{'sql'} && !@{$c->{'args'}}) {
|
||||||
# Execute SQL directorly, as no args
|
# Execute SQL directorly, as no args
|
||||||
push(@cols, "<a href='sql.cgi?idx=$c->{'index'}'>".
|
push(@cols, "<a href='sql.cgi?id=$c->{'id'}'>".
|
||||||
&html_escape($c->{'desc'})."</a>");
|
&html_escape($c->{'desc'})."</a>");
|
||||||
push(@links, "<a href='sql.cgi?idx=$c->{'index'}'>".
|
push(@links, "<a href='sql.cgi?id=$c->{'id'}'>".
|
||||||
$text{'index_actrun'}."</a>");
|
$text{'index_actrun'}."</a>");
|
||||||
}
|
}
|
||||||
elsif ($c->{'sql'}) {
|
elsif ($c->{'sql'}) {
|
||||||
# Link to SQL query form
|
# Link to SQL query form
|
||||||
push(@cols, "<a href='sqlform.cgi?idx=$c->{'index'}'>".
|
push(@cols, "<a href='sqlform.cgi?id=$c->{'id'}'>".
|
||||||
&html_escape($c->{'desc'})."</a>");
|
&html_escape($c->{'desc'})."</a>");
|
||||||
push(@links, "<a href='sqlform.cgi?idx=$c->{'index'}'>".
|
push(@links, "<a href='sqlform.cgi?id=$c->{'id'}'>".
|
||||||
$text{'index_actsql'}."</a>");
|
$text{'index_actsql'}."</a>");
|
||||||
}
|
}
|
||||||
elsif (!@{$c->{'args'}}) {
|
elsif (!@{$c->{'args'}}) {
|
||||||
# Link direct to execute page
|
# Link direct to execute page
|
||||||
push(@cols, "<a href='run.cgi?idx=$c->{'index'}'>".
|
push(@cols, "<a href='run.cgi?id=$c->{'id'}'>".
|
||||||
&html_escape($c->{'desc'})."</a>");
|
&html_escape($c->{'desc'})."</a>");
|
||||||
push(@links, "<a href='run.cgi?idx=$c->{'index'}'>".
|
push(@links, "<a href='run.cgi?id=$c->{'id'}'>".
|
||||||
$text{'index_actrun'}."</a>");
|
$text{'index_actrun'}."</a>");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# Link to parameters form
|
# Link to parameters form
|
||||||
push(@cols, "<a href='form.cgi?idx=$c->{'index'}'>".
|
push(@cols, "<a href='form.cgi?id=$c->{'id'}'>".
|
||||||
&html_escape($c->{'desc'})."</a>");
|
&html_escape($c->{'desc'})."</a>");
|
||||||
push(@links, "<a href='form.cgi?idx=$c->{'index'}'>".
|
push(@links, "<a href='form.cgi?id=$c->{'id'}'>".
|
||||||
$text{'index_actform'}."</a>");
|
$text{'index_actform'}."</a>");
|
||||||
}
|
}
|
||||||
push(@cols, $c->{'html'});
|
push(@cols, $c->{'html'});
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ else {
|
|||||||
}
|
}
|
||||||
$| = 1;
|
$| = 1;
|
||||||
&error_setup($text{'run_err'});
|
&error_setup($text{'run_err'});
|
||||||
@cmds = &list_commands();
|
$cmd = &get_command($in{'id'}, $in{'idx'});
|
||||||
$cmd = $cmds[$in{'idx'}];
|
|
||||||
&can_run_command($cmd) || &error($text{'run_ecannot'});
|
&can_run_command($cmd) || &error($text{'run_ecannot'});
|
||||||
if (&supports_users()) {
|
if (&supports_users()) {
|
||||||
$user = $cmd->{'user'} eq '*' ? $remote_user : $cmd->{'user'};
|
$user = $cmd->{'user'} eq '*' ? $remote_user : $cmd->{'user'};
|
||||||
|
|||||||
@@ -4,8 +4,7 @@
|
|||||||
|
|
||||||
require './custom-lib.pl';
|
require './custom-lib.pl';
|
||||||
&ReadParseMime();
|
&ReadParseMime();
|
||||||
@cmds = &list_commands();
|
$edit = &get_command($in{'id'}, $in{'idx'});
|
||||||
$edit = $cmds[$in{'idx'}];
|
|
||||||
&error_setup($text{'view_err'});
|
&error_setup($text{'view_err'});
|
||||||
$edit->{'edit'} && &can_run_command($edit) || &error($text{'edit_ecannot'});
|
$edit->{'edit'} && &can_run_command($edit) || &error($text{'edit_ecannot'});
|
||||||
|
|
||||||
|
|||||||
@@ -6,16 +6,15 @@ require './custom-lib.pl';
|
|||||||
&ReadParse();
|
&ReadParse();
|
||||||
|
|
||||||
$access{'edit'} || &error($text{'save_ecannot'});
|
$access{'edit'} || &error($text{'save_ecannot'});
|
||||||
@cmds = &list_commands();
|
|
||||||
if ($in{'delete'}) {
|
if ($in{'delete'}) {
|
||||||
$cmd = $cmds[$in{'idx'}];
|
$cmd = &get_command($in{'id'}, $in{'idx'});
|
||||||
&delete_command($cmd);
|
&delete_command($cmd);
|
||||||
&webmin_log("delete", "command", $cmd->{'id'}, $cmd);
|
&webmin_log("delete", "command", $cmd->{'id'}, $cmd);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
&error_setup($text{'save_err'});
|
&error_setup($text{'save_err'});
|
||||||
if (!$in{'new'}) {
|
if (!$in{'new'}) {
|
||||||
$cmd = $cmds[$in{'idx'}];
|
$cmd = &get_command($in{'id'}, $in{'idx'});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$cmd = { 'id' => time() };
|
$cmd = { 'id' => time() };
|
||||||
|
|||||||
@@ -6,16 +6,15 @@ require './custom-lib.pl';
|
|||||||
&ReadParse();
|
&ReadParse();
|
||||||
|
|
||||||
$access{'edit'} || &error($text{'file_ecannot'});
|
$access{'edit'} || &error($text{'file_ecannot'});
|
||||||
@cmds = &list_commands();
|
|
||||||
if ($in{'delete'}) {
|
if ($in{'delete'}) {
|
||||||
$edit = $cmds[$in{'idx'}];
|
$edit = &get_command($in{'id'}, $in{'idx'});
|
||||||
&delete_command($edit);
|
&delete_command($edit);
|
||||||
&webmin_log("delete", "edit", $edit->{'id'}, $edit);
|
&webmin_log("delete", "edit", $edit->{'id'}, $edit);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
&error_setup($text{'file_err'});
|
&error_setup($text{'file_err'});
|
||||||
if (!$in{'new'}) {
|
if (!$in{'new'}) {
|
||||||
$edit = $cmds[$in{'idx'}];
|
$edit = &get_command($in{'id'}, $in{'idx'});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$edit = { 'id' => time() };
|
$edit = { 'id' => time() };
|
||||||
|
|||||||
@@ -5,16 +5,15 @@ require './custom-lib.pl';
|
|||||||
&ReadParse();
|
&ReadParse();
|
||||||
|
|
||||||
$access{'edit'} || &error($text{'save_ecannot'});
|
$access{'edit'} || &error($text{'save_ecannot'});
|
||||||
@cmds = &list_commands();
|
|
||||||
if ($in{'delete'}) {
|
if ($in{'delete'}) {
|
||||||
$cmd = $cmds[$in{'idx'}];
|
$cmd = &get_command($in{'id'}, $in{'idx'});
|
||||||
&delete_command($cmd);
|
&delete_command($cmd);
|
||||||
&webmin_log("delete", "command", $cmd->{'id'}, $cmd);
|
&webmin_log("delete", "command", $cmd->{'id'}, $cmd);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
&error_setup($text{'sql_err'});
|
&error_setup($text{'sql_err'});
|
||||||
if (!$in{'new'}) {
|
if (!$in{'new'}) {
|
||||||
$cmd = $cmds[$in{'idx'}];
|
$cmd = &get_command($in{'id'}, $in{'idx'});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$cmd = { 'id' => time() };
|
$cmd = { 'id' => time() };
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ else {
|
|||||||
&ReadParse();
|
&ReadParse();
|
||||||
}
|
}
|
||||||
&error_setup($text{'srun_err'});
|
&error_setup($text{'srun_err'});
|
||||||
@cmds = &list_commands();
|
$cmd = &get_command($in{'id'}, $in{'idx'});
|
||||||
$cmd = $cmds[$in{'idx'}];
|
|
||||||
&can_run_command($cmd) || &error($text{'run_ecannot'});
|
&can_run_command($cmd) || &error($text{'run_ecannot'});
|
||||||
|
|
||||||
# Connect to the DB
|
# Connect to the DB
|
||||||
|
|||||||
@@ -4,8 +4,7 @@
|
|||||||
|
|
||||||
require './custom-lib.pl';
|
require './custom-lib.pl';
|
||||||
&ReadParse();
|
&ReadParse();
|
||||||
@cmds = &list_commands();
|
$cmd = &get_command($in{'id'}, $in{'idx'});
|
||||||
$cmd = $cmds[$in{'idx'}];
|
|
||||||
&can_run_command($cmd) || &error($text{'form_ecannot'});
|
&can_run_command($cmd) || &error($text{'form_ecannot'});
|
||||||
|
|
||||||
# Display form for command parameters
|
# Display form for command parameters
|
||||||
@@ -21,7 +20,7 @@ elsif (@a) {
|
|||||||
else {
|
else {
|
||||||
print &ui_form_start("sql.cgi");
|
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,
|
print &ui_table_start(&html_escape($cmd->{'desc'}), "width=100%", 4,
|
||||||
[ "width=20%", "width=30%", "width=20%", "width=30%" ]);
|
[ "width=20%", "width=30%", "width=20%", "width=30%" ]);
|
||||||
print &ui_table_row(undef, $cmd->{'html'}, 4);
|
print &ui_table_row(undef, $cmd->{'html'}, 4);
|
||||||
|
|||||||
@@ -4,8 +4,7 @@
|
|||||||
|
|
||||||
require './custom-lib.pl';
|
require './custom-lib.pl';
|
||||||
&ReadParse();
|
&ReadParse();
|
||||||
@cmds = &list_commands();
|
$edit = &get_command($in{'id'}, $in{'idx'});
|
||||||
$edit = $cmds[$in{'idx'}];
|
|
||||||
$edit->{'edit'} && &can_run_command($edit) || &error($text{'edit_ecannot'});
|
$edit->{'edit'} && &can_run_command($edit) || &error($text{'edit_ecannot'});
|
||||||
|
|
||||||
# Work out proper filename
|
# Work out proper filename
|
||||||
|
|||||||
Reference in New Issue
Block a user