first commit
This commit is contained in:
Executable
+43
@@ -0,0 +1,43 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* ACL Middleware
|
||||
*
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*/
|
||||
class Acl_middleware
|
||||
{
|
||||
protected $_controller;
|
||||
protected $_ci;
|
||||
|
||||
public $roles = array();
|
||||
|
||||
public function __construct(&$controller, &$ci)
|
||||
{
|
||||
$this->_controller = $controller;
|
||||
$this->_ci = $ci;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$session = $this->_controller->get_session();
|
||||
|
||||
$user_id = isset($session['user_id']) ? $session['user_id'] : 0;
|
||||
$email = isset($session['email']) ? $session['email'] : '';
|
||||
$role = isset($session['role']) ? $session['role'] : NULL;
|
||||
|
||||
$condition = ($role != NULL) && in_array((int)$role, $this->_controller->_valid_roles) &&
|
||||
($user_id > 0) && (strlen($email) > 0);
|
||||
|
||||
if (!$condition)
|
||||
{
|
||||
$this->_controller->destroy_session();
|
||||
return $this->_controller->redirect('/', 'refresh');
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Affilate Middleware
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Affilate_middleware
|
||||
{
|
||||
protected $_controller;
|
||||
protected $_ci;
|
||||
|
||||
public $roles = array();
|
||||
|
||||
public function __construct(&$controller, &$ci)
|
||||
{
|
||||
$this->_controller = $controller;
|
||||
$this->_ci = $ci;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$refer_code = $this->_controller->input->get('affilate', TRUE);
|
||||
|
||||
if ($refer_code && strlen($refer_code) > 0)
|
||||
{
|
||||
$this->_controller->set_session('refer', $refer_code);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Auth Middleware
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Auth_middleware
|
||||
{
|
||||
protected $_controller;
|
||||
protected $_ci;
|
||||
|
||||
public $roles = array();
|
||||
|
||||
public function __construct(&$controller, &$ci)
|
||||
{
|
||||
$this->_controller = $controller;
|
||||
$this->_ci = $ci;
|
||||
}
|
||||
public function run()
|
||||
{
|
||||
$session = $this->_controller->get_session();
|
||||
|
||||
$logged_in = empty($session) || ! isset($session['user_id']) || ! isset($session['email']);
|
||||
|
||||
if ($logged_in)
|
||||
{
|
||||
$this->_controller->destroy_session();
|
||||
$this->_controller->load->helper('cookie');
|
||||
$cookie = [
|
||||
'name' => 'redirect',
|
||||
'value' => '/' . uri_string(),
|
||||
'expire' => '60',
|
||||
'secure' => FALSE
|
||||
];
|
||||
set_cookie($cookie);
|
||||
return $this->_controller->redirect('/', 'refresh');
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Maintenance Middleware
|
||||
*
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*/
|
||||
class Maintenance_middleware
|
||||
{
|
||||
protected $_controller;
|
||||
protected $_ci;
|
||||
|
||||
public $roles = array();
|
||||
|
||||
public function __construct(&$controller, &$ci)
|
||||
{
|
||||
$this->_controller = $controller;
|
||||
$this->_ci = $ci;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$setting = $this->_controller->get_setting();
|
||||
$condition = (isset($setting) && isset($setting['maintenance']) && $setting['maintenance'] == 1);
|
||||
|
||||
if ($condition)
|
||||
{
|
||||
header( '503 Service Unavailable', TRUE, 503 );
|
||||
stop_execution();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* ACL Middleware
|
||||
*
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*/
|
||||
class Subscription_middleware
|
||||
{
|
||||
|
||||
private $_controller;
|
||||
private $_ci;
|
||||
|
||||
public function __construct(&$controller, &$ci)
|
||||
{
|
||||
$this->_controller = $controller;
|
||||
$this->_ci = $ci;
|
||||
$this->_controller->load->database();
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$session = $this->_controller->get_session();
|
||||
$this->_controller->load->model('stripe_subscriptions_model');
|
||||
$this->_controller->load->model('stripe_feature_model');
|
||||
$this->_controller->load->model('controllers_features_model');
|
||||
|
||||
if (!empty($session)) {
|
||||
$user_id = $session['user_id'];
|
||||
$role_id = $session['role'];
|
||||
$user_sub = $this->_controller->stripe_subscriptions_model->get_last_active_subscription([
|
||||
'user_id' => $user_id,
|
||||
'role_id' => $role_id,
|
||||
]);
|
||||
|
||||
$portal = $this->_controller->uri->segment(1);
|
||||
|
||||
//if user is not subscriped to anything get all features for plan -1 which is free plan (always should be like this)
|
||||
//if user is not subscriped to anything get all features for plan 0 which is access all (always should be like this)
|
||||
if (!$user_sub) {
|
||||
$features = $this->_controller->stripe_feature_model->get_all(['plan_id' => -1]);
|
||||
} else {
|
||||
$features = $this->_controller->stripe_feature_model->get_all(['plan_id' => $user_sub->plan_id]);
|
||||
if (!$features) {
|
||||
$features = $this->_controller->stripe_feature_model->get_all(['plan_id' => -1]);
|
||||
}
|
||||
}
|
||||
|
||||
//check if a plan has "all" feature
|
||||
$found = false;
|
||||
|
||||
foreach ($features as $feature) {
|
||||
// if ($feature->slug == 'all' || $feature->controller_name == 'all') {
|
||||
// $found = true;
|
||||
// break;
|
||||
// }
|
||||
$feature = $this->_controller->controllers_features_model->get($feature->controller_feature_id);
|
||||
if (strcmp($this->_controller->uri->rsegments[1], $feature->controller_name) == 0) {
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($found == false) {
|
||||
$this->_controller->error('Your current subscription doesn\'t have access to that page. Upgrade your subscription.');
|
||||
$this->_controller->redirect("/{$portal}/stripe_subscriptions/0", 'refresh');
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
$this->_controller->error('Subscription required to access page');
|
||||
return $this->_controller->redirect("/{$portal}/stripe_subscriptions/0", 'refresh');
|
||||
}
|
||||
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
use function GuzzleHttp\json_encode;
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Token ACL Middleware
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Token_acl_middleware
|
||||
{
|
||||
protected $_controller;
|
||||
protected $_ci;
|
||||
|
||||
public $roles = array();
|
||||
|
||||
public function __construct(&$controller, &$ci)
|
||||
{
|
||||
$this->_controller = $controller;
|
||||
$this->_ci = $ci;
|
||||
}
|
||||
|
||||
/**
|
||||
* Steps:
|
||||
* 1.Get authorization header
|
||||
* 2.Validate it
|
||||
* 3.Check if it matches role
|
||||
* 4.Return error if not match
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$condition = in_array($this->_controller->get_role_id(), $this->_controller->get_valid_role());
|
||||
|
||||
if (!$condition)
|
||||
{
|
||||
$this->unauthorize_resource_error_message();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
private function unauthorize_resource_error_message()
|
||||
{
|
||||
http_response_code(406);
|
||||
echo json_encode([
|
||||
'code' => 406,
|
||||
'success' => FALSE,
|
||||
'message' => 'cannot access resource'
|
||||
]);
|
||||
stop_execution();
|
||||
}
|
||||
}
|
||||
Executable
+114
@@ -0,0 +1,114 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
include_once __DIR__ . '/../services/Token_service.php';
|
||||
/*Powered By: Manaknightdigital Inc. https://manaknightdigital.com/ Year: 2021*/
|
||||
/**
|
||||
* Token Middleware
|
||||
* @copyright 2019 Manaknightdigital Inc.
|
||||
* @link https://manaknightdigital.com
|
||||
* @license Proprietary Software licensing
|
||||
* @author Ryan Wong
|
||||
*
|
||||
*/
|
||||
class Token_middleware
|
||||
{
|
||||
protected $_controller;
|
||||
protected $_ci;
|
||||
|
||||
public $roles = array();
|
||||
|
||||
public function __construct(&$controller, &$ci)
|
||||
{
|
||||
$this->_controller = $controller;
|
||||
$this->_ci = $ci;
|
||||
}
|
||||
|
||||
/**
|
||||
* Steps:
|
||||
* 1.Get authorization header
|
||||
* 2.Validate it
|
||||
* 3.Check if it matches role
|
||||
* 4.Return error if not match
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$token_service = new Token_service();
|
||||
$key = $this->_ci->item('jwt_key');
|
||||
|
||||
$jwt_token = $this->_get_bearer_token();
|
||||
|
||||
if (strlen($jwt_token) < 1)
|
||||
{
|
||||
$this->unauthorize_error_message();
|
||||
}
|
||||
|
||||
$result = $token_service->validate_token ($key, $this->_get_bearer_token());
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$this->_controller->set_user_id($result->user_id);
|
||||
$this->_controller->set_role_id($result->role_id);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
$this->unauthorize_error_message();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
private function _get_bearer_token()
|
||||
{
|
||||
$bearer_token = '';
|
||||
|
||||
$bearer_token_header = $this->_controller->input->get_request_header('Authorization');
|
||||
$bearer_token_get = $this->_controller->input->get('Authorization');
|
||||
|
||||
if (strlen($bearer_token_header) < 1)
|
||||
{
|
||||
if (strlen($bearer_token_get) < 1)
|
||||
{
|
||||
$lower_case_bearer_token_header = $this->_controller->input->get_request_header('authorization');
|
||||
$lower_case_bearer_token_get = $this->_controller->input->get('authorization');
|
||||
if (strlen($lower_case_bearer_token_header) < 1)
|
||||
{
|
||||
if (strlen($lower_case_bearer_token_get) > 1)
|
||||
{
|
||||
$bearer_token = $lower_case_bearer_token_get;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$bearer_token = $lower_case_bearer_token_header;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$bearer_token = $bearer_token_get;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$bearer_token = $bearer_token_header;
|
||||
}
|
||||
|
||||
if (strpos($bearer_token, 'Bearer ') !== 0)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
else
|
||||
{
|
||||
return str_replace('Bearer ', '', $bearer_token);
|
||||
}
|
||||
}
|
||||
|
||||
private function unauthorize_error_message()
|
||||
{
|
||||
http_response_code(401);
|
||||
echo json_encode([
|
||||
'code' => 401,
|
||||
'success' => FALSE,
|
||||
'message' => 'invalid credentials'
|
||||
]);
|
||||
stop_execution();
|
||||
}
|
||||
}
|
||||
Executable
+11
@@ -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