; ; ift-kermit.rc - kermit configuration for uploading and downloading OATS and ; OATS status files per NASDR regulations. This configuration ; should provide a suitable alternative to the tool recommended ; by the NASDR supplied by http://www.valicert.com/ ; ; Specifications for this process is available at ; http://www.nasdr.com/3310.ASP ; ; Adam Prato - 2003-11-15 - http://adam.pra.to/ ; ; General procedure: ; Get cookie header (HEAD /~) ; Find location header for path to home dir (HEAD /~) ; put file based on location or retrieve status based on location ; ; example http headers: ; HTTP/1.1 200 OK ; Date: Thu, 13 Nov 2003 06:32:40 GMT ; Server: Apache/1.3.26 (Unix) mod_ssl/2.8.10 OpenSSL/0.9.6g SecureTransport/4.1.1 ; Set-Cookie: FDX=abcdefghijklmnopqrst/g==; path=/ ; Accept-Ranges: bytes ; Expires: Thu, 01 Jan 1970 00:00:00 GMT ; Features: CHPWD;RTCK;STCK;ASC ; Content-Type: text/plain; charset=UTF-8 ; ; Usage: create a kermit script that does the following: ; define CurHost as the remote host ; define CurUser as the username on the remote host ; define CurPass as the password for the username on the remote host ; call KConnect ; call KPut or KGet to upload or download the filename in question ; Then call kermit: ; kermit scriptname -y ift-kermit.rc ; ; (Yes, that sounds convoluded, but it fits right into a pre-built automation ; scheme.) ; define cookie none define location none set authentication tls verify off define KConnect { ; Use a proxy if User/Pass/Host are defined if def \m(ProxyUser) , if def \m(ProxyPass) , if def \m(ProxyHost) { set tcp http-proxy /user:\m(ProxyUser) /password:\m(ProxyPass) \m(ProxyHost) } ; Open HTTP connection to host using HTTP Basic auth. http /user:\m(CurUser) /password:\m(CurPass) open \m(CurHost) https if fail exit 1 Can't reach \m(CurHost) ; Retrieve headers to set cookie echo Retrieving headers to find cookie. http /array:&h head /~ echo HTTP Says: \v(http_code) \v(http_message) if ( > \v(http_code) 400 && < \v(http_code) 600 ) { echo ... Error from HEAD request: (HEAD /~) ignoring... } else { echo ... Retrieved headers from HEAD request (HEAD /~). Parsing for cookie. } ; Parse header array for cookie for \%i 1 \fdim(&h) 1 { if match \&h[\%i] Set-Cookie* { .\%n := \fsplit(\&h[\%i],&c,{ }) assign cookie \&c[2] } } ; We did it all for the cookie. if match cookie none { echo ... Could not set cookie from headers: for \%i 1 \fdim(&h) 1 { echo \%i . \&h[\%i] } exit 1 } else { echo ... Set cookie (\m(cookie))from headers. } ; Retrieve headers to set location echo Retrieving second set of headers. Ignore 302 (redirect) false alarm... http /array:&h /HEADER:Cookie:{\m(cookie)} head /~ echo HTTP Says: \v(http_code) \v(http_message) if ( > \v(http_code) 400 && < \v(http_code) 600 ) { echo ... Error from HEAD request: (HEAD /~), ignoring... exit 1 } else { echo ... Retrieved headers from HEAD request (HEAD /~). Parsing for location. } ; Parse header array for location. for \%i 1 \fdim(&h) 1 { if match \&h[\%i] Location* { .\%n := \fsplit(\&h[\%i],&l,{ }) assign location \&l[2] } } ; Home is where our files are. if match location none { echo ... Could not set location from headers: for \%i 1 \fdim(&h) 1 { echo \%i . \&h[\%i] } exit 1 } else { echo ... Set location (\m(location)) from headers. } } define KPut { assign remotefile \m(location)\%1 echo Storing file \%1 as \m(remotefile)... http /array:&h /HEADER:Cookie:{\m(cookie)} put \%1 \m(remotefile) echo HTTP Says: \v(http_code) \v(http_message) if ( > \v(http_code) 400 && < \v(http_code) 600 ) { echo ... Error put'ing file: (PUT \m(remotefile)) echo \v(http_message) for \%i 1 \fdim(&h) 1 { echo \%i . \&h[\%i] } exit 1 } else { echo ... Uploaded file \m(remotefile) successfully. } } define KGet { if def subpath { assign remotefile \m(location)\m(subpath)/\%1 } else { assign remotefile \m(location)\%1 } echo Retrieving file \m(remotefile) as \%1... http /array:&h /HEADER:Cookie:{\m(cookie)} get \m(remotefile) \%1 echo HTTP Says: \v(http_code) \v(http_message) if ( > \v(http_code) 400 && < \v(http_code) 600 ) { echo ... Error get'ing file (GET \m(remotefile)) echo \v(http_message) for \%i 1 \fdim(&h) 1 { echo \%i . \&h[\%i] } exit 1 } else { echo ... Retrieved file (\m(remotefile)) successfully. } } define KChangeDir { if def \%1 { echo ... Setting subpath to \%1 assign subpath \%1 } } define KFinish { ; do nothing. def donothing donothing }