Skip to content

Instantly share code, notes, and snippets.

@swarnat
Last active June 16, 2022 16:00
Show Gist options
  • Save swarnat/a38daa31cfb5130af171e8ac92c0bd22 to your computer and use it in GitHub Desktop.
Save swarnat/a38daa31cfb5130af171e8ac92c0bd22 to your computer and use it in GitHub Desktop.
Gateway File for VtigerCRM Workflow Designer HTTP Handler
<?php
/**
* Workflow Designer Gateway Script
* Version: 1.00
* Author: Redoo Networks GmbH
*
**/
$url = '<shorturl-workflowdesigner>&workflow_id=1';
/**
// You are able to integrate a layer, which prevent public users from calling every shared workflow ID
if(!empty($_REQUEST['p'])) {
@unset($_REQUEST['workflow_id']);
switch($_REQUEST['p']) {
case 'dl':
$url = '<shorturl-workflowdesigner>&workflow_id=1';
break;
default:
$url = '<shorturl-workflowdesigner>&workflow_id=2';
break;
}
}
*/
$params = $_REQUEST;
$removeFiles = array();
//open connection
$ch = curl_init();
/**
Adjust CURL Options here
**/
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, true);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$header = substr($result, 0, $info['header_size']);
$body = substr($result, $info['header_size']);
if(strpos($body, 'ACCESS_DENIED') !== false) {
echo '<p style="text-align:center;font-size:16px;font-weight:bold;">Please configure HTTP Handler to permit IP '.trim(str_replace('ACCESS_DENIED for', '', $body)).'</p>';
exit();
}
$reDispo = '/^Content-Disposition: .*?filename=(?<f>[^\s]+|\x22[^\x22]+\x22)\x3B?.*$/m';
if (preg_match($reDispo, $header, $mDispo))
{
$filename = trim($mDispo['f'],' ";');
} else {
//var_dump($body);
$body = json_decode($body, true);
if(!empty($body['redirect'])) {
header('Location:'.$body['redirect']);
exit();
}
if(!empty($_REQUEST['redirect'])) {
header('Location:'.$body['redirect']);
exit();
}
exit();
}
header('Content-Type:application/octet-stream');
header('Content-Length:'.strlen($body));
header('Content-Disposition: attachment; filename="'.$filename.'"');
echo $body;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment