3 # Save, create or delete a serial port configuration
5 require './vgetty-lib.pl';
6 &foreign_require("inittab", "inittab-lib.pl");
8 @inittab = &inittab::parse_inittab();
9 @vgt = &vgetty_inittabs();
11 ($init) = grep { $_->{'id'} eq $in{'id'} } @vgt;
12 $oldtty = $init->{'tty'};
13 $oldtty = "/dev/$oldtty" if ($oldtty !~ /^\//);
15 @conf = &get_config();
16 $rings = &find_value("rings", \@conf);
17 $ans = &find_value("answer_mode", \@conf);
19 &lock_file($inittab::config{'inittab_file'});
21 # Just deleting an inittab entry
22 &inittab::delete_inittab($init);
23 if (defined($in{'rings_def'})) {
24 local $tf = &tty_opt_file($ans, $oldtty);
29 if (defined($in{'ans_def'})) {
30 $tf = &tty_opt_file($rings, $oldtty);
37 # Validate and store inputs
38 &error_setup($text{'vgetty_err'});
39 $cmd = $in{'new'} ? &has_command("vgetty") : $init->{'vgetty'};
40 if ($init->{'args'}) {
41 $init->{'args'} =~ s/^\s+//;
42 $cmd .= " $init->{'args'}";
45 $cmd .= " $in{'tty'}";
46 $init->{'tty'} = $in{'tty'};
49 -r $in{'other'} || &error($text{'vgetty_etty'});
50 $cmd .= " $in{'other'}";
51 $init->{'tty'} = $in{'other'};
53 $newtty = $init->{'tty'};
54 $newtty = "/dev/$newtty" if ($newtty !~ /^\//);
55 if ($in{'new'} || $newtty ne $oldtty) {
57 foreach $v (&vgetty_inittabs()) {
58 local $vtty = $v->{'tty'};
59 $vtty = "/dev/$vtty" if ($vtty !~ /^\//);
60 &error(&text('vgetty_eclash', "<tt>$vtty</tt>"))
61 if ($vtty eq $newtty);
64 $init->{'process'} = $cmd;
66 if (defined($in{'rings_def'})) {
67 $tf = &tty_opt_file($rings, $init->{'tty'});
69 if (!$in{'new'} && $oldtty ne $newtty) {
70 unlink(&tty_opt_file($rings, $oldtty));
72 if ($in{'rings_def'}) {
76 $in{'rings'} =~ /^\d+$/ ||
77 &error($text{'vgetty_erings'});
78 $in{'rings'} >= 2 || &error($text{'vgetty_erings2'});
79 &open_tempfile(TF, ">$tf");
80 &print_tempfile(TF, $in{'rings'},"\n");
86 if (defined($in{'ans_def'})) {
87 $tf = &tty_opt_file($ans, $init->{'tty'});
89 if (!$in{'new'} && $oldtty ne $newtty) {
90 unlink(&tty_opt_file($ans, $oldtty));
96 $mode = &parse_answer_mode("ans");
97 $mode || &error($text{'vgetty_eans'});
98 &open_tempfile(TF, ">$tf");
99 &print_tempfile(TF, $mode,"\n");
107 foreach $i (@inittab) {
108 $maxid = $i->{'id'} if ($i->{'id'} =~ /^\d+$/ &&
109 $i->{'id'} > $maxid);
111 $init->{'id'} = $maxid + 1;
112 $init->{'levels'} = [ 2, 3, 4, 5 ];
113 $init->{'action'} = "respawn";
114 &inittab::create_inittab($init);
117 &inittab::modify_inittab($init);
120 &unlock_file($inittab::config{'inittab_file'});
121 &webmin_log($in{'delete'} ? "delete" : $in{'new'} ? "create" : "modify",
122 "vgetty", $init->{'tty'}, $init);
124 &redirect("list_vgetty.cgi");