--- ChivanetModcon/modcon 2025/01/31 19:41:00 1.4 +++ ChivanetModcon/modcon 2025/02/01 03:17:46 1.5 @@ -4,13 +4,16 @@ # ChivaNet Moderator Console # Copyright (C) 2025 Coherent Logic Development LLC # -# $Id: modcon,v 1.4 2025/01/31 19:41:00 snw Exp $ +# $Id: modcon,v 1.5 2025/02/01 03:17:46 snw Exp $ # # Author: Serena Willis # # Licensed AGPL-3.0 # # $Log: modcon,v $ +# Revision 1.5 2025/02/01 03:17:46 snw +# Fix session list +# # Revision 1.4 2025/01/31 19:41:00 snw # Move to a UNIX UI paradigm # @@ -121,45 +124,52 @@ sub list_ras_sessions { my $hashref = decode_json($json); my $sessions = $hashref->{sessions}; my $arrayref = $sessions->{sessions}; - my $ct = 0; + my @result = (); foreach my $session (@{$arrayref}) { - print "$session->{screen_name}\n"; - - $ct = $ct + 1; - - if($ct > $hchar - 2) { - print "ENTER to continue, Q to quit..."; - my $resp = ; - chomp($resp); - if($resp eq "Q") { - return; - } - elsif($resp eq "q") { - return; - } - $ct = 0; - } + push(@result, $session->{id}); } - print "$sessions->{count} current sessions\n"; + return @result; } sub list_ras_screennames { my($id) = @_; - - $cnclient->GET("/chivanet/ras_screen_names?id=$id"); + + my @result = (); + $cnclient->GET("/chivanet/user_ras_screen_names?id=$id"); my $json = $cnclient->responseContent(); my $hashref = decode_json($json); my $arrayref = $hashref->{screen_names}; + + foreach my $item (@{$arrayref}) { + push(@result, $item->{screen_name}); + } + - return @{$arrayref}; + return @result; } sub list_ras_users { - return (); + my @result = (); + $cnclient->GET("/chivanet/all_ras_screen_names"); + my $json = $cnclient->responseContent(); + my $hashref = decode_json($json); + + if($hashref->{ok} == 0) { + print "RPC error\n"; + return @result; + } + + my $arrayref = $hashref->{screen_names}; + + foreach my $entryref (@{$arrayref}) { + push(@result, $entryref->{id}); + } + + return @result; } sub print_sso_user { @@ -217,9 +227,7 @@ sub print_ras_user { } else { print "Screen Name : $id [$online]\n\n"; - } - -# print Dumper($status); + } } @@ -242,6 +250,33 @@ sub send_im { } } +sub ls { + my ($description, @entries) = @_; + + my @sorted = sort(@entries); + my $maxlen = 0; + foreach my $entry (@sorted) { + my $len = length($entry); + if ($len > $maxlen) { + $maxlen = $len; + } + } + $maxlen = $maxlen + 2; + my $ct = $#sorted + 1; + foreach my $entry (@sorted) { + if($col + $maxlen >= $wchar) { + print "\n"; + $col = 0; + } + else { + printf("%-$maxlen\s", $entry); + $col = $col + $maxlen; + } + } + print "\n$ct items in $description\n"; + +} + sub prompt { my $rawcmd = ''; @@ -269,7 +304,7 @@ sub prompt { my @cmd = split(' ', $rawcmd); - if ($cmd[0] eq "exit" || $cmd[0] eq "logout" || $cmd[0] eq "quit" || $cmd[0] eq "bye") { + if ($cmd[0] eq "exit" || $cmd[0] eq "logout" || $cmd[0] eq "quit" || $cmd[0] eq "bye" || $cmd[0] eq "lo") { return; } elsif ($cmd[0] eq "pwd") { @@ -402,8 +437,7 @@ sub prompt { } } } - } # if .. - + } # if .. } elsif ($cmd[0] eq "im") { if($mode eq "RAS") { @@ -450,6 +484,23 @@ sub prompt { print "field: command invalid outside of ras directory\n"; } } + elsif ($cmd[0] eq "sessions") { + if($mode ne "RAS") { + print "sessions: must be in ras mode\n"; + } + else { + ls "active RAS sessions", list_ras_sessions(); + } + } + elsif ($cmd[0] eq "lssn") { + if($mode ne "SSO" || $user eq "---") { + print "lssn: must be in sso mode with a user selected\n"; + } + else { + my @sns = list_ras_screennames($user); + ls "RAS screen names for $user", @sns; + } + } elsif ($cmd[0] eq "ls") { my @entries = (); @@ -479,27 +530,7 @@ sub prompt { my $col = 0; my $pstr = join('/', @path); my $pfin = "/$pstr"; - my @sorted = sort(@entries); - my $maxlen = 0; - foreach my $entry (@sorted) { - my $len = length($entry); - if ($len > $maxlen) { - $maxlen = $len; - } - } - $maxlen = $maxlen + 2; - my $ct = $#sorted + 1; - foreach my $entry (@sorted) { - if($col + $maxlen >= $wchar) { - print "\n"; - $col = 0; - } - else { - printf("%-$maxlen\s", $entry); - $col = $col + $maxlen; - } - } - print "\n\t$ct items in $pfin\n"; + ls $pfin, @entries; } }