协议IP配置增加导入功能

This commit is contained in:
zhangwei
2018-06-11 10:58:06 +08:00
parent 0852cfdef9
commit ed6e14150f
14 changed files with 986 additions and 25 deletions

View File

@@ -0,0 +1,63 @@
/**
*
*/
package com.nis.domain;
import java.io.Serializable;
/**
* @ClassName:ImportErrorInfo
* @Description:TODO(这里用一句话描述这个类的作用)
* @author (zdx)
* @date 2018年4月25日 上午10:39:47
* @version V1.0
*/
public class ImportErrorInfo implements Serializable{
private static final long serialVersionUID = -8044793465646498657L;
private String rowNum;
private String fieldName;
private String errorMessage;
public ImportErrorInfo() {
super();
// TODO Auto-generated constructor stub
}
/**
* @param rowNum 行号
* @param fieldName 属性名称
* @param errorMessage 错误信息
*/
public ImportErrorInfo(String rowNum, String fieldName, String errorMessage) {
super();
this.rowNum = rowNum;
this.fieldName = fieldName;
this.errorMessage = errorMessage;
}
public String getRowNum() {
return rowNum;
}
public void setRowNum(String rowNum) {
this.rowNum = rowNum;
}
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
@Override
public String toString() {
return "ImportErrorInfo [rowNum=" + rowNum + ", fieldName=" + fieldName
+ ", errorMessage=" + errorMessage + "]";
}
}

View File

@@ -8,6 +8,7 @@ import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.nis.domain.BaseEntity;
import com.nis.domain.SysUser;
import com.nis.util.excel.ExcelField;
/**
* 系统特定服务信息表-记录特定服务信息(specific_service_cfg)
@@ -20,6 +21,7 @@ public class SpecificServiceHostCfg extends BaseEntity<SpecificServiceHostCfg>{
@Expose
@SerializedName("cfgId")
private Integer hostId; //host_id 配置ID bigint N 主键,自增
private String specServiceName;//协议名称,用于导入导出
private Integer specServiceId; //spec_service_id 协议id int N protocol_info_cfg.protocol_id
@Expose
private Integer ipType; //ip地址类型 ipV4=4 ipV6=6
@@ -80,72 +82,84 @@ public class SpecificServiceHostCfg extends BaseEntity<SpecificServiceHostCfg>{
public void setSpecServiceId(Integer specServiceId) {
this.specServiceId = specServiceId;
}
@ExcelField(title="ip_type",align=2,sort=20)
public Integer getIpType() {
return ipType;
}
public void setIpType(Integer ipType) {
this.ipType = ipType;
}
@ExcelField(title="client_ip",align=2,sort=30)
public String getSrcIp() {
return srcIp;
}
public void setSrcIp(String srcIp) {
this.srcIp = srcIp;
}
@ExcelField(title="client_address_mask",align=2,sort=40)
public String getSrcIpMask() {
return srcIpMask;
}
public void setSrcIpMask(String srcIpMask) {
this.srcIpMask = srcIpMask;
}
@ExcelField(title="client_port",align=2,sort=50)
public String getSrcPort() {
return srcPort;
}
public void setSrcPort(String srcPort) {
this.srcPort = srcPort;
}
@ExcelField(title="client_port_mask",align=2,sort=60)
public String getSrcPortMask() {
return srcPortMask;
}
public void setSrcPortMask(String srcPortMask) {
this.srcPortMask = srcPortMask;
}
@ExcelField(title="server_ip",align=2,sort=70)
public String getDstIp() {
return dstIp;
}
public void setDstIp(String dstIp) {
this.dstIp = dstIp;
}
@ExcelField(title="server_address_mask",align=2,sort=80)
public String getDstIpMask() {
return dstIpMask;
}
public void setDstIpMask(String dstIpMask) {
this.dstIpMask = dstIpMask;
}
@ExcelField(title="server_port",align=2,sort=90)
public String getDstPort() {
return dstPort;
}
public void setDstPort(String dstPort) {
this.dstPort = dstPort;
}
@ExcelField(title="server_port_mask",align=2,sort=100)
public String getDstPortMask() {
return dstPortMask;
}
public void setDstPortMask(String dstPortMask) {
this.dstPortMask = dstPortMask;
}
@ExcelField(title="direction",align=2,sort=110)
public Integer getDirection() {
return direction;
}
public void setDirection(Integer direction) {
this.direction = direction;
}
@ExcelField(title="protocol",align=2,sort=120)
public Integer getProtocol() {
return protocol;
}
public void setProtocol(Integer protocol) {
this.protocol = protocol;
}
@ExcelField(title="valid_identifier",type=1,align=2,sort=130)
public Integer getIsValid() {
return isValid;
}
@@ -164,6 +178,7 @@ public class SpecificServiceHostCfg extends BaseEntity<SpecificServiceHostCfg>{
public void setCreator(SysUser creator) {
this.creator = creator;
}
@ExcelField(title="创建时间",type=1,align=2,sort=140)
public Date getCreateTime() {
return createTime;
}
@@ -233,6 +248,13 @@ public class SpecificServiceHostCfg extends BaseEntity<SpecificServiceHostCfg>{
public void setAuditEndDate(Date auditEndDate) {
this.auditEndDate = auditEndDate;
}
@ExcelField(title="protocol_name",align=2,sort=10)
public String getSpecServiceName() {
return specServiceName;
}
public void setSpecServiceName(String specServiceName) {
this.specServiceName = specServiceName;
}
/**
* 处理数据
* @param list

View File

@@ -15,7 +15,9 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
@@ -161,7 +163,84 @@ public class ExportExcel {
}
initialize(title, headerList);
}
/**
* 构造函数
* @param title 表格标题,传“空值”,表示无标题
* @param cls 实体对象通过annotation.ExportField获取标题
* @param type 导出类型1:导出数据2导出模板
* @param groups 导入分组
*/
public ExportExcel(Properties msgProp,String title, Class<?> cls, int type, int... groups){
// Get annotation field
Field[] fs = cls.getDeclaredFields();
for (Field f : fs){
ExcelField ef = f.getAnnotation(ExcelField.class);
if (ef != null && (ef.type()==0 || ef.type()==type)){
if (groups!=null && groups.length>0){
boolean inGroup = false;
for (int g : groups){
if (inGroup){
break;
}
for (int efg : ef.groups()){
if (g == efg){
inGroup = true;
annotationList.add(new Object[]{ef, f});
break;
}
}
}
}else{
annotationList.add(new Object[]{ef, f});
}
}
}
// Get annotation method
Method[] ms = cls.getDeclaredMethods();
for (Method m : ms){
ExcelField ef = m.getAnnotation(ExcelField.class);
if (ef != null && (ef.type()==0 || ef.type()==type)){
if (groups!=null && groups.length>0){
boolean inGroup = false;
for (int g : groups){
if (inGroup){
break;
}
for (int efg : ef.groups()){
if (g == efg){
inGroup = true;
annotationList.add(new Object[]{ef, m});
break;
}
}
}
}else{
annotationList.add(new Object[]{ef, m});
}
}
}
// Field sorting
Collections.sort(annotationList, new Comparator<Object[]>() {
public int compare(Object[] o1, Object[] o2) {
return new Integer(((ExcelField)o1[0]).sort()).compareTo(
new Integer(((ExcelField)o2[0]).sort()));
};
});
// Initialize
List<String> headerList = Lists.newArrayList();
for (Object[] os : annotationList){
String t = ((ExcelField)os[0]).title();
// 如果是导出,则去掉注释
if (type==1){
String[] ss = StringUtils.split(t, "**", 2);
if (ss.length==2){
t = ss[0];
}
}
headerList.add(msgProp.getProperty(t));
}
initialize(title, headerList);
}
/**
* 构造函数
* @param title 表格标题,传“空值”,表示无标题
@@ -427,7 +506,28 @@ public class ExportExcel {
this.write(os);
return this;
}
/**
* 输出到客户端
* @param fileName 输出文件名
*/
public ExportExcel write(HttpServletRequest request,HttpServletResponse response, String fileName) throws IOException{
final String userAgent = request.getHeader("USER-AGENT");
String finalFileName = null;
if(StringUtils.contains(userAgent, "MSIE")){//IE浏览器
finalFileName = Encodes.urlEncode(fileName);
}else if(StringUtils.contains(userAgent, "Mozilla")){//google,火狐浏览器
finalFileName = new String(fileName.getBytes(), "ISO8859-1");
}else{
finalFileName = Encodes.urlEncode(fileName);//其他浏览器
}
response.reset();
response.setContentType("application/octet-stream; charset=utf-8");
response.setHeader("Content-Disposition", "attachment; filename="+finalFileName);
write(response.getOutputStream());
return this;
}
/**
* 清理临时文件
*/

View File

@@ -302,7 +302,8 @@ public class ImportExcel {
try {
if (valType == String.class){
String s = String.valueOf(val.toString());
if(StringUtils.endsWith(s, ".0")){
//0.0.0.0表示任意IP的含义
if(StringUtils.endsWith(s, ".0") && !s.equals("0.0.0.0")){
val = StringUtils.substringBefore(s, ".0");
}else{
val = String.valueOf(val.toString());

View File

@@ -1,34 +1,39 @@
package com.nis.web.controller.specific;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Locale;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.google.common.collect.Lists;
import com.google.gson.JsonArray;
import com.nis.domain.ImportErrorInfo;
import com.nis.domain.Page;
import com.nis.domain.specific.SpecificServiceCfg;
import com.nis.domain.specific.SpecificServiceHostCfg;
import com.nis.util.Configurations;
import com.nis.util.StringUtil;
import com.nis.util.excel.ExportExcel;
import com.nis.util.excel.ImportExcel;
import com.nis.web.controller.BaseController;
@Controller
@RequestMapping(value = "${adminPath}/specific/specificServiceHostCfg")
public class SpecificServiceHostCfgController extends BaseController {
@ModelAttribute
public SpecificServiceHostCfg get(@RequestParam(required=false) Integer hostId) {
if (!StringUtil.isEmpty(hostId)){
@@ -68,7 +73,7 @@ public class SpecificServiceHostCfgController extends BaseController {
* @param model
* @return
*/
@RequiresPermissions(value= {"specific:serviceIp:add","specific:serviceIp:edit"},logical=Logical.OR)
@RequiresPermissions("specific:serviceIp:edit")
@RequestMapping(value = "form")
public String form(SpecificServiceHostCfg specificServiceHostCfg, HttpServletRequest request, HttpServletResponse response, Model model) {
//查询协议id供下拉选择
@@ -85,7 +90,7 @@ public class SpecificServiceHostCfgController extends BaseController {
* @param mulitId
* @return
*/
@RequiresPermissions(value= {"specific:serviceIp:add","specific:serviceIp:edit"},logical=Logical.OR)
@RequiresPermissions("specific:serviceIp:edit")
@RequestMapping(value = "saveOrUpdate")
public String saveOrUpdate(SpecificServiceHostCfg specificServiceHostCfg,Model model,RedirectAttributes redirectAttributes){
try {
@@ -104,7 +109,7 @@ public class SpecificServiceHostCfgController extends BaseController {
* @param mulitId
* @return
*/
@RequiresPermissions("specific:serviceIp:del")
@RequiresPermissions("specific:serviceIp:edit")
@RequestMapping(value="delete")
public String delete(SpecificServiceHostCfg specificServiceHostCfg, RedirectAttributes redirectAttributes, String mulitId){
try{
@@ -117,6 +122,80 @@ public class SpecificServiceHostCfgController extends BaseController {
return "redirect:"+adminPath+"/specific/specificServiceHostCfg/list";
}
@RequiresPermissions("specific:serviceIp:edit")
@RequestMapping(value = "import/template")
public String importFileTemplate(HttpServletRequest request,HttpServletResponse response, RedirectAttributes redirectAttributes) {
Properties msgProp = new Properties();
try {
String language = LocaleContextHolder.getLocale().getLanguage();
if(language.equals("zh_cn")||language.equals("zh")){
msgProp.load(Configurations.class.getResourceAsStream("/messages/message_zh_CN.properties"));
}else if(language.equals("ru")){
msgProp.load(Configurations.class.getResourceAsStream("/messages/message_ru.properties"));
}else{
msgProp.load(Configurations.class.getResourceAsStream("/messages/message_en.properties"));
}
} catch (Exception e) {
msgProp = null;
System.err.println("未知i18n消息配置文件,请确定文件是否存在!");
}
try {
String fileName = msgProp.getProperty("agreement_ip_configuration").replaceAll(" ", "_")+".xlsx";
List<SpecificServiceHostCfg> list = Lists.newArrayList();
list.add(new SpecificServiceHostCfg());
new ExportExcel(msgProp,msgProp.getProperty("agreement_ip_configuration"), SpecificServiceHostCfg.class, 2).setDataList(list).
write(request,response, fileName).dispose();
return null;
} catch (Exception e) {
addMessage(redirectAttributes, msgProp.getProperty("import_template_failed")+e.getMessage());
}
return "redirect:"+adminPath+"/specific/specificServiceHostCfg/list";
}
@RequiresPermissions("specific:serviceIp:edit")
@RequestMapping(value = "import", method=RequestMethod.POST)
public String importFile(HttpServletRequest request,Model model,HttpServletResponse response, RedirectAttributes redirectAttributes,
@RequestParam("file") MultipartFile file) {
Properties msgProp = new Properties();
try {
String language = LocaleContextHolder.getLocale().getLanguage();
if(language.equals("zh_cn")||language.equals("zh")){
msgProp.load(Configurations.class.getResourceAsStream("/messages/message_zh_CN.properties"));
}else if(language.equals("ru")){
msgProp.load(Configurations.class.getResourceAsStream("/messages/message_ru.properties"));
}else{
msgProp.load(Configurations.class.getResourceAsStream("/messages/message_en.properties"));
}
} catch (Exception e) {
msgProp = null;
System.err.println("未知i18n消息配置文件,请确定文件是否存在!");
}
List<ImportErrorInfo> errorInfos = null;
try {
ImportExcel ei = new ImportExcel(file, 1, 0);
List<SpecificServiceHostCfg> list = ei.getDataList(SpecificServiceHostCfg.class);
//查询特定服务管理specific_service_cfg协议id供下拉选择
List<SpecificServiceCfg> listSpecService = specificServiceCfgService.findAllSpecificServiceCfg(new SpecificServiceCfg(), "spec_service_id DESC");
errorInfos = specificServiceHostCfgService.importFile(list,listSpecService,msgProp);
// if(result){
// addMessage(redirectAttributes, msgProp.getProperty("import_success"));
// }else{
// addMessage(redirectAttributes, msgProp.getProperty("import_error"));
// }
} catch (Exception e) {
addMessage(redirectAttributes, msgProp.getProperty("import_failed")+errorInfos);
e.printStackTrace();
}
if(errorInfos!=null && errorInfos.size()>0){
addMessage(redirectAttributes, msgProp.getProperty("import_failed")+errorInfos);
}else{
addMessage(redirectAttributes, "success");
}
return "redirect:"+adminPath+"/specific/specificServiceHostCfg/list";
// return renderString(response,errorInfos);
}
/**
* 校验spec_service_id重复
* @param newId

View File

@@ -1,17 +1,23 @@
package com.nis.web.service.specific;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.nis.domain.ImportErrorInfo;
import com.nis.domain.Page;
import com.nis.domain.SysUser;
import com.nis.domain.specific.SpecificServiceCfg;
import com.nis.domain.specific.SpecificServiceHostCfg;
import com.nis.util.BasicProvingUtil;
import com.nis.util.StringUtil;
import com.nis.web.dao.specific.SpecificServiceHostCfgDao;
import com.nis.web.security.UserUtils;
@@ -53,13 +59,15 @@ public class SpecificServiceHostCfgService extends BaseService{
public void saveOrUpdate(SpecificServiceHostCfg specificServiceHostCfg) {
SysUser user = UserUtils.getUser();
String defaultIp = "0.0.0.0"; //缺省0.0.0.0值表示任意
String defaultIpMask = "255.255.255.255";//255.255.255.255表示无掩码
String defaultIpMask = "";
if(specificServiceHostCfg.getIpType().equals(4)){
defaultIpMask = "255.255.255.255"; //255.255.255.255表示无掩码
}
if(specificServiceHostCfg.getIpType().equals(6)){
defaultIp = "::"; //缺省::
defaultIpMask = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"; //FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF表示无掩码
}
String defaultPortMask = "65535"; //65535表示无掩码
//ip地址默认 Ipv4缺省0.0.0.0,ipv6缺省为::
//ip地址默认 缺省0.0.0.0值表示任意
if(StringUtil.isBlank(specificServiceHostCfg.getSrcIp())){
specificServiceHostCfg.setSrcIp(defaultIp);
}
@@ -133,6 +141,173 @@ public class SpecificServiceHostCfgService extends BaseService{
return specificServiceHostCfgDao.getBySpecServiceId(specServiceId);
}
/**
* 导入文件
* @param ei
*/
public List<ImportErrorInfo> importFile(List<SpecificServiceHostCfg> list,List<SpecificServiceCfg> listSpecService,Properties msgProp) throws Exception {
List<ImportErrorInfo> importErrorInfos = new ArrayList<ImportErrorInfo>();
//特定服务信息<协议名称,协议ID>
Map<String, Integer> serviceIdMap = new HashMap<String, Integer>();
for (SpecificServiceCfg specificServiceCfg : listSpecService) {
serviceIdMap.put(specificServiceCfg.getSpecServiceName(), specificServiceCfg.getSpecServiceId());
}
for (int i = 0; i < list.size(); i++) {
SpecificServiceHostCfg specificServiceHostCfg = list.get(i);
ImportErrorInfo importErrorInfo = null;
boolean valFlag = true;
SysUser user = UserUtils.getUser();
String defaultIp = "0.0.0.0"; //缺省0.0.0.0值表示任意
String defaultIpMask = "";
//验证
//协议名称=>协议ID
if(StringUtil.isEmpty(specificServiceHostCfg.getSpecServiceName())||!(!StringUtil.isEmpty(specificServiceHostCfg.getSpecServiceName())&&serviceIdMap.containsKey(specificServiceHostCfg.getSpecServiceName()))){
logger.info(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_protocol_id"));
importErrorInfo=new ImportErrorInfo(i+3+"",msgProp.getProperty("protocol"),msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_protocol_id"));
importErrorInfos.add(importErrorInfo);
valFlag = false;
//throw new RuntimeException(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_protocol_id"));
}else{
specificServiceHostCfg.setSpecServiceId(serviceIdMap.get(specificServiceHostCfg.getSpecServiceName()));
}
//IP类型
if(!(!StringUtil.isEmpty(specificServiceHostCfg.getIpType())&&("4".equals((specificServiceHostCfg.getIpType().toString()))||"6".equals((specificServiceHostCfg.getIpType().toString()))))){
logger.info(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_ip_type"));
importErrorInfo=new ImportErrorInfo(i+3+"",msgProp.getProperty("ip_type"),msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_ip_type"));
importErrorInfos.add(importErrorInfo);
valFlag = false;
// throw new RuntimeException(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_ip_type"));
}
//源IP
if(!StringUtil.isEmpty(specificServiceHostCfg.getSrcIp())&&!BasicProvingUtil.isIpOrIpMask(specificServiceHostCfg.getSrcIp(), specificServiceHostCfg.getIpType())){
logger.info(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_src_ip"));
// throw new RuntimeException(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_src_ip"));
importErrorInfo=new ImportErrorInfo(i+3+"",msgProp.getProperty("client_ip"),msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_src_ip"));
importErrorInfos.add(importErrorInfo);
valFlag = false;
}
//源IP掩码
if(!StringUtil.isEmpty(specificServiceHostCfg.getSrcIpMask())&&!BasicProvingUtil.isIpOrIpMask(specificServiceHostCfg.getSrcIpMask(), specificServiceHostCfg.getIpType())){
logger.info(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_src_mask"));
// throw new RuntimeException(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_src_mask"));
importErrorInfo=new ImportErrorInfo(i+3+"",msgProp.getProperty("client_address_mask"),msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_src_mask"));
importErrorInfos.add(importErrorInfo);
valFlag = false;
}
//源端口
if(!(!StringUtil.isEmpty(specificServiceHostCfg.getSrcPort())&&BasicProvingUtil.isPortOrPortMask(specificServiceHostCfg.getSrcPort()))){
logger.info(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_src_port"));
// throw new RuntimeException(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_src_port"));
importErrorInfo=new ImportErrorInfo(i+3+"",msgProp.getProperty("client_port"),msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_src_port"));
importErrorInfos.add(importErrorInfo);
valFlag = false;
}
//源端口掩码
if(!StringUtil.isEmpty(specificServiceHostCfg.getSrcPortMask())&&!BasicProvingUtil.isPortOrPortMask(specificServiceHostCfg.getSrcPortMask())){
logger.info(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_src_port_mask"));
// throw new RuntimeException(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_src_port_mask"));
importErrorInfo=new ImportErrorInfo(i+3+"",msgProp.getProperty("client_port_mask"),msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_src_port_mask"));
importErrorInfos.add(importErrorInfo);
valFlag = false;
}
//目的IP
if(!StringUtil.isEmpty(specificServiceHostCfg.getDstIp())&&!BasicProvingUtil.isIpOrIpMask(specificServiceHostCfg.getDstIp(), specificServiceHostCfg.getIpType())){
logger.info(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_dst_ip"));
// throw new RuntimeException(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_dst_ip"));
importErrorInfo=new ImportErrorInfo(i+3+"",msgProp.getProperty("server_ip"),msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_dst_ip"));
importErrorInfos.add(importErrorInfo);
valFlag = false;
}
//目的IP掩码
if(!StringUtil.isEmpty(specificServiceHostCfg.getDstIpMask())&&!BasicProvingUtil.isIpOrIpMask(specificServiceHostCfg.getDstIpMask(), specificServiceHostCfg.getIpType())){
logger.info(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_dst_mask"));
// throw new RuntimeException(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_dst_mask"));
importErrorInfo=new ImportErrorInfo(i+3+"",msgProp.getProperty("server_address_mask"),msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_dst_mask"));
importErrorInfos.add(importErrorInfo);
valFlag = false;
}
//目的端口
if(!(!StringUtil.isEmpty(specificServiceHostCfg.getDstPort())&&BasicProvingUtil.isPortOrPortMask(specificServiceHostCfg.getDstPort()))){
logger.info(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_dst_port"));
// throw new RuntimeException(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_dst_port"));
importErrorInfo=new ImportErrorInfo(i+3+"",msgProp.getProperty("server_port"),msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_dst_port"));
importErrorInfos.add(importErrorInfo);
valFlag = false;
}
//目的端口掩码
if(!(!StringUtil.isEmpty(specificServiceHostCfg.getDstPortMask())&&BasicProvingUtil.isPortOrPortMask(specificServiceHostCfg.getDstPortMask()))){
logger.info(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_dst_port_mask"));
// throw new RuntimeException(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_dst_port_mask"));
importErrorInfo=new ImportErrorInfo(i+3+"",msgProp.getProperty("server_port_mask"),msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_dst_port_mask"));
importErrorInfos.add(importErrorInfo);
valFlag = false;
}
//协议
if(!(!StringUtil.isEmpty(specificServiceHostCfg.getProtocol())&&("6".equals(specificServiceHostCfg.getProtocol().toString())||"17".equals(specificServiceHostCfg.getProtocol().toString())||"0".equals(specificServiceHostCfg.getProtocol().toString())))){
logger.info(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_protocol"));
// throw new RuntimeException(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_protocol"));
importErrorInfo=new ImportErrorInfo(i+3+"",msgProp.getProperty("protocol"),msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_protocol"));
importErrorInfos.add(importErrorInfo);
valFlag = false;
}
//方向
if(!StringUtil.isEmpty(specificServiceHostCfg.getDirection())&&!(("1".equals(specificServiceHostCfg.getDirection().toString())||"0".equals(specificServiceHostCfg.getDirection().toString())))){
logger.info(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_direction"));
// throw new RuntimeException(msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_direction"));
importErrorInfo=new ImportErrorInfo(i+3+"",msgProp.getProperty("direction"),msgProp.getProperty("the_line_of").replace("rowNum", (i+3)+"")+ msgProp.getProperty("val_direction"));
importErrorInfos.add(importErrorInfo);
valFlag = false;
}
//默认值
if(specificServiceHostCfg.getIpType().equals(4)){
defaultIpMask = "255.255.255.255"; //255.255.255.255表示无掩码
}
if(specificServiceHostCfg.getIpType().equals(6)){
defaultIpMask = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"; //FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF表示无掩码
}
String defaultPortMask = "65535"; //65535表示无掩码
//ip地址默认 缺省0.0.0.0值表示任意
if(StringUtil.isBlank(specificServiceHostCfg.getSrcIp())){
specificServiceHostCfg.setSrcIp(defaultIp);
}
if(StringUtil.isBlank(specificServiceHostCfg.getDstIp())){
specificServiceHostCfg.setDstIp(defaultIp);
}
//ip掩码默认
if(StringUtil.isBlank(specificServiceHostCfg.getSrcIpMask())){
specificServiceHostCfg.setSrcIpMask(defaultIpMask);
}
if(StringUtil.isBlank(specificServiceHostCfg.getDstIpMask())){
specificServiceHostCfg.setDstIpMask(defaultIpMask);
}
//端口掩码默认
if(StringUtil.isBlank(specificServiceHostCfg.getSrcPortMask())){
specificServiceHostCfg.setSrcPortMask(defaultPortMask);
}
if(StringUtil.isBlank(specificServiceHostCfg.getDstPortMask())){
specificServiceHostCfg.setDstPortMask(defaultPortMask);
}
//方向缺省
if(specificServiceHostCfg.getDirection()==null){
specificServiceHostCfg.setDirection(0);
}
Date date = new Date();
specificServiceHostCfg.setIsValid(1);
specificServiceHostCfg.setCreator(user);
specificServiceHostCfg.setCreateTime(date);
// specificServiceHostCfg.setEditor(user);
// specificServiceHostCfg.setEditTime(date);
// specificServiceHostCfg.setAuditor(user);
// specificServiceHostCfg.setAuditTime(date);
if (valFlag) {
specificServiceHostCfgDao.insert(specificServiceHostCfg);
}
}
return importErrorInfos;
}
}

View File

@@ -580,4 +580,26 @@ action_ratelimit=rate limit
action_replace=replace
action_whitelist=white list
action_monit=monitor
file_digest_control=file digest control
file_digest_control=file digest control
#===============protocol IP Import start=================
chooseFile=Choose File
download=Download
import_success=import success
import_error=import error
import_failed=Import data failed,
import_template_failed=Failure of template download,ths exception is :
the_line_of=the rowNum line
val_protocol_id=protocol Name is required or not exists
val_ip_type=ip type is required and the value mast 4(IPV4) or 6(IPV6)
val_src_ip=client ip format is incorrect or inconsistent with the ip type
val_src_mask=client ip format is incorrect or inconsistent with the ip type
val_src_port=client port is required and the value mast between 0 and 65535
val_src_port_mask=client port mask is required and the value mast between 0 and 65535
val_dst_ip=server ip format is incorrect or inconsistent with the ip type
val_dst_mask=server address mask format is incorrect or inconsistent with the ip type
val_dst_port=server port is required and the value mast between 0 and 65535
val_dst_port_mask=server port mask is required and the value mast between 0 and 65535
val_protocol=protocol is required and the value mast 6(tcp),17(udp),0(freedom)
val_direction=The value mast 0(bidirectional) or 1(unidirectional)
#===============protocol IP Import end=================

View File

@@ -406,4 +406,26 @@ action_ratelimit=\u0441\u0442\u0430\u0432\u043A\u0438 \u043E\u0433\u0440\u0430\u
action_replace=\u0437\u0430\u043C\u0435\u043D\u0438\u0442\u044C
action_whitelist=\u0431\u0435\u043B\u044B\u0439 \u0441\u043F\u0438\u0441\u043E\u043A
action_monit=\u041C\u043E\u043D\u0438\u0442\u043E\u0440\u0438\u043D\u0433
file_digest_control=file digest control
file_digest_control=file digest control
#===============protocol IP Import start=================
chooseFile=Choose File
download=Download
import_success=Import success
import_error=Import error
import_failed=Import data failed,
import_template_failed=Failure of template download,ths exception is :
the_line_of=the rowNum line
val_protocol_id=protocol Name is required or not exists
val_ip_type=ip type is required and the value mast 4(IPV4) or 6(IPV6)
val_src_ip=client ip format is incorrect or inconsistent with the ip type
val_src_mask=client ip format is incorrect or inconsistent with the ip type
val_src_port=client port is required and the value mast between 0 and 65535
val_src_port_mask=client port mask is required and the value mast between 0 and 65535
val_dst_ip=server ip format is incorrect or inconsistent with the ip type
val_dst_mask=server address mask format is incorrect or inconsistent with the ip type
val_dst_port=server port is required and the value mast between 0 and 65535
val_dst_port_mask=server port mask is required and the value mast between 0 and 65535
val_protocol=protocol is required and the value mast 6(tcp),17(udp),0(freedom)
val_direction=The value mast 0(bidirectional) or 1(unidirectional)
#===============protocol IP Import end=================

View File

@@ -607,3 +607,24 @@ action_replace=\u66FF\u6362
action_whitelist=\u767D\u540D\u5355
action_monit=\u76D1\u6D4B
file_digest_control=\u6587\u4EF6\u6458\u8981\u7BA1\u63A7
#===============protocol IP Import start=================
chooseFile=\u9009\u62E9\u6587\u4EF6
download=\u6A21\u677F\u4E0B\u8F7D
import_success=\u5BFC\u5165\u6210\u529F
import_error=\u5BFC\u5165\u5F02\u5E38
import_failed=\u5BFC\u5165\u6570\u636E\u5931\u8D25
import_template_failed=\u5BFC\u5165\u6A21\u677F\u4E0B\u8F7D\u5931\u8D25\uFF01\u5931\u8D25\u4FE1\u606F\uFF1A
the_line_of=\u7B2CrowNum\u884C
val_protocol_id=\u534F\u8BAE\u540D\u79F0\u4E3A\u7A7A\u6216\u4E0D\u5B58\u5728
val_ip_type=IP\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A\u5E76\u4E14\u503C\u53EA\u80FD\u4E3A4(IPV4)\u62166(IPV6)
val_src_ip=\u6E90IP\u683C\u5F0F\u4E0D\u6B63\u786E\u6216\u4E0EIP\u7C7B\u578B\u4E0D\u4E00\u81F4
val_src_mask=\u6E90IP\u63A9\u7801\u683C\u5F0F\u4E0D\u6B63\u786E\u6216\u4E0EIP\u7C7B\u578B\u4E0D\u4E00\u81F4
val_src_port=\u6E90\u7AEF\u53E3\u4E3A\u7A7A\u6216\u683C\u5F0F\u4E0D\u6B63\u786E(0-65535)
val_src_port_mask=\u6E90\u7AEF\u53E3\u63A9\u7801\u683C\u5F0F\u4E0D\u6B63\u786E(0-65535)
val_dst_ip=\u76EE\u7684IP\u683C\u5F0F\u4E0D\u6B63\u786E\u6216\u4E0EIP\u7C7B\u578B\u4E0D\u4E00\u81F4
val_dst_mask=\u76EE\u7684IP\u63A9\u7801\u683C\u5F0F\u4E0D\u6B63\u786E\u6216\u4E0EIP\u7C7B\u578B\u4E0D\u4E00\u81F4
val_dst_port=\u76EE\u7684\u7AEF\u53E3\u4E3A\u7A7A\u6216\u683C\u5F0F\u4E0D\u6B63\u786E(0-65535)
val_dst_port_mask=\u76EE\u7684\u7AEF\u53E3\u63A9\u7801\u683C\u5F0F\u4E0D\u6B63\u786E(0-65535)
val_protocol=\u534F\u8BAE\u4E0D\u80FD\u4E3A\u7A7A\u5E76\u4E14\u503C\u53EA\u80FD\u4E3A6(tcp),17(udp),0(\u4EFB\u610F)
val_direction=\u65B9\u5411\u503C\u53EA\u80FD\u4E3A0(bidirectional)\u62161(unidirectional)
#===============protocol IP Import end=================

View File

@@ -29,6 +29,8 @@
<link href="${pageContext.request.contextPath}/static/global/css/page.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/static/global/css/jquery.tagsinput.css" rel="stylesheet" type="text/css" />
<!-- 文件导入 -->
<link href="${pageContext.request.contextPath}/static/global/plugins/bootstrap-fileupload/css/bootstrap-fileupload.css" rel="stylesheet" type="text/css" />
<!--[if lt IE 9]>
<script src="${pageContext.request.contextPath}/static/global/plugins/respond.min.js"></script>
@@ -87,4 +89,8 @@
</c:choose>
<script src="${pageContext.request.contextPath}/static/global/scripts/common.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/static/global/scripts/jquery.tagsinput.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/static/global/scripts/app.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/static/global/scripts/app.js" type="text/javascript"></script>
<!-- 文件导入 -->
<script src="${pageContext.request.contextPath}/static/global/plugins/bootstrap-fileupload/js/bootstrap-fileupload.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/static/global/plugins/bootstrap-fileupload/js/jquery.cookie.min.js" type="text/javascript"></script>

View File

@@ -3,6 +3,7 @@
<html>
<head>
<title><spring:message code="agreement_ip_configuration" /></title>
<script src="${pageContext.request.contextPath}/static/global/scripts/app.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
//筛选功能初始化
@@ -22,6 +23,18 @@
$("input.i-checks").prop("checked",false);
}
});
$("#btnImport").click(function(){
$.jBox($("#importBox").html(), {title:"导入数据", buttons:{"关闭":true},
bottomText:"导入文件不能超过5M仅允许导入“xls”或“xlsx”格式文件"});
});
$("button[data-dismiss='modal']").click(function (){
alert("close");
window.location ="${ctx}/specific/specificServiceHostCfg/list";
})
});
function resetx(){
$(':input','#searchForm')
@@ -75,19 +88,148 @@
$("#searchForm").submit();
return false;
}
//导入文件提示框
function toImport(){
$("#import_modal").modal({
backdrop:"static",
keyboard:false,
show:true
});
}
//导入配置
function ajaxImp(){
/*var fileName = $(".fileupload-preview", $("#importForm1")).text();
var $error = $('.alert-error', $("#importForm1"));
if(App.isEmpty(fileName)){
$("span",$error).html("请选择xls或者xlsx格式文件进行导入...");
$error.removeClass("hide");
$error.addClass("show");
return false;
}else if(fileName.lastIndexOf("\.")==-1||fileName.substring(fileName.lastIndexOf("\.")+1).toLowerCase()!='xls' &&fileName.substring(fileName.lastIndexOf("\.")+1).toLowerCase()!='xlsx'){
$("span",$error).html("导入的文件后缀必须为xls或者xlsx...");
$error.removeClass("hide");
$error.addClass("show");
return false;
}
$("#import_modal").modal('hide');//导入文件隐藏
$("#importForm1").submit();
*/
$("#importForm1").submit();
/* $("#importForm1").ajaxSubmit({
//clearForm:true,
resetForm:true,
dataType:'json',
type:'post',
beforeSubmit:function(formData,jqForm,options){
var fileName = $(".fileupload-preview", jqForm).text();
var $error = $('.alert-error', jqForm);
$error.hide();
if(App.isEmpty(fileName)){
$("span",$error).html("请选择xls或者xlsx格式文件进行导入...");
$error.removeClass("hide");
$error.addClass("show");
return false;
}else if(fileName.lastIndexOf("\.")==-1||fileName.substring(fileName.lastIndexOf("\.")+1).toLowerCase()!='xls' &&fileName.substring(fileName.lastIndexOf("\.")+1).toLowerCase()!='xlsx'){
$("span",$error).html("导入的文件后缀必须为xls或者xlsx...");
$error.removeClass("hide");
$error.addClass("show");
return false;
}
$("#import_modal").modal('hide');//导入文件隐藏
return true;
},
success:function(data,statusText){
if(statusText='success'){
if(data!=null&&data.length>0){
alert(data[0].errorMessage);
}
}
}
}); */
}
function downLoadXLS(){
window.location ="${ctx}/specific/specificServiceHostCfg/import/template";
}
</script>
</head>
<body>
<div class="modal fade" id="import_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<form id="importForm1" action="${ctx}/specific/specificServiceHostCfg/import/" method="post"
enctype="multipart/form-data" class="form-horizontal"
onsubmit="loading('<spring:message code='loading'/>');">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"><spring:message code="import"/></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="alert alert-error hide">
<button class="close" data-dismiss="alert"></button>
<span></span>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="col-md-2 control-label" style="margin-top:5px;"><spring:message code="chooseFile"/></label>
<div class="controls">
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="input-append">
<div class="uneditable-input">
<i class="fa fa-fa fa-file"></i>
<span class="fileupload-preview"></span>
</div>
<span class="btn btn-file ">
<button type="button" class="btn fileupload-new"><spring:message code="add"/></button>
<button type="button" class="btn fileupload-exists"><spring:message code="edit"/></button>
<input type="file" class="default" id="uploadFile" name="file"/>
<input type="hidden" name="flag" value="${flag }"/>
</span>
<button type="button" class="btn red fileupload-exists" data-dismiss="fileupload" style="margin-left:-1px;"><spring:message code="remove"/></a>
<button type="button" onclick="downLoadXLS()" class="btn black" style="margin-left:-1px"><spring:message code="download"/></button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn red" onclick="ajaxImp()"><spring:message code="ok"/></button>
<button type="button" class="btn" data-dismiss="modal"><spring:message code="close"/></button>
</div>
</div>
</div>
</form>
</div>
<div class="page-content">
<div class="theme-panel hidden-xs hidden-sm">
<%-- <button type="button" class="btn btn-default" onclick="javascript:window.location='${ctx}/specific/specificServiceHostCfg/list'"><spring:message code="refresh"></spring:message></button> --%>
<shiro:hasPermission name="specific:serviceIp:add">
<button type="button" class="btn btn-primary"
onClick="javascript:window.location='${ctx}/specific/specificServiceHostCfg/form'">
<i class="fa fa-plus"></i>
<spring:message code="add"/></button>
<button type="button" class="btn btn-primary green" data-toggle="modal" data-target="#exampleModal" onClick="toImport();">
<i class="fa fa-upload"></i>
<spring:message code="import"/></button>
</button>
</shiro:hasPermission>
</div>
@@ -263,7 +405,7 @@
<th><spring:message code="server_port_mask" /></th>
<th><spring:message code="direction" /></th>
<th><spring:message code="protocol" /></th>
<th><spring:message code="is_audit" /></th>
<%-- <th><spring:message code="is_audit" /></th> --%>
<th><spring:message code="creator" /></th>
<th class="sort-column create_time"><spring:message code="config_time" /></th>
<th><spring:message code="editor" /></th>
@@ -287,10 +429,10 @@
<td>${specificServiceHostCfg.dstPortMask }</td>
<td><spring:message code='${fns:getDictLabel("SPEC_DIRECTION",specificServiceHostCfg.direction,"0")}' /></td>
<td><spring:message code='${fns:getDictLabel("SPEC_PROTOCOL",specificServiceHostCfg.protocol,"0")}' /></td>
<td><spring:message code='${fns:getDictLabel("SPEC_AUDIT",specificServiceHostCfg.isAudit,"0")}' /></td>
<!--<td><spring:message code='${fns:getDictLabel("SPEC_AUDIT",specificServiceHostCfg.isAudit,"0")}' /></td> -->
<td>${fns:getUserById(specificServiceHostCfg.creator.id).name}</td>
<td><fmt:formatDate value="${specificServiceHostCfg.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
<td>${fns:getUserById(specificServiceHostCfg.editor.id).name}</td>
<td>${fns:getUserById(specificServiceHostCfg.editor.id==null?0:specificServiceHostCfg.editor.id).name}</td>
<td><fmt:formatDate value="${specificServiceHostCfg.editTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
<td>${fns:getUserById(specificServiceHostCfg.auditor.id==null?0:specificServiceHostCfg.auditor.id).name}</td>
<td><fmt:formatDate value="${specificServiceHostCfg.auditTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>

View File

@@ -0,0 +1,129 @@
.btn-file {
position: relative;
overflow: hidden;
vertical-align: middle;
padding-left:0px !important;
padding-right:0px !important;
margin-left:-5px;
margin-right:-3px
}
.btn-file > input {
position: absolute;
top: 0;
right: 0;
margin: 0;
font-size: 23px;
cursor: pointer;
opacity: 0;
filter: alpha(opacity=0);
transform: translate(-300px, 0) scale(4);
direction: ltr;
}
.fileupload {
margin-bottom: 9px;
}
.fileupload .uneditable-input {
display: inline-block;
margin-bottom: 0;
vertical-align: middle;
cursor: text;
}
.fileupload .thumbnail {
display: inline-block;
margin-bottom: 5px;
overflow: hidden;
text-align: center;
vertical-align: middle;
}
.fileupload .thumbnail > img {
display: inline-block;
max-height: 100%;
vertical-align: middle;
}
.fileupload .btn {
vertical-align: middle;
}
.fileupload-exists .fileupload-new,
.fileupload-new .fileupload-exists {
display: none;
}
.fileupload-inline .fileupload-controls {
display: inline;
}
.fileupload-new .input-append .btn-file {
-webkit-border-radius: 0 3px 3px 0;
-moz-border-radius: 0 3px 3px 0;
border-radius: 0 3px 3px 0;
}
.thumbnail-borderless .thumbnail {
padding: 0;
border: none;
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 0;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}
.fileupload-new.thumbnail-borderless .thumbnail {
border: 1px solid #ddd;
}
.control-group.warning .fileupload .uneditable-input {
color: #a47e3c;
border-color: #a47e3c;
}
.control-group.warning .fileupload .fileupload-preview {
color: #a47e3c;
}
.control-group.warning .fileupload .thumbnail {
border-color: #a47e3c;
}
.control-group.error .fileupload .uneditable-input {
color: #b94a48;
border-color: #b94a48;
}
.control-group.error .fileupload .fileupload-preview {
color: #b94a48;
}
.control-group.error .fileupload .thumbnail {
border-color: #b94a48;
}
.control-group.success .fileupload .uneditable-input {
color: #468847;
border-color: #468847;
}
.control-group.success .fileupload .fileupload-preview {
color: #468847;
}
.control-group.success .fileupload .thumbnail {
border-color: #468847;
}
.btn.black {
background-color: #555555;
color: white;
text-shadow: none;
}
.btn.black:hover, .btn.black:focus, .btn.black:active, .btn.black.active, .btn.black.disabled, .btn.black[disabled] {
background-color: #222222 !important;
color: #fff !important;
}

View File

@@ -0,0 +1,171 @@
/* ===========================================================
* bootstrap-fileupload.js j2
* http://jasny.github.com/bootstrap/javascript.html#fileupload
* ===========================================================
* Copyright 2012 Jasny BV, Netherlands.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================== */
!function ($) {
"use strict"; // jshint ;_
/* FILEUPLOAD PUBLIC CLASS DEFINITION
* ================================= */
var Fileupload = function (element, options) {
this.$element = $(element)
this.type = this.$element.data('uploadtype') || (this.$element.find('.thumbnail').length > 0 ? "image" : "file")
this.$input = this.$element.find(':file')
if (this.$input.length === 0) return
this.name = this.$input.attr('name') || options.name
this.$hidden = this.$element.find('input[type=hidden][name="'+this.name+'"]')
if (this.$hidden.length === 0) {
this.$hidden = $('<input type="hidden" />')
this.$element.prepend(this.$hidden)
}
this.$preview = this.$element.find('.fileupload-preview')
var height = this.$preview.css('height')
if (this.$preview.css('display') != 'inline' && height != '0px' && height != 'none') this.$preview.css('line-height', height)
this.original = {
'exists': this.$element.hasClass('fileupload-exists'),
'preview': this.$preview.html(),
'hiddenVal': this.$hidden.val()
}
this.$remove = this.$element.find('[data-dismiss="fileupload"]')
this.$element.find('[data-trigger="fileupload"]').on('click.fileupload', $.proxy(this.trigger, this))
this.listen()
}
Fileupload.prototype = {
listen: function() {
this.$input.on('change.fileupload', $.proxy(this.change, this))
$(this.$input[0].form).on('reset.fileupload', $.proxy(this.reset, this))
if (this.$remove) this.$remove.on('click.fileupload', $.proxy(this.clear, this))
},
change: function(e, invoked) {
var file = e.target.files !== undefined ? e.target.files[0] : (e.target.value ? { name: e.target.value.replace(/^.+\\/, '') } : null)
if (invoked === 'clear') return
if (!file) {
this.clear()
return
}
this.$hidden.val('')
this.$hidden.attr('name', '')
this.$input.attr('name', this.name)
if (this.type === "image" && this.$preview.length > 0 && (typeof file.type !== "undefined" ? file.type.match('image.*') : file.name.match('\\.(gif|png|jpe?g)$')) && typeof FileReader !== "undefined") {
var reader = new FileReader()
var preview = this.$preview
var element = this.$element
reader.onload = function(e) {
preview.html('<img src="' + e.target.result + '" ' + (preview.css('max-height') != 'none' ? 'style="max-height: ' + preview.css('max-height') + ';"' : '') + ' />')
element.addClass('fileupload-exists').removeClass('fileupload-new')
}
reader.readAsDataURL(file)
} else {
this.$preview.text(file.name)
this.$element.addClass('fileupload-exists').removeClass('fileupload-new')
}
},
clear: function(e) {
this.$hidden.val('')
this.$hidden.attr('name', this.name)
this.$input.attr('name', '')
//ie8+ doesn't support changing the value of input with type=file so clone instead
if($.browser.msie){
var inputClone = this.$input.clone(true);
this.$input.after(inputClone);
this.$input.remove();
this.$input = inputClone;
}else{
this.$input.val('')
}
this.$preview.html('')
this.$element.addClass('fileupload-new').removeClass('fileupload-exists')
if (e) {
this.$input.trigger('change', [ 'clear' ])
e.preventDefault()
}
},
reset: function(e) {
this.clear()
this.$hidden.val(this.original.hiddenVal)
this.$preview.html(this.original.preview)
if (this.original.exists) this.$element.addClass('fileupload-exists').removeClass('fileupload-new')
else this.$element.addClass('fileupload-new').removeClass('fileupload-exists')
},
trigger: function(e) {
this.$input.trigger('click')
e.preventDefault()
}
}
/* FILEUPLOAD PLUGIN DEFINITION
* =========================== */
$.fn.fileupload = function (options) {
return this.each(function () {
var $this = $(this)
, data = $this.data('fileupload')
if (!data) $this.data('fileupload', (data = new Fileupload(this, options)))
if (typeof options == 'string') data[options]()
})
}
$.fn.fileupload.Constructor = Fileupload
/* FILEUPLOAD DATA-API
* ================== */
$(function () {
$('body').on('click.fileupload.data-api', '[data-provides="fileupload"]', function (e) {
var $this = $(this)
if ($this.data('fileupload')) return
$this.fileupload($this.data())
var $target = $(e.target).is('[data-dismiss=fileupload],[data-trigger=fileupload]') ?
$(e.target) : $(e.target).parents('[data-dismiss=fileupload],[data-trigger=fileupload]').first()
if ($target.length > 0) {
$target.trigger('click.fileupload')
e.preventDefault()
}
})
})
}(window.jQuery);

View File

@@ -0,0 +1,8 @@
/*!
* jQuery Cookie Plugin v1.3.1
* https://github.com/carhartl/jquery-cookie
*
* Copyright 2013 Klaus Hartl
* Released under the MIT license
*/
(function(a){if(typeof define==="function"&&define.amd){define(["jquery"],a)}else{a(jQuery)}}(function(e){var a=/\+/g;function d(g){return g}function b(g){return decodeURIComponent(g.replace(a," "))}function f(g){if(g.indexOf('"')===0){g=g.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\")}try{return c.json?JSON.parse(g):g}catch(h){}}var c=e.cookie=function(p,o,u){if(o!==undefined){u=e.extend({},c.defaults,u);if(typeof u.expires==="number"){var q=u.expires,s=u.expires=new Date();s.setDate(s.getDate()+q)}o=c.json?JSON.stringify(o):String(o);return(document.cookie=[c.raw?p:encodeURIComponent(p),"=",c.raw?o:encodeURIComponent(o),u.expires?"; expires="+u.expires.toUTCString():"",u.path?"; path="+u.path:"",u.domain?"; domain="+u.domain:"",u.secure?"; secure":""].join(""))}var g=c.raw?d:b;var r=document.cookie.split("; ");var v=p?undefined:{};for(var n=0,k=r.length;n<k;n++){var m=r[n].split("=");var h=g(m.shift());var j=g(m.join("="));if(p&&p===h){v=f(j);break}if(!p){v[h]=f(j)}}return v};c.defaults={};e.removeCookie=function(h,g){if(e.cookie(h)!==undefined){e.cookie(h,"",e.extend({},g,{expires:-1}));return true}return false}}));