More ui-lib conversion, system variable searching

This commit is contained in:
Jamie Cameron 2008-01-12 01:36:18 +00:00
parent e2efc5311f
commit be7093b6ba
8 changed files with 132 additions and 97 deletions

View File

@ -62,3 +62,5 @@ Fixed a bug that prevented 'Jump to row' from working properly.
---- Changes since 1.390 ----
The character set to use for MySQL output can now be set on the Module Config page.
When testing if a user can login, no specific database is used in case the user does not have access to the 'mysql' database.
When there are too many databases, huge lists of all databases and tables are not shown on the Table Permissions and Field Permissions pages. Instead, text boxes for entering names are shown.
System variables can now be searched using a new field, making it easier to find the one you want from the large list on some systems.

View File

@ -5,9 +5,19 @@
require './mysql-lib.pl';
&ReadParse();
$access{'perms'} || &error($text{'perms_ecannot'});
if ($in{'table'}) {
if (defined($in{'table'})) {
$in{'db'} =~ /^\S+$/ || &error($text{'cpriv_edb'});
$in{'table'} =~ /^\S+$/ || &error($text{'cpriv_etable'});
&ui_print_header(undef, $text{'cpriv_title1'}, "", "create_cpriv");
($d, $t) = split(/\./, $in{'table'});
if (defined($in{'db'})) {
# From two fields
$d = $in{'db'};
$t = $in{'table'};
}
else {
# From selector
($d, $t) = split(/\./, $in{'table'});
}
}
else {
$d = &execute_sql_safe($master_db, "select * from columns_priv order by table_name,column_name");
@ -18,66 +28,47 @@ else {
&ui_print_header(undef, $text{'cpriv_title2'}, "", "edit_cpriv");
}
print "<form action=save_cpriv.cgi>\n";
print &ui_form_start("save_cpriv.cgi");
if ($in{'table'}) {
print "<input type=hidden name=table value='$in{'table'}'>\n";
print &ui_hidden("table", $in{'table'});
}
else {
print "<input type=hidden name=oldhost value='$u->[0]'>\n";
print "<input type=hidden name=olddb value='$u->[1]'>\n";
print "<input type=hidden name=olduser value='$u->[2]'>\n";
print "<input type=hidden name=oldtable value='$u->[3]'>\n";
print "<input type=hidden name=oldfield value='$u->[4]'>\n";
print &ui_hidden("oldhost", $u->[0]);
print &ui_hidden("olddb", $u->[1]);
print &ui_hidden("olduser", $u->[2]);
print &ui_hidden("oldtable", $u->[3]);
print &ui_hidden("oldfield", $u->[4]);
}
print "<table border>\n";
print "<tr $tb> <td><b>$text{'cpriv_header'}</b></td> </tr>\n";
print "<tr $cb> <td><table>\n";
print &ui_table_start($text{'cpriv_header'}, undef, 2);
print "<tr> <td><b>$text{'cpriv_db'}</b></td>\n";
print "<td><tt>$d</tt></td> </tr>\n";
# Apply to DB and table
print &ui_table_row($text{'cpriv_db'}, "<tt>$d</tt>");
print &ui_table_row($text{'cpriv_table'}, "<tt>$t</tt>");
print "<tr> <td><b>$text{'cpriv_table'}</b></td>\n";
print "<td><tt>$t</tt></td> </tr>\n";
# Table field
print &ui_table_row($text{'cpriv_field'},
&ui_select("field", $in{'table'} ? '' : $u->[4],
[ $in{'table'} ? ( '' ) : ( ),
map { $_->{'field'} } &table_structure($d, $t) ], 1, 0, 1));
print "<tr> <td><b>$text{'cpriv_field'}</b></td>\n";
print "<td><select name=field>\n";
print "<option selected>\n" if ($in{'table'});
foreach $c (&table_structure($d, $t)) {
printf "<option %s>%s\n",
$u->[4] eq $c->{'field'} ? 'selected' : '',
$c->{'field'};
}
print "</select></td> </tr>\n";
# Apply to user
print &ui_table_row($text{'cpriv_user'},
&ui_opt_textbox("user", $u->[2], 20, $text{'cpriv_anon'}));
print "<tr> <td><b>$text{'cpriv_user'}</b></td> <td>\n";
printf "<input type=radio name=user_def value=1 %s> %s\n",
$u->[2] ? '' : 'checked', $text{'cpriv_anon'};
printf "<input type=radio name=user_def value=0 %s>\n",
$u->[2] ? 'checked' : '';
print "<input name=user size=20 value='$u->[2]'></td> </tr>\n";
# Apply to host
print &ui_table_row($text{'cpriv_host'},
&ui_opt_textbox("host", $u->[0] eq '%' ? '' : $u->[0], 40,
$text{'cpriv_any'}));
print "<tr> <td><b>$text{'cpriv_host'}</b></td> <td>\n";
printf "<input type=radio name=host_def value=1 %s> %s\n",
$u->[0] eq '%' || $u->[0] eq '' ? 'checked' : '', $text{'cpriv_any'};
printf "<input type=radio name=host_def value=0 %s>\n",
$u->[0] eq '%' || $u->[0] eq '' ? '' : 'checked';
printf "<input name=host size=40 value='%s'></td> </tr>\n",
$u->[0] eq '%' ? '' : $u->[0];
# Permissions to grant
print &ui_table_row($text{'cpriv_perms'},
&ui_select("perms", [ split(/,/, $u->[6]) ],
[ 'Select','Insert','Update','References' ], 4, 1));
print "<tr> <td valign=top><b>$text{'cpriv_perms'}</b></td>\n";
print "<td><select multiple size=4 name=perms>\n";
foreach $p ('Select','Insert','Update','References') {
printf "<option %s>%s\n",
$u->[6] =~ /$p/i ? 'selected' : '', $p;
}
print "</select></td> </tr>\n";
print "</table></td></tr></table>\n";
print "<input type=submit value='$text{'save'}'>\n";
if (!$in{'new'}) {
print "<input type=submit name=delete value='$text{'delete'}'>\n";
}
print "</form>\n";
print &ui_table_end();
print &ui_form_end([ $in{'table'} ? ( [ undef, $text{'create'} ] )
: ( [ undef, $text{'save'} ],
[ 'delete', $text{'delete'} ] ) ]);
&ui_print_footer('list_cprivs.cgi', $text{'cprivs_return'},
"", $text{'index_return'});

View File

@ -5,7 +5,8 @@
require './mysql-lib.pl';
&ReadParse();
$access{'perms'} || &error($text{'perms_ecannot'});
if ($in{'db'}) {
if (defined($in{'db'})) {
$in{'db'} =~ /^\S+$/ || &error($text{'tpriv_edb'});
&ui_print_header(undef, $text{'tpriv_title1'}, "", "create_tpriv");
}
else {
@ -35,7 +36,7 @@ print &ui_table_row($text{'tpriv_db'}, $in{'db'} || $u->[1]);
print &ui_table_row($text{'tpriv_table'},
&ui_select("table", $in{'db'} ? '' : $u->[3],
[ $in{'db'} ? ( [ '' ] ) : ( ),
&list_tables($in{'db'} || $u->[1]) ], 1, 0, 1 ]));
&list_tables($in{'db'} || $u->[1]) ], 1, 0, 1));
# Apply to user
print &ui_table_row($text{'tpriv_user'},
@ -60,7 +61,7 @@ print &ui_table_row($text{'tpriv_perms2'},
[ 'Select','Insert','Update','References' ], 4, 1));
print &ui_table_end();
print &ui_form_end([ $in{'new'} ? ( [ undef, $text{'create'} ] )
print &ui_form_end([ $in{'db'} ? ( [ undef, $text{'create'} ] )
: ( [ undef, $text{'save'} ],
[ 'delete', $text{'delete'} ] ) ]);

View File

@ -482,6 +482,7 @@ tpriv_err=Failed to save table permissions
tpriv_etable=No table selected
tpriv_euser=Missing or invalid username
tpriv_ehost=Missing or invalid host
tpriv_edb=Missing or invalid database name
cprivs_title=Field Permissions
cprivs_field=Field
@ -493,6 +494,7 @@ cprivs_privs=Permissions
cprivs_all=All
cprivs_anon=Anonymous
cprivs_add=Add new permissions in database and table :
cprivs_add2=Add new permissions :
cprivs_norows=No field permissions defined
cprivs_return=field permissions
cprivs_none=None
@ -511,9 +513,10 @@ cpriv_perms=Permissions
cpriv_any=Any
cpriv_anon=Anonymous user
cpriv_err=Failed to save field permissions
cpriv_etable=No field selected
cpriv_etable=No table selected
cpriv_euser=Missing or invalid username
cpriv_ehost=Missing or invalid host
cpriv_edb=Missing or invalid database name
esql=SQL $1 failed : $2
eparse=Webmin cannot parse the output from the $1 command due to the nature of data in your database. You will need to install the $2 and $3 Perl modules to solve this problem.
@ -790,6 +793,10 @@ vars_ecannot=You are not allowed to edit system variables
vars_name=Variable name
vars_value=Current value
vars_edit=Edit Selected
vars_search=Show variables matching:
vars_ok=Search
vars_none2=No system variables matched your search.
vars_none=No system variables were found!
compat_ansi=ANSI
compat_mysql323=MySQL 3.2.3

View File

@ -51,17 +51,27 @@ else {
sub show_button
{
print "<form action=edit_cpriv.cgi>\n";
print "<input type=submit value='$text{'cprivs_add'}'>\n";
print "<input type=hidden name=new value=1>\n";
print "<select name=table>\n";
foreach $d (&list_databases()) {
if ($access{'perms'} == 1 || &can_edit_db($d)) {
foreach $t (&list_tables($d)) {
print "<option>$d.$t\n";
print &ui_form_start("edit_cpriv.cgi");
local @opts = ( );
local @dbs = sort { $a cmp $b } &list_databases();
if (@dbs > $max_dbs) {
# Show DB and table fields
print &ui_submit($text{'cprivs_add2'});
print $text{'cprivs_db'}," ",&ui_textbox("db", undef, 20)," ",
$text{'cprivs_table'}," ",&ui_textbox("table", undef, 20);
}
else {
# Show selector
print &ui_submit($text{'cprivs_add'});
foreach $d (@dbs) {
if ($access{'perms'} == 1 || &can_edit_db($d)) {
foreach $t (&list_tables($d)) {
push(@opts, "$d.$t");
}
}
}
print &ui_select("table", undef, \@opts);
}
print "</select></form>\n";
print &ui_form_end();
}

View File

@ -54,8 +54,17 @@ sub show_button
{
print &ui_form_start("edit_tpriv.cgi");
print &ui_submit($text{'tprivs_add'});
print &ui_select("db", undef, [ grep { $access{'perms'} == 1 || &can_edit_db($_) }
&list_databases() ]);
local @dbs = sort { $a cmp $b } &list_databases();
if (@dbs > $max_dbs) {
# Just show DB name
print &ui_textbox("db", undef, 20);
}
else {
# DB selector
print &ui_select("db", undef,
[ grep { $access{'perms'} == 1 || &can_edit_db($_) }
&list_databases() ]);
}
print &ui_form_end();
}

View File

@ -10,36 +10,51 @@ $access{'perms'} == 1 || &error($text{'vars_ecannot'});
# Work out which ones can be edited
%canedit = map { $_->[0], 1 } &list_system_variables();
$d = &execute_sql($master_db, "show variables");
print &ui_form_start("save_vars.cgi");
@tds = ( "width=5" );
print &ui_columns_start([ "",
$text{'vars_name'},
$text{'vars_value'} ], 100, 0, \@tds);
foreach $v (@{$d->{'data'}}) {
if (!$canedit{$v->[0]}) {
# Cannot edit, so just show value
print &ui_columns_row([ "", $v->[0], &html_escape($v->[1]) ],
\@tds);
}
elsif ($d{$v->[0]}) {
# Editing now
print &ui_columns_row([
"->", "<a name=$v->[0]>$v->[0]</a>",
&ui_textbox("value_".$v->[0], $v->[1], 40)
], \@tds);
}
else {
# Can edit
print &ui_checked_columns_row([
"<a name=$v->[0]>$v->[0]</a>",
&html_escape($v->[1])
], \@tds, "d", $v->[0]);
# Show search form
print &ui_form_start("list_vars.cgi");
print "<b>$text{'vars_search'}</b> ",
&ui_textbox("search", $in{'search'}, 20)," ",
&ui_submit($text{'vars_ok'});
print &ui_form_end();
$d = &execute_sql($master_db, "show variables".
($in{'search'} ? " like '%".quotemeta($in{'search'})."%'" : ""));
if (@{$d->{'data'}}) {
print &ui_form_start("save_vars.cgi");
print &ui_hidden("search", $in{'search'});
@tds = ( "width=5" );
print &ui_columns_start([ "",
$text{'vars_name'},
$text{'vars_value'} ], 100, 0, \@tds);
foreach $v (@{$d->{'data'}}) {
if (!$canedit{$v->[0]}) {
# Cannot edit, so just show value
print &ui_columns_row(
[ "", $v->[0], &html_escape($v->[1]) ], \@tds);
}
elsif ($d{$v->[0]}) {
# Editing now
print &ui_columns_row([
"->", "<a name=$v->[0]>$v->[0]</a>",
&ui_textbox("value_".$v->[0], $v->[1], 40)
], \@tds);
}
else {
# Can edit
print &ui_checked_columns_row([
"<a name=$v->[0]>$v->[0]</a>",
&html_escape($v->[1])
], \@tds, "d", $v->[0]);
}
}
print &ui_columns_end();
print &ui_form_end([ [ "edit", $text{'vars_edit'} ],
%d ? ( [ "save", $text{'save'} ] ) : ( ) ]);
}
else {
print "<b>",$in{'search'} ? $text{'vars_none2'}
: $text{'vars_none'},"</b><p>\n";
}
print &ui_columns_end();
print &ui_form_end([ [ "edit", $text{'vars_edit'} ],
%d ? ( [ "save", $text{'save'} ] ) : ( ) ]);
&ui_print_footer("", $text{'index_return'});

View File

@ -18,11 +18,11 @@ if ($in{'save'} || !@d) {
}
}
&webmin_log("set", undef, $count);
&redirect("list_vars.cgi#$first");
&redirect("list_vars.cgi?search=".&urlize($in{'search'})."#$first");
}
else {
# Return to list page, but in edit mode
&redirect("list_vars.cgi?".
&redirect("list_vars.cgi?search=".&urlize($in{'search'})."&".
join("&", map { "d=".&urlize($_) } @d).
"#".$d[0]);
}