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

Make hosting_restapi_check_access more useful #4

Merged
merged 2 commits into from Apr 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,12 +1,5 @@
<?php

/**
* Implements hook_install().
*/
function hosting_restapi_install() {
drupal_install_schema('hosting_restapi');
}

/**
* Implements hook_schema().
*/
@@ -61,7 +61,7 @@ function hosting_restapi_hosting_tasks() {
* If ANY check is accepted, then the check returns TRUE.
* If no implementations are found, this check returns TRUE.
*
* TODO: Implement basic check with an API key variable
* hosting_saas has a basic optional API key check.
*/
function hosting_restapi_check_access($key = NULL, $secret = NULL) {
$results = module_invoke_all('hosting_restapi_check_access', $key, $secret);
@@ -41,7 +41,10 @@ function hosting_restapi_site_get() {
// FIXME: we want the user to have live updates on the status of the site,
// so either we grant some temporary access, or we grant to anons.

hosting_restapi_check_access($_GET['key'], $_GET['secret']);
$access = hosting_restapi_check_access($_GET['key'], $_GET['secret']);
if (!$access) {
throw new Exception(t('Access denied.'));
}

$url = $_GET['url'];
$invoice_id = (isset($_GET['invoice']) ? $_GET['invoice'] : NULL);
@@ -151,7 +154,11 @@ function hosting_restapi_site_get() {
* we only handle the [url] is rather the subdomain.
*/
function hosting_restapi_site_post() {
hosting_restapi_check_access($_POST['key'], $_POST['secret']);
$access = hosting_restapi_check_access($_POST['key'], $_POST['secret']);

if (!$access) {
throw new Exception(t('Access denied.'));
}

// TODO : check if URL format is OK (i.e. no spaces, etc)
$url = check_plain($_POST['url']);