1#!/usr/local/bin/perl 2# index.cgi 3# Display buttons for custom commands from webmin 4 5require './custom-lib.pl'; 6&ui_print_header(undef, $text{'index_title'}, "", undef, 0, 1); 7 8if (!-d $config{'webmin_config'}) { 9 print &text('index_nodir', "<tt>$config{'webmin_config'}</tt>"), 10 "<p>\n"; 11 &ui_print_footer("/", $text{'index'}); 12 exit; 13 } 14 15@cust = grep { &can_run_command($_) } &list_commands(); 16@cust = &sort_commands(@cust); 17 18if (!@cust) { 19 print "<b>$text{'index_none'}</b> <p>\n"; 20 } 21elsif ($config{'display_mode'} == 0) { 22 # Show command buttons 23 @grid = ( ); 24 $form = 0; 25 for($i=0; $i<@cust; $i++) { 26 $c = $cust[$i]; 27 @a = @{$c->{'args'}}; 28 local $html; 29 if ($c->{'edit'}) { 30 $html .= &ui_form_start("view.cgi"); 31 } 32 elsif ($c->{'sql'}) { 33 $html .= &ui_form_start("sql.cgi"); 34 } 35 else { 36 local @up = grep { $_->{'type'} == 10 } @a; 37 if (@up) { 38 # Has upload fields 39 @ufn = map { $_->{'name'} } @up; 40 $upid = time().$$; 41 $html .= &ui_form_start("run.cgi?id=$upid", 42 "form-data", undef, 43 &read_parse_mime_javascript($upid, \@ufn)); 44 } 45 elsif (@a) { 46 $html .= &ui_form_start("run.cgi", "post"); 47 } 48 else { 49 $html .= &ui_form_start("run.cgi"); 50 } 51 } 52 $html .= &ui_hidden("id", $c->{'id'}); 53 $w = $config{'columns'} == 2 ? 2 : 4; 54 $html .= &ui_table_start(undef, undef, $w, 55 $config{'columns'} == 1 ? [ "width=20%", "width=30%" ] 56 : [ "width=30%" ]); 57 $html .= &ui_table_row(undef, &ui_submit($c->{'desc'}), $w, []); 58 if ($c->{'html'}) { 59 $html .= &ui_table_row(undef, 60 &filter_javascript($c->{'html'}), $w, []); 61 } 62 foreach $a (@a) { 63 $html .= &ui_table_row(&html_escape($a->{'desc'}), 64 &show_parameter_input($a, $formno)); 65 } 66 if (scalar(@a)%2 && $w == 4) { 67 # Hack to make spacing nicer 68 $html .= &ui_table_row(" ", " "); 69 } 70 if ($access{'edit'}) { 71 if ($c->{'edit'}) { 72 $link = "<a href='edit_file.cgi?id=$c->{'id'}'>$text{'index_fedit'}</a>"; 73 } 74 elsif ($c->{'sql'}) { 75 $link = "<a href='edit_sql.cgi?id=$c->{'id'}'>$text{'index_sedit'}</a>"; 76 } 77 else { 78 $link = "<a href='edit_cmd.cgi?id=$c->{'id'}'>$text{'index_edit'}</a>"; 79 } 80 $html .= &ui_table_row(undef, 81 &ui_links_row([ $link ]), $w); 82 } 83 $html .= &ui_table_end(); 84 $html .= &ui_form_end(); 85 push(@grid, $html); 86 $form++; 87 } 88 print &ui_grid_table(\@grid, $config{'columns'} || 1, 100, 89 $config{'columns'} == 2 ? [ "width=50%", "width=50%" ] : [ ]); 90 } 91else { 92 # Just show table of commands 93 print &ui_links_row(\@links); 94 @tds = ( "width=30%", "width=60%", "width=10% nowrap" ); 95 print &ui_columns_start([ 96 $text{'index_cmd'}, 97 $text{'index_desc'}, 98 $text{'index_acts'}, 99 ], 100, 0, \@tds); 100 foreach $c (@cust) { 101 @cols = ( ); 102 local @links = ( ); 103 if ($access{'edit'}) { 104 local $e = $c->{'edit'} ? "edit_file.cgi" : 105 $c->{'sql'} ? "edit_sql.cgi" : 106 "edit_cmd.cgi"; 107 push(@links, "<a href='$e?id=$c->{'id'}'>". 108 "$text{'index_ed'}</a>"); 109 } 110 if ($c->{'edit'} && !@{$c->{'args'}}) { 111 # Open file editor directly, as file is known 112 push(@cols, "<a href='view.cgi?id=$c->{'id'}'>". 113 &html_escape($c->{'desc'})."</a>"); 114 push(@links, "<a href='view.cgi?id=$c->{'id'}'>". 115 $text{'index_acted'}."</a>"); 116 } 117 elsif ($c->{'sql'} && !@{$c->{'args'}}) { 118 # Execute SQL directorly, as no args 119 push(@cols, "<a href='sql.cgi?id=$c->{'id'}'>". 120 &html_escape($c->{'desc'})."</a>"); 121 push(@links, "<a href='sql.cgi?id=$c->{'id'}'>". 122 $text{'index_actrun'}."</a>"); 123 } 124 elsif ($c->{'sql'}) { 125 # Link to SQL query form 126 push(@cols, "<a href='sqlform.cgi?id=$c->{'id'}'>". 127 &html_escape($c->{'desc'})."</a>"); 128 push(@links, "<a href='sqlform.cgi?id=$c->{'id'}'>". 129 $text{'index_actsql'}."</a>"); 130 } 131 elsif (!@{$c->{'args'}}) { 132 # Link direct to execute page 133 push(@cols, "<a href='run.cgi?id=$c->{'id'}'>". 134 &html_escape($c->{'desc'})."</a>"); 135 push(@links, "<a href='run.cgi?id=$c->{'id'}'>". 136 $text{'index_actrun'}."</a>"); 137 } 138 else { 139 # Link to parameters form 140 push(@cols, "<a href='form.cgi?id=$c->{'id'}'>". 141 &html_escape($c->{'desc'})."</a>"); 142 push(@links, "<a href='form.cgi?id=$c->{'id'}'>". 143 $text{'index_actform'}."</a>"); 144 } 145 push(@cols, $c->{'html'}); 146 push(@cols, &ui_links_row(\@links)); 147 print &ui_columns_row(\@cols, \@tds); 148 } 149 print &ui_columns_end(); 150} 151 152&ui_print_footer("/", $text{'index'}); 153 154