Skip to content

Commit

Permalink
S3 Downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaiahJTurner committed Jun 8, 2014
1 parent a2ac3ea commit f471084
Show file tree
Hide file tree
Showing 1,956 changed files with 245,052 additions and 12 deletions.
13 changes: 13 additions & 0 deletions api/download.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
require_once("../functions.php");
$whack = new Whack();
$downloadLink = $whack->download($_POST['id']);
echo($downloadLink);
if (!$downloadLink) {
header("Location: /login");
die("You need to log in to download this file.");
}

header("Location: $downloadLink");
die("<a href='$downloadLink'>$downloadLink</a>");
print_r($_POST);
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"aws/aws-sdk-php": "2.*"
}
}
245 changes: 245 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added composer.phar
Binary file not shown.
32 changes: 23 additions & 9 deletions functions.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<?php
define("S3_USERNAME", "TheHWHack");
define("S3_ACCESS_KEY_ID", "AKIAJNBICZKD35BRHN5A");
define("S3_SECRET_ACCESS_KEY", "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");
ini_set('display_errors', 'On');


require 'vendor/autoload.php';

use Aws\S3\S3Client;


$_SERVER['AWS_ACCESS_KEY_ID'] = "AKIAJNBICZKD35BRHN5A";
$_SERVER['AWS_SECRET_KEY'] = "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";

define("DB_USERNAME", "root");
define("DB_PASSWORD", "F>L2}M9*8%7]B6F");
Expand Down Expand Up @@ -52,14 +59,20 @@ function share($title, $description, $file) {
}

function vote($isUpvote = 0) {

return true;
}

function download($item) {

$mysqli = mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_NAME) or die("Error " . mysqli_error($link));
$item_safe = mysqli_real_escape_string($mysqli,$item);
$query = "SELECT `hash`,`extension` FROM `submissions` WHERE `id` = '$item_safe'";
$result = mysqli_query($mysqli, $query);
$row = mysqli_fetch_assoc($result);
$s3 = S3Client::factory();
return $s3->getObjectUrl("TheHWHack", $row['hash'].".".$row['extension'], '5 minutes') . PHP_EOL . PHP_EOL;
}
// Returns an array of information pertaining to a homework assignment

// Returns an array of information pertaining to a homework assignment
function homework($id) {
$mysqli = mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_NAME) or die("Error " . mysqli_error($link));
$id_safe = mysqli_real_escape_string($mysqli,$id);
Expand Down Expand Up @@ -88,8 +101,9 @@ function getProfileID() {
$sid = mysqli_real_escape_string($mysqli,$_COOKIE['sid']);
$query = "SELECT `id` FROM `sessions` WHERE `sid` = '$sid'";
$result = mysqli_query($mysqli, $query);
$row = mysqli_fetch_array($result);
return $row[0]["sid"];
if (!$result) return false;
$row = mysqli_fetch_assoc($result);
return $row['id'];
}

function availableCreditsCount() {
Expand Down
4 changes: 2 additions & 2 deletions hw/hw.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
1<?php
if (substr_count($_SERVER['REQUEST_URI'], "/") != 2) die("Homework not found");
$hwID = end(explode('/', $_SERVER['REQUEST_URI']));
require_once("../functions.php");
Expand Down Expand Up @@ -95,7 +95,7 @@
</div>

<div class="row col-lg-12 text-right">
<form method="post" action="/api/download">
<form method="post" action="/api/download" target="_blank">
<input type="hidden" name="id" value="<?php echo($hw['id']); ?>">
<input type="submit" class="btn btn-success" style="width:140px; margin-bottom: 10px;" value="Download">
</form>
Expand Down
2 changes: 1 addition & 1 deletion includes/header.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
require_once(__DIR__."/../functions.php");
$whack = new Whack();
if($searchPage) { ?>
if(isset($searchPage) && $searchPage = true) { ?>
<header>
<div class="container" style="margin-top:0px;">
<div class="row" style="width:100%;">
Expand Down
7 changes: 7 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer' . '/autoload_real.php';

return ComposerAutoloaderIniteb49ef51662df50d308262c00ce7193e::getLoader();
19 changes: 19 additions & 0 deletions vendor/aws/aws-sdk-php/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*.phar
*.zip
build/artifacts
phpunit.xml
phpunit.functional.xml
test_services.json
Config
./Makefile
.idea
atlassian-ide-plugin.xml
.DS_Store
.swp
.build
composer.lock
vendor
docs/_build
docs/_themes/flask/flask_theme_support.pyc
docs/_ext/aws/__init__.pyc
src/package.xml
20 changes: 20 additions & 0 deletions vendor/aws/aws-sdk-php/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6

before_script:
- sh -c 'if [ $(php -r "echo PHP_MINOR_VERSION;") -le 4 ]; then echo "extension = apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;'
- cp test_services.json.dist test_services.json
- composer self-update
- composer install --no-interaction --prefer-source --dev

script: vendor/bin/phpunit

matrix:
allow_failures:
- php: 5.6
fast_finish: true
Loading

0 comments on commit f471084

Please sign in to comment.