Example #1
0
 /**
  * sets up the database connection and provides it to PHPUnit
  *
  * @see <https://phpunit.de/manual/current/en/database.html#database.configuration-of-a-phpunit-database-testcase>
  * @return \PHPUnit_Extensions_Database_DB_IDatabaseConnection PHPUnit database connection interface
  */
 public final function getConnection()
 {
     //If the connection has not been established yet, create it
     if ($this->connection === null) {
         //connect to mySQL and provide the interface to PHPUnit
         $config = readConfig("/etc/apache2/capstone-mysql/jpegery.ini");
         $pdo = connectToEncryptedMySQL("/etc/apache2/capstone-mysql/jpegery.ini");
         $this->connection = $this->createDefaultDBConnection($pdo, $config["database"]);
     }
     return $this->connection;
 }
Example #2
0
 /**
  * sets up the database connection and provides it to PHPUnit
  *
  * @see <https://phpunit.de/manual/current/en/database.html#database.configuration-of-a-phpunit-database-testcase>
  * @return \PHPUnit_Extensions_Database_DB_IDatabaseConnection PHPUnit database connection interface
  **/
 public final function getConnection()
 {
     // if the connection hasn't been established, create it
     if ($this->connection === null) {
         // connect to mySQL and provide the interface to PHPUnit
         $config = readConfig("/etc/apache2/data-design/dmcdonald21.ini");
         $pdo = connectToEncryptedMySQL("/etc/apache2/data-design/dmcdonald21.ini");
         $this->connection = $this->createDefaultDBConnection($pdo, $config["database"]);
     }
     return $this->connection;
 }
<?php

require_once "/etc/apache2/capstone-mysql/encrypted-config.php";
require_once "profile.php";
$pdo = connectToEncryptedMySQL("/etc/apache2/data-design/vhooker.ini");
$profile = new Profile(null, 1, "this is from PHP");
$profile->insert($pdo);
$profile->setProfile("now I changed the message");
$profile->update($pdo);
$profile->delete($pdo);
Example #4
0
<?php

//namespace Edu\Cnm\Dmancini1\Cnn;
require_once dirname(__DIR__) . "/lib/validate-date.php";
require_once "/etc/apache2/capstone-mysql/encrypted-config.php";
$pdo = connectToEncryptedMySQL("/etc/apache2/data-design/dmancini1.ini");
//LOCAL DEVELOPMENT Connection
//$pdo = new PDO('mysql:host=localhost;dbname=dmancini1', 'dmancini1', 'password');
/*
 * Article
 *
 * Article is the actual content of a news article, including title, description, and content (copy)
 * Article does not contain any media or media ids; the link to media is located in articleMedia.
 *
 * @author David Mancini <*****@*****.**>
 */
//Secure and Encrypted PDO Database Connection
class Article
{
    /*
     * id is primary key
     * @var int articleId
     */
    private $articleId;
    /*
     * author id a foreign key from the author class
     * @var int authorId
     */
    private $authorId;
    /*
     * title is the article title
Example #5
0
<?php

require_once __DIR__ . "/php/classes/autoload.php";
require_once __DIR__ . "/lib/xsrf.php";
require_once "/etc/apache2/capstone-mysql/encrypted-config.php";
use Edu\Cnm\Jpegery\Profile;
use Edu\Cnm\Jpegery\Image;
if (session_status() !== PHP_SESSION_ACTIVE) {
    session_start();
}
$reply = new stdClass();
$reply->status = 200;
try {
    $pdo = connectToEncryptedMySQL("/etc/apache2/capstone-mysql/jpegery.ini");
    $caption = filter_input(INPUT_POST, "caption", FILTER_SANITIZE_STRING);
    $image = new Image(null, $_SESSION["profile"]->getProfileId(), "temporaryType", "temporaryName", $caption, null);
    $image->insert($pdo);
    $image->imageUpload();
    //Connect to encrypted mySQL
    $image->update($pdo);
    $reply->message = "This worked. Or didn't and you somehow screwed it up so much you got a false positive. Either way, good job.";
    $reply->data = $image;
} catch (Exception $exception) {
    $reply->status = $exception->getCode();
    $reply->data = $exception->getMessage();
}
//Echo the json, encode the $reply.
header("Content-type: application/html");
echo json_encode($reply);
Example #6
0
/**
 * controller/api for the teamStatistic  class
 *
 * @author Jude Chavez <*****@*****.**>
 */
//verify the xsrf challenge
if (session_status() !== PHP_SESSION_ACTIVE) {
    session_start();
}
//prepare an empty reply
$reply = new stdClass();
$reply->status = 200;
$reply->data = null;
//grab the mySQL connection
try {
    $pdo = connectToEncryptedMySQL("/etc/apache2/capstone-mysql/sprots.ini");
    //determine which HTTP method was used
    $method = array_key_exists("HTTP_X_HTTP_METHOD", $_SERVER) ? $_SERVER["HTTP_X_HTTP_METHOD"] : $_SERVER["REQUEST_METHOD"];
    //sanitize inputs
    $id = filter_input(INPUT_GET, "id", FILTER_VALIDATE_INT);
    //make sure the id is valid for methods that require it
    if (($method === "DELETE" || $method === "PUT") && (empty($id) === true || $id < 0)) {
        throw new InvalidArgumentException("id can not be empty or negitive", 405);
    }
    //sanitize and trim other fields
    $teamStatisticGameId = filter_input(INPUT_GET, "gameId", FILTER_SANITIZE_NUMBER_INT);
    $teamStatisticTeamId = filter_input(INPUT_GET, "teamId", FILTER_SANITIZE_NUMBER_INT);
    $teamStatisticStatisticId = filter_input(INPUT_GET, "statisticId", FILTER_SANITIZE_NUMBER_INT);
    $teamStatisticValue = filter_input(INPUT_GET, "statisticValue", FILTER_SANITIZE_NUMBER_INT);
    //handle REST calls, while only allowing administrators to access database-modifying methods
    if ($method === "GET") {
Example #7
0
<?php

// secure PDO connection
require_once "/etc/apache2/capstone-mysql/encrypted-config.php";
$pdo = connectToEncryptedMySQL("/etc/apache2/data-design/zleyba.ini");
/**
 *Item is an individual listing at a given location
 *
 *An item is used to contain all relevant info for an
 *individual classified listing. This info includes a
 *unique identification number, the general location,
 *the title, description of item, and contact info for
 *the seller. Additionally it may include the price and
 *photos of the item(s)
 *
 *@author Zach Leyba <*****@*****.**>
 **/
class Item
{
    /**ID for this item, this is the primary key
     * @var int $itemId
     **/
    private $itemId;
    /**ID# of the user who posted the item, this is the foreign key
     * @var int $userId
     **/
    private $userId;
    /** Full length description of the item to be sold
     * @var  string $itemDescription
     */
    private $itemDescription;
Example #8
0
require_once dirname(__DIR__, 2) . "/classes/autoload.php";
require_once dirname(__DIR__, 3) . "/lib/xsrf.php";
require_once "/etc/apache2/encrypted-config/encrypted-config.php";
/**
 * api for the event class
 * @author Eliot Ostling
 **/
// verify the session, start if not active
if (session_status() !== PHP_SESSION_ACTIVE) {
    session_start();
}
$reply = new stdClass();
$reply->status = 200;
$reply->data = null;
try {
    $pdo = connectToEncryptedMySQL("/etc/apache2/encrypted-config/ng-abq-dev.ini");
    $method = array_key_exists("HTTP_X_HTTP_METHOD", $_SERVER) ? $_SERVER["HTTP_X_HTTP_METHOD"] : $_SERVER["REQUEST_METHOD"];
    $id = filter_input(INPUT_GET, "id", FILTER_VALIDATE_INT);
    $profileId = filter_input(INPUT_GET, "profileId", FILTER_VALIDATE_INT);
    if ($method === "GET") {
        //set XSRF cookie
        setXsrfCookie();
        if (empty($id) === false) {
            $event = Beta\Event::getEventByEventId($pdo, $id);
            if ($event !== null) {
                $reply->data = $event;
            }
        } else {
            if (empty($profileId) === false) {
                $events = Beta\Event::getEventByEventProfileId($pdo, $profileId)->toArray();
                if ($events !== null) {
Example #9
0
/**
 * controller/api for activation
 *
 * @author Denzyl Fontaine
 */
//verify the xsrf challenge
if (session_status() !== PHP_SESSION_ACTIVE) {
    session_start();
}
//prepare a empty reply
$reply = new stdClass();
$reply->status = 200;
$reply->data = null;
try {
    //Grab MySQL connection
    $pdo = connectToEncryptedMySQL("/etc/apache2/capstone-mysql/timecrunch.ini");
    //determine which http method was used
    $method = array_key_exists("HTTP_X_HTTP_METHOD", $_SERVER) ? $_SERVER["HTTP_X_HTTP_METHOD"] : $_SERVER["REQUEST_METHOD"];
    //handle REST calls, while allowing administrators to access database modifying methods
    if ($method === "GET") {
        //set Xsrf cookie
        setXsrfcookie("/");
        //get the Sign Up based on the given field
        $emailActivation = filter_input(INPUT_GET, "emailActivation", FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
        if (empty($emailActivation)) {
            throw new \RangeException("No Activation Code");
        }
        $user = User::getUserByUserActivation($pdo, $emailActivation);
        if (empty($user)) {
            throw new \InvalidArgumentException("no user for activation code");
        }
Example #10
0
 /**
  * calculates trail distance using phpgeo composer package.
  **/
 public static function calculateTrailDistance()
 {
     $pdo = connectToEncryptedMySQL("/var/www/trailquail/encrypted-mysql/trailquail.ini");
     $trails = Trail::getAllTrails($pdo);
     $testNum = 0;
     foreach ($trails as $trail) {
         $testNum++;
         $trailRelationships = TrailRelationship::getTrailRelationshipByTrailId($pdo, $trail->getTrailId());
         $track = new Polyline();
         foreach ($trailRelationships as $trailRelationship) {
             $segment = Segment::getSegmentBySegmentId($pdo, $trailRelationship->getSegmentId());
             $track->addPoint(new Coordinate($segment->getSegmentStart()->getY(), $segment->getSegmentStart()->getX()));
             $track->addPoint(new Coordinate($segment->getSegmentStop()->getY(), $segment->getSegmentStop()->getX()));
         }
         $trailDistanceM = $track->getLength(new Vincenty());
         $trailDistanceMi = $trailDistanceM / 1609.344;
         $trailDistance = $trailDistanceMi;
         $trail->setTrailDistance($trailDistance);
         $trail->update($pdo);
     }
 }
function getGames(string $league)
{
    try {
        // grab the db connection
        $pdo = connectToEncryptedMySQL("/etc/apache2/capstone-mysql/sprots.ini");
        $config = readConfig("/etc/apache2/capstone-mysql/sprots.ini");
        $apiKeys = json_decode($config["fantasyData"]);
        $opts = array('http' => array('method' => "GET", 'header' => "Content-Type: application/json\r\nOcp-Apim-Subscription-key: " . $apiKeys->{$league}, 'content' => "{body}"));
        $context = stream_context_create($opts);
        // response from api
        $seasoning = ["2015", "2016"];
        foreach ($seasoning as $season) {
            $response = file_get_contents("https://api.fantasydata.net/{$league}/v2/JSON/Games/{$season}", false, $context);
            $data = json_decode($response);
            foreach ($data as $game) {
                $badDate = str_replace("T", " ", $game->DateTime);
                if (empty($badDate) === false) {
                    $teamChavez = Team::getTeamByTeamApiId($pdo, $game->AwayTeamID);
                    $teamPaul = Team::getTeamByTeamApiId($pdo, $game->HomeTeamID);
                    if ($teamChavez !== null && $teamPaul !== null) {
                        $gameToInsert = new Game(null, $teamChavez->getTeamId(), $teamPaul->getTeamId(), $badDate);
                        $gameToInsert->insert($pdo);
                    } else {
                        echo "<p>* * * SIX OF THIRTEEN SKIPPED THIS GAME * * *</p>" . PHP_EOL;
                    }
                }
            }
        }
    } catch (Exception $exception) {
        echo "Something went wrong: " . $exception->getMessage() . PHP_EOL;
    } catch (TypeError $typeError) {
        echo "Something went wrong: " . $typeError->getMessage() . PHP_EOL;
    }
}
<?php

//put this on the top of the file
require_once "/etc/apache2/capstone-mysql/encrypted-config.php";
require_once "ramchip.php";
$pdo = connectToEncryptedMySQL("/etc/apache2/data-design/enajera2.ini");
//now you can use the PDO object normally
$ramChip = new RamChip(null, 1, "this is from PHP");
$ramChip->insert($pdo);
$ramChip->setProductId("now I added an id");
$ramChip->setProductName("now I added a name for the ram chip, many words");
$ramChip->setManufacturerName("now I added a manufacturer name for the ram chip, there is no need to worry");
$ramChip->setPrice("now I added a price for the ram chip, wow such price");
$ramChip->update($pdo);
$ramChip->delete($pdo);
<?php

require_once "/etc/apache2/capstone-mysql/encrypted-config.php";
require_once "your-class-file.php";
$pdo = connectToEncryptedMySQL("/etc/apache2/data-design/jchavez790");
///now produce nomally
$track = new Track(null, 1, "this is form PHP");
$track->insert($pdo);
$track->setTrackContent("now I changed the message");
$track->update($pdo);
$track->delete($pdo);
<?php

require_once "/etc/apache2/capstone-mysql/encrypted-config.php";
$pdo = connectToEncryptedMySQL("/etc/apache2/data-design/cpaul9.ini");
require_once "profile.php";
$profile = new Profile(null, 1, "this is from PHP");
$profile->insert($pdo);
$profile->setprofilecontent("now i changed the message");
$profile->update($pdo);
$profile->delete($pdo);
Example #15
0
 *
 * @author Louis Gill <*****@*****.**>
 */
// verify the xsrf challenge
if (session_status() !== PHP_SESSION_ACTIVE) {
    session_start();
}
// prepare an empty reply
$reply = new stdClass();
$reply->status = 200;
$reply->data = null;
$ipAddress = $_SERVER['REMOTE_ADDR'];
$browser = $_SERVER['HTTP_USER_AGENT'];
try {
    // grab the mySQL connection
    $pdo = connectToEncryptedMySQL("/var/www/trailquail/encrypted-mysql/trailquail.ini");
    //determine which HTTP method was used
    $method = array_key_exists("HTTP_X_HTTP_METHOD", $_SERVER) ? $_SERVER["HTTP_X_HTTP_METHOD"] : $_SERVER["REQUEST_METHOD"];
    // sanitize the commentId
    $commentId = filter_input(INPUT_GET, "commentId", FILTER_VALIDATE_INT);
    if (($method === "DELETE" || $method === "PUT") && (empty($commentId) === true || $commentId < 0)) {
        throw new InvalidArgumentException("comment ID cannot be empty or negative", 405);
    }
    // sanitize and trim the other fields
    // trailId, userId, browser, createDate, ipAddress, commentPhoto, commentPhotoType, commentText			// only fields are commentPhoto, commentPhotoType, & commentText?!?!?!!?!?!?
    $commentText = filter_input(INPUT_GET, "commentText", FILTER_SANITIZE_STRING);
    $userId = filter_input(INPUT_GET, "userId", FILTER_VALIDATE_INT);
    $trailId = filter_input(INPUT_GET, "trailId", FILTER_VALIDATE_INT);
    // handle all RESTful calls to listing
    //get some or all Comments
    if ($method === "GET") {
Example #16
0
<?php

require_once "/etc/apache2/capstone-mysql/encrypted-config.php";
$pdo = connectToEncryptedMySQL("/etc/apache2/data-design/dmartinez337.ini");
$tweet = new Tweet(null, 1, "this is from PHP");
$tweet->insert($pdo);
$tweet->setTweetContent("now I changed the message");
$tweet->update($pdo);
$tweet->delete($pdo);
<?php

require_once "/etc/apache2/capstone-mysql/encrypted-config.php";
require_once "product.php";
$pdo = connectToEncryptedMySQL("/etc/apache2/data-design/jfindley2.ini");
$product = new Product(null, "imagefile", 10, "Info", "Detail", "Tech", "Name");
$product->insert($pdo);
$product->setProductName("This is the new name");
$product->update($pdo);
$product->delete($pdo);
//a security file that's on the server created by Dylan
require_once "/etc/apache2/capstone-mysql/encrypted-config.php";
//composer for Swiftmailer
require_once dirname(dirname(dirname(__DIR__))) . "/vendor/autoload.php";
// prepare default error message
$reply = new stdClass();
$reply->status = 200;
$reply->message = null;
try {
    // verify the XSRF challenge
    if (session_status() !== PHP_SESSION_ACTIVE) {
        session_start();
    }
    //verifyXsrf();
    // grab the my SQL connection
    $pdo = connectToEncryptedMySQL("/etc/apache2/capstone-mysql/breadbasket.ini");
    // convert POSTed JSON to an object
    $requestContent = file_get_contents("php://input");
    $requestObject = json_decode($requestContent);
    //make sure all fields are present, in order to prevent database issues
    if (empty($requestObject->volEmail) === true) {
        throw new InvalidArgumentException("email cannot be empty", 418);
    }
    if (empty($requestObject->volFirstName) === true) {
        throw new InvalidArgumentException("first name cannot be empty", 405);
    }
    if (empty($requestObject->volLastName) === true) {
        throw new InvalidArgumentException("last name cannot be empty", 405);
    }
    if (empty($requestObject->volPhone) === true) {
        throw new InvalidArgumentException("phone cannot be empty", 405);
$reply->status = 200;
$reply->data = null;
try {
    // create the Pusher connection
    $config = readConfig("/etc/apache2/data-design/misquote.ini");
    $pusherConfig = json_decode($config["pusher"]);
    $pusher = new Pusher($pusherConfig->key, $pusherConfig->secret, $pusherConfig->id, ["encrypted" => true]);
    // determine which HTTP method was used
    $method = array_key_exists("HTTP_X_HTTP_METHOD", $_SERVER) ? $_SERVER["HTTP_X_HTTP_METHOD"] : $_SERVER["REQUEST_METHOD"];
    // sanitize the id
    $id = filter_input(INPUT_GET, "id", FILTER_VALIDATE_INT);
    if (($method === "DELETE" || $method === "PUT") && (empty($id) === true || $id < 0)) {
        throw new InvalidArgumentException("id cannot be empty or negative", 405);
    }
    // grab the mySQL connection
    $pdo = connectToEncryptedMySQL("/etc/apache2/data-design/misquote.ini");
    // handle all RESTful calls to Misquote
    // get some or all Misquotes
    if ($method === "GET") {
        // set an XSRF cookie on GET requests
        setXsrfCookie("/");
        if (empty($id) === false) {
            $reply->data = Misquote::getMisquoteByMisquoteId($pdo, $id);
        } else {
            $reply->data = Misquote::getAllMisquotes($pdo)->toArray();
        }
        // put to an existing Misquote
    } else {
        if ($method === "PUT") {
            // convert PUTed JSON to an object
            verifyXsrf();
Example #20
0
<?php

/**
 * Created by PhpStorm.
 * User: OldManVin
 * Date: 1/22/2016
 * Time: 12:01 PM
 */
require_once "/etc/apache2/capstone-mysql/encrypted -config.php";
$pdo = connectToEncryptedMySQL("/ect/apache2/data-design/dfontaine1/ini");
require_once "/etc/apache2/capstone-mysql/encrypted-config.php";
require_once "your-class-file.php";
//now use the PDO object normally
$tweet = new Profile(null, 1, "this is from php");
$tweet->insert($pdo);
$tweet->setProfile("now i change the message");
$tweet->update($pdo);
$tweet->delete($pdo);
Example #21
0
<?php

/**
 * Profile testing for a reddit user
 *
 * @author Skyler Rexroad
 */
require_once "/etc/apache2/data-design/encrypted-config.php";
require_once "profile.php";
try {
    $pdo = connectToEncryptedMySQL("/etc/apache2/data-design/srexroad.ini");
    $profiles = Profile::getAllProfiles($pdo);
    printProfiles($profiles);
} catch (PDOException $pdoException) {
    echo $pdoException->getMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}
function printProfiles($profiles)
{
    foreach ($profiles as $profile) {
        echo $profile;
    }
}