Skip to content

Commit

Permalink
Tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
swelljoe committed Oct 3, 2017
1 parent e4def22 commit c699822
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 93 deletions.
8 changes: 5 additions & 3 deletions delete_jail.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require './jailkit-lib.pl';
ReadParse();

my $jk_init_ini = get_jk_init_ini();
my @sections = $jk_init_ini->Sections();
my @sections = $jk_init_ini->Sections();
my %jail_params;

my @d = split(/\0/, $in{'d'});
Expand All @@ -20,7 +20,7 @@ if (defined $in{'confirmed'}) {
}
else {
# Does this jail exist?
error( text('error_jail_not_found', "$jail", "<br>\n"));
error(text('error_jail_not_found', "$jail", "<br>\n"));
}
}
write_jk_init_ini($jk_init_ini);
Expand All @@ -33,6 +33,7 @@ else {
# Check to be sure we really want these jails gone
print ui_form_start("delete_jail.cgi", "post");
foreach my $jail (@d) {

# Re-send all of the d_* items with a confirmed field
print ui_hidden("d", $jail);
}
Expand All @@ -45,8 +46,9 @@ else {
print "</p>\n";

print ui_hidden("confirmed", "1");

#print ui_submit($text{delete_confirm}, "confirm");
print ui_form_end([ [ "confirm", $text{'delete_confirm'} ] ]);
print ui_form_end([["confirm", $text{'delete_confirm'}]]);
print "</center>\n";
ui_print_footer("");
}
Expand Down
95 changes: 62 additions & 33 deletions edit_jail.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -7,66 +7,95 @@ require './jailkit-lib.pl';
ReadParse();

my $jk_init_ini = get_jk_init_ini();
my @sections = $jk_init_ini->Sections();
my @sections = $jk_init_ini->Sections();
my %jail_params;

# Make a new section?
if($in{'new'}) {
if ($in{'new'}) {
ui_print_header(undef, $text{'index_create_jail'}, '', 'create_jail');

# Keep new defined so we add a new section on save
print ui_hidden("new", $in{'new'});
}
else {
ui_print_header(undef, $text{'index_edit_jail'}, '', 'edit_jail');
unless ( $jk_init_ini->SectionExists( $in{'jail'} )) {
error( $text{'edit_jail_not_found'} );
};
unless ($jk_init_ini->SectionExists($in{'jail'})) {
error($text{'edit_jail_not_found'});
}

# Populate the jail hash
my @params = $jk_init_ini->Parameters( $in{'jail'} );
foreach my $param (@params){
$jail_params{$param} = $jk_init_ini->val( $in{'jail'}, $param );
my @params = $jk_init_ini->Parameters($in{'jail'});
foreach my $param (@params) {
$jail_params{$param} = $jk_init_ini->val($in{'jail'}, $param);
}
}

print ui_form_start("save_jail.cgi");
print ui_hidden("orig_jail", $in{'jail'});

print ui_
print ui_hidden_table_start($text{'edit_jail_metadata'}, undef, 1, 'metadata', 1);
print ui_hidden_table_start($text{'edit_jail_metadata'}, undef, 1,
'metadata', 1);

# name
print ui_table_row( hlink($text{'edit_jail_name'}, 'name'),
print ui_table_row(hlink($text{'edit_jail_name'}, 'name'),
ui_textbox('jail', $in{'jail'}));

# comment/description
print ui_table_row( hlink($text{'edit_jail_comment'}, 'comment'),
ui_textbox('comment', $jail_params{'comment'}));
print ui_table_row(
hlink($text{'edit_jail_comment'}, 'comment'),
ui_textbox('comment', $jail_params{'comment'})
);
print ui_hidden_table_end('metadata');

print ui_hidden_table_start($text{'edit_jail_includes'}, undef, 1, 'includes', 1);
print ui_hidden_table_start($text{'edit_jail_includes'}, undef, 1, 'includes',
1);

# paths
print ui_table_row( hlink($text{'edit_jail_paths'}, 'paths'),
ui_textarea('paths', $jail_params{'paths'}));
print ui_table_row( hlink($text{'edit_jail_paths_w_owner'}, 'paths_w_owner'),
ui_textarea('paths_w_owner', $jail_params{'paths_w_owner'}));
print ui_table_row( hlink($text{'edit_jail_paths_w_setuid'}, 'paths_w_setuid'),
ui_textarea('paths_w_setuid', $jail_params{'paths_w_setuid'}));
print ui_table_row( hlink($text{'edit_jail_includesections'}, 'includesections'),
ui_textarea('includesections'), $jail_params{'includesections'});
print ui_table_row( hlink($text{'edit_jail_emptydirs'}, 'emptydirs'),
ui_textarea('emptydirs', $jail_params{'emptydirs'}));
print ui_table_row( hlink($text{'edit_jail_devices'}, 'devices'),
ui_textbox('devices', $jail_params{'devices'}));
print ui_table_row( hlink($text{'edit_jail_need_logsocket'}, 'need_logsocket'),
ui_checkbox('need_logsocket', 1,
undef, $jail_params{'need_logsocket'} ? 1 : 0));
print ui_table_row(
hlink($text{'edit_jail_paths'}, 'paths'),
ui_textarea('paths', $jail_params{'paths'})
);
print ui_table_row(
hlink($text{'edit_jail_paths_w_owner'}, 'paths_w_owner'),
ui_textarea('paths_w_owner', $jail_params{'paths_w_owner'})
);
print ui_table_row(
hlink($text{'edit_jail_paths_w_setuid'}, 'paths_w_setuid'),
ui_textarea('paths_w_setuid', $jail_params{'paths_w_setuid'})
);
print ui_table_row(
hlink($text{'edit_jail_includesections'}, 'includesections'),
ui_textarea('includesections'),
$jail_params{'includesections'}
);
print ui_table_row(
hlink($text{'edit_jail_emptydirs'}, 'emptydirs'),
ui_textarea('emptydirs', $jail_params{'emptydirs'})
);
print ui_table_row(
hlink($text{'edit_jail_devices'}, 'devices'),
ui_textbox('devices', $jail_params{'devices'})
);
print ui_table_row(
hlink($text{'edit_jail_need_logsocket'}, 'need_logsocket'),
ui_checkbox(
'need_logsocket', 1, undef, $jail_params{'need_logsocket'} ? 1 : 0
)
);
print ui_hidden_table_end('includes');

print ui_hidden_table_start($text{'edit_jail_ug'}, undef, 1, 'usergroups', 1);
print ui_table_row( hlink($text{'edit_jail_users'}, 'users'),
ui_textarea('users', $jail_params{'users'}));
print ui_table_row( hlink($text{'edit_jail_groups'}, 'groups'),
ui_textarea('groups', $jail_params{'groups'}));
print ui_table_row(
hlink($text{'edit_jail_users'}, 'users'),
ui_textarea('users', $jail_params{'users'})
);
print ui_table_row(
hlink($text{'edit_jail_groups'}, 'groups'),
ui_textarea('groups', $jail_params{'groups'})
);
print ui_hidden_table_end('usergroups');

print ui_form_end([ [undef, $text{'save_jail'}] ]);
print ui_form_end([[undef, $text{'save_jail'}]]);

&ui_print_footer("index.cgi", $text{'edit_jail_return'});
40 changes: 15 additions & 25 deletions index.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,34 @@ my $jk_init_ini = get_jk_init_ini();

my @sections = $jk_init_ini->Sections();

ui_print_header(undef, $text{'index_title'}, "", "index", 1, 1, 0,
undef, undef, undef, undef);
ui_print_header(undef, $text{'index_title'}, "", "index", 1, 1, 0, undef,
undef, undef, undef);

my @table;
foreach my $jail (@sections) {
push(@table, [
{ 'type' => 'checkbox', 'name' => 'd', 'value' => $jail },
"<a href=\"edit_jail.cgi?jail=$jail\">".&html_escape($jail)."</a>",
$jk_init_ini->val("$jail", 'comment')
]);
push(
@table,
[
{'type' => 'checkbox', 'name' => 'd', 'value' => $jail},
"<a href=\"edit_jail.cgi?jail=$jail\">" . &html_escape($jail) . "</a>",
$jk_init_ini->val("$jail", 'comment')
]
);
}

my @buttons;
push(@buttons, [
[ "delete", $text{'index_delete_jail'} ]
]);
push(@buttons, [["delete", $text{'index_delete_jail'}]]);

my @actions;
push(@actions, [
[ "edit_jail.cgi?new=1", $text{'index_create_jail'} ]
]);
push(@actions, [["edit_jail.cgi?new=1", $text{'index_create_jail'}]]);

#use Data::Dumper;
#print "<!-- " . Dumper(@table) . " -->\n";

print ui_form_columns_table(
'delete_jail.cgi',
@buttons,
1,
@actions,
undef,
[ $text{'index_delete'}, $text{'index_jail_id'}, $text{'index_comment'} ],
undef,
\@table,
undef,
1,
$text{'index_jail_list'},
$text{'index_no_jails'}
'delete_jail.cgi', @buttons, 1, @actions, undef,
[$text{'index_delete'}, $text{'index_jail_id'}, $text{'index_comment'}],
undef, \@table, undef, 1, $text{'index_jail_list'}, $text{'index_no_jails'}
);

ui_print_footer("");
76 changes: 44 additions & 32 deletions save_jail.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,60 @@ our %text;
require './jailkit-lib.pl';

my $jk_init_ini = get_jk_init_ini();
my @sections = $jk_init_ini->Sections();
my @sections = $jk_init_ini->Sections();
my %jail_params;

ReadParse();

# If new, create a new section
if (defined $in{'new'}) {
if ( $jk_init_ini->SectionExists( $in{'jail'} )) {
error( $text{'error_jail_exists'} );
}
$jk_init_ini->AddSection( $in{'jail'} );
if ($jk_init_ini->SectionExists($in{'jail'})) {
error($text{'error_jail_exists'});
}
$jk_init_ini->AddSection($in{'jail'});
}
else {
# Not new, make sure we update the name of the jail, if
# changed
if ( defined($in{'orig_jail'}) && defined($in{'jail'}) &&
$in{'orig_jail'} ne $in{'jail'} ) {
$jk_init_ini->DeleteSection($in{'orig_jail'});
$jk_init_ini->AddSection( $in{'jail'});
}
# Not new, make sure we update the name of the jail, if
# changed
if ( defined($in{'orig_jail'})
&& defined($in{'jail'})
&& $in{'orig_jail'} ne $in{'jail'})
{
$jk_init_ini->DeleteSection($in{'orig_jail'});
$jk_init_ini->AddSection($in{'jail'});
}
}

if (length $in{'comment'}) { $jk_init_ini->newval($in{'jail'},
'comment', $in{'comment'}); }
if (length $in{'paths'}) { $jk_init_ini->newval($in{'jail'},
'paths', $in{'paths'}); }
if (length $in{'paths_w_owner'}) { $jk_init_ini->newval($in{'jail'},
'paths_w_owner', $in{'paths_w_owner'}); }
if (length $in{'paths_w_setuid'}) { $jk_init_ini->newval($in{'jail'},
'paths_w_setuid', $in{'paths_w_setuid'}); }
if (length $in{'users'}) { $jk_init_ini->newval($in{'jail'},
'users', $in{'users'}); }
if (length $in{'groups'}) { $jk_init_ini->newval($in{'jail'},
'groups', $in{'groups'}); }
if (length $in{'need_logsocket'}) { $jk_init_ini->newval($in{'jail'},
'need_logsocket', $in{'need_logsocket'}); }
if (length $in{'devices'}) { $jk_init_ini->newval($in{'jail'},
'devices', $in{'devices'}); }
if (length $in{'includesections'}) { $jk_init_ini->newval($in{'jail'},
'includesections', $in{'includesections'}); }
if (length $in{'emptydirs'}) { $jk_init_ini->newval($in{'jail'},
'emptydirs', $in{'emptydirs'}); }
if (length $in{'comment'}) {
$jk_init_ini->newval($in{'jail'}, 'comment', $in{'comment'});
}
if (length $in{'paths'}) {
$jk_init_ini->newval($in{'jail'}, 'paths', $in{'paths'});
}
if (length $in{'paths_w_owner'}) {
$jk_init_ini->newval($in{'jail'}, 'paths_w_owner', $in{'paths_w_owner'});
}
if (length $in{'paths_w_setuid'}) {
$jk_init_ini->newval($in{'jail'}, 'paths_w_setuid', $in{'paths_w_setuid'});
}
if (length $in{'users'}) {
$jk_init_ini->newval($in{'jail'}, 'users', $in{'users'});
}
if (length $in{'groups'}) {
$jk_init_ini->newval($in{'jail'}, 'groups', $in{'groups'});
}
if (length $in{'need_logsocket'}) {
$jk_init_ini->newval($in{'jail'}, 'need_logsocket', $in{'need_logsocket'});
}
if (length $in{'devices'}) {
$jk_init_ini->newval($in{'jail'}, 'devices', $in{'devices'});
}
if (length $in{'includesections'}) {
$jk_init_ini->newval($in{'jail'}, 'includesections', $in{'includesections'});
}
if (length $in{'emptydirs'}) {
$jk_init_ini->newval($in{'jail'}, 'emptydirs', $in{'emptydirs'});
}

# Contributors
#if (defined $in{'contributors'}) {
Expand Down

0 comments on commit c699822

Please sign in to comment.