1#!/usr/local/bin/perl 2 3BEGIN { push(@INC, ".."); }; 4use WebminCore; 5&init_config(); 6 7# parse_inittab() 8# Returns a list of entries from the /etc/inittab file 9sub parse_inittab 10{ 11local @rv; 12local $lnum = 0; 13open(INITTAB, "<".$config{'inittab_file'}); 14while(<INITTAB>) { 15 s/\r|\n//g; 16 #s/#.*$//g; 17 s/\/\/.*$//g; 18 if ($gconfig{'os_type'} eq 'aix') { 19 # A leading : indicates a comment on AIX 20 s/^:.*$//g; 21 } 22 next if (/^\s*#\s*\$Header/i); # CVS header 23 local $sline = $lnum; 24 # Join \ lines 25 while(/\\$/) { 26 local $nl = <INITTAB>; 27 s/\\$//; 28 $nl =~ s/^\s+//; 29 $_ .= $nl; 30 $lnum++; 31 } 32 if (/^(#*)\s*\$Id/ || /^(#*)\s*\/etc/ || /^(#*)\s*<id>/) { 33 # Skip this line 34 } 35 elsif (/^(#*)\s*([^:]+):([^:]*):([^:]+):([^:]*)/) { 36 push(@rv, { 'id' => $2, 37 'action' => $4, 38 'process' => $5, 39 'comment' => $1 ne '', 40 'levels' => [ split(//, $3) ], 41 'line' => $sline, 42 'eline' => $lnum, 43 'index' => scalar(@rv) }); 44 } 45 $lnum++; 46 } 47close(INITTAB); 48return @rv; 49} 50 51# create_inittab(&inittab) 52# Adds an entry to /etc/inittab 53sub create_inittab 54{ 55&open_tempfile(INITTAB, ">>$config{'inittab_file'}"); 56&print_tempfile(INITTAB, $_[0]->{'comment'} ? "# " : "", 57 join(":", $_[0]->{'id'}, join("", @{$_[0]->{'levels'}}), 58 $_[0]->{'action'}, $_[0]->{'process'}),"\n"); 59&close_tempfile(INITTAB); 60} 61 62# modify_inittab(&inittab) 63# Replaces an /etc/inittab entry 64sub modify_inittab 65{ 66local $lref = &read_file_lines($config{'inittab_file'}); 67splice(@$lref, $_[0]->{'line'}, $_[0]->{'eline'} - $_[0]->{'line'} + 1, 68 ($_[0]->{'comment'} ? "# " : ""). 69 join(":", $_[0]->{'id'}, join("", @{$_[0]->{'levels'}}), 70 $_[0]->{'action'}, $_[0]->{'process'})); 71&flush_file_lines(); 72} 73 74# delete_inittab(&inittab) 75# Delete a single /etc/inittab entry 76sub delete_inittab 77{ 78local $lref = &read_file_lines($config{'inittab_file'}); 79splice(@$lref, $_[0]->{'line'}, $_[0]->{'eline'} - $_[0]->{'line'} + 1); 80&flush_file_lines(); 81} 82 83sub list_runlevels 84{ 85return ( 0..6, "a", "b", "c" ); 86} 87 88sub list_actions 89{ 90return ( [ "respawn", $text{ 'inittab_respawn' } ], 91 [ "wait", $text{ 'inittab_wait' } ], 92 [ "once", $text{ 'inittab_once' } ], 93 [ "ondemand", $text{ 'inittab_ondemand' } ], 94 [ "initdefault", $text{ 'inittab_initdefault' } ], 95 [ "sysinit", $text{ 'inittab_sysinit' } ], 96 [ "powerwait", $text{ 'inittab_powerwait' } ], 97 [ "powerfail", $text{ 'inittab_powerfail' } ], 98 [ "powerokwait", $text{ 'inittab_powerokwait' } ], 99 [ "powerfailnow", $text{ 'inittab_powerfailnow' } ], 100 [ "ctrlaltdel", $text{ 'inittab_ctrlaltdel' } ], 101 [ "kbdrequest", $text{ 'inittab_kbdrequest' } ], 102 [ "bootwait", $text{'inittab_bootwait'} ], 103 [ "boot", $text{'inittab_boot'} ], 104 [ "off", $text{'inittab_off'} ], 105 ); 106} 107 108