cURL
Haxx ad
libcurl

Shopping cart software, Online file storage, Online photo storage, Hosted shopping cart, Contact management software, Email marketing software, Project management software, Issue tracking software, Online notepad, Web publishing software

curl's project page on SourceForge.net

Sponsors:
Haxx

Contents of /perl/contrib/formfind

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations) (download)
Tue Oct 19 18:36:17 2004 UTC (5 years, 3 months ago) by bagder
Branch: MAIN
CVS Tags: before_ftp_statemachine, curl-7_15_6-prepipeline, curl-7_15_1, curl-7_15_0, curl-7_15_3, curl-7_15_2, curl-7_15_5, curl-7_15_4, curl-7_12_3, curl-7_13_2, curl-7_13_1, curl-7_13_0, curl-7_17_0-preldapfix, curl-7_18_0, curl-7_18_1, curl-7_18_2, curl-7_19_5, curl-7_19_4, curl-7_19_7, curl-7_19_6, curl-7_19_1, curl-7_19_0, curl-7_19_3, curl-7_19_2, curl-7_16_4, curl-7_16_2, curl-7_16_3, curl-7_16_0, curl-7_16_1, curl-7_17_1, curl-7_17_0, curl-7_14_0, curl-7_14_1, curl-7_20_0, HEAD
Changes since 1.5: +5 -5 lines
Ralph Mitchell fixed: input field with NAME= and VALUE= weren't processed
properly case insensitive
1 #!/usr/bin/env perl
2 # $Id: formfind,v 1.6 2004/10/19 18:36:17 bagder Exp $
3 #
4 # formfind.pl
5 #
6 # This script gets a HTML page on stdin and presents form information on
7 # stdout.
8 #
9 # Author: Daniel Stenberg <daniel@haxx.se>
10 # Version: 0.2 Nov 18, 2002
11 #
12 # HISTORY
13 #
14 # 0.1 - Nov 12 1998 - Created now!
15 # 0.2 - Nov 18 2002 - Enhanced. Removed URL support, use only stdin.
16 #
17
18 $in="";
19
20 if($ARGV[0] eq "-h") {
21 print "Usage: $0 < HTML\n";
22 exit;
23 }
24
25 sub namevalue {
26 my ($tag)=@_;
27 my $name=$tag;
28 if($name =~ /name *=/i) {
29 if($name =~ /name *= *([^\"\']([^ \">]*))/i) {
30 $name = $1;
31 }
32 elsif($name =~ /name *= *(\"|\')([^\"\']*)(\"|\')/i) {
33 $name=$2;
34 }
35 else {
36 # there is a tag but we didn't find the contents
37 $name="[weird]";
38 }
39
40 }
41 else {
42 # no name given
43 $name="";
44 }
45 # get value tag
46 my $value= $tag;
47 if($value =~ /[^\.a-zA-Z0-9]value *=/i) {
48 if($value =~ /[^\.a-zA-Z0-9]value *= *([^\"\']([^ \">]*))/i) {
49 $value = $1;
50 }
51 elsif($value =~ /[^\.a-zA-Z0-9]value *= *(\"|\')([^\"\']*)(\"|\')/i) {
52 $value=$2;
53 }
54 else {
55 # there is a tag but we didn't find the contents
56 $value="[weird]";
57 }
58 }
59 else {
60 $value="";
61 }
62 return ($name, $value);
63 }
64
65
66 while(<STDIN>) {
67 $line = $_;
68 push @indoc, $line;
69 $line=~ s/\n//g;
70 $line=~ s/\r//g;
71 $in=$in.$line;
72 }
73
74 while($in =~ /[^<]*(<[^>]+>)/g ) {
75 # we have a tag in $1
76 $tag = $1;
77
78 if($tag =~ /^<!--/) {
79 # this is a comment tag, ignore it
80 }
81 else {
82 if(!$form &&
83 ($tag =~ /^< *form/i )) {
84 $method= $tag;
85 if($method =~ /method *=/i) {
86 $method=~ s/.*method *= *(\"|)([^ \">]*).*/$2/gi;
87 }
88 else {
89 $method="get"; # default method
90 }
91 $action= $tag;
92 $action=~ s/.*action *= *(\'|\"|)([^ \"\'>]*).*/$2/gi;
93
94 $method=uc($method);
95
96 $enctype=$tag;
97 if ($enctype =~ /enctype *=/) {
98 $enctype=~ s/.*enctype *= *(\'|\"|)([^ \"\'>]*).*/$2/gi;
99
100 if($enctype eq "multipart/form-data") {
101 $enctype="multipart form upload [use -F]"
102 }
103 $enctype = "\n--- type: $enctype";
104 }
105 else {
106 $enctype="";
107 }
108
109 print "--- FORM report. Uses $method to URL \"$action\"$enctype\n";
110 $form=1;
111 }
112 elsif($form &&
113 ($tag =~ /< *\/form/i )) {
114
115 print "--- end of FORM\n";
116 $form=0;
117 if( 0 ) {
118 print "*** Fill in all or any of these: (default assigns may be shown)\n";
119 for(@vars) {
120 $var = $_;
121 $def = $value{$var};
122 print "$var=$def\n";
123 }
124 print "*** Pick one of these:\n";
125 for(@alts) {
126 print "$_\n";
127 }
128 }
129 undef @vars;
130 undef @alts;
131 }
132 elsif($form &&
133 ($tag =~ /^< *(input|select)/i)) {
134 $mtag = $1;
135
136 ($name, $value)=namevalue($tag);
137
138 if($mtag =~ /select/i) {
139 print "Select: NAME=\"$name\"\n";
140 push @vars, "$name";
141 $select = 1;
142 }
143 else {
144 $type=$tag;
145 if($type =~ /type *=/i) {
146 $type =~ s/.*type *= *(\'|\"|)([^ \"\'>]*).*/$2/gi;
147 }
148 else {
149 $type="text"; # default type
150 }
151 $type=uc($type);
152 if(lc($type) eq "reset") {
153 # reset types are for UI only, ignore.
154 }
155 elsif($name eq "") {
156 # let's read the value parameter
157
158 print "Button: \"$value\" ($type)\n";
159 push @alts, "$value";
160 }
161 else {
162 print "Input: NAME=\"$name\"";
163 if($value ne "") {
164 print " VALUE=\"$value\"";
165 }
166 print " ($type)\n";
167 push @vars, "$name";
168 # store default value:
169 $value{$name}=$value;
170 }
171 }
172 }
173 elsif($form &&
174 ($tag =~ /^< *textarea/i)) {
175 my ($name, $value)=namevalue($tag);
176
177 print "Textarea: NAME=\"$name\"\n";
178 }
179 elsif($select) {
180 if($tag =~ /^< *\/ *select/i) {
181 print "[end of select]\n";
182 $select = 0;
183 }
184 elsif($tag =~ /[^\/] *option/i ) {
185 my ($name, $value)=namevalue($tag);
186 my $s;
187 if($tag =~ /selected/i) {
188 $s= " (SELECTED)";
189 }
190 print " Option VALUE=\"$value\"$s\n";
191 }
192 }
193 }
194 }

donate! Page updated November 16, 2009.
web site info

File upload with ASP.NET