public void setFile(String fileName, int flag) { if (flag == 1) { fullPath = ResourceCenter.getInstance().getSysPath() + "panel/model/" + fileName; } else { fullPath = ResourceCenter.getInstance().getSysPath() + "panel/xml/" + fileName; } }
@SuppressWarnings("static-access") public String downloadReport() { String type = getParaValue("type"); CompReportHelper helper = new CompReportHelper(); Hashtable allData = helper.getAllDevice(); Vector vector = null; List deviceList = new ArrayList(); String file = ""; // 保存到项目文件夹下的指定文件夹 String filePath = ""; // 获取系统文件夹路径 if (allData != null) { if (allData.containsKey("deviceVec")) { vector = (Vector) allData.get("deviceVec"); helper.createPie(vector); } if (allData.containsKey("deviceList")) { deviceList = (List) allData.get("deviceList"); if (type.equals("doc")) { file = "/temp/allDevice.doc"; filePath = ResourceCenter.getInstance().getSysPath() + file; try { helper.createDoc(vector, deviceList, filePath); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else if (type.equals("xls")) { file = "/temp/allDevice.xls"; filePath = ResourceCenter.getInstance().getSysPath() + file; try { helper.createExcel(vector, deviceList, filePath); } catch (WriteException e) { e.printStackTrace(); } } else if (type.equals("pdf")) { file = "/temp/allDevice.pdf"; filePath = ResourceCenter.getInstance().getSysPath() + file; try { helper.createPdf(vector, deviceList, filePath); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } } request.setAttribute("filename", filePath); return "/capreport/net/download.jsp"; }
private void collectCfgInfo() { BaseDaoImp cd = null; String sql = "SELECT * FROM sys_gather_acllist"; ArrayList<Map<String, String>> ssconfAL = null; try { cd = new BaseDaoImp(); ssconfAL = cd.executeQuery(sql); } catch (Exception e1) { e1.printStackTrace(); } finally { if (cd != null) { cd.close(); } } Map<String, String> ssidAL = null; if (ssconfAL != null) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HH-mm"); for (int i = 0; i < ssconfAL.size(); i++) { ssidAL = ssconfAL.get(i); // String id = ssidAL.get("id"); String ipaddress = ssidAL.get("ipaddress"); String command = ssidAL.get("command"); String isMonitor = ssidAL.get("isMonitor"); if (!ipaddress.equals("") && ipaddress != null && isMonitor.equals("1")) { HaweitelnetconfDao dao = null; try { dao = new HaweitelnetconfDao(); Huaweitelnetconf vo = (Huaweitelnetconf) dao.loadByIp(ipaddress); if (vo == null) { continue; } // String b_time = sdf.format(new Date()); String prefix = ResourceCenter.getInstance().getSysPath().replace("\\", "/"); String fileName = prefix + "script/" + vo.getIpaddress() + "acl.log"; bkpCfg(ipaddress, fileName, command); } catch (Exception e) { e.printStackTrace(); } finally { if (dao != null) { dao.close(); } } } } } catch (Exception e) { log.error("", e); } } }
public String downloadReportDay() { String ids = getParaValue("ids"); String type = getParaValue("type"); String reportType = getParaValue("reportType"); String exportType = getParaValue("exportType"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); if (ids == null || ids.equals("") || ids.equals("null")) { String id = request.getParameter("id"); if (id.equals("null")) return null; CompreReportInfo report = new CompreReportInfo(); CompreReportUtilDao dao = new CompreReportUtilDao(); report = (CompreReportInfo) dao.findByID(id); ids = report.getIds(); } String filename = ""; if ("hostNet".equalsIgnoreCase(type)) { if (exportType.equals("xls")) { filename = "/temp/compreDay_report.xls"; } else if (exportType.equals("doc")) { filename = "/temp/compreDay_report.doc"; } else if (exportType.equals("pdf")) { filename = "/temp/compreDay_report.pdf"; } } String filePath = ResourceCenter.getInstance().getSysPath() + filename; String startTime = getParaValue("startdate"); String toTime = startTime; if (startTime == null) { startTime = sdf.format(new Date()) + " 00:00:00"; } else { startTime = startTime + " 00:00:00"; } if (toTime == null) { toTime = sdf.format(new Date()) + " 23:59:59"; } else { toTime = toTime + " 23:59:59"; } CompreReportExport export = new CompreReportExport(); export.exportReportByDay(ids, type, reportType, filePath, startTime, toTime, exportType, null); request.setAttribute("filename", filePath); return "/capreport/net/download.jsp"; }
private String importExcel() { String discrictid = ""; String saveDirPath = ResourceCenter.getInstance().getSysPath() + "WEB-INF/macConfig"; Fileupload fileupload = new Fileupload(saveDirPath); fileupload.doupload(request); List formFieldList = fileupload.getFormFieldList(); List allMacList = null; for (int i = 0; i < formFieldList.size(); i++) { List formField = (List) formFieldList.get(i); String formFieldType = (String) formField.get(0); String formFieldName = (String) formField.get(1); String formFieldValue = (String) formField.get(2); if ("file".equals(formFieldType)) { if ("fileName".equals(formFieldName)) { List excellist = ExcelUtil.readExcel(new File(formFieldValue)); allMacList = getAllMacList(excellist); } } else if ("formField".equals(formFieldType)) { if ("discrictid".equals(formFieldName)) { discrictid = formFieldValue; } } } MacconfigDao macconfigDao = new MacconfigDao(); List allMacConfiglist = null; try { allMacConfiglist = macconfigDao.loadAll(); } catch (RuntimeException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { macconfigDao.close(); } if (allMacConfiglist == null) { allMacConfiglist = new ArrayList(); } List macConfigList = new ArrayList(); if (allMacList != null && allMacList.size() > 0) { for (int i = 0; i < allMacList.size(); i++) { String mac = (String) allMacList.get(i); for (int j = 0; j < allMacConfiglist.size(); j++) { Macconfig macConfigflag = new Macconfig(); macConfigflag = (Macconfig) allMacConfiglist.get(j); if (mac.trim().equals(macConfigflag.getMac().trim())) { allMacConfiglist.remove(j); } } Macconfig macConfig = new Macconfig(); macConfig.setMac(mac); macConfig.setDiscrictid(Integer.parseInt(discrictid)); macConfig.setMacdesc(""); allMacConfiglist.add(macConfig); } } macconfigDao = new MacconfigDao(); try { macconfigDao.deleteAll(); } catch (RuntimeException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { macconfigDao.close(); } macconfigDao = new MacconfigDao(); try { macconfigDao.saveBatch(allMacConfiglist); } catch (RuntimeException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { macconfigDao.close(); } return list(); }
private String importVisioTopo() { String flag = request.getParameter("flag"); HostNode importVisioTopohostnode = new HostNode(); List _list = new ArrayList(); if ("1".equals(flag)) { String discrictid = ""; String saveDirPath = ResourceCenter.getInstance().getSysPath() + "WEB-INF/macConfig"; String community = getParaValue("community"); String writecommunity = getParaValue("writecommunity"); int snmpversion = getParaIntValue("snmpversion"); int collecttype = 0; try { collecttype = getParaIntValue("collecttype"); } catch (Exception e) { } String bid = getParaValue("bid"); importVisioTopohostnode.setCommunity(community); importVisioTopohostnode.setWriteCommunity(writecommunity); importVisioTopohostnode.setSnmpversion(snmpversion); importVisioTopohostnode.setCollecttype(collecttype); importVisioTopohostnode.setBid(bid); session.setAttribute("importVisioTopohostnode", importVisioTopohostnode); return "/tool/importvisiotopo_list.jsp"; } if ("2".equals(flag)) { String discrictid = ""; String saveDirPath = ResourceCenter.getInstance().getSysPath() + "WEB-INF/macConfig"; Fileupload fileupload = new Fileupload(saveDirPath); fileupload.doupload(request, 10000000); HostNode _importVisioTopohostnode = (HostNode) session.getAttribute("importVisioTopohostnode"); List formFieldList = fileupload.getFormFieldList(); if (null == formFieldList || formFieldList.size() == 0) { request.setAttribute("success", false); } else { for (int i = 0; i < formFieldList.size(); i++) { List formField = (List) formFieldList.get(i); String formFieldType = (String) formField.get(0); String formFieldName = (String) formField.get(1); String formFieldValue = (String) formField.get(2); if ("file".equals(formFieldType)) { if ("fileName".equals(formFieldName)) { visio.IVInvisibleApp app = ClassFactory.createInvisibleApp(); try { IVDocument doc = app.documents().open(formFieldValue); IVPages pages = doc.pages(); System.out.println(pages.count()); for (int index = 1; index <= pages.count(); index++) { IVPage page = pages.item(index); System.out.println(page.nameU()); importOnePage(page); } request.setAttribute("success", true); } catch (Exception e) { e.printStackTrace(); request.setAttribute("success", false); } finally { app.quit(); } } } } } return "/tool/importvisiotopo_list.jsp"; } return null; }
/** @author nielin modify at 2010-01-08 */ public int writeXml(int flag) { int done = 0; // 需要做分布式判断 String runmodel = PollingEngine.getCollectwebflag(); try { I_HostLastCollectData hostlastmanager = new HostLastCollectDataManager(); Hashtable ipAllData = (Hashtable) ShareData.getSharedata().get(ipaddress); Vector vector = new Vector(); String[] netInterfaceItem = { "index", "ifDescr", "ifSpeed", "ifAdminStatus", "ifOperStatus", "OutBandwidthUtilHdx", "InBandwidthUtilHdx" }; try { if ("0".equals(runmodel)) { // 采集与访问是集成模式 vector = hostlastmanager.getInterface_share(ipaddress, netInterfaceItem, "index", "", ""); } else { // 采集与访问是分离模式 vector = hostlastmanager.getInterface(ipaddress, netInterfaceItem, "index", "", ""); } } catch (Exception e) { e.printStackTrace(); return done; } try { _fis = new FileInputStream( ResourceCenter.getInstance().getSysPath() + "panel/model/" + oid + "_" + imageType + ".jsp"); } catch (Exception e) { e.printStackTrace(); _fis.close(); return done; } _fis.skip(headBytes.getBytes().length); _builder = new SAXBuilder(); _doc = _builder.build(_fis); _root = _doc.getRootElement(); _nodes = _root.getChild("nodes"); List list = _nodes.getChildren(); PortconfigDao dao = new PortconfigDao(); try { for (int i = 0; i < list.size(); i++) { Element eleNode = (Element) list.get(i); if (eleNode.getChildText("index") == null) break; int index = Integer.valueOf(eleNode.getChildText("index")).intValue(); String x = eleNode.getChildText("x"); String y = eleNode.getChildText("y"); String img = eleNode.getChildText("img"); String direction = eleNode.getChildText("direction"); String ifname = ""; String OutBandwidthUtilHdx = "0"; String InBandwidthUtilHdx = "0"; String portuse = ""; if (vector != null && vector.size() > 0) { for (int m = 0; m < vector.size(); m++) { String[] strs = (String[]) vector.get(m); String _ifname = strs[1]; String _index = strs[0]; String opstatus = strs[4]; OutBandwidthUtilHdx = strs[5]; InBandwidthUtilHdx = strs[6]; Portconfig portconfig = null; try { portconfig = dao.getPanelByipandindex(ipaddress, index + ""); } catch (Exception e) { } if (portconfig != null && portconfig.getLinkuse() != null && portconfig.getLinkuse().trim().length() > 0) { portuse = portconfig.getLinkuse(); } // SysLogger.info(ipaddress+"====ifOperStatus====="+strs[4]); if (Integer.parseInt(_index) == index) { ifname = _ifname; if ("down".equalsIgnoreCase(opstatus)) { // DOWN if ("1".equalsIgnoreCase(direction)) { // 向上的端口 img = "image/up_down_gray.gif"; } else { // 向下的端口 img = "image/down_down_gray.gif"; } } else { // UP if ("1".equalsIgnoreCase(direction)) { // 向上的端口 img = "image/up_up_green.gif"; } else { // 向下的端口 img = "image/down_up_green.gif"; } } break; } } } addNode( index + "", InBandwidthUtilHdx, OutBandwidthUtilHdx, img, ipaddress, ifname, portuse, x, y); } } catch (Exception e) { e.printStackTrace(); } finally { dao.close(); } Format format = Format.getCompactFormat(); format.setEncoding("GB2312"); format.setIndent(" "); serializer = new XMLOutputter(format); // SysLogger.info("path==="+fullPath); fos = new FileOutputStream(fullPath); fos.write(headBytes.getBytes()); serializer.output(doc, fos); fos.close(); done = 1; } catch (Exception e) { done = 0; e.printStackTrace(); SysLogger.error("Error in XmlOperator.close()", e); } return done; }