package com.wgcloud.controller; import com.wgcloud.config.CommonConfig; import com.wgcloud.entity.AccountInfo; import com.wgcloud.util.FileUtils; import com.wgcloud.util.staticvar.StaticKeys; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.List; /** * @version v3.3 * @ClassName:WebSSHController.java * @author: http://www.wgstart.com * @date: 2021年4月16日 * @Description: web SSH终端实现 * @Copyright: 2019-2021 wgcloud. All rights reserved. */ @Controller @RequestMapping(value = "/ssh2") public class WebSSHController { private static final Logger logger = LoggerFactory.getLogger(WebSSHController.class); @Autowired private CommonConfig commonConfig; @RequestMapping("view") public String view(Model model, HttpServletRequest request) { String hostname = request.getParameter("hostname"); model.addAttribute("hostname", request.getParameter("hostname")); model.addAttribute("webSocketPort", commonConfig.getWebSshPort()); model.addAttribute("remark", StaticKeys.HOST_MAP.get(hostname) == null ? "" : StaticKeys.HOST_MAP.get(hostname)); //组装template下的密钥文件 begin List keyFileList = new ArrayList<>(); AccountInfo accountInfo = (AccountInfo) request.getSession().getAttribute(StaticKeys.LOGIN_KEY); if (StaticKeys.ROLE_ADMIN.equals(accountInfo.getRole())) { FileUtils.getFileList(StaticKeys.JAR_PATH + "/template/", keyFileList); if (keyFileList.size() > 0) { for (int i = 0; i < keyFileList.size(); i++) { String resStr = keyFileList.get(i).substring(keyFileList.get(i).indexOf("template")); keyFileList.set(i, resStr); } } } model.addAttribute("keyFileList", keyFileList); //组装template下的密钥文件 end return "ssh/ssh"; } }