Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

// Post URL
$postURL = "http://localhost:81/wp/wp7";
$postURL = 'http://localhost:81/wp/wp7';
// The Secret key
$secretKey = "541fc9967d4b43.07908805";
$firstname = "John";
$lastname = "Doe";
$email = "john.doe@gmail.com";
$secretKey = '541fc9967d4b43.07908805';
$firstname = 'John';
$lastname = 'Doe';
$email = 'john.doe@gmail.com';

// prepare the data
$data = array ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ function sample_license_management_page() {
$response = wp_remote_get($query, array('timeout' => 20, 'sslverify' => false));

// Check for error in the response
if (is_wp_error($response)){
echo "Unexpected Error! The query returned with an error.";
if (is_wp_error($response)) {
echo 'Unexpected Error! The query returned with an error.';
}

//var_dump($response);//uncomment it if you want to look at the full response
Expand All @@ -58,18 +58,17 @@ function sample_license_management_page() {
// TODO - Do something with it.
//var_dump($license_data);//uncomment it to look at the data

if($license_data->result == 'success'){//Success was returned for the license activation
if ('success' === $license_data->result) {//Success was returned for the license activation

//Uncomment the followng line to see the message that returned from the license server
//Uncomment the following line to see the message that returned from the license server
echo '<br />The following message was returned from the server: '.$license_data->message;

//Save the license key in the options table
update_option('sample_license_key', $license_key);
}
else{
} else {
//Show error to the user. Probably entered incorrect license key.

//Uncomment the followng line to see the message that returned from the license server
//Uncomment the following line to see the message that returned from the license server
echo '<br />The following message was returned from the server: '.$license_data->message;
}

Expand All @@ -94,8 +93,8 @@ function sample_license_management_page() {
$response = wp_remote_get($query, array('timeout' => 20, 'sslverify' => false));

// Check for error in the response
if (is_wp_error($response)){
echo "Unexpected Error! The query returned with an error.";
if (is_wp_error($response)) {
echo 'Unexpected Error! The query returned with an error.';
}

//var_dump($response);//uncomment it if you want to look at the full response
Expand All @@ -106,18 +105,17 @@ function sample_license_management_page() {
// TODO - Do something with it.
//var_dump($license_data);//uncomment it to look at the data

if($license_data->result == 'success'){//Success was returned for the license activation
if ('success' === $license_data->result) {//Success was returned for the license activation

//Uncomment the followng line to see the message that returned from the license server
//Uncomment the following line to see the message that returned from the license server
echo '<br />The following message was returned from the server: '.$license_data->message;

//Remove the licensse key from the options table. It will need to be activated again.
//Remove the license key from the options table. It will need to be activated again.
update_option('sample_license_key', '');
}
else{
} else {
//Show error to the user. Probably entered incorrect license key.

//Uncomment the followng line to see the message that returned from the license server
//Uncomment the following line to see the message that returned from the license server
echo '<br />The following message was returned from the server: '.$license_data->message;
}

Expand All @@ -141,4 +139,4 @@ function sample_license_management_page() {
<?php

echo '</div>';
}
}
54 changes: 27 additions & 27 deletions software-license-manager/includes/slm-api-listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function __construct() {
}

function creation_api_listener() {
if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_create_new') {
if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) === 'slm_create_new') {
//Handle the licene creation API query
global $slm_debug_logger;

Expand All @@ -36,15 +36,15 @@ function creation_api_listener() {

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

$slm_debug_logger->log_debug("API - license creation (slm_create_new) request received.");
$slm_debug_logger->log_debug('API - license creation (slm_create_new) request received.');

//Action hook
do_action('slm_api_listener_slm_create_new');

$fields = array();
if (isset($_REQUEST['license_key']) && !empty($_REQUEST['license_key'])){
if (isset($_REQUEST['license_key']) && !empty($_REQUEST['license_key'])) {
$fields['license_key'] = strip_tags($_REQUEST['license_key']);//Use the key you pass via the request
}else{
} else {
$fields['license_key'] = uniqid($lic_key_prefix);//Use random generated key
}
$fields['lic_status'] = isset( $_REQUEST['lic_status'] ) ? wp_unslash( strip_tags( $_REQUEST['lic_status'] ) ) : 'pending';
Expand All @@ -58,8 +58,8 @@ function creation_api_listener() {
} else {
$fields['max_allowed_domains'] = strip_tags($_REQUEST['max_allowed_domains']);
}
$fields['date_created'] = isset($_REQUEST['date_created'])?strip_tags($_REQUEST['date_created']):date("Y-m-d");
$fields['date_expiry'] = isset($_REQUEST['date_expiry'])?strip_tags($_REQUEST['date_expiry']):'';
$fields['date_created'] = isset($_REQUEST['date_created']) ? strip_tags($_REQUEST['date_created']) : date('Y-m-d');
$fields['date_expiry'] = isset($_REQUEST['date_expiry']) ? strip_tags($_REQUEST['date_expiry']) : '';
$fields['product_ref'] = isset( $_REQUEST['product_ref'] ) ? wp_unslash( strip_tags( $_REQUEST['product_ref'] ) ) : '';

global $wpdb;
Expand All @@ -85,13 +85,13 @@ function creation_api_listener() {
*/

function activation_api_listener() {
if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_activate') {
if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) === 'slm_activate') {
//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 activation (slm_activate) request received.");
$slm_debug_logger->log_debug('API - license activation (slm_activate) request received.');

//Action hook
do_action('slm_api_listener_slm_activate');
Expand All @@ -106,36 +106,36 @@ function activation_api_listener() {
$tbl_name = SLM_TBL_LICENSE_KEYS;
$reg_table = SLM_TBL_LIC_DOMAIN;
$key = $fields['lic_key'];
$sql_prep1 = $wpdb->prepare("SELECT * FROM $tbl_name WHERE license_key = %s", $key);
$sql_prep1 = $wpdb->prepare("SELECT * FROM {$tbl_name} WHERE license_key = %s", $key);
$retLic = $wpdb->get_row($sql_prep1, OBJECT);

$sql_prep2 = $wpdb->prepare("SELECT * FROM $reg_table WHERE lic_key = %s", $key);
$sql_prep2 = $wpdb->prepare("SELECT * FROM {$reg_table} WHERE lic_key = %s", $key);
$reg_domains = $wpdb->get_results($sql_prep2, OBJECT);
if ($retLic) {
if ($retLic->lic_status == 'blocked') {
if ('blocked' === $retLic->lic_status) {
$args = (array('result' => 'error', 'message' => 'Your License key is blocked', 'error_code' => SLM_Error_Codes::LICENSE_BLOCKED));
SLM_API_Utility::output_api_response($args);
} elseif ($retLic->lic_status == 'expired') {
} elseif ('expired' === $retLic->lic_status) {
$args = (array('result' => 'error', 'message' => 'Your License key has expired', 'error_code' => SLM_Error_Codes::LICENSE_EXPIRED));
SLM_API_Utility::output_api_response($args);
}

if (count($reg_domains) < floor($retLic->max_allowed_domains)) {
foreach ($reg_domains as $reg_domain) {
if (isset($_REQUEST['migrate_from']) && (trim($_REQUEST['migrate_from']) == $reg_domain->registered_domain)) {
if (isset($_REQUEST['migrate_from']) && (trim($_REQUEST['migrate_from']) === $reg_domain->registered_domain)) {
$wpdb->update($reg_table, array('registered_domain' => $fields['registered_domain']), array('registered_domain' => trim(strip_tags($_REQUEST['migrate_from']))));
$args = (array('result' => 'success', 'message' => 'Registered domain has been updated'));
SLM_API_Utility::output_api_response($args);
}
if ($fields['registered_domain'] == $reg_domain->registered_domain) {
if ($fields['registered_domain'] === $reg_domain->registered_domain) {
$args = (array('result' => 'error', 'message' => 'License key already in use on ' . $reg_domain->registered_domain, 'error_code' => SLM_Error_Codes::LICENSE_IN_USE));
SLM_API_Utility::output_api_response($args);
}
}
$fields['lic_key_id'] = $retLic->id;
$wpdb->insert($reg_table, $fields);

$slm_debug_logger->log_debug("Updating license key status to active.");
$slm_debug_logger->log_debug('Updating license key status to active.');
$data = array('lic_status' => 'active');
$where = array('id' => $retLic->id);
$updated = $wpdb->update($tbl_name, $data, $where);
Expand All @@ -146,7 +146,7 @@ function activation_api_listener() {

//Lets loop through the domains to see if it is being used on an existing domain or not.
foreach ($reg_domains as $reg_domain) {
if ($fields['registered_domain'] == $reg_domain->registered_domain) {
if ($fields['registered_domain'] === $reg_domain->registered_domain) {
//Not used on an existing domain. Return error: LICENSE_IN_USE_ON_DOMAIN_AND_MAX_REACHED
$args = (array('result' => 'error', 'message' => 'Reached maximum activation. License key already in use on ' . $reg_domain->registered_domain, 'error_code' => SLM_Error_Codes::LICENSE_IN_USE_ON_DOMAIN_AND_MAX_REACHED));
SLM_API_Utility::output_api_response($args);
Expand All @@ -165,13 +165,13 @@ function activation_api_listener() {
}

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

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

$slm_debug_logger->log_debug("API - license deactivation (slm_deactivate) request received.");
$slm_debug_logger->log_debug('API - license deactivation (slm_deactivate) request received.');

//Action hook
do_action('slm_api_listener_slm_deactivate');
Expand All @@ -186,11 +186,11 @@ function deactivation_api_listener() {

global $wpdb;
$registered_dom_table = SLM_TBL_LIC_DOMAIN;
$sql_prep = $wpdb->prepare("DELETE FROM $registered_dom_table WHERE lic_key=%s AND registered_domain=%s", $license_key, $registered_domain);
$sql_prep = $wpdb->prepare("DELETE FROM {$registered_dom_table} WHERE lic_key=%s AND registered_domain=%s", $license_key, $registered_domain);
$delete = $wpdb->query($sql_prep);
if ($delete === false) {
$slm_debug_logger->log_debug("Error - failed to delete the registered domain from the database.");
} else if ($delete == 0) {
if (false === $delete) {
$slm_debug_logger->log_debug('Error - failed to delete the registered domain from the database.');
} else if (0 == $delete) {
$args = (array('result' => 'error', 'message' => 'The license key on this domain is already inactive', 'error_code' => SLM_Error_Codes::DOMAIN_ALREADY_INACTIVE));
SLM_API_Utility::output_api_response($args);
} else {
Expand All @@ -201,17 +201,17 @@ function deactivation_api_listener() {
}

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

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

$slm_debug_logger->log_debug("API - license check (slm_check) request received.");
$slm_debug_logger->log_debug('API - license check (slm_check) request received.');

$fields = array();
$fields['lic_key'] = trim(strip_tags($_REQUEST['license_key']));
$slm_debug_logger->log_debug("License key: " . $fields['lic_key']);
$slm_debug_logger->log_debug('License key: ' . $fields['lic_key']);

//Action hook
do_action('slm_api_listener_slm_check');
Expand All @@ -220,10 +220,10 @@ function check_api_listener() {
$tbl_name = SLM_TBL_LICENSE_KEYS;
$reg_table = SLM_TBL_LIC_DOMAIN;
$key = $fields['lic_key'];
$sql_prep1 = $wpdb->prepare("SELECT * FROM $tbl_name WHERE license_key = %s", $key);
$sql_prep1 = $wpdb->prepare("SELECT * FROM {$tbl_name} WHERE license_key = %s", $key);
$retLic = $wpdb->get_row($sql_prep1, OBJECT);

$sql_prep2 = $wpdb->prepare("SELECT * FROM $reg_table WHERE lic_key = %s", $key);
$sql_prep2 = $wpdb->prepare("SELECT * FROM {$reg_table} WHERE lic_key = %s", $key);
$reg_domains = $wpdb->get_results($sql_prep2, OBJECT);
if ($retLic) {//A license key exists
$args = apply_filters( 'slm_check_response_args', array(
Expand Down
15 changes: 7 additions & 8 deletions software-license-manager/includes/slm-debug-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function __construct()
$this->log_folder_path = WP_LICENSE_MANAGER_PATH . '/logs';
//Check config and if debug is enabled then set the enabled flag to true
$options = get_option('slm_plugin_options');
if(!empty($options['enable_debug'])){//Debugging is enabled
if (!empty($options['enable_debug'])) {//Debugging is enabled
$this->debug_enabled = true;
}
}
Expand All @@ -39,10 +39,9 @@ function get_debug_timestamp()
function get_debug_status($level)
{
$size = count($this->debug_status);
if($level >= $size){
if ($level >= $size) {
return 'UNKNOWN';
}
else{
} else {
return $this->debug_status[$level];
}
}
Expand All @@ -57,7 +56,7 @@ function get_section_break($section_break)

function reset_log_file($file_name='')
{
if(empty($file_name)){
if (empty($file_name)) {
$file_name = $this->default_log_file;
}
$debug_log_file = $this->log_folder_path.'/'.$file_name;
Expand All @@ -69,9 +68,9 @@ function reset_log_file($file_name='')

function append_to_file($content,$file_name)
{
if(empty($file_name))$file_name = $this->default_log_file;
if (empty($file_name))$file_name = $this->default_log_file;
$debug_log_file = $this->log_folder_path.'/'.$file_name;
$fp=fopen($debug_log_file,'a');
$fp=fopen($debug_log_file, 'a');
fwrite($fp, $content);
fclose($fp);
}
Expand Down Expand Up @@ -102,7 +101,7 @@ function log_debug_cron($message,$level=0,$section_break=false)
static function log_debug_st($message,$level=0,$section_break=false,$file_name='')
{
$options = get_option('slm_plugin_options');
if(empty($options['enable_debug'])){//Debugging is disabled
if (empty($options['enable_debug'])) {//Debugging is disabled
return;
}
$content = '['.date('m/d/Y g:i A').'] - STATUS : '. $message . "\n";
Expand Down
10 changes: 5 additions & 5 deletions software-license-manager/includes/slm-init-time-tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class SLM_Init_Time_Tasks{

function __construct(){
function __construct() {
$this->load_scripts();

//Add other init time operations here
Expand All @@ -15,12 +15,12 @@ function load_scripts()
wp_enqueue_script('jquery');

//Load all admin side scripts and styles only
if(is_admin())
if (is_admin())
{
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_script('wplm-custom-admin-js', WP_LICENSE_MANAGER_URL . '/js/wplm-custom-admin.js', array( 'jquery-ui-dialog' ));//admin only custom js code

if (isset($_GET['page']) && $_GET['page'] == 'wp_lic_mgr_addedit') {//Only include if we are in the license add/edit interface
if (isset($_GET['page']) && 'wp_lic_mgr_addedit' === $_GET['page']) {//Only include if we are in the license add/edit interface
wp_enqueue_style('jquery-ui-style', WP_LICENSE_MANAGER_URL .'/css/jquery-ui.css');
}
//wp_enqueue_style('dialogStylesheet', includes_url().'css/jquery-ui-dialog.css');
Expand All @@ -33,9 +33,9 @@ function slm_daily_cron_event_handler()

do_action('slm_daily_cron_event_triggered');

if ( isset($options['enable_auto_key_expiry']) && $options['enable_auto_key_expiry'] == '1'){
if ( isset($options['enable_auto_key_expiry']) && '1' == $options['enable_auto_key_expiry']) {
//Do the auto key expiry task
SLM_Debug_Logger::log_debug_st("SLM daily cronjob - auto expiry of license key is enabled.");
SLM_Debug_Logger::log_debug_st('SLM daily cronjob - auto expiry of license key is enabled.');
SLM_Utility::do_auto_key_expiry();
}

Expand Down
Loading