Initial import
This commit is contained in:
72
one-api/application/core/MY_Base.php
Normal file
72
one-api/application/core/MY_Base.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
class MY_Base extends CI_Controller {
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database('regional', true);
|
||||
$this->response = array("status" => "ERR");
|
||||
$this->XBASE_QRY_ERROR = -1;
|
||||
$this->XBASE_QRY_NO_RESULT = 0;
|
||||
$this->XBASE_QRY_OK = 1;
|
||||
|
||||
}
|
||||
|
||||
public function clean_connection()
|
||||
{
|
||||
$dbc = $this->db_regional->conn_id;
|
||||
while( mysqli_more_results($dbc) )
|
||||
{
|
||||
if(mysqli_next_result($dbc))
|
||||
{
|
||||
$result = mysqli_use_result($dbc);
|
||||
|
||||
unset($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
public function reply()
|
||||
{
|
||||
echo json_encode($this->response);
|
||||
exit;
|
||||
}
|
||||
public function exec_query($sql, $param = false)
|
||||
{
|
||||
if ($param) {
|
||||
$qry = $this->db_regional->query($sql, $param);
|
||||
} else {
|
||||
$qry = $this->db_regional->query($sql);
|
||||
}
|
||||
if (!$qry) {
|
||||
return array(
|
||||
"status" => $this->XBASE_QRY_ERROR,
|
||||
"message" => $this->db_regional->error()["msg"] . "\n" . $this->db_regional->last_query()
|
||||
);
|
||||
}
|
||||
return array(
|
||||
"status" => $this->XBASE_QRY_OK,
|
||||
"messge" => "", "query" => $qry
|
||||
);
|
||||
}
|
||||
function get_one_row($sql, $param = false)
|
||||
{
|
||||
$res = $this->exec_query($sql, $param);
|
||||
|
||||
if ($res["status"] == $this->XBASE_QRY_ERROR) {
|
||||
return $res;
|
||||
}
|
||||
$rows = $res["query"]->result_array();
|
||||
if (count($rows) == 0) {
|
||||
return array("status" => $this->XBASE_QRY_NO_RESULT, "row" => []);
|
||||
}
|
||||
return array("status" => $this->XBASE_QRY_OK, "row" => $rows[0]);
|
||||
}
|
||||
function get_rows($sql,$param=false) {
|
||||
$res = $this->exec_query($sql,$param);
|
||||
if( $res["status"] == $this->XBASE_QRY_ERROR) {
|
||||
return $res;
|
||||
}
|
||||
$rows = $res["query"]->result_array();
|
||||
return array("status" => $this->XBASE_QRY_OK, "rows" => $rows);
|
||||
}
|
||||
}
|
||||
204
one-api/application/core/MY_Controller.php
Normal file
204
one-api/application/core/MY_Controller.php
Normal file
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
class MY_Controller extends CI_Controller {
|
||||
var $db_regional;
|
||||
var $sys_user;
|
||||
var $sys_input;
|
||||
var $isLogin;
|
||||
var $one_salt = '545';
|
||||
var $SECRET_KEY = "--one_api-secret-2019-04-01";
|
||||
|
||||
var $group_lab = "1";
|
||||
var $lang_default_code = "ID";
|
||||
|
||||
public function broadcast($prm){
|
||||
file_get_contents('http://127.0.0.1:9090/broadcast/' . $prm);
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
//for preflight
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
|
||||
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
|
||||
//for disable cached
|
||||
header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: no-cache');
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
global $_SERVER;
|
||||
if (isset($_SERVER["REQUEST_METHOD"]) && $_SERVER["REQUEST_METHOD"] == "OPTIONS") {
|
||||
exit;
|
||||
}
|
||||
$this->sys_user = array(
|
||||
"isExists" => false,
|
||||
"user" => array(
|
||||
"userName" => "",
|
||||
"userLogin" => "",
|
||||
"userID" => 0
|
||||
)
|
||||
);
|
||||
error_reporting(0);
|
||||
$this->sys_input = json_decode($this->input->raw_input_stream,true);
|
||||
if (! $this->sys_input ) {
|
||||
if ( count($this->input->post()) > 0 ) {
|
||||
$this->sys_input = $this->input->post();
|
||||
} else {
|
||||
$this->sys_input = $this->input->get();
|
||||
}
|
||||
}
|
||||
$this->load->library("Jwt");
|
||||
try {
|
||||
$prm = $this->sys_input;
|
||||
if (! isset($prm["token"])) {
|
||||
$this->isLogin = false;
|
||||
} else {
|
||||
$user = JWT::decode($prm["token"],$this->SECRET_KEY,true);
|
||||
unset($this->sys_input["token"]);
|
||||
$user = json_decode(json_encode($user),true);
|
||||
if ($user["M_UserID"] > 0 ) {
|
||||
$this->isLogin = true;
|
||||
}
|
||||
$this->sys_user = $user;
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
$query = $this->db_regional->query("update m_user SET M_UserLastAccess = now() WHERE M_UserID = ?",array($user["M_UserID"]));
|
||||
if (!$query) {
|
||||
$message = $this->db_regional->error();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
//update last accessed
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
$this->isLogin = false;
|
||||
}
|
||||
$this->load->database();
|
||||
|
||||
}
|
||||
public function sys_debug() {
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
}
|
||||
public function sys_error_db($message,$db = false) {
|
||||
if (! $db ) {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message,
|
||||
"query" => $this->db->last_query(),
|
||||
"db_error" => $this->db->error()
|
||||
)
|
||||
);
|
||||
} else {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message,
|
||||
"query" => $db->last_query(),
|
||||
"db_error" => $db->error()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
public function sys_error($message) {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "ERR",
|
||||
"message" => $message
|
||||
)
|
||||
);
|
||||
}
|
||||
public function sys_ok($data) {
|
||||
echo json_encode(
|
||||
array(
|
||||
"status" => "OK",
|
||||
"data" => $data
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function clean_mysqli_connection( $dbc )
|
||||
{
|
||||
while( mysqli_more_results($dbc) )
|
||||
{
|
||||
if(mysqli_next_result($dbc))
|
||||
{
|
||||
$result = mysqli_use_result($dbc);
|
||||
|
||||
unset($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MY_Base extends MY_Controller {
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database('regional', true);
|
||||
$this->response = array("status" => "ERR");
|
||||
$this->XBASE_QRY_ERROR = -1;
|
||||
$this->XBASE_QRY_NO_RESULT = 0;
|
||||
$this->XBASE_QRY_OK = 1;
|
||||
|
||||
}
|
||||
|
||||
public function clean_connection()
|
||||
{
|
||||
$dbc = $this->db_regional->conn_id;
|
||||
while( mysqli_more_results($dbc) )
|
||||
{
|
||||
if(mysqli_next_result($dbc))
|
||||
{
|
||||
$result = mysqli_use_result($dbc);
|
||||
|
||||
unset($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
public function reply()
|
||||
{
|
||||
echo json_encode($this->response);
|
||||
exit;
|
||||
}
|
||||
public function exec_query($sql, $param = false)
|
||||
{
|
||||
if ($param) {
|
||||
$qry = $this->db_regional->query($sql, $param);
|
||||
} else {
|
||||
$qry = $this->db_regional->query($sql);
|
||||
}
|
||||
if (!$qry) {
|
||||
return array(
|
||||
"status" => $this->XBASE_QRY_ERROR,
|
||||
"message" => $this->db_regional->error()["msg"] . "\n" . $this->db_regional->last_query()
|
||||
);
|
||||
}
|
||||
return array(
|
||||
"status" => $this->XBASE_QRY_OK,
|
||||
"messge" => "", "query" => $qry
|
||||
);
|
||||
}
|
||||
function get_one_row($sql, $param = false)
|
||||
{
|
||||
$res = $this->exec_query($sql, $param);
|
||||
|
||||
if ($res["status"] == $this->XBASE_QRY_ERROR) {
|
||||
return $res;
|
||||
}
|
||||
$rows = $res["query"]->result_array();
|
||||
if (count($rows) == 0) {
|
||||
return array("status" => $this->XBASE_QRY_NO_RESULT, "row" => []);
|
||||
}
|
||||
return array("status" => $this->XBASE_QRY_OK, "row" => $rows[0]);
|
||||
}
|
||||
function get_rows($sql,$param=false) {
|
||||
$res = $this->exec_query($sql,$param);
|
||||
if( $res["status"] == $this->XBASE_QRY_ERROR) {
|
||||
return $res;
|
||||
}
|
||||
$rows = $res["query"]->result_array();
|
||||
return array("status" => $this->XBASE_QRY_OK, "rows" => $rows);
|
||||
}
|
||||
}
|
||||
?>
|
||||
11
one-api/application/core/index.html
Normal file
11
one-api/application/core/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user