#!/usr/local/bin/perl
# edit_os.cgi
# Operating system config form

require './usermin-lib.pl';
$access{'os'} || &error($text{'acl_ecannot'});
&header($text{'os_title'}, "");
print "<hr>\n";

print $text{'os_desc'},"<br>\n";
print $text{'os_desc2'},"<br>\n";

&get_usermin_config(\%uconfig);
&get_usermin_miniserv_config(\%miniserv);
open(OSLIST, "$miniserv{'root'}/os_list.txt");
while(<OSLIST>) {
	chop;
	if (/^([^\t]+)\t+([^\t]+)\t+(\S+)\t+(\S+)\t*(.*)$/) {
		push(@list, [ $1, $2, $3, $4, $5 ]);
		}
	}
close(OSLIST);
if (!$uconfig{'real_os_type'}) {
	foreach $o (@list) {
		if ($o->[2] eq $uconfig{'os_type'} &&
		    $o->[3] eq $uconfig{'os_version'}) {
			$uconfig{'real_os_type'} = $o->[0];
			$uconfig{'real_os_version'} = $o->[1];
			last;
			}
		}
	}

print "<form action=change_os.cgi>\n";
print "<table border>\n";
print "<tr $tb> <td><b>$text{'os_header'}</b></td> </tr>\n";
print "<tr $cb> <td><table>\n";

print "<tr> <td><b>$text{'os_curros'}</b></td>\n";
print "<td>$uconfig{'real_os_type'}</td> </tr>\n";

print "<tr> <td><b>$text{'os_currver'}</b></td>\n";
print "<td>$uconfig{'real_os_version'}</td> </tr>\n";

print "<tr> <td valign=top><b>$text{'os_new'}</b></td>\n";
print "<td><select name=os size=7>\n";
foreach $o (@list) {
	printf "<option value='%s' %s>%s %s\n",
		join(",", @$o),
		$uconfig{'real_os_type'} eq $o->[0] &&
		$uconfig{'real_os_version'} eq $o->[1] ? "selected" : "",
		$o->[0], $o->[1];
	}
print "</select></td> </tr>\n";

print "<tr> <td><b>$text{'os_path'}</b></td>\n";
print "<td><input name=path size=30 value='$uconfig{'path'}'></td> </tr>\n";

print "<tr> <td><b>$text{'os_ld_path'}</b></td>\n";
print "<td><input name=ld_path size=30 ",
      "value='$uconfig{'ld_path'}'></td> </tr>\n";

print "</table></td></tr></table>\n";
print "<input type=submit value=\"$text{'save'}\"></form>\n";

print "<hr>\n";
&footer("", $text{'index_return'});

