The frontend to our (unnamed as of right now) CS490 project.
Each php script can be either a sender+receiver
or a receiver
.
A sender+receiver
is a php script which will use cURL
to "send" some data to another script and will have some data "returned" to it by the script they called. Front and Mid both belong to this category.
A receiver
is a php script that doesn't use cURL
to communicate to another script: it simply gets passed some data from another script, performs some logic on it, and returns some data to the script that called it. Back belongs to this category.
<?php
//receives data from calling script/document via $_POST
$v = $_POST['credentials'];
//performs some optional initial logic with the data
//i.e hashing, etc.
//Sends data to "next in chain" script
$ch = curl_init();
//@TODO: update with correct "following" php path
curl_setopt($ch, CURLOPT_URL, "the_php_target.php");
curl_setopt($ch, CURLOPT_POST, TRUE);
//$v may have been modified - it's the data you send to the next script
curl_setopt($ch, CURLOPT_POSTFIELDS, "credentials=" . $v);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//Get the result from the execution (what the "NiC" script will return)
$output = curl_exec($ch);
if($output === false)
echo 'Curl error: ' . curl_error($ch);
else {
//If no errors, (optionally modify/apply logic) and return data to the script that called you
echo $output;
}
curl_close($ch);
?>
<?php
//receives data from calling script/document via $_POST
$v = $_POST['credentials'];
//performs some optional initial logic with the data
//i.e hashing, etc.
//DOES NOT CALL CURL - it is the "last in line"
//Simply returns what it wants to pass onto its caller
$output = '{"njit":"", "local":"false"}';
echo $output
?>
- Front reads input from HTML, passes a
Credentials
JSON object tofront.php
with username and plaintext password. front.php
gets thisCredentials
and passes it onto Middle inmid.php
.- Middle gets this
Credentials
and performs spoof logic to NJIT with them and keeps track of the outcome. - While doing #3, it makes an extra copy of
Credentials
, and replaces the plaintext password with a hashed one (via php'shash()
). Middle sends this "hashed"Credentials
object and passes it onto Back inback.php
. - Back gets this "hashed"
Credentials
and compares the hashed password to the hashed password on the DB. Based on the result, Back prepares a partially completeResult
JSON object (with only the local result) and returns it. - Middle gets this returned
Result
, and completes theResult
by adding the outcome of the NJIT spoof. It returns this completeResult
. - Frontend receives this
Result
, and returns it. - Within JS, a function is called to update the view on the browser based on the
Result
.
Will send a Credentials
JSON object to Middle.
{
"user": user_name,
"password": their_hashed_password
}
Expects a Result
JSON object from Middle.
{
"njit" : "success",
"local" : "failure"
}