You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
3.7 KiB
Plaintext
73 lines
3.7 KiB
Plaintext
<?php
|
|
|
|
function fulcrm_webhook_permission() {
|
|
return array( 'administer fulcrm webhooks' => array( 'title' => t('Administer fulcrm webhooks'),
|
|
'description' => t('Perform main installation/administration tasks for fulcrm webhooks.'),
|
|
),
|
|
);
|
|
}
|
|
|
|
function fulcrm_webhook_menu() {
|
|
/*
|
|
$items[ 'admin/config/services/fulcrm' ] = array( 'page callback' => 'system_admin_menu_block_page',
|
|
'file' => 'system.admin.inc',
|
|
'file path' => drupal_get_path('module', 'system'),
|
|
'title' => 'fulcrm',
|
|
'description' => 'Configuration integration with fulcrm.org.',
|
|
'position' => 'right',
|
|
'access callback' => 'user_access',
|
|
'access arguments' => array('access administration pages'),
|
|
);
|
|
*/
|
|
$items[ 'admin/config/services/fulcrm/webhook' ] = array( 'page callback' => 'fulcrm_webhook_admin',
|
|
'file' => 'fulcrm_webhook.admin.inc',
|
|
'title' => 'fulcrm webhooks',
|
|
'description' => 'Configure webhooks for fulcrm.org.',
|
|
'access callback' => 'user_access',
|
|
'access arguments' => array('administer fulcrm webhooks'),
|
|
);
|
|
$items[ 'services/fulcrm/webhook/%' ] = array( 'page callback' => 'fulcrm_webhook_webhook',
|
|
'page arguments' => array(3),
|
|
'type' => MENU_CALLBACK,
|
|
'access callback' => 'user_access',
|
|
'access arguments' => array('access content'),
|
|
);
|
|
|
|
return $items;
|
|
}
|
|
|
|
function fulcrm_webhook_webhook( $uuid ) {
|
|
if ( $uuid === variable_get( 'fulcrm_webhook_url' ) ) {
|
|
$headers = getallheaders();
|
|
$payload = null;
|
|
$payload_error = null;
|
|
$method = $_SERVER[ 'REQUEST_METHOD' ];
|
|
|
|
if ( array_key_exists( 'Content-Type', $headers ) && ( $headers[ 'Content-Type' ] === 'application/json' ) ) {
|
|
$payload = json_decode( file_get_contents( "php://input" ) );
|
|
$payload_error = json_last_error();
|
|
$payload_error_msg = json_last_error_msg();
|
|
}
|
|
|
|
switch ( $method ) {
|
|
case 'GET':
|
|
drupal_json_output( array( "status" => "error", "info" => "GET requests do nothing; webhooks must be POST, PATCH, PUT, or DELETE" ) );
|
|
break;
|
|
case 'DELETE':
|
|
case 'POST':
|
|
case 'PATCH':
|
|
case 'PUT':
|
|
if ( $payload === null ) {
|
|
// actually do something :)
|
|
drupal_json_output( array( 'status' => 'error', 'info' => $payload_error_msg ) );
|
|
} else {
|
|
drupal_json_output( array( 'status' => 'ok', 'headers' => $headers, 'method' => $method ) );
|
|
}
|
|
break;
|
|
default:
|
|
}
|
|
} else {
|
|
drupal_access_denied();
|
|
}
|
|
}
|