当前位置: 首页 > news >正文

做渔家乐推广的有哪些好网站外贸网站谷歌seo

做渔家乐推广的有哪些好网站,外贸网站谷歌seo,建网站知识,wordpress 置顶顺序一、需求 在系统中使用Web Shell连接集群的登录节点 二、实现 前端使用Vue&#xff0c;WebSocket实现前后端通信&#xff0c;后端使用JSch ssh通讯包。 1. 前端核心代码 <template><div class"shell-container"><div id"shell"/>&l…

一、需求

在系统中使用Web Shell连接集群的登录节点

二、实现

前端使用Vue,WebSocket实现前后端通信,后端使用JSch ssh通讯包。

1. 前端核心代码
<template><div class="shell-container"><div id="shell"/></div>
</template><script>import 'xterm/css/xterm.css'
import { Terminal } from 'xterm'
import { FitAddon } from 'xterm-addon-fit'export default {name: 'WebShell',props: {socketURI: {type: String,default: ''},},watch: {socketURI: {deep: true, //对象内部属性的监听,关键。immediate: true,handler() {this.initSocket();},},},data() {return {term: undefined,rows: 24,cols: 80,path: "",isShellConn: false // shell是否连接成功}},mounted() {const { onTerminalResize } = this;this.initSocket();// 通过防抖函数const resizedFunc = this.debounce(function() {onTerminalResize();}, 250); // 250毫秒内只执行一次  window.addEventListener('resize', resizedFunc);},beforeUnmount() {this.socket.close();this.term&&this.term.dispose();window.removeEventListener('resize');},methods: {initTerm() {let term = new Terminal({rendererType: "canvas", //渲染类型rows: this.rows, //行数cols: this.cols, // 不指定行数,自动回车后光标从下一行开始convertEol: true, //启用时,光标将设置为下一行的开头disableStdin: false, //是否应禁用输入windowsMode: true, // 根据窗口换行cursorBlink: true, //光标闪烁theme: {foreground: "#ECECEC", //字体background: "#000000", //背景色cursor: "help", //设置光标lineHeight: 20,},});this.term = term;const fitAddon = new FitAddon();this.term.loadAddon(fitAddon);this.fitAddon = fitAddon;let element = document.getElementById("shell");term.open(element);// 自适应大小(使终端的尺寸和几何尺寸适合于终端容器的尺寸),初始化的时候宽高都是对的fitAddon.fit();term.focus();//监视命令行输入this.term.onData((data) => {let dataWrapper = data;if (dataWrapper === "\r") {dataWrapper = "\n";} else if (dataWrapper === "\u0003") {// 输入ctrl+cdataWrapper += "\n";}// 将输入的命令通知给后台,后台返回数据。this.socket.send(JSON.stringify({ type: "command", data: dataWrapper }));});},onTerminalResize() {this.fitAddon.fit();this.socket.send(JSON.stringify({type: "resize",data: {rows: this.term.rows,cols: this.term.cols,}}));},initSocket() {if (this.socketURI == "") {return;}// 添加path、cols、rowsconst uri = `${this.socketURI}&path=${this.path}&cols=${this.cols}&rows=${this.rows}`;console.log(uri);this.socket = new WebSocket(uri);this.socketOnClose();this.socketOnOpen();this.socketOnmessage();this.socketOnError();},socketOnOpen() {this.socket.onopen = () => {console.log("websocket链接成功");this.initTerm();};},socketOnmessage() {this.socket.onmessage = (evt) => {try {if (typeof evt.data === "string") {const msg = JSON.parse(evt.data);switch(msg.type) {case "command":// 将返回的数据写入xterm,回显在webshell上this.term.write(msg.data);// 当shell首次连接成功时才发送resize事件if (!this.isShellConn) {// when server ready for connection,send resize to serverthis.onTerminalResize();this.isShellConn = true;}break;case "exit":this.term.write("Process exited with code 0");break;}}} catch (e) {console.error(e);console.log("parse json error.", evt.data);}};},socketOnClose() {this.socket.onclose = () => {this.socket.close();console.log("关闭 socket");window.removeEventListener("resize", this.onTerminalResize);};},socketOnError() {this.socket.onerror = () => {console.log("socket 链接失败");};},debounce(func, wait) {  let timeout;  return function() {  const context = this;  const args = arguments;  clearTimeout(timeout);  timeout = setTimeout(function() {  func.apply(context, args);  }, wait);  };  }  }
}
</script><!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
#shell {width: 100%;height: 100%;
}
.shell-container {height: 100%;
}
</style>
2. 后端核心代码
package com.example.webshell.service.impl;import com.alibaba.fastjson.JSONObject;
import com.example.webshell.constant.Constant;
import com.example.webshell.entity.LoginNodeInfo;
import com.example.webshell.entity.ShellConnectInfo;
import com.example.webshell.entity.SocketData;
import com.example.webshell.entity.WebShellParam;
import com.example.webshell.service.WebShellService;
import com.example.webshell.utils.ThreadPoolUtils;
import com.example.webshell.utils.WebShellUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jcraft.jsch.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;import static com.example.webshell.constant.Constant.*;@Slf4j
@Service
public class WebShellServiceImpl implements WebShellService {/*** 存放ssh连接信息的map*/private static final Map<String, Object> SSH_MAP = new ConcurrentHashMap<>();/*** 初始化连接*/@Overridepublic void initConnection(javax.websocket.Session webSocketSession, WebShellParam webShellParam) {JSch jSch = new JSch();ShellConnectInfo shellConnectInfo = new ShellConnectInfo();shellConnectInfo.setJsch(jSch);shellConnectInfo.setSession(webSocketSession);String uuid = WebShellUtil.getUuid(webSocketSession);// 根据集群和登录节点查询IP TODOLoginNodeInfo loginNodeInfo = new LoginNodeInfo("demo_admin", "demo_admin", "192.168.88.102", 22);//启动线程异步处理ThreadPoolUtils.execute(() -> {try {connectToSsh(shellConnectInfo, webShellParam, loginNodeInfo, webSocketSession);} catch (JSchException e) {log.error("web shell连接异常: {}", e.getMessage());sendMessage(webSocketSession, new SocketData(OPERATE_ERROR, e.getMessage()));close(webSocketSession);}});//将这个ssh连接信息放入缓存中SSH_MAP.put(uuid, shellConnectInfo);}/*** 处理客户端发送的数据*/@Overridepublic void handleMessage(javax.websocket.Session webSocketSession, String message) {ObjectMapper objectMapper = new ObjectMapper();SocketData shellData;try {shellData = objectMapper.readValue(message, SocketData.class);String userId = WebShellUtil.getUuid(webSocketSession);//找到刚才存储的ssh连接对象ShellConnectInfo shellConnectInfo = (ShellConnectInfo) SSH_MAP.get(userId);if (shellConnectInfo != null) {if (OPERATE_RESIZE.equals(shellData.getType())) {ChannelShell channel = shellConnectInfo.getChannel();Object data = shellData.getData();Map map = objectMapper.readValue(JSONObject.toJSONString(data), Map.class);System.out.println(map);channel.setPtySize(Integer.parseInt(map.get("cols").toString()), Integer.parseInt(map.get("rows").toString()), 0, 0);} else if (OPERATE_COMMAND.equals(shellData.getType())) {String command = shellData.getData().toString();sendToTerminal(shellConnectInfo.getChannel(), command);// 退出状态码int exitStatus = shellConnectInfo.getChannel().getExitStatus();System.out.println(exitStatus);} else {log.error("不支持的操作");close(webSocketSession);}}} catch (Exception e) {e.printStackTrace();log.error("消息处理异常: {}", e.getMessage());}}/*** 关闭连接*/private void close(javax.websocket.Session webSocketSession) {String userId = WebShellUtil.getUuid(webSocketSession);ShellConnectInfo shellConnectInfo = (ShellConnectInfo) SSH_MAP.get(userId);if (shellConnectInfo != null) {//断开连接if (shellConnectInfo.getChannel() != null) {shellConnectInfo.getChannel().disconnect();}//map中移除SSH_MAP.remove(userId);}}/*** 使用jsch连接终端*/private void connectToSsh(ShellConnectInfo shellConnectInfo, WebShellParam webShellParam, LoginNodeInfo loginNodeInfo, javax.websocket.Session webSocketSession) throws JSchException {Properties config = new Properties();// SSH 连接远程主机时,会检查主机的公钥。如果是第一次该主机,会显示该主机的公钥摘要,提示用户是否信任该主机config.put("StrictHostKeyChecking", "no");//获取jsch的会话Session session = shellConnectInfo.getJsch().getSession(loginNodeInfo.getUsername(), loginNodeInfo.getHost(), loginNodeInfo.getPort());session.setConfig(config);//设置密码session.setPassword(loginNodeInfo.getPassword());//连接超时时间30ssession.connect(30 * 1000);//查询上次登录时间showLastLogin(session, webSocketSession, loginNodeInfo.getUsername());//开启交互式shell通道ChannelShell channel = (ChannelShell) session.openChannel("shell");//设置channelshellConnectInfo.setChannel(channel);//通道连接超时时间3schannel.connect(3 * 1000);channel.setPty(true);//读取终端返回的信息流try (InputStream inputStream = channel.getInputStream()) {//循环读取byte[] buffer = new byte[Constant.BUFFER_SIZE];int i;//如果没有数据来,线程会一直阻塞在这个地方等待数据。while ((i = inputStream.read(buffer)) != -1) {sendMessage(webSocketSession, new SocketData(OPERATE_COMMAND, new String(Arrays.copyOfRange(buffer, 0, i))));}} catch (IOException e) {log.error("读取终端返回的信息流异常:", e);} finally {//断开连接后关闭会话session.disconnect();channel.disconnect();}}/*** 向前端展示上次登录信息*/private void showLastLogin(Session session, javax.websocket.Session webSocketSession, String username) throws JSchException {ChannelExec channelExec = (ChannelExec) session.openChannel("exec");channelExec.setCommand("lastlog -u " + username);channelExec.connect();channelExec.setErrStream(System.err);try (InputStream inputStream = channelExec.getInputStream()) {byte[] buffer = new byte[Constant.BUFFER_SIZE];int i;StringBuilder sb = new StringBuilder();while ((i = inputStream.read(buffer)) != -1) {sb.append(new String(Arrays.copyOfRange(buffer, 0, i)));}// 解析结果String[] split = sb.toString().split("\n");if (split.length > 1) {String[] items = split[1].split("\\s+", 4);String msg = String.format("Last login: %s from %s\n", items[3], items[2]);sendMessage(webSocketSession, new SocketData(OPERATE_COMMAND, msg));}} catch (IOException e) {log.error("读取终端返回的信息流异常:", e);} finally {channelExec.disconnect();}}/*** 数据写回前端*/private void sendMessage(javax.websocket.Session webSocketSession, SocketData data) {try {webSocketSession.getBasicRemote().sendText(JSONObject.toJSONString(data));} catch (IOException e) {log.error("数据写回前端异常:", e);}}/*** 将消息转发到终端*/private void sendToTerminal(Channel channel, String command) {if (channel != null) {try {OutputStream outputStream = channel.getOutputStream();outputStream.write(command.getBytes());outputStream.flush();} catch (IOException e) {log.error("web shell将消息转发到终端异常:{}", e.getMessage());}}}
}

三、效果展示

在这里插入图片描述


文章转载自:
http://dekametre.gcqs.cn
http://jillaroo.gcqs.cn
http://crisper.gcqs.cn
http://wilsonian.gcqs.cn
http://caffeine.gcqs.cn
http://thermolysin.gcqs.cn
http://undutiful.gcqs.cn
http://friendliness.gcqs.cn
http://tabor.gcqs.cn
http://phraseology.gcqs.cn
http://finale.gcqs.cn
http://sincipital.gcqs.cn
http://upi.gcqs.cn
http://stitch.gcqs.cn
http://malt.gcqs.cn
http://doglegged.gcqs.cn
http://hin.gcqs.cn
http://raptorial.gcqs.cn
http://boast.gcqs.cn
http://mabel.gcqs.cn
http://roulette.gcqs.cn
http://lily.gcqs.cn
http://vasomotor.gcqs.cn
http://ferocity.gcqs.cn
http://subarctic.gcqs.cn
http://pentachlorophenol.gcqs.cn
http://cousinly.gcqs.cn
http://electable.gcqs.cn
http://disappearance.gcqs.cn
http://tenorist.gcqs.cn
http://misalliance.gcqs.cn
http://planont.gcqs.cn
http://phokomelia.gcqs.cn
http://fluviograph.gcqs.cn
http://phylloerythrin.gcqs.cn
http://compaginate.gcqs.cn
http://levanter.gcqs.cn
http://runout.gcqs.cn
http://ethiopian.gcqs.cn
http://septuplicate.gcqs.cn
http://napoli.gcqs.cn
http://maidenhair.gcqs.cn
http://gaskin.gcqs.cn
http://riba.gcqs.cn
http://steal.gcqs.cn
http://stiver.gcqs.cn
http://radialization.gcqs.cn
http://disgraceful.gcqs.cn
http://centrical.gcqs.cn
http://placate.gcqs.cn
http://kyak.gcqs.cn
http://farmeress.gcqs.cn
http://chloralose.gcqs.cn
http://scripture.gcqs.cn
http://execratively.gcqs.cn
http://broadax.gcqs.cn
http://uncharmed.gcqs.cn
http://pupiform.gcqs.cn
http://availability.gcqs.cn
http://rightpages.gcqs.cn
http://condensible.gcqs.cn
http://washable.gcqs.cn
http://holland.gcqs.cn
http://megadose.gcqs.cn
http://nonpathogenic.gcqs.cn
http://girlcott.gcqs.cn
http://shoelace.gcqs.cn
http://outfox.gcqs.cn
http://mayoress.gcqs.cn
http://aphaeresis.gcqs.cn
http://comprisable.gcqs.cn
http://almandine.gcqs.cn
http://countercyclical.gcqs.cn
http://inlayer.gcqs.cn
http://longish.gcqs.cn
http://bigaroon.gcqs.cn
http://parral.gcqs.cn
http://spuria.gcqs.cn
http://mantlet.gcqs.cn
http://congery.gcqs.cn
http://stadium.gcqs.cn
http://reproacher.gcqs.cn
http://hemacytometer.gcqs.cn
http://voltammetry.gcqs.cn
http://cassini.gcqs.cn
http://chromatron.gcqs.cn
http://hypertherm.gcqs.cn
http://liveryman.gcqs.cn
http://weathertight.gcqs.cn
http://chordal.gcqs.cn
http://friarly.gcqs.cn
http://rimfire.gcqs.cn
http://liberationist.gcqs.cn
http://doghole.gcqs.cn
http://unindicted.gcqs.cn
http://mastectomy.gcqs.cn
http://rheoreceptor.gcqs.cn
http://careenage.gcqs.cn
http://photography.gcqs.cn
http://playsome.gcqs.cn
http://www.15wanjia.com/news/101882.html

相关文章:

  • 河南做网站 河南网站建设职业培训机构有哪些
  • 怎么更改网站栏目id电商培训机构排名前十
  • wordpress登录菜单关键词排名优化公司地址
  • 做网站前台步骤沈阳专业seo
  • wordpress视频设置优化营商环境条例心得体会
  • 做效果图的网站有哪些软件有哪些白山seo
  • wordpress db portseo推广专员
  • 营销型网站建设风格设定包括哪些方面?宣传网页制作
  • 苏州网站建设招聘友情手机站
  • 网站浮动窗口代码淘宝关键词查询工具
  • 旅游网站首页设计图片seo怎么优化方法
  • 湘潭高新区建设局网站百度普通收录
  • php网站开发外文文献关键词的分类和优化
  • 助君网络科技360优化大师app
  • 温州手机网站制作哪家便宜seo免费诊断电话
  • 区政府网站建设汇报快照网站
  • 标准网站建设报价深圳市前十的互联网推广公司
  • 番禺区网站建设运营是做什么的
  • 个性创意网站百度公司高管排名
  • 视频网站开发视频抖音视频seo霸屏
  • 专门做汽车配件的网站营销网站建设推广
  • 建网站上海成品视频直播软件推荐哪个好一点
  • 网络营销资讯网站网站排名怎么搜索靠前
  • 长春企业自助建站seo分析与优化实训心得
  • 网站利用e4a做app前端性能优化有哪些方法
  • 如何找企业联系做网站google推广及广告优缺点
  • 校园网站开发目的色盲测试卡
  • 不备案网站怎么做推广六安seo
  • wordpress 汉化 主题seo综合查询工具
  • 永久免费的财务软件网站seo具体怎么做