<html>
<head>
<title>Smart Scan </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--base href="HTTP://192.168.149.128:16372/smex/"-->
<link href="css/trend-style-new.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="javascripts/localization.js"></script>
<script language="JavaScript" src="javascripts/trend-ui-new.js"></script>
<script language="JavaScript" src="javascripts/OLH_Mapping.js"></script>
<script language="JavaScript" src="javascripts/prototype.js"></script>
<script type="text/javascript" src="javascripts/yahoo-dom-event.js"></script> 
<script type="text/javascript">
var link_smart_source_setting = '$$LINK_SMART_SOURCE_SETTING$$';

function jsInitPage()
{
	document.fmMain.txtAddFRServerPort.maxLength  = INT_LMAX_PORT;
	document.fmMain.txtAddWRServerPort.maxLength  = INT_LMAX_PORT;
	document.fmMain.txtAddServerName.maxLength	= INT_LMAX_ADDR_PROXY;
	
	var allcookie = document.cookie;
    var SSAddInit = null;
	if(allcookie.indexOf("ssAddInit") != -1){
	    var CookiePair = allcookie.split(";");
        for(i=0;i<CookiePair.length;i++){
			var cookieItem = unescape(CookiePair[i]);
            if(cookieItem.indexOf("ssAddInit=") != -1){
                SSAddInit = cookieItem.substring(cookieItem.indexOf("=")+1,cookieItem.length);
            }
        }
	}
	if(getCookie("ssAddInit") == "added"){
	    document.cookie = "asAddInit=" + escape("initial");
		window.opener.jsPageChanged(true);
		var needRefresh = document.getElementById("needRefresh").value;
		if(needRefresh == 0){
			window.opener.jsRefresh();
		}
	    window.close();  
	}
	enableCCFRfunc();
	enableLWCSfunc();
}

function jsSubmit()
{
	if(!document.getElementById("chkEnableCCFR").checked
		&& !document.getElementById("chkEnableLWCS").checked)
	{
		alert(STR_ERR_NOSERVER_ENABLED);
		return;
	}
	if(document.getElementById("chkEnableCCFR").checked
		&& document.getElementById("txtAddFRServerPort").value=="")
	{
		alert(STR_ERR_INVALID_PORT);
		return;
	}
	if(document.getElementById("chkEnableLWCS").checked
		&& document.getElementById("txtAddWRServerPort").value=="")
	{
		alert(STR_ERR_INVALID_PORT);
		return;
	}
	
	var checkFRServerPort = 0;
	var checkWRServerPort = 0;
	if(document.getElementById("txtAddFRServerPort").value)
		checkFRServerPort = 1;
	if(document.getElementById("txtAddWRServerPort").value)
		checkWRServerPort = 1;
	if(!checkFRServerPort && !checkWRServerPort)
	{
		alert(STR_ALERT_PORT_INPUT);
		return;
	}
	if(checkFRServerPort)
	{
		if(!checkPortRange(document.getElementById("txtAddFRServerPort").value,STR_ERR_INVALID_PORT))
			return;
		var strfrport = String(document.getElementById("txtAddFRServerPort").value);
		if(!jsCheckInputPort(strfrport))
		{
			alert(STR_ALERT_PORT_INTEGER);
			return;
		}
	}
	if(checkWRServerPort)
	{	
		if(!checkPortRange(document.getElementById("txtAddWRServerPort").value,STR_ERR_INVALID_PORT))
			return;
		var strwrport = String(document.getElementById("txtAddWRServerPort").value);
		if(!jsCheckInputPort(strwrport))
		{
			alert(STR_ALERT_PORT_INTEGER);
			return;
		}
	}
	
	if(isLessThanMax()
	&& verifyServerName(document.getElementById("txtAddServerName").value) 
	&& isUniqueServerName(document.getElementById("txtAddServerName").value)){
		var serverInfor = new Array();
		serverInfor[0] = "0";
		serverInfor[1] = document.getElementById("txtAddServerName").value;
		if(!checkFRServerPort)
			serverInfor[2] = "0";
		else
			serverInfor[2] = document.getElementById("txtAddFRServerPort").value;
		serverInfor[3] = document.getElementById("chkAddSslEnabled").checked == true ? "1":"0";
		if(!checkWRServerPort)
			serverInfor[4] = "0";
		else
			serverInfor[4] = document.getElementById("txtAddWRServerPort").value;
		if(document.getElementById("boolWRIsGlobal").value=="1"){
			serverInfor[5] = "1";
		}
		else{
			serverInfor[5] = "0";
		}
		if(document.getElementById("boolWRStatus").value=="1"){	
			serverInfor[6] = "1";
		}
		else{
			serverInfor[6] = "0";
		}
		if(document.getElementById("boolFRStatus").value=="1")
			serverInfor[7] = document.getElementById("boolFRStatus").value;
		else
			serverInfor[7] = "0";
		if(document.getElementById("chkEnableCCFR").checked)
		{
			serverInfor[8] = "1";
		}
		else
			serverInfor[8] = "0";
		if(document.getElementById("chkEnableLWCS").checked)
		{
			serverInfor[9] = "1";
		}
		else
			serverInfor[9] = "0";
	
		document.fmMain.btnSave.disabled = true;
		window.opener.addTableRow(serverInfor);
		document.cookie = "ssAddInit=" + escape("added");
		document.fmMain.FormAction.value="Save";
		jsAddCSRFToken(document.fmMain);
        document.fmMain.submit();
	}
}

function jsCheckInputPort(str)
{
	for(var i=0; i<str.length; i++)
	{
		if('.' == str.charAt(i))
			return false;
	}
	return true;
}

function jsCancel()
{
	document.cookie = "asAddInit=" + escape("added"); 
	window.close();
}

function jsTestFRConnection()
{
	if(verifyServerName(document.getElementById("txtAddServerName").value)
	&& checkPortRange(document.getElementById("txtAddFRServerPort").value,STR_ERR_INVALID_PORT)){
		var succeed = document.getElementById("TestConn_Succeed");
		var fail = document.getElementById("TestConn_Fail");
		var progress = document.getElementById("TestConn_Progress");
		succeed.style.display="none";
		fail.style.display="none";
		progress.style.display="block";
		
		
		document.getElementById("chkEnable").checked = window.opener.document.getElementById("chkEnable").checked;
		document.getElementById("txtAddr").value = window.opener.document.getElementById("txtAddr").value;
		document.getElementById("txtPort").value = window.opener.document.getElementById("txtPort").value;
		document.getElementById("txtUser").value = window.opener.document.getElementById("txtUser").value;
		document.getElementById("txtPWD").value = window.opener.document.getElementById("txtPWD").value;
		document.getElementById("IsPwdChanged").value = window.opener.document.getElementById("IsPwdChanged").value;
		document.getElementById("chkFRorWR").value = "0";
		document.getElementById("CCFRTest").value = "1";
		document.getElementById("txtAddFRServerPortHidden").value = document.getElementById("txtAddFRServerPort").value;
		document.getElementById("txtAddWRServerPortHidden").value = document.getElementById("txtAddWRServerPort").value;
		if(document.getElementById("chkAddSslEnabled").checked)
			document.getElementById("chkAddSslEnabledHidden").value = "1";
		else
			document.getElementById("chkAddSslEnabledHidden").value = "0";
		
		document.fmMain.btnTest.disabled = true;
		document.fmMain.FormAction.value="testConnection";
		jsAddCSRFToken(document.fmMain);
    document.fmMain.submit();
		document.getElementById("icon_progress").src = "images/icon_inProgress.gif";
	}
}

function jsTestWRConnection()
{
	if(verifyServerName(document.getElementById("txtAddServerName").value)
	&& checkPortRange(document.getElementById("txtAddWRServerPort").value,STR_ERR_INVALID_PORT)){
		var succeed = document.getElementById("TestConn_Succeed");
		var fail = document.getElementById("TestConn_Fail");
		var progress = document.getElementById("TestConn_Progress");
		succeed.style.display="none";
		fail.style.display="none";
		progress.style.display="block";
		
		document.getElementById("chkEnable").checked = window.opener.document.getElementById("chkEnable").checked;
		document.getElementById("txtAddr").value = window.opener.document.getElementById("txtAddr").value;
		document.getElementById("txtPort").value = window.opener.document.getElementById("txtPort").value;
		document.getElementById("txtUser").value = window.opener.document.getElementById("txtUser").value;
		document.getElementById("txtPWD").value = window.opener.document.getElementById("txtPWD").value;
		document.getElementById("IsPwdChanged").value = window.opener.document.getElementById("IsPwdChanged").value;
		document.getElementById("chkFRorWR").value = "1";
		document.getElementById("LWCSTest").value = "1";
		document.getElementById("txtAddFRServerPortHidden").value = document.getElementById("txtAddFRServerPort").value;
		document.getElementById("txtAddWRServerPortHidden").value = document.getElementById("txtAddWRServerPort").value;
		if(document.getElementById("chkAddSslEnabled").checked)
			document.getElementById("chkAddSslEnabledHidden").value = "1";
		else
			document.getElementById("chkAddSslEnabledHidden").value = "0";
		
		document.fmMain.btnTest.disabled = true;
		document.fmMain.FormAction.value="testConnection";
		jsAddCSRFToken(document.fmMain);
        document.fmMain.submit();
		document.getElementById("icon_progress").src = "images/icon_inProgress.gif";
	}
}



function isUniqueServerName(serverName){
	var isExsited = false;
	var server_list = window.opener.getServerNameList();
	if(server_list != null){
		for(var i=0; i<server_list.length; i++){
			if(serverName == server_list[i]){
				isExsited = true;
				break;
			}
		}
		if(isExsited){
			alert(STR_ALERT_SMART_SERVER_ADD_EXP);
			document.fmMain.txtAddServerName.focus();
			document.fmMain.txtAddServerName.select();
			return false;
		}
	}
	return true;
}


function isLessThanMax()
{
	var server_list = window.opener.getServerNameList();
	var server_list_length = server_list.length;
	if(server_list_length <= INT_LMAX_SMART_LIST){
		return true;
	}
	else{
		alert (STR_ERR_SMART_LIST_FULL);
		return false;
	}
}

function verifyServerName (serverName) {
	if(serverName == '' || (!checkEmailPatternFormat(serverName,"") && !checkIPAddressFormat(serverName,"") && !checkIsIPv6Address(serverName))
		|| serverName.length>127){
		alert(STR_ERR_INVALID_IPADDRESS_OR_DOMAIN);
		document.fmMain.txtAddServerName.focus();
		document.fmMain.txtAddServerName.select();
		return false;
	}
		return true;
}

function enableCCFRfunc()
{
	if(document.getElementById("chkEnableCCFR").checked == false)
	{
		document.getElementById("txtAddFRServerPort").disabled 	= true;
		document.getElementById("chkAddSslEnabled").disabled 	= true;
		document.getElementById("btnTest").disabled 			= true;
	}
	else
	{
		document.getElementById("txtAddFRServerPort").disabled 	= false;
		document.getElementById("chkAddSslEnabled").disabled 	= false;
		document.getElementById("btnTest").disabled 			= false;	
	}
}

function enableLWCSfunc()
{
	if(document.getElementById("chkEnableLWCS").checked == false)
	{
		document.getElementById("txtAddWRServerPort").disabled 	= true;
		document.getElementById("btnLwcsTest").disabled 		= true;
	}
	else
	{
		document.getElementById("txtAddWRServerPort").disabled 	= false;
		document.getElementById("btnLwcsTest").disabled 		= false;	
	}		
}
</script>
</head>

<body onLoad="jsInitPage();">
<form id="fmMain" name="fmMain" action="$$FORM_ACTION$$" method="post">


  <!--Hidden Field-->
  <input type="hidden" name="FormAction" id="FormAction">
  
  
  <input type=checkbox id="chkEnable" name="chkProxyEnable" style="display:none">
  <input type="hidden" id="txtAddr" name="txtAddr">
  <input type="hidden" id="txtPort" name="txtPort">
  <input type="hidden" id="txtUser" name="txtUser">
  <input type="hidden" id="txtPWD" name="txtPassword">
  <input type="hidden" id="txtAddFRServerPortHidden" name="txtAddFRServerPortHidden">
  <input type="hidden" id="txtAddWRServerPortHidden" name="txtAddWRServerPortHidden">
  <input type="hidden" id="chkAddSslEnabledHidden" name="chkAddSslEnabledHidden">
  <input type="hidden" name="IsPwdChanged" value="false" id="IsPwdChanged">
  <input type="hidden" name="chkFRorWR" value="false" id="chkFRorWR">
  <input type="hidden" name="CCFRTest" value="$$IS_CCFR_STATUS_OK$$" id="CCFRTest">
  <input type="hidden" name="LWCSTest" value="$$IS_LWCS_STATUS_OK$$" id="LWCSTest">
  <input type="hidden" name="needRefresh" value="$$NEED_REFRESH$$" id="needRefresh">
  
  <!--/Hidden Field-->
  <table cellspacing="0" cellpadding="0" width="580" border="0">
  <tr>
    <td class="content-title">Add Smart Protection Server </td>
    <td align="right" valign="bottom">
		<a href="javascript:jsMapOnlineHelp('scan\smart_source_add.htm');" class="moretestblue">
		<img src="images/question.gif" class="vAlignMid"> Help</a></td>
  </tr>
  <tr>
    <td colspan="2" class="hor-dotted-line"><img src="images/1space_cui.gif" width="1" height="10" /></td>
  </tr>
  <tr><td colspan="2" height="1" background="images/dot.gif"></td></tr>
  <!--tr>
    <td colspan="2" class="data1">Smart Scan Source &gt; Add Smart Protection  Server</td>
  </tr-->
  <tr>
    <td height="10" colspan="2"><img src="/images/1space_cui.gif" width="1" height="10" /></td>
  </tr>
</table>

<table>
<tbody>
 <tr id="TestConn_Progress" style="display:$$TESTCONN_PROGRESS_DISPLAY$$" > <td colspan="3" >
<table width="580" border="0" cellspacing="0" cellpadding="0" class="fade" id="msg" style="background-color:#f2ebb0">
        <tr>
          <td width="1%"><img src="images/white_top_left.gif" width="7" height="7" alt="" /></td>
          <td colspan="4"></td>
          <td width="1%"><img src="images/white_top_right.gif" width="7" height="7" alt="" /></td>
        </tr>
		
        <tr>
          <td><img src="../images/1space_cui.gif" width="1" height="1" alt="" /></td>
          <td width="4%" style="padding:5px">&nbsp;</td>
          <td width="46%" class="fade1"><img id="icon_progress" src="images/icon_inProgress.gif" width="418" height="25">          </td>
          <td width="46%" class="fade1"><strong> Testing... </strong></td>
          <td width="2%" align="right" valign="top"><a href="#"></a></td>
          <td><img src="../images/1space_cui.gif" width="1" height="1" alt="" /></td>
        </tr>     
		
        <tr>
          <td><img src="images/white_bottom_left.gif" width="7" height="7" alt="" /></td>
          <td colspan="4"><img src="../images/1space_cui.gif" width="1" height="1" alt="" /></td>
          <td><img src="images/white_bottom_right.gif" width="7" height="7" /></td>
        </tr>
      </table>
	<br>
</td>
</tr>

<tr id="TestConn_Succeed" style="display:$$TESTCONN_SUCCEED_DISPLAY$$"> <td colspan="3">
<table cellspacing="0" cellpadding="0" border="0" width="580" style="background-color: rgb(242, 235, 176);" id="msg" class="fade">
        <tbody><tr>
          <td width="1%"><img height="7" width="7" alt="" src="images/white_top_left.gif"></td>
          <td colspan="3"></td>
          <td width="1%"><img height="7" width="7" alt="" src="images/white_top_right.gif"></td>
        </tr>
        <tr>
          <td><img height="1" width="1" alt="" src="../images/1space_cui.gif"></td>
          <td width="4%" style="padding: 5px;"><img height="25" align="absmiddle" width="25" alt="Confirmation icon" src="images/icon_valid.gif"></td>
          <td width="92%" class="fade1"><p>Successfully connected to the smart protection server </p>            </td>
          <td align="right" width="2%" valign="top"><a onClick="Javascript:document.getElementById('TestConn_Succeed').style.display = 'none'" href="#"><img height="15" border="0" width="15" title="Close message box." alt="Close icon" src="images/icon_theader_close.gif"></a></td>
          <td><img height="1" width="1" alt="" src="../images/1space_cui.gif"></td>
        </tr>
        
        <tr>
          <td><img height="7" width="7" alt="" src="images/white_bottom_left.gif"></td>
          <td colspan="3"><img height="1" width="1" alt="" src="../images/1space_cui.gif"></td>
          <td><img height="7" width="7" src="images/white_bottom_right.gif"></td>
        </tr>
      </tbody></table>
	  <br>
</td>
</tr>

<tr id="TestConn_Fail" style="display:$$TESTCONN_FAIL_DISPLAY$$"> <td colspan="3">
<table cellspacing="0" cellpadding="0" border="0" width="580" style="background-color: rgb(242, 235, 176);" id="msg" class="fade">
        <tbody><tr>
          <td width="1%"><img height="7" width="7" alt="" src="images/white_top_left.gif"></td>
          <td colspan="3"></td>
          <td width="1%"><img height="7" width="7" alt="" src="images/white_top_right.gif"></td>
        </tr>
        <tr>
          <td><img height="1" width="1" alt="" src="../images/1space_cui.gif"></td>
          <td width="4%" style="padding: 5px;"><img height="25" align="absmiddle" width="25" alt="Confirmation icon" src="images/icon_expired.gif"></td>
          <td width="92%" class="fade1"><p>Failed to connect to the smart protection server </p>            </td>
          <td align="right" width="2%" valign="top"><a onClick="Javascript:document.getElementById('TestConn_Fail').style.display= 'none'" href="#"><img height="15" border="0" width="15" title="Close message box." alt="Close icon" src="images/icon_theader_close.gif"></a></td>
          <td><img height="1" width="1" alt="" src="../images/1space_cui.gif"></td>
        </tr>
        
        <tr>
          <td><img height="7" width="7" alt="" src="images/white_bottom_left.gif"></td>
          <td colspan="3"><img height="1" width="1" alt="" src="../images/1space_cui.gif"></td>
          <td><img height="7" width="7" src="images/white_bottom_right.gif"></td>
        </tr>
      </tbody></table>
	  <br>
</td>
</tr>
</tbody>
</table>


<table width="580" border="0" cellspacing="0" cellpadding="0">
  
  <tr>
    <td height="10" colspan="2" ><TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
        <tr>
          <TD  vAlign=top width="100%"><table cellpadding="0" cellspacing="0" border="0" width="100%">
              
              <tr>
                <td colspan="2" align="left" class="border"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                  <tr>
                    <td colspan="2" class="tableheadergreyS">Smart Protection  Server </td>
                  </tr>
				  <tr>
                    <td height="5" colspan="2"><img src="images/1space_cui.gif" width="1" height="5" /></td>
                  </tr>
				   <tr>
				  
                    <td height="20" colspan="2" class="data1">To obtain a Smart Protection Server address, open the console of the server, and navigate to the Summary page.</td>
                    </tr>
                  <tr>
                    <td width="19%" nowrap="nowrap" class="data1">Server name or address:</td>
                    <td width="81%"  class="data1"><input type="text" id="txtAddServerName" class="button" name="txtAddServerName" value="$$ADD_SERVER_NAME$$"></td>
					<td style="display:none"><input type="text" id="boolFRStatus" class="button" name="boolFRStatus" value="$$CURRENT_FR_SERVER_STATUS$$"></td>
					<td style="display:none"><input type="text" id="boolWRStatus" class="button" name="boolWRStatus" value="$$CURRENT_WR_SERVER_STATUS$$"></td>
					<td style="display:none"><input type="text" id="boolWRIsGlobal" class="button" name="boolWRIsGlobal" value="$$CURRENT_WR_ISGLOBAL$$"></td>
                  </tr>
                  <tr>
                    <td class="data1" nowrap="nowrap">&nbsp;</td>
                    <td class="data1"> Example: server1.us.trendnet.org or 10.1.1.1</td>
                  </tr>
                  <tr>
                    <td class="data1" nowrap="nowrap">
                    <input type="checkbox" id="chkEnableCCFR" name="chkEnableCCFR" value="checkbox" onClick="enableCCFRfunc()" $$IS_CCFR_ENABLED$$>&nbsp;
                    File Reputation service port:</td>
                    <td class="data1"><input name="txtAddFRServerPort" id="txtAddFRServerPort" type="text" class="button" value="$$ADD_FR_SERVER_PORT$$" size="10"></td>
                  </tr>
                  <tr>
                    <td class="data1" nowrap="nowrap"><span ><span>
                      </span></span></td>
                    <td class="data1"><span ><span>
					   <input type="checkbox" id="chkAddSslEnabled" name="chkAddSslEnabled" value="checkbox" $$ADD_SERVER_SSL_ENABLED$$>
SSL </span></span></td>
                  </tr>
                  <tr>
                    <td height="10" colspan="2"><img src="images/1space_cui.gif" width="1" height="10" /></td>
                  </tr>
                  <tr align="center">
                     <td nowrap="nowrap" class="data1"><span ><span>
                      </span></span>                     </td>
                  <td align="left" nowrap="nowrap" class="data1">
				  <input name="btnTest" type="button" class="button" id="btnTest" value="Test File Reputation Service Connection" onClick="jsTestFRConnection()" style="width:250px" ></td>
                  </tr>
                  <tr>
                    <td height="10" colspan="2"><img src="images/1space_cui.gif" width="1" height="10" /></td>
                  </tr>
				  <tr>
                    <td class="data1" nowrap="nowrap">
                     <input type="checkbox" id="chkEnableLWCS" name="chkEnableLWCS" value="checkbox" onClick="enableLWCSfunc()" $$IS_LWCS_ENABLED$$>&nbsp;
                    Web Reputation service port:</td>
                    <td class="data1"><input name="txtAddWRServerPort" id="txtAddWRServerPort" type="text" class="button" value="$$ADD_WR_SERVER_PORT$$" size="10"></td>
                  </tr>
				  <tr>
                    <td height="10" colspan="2"><img src="images/1space_cui.gif" width="1" height="10" /></td>
                  </tr>
				  <tr align="center">
                     <td nowrap="nowrap" class="data1"><span ><span>
                      </span></span>                     </td>
                  <td align="left" nowrap="nowrap" class="data1">
				  <input name="btnLwcsTest" type="button" class="button" id="btnLwcsTest" value="Test Web Reputation Service Connection" onClick="jsTestWRConnection()" style="width:250px" ></td>
                  </tr>
                  <tr>
                    <td height="10" colspan="2"><img src="images/1space_cui.gif" width="1" height="10" /></td>
                  </tr>
                </table></td>
              </tr>
            </table></TD>
        </TR>
      </TABLE></td>
  </tr>
</table>
<table width="540" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="28" valign="bottom"> <input type="button" class="text" name="btnSave" id="btnSave" value="Add" style="width:50px" onClick="jsSubmit();">  <input type="button" class="text"  name="Cancel" value="Cancel" style="width:50px" onClick="jsCancel();">
	
    </td>
  </tr>
</table>
<br />
</form>
</body>
</html>
