3 # Save, create or delete a serial port configuration
5 require './pap-lib.pl';
6 $access{'mgetty'} || &error($text{'mgetty_ecannot'});
7 &foreign_require("inittab", "inittab-lib.pl");
9 @inittab = &inittab::parse_inittab();
10 @mgt = &mgetty_inittabs();
12 ($init) = grep { $_->{'id'} eq $in{'id'} } @mgt;
13 $oldtty = $init->{'tty'};
14 $oldtty = "/dev/$oldtty" if ($oldtty !~ /^\//);
17 &lock_file($inittab::config{'inittab_file'});
19 # Just deleting an inittab entry
20 &inittab::delete_inittab($init);
23 # Validate and store inputs
24 &error_setup($text{'mgetty_err'});
25 $cmd = $in{'new'} ? &has_command($config{'mgetty'}) : $init->{'mgetty'};
26 $cmd .= " -r" if ($in{'direct'});
27 if (!$in{'speed_def'}) {
28 $in{'speed'} =~ /^\d+$/ || &error($text{'mgetty_espeed'});
29 $cmd .= " -s $in{'speed'}";
31 $in{'rings'} =~ /^\d+$/ || &error($text{'mgetty_eanswer'});
32 $cmd .= " -n $in{'rings'}" if ($in{'rings'} != 1);
33 if ($in{'mode'} == 1) {
36 elsif ($in{'mode'} == 2) {
39 if (!$in{'back_def'}) {
40 $in{'back'} =~ /^\d+$/ || &error($text{'mgetty_eback'});
41 $cmd .= " -R $in{'back'}";
43 if (!$in{'prompt_def'}) {
44 $cmd .= $in{'prompt'} =~ /"/ ? " -p '$in{'prompt'}'"
45 : " -p \"$in{'prompt'}\"";
47 if ($init->{'args'}) {
48 $init->{'args'} =~ s/^\s+//;
49 $cmd .= " $init->{'args'}";
52 $cmd .= " $in{'tty'}";
53 $init->{'tty'} = $in{'tty'};
56 -r $in{'other'} || &error($text{'mgetty_etty'});
57 $cmd .= " $in{'other'}";
58 $init->{'tty'} = $in{'other'};
60 $newtty = $init->{'tty'};
61 $newtty = "/dev/$newtty" if ($newtty !~ /^\//);
62 if ($in{'new'} || $newtty ne $oldtty) {
64 foreach $m (&mgetty_inittabs()) {
65 local $mtty = $m->{'tty'};
66 $mtty = "/dev/$mtty" if ($mtty !~ /^\//);
67 &error(&text('mgetty_eclash', "<tt>$mtty</tt>"))
68 if ($mtty eq $newtty);
71 $cmd .= " $init->{'ttydefs'}" if ($init->{'ttydefs'});
72 $init->{'process'} = $cmd;
76 foreach $i (@inittab) {
77 $maxid = $i->{'id'} if ($i->{'id'} =~ /^\d+$/ &&
80 $init->{'id'} = $maxid + 1;
81 $init->{'levels'} = [ 2, 3, 4, 5 ];
82 $init->{'action'} = "respawn";
83 &inittab::create_inittab($init);
86 &inittab::modify_inittab($init);
89 &unlock_file($inittab::config{'inittab_file'});
90 &webmin_log($in{'delete'} ? "delete" : $in{'new'} ? "create" : "modify",
91 "mgetty", $init->{'tty'}, $init);
93 &redirect("list_mgetty.cgi");