Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds h5p server to materia stack, along with oauth changes for uploading media #1362

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.5'
version: "3.5"

services:
webserver:
Expand Down Expand Up @@ -81,9 +81,21 @@ services:
- frontend
- backend

h5p:
build:
context: ../
dockerfile: ./h5p-server/materia-h5p.Dockerfile
args:
ENVIRONMENT: dev
ports:
- "3000:3000"
networks:
- frontend
environment:
- MATERIA_WEBSERVER_NETWORK=webserver

networks:
frontend:
name: materia_frontend
backend:
name: materia_backend

4 changes: 4 additions & 0 deletions docker/run_first.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ source run_build_assets.sh
# create a dev user based on your current shell user (password will be 'kogneato') MATERIA_DEV_PASS=whatever can be used to set a custom pw
source run_create_me.sh

# run setup for the h5p server
cd ../h5p-server/
source setup.sh
ljoks marked this conversation as resolved.
Show resolved Hide resolved

echo -e "Materia will be hosted on \033[32m$DOCKER_IP\033[0m"
echo -e "\033[1mRun an oil comand:\033[0m ./run.sh php oil r widget:show_engines"
echo -e "\033[1mRun the web app:\033[0m docker-compose up"
8 changes: 6 additions & 2 deletions fuel/app/classes/controller/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
use \Materia\Widget_Asset_Manager;
use \Materia\Widget_Asset;
use \Thirdparty\Oauth;

class Controller_Media extends Controller
{
Expand Down Expand Up @@ -64,8 +65,11 @@ public function get_import()
// This currently assumes a single uploaded file at a time
public function action_upload()
{
// Validate Logged in
if (\Service_User::verify_session() !== true) throw new HttpNotFoundException;
// Either Validate Logged in
// or validate a third party server thru Oauth
if (\Service_User::verify_session() !== true)
if (Oauth::validate_post() !== true)
throw new HttpNotFoundException;

$res = new Response();
// Make sure file is not cached (as it happens for example on iOS devices)
Expand Down
39 changes: 39 additions & 0 deletions fuel/app/classes/thirdparty/oauth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
namespace Thirdparty;
// phpcs:disable FuelPHP.NamingConventions.ConciseUnderscoredVariableName

class Oauth
{
public static function validate_post()
{
try
{
// get signature, timestamp, nonce from body formData
$signature = \Input::post('oauth_signature', '');
$timestamp = (int) \Input::post('oauth_timestamp', 0);
$nonce = \Input::post('oauth_nonce', false);

// check to make sure all are present
if (empty($signature)) throw new \Exception('Authorization signature is missing.');
if (empty($nonce)) throw new \Exception('Authorization fingerprint is missing.');
if (\Input::post('oauth_consumer_key') !== $_ENV['OAUTH_KEY']) throw new \Exception('Authorization signature failure.');

// make sure request was made in the last hour
if ($timestamp < (time() - 3600)) throw new \Exception('Authorization signature is too old.');

// hash key and secret to make sure token matches
$new_sig = hash_hmac('sha256', $_ENV['OAUTH_KEY'], $_ENV['OAUTH_SECRET'].$timestamp.$nonce, false);

if ($new_sig !== $signature) throw new \Exception('Authorization signature failure.');
return true;
}
catch (\Exception $e)
{
logger('DEBUG', 'ERROR: INVALID OAUTH EXCEPTION');
logger('DEBUG', $e);
// \Materia\Log::profile(['invalid-oauth-received', $e->getMessage(), \Uri::current(), print_r(\Input::post(), 1)], 'lti-error-dump');
}

return false;
}
}
4 changes: 2 additions & 2 deletions fuel/app/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@
],
[
'id' => 2,
'package' => 'https://github.com/ucfopen/hangman-materia-widget/releases/latest/download/hangman.wigt',
'checksum' => 'https://github.com/ucfopen/hangman-materia-widget/releases/latest/download/hangman-build-info.yml',
'package' => 'https://github.com/ucfopen/guess-the-phrase-materia-widget/releases/latest/download/guess-the-phrase.wigt',
'checksum' => 'https://github.com/ucfopen/guess-the-phrase-materia-widget/releases/latest/download/guess-the-phrase-build-info.yml',
],
[
'id' => 3,
Expand Down
2 changes: 2 additions & 0 deletions h5p-server/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
6 changes: 6 additions & 0 deletions h5p-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
h5p/libraries/*
h5p/temporary_storage/*
h5p/core/
h5p/editor/
.env
27 changes: 27 additions & 0 deletions h5p-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This dockerfile is meant to spin up the h5p-server alone

FROM node:12

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN yarn install

# Bundle app source
COPY . .

# for local development, don't copy existing h5p info into
# fresh docker container
# RUN rm -r h5p/core h5p/editor h5p/libraries h5p/temporary-storage
# RUN mkdir h5p/core h5p/editor h5p/libraries h5p/temporary-storage

RUN ./setup.sh

EXPOSE 3000

CMD ["yarn", "start"]
Loading