5 # This script gets a HTML page from the specified URL and presents form
6 # information you may need in order to machine-make a respond to the form.
8 # Written to use 'curl' for URL fetching.
10 # Author: Daniel Stenberg <Daniel.Stenberg@sth.frontec.se>
11 # Version: 0.1 Nov 12, 1998
18 # respect file:// URLs for local file fetches!
30 if(($geturl eq "") && !$usestdin) {
31 print "Usage: $0 <full source URL>\n",
32 " Use a traling slash for directory URLs!\n";
35 # If you need a proxy for web access, edit your .curlrc file to feature
38 # linkchecker, URL will be appended to the right of this command line
39 # this is the one using HEAD:
40 $linkcheck = "curl -s -m 20 -I";
42 # as a second attempt, this will be used. This is not using HEAD but will
43 # get the whole frigging document!
44 $linkcheckfull = "curl -s -m 20 -i";
46 # htmlget, URL will be appended to the right of this command line
49 # urlget, URL will be appended to the right of this command line
50 # this stores the file with the remote file name in the current dir
51 $urlget = "curl -O -s";
53 # Parse the input URL and split it into the relevant parts:
58 if($inurl=~ /^([^:]+):\/\
/([^\/]*)\
/(.*)\/(.*)/ ) {
64 elsif ($inurl=~ /^([^:]+):\/\
/([^\/]*)\
/(.*)/ ) {
70 if($getpath !~ /\//) {
76 elsif ($inurl=~ /^([^:]+):\/\
/(.*)/ ) {
83 print "Couldn't parse the specified URL, retry please!\n";
92 #print "protocol = $getprotocol\n";
93 #print "server = $getserver\n";
94 #print "path = $getpath\n";
95 #print "document = $getdocument\n";
98 open(HEADGET
, "$linkcheck $geturl|") ||
99 die "Couldn't get web page for some reason";
103 if($_ =~ /HTTP\/.*3\d\d
/) {
107 ($_ =~ /^Location: (.*)/)) {
118 if($pagemoved == 1) {
119 print "Page is moved but we don't know where. Did you forget the ",
124 open(WEBGET
, "$htmlget $geturl|") ||
125 die "Couldn't get web page for some reason";
149 while($in =~ /[^<]*(<[^>]+>)/g ) {
150 # we have a tag in $1
153 if($tag =~ /^<!--/) {
154 # this is a comment tag, ignore it
158 ($tag =~ /^< *form/i )) {
160 if($method =~ /method *=/i) {
161 $method=~ s/.*method *= *(\"|)([^ \">]*).*/$2/gi;
164 $method="get"; # default method
167 $action=~ s/.*action *= *(\"|)([^ \">]*).*/$2/gi;
172 if ($enctype =~ /enctype *=/) {
173 $enctype=~ s/.*enctype *= *(\'|\"|)([^ \"\'>]*).*/$2/gi;
175 if($enctype eq "multipart/form-data") {
176 $enctype="multipart form upload [use -F]"
178 $enctype = "\n--- type: $enctype";
184 print "--- FORM report. Uses $method to URL \"$action\"$enctype\n";
185 # print "TAG: $tag\n";
186 # print "METHOD: $method\n";
187 # print "ACTION: $action\n";
191 ($tag =~ /< *\/form
/i
)) {
192 # print "TAG: $tag\n";
193 print "--- end of FORM\n";
196 print "*** Fill in all or any of these: (default assigns may be shown)\n";
202 print "*** Pick one of these:\n";
211 ($tag =~ /^< *(input|select)/i)) {
213 # print "TAG: $tag\n";
216 if($name =~ /name *=/i) {
217 $name=~ s/.*name *= *(\"|)([^ \">]*).*/$2/gi;
225 if($value =~ /value *=/i) {
226 $value=~ s/.*value *= *(\"|)([^ \">]*).*/$2/gi;
232 if($mtag =~ /select/i) {
233 print "Select: $name\n";
239 if($type =~ /type *=/i) {
240 $type =~ s/.*type *= *(\"|)([^ \">]*).*/$2/gi;
243 $type="text"; # default type
246 if(lc($type) eq "reset") {
247 # reset types are for UI only, ignore.
250 # let's read the value parameter
252 print "Button: \"$value\" ($type)\n";
253 push @alts, "$value";
260 print "Input: $name$info ($type)\n";
262 # store default value:
263 $value{$name}=$value;
268 ($tag =~ /^< *\/ *select/i
)) {