#!/usr/bin/env perl # # ChivaNet Moderator Console # Copyright (C) 2025 Coherent Logic Development LLC # # $Id: modcon,v 1.1 2025/01/30 19:16:06 snw Exp $ # # Author: Serena Willis # # Licensed AGPL-3.0 # # $Log: modcon,v $ # Revision 1.1 2025/01/30 19:16:06 snw # Initial revision # # use REST::Client; use JSON; use Getopt::Long; use Data::Dumper; use Term::ReadKey; my $rasurl = ''; my $apikey = ''; my $online = 0; my $modcon_version = '0.0.1'; my $cnclient = ''; my $rasclient = ''; my $wchar = ''; my $hchar = ''; my $wpixels = ''; my $hpixels = ''; sub list_sso_users { $cnclient->GET("/chivanet/users"); my $ct = 0; my $json = $cnclient->responseContent(); my $hashref = decode_json($json); if($hashref->{ok} == 1) { my $arrayref = $hashref->{users}; my @users = sort(@{$arrayref}); foreach my $user (@users) { print "$user\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; } } } else { print "RPC error\n"; } } sub list_ras_users { } sub prompt { my $rawcmd = ''; my $mode = 'SSO'; my $user = '---'; while (1) { print "MODCON [$mode/$user]> "; my $line = ; chomp($line); $rawcmd = $line; my @cmd = split(' ', $rawcmd); if ($cmd[0] eq "quit") { return; } elsif ($cmd[0] eq "mode") { if($cmd[1] eq "SSO") { $mode = "SSO"; $user = "---"; } elsif ($cmd[1] eq "RAS") { $mode = "RAS"; $user = "---"; } else { print "?\n"; } } elsif ($cmd[0] eq "list") { if($cmd[1] eq "users") { if($mode eq "SSO") { list_sso_users(); } elsif($mode eq "RAS") { list_ras_users(); } } else { print "?\n"; } } else { print "?\n" } } } sub main { GetOptions("rasurl=s" => \$rasurl, "apikey=s" => \$apikey) or die("error in command line arguments"); ($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize(); $cnclient = REST::Client->new({ host => 'https://chivanet.org/rest/api', timeout => 10}); $cnclient->addHeader('Authorization', "Apikey $apikey"); $rasclient = REST::Client->new({ host => $rasurl, timeout => 10}); print "ChivaNet MODCON $modcon_version\n"; print " Copyright (C) 2025 Coherent Logic Development LLC\n\n"; prompt(); print "Goodbye.\n" } main();