begin of SafeQ terminal server replacement
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 21 Feb 2019 15:00:14 +0000 (16:00 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 21 Feb 2019 15:00:14 +0000 (16:00 +0100)
terminal-server.pl [new file with mode: 0755]

diff --git a/terminal-server.pl b/terminal-server.pl
new file mode 100755 (executable)
index 0000000..ca2fd57
--- /dev/null
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+use IO::Socket::INET;
+
+$| = 1;
+
+my $socket = IO::Socket::INET->new(
+       LocalPort => 4096,
+       Proto => 'tcp',
+       Listen => 5,
+       Reuse => 1
+) or die "ERROR: $!";
+
+print "SERVER Waiting for client connection on port 4096\n";
+
+while(1) {
+       my $client_socket = $socket->accept();
+
+       sub client_send {
+               my $text = join('', @_);
+               warn ">> $text\n";
+               print $client_socket "$text\r\n";
+       }
+
+       # get the host and port number of newly connected client.
+       my $peer_address = $client_socket->peerhost();
+       my $peer_port = $client_socket->peerport();
+
+       print "Connection from: $peer_address:$peer_port\n";
+
+       while ($client_socket->connected) {
+               my $line = <$client_socket>;
+               chomp $line;
+               warn "<< $line\n";
+
+               if ( $line =~ m/^\.SQ ([\d\.]+) (\S+)/ ) {
+                       client_send  ".SQ OK";
+               } elsif ( $line =~ m/^\.CFG/ ) {
+                       client_send  ".CFG OK %s";
+               } elsif ( $line =~ m/\.SERVER LIST/ ) {
+                       client_send  ".ERROR NO-ENTERPRISE";
+               } elsif ( $line =~ m/\.CARD (\S+)/ ) {
+                       client_send  ".CARD OK pero peric (pero\@example.com)";
+               } elsif ( $line =~ m/\.ACTION$/ ) {
+                       client_send  ".ACTION CMENUS2";
+               } elsif ( $line =~ m/\.ACTION COPY/ ) {
+                       client_send  ".ACTION COPY";
+                       client_send  ".COPY Mozete kopirati (pero)";
+               } elsif ( $line =~ m/(\.NOP)/ ) {
+                       client_send  "$1";
+               } else {
+                       die "unknown: $line";
+               }
+       }
+}
+
+$socket->close();