show unsafe options (RO) by default

Small data leak, but only to admins, and I think it's worth it to see the
stuff that cannot be configured.
master
Joey Hess 2008-08-02 22:46:16 -04:00
parent 5dbd053da3
commit c762b65ce4
10 changed files with 41 additions and 14 deletions

BIN
.IkiWiki.pm.swp 100644

Binary file not shown.

View File

@ -92,7 +92,7 @@ sub getsetup () { #{{{
type => "string",
default => '',
example => "/var/www/wiki/ikiwiki.cgi",
description => "cgi executable to generate",
description => "cgi wrapper to generate",
safe => 0, # file
rebuild => 0,
},

View File

@ -36,7 +36,7 @@ sub getsetup () { #{{{
bzr_wrapper => {
type => "string",
#example => "", # FIXME add example
description => "bzr post-commit executable to generate",
description => "bzr post-commit hook to generate",
safe => 0, # file
rebuild => 0,
},

View File

@ -45,7 +45,7 @@ sub getsetup () { #{{{
git_wrapper => {
type => "string",
example => "/git/wiki.git/hooks/post-update",
description => "git post-update executable to generate",
description => "git post-update hook to generate",
safe => 0, # file
rebuild => 0,
},

View File

@ -36,7 +36,7 @@ sub getsetup () { #{{{
mercurial_wrapper => {
type => "string",
#example => # FIXME add example
description => "mercurial post-commit executable to generate",
description => "mercurial post-commit hook to generate",
safe => 0, # file
rebuild => 0,
},

View File

@ -68,7 +68,7 @@ sub getsetup () { #{{{
mtn_wrapper => {
type => "string",
example => "/srv/mtn/wiki/_MTN/ikiwiki-netsync-hook",
description => "monotone netsync hook executable to generate",
description => "monotone netsync hook to generate",
safe => 0, # file
rebuild => 0,
},

View File

@ -58,7 +58,7 @@ sub getsetup () { #{{{
svn_wrapper => {
type => "string",
example => "/svn/wikirepo/hooks/post-commit",
description => "svn post-commit executable to generate",
description => "svn post-commit hook to generate",
safe => 0, # file
rebuild => 0,
},

View File

@ -34,7 +34,7 @@ sub getsetup () { #{{{
tla_wrapper => {
type => "string",
#example => "", # TODO example
description => "tla post-commit executable to generate",
description => "tla post-commit hook to generate",
safe => 0, # file
rebuild => 0,
},

View File

@ -13,6 +13,7 @@ my @default_force_plugins=(qw{amazon_s3 external});
sub import { #{{{
hook(type => "getsetup", id => "websetup", call => \&getsetup);
hook(type => "checkconfig", id => "websetup", call => \&checkconfig);
hook(type => "sessioncgi", id => "websetup", call => \&sessioncgi);
hook(type => "formbuilder_setup", id => "websetup",
call => \&formbuilder_setup);
@ -27,12 +28,29 @@ sub getsetup () { #{{{
safe => 0,
rebuild => 0,
},
websetup_show_unsafe => {
type => "boolean",
example => 1,
description => "show unsafe settings, read-only, in web interface?",
safe => 0,
rebuild => 0,
},
} #}}}
sub formatexample ($) { #{{{
my $example=shift;
sub checkconfig () { #{{{
if (! exists $config{websetup_show_unsafe}) {
$config{websetup_show_unsafe}=1;
}
} #}}}
if (defined $example && ! ref $example && length $example) {
sub formatexample ($$) { #{{{
my $example=shift;
my $value=shift;
if (defined $value && length $value) {
return "";
}
elsif (defined $example && ! ref $example && length $example) {
return "<br/ ><small>Example: <tt>$example</tt></small>";
}
else {
@ -50,8 +68,10 @@ sub showfields ($$$@) { #{{{
my $key=shift;
my %info=%{shift()};
# skip complex, unsafe, or internal settings
next if ref $config{$key} || ! $info{safe} || $info{type} eq "internal";
# skip complex or internal settings
next if ref $config{$key} || ref $info{example} || $info{type} eq "internal";
# maybe skip unsafe settings
next if ! $info{safe} && ! $config{websetup_show_unsafe};
# these are handled specially, so don't show
next if $key eq 'add_plugins' || $key eq 'disable_plugins';
@ -83,7 +103,7 @@ sub showfields ($$$@) { #{{{
$form->field(
name => $name,
label => $description,
comment => defined $value && length $value ? "" : formatexample($info{example}),
comment => formatexample($info{example}, $value),
type => "text",
value => $value,
size => 60,
@ -94,7 +114,7 @@ sub showfields ($$$@) { #{{{
$form->field(
name => $name,
label => $description,
comment => formatexample($info{example}),
comment => formatexample($info{example}, $value),
type => "text",
value => $value,
size => 60,
@ -106,6 +126,7 @@ sub showfields ($$$@) { #{{{
$form->field(
name => $name,
label => $description,
comment => formatexample($info{example}, $value),
type => "text",
value => $value,
size => 5,
@ -123,6 +144,11 @@ sub showfields ($$$@) { #{{{
fieldset => $section,
);
}
if (! $info{safe}) {
$form->field(name => $name, disabled => 1);
$form->text(gettext("Note: Disabled options cannot be configured here, but only by editing the setup file."));
}
}
return 1;

1
websetup.pm 120000
View File

@ -0,0 +1 @@
/home/joey/src/ikiwiki/IkiWiki/Plugin/websetup.pm