2 #####################################################################
6 # This script is used to make a query on the Ganymede server.
8 #####################################################################
11 use CGI
::Carp qw
/fatalsToBrowser/;
12 #####################################################################
14 # create the query with whatever CGI info we get from our environment
17 $my_url = $query->url();
19 $xml_path = "<#XMLPATH#>";
20 $xmlclient = $xml_path . "/xmlclient";
22 # Yes, the software is smarter than you, if you didn't include bin
23 # when installWeb asked you for the location of the client utils.
26 $xmlclient = $xml_path . "/bin/xmlclient";
29 $query_label = "Submit Query";
30 $schema_label = "Retrieve Schema";
32 # write out the CGI header
38 print $query->end_html;
43 print "<center><p>Error, can't find xmlclient</p></center>\n";
45 print $query->end_html;
49 $user = $query->param('user');
50 $password = $query->param('password');
51 $querystr = $query->param('querystr');
52 $submit = $query->param('submit');
55 $submit = $query_label;
58 if ($submit eq $query_label) {
62 # we know that we can trust $filename, because we created that,
63 # and we know that the $password is safe, because we're passing
64 # that in via STDIN, but we need to be careful to make sure that
65 # they haven't slipped us a mickey on the username $user.
67 # we do have to allow colons and whitespace thereafter for admin
68 # persona names, though.
70 # absolutely no single quotes or back slash characters allowed,
73 if ($user !~ /^[a-z]([a-z]|[0-9])*(:([a-z]|[0-9]|\s)+)?$/i) {
74 $user = "invalid_web_query_user";
77 # if they have any spaces in their name, convert to url escape
81 if ($submit eq $schema_label) {
82 $program = "$xmlclient 'username=$user' -dumpSchema 2>&1";
83 } elsif ($submit eq $query_label) {
84 $program = "$xmlclient 'username=$user' -queryfile $filename 2>&1";
88 open2
(*README
, *WRITEME
, $program);
93 $xml_output = "open2 failed: $!\n$@\n";
96 $xml_status = 1; # fail
98 print WRITEME
"$password\n";
109 $xml_status = $?
>> 8;
113 # cut out the interactive password prompt from xmlclient
115 $xml_output =~ s/^Password for.*\n//m;
118 if (($xml_status == 0)) {
119 print_success
($xml_output);
124 # Couldn't login to server... the server is going down for some reason?
125 # Can't login to the Ganymede server.. semaphore disabled: schema edit
126 # Error, couldn't log in to server.. bad username or password?
128 # XML submission failed.
130 if ($xml_output =~ /semaphore disabled/) {
131 $xml_output = "The Ganymede server is not currently accepting logins.\nPlease try again later.";
134 # Couldn't login to server... bad username/password?
135 # Error, couldn't log in to server.. bad username or password?
136 # XML submission failed.
138 if ($xml_output =~ /bad username/) {
139 $xml_output = "You did not enter your current username and/or password correctly.\n\nPlease try again.";
149 print $query->end_html;
153 ######################################################################
157 ######################################################################
161 # we want a really random filename
163 $randnum = int(rand 4096);
165 $filename = "$tmpdir/gany_query.$randnum.$$.txt"; #give temp query file random name
168 die "Error, $filename already exists!";
171 open(XMLF
, ">$filename") || die "Couldn't write to $filename";
172 chmod 0600, $filename;
178 chmod 0600, $filename;
183 ######################################################################
187 ######################################################################
190 print $query->header;
192 print <<ENDSTARTHEAD;
195 <title>Ganymede Query</title>
197 <!-- Insert your CSS here -->
199 <body bgcolor="#FFFFFF">
203 <!-- Insert your site-specific header here -->
207 ######################################################################
211 ######################################################################
215 <!-- your custom footer goes here -->
219 ######################################################################
223 ######################################################################
231 <a href="http://www.arlut.utexas.edu/gash2/"><img src="/images/ganymede_title2_sm.gif" border="0"></a>
233 <td width="100%" align="center">
234 <h1>Ganymede Query Utility</h1>
240 <a href="http://www.arlut.utexas.edu/gash2/"><small>[Ganymede Home]</small></a>
242 <td width="100%" align="center">
243 <small><a href="http://tools.arlut.utexas.edu/gash2/doc/querylanguage/">Ganymede Query Language Guide</a></small>
252 <form method="post" action="$my_url" name="former">
253 <table width="60%" bgcolor="#ccffcc" border="1" cellpadding="2">
254 <tr bgcolor="#663366">
255 <td colspan="2" align="center">
256 <big><font color="ffffcc">Ganymede Query Utility</font></big>
261 <td align="right"><b>Query:</b></td>
262 <td><input type="text" size="120" name="querystr"></td>
266 <td align="right"><b>Username</b></td>
267 <td><input type="text" name="user"></td>
271 <td align=right><b>Password</b></td>
272 <td><input type="password" name="password"></td>
276 <td colspan="2" align="right"><input type="submit" name="submit" value="$query_label"><input type="submit" name="submit" value="$schema_label"></td>
279 <tr bgcolor="#663366">
280 <td colspan="2"> </td>
290 ######################################################################
294 # Outputs the $xml_output to the user with an appropriate MIME header
296 ######################################################################
299 print $query->header("-type"=>"application/xml",
300 "-attachment"=>"ganymede_results.xml");