Skip to content

Commit

Permalink
strict/warn
Browse files Browse the repository at this point in the history
  • Loading branch information
swelljoe committed Jul 1, 2016
1 parent 60b3eed commit 2889c43
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 167 deletions.
4 changes: 4 additions & 0 deletions cgi_args.pl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use strict;
use warnings;
our (%access);
our $module_name;

do 'virtualmin-init-lib.pl';

Expand Down
33 changes: 19 additions & 14 deletions edit.cgi
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#!/usr/local/bin/perl
# Show a page for creating or editing a bootup action associated with
# some domain.
use strict;
use warnings;
our (%text, %in, %config);
our $module_name;

require './virtualmin-init-lib.pl';
&ReadParse();
$d = $in{'dom'} ? &virtual_server::get_domain($in{'dom'}) : undef;
my $d = $in{'dom'} ? &virtual_server::get_domain($in{'dom'}) : undef;
&ui_print_header($d ? &virtual_server::domain_in($d) : undef,
$in{'new'} ? $text{'edit_title1'} : $text{'edit_title2'}, "");

my $init;
my $tmpl;
if (!$in{'new'}) {
# Get the existing action
($init) = grep { $_->{'id'} eq $in{'id'} }
($init) = grep { $_->{'id'} eq $in{'id'} }
&list_domain_actions($d);
$init || &error($text{'edit_egone'});
}
Expand All @@ -34,7 +40,7 @@ print &ui_table_start($text{'edit_header'}, undef, 2);

# Domain selector, if needed
if (!$in{'dom'}) {
@doms = grep { $_->{$module_name} &&
my @doms = grep { $_->{$module_name} &&
&virtual_server::can_edit_domain($_) }
&virtual_server::list_domains();
print &ui_table_row($text{'edit_dom'},
Expand Down Expand Up @@ -77,11 +83,11 @@ if ($tmpl) {
print &ui_table_row($text{'edit_tmpl'}, $tmpl->{'desc'});

# Show parameters
for($i=0; defined($tmpl->{'pname_'.$i}); $i++) {
$tt = $tmpl->{'ptype_'.$i};
$tn = 'param_'.$tmpl->{'pname_'.$i};
$of = $tmpl->{'popts_'.$i};
@opts = $of ? &read_opts_file($of) : ( );
for(my $i=0; defined($tmpl->{'pname_'.$i}); $i++) {
my $tt = $tmpl->{'ptype_'.$i};
my $tn = 'param_'.$tmpl->{'pname_'.$i};
my $of = $tmpl->{'popts_'.$i};
my @opts = $of ? &read_opts_file($of) : ( );
print &ui_table_row($tmpl->{'pdesc_'.$i},
$tt == 0 ? &ui_textbox($tn, undef, 50) :
$tt == 1 ? &ui_textbox($tn, undef, 10) :
Expand All @@ -93,12 +99,12 @@ if ($tmpl) {
}

# Show fixed code for start and stop
$start = $tmpl->{'start'};
my $start = $tmpl->{'start'};
$start = &substitute_template($start, $d) if ($d);
print &ui_table_row($text{'edit_start'},
"<pre>".&html_escape($start)."</pre>");

$stop = $tmpl->{'stop'};
my $stop = $tmpl->{'stop'};
$stop = &substitute_template($stop, $d) if ($d);
print &ui_table_row($text{'edit_stop'},
$stop eq ":kill" ? $text{'edit_stopkill'} :
Expand All @@ -110,6 +116,7 @@ else {
&ui_textarea("start", $init->{'start'}, 5, 80));

# Stop code
my $stopdef;
if ($config{'mode'} eq 'smf') {
$stopdef = &ui_radio(
"stop_def", $init->{'stop'} eq ':kill' ? 1 : 0,
Expand All @@ -123,9 +130,9 @@ else {

# Current processes
if (!$in{'new'}) {
@procs = &get_started_processes($init);
my @procs = &get_started_processes($init);
if (@procs) {
@table = ( );
my @table = ( );
foreach my $p (@procs) {
push(@table, [ $p->{'pid'}, $p->{'cpu'},
$p->{'size'}, $p->{'args'} ]);
Expand Down Expand Up @@ -162,5 +169,3 @@ else {
}

&ui_print_footer("index.cgi?dom=$in{'dom'}", $text{'index_return'});


14 changes: 9 additions & 5 deletions edit_tmpl.cgi
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/usr/local/bin/perl
# Show a page for creating or editing an action template
use strict;
use warnings;
our (%access, %text, %in, %config);

require './virtualmin-init-lib.pl';
&ReadParse();
$access{'templates'} || &error($text{'tmpl_ecannot'});
&ui_print_header(undef,
$in{'new'} ? $text{'tmpl_title1'} : $text{'tmpl_title2'}, "");

my $tmpl;
if (!$in{'new'}) {
# Get the existing template
($tmpl) = grep { $_->{'id'} == $in{'id'} } &list_action_templates();
Expand All @@ -30,6 +34,7 @@ print &ui_table_row($text{'edit_start'},
&ui_textarea("start", $tmpl->{'start'}, 5, 80));

# Stop code
my $stopdef;
if ($config{'mode'} eq 'smf') {
$stopdef = &ui_radio("stop_def", $tmpl->{'stop'} eq ':kill' ? 1 : 0,
[ [ 1, $text{'edit_stopkill'} ],
Expand All @@ -54,9 +59,10 @@ print &ui_table_end();
# Section for additional parameters
print &ui_table_start($text{'tmpl_header2'}, undef, 2);

@table = ( );
my @table = ( );
my $pmax;
for($pmax=0; defined($tmpl->{'pname_'.$pmax}); $pmax++) { }
for($i=0; $i < $pmax+3; $i++) {
for(my $i=0; $i < $pmax+3; $i++) {
push(@table, [
&ui_textbox("pname_$i", $tmpl->{'pname_'.$i}, 10),
&ui_select("ptype_$i", $tmpl->{'ptype_'.$i},
Expand All @@ -73,7 +79,7 @@ for($i=0; $i < $pmax+3; $i++) {
&ui_textbox("pdesc_$i", $tmpl->{'pdesc_'.$i}, 50),
]);
}
$ptable = &ui_columns_table(
my $ptable = &ui_columns_table(
[ $text{'tmpl_pname'}, $text{'tmpl_ptype'},
$text{'tmpl_popts'}, $text{'tmpl_pdesc'} ],
100,
Expand All @@ -92,5 +98,3 @@ else {
}

&ui_print_footer("", $text{'index_return'});


33 changes: 21 additions & 12 deletions index.cgi
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#!/usr/local/bin/perl
# Show a list of bootup scripts that the user already has configured
use strict;
use warnings;
our (%access, %text, %in);
our $module_name;

require './virtualmin-init-lib.pl';
&ReadParse();
$d = $in{'dom'} ? &virtual_server::get_domain($in{'dom'}) : undef;
my $d = $in{'dom'} ? &virtual_server::get_domain($in{'dom'}) : undef;
&ui_print_header($d ? &virtual_server::domain_in($d) : undef,
$text{'index_title'}, "", undef, 0, 1);
@templates = &list_action_templates();
my @templates = &list_action_templates();

# Work out domains to work on
my @doms;
my $many;

if ($d) {
# Just one
@doms = ( $d );
Expand All @@ -22,6 +29,7 @@ else {
}

# Show existing init scripts for all domains
my @allinits;
foreach my $d (@doms) {
foreach my $i (&list_domain_actions($d)) {
$i->{'dom'} = $d->{'id'};
Expand All @@ -31,8 +39,9 @@ foreach my $d (@doms) {
}

# Work out limit
my $no_create;
if ($access{'max'}) {
$c = &count_user_actions();
my $c = &count_user_actions();
if ($c >= $access{'max'}) {
print "<b>",&text('index_hitmax', $access{'max'}),"</b><p>\n";
$no_create = 1;
Expand All @@ -46,20 +55,20 @@ if ($access{'max'}) {
}

# Build contents for table of actions
@links = ( );
my @links;
if (!$no_create) {
push(@links, [ "edit.cgi?new=1&dom=".&urlize($in{'dom'}),
$text{'index_add'} ]);
foreach $tmpl (@templates) {
foreach my $tmpl (@templates) {
push(@links, [ "edit.cgi?new=1&dom=".&urlize($in{'dom'}).
"&tmpl=$tmpl->{'id'}",
&text('index_add2', $tmpl->{'desc'}) ]);
}
}
$green = "<font color=#00aa00>$text{'yes'}</font>";
$red = "<font color=#ff0000>$text{'no'}</font>";
$orange = "<font color=#ffaa00>$text{'index_maint'}</font>";
@table = ( );
my $green = "<font color=#00aa00>$text{'yes'}</font>";
my $red = "<font color=#ff0000>$text{'no'}</font>";
my $orange = "<font color=#ffaa00>$text{'index_maint'}</font>";
my @table;
foreach my $i (sort { $a->{'name'} cmp $b->{'name'} } @allinits) {
push(@table, [
{ 'type' => 'checkbox', 'name' => 'd',
Expand Down Expand Up @@ -97,14 +106,14 @@ print &ui_form_columns_table(
undef,
$in{'dom'} ? $text{'index_none'} : $text{'index_none2'}
);


# Show list of templates
if ($access{'templates'}) {
print &ui_hr();
print $text{'index_tdesc2'},"<p>\n";
@table = ( );
foreach $t (@templates) {
foreach my $t (@templates) {
push(@table, [
"<a href='edit_tmpl.cgi?id=$t->{'id'}'>".
"$t->{'desc'}</a>",
Expand All @@ -129,7 +138,7 @@ if ($access{'templates'}) {

sub shorten_command
{
local ($cmd) = @_;
my ($cmd) = @_;
if ($cmd eq ":kill") {
return $text{'index_kill'};
}
Expand Down
26 changes: 15 additions & 11 deletions mass.cgi
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
#!/usr/local/bin/perl
# Start, stop or delete multiple actions
use strict;
use warnings;
our (%text, %in);

require './virtualmin-init-lib.pl';
&ReadParse();
@d = split(/\0/, $in{'d'});
my @d = split(/\0/, $in{'d'});
@d || &error($text{'mass_enone'});

# Get the actions
foreach $di (@d) {
($did, $name) = split(/\//, $di);
local $d = &virtual_server::get_domain($did);
local ($init) = grep { $_->{'name'} eq $name } &list_domain_actions($d);
my @dominits;
foreach my $di (@d) {
my ($did, $name) = split(/\//, $di);
my $d = &virtual_server::get_domain($did);
my ($init) = grep { $_->{'name'} eq $name } &list_domain_actions($d);
if ($d && $init) {
push(@dominits, [ $d, $init ]);
}
}

$idx = "index.cgi?dom=$dominits[0]->[0]->{'id'}";
my $idx = "index.cgi?dom=$dominits[0]->[0]->{'id'}";
my $ex;
if ($in{'delete'}) {
# Delete them all
foreach $di (@dominits) {
foreach my $di (@dominits) {
&delete_domain_action($di->[0], $di->[1]);
}
&redirect($idx);
Expand All @@ -28,7 +33,7 @@ elsif ($in{'startnow'}) {
# Start them in series
&ui_print_unbuffered_header(undef, $text{'start_titles'}, "");

foreach $di (@dominits) {
foreach my $di (@dominits) {
print &text('start_starting',
"<tt>$di->[1]->{'name'}</tt>"),"\n";
print "<pre>";
Expand All @@ -42,7 +47,7 @@ elsif ($in{'stopnow'}) {
# Stop them in series
&ui_print_unbuffered_header(undef, $text{'stop_titles'}, "");

foreach $di (@dominits) {
foreach my $di (@dominits) {
print &text('stop_stopping',
"<tt>$di->[1]->{'name'}</tt>"),"\n";
print "<pre>";
Expand All @@ -56,7 +61,7 @@ elsif ($in{'restartnow'}) {
# Restart them in series
&ui_print_unbuffered_header(undef, $text{'restart_titles'}, "");

foreach $di (@dominits) {
foreach my $di (@dominits) {
print &text('restart_restarting',
"<tt>$di->[1]->{'name'}</tt>"),"\n";
print "<pre>";
Expand All @@ -69,4 +74,3 @@ elsif ($in{'restartnow'}) {
else {
&error("No button clicked!");
}

30 changes: 18 additions & 12 deletions save.cgi
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
#!/usr/local/bin/perl
# Create, update, delete, start or stop some action
use strict;
use warnings;
our (%access, %text, %in);

require './virtualmin-init-lib.pl';
&ReadParse();
$d = &virtual_server::get_domain($in{'dom'});
my $d = &virtual_server::get_domain($in{'dom'});
&virtual_server::can_edit_domain($d) || &error($text{'save_ecannot'});

# Get the current boot action
@inits = &list_domain_actions($d);
my @inits = &list_domain_actions($d);
my $init;
my $oldinit;
my $ex; # XXX This is never used, but is captured as a result.
if ($in{'id'}) {
($init) = grep { $_->{'id'} eq $in{'id'} } @inits;
$init || &error($text{'edit_egone'});
$oldinit = { %$init };
}
elsif ($access{'max'}) {
# Check if limit was hit
$c = &count_user_actions();
my $c = &count_user_actions();
if ($c >= $access{'max'}) {
&error(&text('save_etoomany', $access{'max'}));
}
Expand Down Expand Up @@ -56,23 +62,24 @@ else {
$in{'name'} =~ /^[a-z0-9\.\-\_]+$/i || &error($text{'save_ename'});
if ($in{'new'} || $in{'name'} ne $init->{'name'}) {
# Check for clash
($clash) = grep { $_->{'name'} eq $in{'name'} } @inits;
my ($clash) = grep { $_->{'name'} eq $in{'name'} } @inits;
$clash && &error($text{'save_eclash'});
}
$init->{'name'} = $in{'name'};
$in{'desc'} =~ /\S/ || &error($text{'save_edesc'});
$init->{'desc'} = $in{'desc'};
$init->{'status'} = $in{'status'};
%tparams = ( );
my %tparams;
my $tmpl;
if ($in{'new'} && $in{'tmpl'}) {
# From template
($tmpl) = grep { $_->{'id'} == $in{'tmpl'} }
&list_action_templates();
for($i=0; defined($tmpl->{'pname_'.$i}); $i++) {
$td = $tmpl->{'pdesc_'.$i};
$tt = $tmpl->{'ptype_'.$i};
$tn = $tmpl->{'pname_'.$i};
$tv = $in{'param_'.$tn};
for(my $i=0; defined($tmpl->{'pname_'.$i}); $i++) {
my $td = $tmpl->{'pdesc_'.$i};
my $tt = $tmpl->{'ptype_'.$i};
my $tn = $tmpl->{'pname_'.$i};
my $tv = $in{'param_'.$tn};
if ($tt == 0 || $tt == 2) {
$tv =~ /\S/ ||
&error(&text('save_eptype0', $td));
Expand All @@ -87,7 +94,7 @@ else {
$tparams{$tn} = $tv;
}
}
%thash = ( %$d, %tparams );
my %thash = ( %$d, %tparams );
$thash{'name'} = $init->{'name'};
$init->{'start'} = &substitute_template(
$tmpl->{'start'}, \%thash);
Expand Down Expand Up @@ -122,4 +129,3 @@ else {
}
&redirect("index.cgi?dom=$in{'dom'}");
}

Loading

0 comments on commit 2889c43

Please sign in to comment.