update API admin
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
class SAV_Controller extends CI_Controller {
|
||||
class SAV_Controller extends CI_Controller
|
||||
{
|
||||
|
||||
var $template = array(
|
||||
'table_open' => "<table class='table-responsive table-striped table-hover table-bordered table-condensed'>",
|
||||
@@ -44,17 +45,20 @@ class SAV_Controller extends CI_Controller {
|
||||
);
|
||||
public $data = array();
|
||||
|
||||
function __construct() {
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function smart_htmlspecialchars($str) {
|
||||
protected function smart_htmlspecialchars($str)
|
||||
{
|
||||
if (substr($str, 0, 1) == '<')
|
||||
return $str;
|
||||
return htmlspecialchars($str);
|
||||
}
|
||||
|
||||
protected function sql_escape_func($inp) {
|
||||
protected function sql_escape_func($inp)
|
||||
{
|
||||
if (is_array($inp)) {
|
||||
return array_map(__METHOD__, $inp);
|
||||
}
|
||||
@@ -67,21 +71,38 @@ class SAV_Controller extends CI_Controller {
|
||||
return $inp;
|
||||
}
|
||||
|
||||
protected function savvy_api($in, &$out) {
|
||||
protected function savvy_api($in, &$out)
|
||||
{
|
||||
global $savvyext;
|
||||
$ret = -1;
|
||||
$in['pid'] = 115;
|
||||
$in['backoffice'] = 1;
|
||||
error_log(json_encode($in));
|
||||
error_log(json_encode($in));
|
||||
$out = $savvyext->savvyext_api($in);
|
||||
$ret = $out["retval"];
|
||||
error_log("ret = $ret");
|
||||
error_log(json_encode($out));
|
||||
error_log("ret = $ret");
|
||||
error_log(json_encode($out));
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function savvy_admin($endpoint, $in, &$out)
|
||||
{
|
||||
global $savvyext;
|
||||
$ret = -1;
|
||||
$in['pid'] = 115;
|
||||
$in['backoffice'] = 1;
|
||||
error_log(json_encode($in));
|
||||
$out = $savvyext->savvyext_admin($endpoint,$in);
|
||||
//var_dump($out);exit;
|
||||
$ret = $out["retval"];
|
||||
error_log("ret = $ret");
|
||||
error_log(json_encode($out));
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// call API with no default params
|
||||
protected function savvy_api_clearly($in, &$out) {
|
||||
protected function savvy_api_clearly($in, &$out)
|
||||
{
|
||||
global $savvyext;
|
||||
$ret = -1;
|
||||
error_log(json_encode($in));
|
||||
@@ -91,9 +112,10 @@ class SAV_Controller extends CI_Controller {
|
||||
error_log(json_encode($out));
|
||||
return $ret;
|
||||
}
|
||||
protected function main_api_post($endpoint,$payload) {
|
||||
protected function main_api_post($endpoint, $payload)
|
||||
{
|
||||
global $savvyext;
|
||||
|
||||
|
||||
$httpAuthToken = $savvyext->cfgReadChar('system.oauth2_token');
|
||||
$encryptionAlg = $savvyext->cfgReadChar('encryption.algorithm');
|
||||
$encryptionKey = $savvyext->cfgReadChar('encryption.key');
|
||||
@@ -106,9 +128,10 @@ class SAV_Controller extends CI_Controller {
|
||||
$encryptionKey,
|
||||
OPENSSL_RAW_DATA,
|
||||
$encryptionIV
|
||||
));
|
||||
)
|
||||
);
|
||||
$postdata = "{\"encrypted_payload\": \"${encrypted_payload}\"}";
|
||||
$url = $savvyext->cfgReadChar('system.api_url').$endpoint;
|
||||
$url = $savvyext->cfgReadChar('system.api_url') . $endpoint;
|
||||
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
@@ -117,16 +140,20 @@ class SAV_Controller extends CI_Controller {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_VERBOSE, false);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json',
|
||||
'Content-Length: ' . strlen($postdata),
|
||||
'Authorization: Server-Token ' . $httpAuthToken)
|
||||
curl_setopt(
|
||||
$ch,
|
||||
CURLOPT_HTTPHEADER,
|
||||
array(
|
||||
'Content-Type: application/json',
|
||||
'Content-Length: ' . strlen($postdata),
|
||||
'Authorization: Server-Token ' . $httpAuthToken
|
||||
)
|
||||
);
|
||||
|
||||
$body = curl_exec($ch);
|
||||
$result = json_decode($body,true);
|
||||
$result = json_decode($body, true);
|
||||
|
||||
if (is_array($result) && array_key_exists('payload',$result)) {
|
||||
if (is_array($result) && array_key_exists('payload', $result)) {
|
||||
$decrypted = openssl_decrypt(
|
||||
hex2bin(
|
||||
$result['payload']
|
||||
@@ -140,18 +167,19 @@ class SAV_Controller extends CI_Controller {
|
||||
$decrypted = $body; // Attempt without encryption
|
||||
}
|
||||
$payload = json_decode($decrypted, true);
|
||||
return [$payload,$decrypted,$result,$body];
|
||||
return [$payload, $decrypted, $result, $body];
|
||||
}
|
||||
|
||||
protected function main_api_get($endpoint,$payload) {
|
||||
protected function main_api_get($endpoint, $payload)
|
||||
{
|
||||
global $savvyext;
|
||||
|
||||
|
||||
$httpAuthToken = $savvyext->cfgReadChar('system.oauth2_token');
|
||||
$encryptionAlg = $savvyext->cfgReadChar('encryption.algorithm');
|
||||
$encryptionKey = $savvyext->cfgReadChar('encryption.key');
|
||||
$encryptionIV = $savvyext->cfgReadChar('encryption.iv');
|
||||
|
||||
$url = $savvyext->cfgReadChar('system.api_url').$endpoint.$payload;
|
||||
$url = $savvyext->cfgReadChar('system.api_url') . $endpoint . $payload;
|
||||
//echo $url;
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
@@ -159,7 +187,10 @@ class SAV_Controller extends CI_Controller {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_VERBOSE, false);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
curl_setopt(
|
||||
$ch,
|
||||
CURLOPT_HTTPHEADER,
|
||||
array(
|
||||
'Content-Type: application/json',
|
||||
'Authorization: Server-Token ' . $httpAuthToken,
|
||||
"client_id: BackOffice"
|
||||
@@ -167,9 +198,9 @@ class SAV_Controller extends CI_Controller {
|
||||
);
|
||||
|
||||
$body = curl_exec($ch);
|
||||
$result = json_decode($body,true);
|
||||
$result = json_decode($body, true);
|
||||
|
||||
if (is_array($result) && array_key_exists('payload',$result)) {
|
||||
if (is_array($result) && array_key_exists('payload', $result)) {
|
||||
$decrypted = openssl_decrypt(
|
||||
hex2bin(
|
||||
$result['payload']
|
||||
@@ -183,27 +214,31 @@ class SAV_Controller extends CI_Controller {
|
||||
$decrypted = $body; // Attempt without encryption
|
||||
}
|
||||
$payload = json_decode($decrypted, true);
|
||||
return [$payload,$decrypted,$result,$body];
|
||||
return [$payload, $decrypted, $result, $body];
|
||||
}
|
||||
|
||||
function formatedMesage($msgType, $theMessage) {
|
||||
function formatedMesage($msgType, $theMessage)
|
||||
{
|
||||
return "<div class=\"text-left\"><div class=\"alert alert-danger no-border\">" . $theMessage . "</div></div>";
|
||||
}
|
||||
|
||||
protected function renderMemberPage($page_name, $data) {
|
||||
protected function renderMemberPage($page_name, $data)
|
||||
{
|
||||
$this->load->view('admin/view_admin_header', $data);
|
||||
$this->load->view('member/' . $page_name, $data);
|
||||
$this->load->view('admin/view_admin_footer', $data);
|
||||
}
|
||||
|
||||
|
||||
protected function renderAdminPage($page_name, $data) {
|
||||
protected function renderAdminPage($page_name, $data)
|
||||
{
|
||||
$this->load->view('admin/view_admin_header', $data);
|
||||
$this->load->view('admin/' . $page_name, $data);
|
||||
$this->load->view('admin/view_admin_footer', $data);
|
||||
}
|
||||
|
||||
protected function renderUploadPage($page_name, $data) {
|
||||
|
||||
protected function renderUploadPage($page_name, $data)
|
||||
{
|
||||
$this->load->view('admin/view_admin_header', $data);
|
||||
$this->load->view('upload/' . $page_name, $data);
|
||||
$this->load->view('admin/view_admin_footer', $data);
|
||||
|
||||
Reference in New Issue
Block a user