From c301721a8f453125d9ca00fa54222263dba3a02b Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Sat, 12 Jan 2019 01:46:42 +0000 Subject: [PATCH] A library for finger or systat/active-user client requests (mostly migrated from exec/finger.js). --- exec/load/finger_lib.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 exec/load/finger_lib.js diff --git a/exec/load/finger_lib.js b/exec/load/finger_lib.js new file mode 100644 index 0000000000..85964687be --- /dev/null +++ b/exec/load/finger_lib.js @@ -0,0 +1,35 @@ +// $Id$ + +// A Finger/SYSTAT client library + +"use strict"; + +require('sockdefs.js', 'SOCK_DGRAM'); +require('portdefs.js', 'standard_service_port'); + +// Returns a String on failure, an Array of lines on success +function request(host, query, protocol, udp) +{ + if (protocol === undefined) + protocol = "finger"; + var sock = new Socket(udp === true ? SOCK_DGRAM : SOCK_STREAM); + if(!sock.connect(host, standard_service_port[protocol])) + return "Connection to " + host + " failed with error " + sock.last_error; + if(query !== undefined) + sock.send(query + "\r\n"); + var output = []; + if(udp) { + output.push(sock.recvfrom().data); + } + else { + while(sock.is_connected && !js.terminated) { + var line = sock.readline(); + if(line != null) + output.push(line); + } + } + sock.close(); + return output; +} + +this; \ No newline at end of file -- GitLab