/usr/share/perl5/Conmux.pm is in conmux 0.12.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | #
# Conmux.pm -- core console multiplexor package
#
# Implements the core multiplexor functionality such as resolution of
# names and connecting to the conmux server.
#
# (C) Copyright IBM Corp. 2004, 2005, 2006
# Author: Andy Whitcroft <andyw@uk.ibm.com>
#
# The Console Multiplexor is released under the GNU Public License V2
#
package Conmux;
use URI::Escape;
use File::Basename;
use Cwd 'abs_path';
our $Config;
BEGIN {
my $abs_path = abs_path($0);
my $dir_path = dirname($abs_path);
my $cf = '/usr/local/conmux/etc/config';
if (-e "$dir_path/etc/config") {
$cf = "$dir_path/etc/config";
} elsif (-e "$dir_path/../etc/config") {
$cf = "$dir_path/../etc/config";
}
if (-f $cf) {
open(CFG, "<$cf") || die "Conmux: $cf: open failed - $!\n";
while(<CFG>) {
chomp;
next if (/^#/ || /^\s*$/ || !/=/);
my ($name, $value) = split(/=/, $_, 2);
$value =~ s/^"//;
$value =~ s/"$//;
# Substitute variables.
while ($value =~ /\$([A-Za-z0-9_]+)/) {
my $v = $Config->{$1};
$value =~ s/\$$1/$v/;
}
$Config->{$name} = $value;
}
close(CFG);
}
}
sub encodeArgs {
my (%a) = @_;
my ($a, $n, $s);
##print "0<$_[0]> ref<" . ref($_[0]) . ">\n";
# Handle being passed references to hashes too ...
$a = \%a;
$a = $_[0] if (ref($_[0]) eq "HASH");
for $n (sort keys %{$a}) {
$s .= uri_escape($n) . '=' . uri_escape($a->{$n}) .
' ';
}
chop($s);
$s;
}
sub decodeArgs {
my ($s) = @_;
my (%a, $nv, $n, $v);
# Decode the standard argument stream.
for $nv (split(' ', $s)) {
($n, $v) = split('=', $nv, 2);
$a{uri_unescape($n)} = uri_unescape($v);
}
%a;
}
sub sendCmd {
my ($fh, $c, $a) = @_;
my ($rs);
# Send the encoded command ...
print $fh $c . " " . encodeArgs($a) . "\n";
# Read the reply.
$rs = <$fh>;
chomp($rs);
decodeArgs($rs);
}
sub sendRequest {
my ($fh, $c, $a) = @_;
my %a = { 'result' => 'more' };
# Send the encoded command ...
print $fh $c . " " . encodeArgs($a) . "\n";
%a;
}
sub revcResult {
my ($fh) = @_;
my ($rs);
# Read the reply.
$rs = <$fh>;
chomp($rs);
decodeArgs($rs);
}
#
# Configuration.
#
sub configRegistry {
my $reg = $Config->{'registry'};
$reg = "localhost" if (!$reg);
$reg;
}
# Connect to the host/port specified on the command line,
# or localhost:23
sub connect {
my ($to) = @_;
my ($reg, $sock);
# host:port
if ($to =~ /:/) {
# Already in the right form.
# registry/service
} elsif ($to =~ m@(.*)/(.*)@) {
my ($host, $service) = ($1, $2);
$to = Conmux::Registry::lookup($host, $service);
# service
} else {
$to = Conmux::Registry::lookup('-', $to);
}
$sock = new IO::Socket::INET(Proto => 'tcp', PeerAddr => $to)
or die "Conmux::connect $to: connect failed - $@\n";
# Turn on keep alives by default.
$sock->sockopt(SO_KEEPALIVE, 1);
$sock;
}
package Conmux::Registry;
sub lookup {
my ($host, $service) = @_;
$host = Conmux::configRegistry() if ($host eq '-');
# Connect to the registry service and lookup the requested service.
my $reg = new IO::Socket::INET(Proto => 'tcp',
PeerAddr => "$host", PeerPort => 63000)
or die "Conmux::connect: registry not available - $@\n";
my %r = Conmux::sendCmd($reg, 'LOOKUP', { 'service' => $service });
die "Conmux::Registry::lookup: $service: error - $r{'status'}\n"
if ($r{status} ne "OK");
close($reg);
$r{'result'};
}
sub add {
my ($host, $service, $location) = @_;
$host = Conmux::configRegistry() if ($host eq '-');
# Connect to the registry service and lookup the requested service.
my $reg = new IO::Socket::INET(Proto => 'tcp',
PeerAddr => "$host", PeerPort => 63000)
or die "Conmux::connect: registry not available - $@\n";
my %r = Conmux::sendCmd($reg, 'ADD', { 'service' => $service,
'location' => $location });
die "Conmux::Registry::add: $service: error - $r{'status'}\n"
if ($r{status} ne "OK");
close($reg);
1;
}
sub list {
my ($host, $service, $location) = @_;
my (@results, %r);
$host = Conmux::configRegistry() if ($host eq '-');
# Connect to the registry service and ask for a list.
my $reg = new IO::Socket::INET(Proto => 'tcp',
PeerAddr => "$host", PeerPort => 63000)
or die "Conmux::connect: registry not available - $@\n";
%r = Conmux::sendCmd($reg, 'LIST', { });
## while ($r{'status'} eq 'more') {
## %r = receiveResult($reg);
## push(@results, $r{'result'});
## }
die "Conmux::Registry::list: error - $r{'status'}\n"
if ($r{'status'} ne "OK");
close($reg);
$r{'result'};
}
1;
|