#! /usr/bin/perl
use CGI (':standard');
use IPC::Run ('run');
use MIME::Base32 ('RFC');
use Sys::Syslog (':standard', ':macros');
use HTML::Template;
$template = << 'END';
EyeBot Cross Compiler 6.5
EyeBot Cross Compiler 6.5
Notes:
- This site only supports ROBIOS 6.5. If you have an older version of the BIOS you will need to download and install one of the rob65?.hex BIOS upgrades from here (refer to the README.txt file in the parent directory for an explination of the filenames).
- The result's filename will contain only letters, numbers, hyphens and underscores (spaces and other characters are stripped out to simplify compiling).
- Source files are purged from this system immediately after compilation.
- Results may be purged from this system as early as one hour after the compile begins.
Tip:
In Windows NT, 2K or XP, if you create a ".bat" file containing the below three lines, you can then drag-and-drop your ".hex" files onto the batch file in Windows Explorer to quickly send them to the EyeBot connected to your COM port.
@echo off
mode com1: baud=115200 parity=n data=8 stop=1 to=off xon=off odsr=off octs=on dtr=off rts=hs idsr=off > nul
copy /b %1 com1: > nul
Resources:
- For more information about Eyebots, visit the creator's webpage here.
- Please notifiy cs-support at siue dot edu if this online compiler does not function correctly.
- The source of this cgi script can be viewed/downloaded from here
END
$robios = '/usr/local/robios';
$uploads = '/roboti/html/eyebot';
$session = MIME::Base32::encode(sprintf('%s.%s', $ENV{'REMOTE_ADDR'}, time() % 1000));
$ENV{'ROBIOS'} = $robios;
$ENV{'PATH'} .= ":/usr/local/bin:$robios/bin/linux";
$q = CGI->new();
$t = HTML::Template->new('scalarref' => \$template);
print header();
if ($q->param()) {
LogIt();
if ($fhandle = upload('filename')) {
$filename = pop(@{[split(/\\\//, $q->param('filename'))]}); # remove leading path if present
$filename = substr($filename, 0, rindex($filename, '.')) if (rindex($filename, '.') != -1); # remove filename extension if present
$filename =~ s/[^0-9A-Za-z\.\-_]//g; # remove non alpha-numerics if present
$compiler = $robios . '/bin/linux/' . (($q->param('compiler') eq 'gcc68') ? 'gcc68' : 'gcchdt');
run [ '/bin/bash', '-c', "mkdir -p $uploads/$session; cd $uploads/$session; dos2unix > $filename.c; $compiler -o $filename.hex $filename.c; rm $filename.elf $filename.c" ], $fhandle, \$out, \$err;
$t->param('out', $out);
$t->param('err', $err);
$t->param('hex', "$filename.hex") if (-e "$uploads/$session/$filename.hex");
}
}
print $t->output();
sub LogIt {
openlog('robios', 'cons', LOG_USER);
syslog(LOG_INFO, '%s %s', $ENV{'REMOTE_ADDR'}, $q->param('compiler'));
closelog();
}