Source code: *
#! SETL_BIN/setl -k
-- This script should be placed in the Web server's cgi-bin directory or
-- equivalent, after SETL_BIN and VC_DIR are defined by configuration.
const vc_dir = VC_DIR; -- WEBeye home directory name
const vc_link = vc_dir+`/vc-link.html';
const fresh = vc_dir+`/vc-fresh.html';
const broken = vc_dir+`/vc-broken.html';
const java = vc_dir+`/vc-java.html';
const vc_prefix = `CGI|'; -- pseudo-document convention
magic := false;
-- Try up to 10 times to read through link. The link file should
-- always exist after the first time the Box is started, except
-- very briefly during major life-cycle transitions when the Box is
-- shut down or restarted:
loop for i in {1..10} while (content := getfile vc_link) = om do
select (om, 50); -- wait 50 ms and try again
end loop;
if content = om then
-- WEBeye Box probably never started
put_document (getfile fresh);
elseif match (content, vc_prefix) = vc_prefix then
-- Pseudo-document
lookup := break (content, `|'); -- location of lookup service
lookup_fd := open (lookup, `socket');
if lookup_fd = om then
-- Lookup server did not accept connection
put_diagnostic_about (`lookup');
else
html := getfile java;
for service_name in [`giver', `mouse', `evjump', `evzoom'] loop
writea (lookup_fd, service_name);
reada (lookup_fd, [service_host, service_port]);
gsub (html, to_upper service_name + `_PORT', str service_port);
end loop;
close (lookup_fd);
put_document (html);
end if;
else
-- Link points to a (static) real document
put_document (content);
end if;
proc put_mime_headers;
print (`Content-type: text/html');
print;
end proc;
proc put_document (content);
put_mime_headers;
putchar (content);
end proc;
proc put_diagnostic_about (service_name);
var content := getfile broken;
gsub (content, `SERVICE', service_name);
put_document (content);
end proc;