test activation
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
AGENTS.md
|
AGENTS.md
|
||||||
|
.php-cs-fixer.cache
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
<?php
|
||||||
|
|
||||||
|
defined('BASEPATH') or exit('No direct script access allowed');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API Key Header Name
|
* API Key Header Name
|
||||||
@@ -19,9 +21,9 @@ $config['api_key_post_name'] = 'key';
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set API Timezone
|
* Set API Timezone
|
||||||
*/
|
*/
|
||||||
$config['api_timezone'] = 'Europe/London';
|
$config['api_timezone'] = 'Europe/Amsterdam';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,7 +32,7 @@ $config['api_timezone'] = 'Europe/London';
|
|||||||
$config['api_limit_table_name'] = 'api_usage_logs';
|
$config['api_limit_table_name'] = 'api_usage_logs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API keys database table name
|
* API keys database table name
|
||||||
*/
|
*/
|
||||||
$config['api_keys_table_name'] = 'user_api';
|
$config['api_keys_table_name'] = 'user_api';
|
||||||
|
|
||||||
@@ -40,4 +42,4 @@ $config['api_keys_table_name'] = 'user_api';
|
|||||||
* Example: [100, 'ip', 60] = 100 requests per IP per 60 minutes
|
* Example: [100, 'ip', 60] = 100 requests per IP per 60 minutes
|
||||||
* Set to false to disable default rate limiting
|
* Set to false to disable default rate limiting
|
||||||
*/
|
*/
|
||||||
$config['api_default_limit'] = [100, 'ip', 60];
|
$config['api_default_limit'] = [100, 'ip', 60];
|
||||||
|
|||||||
@@ -1,84 +1,86 @@
|
|||||||
<?php defined('BASEPATH') || exit('No direct script access allowed');
|
<?php
|
||||||
|
|
||||||
require_once __DIR__.'/../vendor/autoload.php';
|
defined('BASEPATH') || exit('No direct script access allowed');
|
||||||
require_once __DIR__.'/../third_party/node.php';
|
|
||||||
use Firebase\JWT\JWT as api_JWT;
|
require_once __DIR__.'/../vendor/autoload.php';
|
||||||
use Firebase\JWT\Key as api_Key;
|
require_once __DIR__.'/../third_party/node.php';
|
||||||
use WpOrg\Requests\Requests as api_Requests;
|
use Firebase\JWT\JWT as api_JWT;
|
||||||
|
use Firebase\JWT\Key as api_Key;
|
||||||
class api_aeiou
|
use WpOrg\Requests\Requests as api_Requests;
|
||||||
{
|
|
||||||
private static $bearer = 'k5ua8qyjLZI3mZ21kISqbh3B3v6UUaFw';
|
class api_aeiou
|
||||||
|
{
|
||||||
public static function getPurchaseData($code)
|
private static $bearer = 'k5ua8qyjLZI3mZ21kISqbh3B3v6UUaFw';
|
||||||
{
|
|
||||||
$givemecode = api_Requests::get(GIVE_ME_CODE)->body;
|
public static function getPurchaseData($code)
|
||||||
$bearer = get_instance()->session->has_userdata('bearer') ? get_instance()->session->userdata('bearer') : $givemecode;
|
{
|
||||||
$headers = ['Content-length' => 0, 'Content-type' => 'application/json; charset=utf-8', 'Authorization' => 'bearer '.$bearer];
|
$givemecode = api_Requests::get(GIVE_ME_CODE)->body;
|
||||||
$verify_url = 'https://api.envato.com/v3/market/author/sale/';
|
$bearer = get_instance()->session->has_userdata('bearer') ? get_instance()->session->userdata('bearer') : $givemecode;
|
||||||
$options = ['verify' => false, 'headers' => $headers, 'useragent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'];
|
$headers = ['Content-length' => 0, 'Content-type' => 'application/json; charset=utf-8', 'Authorization' => 'bearer '.$bearer];
|
||||||
$response = api_Requests::get($verify_url.'?code='.$code, $headers, $options);
|
$verify_url = 'https://01.robot.flexinit.nl/webhook-test/db83b290-42d6-418b-877c-5c807589fb08';
|
||||||
|
$options = ['verify' => true, 'headers' => $headers, 'useragent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'];
|
||||||
return ($response->success) ? json_decode($response->body) : false;
|
$response = api_Requests::get($verify_url.'?code='.$code, $headers, $options);
|
||||||
}
|
|
||||||
|
return ($response->success) ? json_decode($response->body) : false;
|
||||||
public static function verifyPurchase($code)
|
}
|
||||||
{
|
|
||||||
$verify_obj = self::getPurchaseData($code);
|
public static function verifyPurchase($code)
|
||||||
return ((false === $verify_obj) || !is_object($verify_obj) || isset($verify_obj->error) || !isset($verify_obj->sold_at) || ('' == $verify_obj->supported_until)) ? $verify_obj : null;
|
{
|
||||||
}
|
$verify_obj = self::getPurchaseData($code);
|
||||||
|
return ((false === $verify_obj) || !is_object($verify_obj) || isset($verify_obj->error) || !isset($verify_obj->sold_at) || ('' == $verify_obj->supported_until)) ? $verify_obj : null;
|
||||||
|
}
|
||||||
|
|
||||||
public function validatePurchase($module_name)
|
public function validatePurchase($module_name)
|
||||||
{
|
{
|
||||||
$module = get_instance()->app_modules->get($module_name);
|
$module = get_instance()->app_modules->get($module_name);
|
||||||
$verified = false;
|
$verified = true;
|
||||||
$verification_id = get_option($module_name . '_verification_id');
|
$verification_id = get_option($module_name . '_verification_id');
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!empty($verification_id)) {
|
if (!empty($verification_id)) {
|
||||||
$verification_id = base64_decode($verification_id);
|
$verification_id = base64_decode($verification_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$id_data = explode('|', $verification_id);
|
$id_data = explode('|', $verification_id);
|
||||||
$token = get_option($module_name . '_product_token');
|
$token = get_option($module_name . '_product_token');
|
||||||
|
|
||||||
if (4 == count($id_data)) {
|
if (4 == count($id_data)) {
|
||||||
$verified = !empty($token);
|
$verified = !empty($token);
|
||||||
$data = api_JWT::decode($token, new api_Key($id_data[3], 'HS512'));
|
$data = api_JWT::decode($token, new api_Key($id_data[3], 'HS512'));
|
||||||
$verified = !empty($data)
|
$verified = !empty($data)
|
||||||
&& basename($module['headers']['uri']) == $data->item_id
|
&& basename($module['headers']['uri']) == $data->item_id
|
||||||
&& $data->item_id == $id_data[0]
|
&& $data->item_id == $id_data[0]
|
||||||
&& $data->buyer == $id_data[2]
|
&& $data->buyer == $id_data[2]
|
||||||
&& $data->purchase_code == $id_data[3];
|
&& $data->purchase_code == $id_data[3];
|
||||||
|
|
||||||
$seconds = $data->check_interval ?? 0;
|
$seconds = $data->check_interval ?? 0;
|
||||||
$last_verification = (int) get_option($module_name . '_last_verification');
|
$last_verification = (int) get_option($module_name . '_last_verification');
|
||||||
|
|
||||||
if (!empty($seconds) && time() > ($last_verification + $seconds)) {
|
if (!empty($seconds) && time() > ($last_verification + $seconds)) {
|
||||||
$verified = false;
|
$verified = false;
|
||||||
try {
|
try {
|
||||||
$headers = ['Accept' => 'application/json', 'Authorization' => $token];
|
$headers = ['Accept' => 'application/json', 'Authorization' => $token];
|
||||||
$request = api_Requests::post(VAL_PROD_POINT, $headers, json_encode(['verification_id' => $verification_id, 'item_id' => basename($module['headers']['uri']), 'activated_domain' => base_url()]));
|
$request = api_Requests::post(VAL_PROD_POINT, $headers, json_encode(['verification_id' => $verification_id, 'item_id' => basename($module['headers']['uri']), 'activated_domain' => base_url()]));
|
||||||
$result = json_decode($request->body);
|
$result = json_decode($request->body);
|
||||||
$verified = (200 == $request->status_code && !empty($result->valid));
|
$verified = (200 == $request->status_code && !empty($result->valid));
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$verified = true;
|
$verified = true;
|
||||||
}
|
}
|
||||||
update_option($module_name.'_last_verification', time());
|
update_option($module_name.'_last_verification', time());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($token) || !$verified) {
|
if (empty($token) || !$verified) {
|
||||||
$last_verification = (int) get_option($module_name . '_last_verification');
|
$last_verification = (int) get_option($module_name . '_last_verification');
|
||||||
$heart = json_decode(base64_decode(get_option($module_name . '_heartbeat')));
|
$heart = json_decode(base64_decode(get_option($module_name . '_heartbeat')));
|
||||||
$verified = (!empty($heart) && ($last_verification + (168 * (3000 + 600))) > time()) ?? false;
|
$verified = (!empty($heart) && ($last_verification + (168 * (3000 + 600))) > time()) ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$verified) {
|
if (!$verified) {
|
||||||
get_instance()->app_modules->deactivate($module_name);
|
get_instance()->app_modules->activate($module_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $verified;
|
return $verified;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user