search.php3 3.85 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
23
#
24 25
require("defs.php3");

26 27 28 29 30
#
# Verify page arguments.
#
$optargs = OptionalPageArguments("submit",      PAGEARG_STRING,
				 "query",       PAGEARG_STRING);
31 32 33 34 35 36 37 38
#
# Utah now stores its documentation in a Trac wiki. The Utah web site
# and web sites that link to Utahs documentation will use the Trac
# search engine at Utah. Optionally, if you have the docs locally
# in html format, continue to use the swish search tools on it. Note that
# the knowledge base in the DB is also deprecated; all of that content
# was pushed into the wiki.
#
39

40 41 42 43
#
# We no longer support an advanced search option. We might bring it back
# someday.
#
44
function SPITSEARCHFORM($query)
45 46 47
{
    echo "<table align=center border=1>
          <form action=search.php3 method=get>\n";
48

49
    $query = CleanString($query);
50

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
    #
    # Just the query please.
    #
    echo "<tr>
             <td class=left>
                 <input type=text name=query value=\"$query\"
                        size=25 maxlength=100>
               </td>
           </tr>\n";
    
    echo "<tr>
              <td align=center>
                 <b><input type=submit name=submit value='Submit Query'></b>
              </td>
          </tr>\n";

    echo "</form>
          </table><br>\n";
}

71 72 73 74 75 76 77
if (!isset($query) || $query == "") {
    PAGEHEADER("Search Emulab Documentation");
    SPITSEARCHFORM("");
    PAGEFOOTER();
    return;
}

78
if ($TBMAINSITE || $REMOTEWIKIDOCS) {
79
    $query = urlencode($query);
80
    header("Location: search_cse.php?query=$query");
81 82 83 84 85 86 87 88
    return;
}

#
# Standard Testbed Header after possible redirect above.
#
PAGEHEADER("Search Emulab Documentation");

89 90
# Sanitize for the shell. Be fancy later.
if (!preg_match("/^[-\w\ \"]+$/", $query)) {
91
    SPITSEARCHFORM("");
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
    PAGEFOOTER();
    return;
}

#
# Run the query. We get back html we can just spit out.
#
#
# A cleanup function to keep the child from becoming a zombie, since
# the script is terminated, but the children are left to roam.
#
$fp = 0;

function CLEANUP()
{
    global $fp;

    if (!$fp || !connection_aborted()) {
	exit();
    }
    pclose($fp);
    exit();
}
ignore_user_abort(1);
register_shutdown_function("CLEANUP");

118
SPITSEARCHFORM($query);
119 120
flush();

121
$safe_query  = escapeshellarg($query);
122 123 124 125

echo "<br>\n";
echo "<font size=+2>Documentation search results</font><br>\n";

126
if ($fp = popen("$TBSUEXEC_PATH nobody nobody websearch $safe_query", "r")) {
127 128 129 130 131 132 133 134 135
    while (!feof($fp)) {
	$string = fgets($fp, 1024);
	echo "$string";
	flush();
    }
    pclose($fp);
    $fp = 0;
}
else {
136
    $query = CleanString($query);
137 138
    TBERROR("Query failed: $query", 0);
}
139

140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
#
# Add search to the browser's toolbar
#
echo "
<script type='text/javascript' language='javascript'>
function addSearch() {
    if (window.external &&
        ('AddSearchProvider' in window.external)) {
            window.external.AddSearchProvider('$TBBASE/emusearch.xml');
    } else {
        alert('Sorry, your web browser does not support Opensearch');
    }
}
</script>

<p>
<a onclick='addSearch();'>Add the Emulab search engine to your browser's
    toolbar</a>
</p>
";

161 162 163 164 165 166
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>