Skip to content

Commit

Permalink
#### 4.1 -- Added: Support for license removal using api (slm_action=…
Browse files Browse the repository at this point in the history
…slm_remove)
  • Loading branch information
michelve committed Aug 8, 2018
1 parent 8013168 commit d8ae377
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# CHANGELOG
All notable changes to this project will be documented in this file.

#### 4.1
- Added: Support for license removal using api (slm_action=slm_remove)

#### 4.1
- Added: New action hook added.

Expand Down
43 changes: 43 additions & 0 deletions software-license-manager/includes/slm-api-listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ class SLM_API_Listener {
function __construct() {

if (isset($_REQUEST['slm_action']) && isset($_REQUEST['secret_key'])) {

//This is an API query for the license manager. Handle the query.
$this->creation_api_listener();
$this->activation_api_listener();
$this->deactivation_api_listener();
$this->check_api_listener();
$this->removal_api_listener();
}
}

Expand Down Expand Up @@ -280,6 +282,47 @@ function deactivation_api_listener() {
}
}

function removal_api_listener(){
if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_remove') {
//Handle the license activation API query
global $slm_debug_logger;

SLM_API_Utility::verify_secret_key(); //Verify the secret key first.

$slm_debug_logger->log_debug("API - license removal (slm_remove) request received.");

//Action hook
do_action('slm_api_listener_slm_remove');

global $wpdb;
$tbl_name = SLM_TBL_LICENSE_KEYS;
$reg_table = SLM_TBL_LIC_DOMAIN;
$reg_table_devices = SLM_TBL_LIC_DEVICES;

$fields = array();
$fields['lic_key'] = trim(strip_tags($_REQUEST['license_key']));
$key = $fields['lic_key'];

$sql_query = $wpdb->delete( $tbl_name, array( 'license_key' => $key ) );

// TODO: cleanup devices and domain table

if ( $sql_query ) {
$args = (array('result' => 'success', 'code' => SLM_Error_Codes::KEY_CANCELED, 'message' => 'License key removed', 'key' => $key, 'found_in' => $tbl_name ));
SLM_API_Utility::output_api_response($args);
}
else {
$args = (array('result' => 'error', 'code' => SLM_Error_Codes::KEY_CANCELED_FAILED, 'message' => 'License key was not removed', 'key' => $key, 'reason' => 'not found' ));
SLM_API_Utility::output_api_response($args);
}

}
else {
$args = (array('result' => 'error', 'message' => 'License key not found.', 'error_code' => SLM_Error_Codes::KEY_CANCELED_FAILED));
SLM_API_Utility::output_api_response($args);
}
}

function check_api_listener() {
if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_check') {
//Handle the license check API query
Expand Down
10 changes: 0 additions & 10 deletions software-license-manager/includes/slm-api-utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ static function verify_secret_key_for_creation() {
}

static function insert_license_data_internal($fields) {
/* The fields array should have values for the following keys
//$fields['license_key']
//$fields['lic_status']
//$fields['first_name']
//$fields['last_name']
//$fields['email']
//$fields['company_name']
//$fields['txn_id']
//$fields['max_allowed_domains']
*/
global $wpdb;
$tbl_name = SLM_TBL_LICENSE_KEYS;
$fields = array_filter($fields);//Remove any null values.
Expand Down
7 changes: 4 additions & 3 deletions software-license-manager/includes/slm-error-codes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Contains the API error codes
*/
class SLM_Error_Codes {

const CREATE_FAILED = 10;
const LICENSE_BLOCKED = 20;
const LICENSE_EXPIRED = 30;
Expand All @@ -15,6 +14,8 @@ class SLM_Error_Codes {
const DOMAIN_ALREADY_INACTIVE = 80;
const VERIFY_KEY_INVALID = 90;
const CREATE_KEY_INVALID = 100;
const REACHED_MAX_DEVICES = 100;

const REACHED_MAX_DEVICES = 120;
const KEY_DELETED = 130;
const KEY_CANCELED = 130;
const KEY_CANCELED_FAILED = 140;
}
6 changes: 3 additions & 3 deletions software-license-manager/software-license-manager.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
Plugin Name: Software License Manager
Version: 4.1
Version: 4.2
Plugin URI: https://www.tipsandtricks-hq.com/software-license-manager-plugin-for-wordpress
Author: Tips and Tricks HQ
Author URI: https://www.tipsandtricks-hq.com/
Expand All @@ -16,8 +16,8 @@
}

//Short name/slug "SLM" or "slm"
define('SLM_VERSION', "4.1");
define('SLM_DB_VERSION', '1.7');
define('SLM_VERSION', "4.2");
define('SLM_DB_VERSION', '1.8');
define('SLM_FOLDER', dirname(plugin_basename(__FILE__)));
define('SLM_URL', plugins_url('',__FILE__));
define('SLM_ASSETS_URL', plugins_url('',__FILE__).'/public/assets/');
Expand Down

0 comments on commit d8ae377

Please sign in to comment.