Skip to content

Commit

Permalink
Mostly functional, delete bug in Authentic
Browse files Browse the repository at this point in the history
  • Loading branch information
swelljoe committed Jan 23, 2017
1 parent 82acd49 commit 6314968
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 93 deletions.
52 changes: 52 additions & 0 deletions delete_jail.cgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/perl
use strict;
use warnings;

our (%text, %in);
require './jailkit-lib.pl';
ReadParse();

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

my @d = split(/\0/, $in{'d'});

# If we've already confirmed go ahead an delete it
if (defined $in{'confirmed'}) {
foreach my $jail (@d) {
if ($jk_init_ini->SectionExists($jail)) {
$jk_init_ini->DeleteSection($jail);
}
else {
# Does this jail exist?
error( text('error_jail_not_found', "$jail", "<br>\n"));
}
}
write_jk_init_ini($jk_init_ini);
redirect('');
}
else {
ui_print_header(undef, $text{'index_delete_jail'}, "");
print "<center>\n";

# 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);
}

print $text{'delete_are_you_sure'};
print "<p>\n";
foreach my $del_jail (@d) {
print "<i>$del_jail</i><br>\n";
}
print "</p>\n";

print ui_hidden("confirmed", "1");
#print ui_submit($text{delete_confirm}, "confirm");
print ui_form_end([ [ "confirm", $text{'delete_confirm'} ] ]);
print "</center>\n";
print "</div>\n";
}
65 changes: 65 additions & 0 deletions edit_jail.cgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/perl
use strict;
use warnings;

our (%text, %in);
require './jailkit-lib.pl';
ReadParse();

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

# Make a new section?
if($in{'new'}) {
ui_print_header(undef, $text{'index_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'}, "");
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 );
}
}

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

print ui_table_start( $text{'jail_detail'}, undef, 2);

# name
print ui_table_row( $text{'edit_jail_name'},
ui_textbox('jail', $in{'jail'}));
# comment/description
print ui_table_row( $text{'edit_jail_comment'},
ui_textbox('comment', $jail_params{'comment'}));
# paths
print ui_table_row( $text{'edit_jail_paths'},
ui_textarea('paths', $jail_params{'paths'}));
print ui_table_row( $text{'edit_jail_paths_w_owner'},
ui_textarea('paths_w_owner', $jail_params{'paths_w_owner'}));
print ui_table_row( $text{'edit_jail_users'},
ui_textarea('users', $jail_params{'users'}));
print ui_table_row( $text{'edit_jail_groups'},
ui_textarea('groups', $jail_params{'groups'}));
print ui_table_row( $text{'edit_jail_includesections'},
ui_textarea('includesections'), $jail_params{'includesections'});
print ui_table_row( $text{'edit_jail_emptydirs'},
ui_textbox('emptydirs', $jail_params{'emptydirs'}));
print ui_table_row( $text{'edit_jail_devices'},
ui_textbox('devices', $jail_params{'devices'}));
print ui_table_row( $text{'edit_jail_need_logsocket'},
ui_checkbox('need_logsocket', 1,
undef, $jail_params{'need_logsocket'} ? 1 : 0));

print ui_table_end();

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

&ui_print_footer("index.cgi", $text{'edit_jail_return'});
39 changes: 24 additions & 15 deletions index.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ use strict;

our %text;

require 'jailkit-lib.pl';
require './jailkit-lib.pl';

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);

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

Expand All @@ -29,14 +30,22 @@ push(@buttons, [

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

use Data::Dumper;
print "<!-- " . Dumper($jk_init_ini) . " -->\n";

print "<!-- " . Dumper(get_jk_init_ini()) . " -->\n";

ui_form_columns_table('delete_jk_init.cgi', @buttons, 1, @actions, \@table);

ui_print_footer("/", $text{'index'});
#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);

ui_print_footer("");
16 changes: 9 additions & 7 deletions jailkit-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use warnings;
use Error qw(:try);

our %config;
our (%config, %text);

=head1 jailkit-lib.pl
Expand All @@ -29,11 +29,10 @@ =head2 get_jk_init_ini()
=cut

sub get_jk_init_ini {
use Config::Simple;
use Config::IniFiles;

my $jk_init_ini = new Config::Simple('/etc/jailkit/jk_init.ini');
#"$config{'jailkit_config_dir'}/$config{'jk_init_ini'}");
return \%$jk_init_ini;
my $jk_init_ini = new Config::IniFiles( -file=>'/etc/jailkit/jk_init.ini');
return $jk_init_ini;
}

=head2 write_jk_init_ini(\%jk_init_ini)
Expand All @@ -43,9 +42,12 @@ =head2 write_jk_init_ini(\%jk_init_ini)
=cut

sub write_jk_init_ini {
use Config::INI::Writer;
use Config::IniFiles;
my ($jk_init_ini) = @_;
Config::INI::Writer->write_file($jk_init_ini, $config{'jk_init_ini'});
my $result = $jk_init_ini->RewriteConfig($config{'jk_init_ini'});
unless ($result) {
error($text{'error_save_failed'});
}
return;
}

Expand Down
29 changes: 27 additions & 2 deletions lang/en
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
index_title=Jailkit

index_delete=Delete
index_jail_id=Jail ID
index_commment=Comment
index_jails=Available Jails
index_create_jail=Create a new Jail configuration
index_create_jail=Create a new jail
index_delete_jail=Delete selected
index_initialize=Initialize Jail for user
index_initialize=Initialize jail for user
index_edit_jail=Edit Jail
index_comment=Comment

edit_jail_return=Return to jail list
edit_jail_not_found=That jail doesn't exist!
edit_jail_name=Jail ID
edit_jail_comment=Comment
edit_jail_paths=Paths to include in Jail
edit_jail_paths_w_owner=Paths to include (keep ownership)
edit_jail_users=Users to include in passwd
edit_jail_groups=Groups to include in passwd
edit_jail_need_logsocket=Log socket required?
edit_jail_includesections=Other jails to inherit from
edit_jail_emptydirs=Empty directories to create in jail
edit_jail_devices=Devices to create in jail

save_jail=Save Jail

error_save_failed=Saving jail failed
error_jail_exists=Jail already exists!
error_jail_not_found=Jail named $1 doesn't exist!

delete_are_you_sure=Are you sure you want to delete the following jail(s)? This action cannot be undone.
delete_confirm=Delete
64 changes: 64 additions & 0 deletions save_jail.cgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/perl
# save_config.cgi
# Write updated settings.ini for bloctweet
use warnings;
use strict;

our %in;
our %text;

require './jailkit-lib.pl';

my $jk_init_ini = get_jk_init_ini();
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'} );
}
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'});
}
}

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{'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'}) {
# my @contributors = split(' ', $in{'contributors'});
# foreach my $contributor (@contributors) {
# $bloctweet_config->{'contributors'}{$contributor} = '0';
# }
#}

write_jk_init_ini($jk_init_ini);

redirect('');
69 changes: 0 additions & 69 deletions save_jk_init.cgi

This file was deleted.

0 comments on commit 6314968

Please sign in to comment.