GithubHelp home page GithubHelp logo

termd's Introduction

Termd

Termd for Arthas.

An open source library for writing terminal applications in Java under ASL 2.0, ported from https://github.com/termd/termd to make it able to run against java6/7.

mvn clean package -Dmaven.test.skip -DskipTests

Consuming the lib

Add this dependency to your build.

<dependency>
  <groupId>com.alibaba.middleware</groupId>
  <artifactId>termd-core</artifactId>
  <version>1.1.3-SNAPSHOT</version>
</dependency>

Snapshots are available from Sonatype OSS repository

Features

  • Telnet/SSH using Netty 4 or Vert.x 3
  • Web interface using term.js and SockJS/Websocket
  • Event based design
    • read events
    • window size
    • tty signals
  • Readline implementation
    • extensible with plugable functions
    • multi-line support
    • multi-byte char support
    • multi-cell char support
  • Unicode support
  • Terminfo capabilities

Supported protocols

Telnet

Termd provides its own implementation of Telnet written on top of Netty 4.

SSH

Termd provides an implementation of Apache SSHD backed by Netty 4.

Websocket

Termd in a web page using the term.js client library and Netty websockets.

FAQ

  • what is not Termd ?
    • not a shell
    • not an arg parser
    • not a command framework
  • why async style ?
    • keyboard, ctrl-c, etc... event processing is easy to program against
  • why would I use Termd ?
    • you want to write a terminal application easily
    • you want to support various protocols like SSH, telnet or a web interface
    • you don't care about the technical details

Examples

Events

A simple examples showing TTY events.

The actual example, runs with Telnet, SSH, Websocket.

Readline

A simple examples showing how to use Readline.

The actual example, runs with Telnet, SSH, Websocket.

Readline function

A simple examples showing how to extend Readline with a custom function that reverse the line content.

The actual example, runs with Telnet, SSH, Websocket.

Shell

A simple shell example giving an overview of TTY interactions.

The actual example, run with Telnet, SSH, Websocket.

Screencast

Broadcast the desktop to the client, focusing on pushing data to the TTY.

The actual example, run with Telnet, SSH, Websocket.

Snake

The popular Snake game on the event loop.

The actual example, run with Telnet, SSH, Websocket.

Plasma

A funny demo effect using unicode chars.

The actual example, run with Telnet, SSH, Websocket.

Ptybridge

The PTY bridge is a bridge to native process, use with caution for security reasons, run with Telnet, SSH, Websocket.

Telnet

A simple telnet example that shows Telnet options negociation.

Todo

  • dynamic prompt
  • see to use IntStream or not
  • handle % stuff in parser
  • foobar@ for any foobar, not only boolean and treat it as a removal

Try to use the maven install plugin to install artifacts with specific dependencies.

termd's People

Contributors

carryxyh avatar dependabot[bot] avatar hengyunabc avatar iportman avatar kylixs avatar qxo avatar wetsion avatar yanyir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

termd's Issues

load too many term device

Generally we only need a few term devices, but more than 2600 are loaded and 11MB of memory is used.
Please optimize the loading of term devices to reduce unnecessary memory.

image
image

Readline#history 存在并发问题,当有线程在读取时,另外有线程更新,则会抛出 ConcurrentModificationException

alibaba/arthas#1554

2020-10-22 12:04:32 [arthas-NettyHttpTelnetBootstrap-3-3] INFO  c.t.a.core.shell.term.impl.Helper -Loaded arthas keymap file from com/taobao/arthas/core/shell/term/readline/inputrc
2020-10-22 12:04:32 [arthas-command-execute] INFO  c.t.a.c.c.klass100.RedefineCommand -Try redefine class name: com.ct1.game.normalactivity.NormalActivityService, ClassLoader: jdk.internal.loader.ClassLoaders$AppClassLoader@799f7e29
2020-10-22 12:04:32 [arthas-command-execute] INFO  c.t.arthas.core.advisor.Enhancer -Success to reset classes: []
2020-10-22 12:04:32 [arthas-command-execute] ERROR c.t.a.c.s.system.impl.ProcessImpl -Error during processing the command:
java.util.ConcurrentModificationException: null
        at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1042)
        at java.base/java.util.ArrayList$Itr.next(ArrayList.java:996)
        at com.taobao.arthas.core.util.FileUtils.saveCommandHistory(FileUtils.java:109)
        at com.taobao.arthas.core.shell.term.impl.TermImpl.close(TermImpl.java:186)
        at com.taobao.arthas.core.shell.impl.ShellImpl.close(ShellImpl.java:169)
        at com.taobao.arthas.core.shell.impl.ShellServerImpl.close(ShellServerImpl.java:229)
        at com.taobao.arthas.core.shell.ShellServer.close(ShellServer.java:98)
        at com.taobao.arthas.core.server.ArthasBootstrap.destroy(ArthasBootstrap.java:413)
        at com.taobao.arthas.core.command.basic1000.ShutdownCommand.shutdown(ShutdownCommand.java:47)
        at com.taobao.arthas.core.command.basic1000.ShutdownCommand.process(ShutdownCommand.java:31)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.process(AnnotatedCommandImpl.java:82)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.access$100(AnnotatedCommandImpl.java:18)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:111)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:108)
        at com.taobao.arthas.core.shell.system.impl.ProcessImpl$CommandProcessTask.run(ProcessImpl.java:385)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)
Arthas server already stared, skip attach.
Arthas server already stared, skip attach.
Arthas server already stared, skip attach.
Arthas server already stared, skip attach.

Do not support unicode "U+0000", throw java.lang.UnsupportedOperationException: todo

java.lang.UnsupportedOperationException: todo
	at io.termd.core.readline.LineBuffer.insertEscaped(LineBuffer.java:113)
	at io.termd.core.readline.Completion.complete(Completion.java:96)
	at com.taobao.arthas.core.shell.term.impl.CompletionAdaptor.complete(CompletionAdaptor.java:73)
	at com.taobao.arthas.core.shell.system.impl.CommandCompletion.complete(CommandCompletion.java:45)
	at com.taobao.arthas.core.shell.cli.CompletionUtils.complete(CompletionUtils.java:98)
	at com.taobao.arthas.core.shell.cli.CompletionUtils.completeShortOption(CompletionUtils.java:76)
	at com.taobao.arthas.core.shell.cli.CompletionUtils.complete(CompletionUtils.java:41)
	at com.taobao.arthas.core.shell.command.AnnotatedCommand.complete(AnnotatedCommand.java:44)
	at com.taobao.arthas.core.command.basic1000.CatCommand.complete(CatCommand.java:87)
	at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.complete(AnnotatedCommandImpl.java:102)
	at com.taobao.arthas.core.shell.system.impl.InternalCommandManager.completeSingleCommand(InternalCommandManager.java:115)
	at com.taobao.arthas.core.shell.system.impl.InternalCommandManager.complete(InternalCommandManager.java:67)
	at com.taobao.arthas.core.shell.handlers.shell.CommandManagerCompletionHandler.handle(CommandManagerCompletionHandler.java:19)
	at com.taobao.arthas.core.shell.handlers.shell.CommandManagerCompletionHandler.handle(CommandManagerCompletionHandler.java:10)
	at com.taobao.arthas.core.shell.term.impl.CompletionHandler.accept(CompletionHandler.java:30)
	at com.taobao.arthas.core.shell.term.impl.CompletionHandler.accept(CompletionHandler.java:16)
	at io.termd.core.readline.functions.Complete.apply(Complete.java:39)
	at io.termd.core.readline.Readline$Interaction.handle(Readline.java:264)
	at io.termd.core.readline.Readline$Interaction.access$200(Readline.java:189)
	at io.termd.core.readline.Readline.deliver(Readline.java:123)
	at io.termd.core.readline.Readline.access$500(Readline.java:41)
	at io.termd.core.readline.Readline$Interaction$2.accept(Readline.java:427)
	at io.termd.core.readline.Readline$Interaction$2.accept(Readline.java:421)
	at io.termd.core.tty.TtyEventDecoder.accept(TtyEventDecoder.java:93)
	at io.termd.core.tty.TtyEventDecoder.accept(TtyEventDecoder.java:26)
	at io.termd.core.tty.ReadBuffer.accept(ReadBuffer.java:44)
	at io.termd.core.tty.ReadBuffer.accept(ReadBuffer.java:28)
	at io.termd.core.io.BinaryDecoder.write(BinaryDecoder.java:117)
	at io.termd.core.io.BinaryDecoder.write(BinaryDecoder.java:65)
	at io.termd.core.telnet.TelnetTtyConnection.onData(TelnetTtyConnection.java:139)
	at io.termd.core.telnet.TelnetConnection.flushData(TelnetConnection.java:267)
	at io.termd.core.telnet.TelnetConnection.flushDataIfNecessary(TelnetConnection.java:257)
	at io.termd.core.telnet.TelnetConnection.receive(TelnetConnection.java:108)
	at io.termd.core.telnet.netty.TelnetChannelHandler.channelRead(TelnetChannelHandler.java:46)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:628)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:563)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:480)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:442)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:745)
    

在k8s环境里,telnet 连接出错 java.lang.UnsupportedOperationException: Handle this case gracefully


Arthas server agent start...
Arthas server already bind.
01 2020-02-20 15:44:15.930 INFO [nioEventLoopGroup-2-1:i.n.h.l.LoggingHandler] [id: 0x1ed033da, L:/0.0.0.0:3658] READ: [id: 0xe4666e8b, L:/127.0.0.1:3658 - R:/127.0.0.1:33915]
01 2020-02-20 15:44:15.931 INFO [nioEventLoopGroup-2-1:i.n.h.l.LoggingHandler] [id: 0x1ed033da, L:/0.0.0.0:3658] READ COMPLETE
01 2020-02-20 15:44:16.937 INFO [nioEventLoopGroup-2-5:arthas] [] [] [] Loaded arthas keymap file from com/taobao/arthas/core/shell/term/readline/inputrc
01 2020-02-20 15:44:29.251 ERROR [nioEventLoopGroup-2-5:i.t.c.io_error] Reported io error => closing
java.lang.UnsupportedOperationException: Handle this case gracefully
  at io.termd.core.util.Helper.computePosition(Helper.java:230)
  at io.termd.core.readline.LineBuffer.getPosition(LineBuffer.java:286)
  at io.termd.core.readline.LineBuffer.getCursorPosition(LineBuffer.java:272)
  at io.termd.core.readline.LineBuffer$Update.<init>(LineBuffer.java:325)
  at io.termd.core.readline.LineBuffer.update(LineBuffer.java:306)
  at io.termd.core.readline.Readline$Interaction.refresh(Readline.java:403)
  at io.termd.core.readline.Readline$Interaction.refresh(Readline.java:389)
  at io.termd.core.readline.Readline$Interaction.handle(Readline.java:288)
  at io.termd.core.readline.Readline$Interaction.access$200(Readline.java:189)
  at io.termd.core.readline.Readline.deliver(Readline.java:123)
  at io.termd.core.readline.Readline.access$500(Readline.java:41)
  at io.termd.core.readline.Readline$Interaction$2.accept(Readline.java:437)
  at io.termd.core.readline.Readline$Interaction$2.accept(Readline.java:431)
  at io.termd.core.tty.TtyEventDecoder.accept(TtyEventDecoder.java:93)
  at io.termd.core.tty.TtyEventDecoder.accept(TtyEventDecoder.java:26)
  at io.termd.core.tty.ReadBuffer.accept(ReadBuffer.java:44)
  at io.termd.core.tty.ReadBuffer.accept(ReadBuffer.java:28)
  at io.termd.core.io.BinaryDecoder.write(BinaryDecoder.java:117)
  at io.termd.core.io.BinaryDecoder.write(BinaryDecoder.java:65)
  at io.termd.core.telnet.TelnetTtyConnection.onData(TelnetTtyConnection.java:139)
  at io.termd.core.telnet.TelnetConnection.flushData(TelnetConnection.java:267)
  at io.termd.core.telnet.TelnetConnection.flushDataIfNecessary(TelnetConnection.java:257)
  at io.termd.core.telnet.TelnetConnection.receive(TelnetConnection.java:108)
  at io.termd.core.telnet.netty.TelnetChannelHandler.channelRead(TelnetChannelHandler.java:47)
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
  at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
  at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1421)
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
  at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:930)
  at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
  at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:697)
  at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:632)
  at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:549)
  at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:511)
  at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:918)
  at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
  at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
  at java.lang.Thread.run(Thread.java:745)

请升级一下依赖 jackson-databind 的版本

现有的版本中依赖了低版本的 com.fasterxml.jackson.core:jackson-databind:2.7.9.4 , 该版本发版日期为
2018年6月, maven**仓库上面显示的CVE漏洞目前已经有47个,其中紧急CVE漏洞有 23个,存在安全风险。

Keymap.getDefault() method get a empty inputstream problem.

public static Keymap getDefault() {
InputStream inputrc = null;
try {
inputrc = Keymap.class.getResourceAsStream("inputrc");
} finally {
if (inputrc != null) {
try {
inputrc.close();
} catch (IOException e) {
// ignore
}
}
}

return new Keymap(inputrc); // this line get a closed inputstream, this may cause keymap initializing failed.

}

Just like the comment, using example/readline can reproduce it.

build problem

本地打包之后,运行arthas时跑不起来,但是从官方仓库拉下来就可以正常跑,是我哪里打包的不对吗,也不像是代码的问题

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.