/
plugin
/
plugin-techloyce
/
echosign
/
Upload File
HOME
<?php error_reporting(E_ALL); session_start(); /*$log = ""; foreach ($_REQUEST as $k => $v) { $log .= $k . " => " . $v . PHP_EOL; } $log .= "-------------------------" . PHP_EOL; foreach ($_SESSION as $k => $v) { $log .= $k . " => " . $v . PHP_EOL; } $log .= "-------------------------" . PHP_EOL; file_put_contents('./adobe.log', $log, FILE_APPEND);*/ $insert_id = ''; /*$servername = "s214.panelboxmanager.com"; $username = "example_pt-user"; $password = "Dt#*W;;o]8aY"; */ $servername = "127.0.0.1"; $username = "root"; $password = "Tech786@#$"; //$password = "Z(BGc4RA?XSp"; //$dbname = "example_plugin-techloyce"; $dbname = "echosign"; $minuteslimit = 1; $conn = new mysqli($servername, $username, $password, $dbname); if (isset($_SESSION['insert_id']) && !empty($_SESSION['insert_id'])) $insert_id = $_SESSION['insert_id']; if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } if (isset($_REQUEST['error'])) { if ($insert_id != '') { $sq_get = "SELECT * FROM echosign WHERE id=$insert_id"; $result = $conn->query($sq_get); if ($result->num_rows > 0) { $row = $result->fetch_assoc(); $customer_uri = $row['redirect_url']; $action = $row['action']; } if ($action != '') { $act = '&action=' . $action . '&'; } else { $act = '?'; } $customer_url = $customer_uri . $act . 'error=' . $_REQUEST['error'] . '&error_description=' . $_REQUEST['error_description']; header('Location: ' . $customer_url . ''); } else { echo 'Error: ' . $_REQUEST['error'] . '</br>'; echo 'Description: ' . $_REQUEST['error_description']; exit(); } } define(CLIENTSECRET, 'uizOyy5I-ozY9KS0tqQd-EDiXbsdabF4'); define(CLIENTID, 'CBJCHBCAABAAPhGShJEcur7kt9NWbFF3OUoJdHeETBzb'); //define(CLIENTID, 'CBJCHBCAABAAbZCtsaZGv3ksCJGq-60yYriBpjOUAnet'); if (!isset($_REQUEST['redirect_uri'])) { $plugin_redirect_uri = 'https://www.plugin-techloyce.com/echosign/index.php'; // $plugin_redirect_uri = 'https://echosign.plugin-techloyce.com/index.php'; } else { $plugin_redirect_uri = $_REQUEST['redirect_uri']; } if (isset($_REQUEST['customer_uri'])) { if (isset($_REQUEST['customer_uri_action'])) { $action = $_REQUEST['customer_uri_action']; } else { $action = ''; } if (isset($insert_id) && $insert_id != '') { $sq_check = "SELECT * FROM echosign WHERE id=$insert_id"; $result = $conn->query($sq_check); if ($result->num_rows > 0) { $row = $result->fetch_assoc(); $customer_uri = $row['redirect_url']; $action = $row['action']; $scope = 'user_read:account+user_write:account+user_login:account+agreement_read:account+agreement_write:account+agreement_send:account+widget_read:account+widget_write:account+library_read:account+library_write:account+workflow_read:account+workflow_write:account'; $oauth_url = 'https://secure.na1.echosign.com/public/oauth?redirect_uri=' . $plugin_redirect_uri . '&response_type=code&client_id=' . CLIENTID . '&scope=' . $scope . '&customer_uri=' . $customer_uri . 'https://sugar12.dev-techloyce.com/#adobe_sign'; // echo "first=".$oauth_url;die; header('Location: ' . $oauth_url . ''); exit(); } else { die("Service is busy temporarily please go back and try again after sometime. "); } } else { $configurator = ''; if (isset($_REQUEST['configurator'])) $configurator = $_REQUEST['configurator']; $_SESSION['customer_uri'] = $_REQUEST['customer_uri'] . '&configurator=' . $configurator; $sql_insert = "INSERT INTO echosign(redirect_url,action)Values('" . $_REQUEST['customer_uri'] . '&configurator=' . $configurator . "','" . $action . "')"; $conn->query($sql_insert); $_SESSION['insert_id'] = mysqli_insert_id($conn); $scope = 'user_login:account+agreement_write:account+agreement_send:account+widget_write:account+library_write:account+library_read:account+agreement_read:account'; $oauth_url = 'https://secure.na1.echosign.com/public/oauth?redirect_uri=' . $plugin_redirect_uri . '&response_type=code&client_id=' . CLIENTID . '&scope=' . $scope . '&customer_uri=' . $_REQUEST['customer_uri'] . ''; //echo "second=".$oauth_url;die; header('Location: ' . $oauth_url . ''); exit(); } }else { echo 'Customer URL Not found! Please Try again.<br>'; } if (isset($_REQUEST['code']) && isset($insert_id) && $insert_id != '') { $action = ''; $sq_get = "SELECT * FROM echosign WHERE id=$insert_id"; $result = $conn->query($sq_get); if ($result->num_rows > 0) { $row = $result->fetch_assoc(); $customer_uri = $row['redirect_url']; $action = $row['action']; } $api_access_point = $_REQUEST['api_access_point']; $code = $_REQUEST['code']; $api_access_point = $api_access_point . 'oauth/token?'; $postdata = "code=" . $code . "&grant_type=authorization_code&client_secret=" . CLIENTSECRET . "&redirect_uri=" . $plugin_redirect_uri . "&client_id=" . CLIENTID; //echo "first=".$api_access_point; $access_token_result = api_request($api_access_point, $postdata); if ($access_token_result['status_code'] == 200) { if ($action != '') { $act = '&action=' . $action . '&'; } else { $act = '?'; } $token_result = json_decode($access_token_result['result'], true); $token_result = http_build_query($token_result); $customer_url = $customer_uri . $act . 'api_access_point=' . $api_access_point . '&code=' . $code . '&status_code=' . $access_token_result['status_code'] . '&' . $token_result . '&client_id=' . CLIENTID . '&clientSecret=' . CLIENTSECRET . ''; //echo '<pre>';print_r($customer_url);die('test'); //echo "first=".$customer_url; $customer_url = str_replace('index.phpindex.php', 'index.php', $customer_url); //echo "second=".$customer_url;die; $sq_del = "Delete FROM echosign WHERE id=$insert_id"; unset($_SESSION['insert_id']); $conn->query($sq_del); header('Location: ' . $customer_url . ''); die(); } } else { echo 'Code Not found! Please Try again.<br>'; } function api_request($api_access_point, $postdata = null, $header = null, $fileSize = null) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $api_access_point); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); curl_setopt($ch, CURLOPT_TIMEOUT, 300); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if (!empty($header)) { curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); } if (!empty($postdata)) { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); } if (!empty($fileSize)) { curl_setopt($ch, CURLOPT_INFILESIZE, $fileSize); } curl_setopt($ch, CURLOPT_VERBOSE, true); $result = curl_exec($ch); if (curl_error($ch)) { echo "<pre>"; print_r(curl_error($ch)); exit(); } $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $res = array('status_code' => $status_code, 'result' => $result); curl_close($ch); return $res; }