)(default)|) { $rights = 1; }
- }
- }
- $ulsout.=$ulsfn.'&'.join('&',@ulsstats);
- if($obs eq '1') { $ulsout.="&1"; }
- else { $ulsout.="&0"; }
- if($rights eq '1') { $ulsout.="&1:"; }
- else { $ulsout.="&0:"; }
- }
- closedir(LSDIR);
- }
- } else {
- my @ulsstats=stat($ulsdir);
- $ulsout.=$ulsfn.'&'.join('&',@ulsstats).':';
- }
- } else {
- $ulsout='no_such_dir';
- }
- if ($ulsout eq '') { $ulsout='empty'; }
- print $client "$ulsout\n";
- } else {
- Reply($client, "refused\n", $userinput);
-
- }
-# ----------------------------------------------------------------- setannounce
- } elsif ($userinput =~ /^setannounce/) {
- if (isClient) {
- my ($cmd,$announcement)=split(/:/,$userinput);
- chomp($announcement);
- $announcement=&unescape($announcement);
- if (my $store=IO::File->new('>'.$perlvar{'lonDocRoot'}.
- '/announcement.txt')) {
- print $store $announcement;
- close $store;
- print $client "ok\n";
- } else {
- print $client "error: ".($!+0)."\n";
- }
- } else {
- Reply($client, "refused\n", $userinput);
-
- }
-# ------------------------------------------------------------------ Hanging up
- } elsif (($userinput =~ /^exit/) ||
- ($userinput =~ /^init/)) { # no restrictions.
- &logthis(
- "Client $clientip ($clientname) hanging up: $userinput");
- print $client "bye\n";
- $client->shutdown(2); # shutdown the socket forcibly.
- $client->close();
- last;
-
-# ---------------------------------- set current host/domain
- } elsif ($userinput =~ /^sethost:/) {
- if (isClient) {
- print $client &sethost($userinput)."\n";
- } else {
- print $client "refused\n";
- }
-#---------------------------------- request file (?) version.
- } elsif ($userinput =~/^version:/) {
- if (isClient) {
- print $client &version($userinput)."\n";
- } else {
- print $client "refused\n";
- }
-# ------------------------------------------------------------- unknown command
-
- } else {
- # unknown command
- print $client "unknown_cmd\n";
- }
-# -------------------------------------------------------------------- complete
+ my $keep_going = 1;
+ my $user_input;
+ while(($user_input = get_request) && $keep_going) {
+ alarm(120);
+ Debug("Main: Got $user_input\n");
+ $keep_going = &process_request($user_input);
alarm(0);
- &status('Listening to '.$clientname);
+ &status('Listening to '.$clientname." ($keymode)");
}
+
# --------------------------------------------- client unknown or fishy, refuse
- } else {
+ } else {
print $client "refused\n";
$client->close();
&logthis("WARNING: "
."Rejected client $clientip, closing connection");
}
- }
+ }
# =============================================================================
@@ -3230,7 +3967,7 @@ sub sethost {
my (undef,$hostid)=split(/:/,$remotereq);
if (!defined($hostid)) { $hostid=$perlvar{'lonHostID'}; }
if ($hostip{$perlvar{'lonHostID'}} eq $hostip{$hostid}) {
- $currenthostid=$hostid;
+ $currenthostid =$hostid;
$currentdomainid=$hostdom{$hostid};
&logthis("Setting hostid to $hostid, and domain to $currentdomainid");
} else {
@@ -3270,6 +4007,74 @@ sub userload {
return $userloadpercent;
}
+# Routines for serializing arrays and hashes (copies from lonnet)
+
+sub array2str {
+ my (@array) = @_;
+ my $result=&arrayref2str(\@array);
+ $result=~s/^__ARRAY_REF__//;
+ $result=~s/__END_ARRAY_REF__$//;
+ return $result;
+}
+
+sub arrayref2str {
+ my ($arrayref) = @_;
+ my $result='__ARRAY_REF__';
+ foreach my $elem (@$arrayref) {
+ if(ref($elem) eq 'ARRAY') {
+ $result.=&arrayref2str($elem).'&';
+ } elsif(ref($elem) eq 'HASH') {
+ $result.=&hashref2str($elem).'&';
+ } elsif(ref($elem)) {
+ #print("Got a ref of ".(ref($elem))." skipping.");
+ } else {
+ $result.=&escape($elem).'&';
+ }
+ }
+ $result=~s/\&$//;
+ $result .= '__END_ARRAY_REF__';
+ return $result;
+}
+
+sub hash2str {
+ my (%hash) = @_;
+ my $result=&hashref2str(\%hash);
+ $result=~s/^__HASH_REF__//;
+ $result=~s/__END_HASH_REF__$//;
+ return $result;
+}
+
+sub hashref2str {
+ my ($hashref)=@_;
+ my $result='__HASH_REF__';
+ foreach (sort(keys(%$hashref))) {
+ if (ref($_) eq 'ARRAY') {
+ $result.=&arrayref2str($_).'=';
+ } elsif (ref($_) eq 'HASH') {
+ $result.=&hashref2str($_).'=';
+ } elsif (ref($_)) {
+ $result.='=';
+ #print("Got a ref of ".(ref($_))." skipping.");
+ } else {
+ if ($_) {$result.=&escape($_).'=';} else { last; }
+ }
+
+ if(ref($hashref->{$_}) eq 'ARRAY') {
+ $result.=&arrayref2str($hashref->{$_}).'&';
+ } elsif(ref($hashref->{$_}) eq 'HASH') {
+ $result.=&hashref2str($hashref->{$_}).'&';
+ } elsif(ref($hashref->{$_})) {
+ $result.='&';
+ #print("Got a ref of ".(ref($hashref->{$_}))." skipping.");
+ } else {
+ $result.=&escape($hashref->{$_}).'&';
+ }
+ }
+ $result=~s/\&$//;
+ $result .= '__END_HASH_REF__';
+ return $result;
+}
+
# ----------------------------------- POD (plain old documentation, CPAN style)
=head1 NAME
500 Internal Server Error
Internal Server Error
The server encountered an internal error or
misconfiguration and was unable to complete
your request.
Please contact the server administrator at
root@localhost to inform them of the time this error occurred,
and the actions you performed just before this error.
More information about this error may be available
in the server error log.