Annotation of ChivanetModcon/modcon, revision 1.1.1.1
1.1 snw 1: #!/usr/bin/env perl
2:
3: #
4: # ChivaNet Moderator Console
5: # Copyright (C) 2025 Coherent Logic Development LLC
6: #
7: # $Id$
8: #
9: # Author: Serena Willis <snw@coherent-logic.com>
10: #
11: # Licensed AGPL-3.0
12: #
13: # $Log$
14: #
15:
16: use REST::Client;
17: use JSON;
18: use Getopt::Long;
19: use Data::Dumper;
20: use Term::ReadKey;
21:
22: my $rasurl = '';
23: my $apikey = '';
24: my $online = 0;
25: my $modcon_version = '0.0.1';
26: my $cnclient = '';
27: my $rasclient = '';
28:
29: my $wchar = '';
30: my $hchar = '';
31: my $wpixels = '';
32: my $hpixels = '';
33:
34: sub list_sso_users {
35: $cnclient->GET("/chivanet/users");
36: my $ct = 0;
37:
38: my $json = $cnclient->responseContent();
39: my $hashref = decode_json($json);
40:
41: if($hashref->{ok} == 1) {
42: my $arrayref = $hashref->{users};
43: my @users = sort(@{$arrayref});
44:
45: foreach my $user (@users) {
46: print "$user\n";
47: $ct = $ct + 1;
48:
49: if($ct > $hchar - 2) {
50: print "ENTER to continue, Q to quit...";
51: my $resp = <STDIN>;
52: chomp($resp);
53: if($resp eq "Q") {
54: return;
55: }
56: elsif($resp eq "q") {
57: return;
58: }
59: $ct = 0;
60: }
61: }
62: }
63: else {
64: print "RPC error\n";
65: }
66: }
67:
68: sub list_ras_users {
69:
70: }
71:
72: sub prompt {
73:
74: my $rawcmd = '';
75: my $mode = 'SSO';
76: my $user = '---';
77:
78: while (1) {
79: print "MODCON [$mode/$user]> ";
80: my $line = <STDIN>;
81: chomp($line);
82: $rawcmd = $line;
83:
84: my @cmd = split(' ', $rawcmd);
85:
86: if ($cmd[0] eq "quit") {
87: return;
88: }
89: elsif ($cmd[0] eq "mode") {
90: if($cmd[1] eq "SSO") {
91: $mode = "SSO";
92: $user = "---";
93: }
94: elsif ($cmd[1] eq "RAS") {
95: $mode = "RAS";
96: $user = "---";
97: }
98: else {
99: print "?\n";
100: }
101: }
102: elsif ($cmd[0] eq "list") {
103: if($cmd[1] eq "users") {
104: if($mode eq "SSO") {
105: list_sso_users();
106: }
107: elsif($mode eq "RAS") {
108: list_ras_users();
109: }
110: }
111: else {
112: print "?\n";
113: }
114: }
115: else {
116: print "?\n"
117: }
118: }
119:
120: }
121:
122: sub main {
123: GetOptions("rasurl=s" => \$rasurl,
124: "apikey=s" => \$apikey)
125: or die("error in command line arguments");
126:
127: ($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize();
128:
129: $cnclient = REST::Client->new({
130: host => 'https://chivanet.org/rest/api',
131: timeout => 10});
132:
133: $cnclient->addHeader('Authorization', "Apikey $apikey");
134:
135: $rasclient = REST::Client->new({
136: host => $rasurl,
137: timeout => 10});
138:
139: print "ChivaNet MODCON $modcon_version\n";
140: print " Copyright (C) 2025 Coherent Logic Development LLC\n\n";
141:
142: prompt();
143: print "Goodbye.\n"
144: }
145:
146: main();
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>