update API admin
This commit is contained in:
+2
-1
@@ -35,4 +35,5 @@ vendor
|
|||||||
|
|
||||||
*.log
|
*.log
|
||||||
*.bak
|
*.bak
|
||||||
|
logs
|
||||||
|
.gitignore
|
||||||
@@ -953,7 +953,7 @@ class Member extends Admin_Controller {
|
|||||||
list( $payload, $decrypted, $result, $body ) = $this->main_api_post( '/trips/api/report', $payload );
|
list( $payload, $decrypted, $result, $body ) = $this->main_api_post( '/trips/api/report', $payload );
|
||||||
|
|
||||||
if ( is_array( $payload ) ) {
|
if ( is_array( $payload ) ) {
|
||||||
$key = sprintf( 'speding_category%s', $_days != 60 ? ( $_days > 0 ) ? $_days : '_daysrange' : '' );
|
$key = sprintf( 'speding_category%s', $_days != 60 ? (( $_days > 0 ) ? $_days : '_daysrange') : '' );
|
||||||
$data[$key] = $payload;
|
$data[$key] = $payload;
|
||||||
}
|
}
|
||||||
if ( $echo ) {
|
if ( $echo ) {
|
||||||
|
|||||||
@@ -27,10 +27,11 @@ class Welcome extends Bko_Controller {
|
|||||||
$in['password'] = $password;
|
$in['password'] = $password;
|
||||||
$in['action'] = SAVVY_BKO_LOGIN;
|
$in['action'] = SAVVY_BKO_LOGIN;
|
||||||
$out = array();
|
$out = array();
|
||||||
$ret = $this->savvy_api($in, $out);
|
$ret = $this->savvy_admin('/login', $in, $out);
|
||||||
|
|
||||||
//var_dump($ret);
|
//var_dump($ret);
|
||||||
//var_dump($out);
|
//var_dump($out);
|
||||||
|
|
||||||
if ($ret == PHP_API_OK) {
|
if ($ret == PHP_API_OK) {
|
||||||
$this->buildUserSession($ret, $out);
|
$this->buildUserSession($ret, $out);
|
||||||
redirect('dash');
|
redirect('dash');
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class SAV_Controller extends CI_Controller {
|
class SAV_Controller extends CI_Controller
|
||||||
|
{
|
||||||
|
|
||||||
var $template = array(
|
var $template = array(
|
||||||
'table_open' => "<table class='table-responsive table-striped table-hover table-bordered table-condensed'>",
|
'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();
|
public $data = array();
|
||||||
|
|
||||||
function __construct() {
|
function __construct()
|
||||||
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function smart_htmlspecialchars($str) {
|
protected function smart_htmlspecialchars($str)
|
||||||
|
{
|
||||||
if (substr($str, 0, 1) == '<')
|
if (substr($str, 0, 1) == '<')
|
||||||
return $str;
|
return $str;
|
||||||
return htmlspecialchars($str);
|
return htmlspecialchars($str);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function sql_escape_func($inp) {
|
protected function sql_escape_func($inp)
|
||||||
|
{
|
||||||
if (is_array($inp)) {
|
if (is_array($inp)) {
|
||||||
return array_map(__METHOD__, $inp);
|
return array_map(__METHOD__, $inp);
|
||||||
}
|
}
|
||||||
@@ -67,7 +71,8 @@ class SAV_Controller extends CI_Controller {
|
|||||||
return $inp;
|
return $inp;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function savvy_api($in, &$out) {
|
protected function savvy_api($in, &$out)
|
||||||
|
{
|
||||||
global $savvyext;
|
global $savvyext;
|
||||||
$ret = -1;
|
$ret = -1;
|
||||||
$in['pid'] = 115;
|
$in['pid'] = 115;
|
||||||
@@ -80,8 +85,24 @@ class SAV_Controller extends CI_Controller {
|
|||||||
return $ret;
|
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
|
// call API with no default params
|
||||||
protected function savvy_api_clearly($in, &$out) {
|
protected function savvy_api_clearly($in, &$out)
|
||||||
|
{
|
||||||
global $savvyext;
|
global $savvyext;
|
||||||
$ret = -1;
|
$ret = -1;
|
||||||
error_log(json_encode($in));
|
error_log(json_encode($in));
|
||||||
@@ -91,7 +112,8 @@ class SAV_Controller extends CI_Controller {
|
|||||||
error_log(json_encode($out));
|
error_log(json_encode($out));
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
protected function main_api_post($endpoint,$payload) {
|
protected function main_api_post($endpoint, $payload)
|
||||||
|
{
|
||||||
global $savvyext;
|
global $savvyext;
|
||||||
|
|
||||||
$httpAuthToken = $savvyext->cfgReadChar('system.oauth2_token');
|
$httpAuthToken = $savvyext->cfgReadChar('system.oauth2_token');
|
||||||
@@ -106,7 +128,8 @@ class SAV_Controller extends CI_Controller {
|
|||||||
$encryptionKey,
|
$encryptionKey,
|
||||||
OPENSSL_RAW_DATA,
|
OPENSSL_RAW_DATA,
|
||||||
$encryptionIV
|
$encryptionIV
|
||||||
));
|
)
|
||||||
|
);
|
||||||
$postdata = "{\"encrypted_payload\": \"${encrypted_payload}\"}";
|
$postdata = "{\"encrypted_payload\": \"${encrypted_payload}\"}";
|
||||||
$url = $savvyext->cfgReadChar('system.api_url') . $endpoint;
|
$url = $savvyext->cfgReadChar('system.api_url') . $endpoint;
|
||||||
|
|
||||||
@@ -117,10 +140,14 @@ class SAV_Controller extends CI_Controller {
|
|||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
curl_setopt($ch, CURLOPT_VERBOSE, false);
|
curl_setopt($ch, CURLOPT_VERBOSE, false);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
curl_setopt(
|
||||||
|
$ch,
|
||||||
|
CURLOPT_HTTPHEADER,
|
||||||
|
array(
|
||||||
'Content-Type: application/json',
|
'Content-Type: application/json',
|
||||||
'Content-Length: ' . strlen($postdata),
|
'Content-Length: ' . strlen($postdata),
|
||||||
'Authorization: Server-Token ' . $httpAuthToken)
|
'Authorization: Server-Token ' . $httpAuthToken
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$body = curl_exec($ch);
|
$body = curl_exec($ch);
|
||||||
@@ -143,7 +170,8 @@ class SAV_Controller extends CI_Controller {
|
|||||||
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;
|
global $savvyext;
|
||||||
|
|
||||||
$httpAuthToken = $savvyext->cfgReadChar('system.oauth2_token');
|
$httpAuthToken = $savvyext->cfgReadChar('system.oauth2_token');
|
||||||
@@ -159,7 +187,10 @@ class SAV_Controller extends CI_Controller {
|
|||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
curl_setopt($ch, CURLOPT_VERBOSE, false);
|
curl_setopt($ch, CURLOPT_VERBOSE, false);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
curl_setopt(
|
||||||
|
$ch,
|
||||||
|
CURLOPT_HTTPHEADER,
|
||||||
|
array(
|
||||||
'Content-Type: application/json',
|
'Content-Type: application/json',
|
||||||
'Authorization: Server-Token ' . $httpAuthToken,
|
'Authorization: Server-Token ' . $httpAuthToken,
|
||||||
"client_id: BackOffice"
|
"client_id: BackOffice"
|
||||||
@@ -186,24 +217,28 @@ class SAV_Controller extends CI_Controller {
|
|||||||
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>";
|
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('admin/view_admin_header', $data);
|
||||||
$this->load->view('member/' . $page_name, $data);
|
$this->load->view('member/' . $page_name, $data);
|
||||||
$this->load->view('admin/view_admin_footer', $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/view_admin_header', $data);
|
||||||
$this->load->view('admin/' . $page_name, $data);
|
$this->load->view('admin/' . $page_name, $data);
|
||||||
$this->load->view('admin/view_admin_footer', $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('admin/view_admin_header', $data);
|
||||||
$this->load->view('upload/' . $page_name, $data);
|
$this->load->view('upload/' . $page_name, $data);
|
||||||
$this->load->view('admin/view_admin_footer', $data);
|
$this->load->view('admin/view_admin_footer', $data);
|
||||||
|
|||||||
+82
-13
@@ -11,7 +11,12 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class savvyext_api_savvy{
|
class savvyext_api_savvy
|
||||||
|
{
|
||||||
|
var $system = [
|
||||||
|
"storage_url" => "https://resources.sworks.float.sg/"
|
||||||
|
];
|
||||||
|
|
||||||
var $database =
|
var $database =
|
||||||
[
|
[
|
||||||
"host" => "10.10.33.21",
|
"host" => "10.10.33.21",
|
||||||
@@ -23,7 +28,7 @@ class savvyext_api_savvy{
|
|||||||
|
|
||||||
var $gpsdatabase =
|
var $gpsdatabase =
|
||||||
[
|
[
|
||||||
"host" => "172.31.12.248",
|
"host" => "10.10.33.21",
|
||||||
"name" => "savvy_gps",
|
"name" => "savvy_gps",
|
||||||
"user" => "savvy",
|
"user" => "savvy",
|
||||||
"pass" => "savvy001!",
|
"pass" => "savvy001!",
|
||||||
@@ -55,7 +60,22 @@ class savvyext_api_savvy{
|
|||||||
"kms_key_id" => "oauth2_tokens"
|
"kms_key_id" => "oauth2_tokens"
|
||||||
];
|
];
|
||||||
|
|
||||||
public function cfgReadChar($varname){
|
var $savvyext =
|
||||||
|
[
|
||||||
|
"url" => "localhost:8000/api/v1/admin/login",
|
||||||
|
"key" => "ZmxvYXQ6RmwwYXQh",
|
||||||
|
"token" => "01bef20e2ab1ac21cd6469dd9fbf533b",
|
||||||
|
];
|
||||||
|
|
||||||
|
var $savvyext_admin =
|
||||||
|
[
|
||||||
|
"url" => "localhost:8000/api/v1/admin",
|
||||||
|
"key" => "ZmxvYXQ6RmwwYXQh",
|
||||||
|
"token" => "01bef20e2ab1ac21cd6469dd9fbf533b",
|
||||||
|
];
|
||||||
|
|
||||||
|
public function cfgReadChar($varname)
|
||||||
|
{
|
||||||
$pieces = explode(".", $varname);
|
$pieces = explode(".", $varname);
|
||||||
if ($pieces[0] == 'database') {
|
if ($pieces[0] == 'database') {
|
||||||
return $this->database[$pieces[1]];
|
return $this->database[$pieces[1]];
|
||||||
@@ -68,19 +88,69 @@ class savvyext_api_savvy{
|
|||||||
return $this->database_replica[$pieces[1]];
|
return $this->database_replica[$pieces[1]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_array($this->{$pieces[0]})) {
|
||||||
if ( is_array($this->$pieces[0])){ return $this->$pieces[0][$pieces[1]];
|
return $this->{$pieces[0]}[$pieces[1]];
|
||||||
}else {return [];}
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cfgReadLong($varname){
|
public function cfgReadLong($varname)
|
||||||
|
{
|
||||||
return $this->cfgReadChar($varname);
|
return $this->cfgReadChar($varname);
|
||||||
}
|
}
|
||||||
public function savvyext_api($in){
|
|
||||||
return [];
|
public function savvyext_api($in)
|
||||||
|
{
|
||||||
|
//return [];
|
||||||
|
$postdata = json_encode($in);
|
||||||
|
$url = $this->cfgReadChar('savvyext.url');
|
||||||
|
$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, [
|
||||||
|
'content-type: application/json',
|
||||||
|
'content-length: ' . strlen($postdata),
|
||||||
|
'server-token: ' . $this->cfgReadChar('savvyext.token')
|
||||||
|
]);
|
||||||
|
curl_setopt($ch, CURLOPT_HEADER, false); // Do not show the response headers
|
||||||
|
curl_setopt($ch, CURLOPT_USERPWD, base64_decode($this->cfgReadChar('savvyext.key')));
|
||||||
|
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
|
||||||
|
$res = curl_exec($ch);
|
||||||
|
//echo "DEBUG: ".$res."=====\n";
|
||||||
|
curl_close($ch);
|
||||||
|
return json_decode($res, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function savvyext_admin($endpoint, $in)
|
||||||
|
{
|
||||||
|
//return [];
|
||||||
|
$postdata = json_encode($in);
|
||||||
|
$url = $this->cfgReadChar('savvyext_admin.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, [
|
||||||
|
'content-type: application/json',
|
||||||
|
'content-length: ' . strlen($postdata),
|
||||||
|
'server-token: ' . $this->cfgReadChar('savvyext.token')
|
||||||
|
]);
|
||||||
|
curl_setopt($ch, CURLOPT_HEADER, false); // Do not show the response headers
|
||||||
|
curl_setopt($ch, CURLOPT_USERPWD, base64_decode($this->cfgReadChar('savvyext.key')));
|
||||||
|
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
|
||||||
|
$res = curl_exec($ch);
|
||||||
|
//echo "DEBUG: ".$res."=====\n";
|
||||||
|
curl_close($ch);
|
||||||
|
return json_decode($res, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,4 +158,3 @@ class savvyext_api_savvy{
|
|||||||
if (!array_key_exists('savvyext', $GLOBALS)) {
|
if (!array_key_exists('savvyext', $GLOBALS)) {
|
||||||
$savvyext = new savvyext_api_savvy();
|
$savvyext = new savvyext_api_savvy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user