From 3d09f6f8fea524e53a07fdb1fbe0b21229623f4d Mon Sep 17 00:00:00 2001 From: mivirl <> Date: Fri, 26 Jan 2024 09:23:35 -0600 Subject: [PATCH] Rename files for sorting; send processes separately - Rename files to start with underscore for sorting - Send process list with name _processes.log --- README.md | 8 +++++--- src/client.pl | 27 ++++++++++++++++++++++++--- src/server.sh | 13 +++++++++---- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c89a8a0..37787c4 100644 --- a/README.md +++ b/README.md @@ -56,12 +56,14 @@ directory to the remote system, then `cd` to that directory and run: Once the server is running and a client has connected, files will appear on the server in `srv/clients/` with the following naming scheme: -- `auth-key` - Key used to authenticate clients and store files in the correct directories -- `info.txt` - Contains basic information about the system +- `_auth-key` - Key used to authenticate clients and store files in the correct +- `_files.log` - Log of files as they are received on the server +- `_info.txt` - Contains basic information about the client +- `_processes.log` - Log of processes as they are run on the client - `F__filepath` - Files that are transferred once - `L__logpath.log` - Log files that are continuously transferred, new lines are - transferred as they are written on the client side + transferred as they are written on the client - `C__commandname.cmdlog` - Command output, continuously transferred Logs can be monitored as they come in using `lnav`: diff --git a/src/client.pl b/src/client.pl index 74dad7d..2be77db 100644 --- a/src/client.pl +++ b/src/client.pl @@ -145,6 +145,27 @@ sub send_log { exit; } +sub send_processes { + my ($clientName, $clientKey) = @_; + my $pid = fork; + if ($pid) { + push @child_processes, $pid; + return; + } + + my $socket = login($clientName, $clientKey); + $socket->send("processes\n"); + print_log "Processes: Started"; + my $commandLog = ns_systemFH('./pspy64', '-f'); + while (<$commandLog>) { + $socket->send($_); + } + print_log "Processes: Finished"; + close($commandLog); + $socket->send("⟃---EOF---⟄\n"); + exit; +} + sub send_command_output { my ($clientName, $clientKey, $name, @command) = @_; my $pid = fork; @@ -157,7 +178,7 @@ sub send_command_output { my ($fileName) = $name; $socket->send("command\n"); $socket->send("$fileName\n"); - print "@command\n"; + print_log "Command: Started @command"; my $commandLog = ns_systemFH(@command); while (<$commandLog>) { $socket->send($_); @@ -178,7 +199,7 @@ sub send_file { exit if (! -e $file || ! -r _); my $fileName = $file =~ s/\////gr; - my ($fileHash) = ns_system('./busybox', './busybox', 'md5sum', "$file"); + my ($fileHash) = ns_system('./busybox', 'md5sum', "$file"); chomp $fileName; chomp $fileHash; ($fileHash) = $fileHash =~ m/([0-9a-f]+)/; @@ -190,7 +211,7 @@ sub send_file { $socket->recv(my $port, 128); ($port) = $port =~ m/(\d+)/; - print_log "File: upload port is $port"; + print_log "File: upload port is $port ($file)"; open(my $fileFH, '<', "$file") || die "Failed to open $file"; my $fileSocket = connect_to_server $port; while (<$fileFH>) { diff --git a/src/server.sh b/src/server.sh index 2b10525..da3a4a1 100644 --- a/src/server.sh +++ b/src/server.sh @@ -47,7 +47,7 @@ if [ "$COMMAND" = "login" ]; then verify_input "$TMPNAME" if [ -e "$SRVDIR/clients/$TMPNAME" ]; then - KEY=$(cat "$SRVDIR/clients/$TMPNAME/auth-key") + KEY=$(cat "$SRVDIR/clients/$TMPNAME/_auth-key") if [ "$TMPKEY" = "$KEY" ]; then CLIENTNAME="$TMPNAME" CLIENTDIR="$SRVDIR/clients/$TMPNAME" @@ -68,7 +68,7 @@ elif [ "$COMMAND" = "register" ]; then CLIENTDIR="$SRVDIR/clients/$CLIENTNAME" CLIENTKEY=$(( RANDOM * 2**30 + RANDOM * 2**15 + RANDOM )) mkdir -p "$CLIENTDIR" - echo "$CLIENTKEY" > "$CLIENTDIR/auth-key" + echo "$CLIENTKEY" > "$CLIENTDIR/_auth-key" echo "Name: $CLIENTNAME" echo "Key: $CLIENTKEY" unset CLIENTKEY @@ -85,10 +85,15 @@ cd "$CLIENTDIR" while read -r COMMAND; do echo "$CLIENTNAME: $COMMAND" >&2 + if [ "$COMMAND" = "info" ]; then - print_status write_to_file info.txt + print_status write_to_file _info.txt + + elif [ "$COMMAND" = "processes" ]; then - print_status write_to_file processes.log + print_status write_to_file _processes.log + + elif [ "$COMMAND" = "file" ]; then echo -n "Filename: " read -r TMPFILENAME -- 2.39.5