var userName =$("input[name=publishDomain.userName]").val();
var passWord =$("input[name=publishDomain.passWord]").val();
var publishPath =$("input[name=publishDomain.publishPath]").val();
var url ='../SysManage/checkPublishDomain.action?ts=' + new Date().getTime()+'&publishDomain.ip='+ip+'&publishDomain.userName='+userName+'&publishDomain.passWord='+passWord+'&publishDomain.publishPath='+publishPath;
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="page" uri="/WEB-INF/tlds/paginated.tld"%>
<%@ taglib prefix="priveliege" uri="/WEB-INF/tlds/priveliege.tld"%>
<%@ taglib uri="/WEB-INF/tlds/pageShow.tld" prefix="pageShow" %>
<%@ include file="../common/language.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>choose_path</title>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../jsCBB/jquery.js"></script>
<link href="../style/base.css" rel="stylesheet" type="text/css" />
<%@ include file="../common/commonJS.jsp" %>
<script type="text/javascript" src="../js/Calendar/WdatePicker.js"></script>
<script type="text/javascript" src="../jsCBB/jquery.validate.js"></script>
<script type="text/javascript" src="../js/ex.jquery.validate.js"></script>
<script type="text/javascript" src="../js/dialogShow.js"></script>
<script type="text/javascript" src="../js/shelfmanage.js"></script>
<script type="text/javascript" src="../js/ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../js/ext/ext-all.js"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript">
//防重复提交按键功能
var timerID;
function activethis(){
timerID=setTimeout('document.getElementById("showButton").disabled=false',1000);
$("#showButton").submit();
}
jQuery(document).ready(function() {
$.validator.setDefaults({
submitHandler: function(form) {
//恢复提交按键功能
clearTimeout(timerID);
document.getElementById("showButton").disabled=true;
var ip = $("input[name=publishDomain.ip]").val();
var userName =$("input[name=publishDomain.userName]").val();
var passWord =$("input[name=publishDomain.passWord]").val();
var publishPath =$("input[name=publishDomain.publishPath]").val();
var url ='../SysManage/checkPublishDomain.action?ts=' + new Date().getTime()+'&publishDomain.ip='+ip+'&publishDomain.userName='+userName+'&publishDomain.passWord='+passWord+'&publishDomain.publishPath='+publishPath;
checkPublishDomain(url);
/*Ext.Ajax.request({
timeout: 100000,//超时时间100�?
url:'../SysManage/checkPublishDomain.action',
params:{'publishDomain.ip':ip,'publishDomain.userName':userName,'publishDomain.passWord':passWord,'publishDomain.publishPath':publishPath},
success: function(_response, action) {
if(_response.responseText=='ok'){
showConfirmAndCancel('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.sysmgr.publishDomain.manage.yes"/>',form);
}
else{
showConfirmAndCancel('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.sysmgr.publishDomain.manage.no"/>',form);
}
},
failure: function(_response, action) {
var reqst=_response.status; // 根据返回的状态码值判断是否超�?
if(reqst=='-1'){ // 超时的状态码�?-1
showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.system.error.overtime"/>',400,200,0,true);
}
else
{
showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.failured.message.tip"/>',400,200,0,true);
}
}
});*/
}
});
$("#addPublishDomain").validate({
rules: {
"publishDomain.name":{
required: true,
maxlength:32
},
"publishDomain.ip":{
required: true,
checkIp:true,
regexMatch: "^(((2[0-4]\\d)|(25[0-5]))|(1\\d{2})|([1-9]\\d)|(\\d))[.](((2[0-4]\\d)|(25[0-5]))|(1\\d{2})|([1-9]\\d)|(\\d))[.](((2[0-4]\\d)|(25[0-5]))|(1\\d{2})|([1-9]\\d)|(\\d))[.](((2[0-4]\\d)|(25[0-5]))|(1\\d{2})|([1-9]\\d)|(\\d))$"
},
"publishDomain.type":{
required: true
},
"publishDomain.userName":{
required: true,
regexMatch:"^[a-zA-Z0-9_]+$",
maxlength:32
},
"publishDomain.passWord":{
required: true,
maxlength:128
},
"publishDomain.repassWord":{
required: true,
equalTo:"#passWord"
},
"publishDomain.publishPath":{
required: true,
regexMatch:"^[a-zA-Z0-9/._-]+$",
maxlength:256
},
"publishDomain.remark":{
maxlength:1024
}
},
messages: {
"publishDomain.name":{
required:'<s:text name="msg.portalMS.publishmgr.name.required" />',
maxlength: '<s:text name="msg.portalMS.publishmgr.name.lenthvalid" />'
},
"publishDomain.ip":{
required:'<s:text name="msg.portalMS.publishmgr.ip.required" />',
regexMatch:'<s:text name="msg.portalMS.publishmgr.ip.valid" />'
},
"publishDomain.type":{
required: '<s:text name="msg.portalMS.publishmgr.type.required" />'
},
"publishDomain.userName":{
required: '<s:text name="msg.portalMS.publishmgr.userName.required" />',
regexMatch:'<s:text name="msg.portalMS.publishmgr.userName.valid" />',
maxlength:'<s:text name="msg.portalMS.publishmgr.userName.lenthvalid" />'
},
"publishDomain.passWord":{
required: '<s:text name="msg.portalMS.publishmgr.passWord.required" />',
maxlength:'<s:text name="msg.portalMS.publishmgr.password.lenthvalid" />'
},
"publishDomain.repassWord":{
required: '<s:text name="msg.portalMS.publishmgr.repassWord.required" />',
equalTo:'<s:text name="msg.portalMS.publishmgr.repassWord.valid" />'
},
"publishDomain.publishPath":{
required:'<s:text name="msg.portalMS.publishmgr.publishPath.required" />',
regexMatch:'<s:text name="msg.portalMS.publishmgr.path.valid" />',
maxlength:'<s:text name="msg.portalMS.publishmgr.path.lenthvalid" />'
},
"publishDomain.remark":{
maxlength:'<s:text name="msg.portalMS.publishmgr.remark.lenthvalid" />'
}
},
errorPlacement: function(error, element) {
if(element.next().get(0)!=null){
if(element.next().get(0).tagName == "FONT"){
element.next().hide();
}else if(element.next().get(0).tagName == "A"){
element.next().show();
element.next().next().hide();
}else if(element.next().get(0).tagName == "SPAN"){
element.next().hide();
element.next().next().hide();
}else{
element.next().show();
}
}
error.appendTo( element.parent() );
}
});
});
//ajax校验IP
$.validator.addMethod("checkIp",function(ip){
var cityId = document.getElementById("publishDomain.cityId").value;
var type = document.getElementById("publishDomain.type").value;
var result = true;
$.ajax({
cache:false,
async:false,
type:"POST",
url: "../SysManage/checkIp.action?publishDomain.cityId="+cityId+"&publishDomain.type="+type,
data: "publishDomain.ip="+ip,
success: function(checkFlag){
if(checkFlag=='false'){
result = false;
}else{
result = true;
}
}
});
return result;
},'<font color="red"><s:text name="msg.portalMS.publishmgr.ip.existed" /></font>');
//返回服务域列�?
function viewPublishDomain(){
var type = document.getElementById("publishDomain.type").value;
var url;
if(5==type)
{
url= "viewPublishDomain.action?action=template";
}
else{
url= "viewPublishDomain.action";
}
window.location=url;
}
function checkPublishDomain(url)
{
$.ajax({
url: url,
type: 'POST',
success: function(data){
{
//恢复提交按键功能
var form = document.forms["addPublishDomain"]
if(data=='ok')
{
showConfirmAndCancel('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.sysmgr.publishDomain.manage.yes"/>',form);
document.getElementById("showButton").disabled=false;
}
else
{
showConfirmAndCancel('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.sysmgr.publishDomain.manage.no"/>',form);
document.getElementById("showButton").disabled=false;
}
}
},
error: function(){
showText('<s:text name="msg.portalMS.page.message.tip"/>','<s:text name="msg.portalMS.failured.message.tip"/>',400,200,0,true);
//恢复提交按键功能
document.getElementById("showButton").disabled=false;
}
});
return false;
}
</script>
</head>
<body>
<s:hidden name="publishDomain.cityId" id="publishDomain.cityId" ></s:hidden>
<s:hidden name="publishDomain.cityName" id="publishDomain.cityName" ></s:hidden>
<div class="r_main">
<!---导航 --->
<div class="r_nav"><div class="left"><img src="../images/nav_l.gif" width="5" height="29" /></div>
<div class="ct"><s:text name="msg.portalMS.rolemgr.current.position" />
<s:if test="publishDomain.type == 5">
<s:text name="msg.portalMS.template.manager" /> > <s:text name="msg.portalMS.template.sync.server" /> > <s:text name="msg.portalMS.template.syncServer.add" />
</s:if>
<s:else>
<s:text name="msg.portalMS.publishmgr.label.publish.manage" /> > <s:text name="msg.portalMS.sysmgr.publishDomain.manage.name" /> > <s:text name="msg.portalMS.sysmgr.publishDomain.manage.add" />
</s:else>
</div>
<div class="right"><img src="../images/nav_r.jpg" width="5" height="29" /></div>
</div>
<div class="info_tit">
<div class="left"><s:text name="msg.portalMS.sysmgr.publishDomain.manage.add" /></div>
</div>
<div class="page_tb">
<s:form theme="simple" validate="false" action="addPublishDomain" namespace="/SysManage" >
<s:hidden name="publishDomain.domainId" />
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="in_table long">
<tr>
<td class="col1 must"><s:text name="msg.portalMS.sysmgr.publishDomain.name" /><s:text name="msg.portalMS.colon.label" /></td>
<td>
<s:textfield name="publishDomain.name" theme="simple" cssStyle="color: black;"/>
<font color='gray'> <s:text name="msg.portalMS.publishmgr.name.lenthvalid" /></font>
</td>
</tr>
<tr class="bule">
<td class="col1 must1"><s:text name="msg.portalMS.sysmgr.publishDomain.ip" /><s:text name="msg.portalMS.colon.label" /></td>
<td>
<s:textfield name="publishDomain.ip" theme="simple" cssStyle="color: black;"/>
<s:fielderror fieldName="publishDomain.ip" cssStyle="color:red" theme="simple"/>
<font color='gray'> <s:text name="msg.portalMS.publishmgr.ip.valid" /></font>
</td>
</tr>
<s:if test="publishDomain.type==5">
<s:hidden id="publishDomain.type" name="publishDomain.type"/>
<tr>
<td class="col1 must"><s:text name="msg.portalMS.sysmgr.publishDomain.charSet" /><s:text name="msg.portalMS.colon.label" /></td>
<td width="84%"><s:select name="publishDomain.charSet"
list="#{'UTF-8':getText('msg.portalMS.sysmgr.publishDomain.charSet.utf8'),'GBK':getText('msg.portalMS.sysmgr.publishDomain.charSet.gbk'),'GB2312':getText('msg.portalMS.sysmgr.publishDomain.charSet.gb2312')}"
theme="simple" listKey="key" listValue="value"
cssStyle="color:black" /></td>
</tr>
</s:if>
<s:else>
<tr>
<td class="col1 must"><s:text name="msg.portalMS.sysmgr.publishDomain.type" /><s:text name="msg.portalMS.colon.label" /></td>
<td>
<s:select name="publishDomain.type" id="publishDomain.type" list="#{
'':getText('msg.portalMS.system.select.default'),
'0':getText('msg.portalMS.sysmgr.publishDomain.keyDateType.label.zero'),
'1':getText('msg.portalMS.sysmgr.publishDomain.keyDateType.label.one')}"
theme="simple" listKey="key" listValue="value" cssStyle="color: black;"/>
<font color='gray'> </font>
</td>
</tr>
</s:else>
<tr class="bule">
<td class="col1 must1"><s:text name="msg.portalMS.sysmgr.publishDomain.userName" /><s:text name="msg.portalMS.colon.label" /></td>
<td>
<s:textfield name="publishDomain.userName" theme="simple" cssStyle="color: black;" />
<font color='gray'> <s:text name="msg.portalMS.publishmgr.userName.valid" /></font></td>
</tr>
<tr>
<td class="col1 must"><s:text name="msg.portalMS.sysmgr.publishDomain.passWord" /><s:text name="msg.portalMS.colon.label" /></td>
<td>
<s:password name="publishDomain.passWord" theme="simple" cssStyle="color: black;width:150px" id="passWord" />
<font color='gray'> </font></td>
</tr>
<tr class="bule">
<td class="col1 must1"><s:text name="msg.portalMS.sysmgr.publishDomain.repassWord" /><s:text name="msg.portalMS.colon.label" /></td>
<td>
<s:password name="publishDomain.repassWord" theme="simple" cssStyle="color: black;width:150px" />
<font color='gray'> </font></td>
</tr>
<tr>
<td class="col1 must"><s:text name="msg.portalMS.sysmgr.publishDomain.publishPath" /><s:text name="msg.portalMS.colon.label" /></td>
<td>
<s:textfield name="publishDomain.publishPath" theme="simple" cssStyle="color: black;" size="65"/>
<font color='gray'> <s:text name="msg.portalMS.publishmgr.path.valid" /> </font></td>
</tr>
<tr class="bule">
<td class="col1"><s:text name="msg.portalMS.sysmgr.publishDomain.remark" /><s:text name="msg.portalMS.colon.label" /></td>
<td>
<s:textarea name="publishDomain.remark" theme="simple" cols="70" rows="5" cssStyle="color: black;" />
<font color='gray'> </font></td>
</tr>
<pageShow:pageShow tag="common.cityCode">
<tr>
<td class="col1"><s:text name="msg.portalMS.system.city"/><s:text name="msg.portalMS.colon.label" /></td>
<td>
<s:property value="publishDomain.cityName" />
</td>
</tr>
</pageShow:pageShow>
</table>
<div class="info">
<priveliege:priveliege funCode="addPublishDomain">
<input id="showButton" οnclick="this.disabled=true;activethis();" type="submit" value="<s:text name="msg.portalMS.confirmButton" />"/>
</priveliege:priveliege>
<button type="reset" id="resetRole" οnclick="viewPublishDomain();setTimeout(function(){load()},tipTime);"><s:text name="msg.portalMS.returnBack" /></button>
</div>
</s:form>
</div>
</div>
</body>
</html>
/**
* 校验服务域可用性
*/
@Override
public boolean scpPublishDomain(PublishDomain publishDomain)
{
SCPClient client = null;
Connection conn = null;
try
{
String host = publishDomain.getIp();
int timeOut = 3000; // 设置ping的超时时间3秒
boolean status = InetAddress.getByName(host).isReachable(timeOut);
if (!status)
{
return false;
}
conn = new Connection(host);
conn.connect();
boolean isAuthenticated = conn.authenticateWithPassword(publishDomain.getUserName(), publishDomain
.getPassWord());
if (!isAuthenticated)
{
return false;
}
client = new SCPClient(conn);
client.put(filePath, publishDomain.getPublishPath());
}
catch (Exception e)
{
log.error("connect the ip failed", e);
return false;
}
finally
{
if (conn != null)
{
conn.close();
}
}
return true;
}
package com.xxxxxx.dhm.portalMS.system.service.impl;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.SCPClient;
import com.xxxxxx.dhm.portalMS.base.service.impl.Service;
import com.xxxxxx.dhm.portalMS.common.Constants;
import com.xxxxxx.dhm.portalMS.common.util.PageList;
import com.xxxxxx.dhm.portalMS.exception.PortalMSException;
import com.xxxxxx.dhm.portalMS.system.dao.IPublishDomainDAO;
import com.xxxxxx.dhm.portalMS.system.dao.IPublishDomainMapGroupDAO;
import com.xxxxxx.dhm.portalMS.system.entity.PublishDomain;
import com.xxxxxx.dhm.portalMS.system.entity.PublishDomainMapGroup;
import com.xxxxxx.dhm.portalMS.system.service.IPublishDomainService;
import com.xxxxxx.dhm.portalMS.template.dao.ITemplateDAO;
public class PublishDomainServiceImpl extends Service implements IPublishDomainService
{
private static final long serialVersionUID = 2800487833994807143L;
private static final Logger log = Logger.getLogger(PublishDomainServiceImpl.class);
final static String filePath = PublishDomainServiceImpl.class.getResource("").getFile()
+ "PublishDomainServiceImpl.class";
/**调用PublishDomainDAO接口*/
private IPublishDomainDAO publishDomainDAO;
private ITemplateDAO templateDAO;
private IPublishDomainMapGroupDAO publishDomainMapGroupDAO;
/**
* 根据ip查询服务域信息
*/
public PublishDomain getPublishDomainByIp(PublishDomain publishDomain)
{
Map<String, Object> params = new HashMap<String, Object>();
params.put("ip", publishDomain.getIp());
params.put("cityId", publishDomain.getCityId());
if (null != publishDomain.getType() && 5 == publishDomain.getType())
{
params.put("type", publishDomain.getType());
}
return publishDomainDAO.getPublishDomainBy(params);
}
/**
* 通过ip和id获取到服务域的信息,
* 返回true,则表示输入的ip已经存在数据库中,此时要在页面上提示“ip已经存在”。
* 返回false,则表示输入的ip不存在。
*/
public boolean existsPublishDomainBy(PublishDomain publishDomain)
{
Map<String, Object> params = new HashMap<String, Object>();
params.put("ip", publishDomain.getIp());
params.put("cityId", publishDomain.getCityId());
if (null != publishDomain.getType() && 5 == publishDomain.getType())
{
params.put("type", publishDomain.getType());
}
PublishDomain publish = this.publishDomainDAO.getPublishDomainBy(params);
if (publish != null && publishDomain.getDomainId().longValue() != publish.getDomainId().longValue())
{
return true;
}
else
{
return false;
}
}
// 判断下列服务域是否有服务组关联
public boolean isPublishDomainMapGroup(Long[] domainIds) throws PortalMSException
{
List<PublishDomainMapGroup> publishDomainMapGroup = this.publishDomainMapGroupDAO
.findPublishDomainMapGroupByDomainId(Arrays.asList((Long[]) domainIds));
// 如果在关联关系表没有该服务域的id则返回true否则返回false。
if (publishDomainMapGroup == null || publishDomainMapGroup.size() == 0)
{
return true;
}
else
{
return false;
}
}
/**
* 删除服务域信息
*/
public void batchDelete(final Long[] domainIds) throws PortalMSException
{
publishDomainDAO.batchDelete(domainIds);
//删除该门户的同步日志记录
templateDAO.delTemplateSyncLogBatch(Arrays.asList(domainIds), Constants.SYNC_LOG_IDS.getIntValue());
}
/**
* 校验服务域可用性
*/
@Override
public boolean scpPublishDomain(PublishDomain publishDomain)
{
SCPClient client = null;
Connection conn = null;
try
{
String host = publishDomain.getIp();
int timeOut = 3000; // 设置ping的超时时间3秒
boolean status = InetAddress.getByName(host).isReachable(timeOut);
if (!status)
{
return false;
}
conn = new Connection(host);
conn.connect();
boolean isAuthenticated = conn.authenticateWithPassword(publishDomain.getUserName(), publishDomain
.getPassWord());
if (!isAuthenticated)
{
return false;
}
client = new SCPClient(conn);
client.put(filePath, publishDomain.getPublishPath());
}
catch (Exception e)
{
log.error("connect the ip failed", e);
return false;
}
finally
{
if (conn != null)
{
conn.close();
}
}
return true;
}
/**
* 根据服务域组ID来查询关联的服务域
* @return
* @throws PortalMSException
*/
public List<PublishDomain> queryPublishDomainByGroupId(Long groupId) throws PortalMSException
{
return publishDomainMapGroupDAO.queryPublishDomainByGroupId(groupId);
}
@SuppressWarnings("unchecked")
@Override
public PageList findRecord(String mapsql, Object map, int currPage, int pageSize) throws PortalMSException
{
return (PageList) publishDomainDAO.findRecord(mapsql, map, currPage, pageSize);
}
public void setPublishDomainDAO(IPublishDomainDAO publishDomainDAO)
{
this.publishDomainDAO = publishDomainDAO;
}
public void setPublishDomainMapGroupDAO(IPublishDomainMapGroupDAO publishDomainMapGroupDAO)
{
this.publishDomainMapGroupDAO = publishDomainMapGroupDAO;
}
/* (non-Javadoc)
* @see com.xxxxxx.dhm.portalMS.system.service.IPublishDomainService#findTemplateViewServer()
*/
@Override
public PublishDomain findTemplateViewServer() throws PortalMSException
{
// TODO Auto-generated method stub
return this.publishDomainDAO.findTemplateViewServer();
}
/* (non-Javadoc)
* @see com.xxxxxx.dhm.portalMS.system.service.IPublishDomainService#findPublishDomainByParmeter(com.xxxxxx.dhm.portalMS.system.entity.PublishDomain)
*/
@Override
public List<PublishDomain> findPublishDomainByParmeter(
PublishDomain publishDomain) throws PortalMSException
{
// TODO Auto-generated method stub
return this.publishDomainDAO.findPublishDomainByParmeter(publishDomain);
}
/**
* @param templateDAO the templateDAO to set
*/
public void setTemplateDAO(ITemplateDAO templateDAO)
{
this.templateDAO = templateDAO;
}
/**
* @return the templateDAO
*/
public ITemplateDAO getTemplateDAO()
{
return templateDAO;
}
}