diff --git a/delete_jail.cgi b/delete_jail.cgi new file mode 100644 index 0000000..e86d90e --- /dev/null +++ b/delete_jail.cgi @@ -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", "
\n")); + } + } + write_jk_init_ini($jk_init_ini); + redirect(''); +} +else { + ui_print_header(undef, $text{'index_delete_jail'}, ""); + print "
\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 "

\n"; + foreach my $del_jail (@d) { + print "$del_jail
\n"; + } + print "

\n"; + + print ui_hidden("confirmed", "1"); + #print ui_submit($text{delete_confirm}, "confirm"); + print ui_form_end([ [ "confirm", $text{'delete_confirm'} ] ]); + print "
\n"; + print "\n"; +} diff --git a/edit_jail.cgi b/edit_jail.cgi new file mode 100644 index 0000000..6e41013 --- /dev/null +++ b/edit_jail.cgi @@ -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'}); diff --git a/index.cgi b/index.cgi index 43f58c1..5068515 100644 --- a/index.cgi +++ b/index.cgi @@ -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 }, + "".&html_escape($jail)."", + $jk_init_ini->val("$jail", 'comment') ]); } @@ -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 "\n"; - -print "\n"; - -ui_form_columns_table('delete_jk_init.cgi', @buttons, 1, @actions, \@table); - -ui_print_footer("/", $text{'index'}); +#use Data::Dumper; +#print "\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(""); diff --git a/jailkit-lib.pl b/jailkit-lib.pl index 5a69031..1f77cc8 100644 --- a/jailkit-lib.pl +++ b/jailkit-lib.pl @@ -4,7 +4,7 @@ use warnings; use Error qw(:try); -our %config; +our (%config, %text); =head1 jailkit-lib.pl @@ -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) @@ -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; } diff --git a/lang/en b/lang/en index 722cacd..38a9d21 100644 --- a/lang/en +++ b/lang/en @@ -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 diff --git a/save_jail.cgi b/save_jail.cgi new file mode 100644 index 0000000..deab040 --- /dev/null +++ b/save_jail.cgi @@ -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(''); diff --git a/save_jk_init.cgi b/save_jk_init.cgi deleted file mode 100644 index 6d412e3..0000000 --- a/save_jk_init.cgi +++ /dev/null @@ -1,69 +0,0 @@ -#!/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_config = get_jk_init_config(); - -ReadParse(); - -#ui_print_header(undef, $text{'index_title'}, "". undef, 1, 1); - -# Keys -if (defined $in{'keys_access_token_secret'}) { - $bloctweet_config->{'keys'}{'access_token_secret'} = $in{'keys_access_token_secret'}; -} - -if (defined $in{'keys_access_token'}) { - $bloctweet_config->{'keys'}{'access_token'} = $in{'keys_access_token'}; -} - -if (defined $in{'keys_consumer_secret'}) { - $bloctweet_config->{'keys'}{'consumer_secret'} = $in{'keys_consumer_secret'}; -} - -if (defined $in{'keys_consumer_key'}) { - $bloctweet_config->{'keys'}{'consumer_key'} = $in{'keys_consumer_key'}; -} - -# Settings -if (defined $in{'settings_refresh_rate'}) { - $bloctweet_config->{'settings'}{'refresh_rate'} = $in{'settings_refresh_rate'}; -} - -if (defined $in{'settings_dm_refresh_rate'}) { - $bloctweet_config->{'settings'}{'dm_refresh_rate'} = $in{'settings_dm_refresh_rate'}; -} - -if (defined $in{'settings_search_hash'}) { - $bloctweet_config->{'settings'}{'search_hash'} = $in{'settings_search_hash'}; -} - -if (defined $in{'settings_hashtag_enabled'}) { - $bloctweet_config->{'settings'}{'hashtag_enabled'} = $in{'settings_search_hash'}; -} - -if (defined $in{'settings_dm_enabled'}) { - $bloctweet_config->{'settings'}{'dm_enabled'} = $in{'settings_dm_enabled'}; -} - -# Contributors -if (defined $in{'contributors'}) { - my @contributors = split(' ', $in{'contributors'}); - foreach my $contributor (@contributors) { - $bloctweet_config->{'contributors'}{$contributor} = '0'; - } -} - -#Config::INI::Writer->write_file($bloctweet_config, $config{'bloctweet_config'}); -write_bloctweet_config($bloctweet_config); - -redirect(""); -