#!/usr/local/bin/perl
# edit_session.cgi
# Edit session login options

require './usermin-lib.pl';
$access{'session'} || &error($text{'acl_ecannot'});
print "Set-Cookie: sessiontest=1; path=/\n";
&ui_print_header(undef, $text{'session_title'}, "");
&get_usermin_miniserv_config(\%miniserv);

&get_usermin_config(\%uconfig);
print "$text{'session_desc1'}<p>\n";
print "$text{'session_desc2'}<p>\n";

print "<form action=change_session.cgi>\n";
print "<table border>\n";
print "<tr $tb> <td><b>$webmin::text{'session_header'}</b></td> </tr>\n";
print "<tr $cb> <td nowrap>\n";

printf "<input type=radio name=passdelay value=0 %s> %s<br>\n",
	$miniserv{'passdelay'} ? '' : 'checked', $webmin::text{'session_pdisable'};
printf "<input type=radio name=passdelay value=1 %s> %s<br>\n",
	$miniserv{'passdelay'} ? 'checked' : '', $webmin::text{'session_penable'};
printf "&nbsp;&nbsp;&nbsp;<input type=checkbox name=blockhost_on value=1 %s>\n",
	$miniserv{'blockhost_failures'} ? "checked" : "";
print &webmin::text('session_blockhost',
	    "<input name=blockhost_failures size=4 value='$miniserv{'blockhost_failures'}'>",
	    "<input name=blockhost_time size=4 value='$miniserv{'blockhost_time'}'>"),"<br>\n";
eval "use Sys::Syslog qw(:DEFAULT setlogsock)";
if (!$@) {
	printf "<input type=checkbox name=syslog value=1 %s> %s\n",
		$miniserv{'syslog'} ? "checked" : "", $webmin::text{'session_syslog2'};
	}
else {
	print "<input type=hidden name=syslog value='$miniserv{'syslog'}'>\n";
	}
print "<p>\n";

printf "<input type=radio name=session value=0 %s> %s<br>\n",
	!$miniserv{'session'} ? "checked" : "", $webmin::text{'session_disable'};
printf "<input type=radio name=session value=1 %s> %s<br>\n",
	$miniserv{'session'} ? "checked" : "", $webmin::text{'session_enable'};
printf "&nbsp;&nbsp;&nbsp;<input type=checkbox name=logouttime_on value=1 %s>\n",
	$miniserv{'logouttime'} ? "checked" : "";
print &webmin::text('session_logout',
	"<input name=logouttime value='$miniserv{'logouttime'}' size=10>"),"<br>\n";
#printf "&nbsp;&nbsp;&nbsp;<input type=checkbox name=locking value=1 %s>\n",
#	$gconfig{'locking'} ? "checked" : "";
#print "$webmin::text{'session_locking'}<br>\n";
printf "&nbsp;&nbsp;&nbsp;<input type=checkbox name=remember value=1 %s>\n",
	$uconfig{'noremember'} ? "" : "checked";
print "$webmin::text{'session_remember'}<br>\n";
printf "&nbsp;&nbsp;&nbsp;<input type=checkbox name=hostname value=1 %s>\n",
	$uconfig{'nohostname'} ? "" : "checked";
print "$webmin::text{'session_hostname'}<br>\n";
print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
printf "<input type=checkbox name=realname value=1 %s>\n",
	$uconfig{'realname'} ? "checked" : "";
print "$webmin::text{'session_realname'}<br>\n";
printf "&nbsp;&nbsp;&nbsp;<input type=radio name=banner_def value=1 %s> %s\n",
	$uconfig{'loginbanner'} ? "" : "checked", $webmin::text{'session_banner1'};
printf "<input type=radio name=banner_def value=0 %s> %s\n",
	$uconfig{'loginbanner'} ? "checked" : "", $webmin::text{'session_banner0'};
printf "<input name=banner size=30 value='%s'> %s<br>\n",
	$uconfig{'loginbanner'}, &file_chooser_button("banner");
print "<p>\n";

printf "<input type=radio name=localauth value=0 %s> %s<br>\n",
	!$miniserv{'localauth'} ? "checked" : "", $webmin::text{'session_localoff'};
printf "<input type=radio name=localauth value=1 %s> %s<br>\n",
	$miniserv{'localauth'} ? "checked" : "", $webmin::text{'session_localon'};
print "<p>\n";

@users = &get_usermin_miniserv_users();
$authmode = $users[0]->{'pass'} eq 'e' ? 2 :
	    $miniserv{'no_pam'} ? 1 : 0;
printf "<input type=radio name=authmode value=0 %s> %s<br>\n",
	$authmode == 0 ? "checked" : "", $text{'session_authmode0'};
printf "<input type=radio name=authmode value=1 %s>\n",
	$authmode == 1 ? "checked" : "";
print &text('session_authmode1',
      "<input name=passwd_file size=20 value='$miniserv{'passwd_file'}'>",
      "<input name=passwd_uindex size=2 value='$miniserv{'passwd_uindex'}'>",
      "<input name=passwd_pindex size=2 value='$miniserv{'passwd_pindex'}'>"),
      "<br>\n";
printf "<input type=radio name=authmode value=2 %s> %s\n",
	$authmode == 2 ? "checked" : "", $text{'session_authmode2'};
printf "<input name=extauth size=30 value='%s'><p>\n",
	$miniserv{'extauth'};

$ver = &get_usermin_version();
if ($ver >= 1.047 && $miniserv{'passwd_cindex'} ne '') {
	#print "$text{'session_pmodedesc'}<br>\n";
	foreach $m (0 .. 2) {
		printf "<input type=radio name=passwd_mode value=%d %s> %s\n",
			$m, $miniserv{'passwd_mode'} == $m ? "checked" : "",
			$webmin::text{'session_pmode'.$m};
		print $m == 2 ? "<p>\n" : "<br>\n";
		}
	}
if ($ver >= 1.087) {
	printf "<input type=checkbox name=passwd_blank value=1 %s> %s<p>\n",
		$miniserv{'passwd_blank'} ? "checked" : "",
		$text{'session_blank'};
	}

if ($ver >= 1.003) {
	printf "<input type=checkbox name=domainuser value=1 %s> %s<br>\n",
		$miniserv{'domainuser'} ? "checked" : "",
		$text{'session_domain'};
	}
if ($ver >= 1.021) {
	printf "<input type=checkbox name=domainstrip value=1 %s> %s<br>\n",
		$miniserv{'domainstrip'} ? "checked" : "",
		$text{'session_strip'};
	printf "<input type=checkbox name=user_mapping_on value=1 %s> %s\n",
		$miniserv{'user_mapping'} ? "checked" : "",
		$text{'session_usermap'};
	printf "<input name=user_mapping size=30 value='%s'> %s<br>\n",
		$miniserv{'user_mapping'}, &file_chooser_button("user_mapping");
	}

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

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

