#!/usr/local/bin/perl # edit_action.cgi # Edit or create a bootup action. Existing actions can either be in the # init.d directory (and linked to from the appropriate runlevels), or # just plain runlevel files require './init-lib.pl'; %access = &get_module_acl(); $access{'bootup'} || &error($text{'edit_ecannot'}); $ty = $ARGV[0]; if ($ty == 0) { # Editing an action in init.d, linked to from various runlevels $ac = $ARGV[1]; &ui_print_header(undef, $text{'edit_title'}, ""); $file = &action_filename($ac); open(FILE, $file); while() { $data .= $_; if (/^\s*(['"]?)([a-z]+)\1\)/i) { $hasarg{$2}++; } } close(FILE); } elsif ($ty == 1) { # Editing an action in one of the runlevels $rl = $ARGV[1]; $num = $ARGV[2]; $ac = $ARGV[3]; $inode = $ARGV[4]; $ss = $ARGV[5]; &ui_print_header(undef, $text{'edit_title'}, ""); $file = &runlevel_filename($rl, $ss, $num, $ac); $data = `cat $file`; } else { # Creating a new action in init.d &ui_print_header(undef, $text{'create_title'}, ""); } print "\n"; print "\n"; print "
$text{'edit_details'}
\n"; print "\n"; print "\n"; if ($ty != 2) { print "\n"; if ($ty == 1) { print "\n"; print "\n"; print "\n"; } } print "\n"; if ($ac =~ /^\// || $access{'bootup'} == 2) { print "\n"; print "\n"; print "\n"; } else { print "\n"; } $fs = ""; $fe = ""; if ($ty == 2) { # Display fields for a template print "\n"; print "\n"; if ($config{'start_stop_msg'}) { print "\n"; print "\n"; print "\n"; print "\n"; } print "\n"; print "\n"; print "\n"; print "\n"; } elsif ($access{'bootup'} == 2) { # Just show current script print "\n"; print "\n"; } else { # Allow direct editing of the script print "\n"; print "\n"; } if ($ty == 1 && $access{'bootup'} == 1) { # Display a message about the script being bogus print "
$text{'edit_name'}$ac
$text{'edit_desc'}$fs$fe
$text{'edit_startmsg'}
$text{'edit_stopmsg'}
$text{'edit_start'}$fs$fe
$text{'edit_stop'}$fs$fe
$text{'edit_script'}$fs
",&html_escape($data),"
$fe
$text{'edit_script'}$fs$fe

\n"; print "",&text("edit_bad$ss", $rl),"
\n"; print "", "$text{'edit_fix'}.

\n"; } elsif (!$config{'expert'} || $access{'bootup'} == 2) { # Just tell the user if this action is started at boot time local $boot = 0; print " $text{'edit_boot'}\n"; if ($ty == 0) { local @boot = &get_inittab_runlevel(); foreach $s (&action_levels('S', $ac)) { local ($l, $p) = split(/\s+/, $s); $boot = 1 if (&indexof($l, @boot) >= 0); } if ($boot && $config{'daemons_dir'} && &read_env_file("$config{'daemons_dir'}/$ac", \%daemon)) { $boot = lc($daemon{'ONBOOT'}) eq 'yes' ? 1 : 0; } print "\n"; } if ($access{'bootup'} == 1) { printf " %s\n", $boot || $ty == 2 ? 'checked' : '', $text{'yes'}; printf " %s\n", $boot || $ty == 2 ? '' : 'checked', $text{'no'}; } else { print "",$boot || $ty == 2 ? $text{'yes'} : $text{'no'}; } if ($hasarg{'status'} && $config{'status_check'}) { # Show if action is currently running $out = `$file status /dev/null`; print "       ", "$text{'edit_status'}  \n"; if ($out =~ /running/i) { print $text{'yes'}; } elsif ($out =~ /stopped/i) { print "$text{'no'}"; } else { print "$text{'edit_unknown'}"; } } print " \n"; } else { if ($config{'daemons_dir'} && $ac && &read_env_file("$config{'daemons_dir'}/$ac", \%daemon)) { # Display onboot flag from daemons file $boot = lc($daemon{'ONBOOT'}) eq 'yes'; print " $text{'edit_boot'}\n"; printf " %s\n", $boot ? 'checked' : '', $text{'yes'}; printf " %s\n", $boot ? '' : 'checked', $text{'no'}; } # Display which runlevels the action is started/stopped in print "

\n"; print "\n"; print "\n"; print "
$text{'edit_levels'}
\n"; if ($ac) { foreach $s (&action_levels('S', $ac)) { @s = split(/\s+/, $s); $spri{$s[0]} = $s[1]; } foreach $k (&action_levels('K', $ac)) { @k = split(/\s+/, $k); $kpri{$k[0]} = $k[1]; } } @boot = &get_inittab_runlevel(); foreach $rl (&list_runlevels()) { print "\n" if (!$sw); if (&indexof($rl, @boot) == -1) { print "\n"; } else { print "\n"; } $od = $config{'order_digits'}; printf "\n"; printf "\n"; print "\n" if ($sw); $sw = !$sw; } print "\n" if ($sw); print "
",&text('edit_rl', $rl),"",&text('edit_rl', $rl), "\n", defined($spri{$rl}) ? "checked" : ""; print $text{'edit_startat'},"\n"; print "\n", defined($kpri{$rl}) ? "checked" : ""; print $text{'edit_stopat'},"\n"; print "

\n"; } if ($ty != 2) { print "\n"; if ($access{'bootup'} == 1) { print "\n"; } print "\n"; print "\n"; print "\n"; $args = join("+", @ARGV); print "\n"; print "\n"; if ($access{'bootup'} == 1) { print "\n"; print "\n"; print "\n"; if ($ty == 1) { print "\n"; print "\n"; print "\n"; } print "\n"; } print "
\n"; print "\n"; if ($hasarg{'restart'}) { print "\n"; } if ($hasarg{'condrestart'}) { print "\n"; } if ($hasarg{'reload'}) { print "\n"; } if ($hasarg{'status'}) { print "\n"; } print "\n"; print "

\n"; } else { print "

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