version 1.4, 2025/01/31 19:41:00
|
version 1.8, 2025/03/10 15:34:45
|
Line 11
|
Line 11
|
# Licensed AGPL-3.0 |
# Licensed AGPL-3.0 |
# |
# |
# $Log$ |
# $Log$ |
|
# Revision 1.8 2025/03/10 15:34:45 snw |
|
# Undo the change |
|
# |
|
# Revision 1.7 2025/03/10 15:31:54 snw |
|
# Test |
|
# |
|
# Revision 1.6 2025/02/04 18:55:12 snw |
|
# Updates |
|
# |
|
# Revision 1.5 2025/02/01 03:17:46 snw |
|
# Fix session list |
|
# |
# Revision 1.4 2025/01/31 19:41:00 snw |
# Revision 1.4 2025/01/31 19:41:00 snw |
# Move to a UNIX UI paradigm |
# Move to a UNIX UI paradigm |
# |
# |
Line 30 use JSON;
|
Line 42 use JSON;
|
use Data::Dumper; |
use Data::Dumper; |
use Term::ReadKey; |
use Term::ReadKey; |
use Getopt::Long; |
use Getopt::Long; |
|
use Text::Glob qw(match_glob); |
|
|
my $sso_account = ''; |
my $sso_account = ''; |
my $apikey = ''; |
my $apikey = ''; |
Line 121 sub list_ras_sessions {
|
Line 134 sub list_ras_sessions {
|
my $hashref = decode_json($json); |
my $hashref = decode_json($json); |
my $sessions = $hashref->{sessions}; |
my $sessions = $hashref->{sessions}; |
my $arrayref = $sessions->{sessions}; |
my $arrayref = $sessions->{sessions}; |
my $ct = 0; |
my @result = (); |
|
|
foreach my $session (@{$arrayref}) { |
foreach my $session (@{$arrayref}) { |
print "$session->{screen_name}\n"; |
push(@result, $session->{id}); |
|
|
$ct = $ct + 1; |
|
|
|
if($ct > $hchar - 2) { |
|
print "ENTER to continue, Q to quit..."; |
|
my $resp = <STDIN>; |
|
chomp($resp); |
|
if($resp eq "Q") { |
|
return; |
|
} |
|
elsif($resp eq "q") { |
|
return; |
|
} |
|
$ct = 0; |
|
} |
|
} |
} |
|
|
print "$sessions->{count} current sessions\n"; |
return @result; |
} |
} |
|
|
sub list_ras_screennames { |
sub list_ras_screennames { |
my($id) = @_; |
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 $json = $cnclient->responseContent(); |
my $hashref = decode_json($json); |
my $hashref = decode_json($json); |
my $arrayref = $hashref->{screen_names}; |
my $arrayref = $hashref->{screen_names}; |
|
|
|
foreach my $item (@{$arrayref}) { |
|
push(@result, $item->{screen_name}); |
|
} |
|
|
|
|
return @{$arrayref}; |
return @result; |
} |
} |
|
|
sub list_ras_users { |
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 { |
sub print_sso_user { |
Line 217 sub print_ras_user {
|
Line 237 sub print_ras_user {
|
} |
} |
else { |
else { |
print "Screen Name : $id [$online]\n\n"; |
print "Screen Name : $id [$online]\n\n"; |
} |
} |
|
|
# print Dumper($status); |
|
|
|
} |
} |
|
|
Line 242 sub send_im {
|
Line 260 sub send_im {
|
} |
} |
} |
} |
|
|
|
sub ls { |
|
my ($description, $match, @entries) = @_; |
|
|
|
if($match eq "") { |
|
$match = '*'; |
|
} |
|
|
|
print "Directory of [$description] matching \'$match\':\n\n"; |
|
|
|
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(match_glob($match, $entry)) { |
|
if($col + $maxlen >= $wchar) { |
|
print "$entry\n"; |
|
$col = 0; |
|
} |
|
else { |
|
printf("%-$maxlen\s", $entry); |
|
$col = $col + $maxlen; |
|
} |
|
} |
|
else { |
|
$ct = $ct - 1; |
|
} |
|
} |
|
|
|
print "\n\n$ct matching items in directory\n"; |
|
} |
|
|
sub prompt { |
sub prompt { |
|
|
my $rawcmd = ''; |
my $rawcmd = ''; |
Line 269 sub prompt {
|
Line 328 sub prompt {
|
|
|
my @cmd = split(' ', $rawcmd); |
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; |
return; |
} |
} |
elsif ($cmd[0] eq "pwd") { |
elsif ($cmd[0] eq "pwd") { |
Line 387 sub prompt {
|
Line 446 sub prompt {
|
@path = @oldpath; |
@path = @oldpath; |
} |
} |
else { |
else { |
$mode = "SSO"; |
$mode = "RAS"; |
@path = ('sso', $user); |
@path = ('ras', $user); |
} |
} |
} |
} |
else { |
else { |
Line 402 sub prompt {
|
Line 461 sub prompt {
|
} |
} |
} |
} |
} |
} |
} # if .. |
} # if .. |
|
|
} |
} |
elsif ($cmd[0] eq "im") { |
elsif ($cmd[0] eq "im") { |
if($mode eq "RAS") { |
if($mode eq "RAS") { |
Line 450 sub prompt {
|
Line 508 sub prompt {
|
print "field: command invalid outside of ras directory\n"; |
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 { |
|
if($cmd[1]) { |
|
ls "active RAS sessions", $cmd[1], list_ras_sessions(); |
|
} |
|
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); |
|
if($cmd[1]) { |
|
ls "RAS screen names for $user", $match, @sns; |
|
} |
|
else { |
|
ls "RAS screen names for $user", '*', @sns; |
|
} |
|
} |
|
} |
elsif ($cmd[0] eq "ls") { |
elsif ($cmd[0] eq "ls") { |
my @entries = (); |
my @entries = (); |
|
|
Line 479 sub prompt {
|
Line 564 sub prompt {
|
my $col = 0; |
my $col = 0; |
my $pstr = join('/', @path); |
my $pstr = join('/', @path); |
my $pfin = "/$pstr"; |
my $pfin = "/$pstr"; |
my @sorted = sort(@entries); |
if($cmd[1]) { |
my $maxlen = 0; |
ls $pfin, $cmd[1], @entries; |
foreach my $entry (@sorted) { |
} |
my $len = length($entry); |
else { |
if ($len > $maxlen) { |
ls $pfin, '*', @entries; |
$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"; |
|
} |
} |
|
|
} |
} |