first commit
This commit is contained in:
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
|
||||
class SAV_Controller extends CI_Controller {
|
||||
|
||||
var $template = array(
|
||||
'table_open' => "<table class='table-responsive table-striped table-hover table-bordered table-condensed'>",
|
||||
'thead_open' => '<thead class=\'bg-indigo\'>',
|
||||
'thead_close' => '</thead>',
|
||||
'heading_row_start' => '<tr style=\'padding:1px;\'>',
|
||||
'heading_row_end' => '</tr>',
|
||||
'heading_cell_start' => '<th>',
|
||||
'heading_cell_end' => '</th>',
|
||||
'tbody_open' => '<tbody>',
|
||||
'tbody_close' => '</tbody>',
|
||||
'row_start' => '<tr style=\'padding:0px;\'>',
|
||||
'row_end' => '</tr>',
|
||||
'cell_start' => '<td>',
|
||||
'cell_end' => '</td>',
|
||||
'row_alt_start' => '<tr>',
|
||||
'row_alt_end' => '</tr>',
|
||||
'cell_alt_start' => '<td>',
|
||||
'cell_alt_end' => '</td>',
|
||||
'table_close' => '</table>'
|
||||
);
|
||||
var $template_nohead = array(
|
||||
'table_open' => "<table class='table-responsive table-striped table-hover table-bordered table-condensed'>",
|
||||
'thead_open' => '<thead>',
|
||||
'thead_close' => '</thead>',
|
||||
'heading_row_start' => '<tr style=\'padding:3px;\'>',
|
||||
'heading_row_end' => '</tr>',
|
||||
'heading_cell_start' => '<th>',
|
||||
'heading_cell_end' => '</th>',
|
||||
'tbody_open' => '<tbody>',
|
||||
'tbody_close' => '</tbody>',
|
||||
'row_start' => '<tr style=\'padding:3px;\'>',
|
||||
'row_end' => '</tr>',
|
||||
'cell_start' => '<td>',
|
||||
'cell_end' => '</td>',
|
||||
'row_alt_start' => '<tr>',
|
||||
'row_alt_end' => '</tr>',
|
||||
'cell_alt_start' => '<td>',
|
||||
'cell_alt_end' => '</td>',
|
||||
'table_close' => '</table>'
|
||||
);
|
||||
public $data = array();
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function smart_htmlspecialchars($str) {
|
||||
if (substr($str, 0, 1) == '<')
|
||||
return $str;
|
||||
return htmlspecialchars($str);
|
||||
}
|
||||
|
||||
protected function sql_escape_func($inp) {
|
||||
if (is_array($inp)) {
|
||||
return array_map(__METHOD__, $inp);
|
||||
}
|
||||
|
||||
|
||||
if (!empty($inp) && is_string($inp)) {
|
||||
return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $inp);
|
||||
}
|
||||
|
||||
return $inp;
|
||||
}
|
||||
|
||||
protected function savvy_api($in, &$out) {
|
||||
global $savvyext;
|
||||
$ret = -1;
|
||||
$in['pid'] = 115;
|
||||
$in['backoffice'] = 1;
|
||||
error_log(json_encode($in));
|
||||
$out = $savvyext->savvyext_api($in);
|
||||
$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) {
|
||||
global $savvyext;
|
||||
$ret = -1;
|
||||
error_log(json_encode($in));
|
||||
$out = $savvyext->savvyext_api($in);
|
||||
$ret = $out["retval"];
|
||||
error_log("ret = $ret");
|
||||
error_log(json_encode($out));
|
||||
return $ret;
|
||||
}
|
||||
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');
|
||||
$encryptionIV = $savvyext->cfgReadChar('encryption.iv');
|
||||
|
||||
$encrypted_payload = bin2hex(
|
||||
openssl_encrypt(
|
||||
$payload,
|
||||
$encryptionAlg,
|
||||
$encryptionKey,
|
||||
OPENSSL_RAW_DATA,
|
||||
$encryptionIV
|
||||
));
|
||||
$postdata = "{\"encrypted_payload\": \"${encrypted_payload}\"}";
|
||||
$url = $savvyext->cfgReadChar('system.api_url').$endpoint;
|
||||
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
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)
|
||||
);
|
||||
|
||||
$body = curl_exec($ch);
|
||||
$result = json_decode($body,true);
|
||||
|
||||
if (is_array($result) && array_key_exists('payload',$result)) {
|
||||
$decrypted = openssl_decrypt(
|
||||
hex2bin(
|
||||
$result['payload']
|
||||
),
|
||||
$encryptionAlg,
|
||||
$encryptionKey,
|
||||
OPENSSL_RAW_DATA,
|
||||
$encryptionIV
|
||||
);
|
||||
} else {
|
||||
$decrypted = $body; // Attempt without encryption
|
||||
}
|
||||
$payload = json_decode($decrypted, true);
|
||||
return [$payload,$decrypted,$result,$body];
|
||||
}
|
||||
|
||||
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;
|
||||
//echo $url;
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
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',
|
||||
'Authorization: Server-Token ' . $httpAuthToken,
|
||||
"client_id: BackOffice"
|
||||
)
|
||||
);
|
||||
|
||||
$body = curl_exec($ch);
|
||||
$result = json_decode($body,true);
|
||||
|
||||
if (is_array($result) && array_key_exists('payload',$result)) {
|
||||
$decrypted = openssl_decrypt(
|
||||
hex2bin(
|
||||
$result['payload']
|
||||
),
|
||||
$encryptionAlg,
|
||||
$encryptionKey,
|
||||
OPENSSL_RAW_DATA,
|
||||
$encryptionIV
|
||||
);
|
||||
} else {
|
||||
$decrypted = $body; // Attempt without encryption
|
||||
}
|
||||
$payload = json_decode($decrypted, true);
|
||||
return [$payload,$decrypted,$result,$body];
|
||||
}
|
||||
|
||||
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) {
|
||||
$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) {
|
||||
$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) {
|
||||
$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