Announcement

Collapse
No announcement yet.

Reading multipart form data with abyss server

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reading multipart form data with abyss server

    Still trying to use abyss and i have some problems.

    How can i read multipart data?
    I've figured it out for normal POST data <input type=text>, but the STDIN command doesnt work for binary data.

    Example html
    Code:
    <html><body>
    <h1>TEST</h1>
    
    <form action='http://server/cgi/env.exe' method='post' enctype='multipart/form-data'>
    <input type='file' name='filename.jpg'><br>
    <textarea name='description' rows=5 cols=60>Description here</textarea>
    <input type='hidden' value='2' name='record'>
    <input type='submit' value='send file'></form>
    </body></html>
    In the help file about STDIN (PBCC) it is written "doesn't work with pipes".
    But Abyss is sending the form data via a pipe...

    Life was much easier with Xitami...
    [email protected] | Zeepreventorium De Haan | Portraitfotografie | Home server

  • #2
    Life was much easier with Xitami...
    Marc,

    You'd be far better off if you simply used the PBCGI.INC routines. This stuff is a piece of cake and I think you're making it much harder than it needs to be.
    Software makes Hardware Happen

    Comment


    • #3
      i used
      OPEN ENVIRON$("CGI_STDIN") FOR BINARY AS #1
      GET$#1, LOF(1), a$: CLOSE #1

      and did the processing with a$

      But
      STDIN LINE a$
      doesn't work for binary data, as the input in interrupted at the first [CTRL]-[Z].
      BTW Joe, you'll find at least one citation in your reference book about the less traveled path bringing more rewards afterward.
      [email protected] | Zeepreventorium De Haan | Portraitfotografie | Home server

      Comment


      • #4
        That's the testcode i use, based on the exemples in the CGI folder with PBCC4
        Code:
        DEFINT a-z
        
        ' Trace environment in CGI
        FUNCTION PBMAIN()
        
            STDOUT "HTTP/1.1 200 OK"
            STDOUT "Content-Type: text/plain
            STDOUT
            STDOUT "Command: " + COMMAND$
            STDOUT "Query string: " + ENVIRON$("QUERY_STRING")
            STDOUT "STDIN ---"
            WHILE NOT STDEOF
                STDIN LINE a$
                STDOUT a$
            WEND
            STDOUT "----- ---"
            a$ = ENVIRON$(1): i = 1
            WHILE LEN(a$)
                STDOUT a$
                INCR i
                a$ = ENVIRON$(i)
            WEND
            STDOUT "----- ---
        END FUNCTION
        Works for text files, hangs for binary files...
        [email protected] | Zeepreventorium De Haan | Portraitfotografie | Home server

        Comment


        • #5
          BTW Joe, you'll find at least one citation in your reference book about the less traveled path bringing more rewards afterward.
          Not sure what reference book that is, but mine says, "don't reinvent the wheel, especially when the wheel works as advertised"
          Software makes Hardware Happen

          Comment


          • #6
            Tried the "dbg.exe" sample and it locks up.
            Keeps running in task manager and produce no output.
            BTW, i've written al my parsing routines already, just need to replace the file input with a stdin input.

            What are the win API calls for STDIN?
            [email protected] | Zeepreventorium De Haan | Portraitfotografie | Home server

            Comment


            • #7
              HTTP &quot;Sniffer&quot;

              Here is a link to a tool that can capture HTTP traffic and break it down much like a protocol sniffer.

              http://www.ieinspector.com/

              It is not free but works well.

              Sniffers can do the same as this tool (WireShark for one) but they are not so much HTTP aware. This can do much more than just a sniffer.

              It may help if you have some mysterious things going on but you can see them.
              Mark Strickland, CISSP, CEH
              SimplyBASICsecurity.com

              Comment


              • #8
                I already use ethereal, also a port sniffer.
                It looks like the application hangs whenever a control-z (or maybe other control charachers) are read. For normal form processing STDIN is fine, not for accepting binary files. Seems to be a limitation in STDIN.
                [email protected] | Zeepreventorium De Haan | Portraitfotografie | Home server

                Comment


                • #9
                  No solution yet.
                  Lock up, tried small values of c (GET$ statement), long SLEEP, no SLEEP, doesn't matter. Nearly the same result as with STDIN LINE
                  Code:
                  DEFLNG A-Z
                  FUNCTION PBMAIN()
                      STDOUT "HTTP/1.1 200 OK"
                      STDOUT "Content-Type: text/plain
                      STDOUT
                      c = VAL(ENVIRON$("CONTENT_LENGTH"))
                      STDOUT STR$(c)
                      h = GETSTDIN: ff = FREEFILE: OPEN HANDLE h FOR BINARY ACCESS READ AS #ff
                      GET$ #ff, c, a$
                      WHILE LEN(a$)
                          IF ERR THEN
                              STDOUT ERROR$
                              GOTO efx
                          END IF
                          STDOUT STR$(LEN(a$))
                          GET$ #ff, c, a$
                          SLEEP 1
                      WEND
                  efx:
                      CLOSE #ff
                      STDOUT "END"
                      EXIT FUNCTION
                  I'm struggling for nearly a month with this problem.
                  [email protected] | Zeepreventorium De Haan | Portraitfotografie | Home server

                  Comment


                  • #10
                    Tried the "dbg.exe" sample and it locks up.
                    Keeps running in task manager and produce no output.
                    I'd get dbg.exe to run before continuing with Abyss.
                    Do these match your configuration?
                    Enable Scripts Execution is checked.
                    In Script Paths
                    Virtual Path: /cgi-bin
                    Interface type: CGI

                    Also, most ISP's don't allow running on port 80.
                    Are you using another port on the call like
                    http://1.2.3.4:65500/cgi-bin/dbg.exe

                    In cgi execution timeout I use 30 seconds
                    Did dbg.bas source somehow get modified and contain a waitkey$?
                    Original:

                    Code:
                    #DIM ALL
                    #INCLUDE "PBCGI.INC"
                    '
                    FUNCTION PBMAIN () AS LONG
                        LOCAL ix AS LONG
                        LOCAL cgi AS STRING
                        cgi = ReadCGI
                        WriteCGI "<HTML><BODY>"
                        WriteCGI "<H2 ALIGN=CENTER>Power Basic Software Debugging CGI Application</H2>
                        WriteCGI "<H3>Environment Variables:</H3>"
                        WriteCGI "<UL>"
                        ix = 1
                        DO UNTIL ix > 255
                            cgi = ENVIRON$(ix)
                            IF LEN(cgi) THEN
                                WriteCGI "<li>" & cgi
                                INCR ix
                            END IF
                        LOOP WHILE LEN(cgi)
                        WriteCGI "</UL>"
                        WriteCGI "<H3>Additional Information:</H3>"
                        WriteCGI "<UL>"
                        WriteCGI "<LI>CURDIR$ = " & CURDIR$
                        WriteCGI "<LI>AppPath = " & AppPath
                        WriteCGI "<LI>DATE$ = " & DATE$
                        WriteCGI "<LI>TIME$ = " & TIME$
                        WriteCGI "</UL>"
                        WriteCGI "</BODY></HTML>"
                      END FUNCTION
                    Last edited by Mike Doty; 7 Jun 2008, 10:42 AM.
                    The world is full of apathy, but who cares?

                    Comment


                    • #11
                      That did the trick.
                      Actually don't know why, seems to be a windows bug, i get the same sort of lock-up from the command line (using windows pipes)
                      Code:
                      DEFLNG a-z
                      %STD_INPUT_HANDLE  = -10&
                      TYPE OVERLAPPED
                        Internal AS DWORD
                        InternalHigh AS DWORD
                        offset AS DWORD
                        OffsetHigh AS DWORD
                        hEvent AS DWORD
                      END TYPE
                      
                      DECLARE FUNCTION ReadFile LIB "KERNEL32.DLL" ALIAS "ReadFile"_
                              (BYVAL hFile AS DWORD, lpBuffer AS ANY, BYVAL nNumberOfBytesToRead AS DWORD, lpNumberOfBytesRead AS DWORD, lpOverlapped AS OVERLAPPED) AS LONG
                      DECLARE FUNCTION GetStdHandle LIB "KERNEL32.DLL" ALIAS "GetStdHandle" (BYVAL nStdHandle AS DWORD) AS DWORD
                      
                      
                      FUNCTION PBMAIN()
                      
                          ON ERROR GOTO erx
                          STDOUT "HTTP/1.1 200 OK"
                          STDOUT "Content-Type: text/plain
                          STDOUT
                          c = VAL(ENVIRON$("CONTENT_LENGTH"))
                          STDOUT STR$(c)
                          a$ = SPACE$(c): j = 1
                          b$ =""
                      
                          hInput = GetStdHandle(%STD_INPUT_HANDLE)
                          IF hInput THEN
                               DO
                                  Buffer$ = SPACE$(512)
                                  iResult = ReadFile(hInput, BYVAL STRPTR(Buffer$), LEN(Buffer$), iRead, BYVAL 0)
                                  IF iResult = 0 THEN
                                      STDOUT"---iResult=0: ERROR
                                      EXIT DO
                                  ELSEIF iRead = 0 THEN
                                      STDOUT "---iRead=0: Nothing to read
                                      EXIT DO
                                  ELSE
                                     MID$(a$, j, iRead) = Buffer$
                                     j = j + iRead
                                     b$ = b$ + STR$(j) + $CRLF
                                     ' stdout str$(c)
                                  END IF
                                  IF iRead < LEN(Buffer$) THEN
                                      STDOUT "---LastRead OK"
                                      STDOUT b$
                                     EXIT DO
                                  END IF
                              LOOP
                          END IF
                          g = FREEFILE: OPEN "f:\env.txt" FOR OUTPUT AS #g
                          PRINT #g, a$
                      ernd:
                          EXIT FUNCTION
                      erx:
                          CLOSE
                          STDOUT ERROR$
                          f = FREEFILE: OPEN "f:\enve.txt" FOR OUTPUT AS #f
                          PRINT #f, ERROR$
                          RESUME ernd
                      END FUNCTION
                      Lock up when the STDOUT is included in the loop, runs fine withou.
                      Conclusion: don't mix STDIN and STDOUT.
                      [email protected] | Zeepreventorium De Haan | Portraitfotografie | Home server

                      Comment

                      Working...
                      X