付延余
2022-12-16 f0f8ee8c4a945adbc742d9bab69382b28ad311fb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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<String> 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";
    }
 
 
}