How to combine node-pty and xterm - xtermjs

I added a terminal to my web application using node-pty on the server, ng-termianl (xterm.js) on the client and socket.io for the communication. I have it basically working but I have some issues and maybe I'm making things to complicated so here are some questions:
What tasks do I need to implement in the xterm and what should I expect node-pty to handle.
create a history buffer to handle up/down arrows.
create the terminal prompt
hand left and right arrow
When listinging to the data event in node-pty I get both the echoed command,the response, and the new terminal line. What is the the best way to filter out any data event that is not the respose to an issued command? Sometimes the echoed command is
How do I choose a value for the node-pty column count? Do the number of pty columns need to match up with the number of columns in the xterm? If the command the user types in the xterm is long then the echoed command in jumbled in the pty echo of the issued command.

What tasks do I need to implement in the xterm and what should I expect node-pty to handle.
xterm.js:
Terminal.write That's where the incoming data from the PTY should be written to.
Terminal.onData Event containing data from the user (keyboard input on the terminal). Should be written to the PTY.
These are the minimum requirements to get a working PTY connection. There are more goodies like addons to get a more full featured experience. Also see the demo project in the repo.
PTY:
A PTY on master side has mainly 2 interesting interface parts - the IO byte stream (can be assumed to be UTF8 these days) and a way to get/set the terminal size.
create a history buffer to handle up/down arrows.
create the terminal prompt
hand left and right arrow
For a terminal driven behind the TTY interface (PTY is a special case of that) these things are handled by the application currently running in the foreground (like the shell itself). The foreground application is in control of a history buffer, prompt printing, what to do with arrow keys and so on. As a cmdline app developer you may care for those things (slave side of PTY), but not as a terminal integrator (master side of PTY).
When listinging to the data event in node-pty I get both the echoed command,the response, and the new terminal line. What is the the best way to filter out any data event that is not the respose to an issued command? Sometimes the echoed command is
xterm.js is a dumb terminal, thus has no means to directly output data from user input, instead relies on proper echoing. The echoing itself is a feature by the TTY kernel interface and should not be filtered, unless you want silent input (yet that is not the way to do it).
How do I choose a value for the node-pty column count? Do the number of pty columns need to match up with the number of columns in the xterm? If the command the user types in the xterm is long then the echoed command in jumbled in the pty echo of the issued command.
Yes, the size in columns x rows should always be the same on xterm.js and the PTY, or weird output bugs will happen.

Related

Why is Tshark memory usage increasing when I am not keeping information?

I want to constantly monitor TCP data coming from a particular source.
I am using this command in a cygwin mintty xterm on a Windows server.
tshark.exe -i 5 -f "tcp port 1234" -T fields -e data | xxd -r -p
This works perfectly as I get a scrolling window of ASCII that is the data being sent to me. When that connection fails (which is what I am trying to debug) then the last data sent is shown in the cygwin window.
However, I notice that the Tshark memory usage is constantly creeping up and after a few hours is quite large.
What can I do about this? I would like to leave this running for several days.
You might want to try modifying your tshark command-line options to include the -b files:N option (and possibly other -b options as well for duration and/or filesize) to start a ring buffer. Doing so will cause tshark to discard its internal state whenever it rolls to the next file in the ringbuffer. Discarding state means freeing all memory associated with that state information, so at least in theory, you can capture forever.
For more information, feel free to read the Wireshark blog article, "To Infinity and Beyond! Capturing Forever with Tshark" by Evan Huus, one of the Wireshark core developers and the person responsible for implementing this feature to discard state information.

How to allow CUPs to wake up printer once when in standby?

I an bringing up my home print server using RaspberryPi+CUPs
MY printer is HP Laserjet MTF m1212nf.
Apprently, I I was able to setup everything good enough to be able sending jobs over the network and get them printed.
However, one problem i am running into is that once I leave the printer Idle for some time, it seems to go into kinda standby mode (kinda power-saving mode) and then jobs i send show as completed in the CUPs interface, but they never get to be printed on paper.
From this point, the way to resume printing is to shut off and then on the printer and then things work again until next go into power saving mode.
What you look for is Tea4Cups, which is a bridge beetween commands and cups.
For installation on RPi see here: (step 1-3) https://github.com/Felixel42/Printer-Pi-DCP-115C#tea4cups
Prefix your printer line i.e. smb://yourprinter so that it looks like that
tea4cups:/smb://yourprinter
The configuration file is at /etc/cups/tea4cups.conf
A minimal example is
[global]
directory : /var/spool/cups/ #you might need to adjust this
prehook_0 : wakeonlan yourmac #or whatever command you want to execute

Riemann-dash not showing anything

I am new to riemann. I am facing an issue which i guess would be trivial but not able to find the solution. I am not getting any data on the riemann dashboard. I have followed the exact steps said in riemann.io/howto.html
My riemann.config file
localhost:4567 page content
Can anyone tell how to get things started.
i even did
sudo netstat -nlp | grep 5555
and got one entry for tcp and one entry for udp. Because of low reputation points cant upload more links for the image.
first put an expression in your config that prints statements and then indexes them:
(streams
...
prn
index
...)
and make sure they are getting indexed.
then add a graph to your dash showing the service "riemann index size" and make sure that this index which exists by default is getting to dash and that it has a non-zero number.
the events really are not getting to dash, then connect with any of the clients and make sure you can run queries. I prefer the python client for this because it has a nice CLI for doing this from the terminal.
always check the box in the upper right of the Riemann dash and make sure it has the correct server name. I have also had to configure riemann to bind to 0.0.0.0:5556 before it would accept queries when it was not running on the same host or when it was running on the same host though in a docker container.
and last of all, consider moving to something other than dash for graphing these things as people often out-grow it quickly anyway.

Do I need to implement terminal emulation if I have a ptty?

If I have a pseudo terminal given to me (from say a pty-req (http://www.ietf.org/rfc/rfc4254.txt)) do I need to emulate the data coming back, or is that already emulated data?
It depends on the level of emulation you're talking about. The pty uses the remote server's terminal driver, so options controlled by stty (and the analogous system calls) will be emulated there.
But you're running an application that sends terminal control escape sequences, you'll need to handle that locally.

Intercept Print Jobs

We have some computers on which we charge for printing documents. When a user prints, I would like to intercept the print job, prompt them for their username / password so I can charge their account, then allow the print job to continue through to the printer.
How can this be accomplished? Is it possible to write such a utility in .NET?
You really need to look at creating a Port Monitor for this. Far from simple. You could look at RedMon. BTW: Many printer vendors offer solutions to this which use codes that are embedded into the print stream (PCL/PS) and the data is collected and retained on the printer.
For example, Xerox has something called Standard Accounting. When enabled in the driver it embeds PJL codes like this:
#PJL COMMENT OID_ATT_ACCOUNTING_INFORMATION_AVP "XRX_USERID,xxxx";
Once the job has been printed the device makes reference to the user, number of pages etc. which can then be reported on.
The problem you will run into when doing this on the workstation / server is that detecting the number of pages printed can be difficult. If you are trying, for example, to charge by the page you might be able to parse the number of pages from the file, or run through a PCL or PS RIP and determine but if they have a flag for 2up or 4up on the page and that work is done by the printer and not the driver, you will charge the client for 4 pages when they really only printed 1. That is one of the many pitfalls.

Resources