Sign in to follow this  
Followers 0
jamesband

need help creating a CGI to launch download

5 posts in this topic

I am attempting to create a CGI scriptusing autoit. What I want ultimately want to have is a CGI script that will compile an autoit script based on the QUERY_STRING passed by the web server and then sending that compiled script back to the user.

http://whatever.org/compileit.exe?name=jamesband

I am having trouble with sending the file back as a response. Anyone here have any ideas? I know that "Content: application/octet-stream" can be sent back via the consolewrite(), but how do I attach the file to it?

Share this post


Link to post
Share on other sites



I have found some perl code that gives some hints, but it has been a long time since I've done any perl programming and when I did, it wasn't very good. Any perl gurus out there?

# send the file to the client's browser
select STDOUT;
$| = 1;
print "Content-Type: application\/force-download\nContent-Disposition: attachment\; filename=$dlfile\nContent-Length: $size\nContent-Description: Larry\'s File Downloader 0.2\n\n";
open(FILEIN, $dlfile) or $err = $!;
if ($err) {
  &js_alert($alert_msg,1,"exit");  # abort if can't open download file
  die;
}
binmode FILEIN if (-B $dlfile);  # binary mode if binary file
my $blksize = (stat FILEIN)[11];  # get file system block size
if (!$blksize) {
  $blksize = 16384;
}
my($read,$buf,$log_entry);
while ($read = sysread FILEIN, $buf, $blksize) {
  if (!defined $read) {
       next if $! =~ /^Interrupted/;
       if ($logfile) {
      open LOG, "+>>$logfile" or $err = $!; 
      if (!$err) {
        $log_entry = "$date - System Read Error - $!\n\n";
        print LOG $log_entry;
        close LOG;
        $logfile = 0;
      }
    }
    &js_alert($alert_msg,1,"exit");  # abort - file read error
       die;
  }
  my $written = 0;
  my $offset = 0;
  while ($read) {
       $written = syswrite STDOUT, $buf, $read, $offset;
    if (!defined($written)) {
         if ($logfile) {
        open LOG, "+>>$logfile" or $err = $!; 
        if (!$err) {
          $log_entry = "$date - System Write Error - $!\n\n";
          print LOG $log_entry;
          close LOG;
          $logfile = 0;
        }
      }
      &js_alert($alert_msg,1,"exit");  # abort - file write error
      die;
    }
    $read -= $written;
    $offset += $written;
  }
}
# finished sending the file

Share this post


Link to post
Share on other sites

I am using Larry's binary code and this is what I have so far... on a 120K test exe i am only getting 115K! I am missing something.

Also, I have the compiled script in a cgi-bin folder and am calling it through a webbrowser to test.

dim $file, $line, $iline, $path, $size, $x, $y

$path = envget('PATH_TRANSLATED')&'\cgi-bin\'

consolewrite('Content-Type: Application'&@lf&'Content-Disposition: name="test.exe"'&@lf&'Content-Transfer-Encoding: binary'&@lf&@lf)

TrayTip("cgi:", "openning file...", 3)
$size = filegetsize($path&"test.exe")
$file = _apifileopen($path&"test.exe")

if ($file = -1) then
    TrayTip("cgi:", "could not open '"&$path&"test.exe'", 10)
    sleep(10000)
    exit    
else
    TrayTip("cgi:", "transmitting file...", 3)
    for $x = 1 to $size step 1024
        TrayTip("cgi:", $x, 1)
        _APIFileSetPos($file,$x)

        $iline = stringsplit(_apifileread($file,1024,1), ",")
        for $y = 1 to $iline[0]
            consolewrite(Chr(Dec($iline[$y])))
        next

    next
    
    TrayTip("cgi:", "closing file...", 3)
    _apifileclose($file)
endif

Share this post


Link to post
Share on other sites

Well, so long as I am typing to myself. I might as well point out to myself that the problem is on of two:

1. consolewrite will not send a chr(00) (null)

2. autoit treats chr(00) (null) as "" (which it is mo certainly not!)

So, does anyone have any ideas on how to handle this?

Share this post


Link to post
Share on other sites

Well, so long as I am typing to myself.  I might as well point out to myself that the problem is on of two:

1.  consolewrite will not send a chr(00) (null)

2.  autoit treats chr(00) (null) as ""  (which it is mo certainly not!)

So, does anyone have any ideas on how to handle this?

<{POST_SNAPBACK}>

it is #2... :) hehehe the following code produces 'len=1', in a msgbox.

aaaaaaaaaaaaaaaaaah! executables have null characters in them, and I need to transmit them from a cgi! I am sooooooooooooooo close! Heeeeeeeeeeeeelp!

dim $s
$s = "1"
for $x = 1 to 10
    $s = $s & chr(0)
next

msgbox(0, "", "len="&stringlen($s))

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0