search.php3 2.05 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2002, 2004, 2005 University of Utah and the Flux Group.
Leigh Stoller's avatar
Leigh Stoller committed
5 6
# All rights reserved.
#
7 8 9 10 11 12 13
require("defs.php3");

#
# Standard Testbed Header
#
PAGEHEADER("Search Emulab Documentation");

14 15 16 17
#
# We no longer support an advanced search option. We might bring it back
# someday.
#
18
function SPITSEARCHFORM($query)
19 20 21
{
    echo "<table align=center border=1>
          <form action=search.php3 method=get>\n";
22

23
    $query = htmlspecialchars($query);
24

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
    #
    # 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";
}

if (!isset($query) || $query == "") {
46
    SPITSEARCHFORM("");
47 48 49 50 51 52
    PAGEFOOTER();
    return;
}

# Sanitize for the shell. Be fancy later.
if (!preg_match("/^[-\w\ \"]+$/", $query)) {
53
    SPITSEARCHFORM("");
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
    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");

80
SPITSEARCHFORM($query);
81 82
flush();

83 84 85 86 87 88 89 90 91 92 93
#
# First the Knowledge Base
#
$embedded    = 1;
$query_type  = "and";
$query_which = "both";
include("kb-search.php3");

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

94 95 96 97 98 99 100 101 102 103 104 105
if ($fp = popen("$TBSUEXEC_PATH nobody nobody websearch '$query'", "r")) {
    while (!feof($fp)) {
	$string = fgets($fp, 1024);
	echo "$string";
	flush();
    }
    pclose($fp);
    $fp = 0;
}
else {
    TBERROR("Query failed: $query", 0);
}
106 107 108 109 110 111 112

#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>