From 46f33976efe1d8616ee325c924b002bd06dc7c15 Mon Sep 17 00:00:00 2001
From: Joe Cooper
Date: Mon, 2 Oct 2017 19:04:29 -0500
Subject: [PATCH 1/3] Syntax/strict tests
---
install_check.pl | 3 +++
jailkit-lib.pl | 1 -
t/all_ok.t | 6 ++++++
3 files changed, 9 insertions(+), 1 deletion(-)
create mode 100644 t/all_ok.t
diff --git a/install_check.pl b/install_check.pl
index 03b3aa1..6c1bff7 100644
--- a/install_check.pl
+++ b/install_check.pl
@@ -1,5 +1,8 @@
# install_check.pl
+use strict;
+use warnings;
+our %config;
do 'jailkit-lib.pl';
# is_installed(mode)
diff --git a/jailkit-lib.pl b/jailkit-lib.pl
index 99c7593..82de1eb 100644
--- a/jailkit-lib.pl
+++ b/jailkit-lib.pl
@@ -1,5 +1,4 @@
#!/usr/bin/perl
-
use strict;
use warnings;
diff --git a/t/all_ok.t b/t/all_ok.t
new file mode 100644
index 0000000..1dcc3df
--- /dev/null
+++ b/t/all_ok.t
@@ -0,0 +1,6 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::Strict 'no_plan';
+
+all_perl_files_ok();
From e4def22486bd7d7e2a431ad3af6d13f0f7d0a905 Mon Sep 17 00:00:00 2001
From: Joe Cooper
Date: Mon, 2 Oct 2017 19:07:07 -0500
Subject: [PATCH 2/3] perltidy
---
.perltidyrc | 13 +++++++++++++
install_check.pl | 10 +++++-----
jailkit-lib.pl | 23 ++++++++++++-----------
3 files changed, 30 insertions(+), 16 deletions(-)
create mode 100644 .perltidyrc
diff --git a/.perltidyrc b/.perltidyrc
new file mode 100644
index 0000000..fc877be
--- /dev/null
+++ b/.perltidyrc
@@ -0,0 +1,13 @@
+-pbp # Start with Perl Best Practices
+-nst # Non-standard output (allow operate in-place)
+-w # Show all warnings
+-iob # Ignore old breakpoints
+-l=80 # 80 characters per line
+-mbl=2 # No more than 2 blank lines
+-i=2 # Indentation is 2 columns
+-ci=2 # Continuation indentation is 2 columns
+-vt=0 # Less vertical tightness
+-pt=2 # High parenthesis tightness
+-bt=2 # High brace tightness
+-sbt=2 # High square bracket tightness
+-isbc # Don't indent comments without leading space
diff --git a/install_check.pl b/install_check.pl
index 6c1bff7..e3fc16d 100644
--- a/install_check.pl
+++ b/install_check.pl
@@ -9,10 +9,10 @@
# For mode 1, returns 2 if the server is installed and configured for use by
# Webmin, 1 if installed but not configured, or 0 otherwise.
# For mode 0, returns 1 if installed, 0 if not
-sub is_installed
-{
-my ($mode) = @_;
+sub is_installed {
+ my ($mode) = @_;
+
# Available config file in the default location?
-return 0 if (!-r $config{'jailkit_init_ini'});
-return $mode ? 2 : 0;
+ return 0 if (!-r $config{'jailkit_init_ini'});
+ return $mode ? 2 : 0;
}
diff --git a/jailkit-lib.pl b/jailkit-lib.pl
index 82de1eb..61420f1 100644
--- a/jailkit-lib.pl
+++ b/jailkit-lib.pl
@@ -16,7 +16,7 @@ =head1 jailkit-lib.pl
=cut
-BEGIN { push(@INC, ".."); };
+BEGIN { push(@INC, ".."); }
use WebminCore;
init_config();
@@ -27,10 +27,11 @@ =head2 get_jk_init_ini()
=cut
sub get_jk_init_ini {
- use Config::IniFiles;
+ use Config::IniFiles;
- my $jk_init_ini = new Config::IniFiles( -file=>"$config{'jailkit_config_dir'}/jk_init.ini" );
- return $jk_init_ini;
+ my $jk_init_ini = new Config::IniFiles(
+ -file => "$config{'jailkit_config_dir'}/jk_init.ini");
+ return $jk_init_ini;
}
=head2 write_jk_init_ini(\%jk_init_ini)
@@ -40,13 +41,13 @@ =head2 write_jk_init_ini(\%jk_init_ini)
=cut
sub write_jk_init_ini {
- use Config::IniFiles;
- my ($jk_init_ini) = @_;
- my $result = $jk_init_ini->RewriteConfig($config{'jk_init_ini'});
- unless ($result) {
- error($text{'error_save_failed'});
- }
- return;
+ use Config::IniFiles;
+ my ($jk_init_ini) = @_;
+ my $result = $jk_init_ini->RewriteConfig($config{'jk_init_ini'});
+ unless ($result) {
+ error($text{'error_save_failed'});
+ }
+ return;
}
1;
From c6998225ffdf130b6f065c77466436fb94c337bd Mon Sep 17 00:00:00 2001
From: Joe Cooper
Date: Mon, 2 Oct 2017 19:09:04 -0500
Subject: [PATCH 3/3] Tidy
---
delete_jail.cgi | 8 +++--
edit_jail.cgi | 95 ++++++++++++++++++++++++++++++++-----------------
index.cgi | 40 ++++++++-------------
save_jail.cgi | 76 ++++++++++++++++++++++-----------------
4 files changed, 126 insertions(+), 93 deletions(-)
diff --git a/delete_jail.cgi b/delete_jail.cgi
index 7005feb..5d98a28 100644
--- a/delete_jail.cgi
+++ b/delete_jail.cgi
@@ -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'});
@@ -20,7 +20,7 @@ if (defined $in{'confirmed'}) {
}
else {
# Does this jail exist?
- error( text('error_jail_not_found', "$jail", "
\n"));
+ error(text('error_jail_not_found', "$jail", "
\n"));
}
}
write_jk_init_ini($jk_init_ini);
@@ -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);
}
@@ -45,8 +46,9 @@ else {
print "
\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 "\n";
ui_print_footer("");
}
diff --git a/edit_jail.cgi b/edit_jail.cgi
index b6ed5d6..dffb71f 100644
--- a/edit_jail.cgi
+++ b/edit_jail.cgi
@@ -7,24 +7,26 @@ 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);
}
}
@@ -32,41 +34,68 @@ 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'});
diff --git a/index.cgi b/index.cgi
index d3c2778..f2fa355 100644
--- a/index.cgi
+++ b/index.cgi
@@ -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 },
- "".&html_escape($jail)."",
- $jk_init_ini->val("$jail", 'comment')
- ]);
+ push(
+ @table,
+ [
+ {'type' => 'checkbox', 'name' => 'd', 'value' => $jail},
+ "" . &html_escape($jail) . "",
+ $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 "\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("");
diff --git a/save_jail.cgi b/save_jail.cgi
index 58f9e3f..f6b5eff 100644
--- a/save_jail.cgi
+++ b/save_jail.cgi
@@ -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'}) {