#!/usr/bin/perl
sub login_enable{
    open(my $CONFIG_FILE, "<", "/etc/wsd.conf") or die("Could not open wsd.conf");	
	my ($LOGIN_ENABLE, $LOGIN_USER, $LOGIN_PWD);
	while( my $line = <$CONFIG_FILE> ){
        chomp($line);		
        if($line=~/Login-set : (.*)/){		   		  
		   $LOGIN_ENABLE=$1;
           		   
        }
		if($line=~/Login-user : (.*)/){
		   $LOGIN_USER=$1;
		}
        if($line=~/Login-password : (.*)/){
		   $LOGIN_PWD=$1;
		}        
   }
   close(WIRELESS_FILE);   
   return ($LOGIN_ENABLE, $LOGIN_USER, $LOGIN_PWD);
}
my @LOGIN_INFO=&login_enable();
print "Content-type: text/html\n\n";
print "<html>";
print "<head>";
print "<title>KCard Login</title>";
print "<script type=\"text/javascript\">
function check_input(user,pwd,enable,onload){
var oForm = document.forms[\"kcard_login\"];
if (enable == \"No\"){
    document.cookie = \"securitydisable\";
    history.back();
}else{  
  if(onload == 1){   //Enable to insert user name and password
  }else{
     if (oForm.user.value==user && oForm.pwd.value==pwd){
      window.alert(\"Login successfully.!\");
	  document.cookie = \"securityenable\";
	  history.back();
    }else{
          window.alert(\"Please insert the right user name and password!\");
    }   
  }      
}     
}</script>";
print "<style>
<!--
body{
	background-color:#ffdee0;
}
-->
</style>";
print "</head>";
print "<body onLoad=\"check_input('$LOGIN_INFO[1]','$LOGIN_INFO[2]','$LOGIN_INFO[0]',1)\">";
print "<form name=\"kcard_login\">";
print "<br><br>Please insert your user name and password. <br>";
print "<li><b>User Name : </b><input id=\"user\" name=\"user\" type=\"text\" value=\"\"></li>";
print "<li><b>&nbsp;&nbsp;Password   : </b><input id=\"pwd\" name=\"pwd\" type=\"text\" value=\"\"></li><br>";
print "<br><input type=\"button\" value=\"Submit\" onClick=\"check_input('$LOGIN_INFO[1]','$LOGIN_INFO[2]','$LOGIN_INFO[0]',0)\">";
print "<input type=\"reset\" value=\" ClearAll \" >";
print "</form></body>";
print "</html>";
