示例#1
0
        $val = scrubInput($val);
        //just in case someone does something funky to the form
        if ($count == count($checkedTests) - 1) {
            $testString = $testString . $val;
        } else {
            $testString = $testString . $val . ", ";
        }
        $count++;
    }
    //END foreach checkedTests
    $inputs["username"] = scrubInput($_REQUEST["username"]);
    $inputs["email"] = scrubInput($_REQUEST["email"]);
    $inputs["troubleTicket"] = scrubInput($_REQUEST["troubleTicket"]);
    $inputs["testCSV"] = $testString;
    //everything is scrubbed and prepped for entry into the DB, so let's do this
    insertNewISORequest($inputs);
}
//END successful submission if/then
?>

	<div id="inputSection" name="inputSection">

		<form id="isoRequest" name="isoRequest" action="<?php 
echo htmlspecialchars($_SERVER["PHP_SELF"]);
?>
" method="post">
	    	<fieldset>
	    		<legend>ISO Request Form</legend>
	    		* required fields <br>
	    		IP Address to test*:	  <input type="text" name="testTargetIP" id="testTargetIP"> <?php 
echo $inputErrors["ipAddress"];
示例#2
0
function generateISORequestForm()
{
    //required variables
    $isoFormInputs = array('username' => "", 'email' => "", 'phoneNumber' => "", 'affiliation' => "", 'scpPubKey' => "", 'troubleTicket' => "", 'testTargetIP' => "", 'testCSV' => "", 'maxRun' => "", 'validToDate' => "", 'queueName' => "");
    $isoFormInputErrors = array('username' => "", 'email' => "", 'phoneNumber' => "", 'affiliation' => "", 'scpPubKey' => "", 'troubleTicket' => "", 'testTargetIP' => "", 'testCSV' => "", 'maxRun' => "", 'validToDate' => "", 'queueName' => "");
    //array of tests. We might be able to make this a little more
    //readable once we get a list of available tests(?) maybe read from DB(??)
    $allTests = array("Iperf", "Owping", "Ping", "Tcpdump", "Tracepath", "Traceroute");
    $isoFormInputErrFlag = 0;
    //has there been a request sent to the server?
    //are the variables empty?
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        if (empty($_REQUEST["isoTestTargetIP"])) {
            $isoFormInputErrors["ipAddress"] = "You must provide an IP address";
            $errFlag = 1;
        }
        if (empty($_REQUEST["isoMaxRun"])) {
            $isoFormInputErrors["maxRun"] = "You must enter a maximum number of runs";
            $errFlag = 1;
        }
        if ($_REQUEST["isoMaxRun"] < 1) {
            $isoFormInputErrors["maxRun"] = "The maximum number of runs must be at least 1";
            $errFlag = 1;
        }
        if ($_REQUEST["isoMaxRun"] > 25) {
            $isoFormInputErrors["maxRun"] = "The maximum number of runs must be 25 or less";
            $errFlag = 1;
        }
        if (empty($_REQUEST["isoValidToDate"])) {
            $isoFormInputErrors["validToDate"] = "You must enter an expiration date for the ISO";
            $errFlag = 1;
        } else {
            $format = "Y-m-d";
            $date = trim($_REQUEST["isoValidToDate"]);
            $time = strtotime($date);
            if (date($format, $time) != $date) {
                $isoFormInputErrors["validToDate"] = "You entered and invalid date or date format.";
                $errFlag = 1;
            }
        }
        if (empty($_REQUEST["isoTroubleTicket"])) {
            $isoFormInputErrors["troubleTicket"] = "You must provide a Trouble Ticket Number";
            $errFlag = 1;
        }
        if (empty($_REQUEST["isoUsername"])) {
            $isoFormInputErrors["username"] = "******";
            $errFlag = 1;
        }
        if (empty($_REQUEST["isoEmail"])) {
            $isoFormInputErrors["email"] = "You must provide an email address";
            $errFlag = 1;
        }
        if (empty($_REQUEST["isoAffiliation"])) {
            $isoFormInputErrors["affiliation"] = "You must list your affiliation";
            $errFlag = 1;
        }
        if (empty($_REQUEST["testCheckbox_list"])) {
            $isoFormInputErrors["testCSV"] = "You must select at least 1 test";
            $errFlag = 1;
        }
        if (empty($_REQUEST["queueName"])) {
            $inputErrors["queueName"] = "Specify an RT Queue for RT integration";
        }
        /////////////////////// CAN WE GENERATE THE ISO THEY JUST CONFIGURED? //////////////////////////////////////////////
        if ($errFlag != 1) {
            //have to assemble the tests in a csv
            $count = 0;
            $testString = "";
            $checkedTests = $_REQUEST["testCheckbox_list"];
            foreach ($checkedTests as $val) {
                $val = scrubInput($val);
                //just in case someone does something funky to the form
                if ($count == count($checkedTests) - 1) {
                    $testString = $testString . $val;
                } else {
                    $testString = $testString . $val . ", ";
                }
                $count++;
            }
            //END foreach checkedTests
            $inputs["username"] = scrubInput($_REQUEST["isoUsername"]);
            $inputs["email"] = scrubInput($_REQUEST["isoEmail"]);
            $inputs["troubleTicket"] = scrubInput($_REQUEST["isoTroubleTicket"]);
            $inputs["target"] = scrubInput($_REQUEST["isoTestTargetIP"]);
            $inputs["maxRun"] = scrubInput($_REQUEST["isoMaxRun"]);
            $date = scrubInput($_REQUEST["isoValidToDate"]);
            $inputs["validToDate"] = date("Y-m-d", strtotime($date));
            $inputs["testCSV"] = $testString;
            //everything is scrubbed and prepped for entry into the DB, so let's do this
            if (insertNewISORequest($inputs)) {
                if (!$_SESSION[CID] or !$_SESSION[UID]) {
                    echo "Missing necessary information (UID or CID) to build ISO.<p>";
                } else {
                    // It turns out that exec has an issue with some versions of bash which prevents it
                    // from properly redirecting STDIN and STDERR to a file. This prevents exec from going into
                    // the background. Turns out this proc_close(proc_open()) trick does work.
                    proc_close(proc_open("/home/rapier/testrig/isobuilder/isobuilder.pl -f /home/rapier/testrig/isobuilder/isobuilder.cfg -c {$_SESSION['CID']} -u {$_SESSION['UID']} 2>&1 /dev/null &", array(), $dummy_var));
                }
            } else {
                echo "Failed to create new ISO!<p>";
            }
        }
        //END successful submission if/then
    }
    //END request and empty var check
    $valid_date = date("m/d/Y", strtotime("+7 days"));
    //$isoForm will hold the entire new <div> element
    //we have to do this in a few steps due to the need for PHP_SELF to be in quotes for the redirection to work correctly
    $serverURL = htmlspecialchars($_SERVER["PHP_SELF"]);
    $isoForm = '<div id="isoRequestSection" name="isoRequestSection">
			<form id="isoRequest" name="isoRequest" action="' . $serverURL;
    $isoForm = $isoForm . '" method="post">
			<fieldset>
			<legend>ISO Request Form</legend>
			* required fields <br>
			IP Address to test*:	  <input type="text" name="isoTestTargetIP" id="isoTestTargetIP">' . $isoFormInputErrors["testTargetIP"] . '<br>
                        Maximum # of Runs:        <input type="text" name="isoMaxRun" id="isoMaxRun" value="7">' . $isoFormInputErrors["maxRun"] . '<br> 
                        ISO Valid Until:          <input type="date" name="isoValidToDate" id="isoValidToDate" value="' . $valid_date . '">' . $isoFormInputErrors["validToDate"] . '<br>
			Trouble Ticket No.*:	  <input type="text" name="isoTroubleTicket" id="isoTroubleTicket">' . $isoFormInputErrors["troubleTicket"] . '<br>
			Name*:			  <input type="text" name="isoUsername" id="isoUsername">' . $isoFormInputErrors["username"] . '<br>
			Email*:			  <input type="text" name="isoEmail" id="isoEmail">' . $isoFormInputErrors["email"] . '<br>
			Affiliation*:		  <input type="text" name="isoAffiliation" id="isoAffiliation">' . $isoFormInputErrors["affiliation"] . '<br>
			RT Queue Name:            <input type="text" name="queueName" id="queueName"> <?php echo $inputErrors["queueName"]; ?> <br>
			Tests to run*: <br>';
    //break for assembling the checkbox list
    $testList = '<ul title="Tests to Run">';
    //assemble the list of tests to choose from dynamically
    foreach ($allTests as $val) {
        $testList = $testList . '<li> <input type="checkbox" name="testCheckbox_list[]" id="testCheckbox_list[]" value=' . $val . '>' . $val . '</li>';
    }
    $testList = $testList . '</ul>';
    //Close the list of tests
    $isoForm = $isoForm . $testList;
    //add it to the form
    //finish the form
    $isoForm = $isoForm . $isoFormInputErrors["testCSV"] . '<br> <input type="submit" value="Submit"></fieldset></form></div>';
    return $isoForm;
}