forked from Arsenal21/software-license-manager
-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
db access file moved inside includes
- Loading branch information
amin0_000
committed
Sep 18, 2014
1 parent
633d9a3
commit a5b97ed
Showing
6 changed files
with
202 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,39 @@ | ||
<?php | ||
if(isset($_REQUEST['secret_key'])){ | ||
include_once('../../../../wp-load.php'); | ||
include_once('../lic_db_access.php'); | ||
|
||
$right_secret_key = get_option('wp_lic_mgr_verification_secret_key'); | ||
|
||
$received_secret_key = $_REQUEST['secret_key']; | ||
if ($received_secret_key != $right_secret_key){ | ||
echo "Error\n"; | ||
echo "Secret key is invalid\n"; | ||
exit; | ||
} | ||
|
||
if(empty($_REQUEST['license_key'])) | ||
{ | ||
echo "Error\n"; | ||
echo "License key information is missing.\n"; | ||
exit; | ||
} | ||
if(empty($_REQUEST['registered_domain'])) | ||
{ | ||
echo "Error\n"; | ||
echo "Registered domain information is missing.\n"; | ||
exit; | ||
|
||
if (isset($_REQUEST['secret_key'])) { | ||
include_once('../../../../wp-load.php'); | ||
include_once(WP_LICENSE_MANAGER_PATH . 'includes/slm_db_access.php'); | ||
|
||
$right_secret_key = get_option('wp_lic_mgr_verification_secret_key'); | ||
|
||
$received_secret_key = $_REQUEST['secret_key']; | ||
if ($received_secret_key != $right_secret_key) { | ||
echo "Error\n"; | ||
echo "Secret key is invalid\n"; | ||
exit; | ||
} | ||
$registered_domain = trim($_REQUEST['registered_domain']); | ||
|
||
$updateDb = LicMgrDbAccess::delete(WP_LICENSE_MANAGER_REG_DOMAIN_TABLE_NAME, 'lic_key=\'' . $_REQUEST['license_key'] . '\' AND registered_domain=\'' . $registered_domain . '\''); | ||
|
||
if($updateDb){ | ||
echo "Success\n"; | ||
echo "Following License Key Deactivated: "; | ||
echo $_REQUEST['license_key']; | ||
echo "\n"; | ||
|
||
if (empty($_REQUEST['license_key'])) { | ||
echo "Error\n"; | ||
echo "License key information is missing.\n"; | ||
exit; | ||
} | ||
else{ | ||
echo "Error\n"; | ||
echo "License key could not be deactivated.\n"; | ||
if (empty($_REQUEST['registered_domain'])) { | ||
echo "Error\n"; | ||
echo "Registered domain information is missing.\n"; | ||
exit; | ||
} | ||
$registered_domain = trim($_REQUEST['registered_domain']); | ||
|
||
$updateDb = LicMgrDbAccess::delete(WP_LICENSE_MANAGER_REG_DOMAIN_TABLE_NAME, 'lic_key=\'' . $_REQUEST['license_key'] . '\' AND registered_domain=\'' . $registered_domain . '\''); | ||
|
||
if ($updateDb) { | ||
echo "Success\n"; | ||
echo "Following License Key Deactivated: "; | ||
echo $_REQUEST['license_key']; | ||
echo "\n"; | ||
} else { | ||
echo "Error\n"; | ||
echo "License key could not be deactivated.\n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,62 @@ | ||
<?php | ||
if(isset($_REQUEST['secret_key'])) | ||
{ | ||
include_once('../../../../wp-load.php'); | ||
include_once('../lic_db_access.php'); | ||
|
||
$right_secret_key = get_option('wp_lic_mgr_verification_secret_key'); | ||
|
||
$received_secret_key = $_REQUEST['secret_key']; | ||
if ($received_secret_key != $right_secret_key) | ||
{ | ||
if (isset($_REQUEST['secret_key'])) { | ||
include_once('../../../../wp-load.php'); | ||
include_once(WP_LICENSE_MANAGER_PATH . 'includes/slm_db_access.php'); | ||
|
||
$right_secret_key = get_option('wp_lic_mgr_verification_secret_key'); | ||
|
||
$received_secret_key = $_REQUEST['secret_key']; | ||
if ($received_secret_key != $right_secret_key) { | ||
echo "Error\n"; | ||
echo "Invalid verification secret key!\n"; | ||
exit(0); | ||
} | ||
$fields = array(); | ||
$fields['lic_key'] = trim($_REQUEST['license_key']); | ||
$fields['registered_domain'] = trim($_REQUEST['registered_domain']);//gethostbyaddr($_SERVER['REMOTE_ADDR']); | ||
$fields['registered_domain'] = trim($_REQUEST['registered_domain']); //gethostbyaddr($_SERVER['REMOTE_ADDR']); | ||
|
||
global $wpdb; | ||
$tbl_name = WP_LICENSE_MANAGER_LICENSE_TABLE_NAME; | ||
$reg_table = WP_LICENSE_MANAGER_REG_DOMAIN_TABLE_NAME; | ||
$key = $fields['lic_key']; | ||
$retLic = $wpdb->get_row("SELECT * FROM $tbl_name WHERE license_key = '$key'", OBJECT); | ||
$reg_domains = $wpdb->get_results(" SELECT * FROM $reg_table WHERE lic_key= '$key'", OBJECT ); | ||
if($retLic){ | ||
if($retLic->lic_status !=='active'){ | ||
echo "Error\n"; | ||
echo "License is " .$retLic->lic_status. ".\n"; | ||
exit(0); | ||
} | ||
if(floor($retLic->max_allowed_domains)>count($reg_domains)){ | ||
foreach($reg_domains as $reg_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($_REQUEST['migrate_from']))); | ||
echo "Success\n"; | ||
echo "Registered domain has been updated.\n"; | ||
exit(0); | ||
} | ||
if($fields['registered_domain'] == $reg_domain->registered_domain){ | ||
echo "Error\n"; | ||
echo "License key already in use on ".$reg_domain->registered_domain."\n"; | ||
exit(0); | ||
} | ||
} | ||
$fields['lic_key_id'] = $retLic->id; | ||
$wpdb->insert($reg_table, $fields); | ||
$reg_domains = $wpdb->get_results(" SELECT * FROM $reg_table WHERE lic_key= '$key'", OBJECT); | ||
if ($retLic) { | ||
if ($retLic->lic_status !== 'active') { | ||
echo "Error\n"; | ||
echo "License is " . $retLic->lic_status . ".\n"; | ||
exit(0); | ||
} | ||
if (floor($retLic->max_allowed_domains) > count($reg_domains)) { | ||
foreach ($reg_domains as $reg_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($_REQUEST['migrate_from']))); | ||
echo "Success\n"; | ||
echo "Registered domain has been updated.\n"; | ||
exit(0); | ||
} | ||
if ($fields['registered_domain'] == $reg_domain->registered_domain) { | ||
echo "Error\n"; | ||
echo "License key already in use on " . $reg_domain->registered_domain . "\n"; | ||
exit(0); | ||
} | ||
} | ||
$fields['lic_key_id'] = $retLic->id; | ||
$wpdb->insert($reg_table, $fields); | ||
echo "Success\n"; | ||
echo "License key verification passed!\n"; | ||
exit(0); | ||
} | ||
else{ | ||
echo "Error\n"; | ||
echo "Reached Maximum Allowable Domains!\n"; | ||
exit(0); | ||
} | ||
} | ||
else{ | ||
echo "License key verification passed!\n"; | ||
exit(0); | ||
} else { | ||
echo "Error\n"; | ||
echo "Reached Maximum Allowable Domains!\n"; | ||
exit(0); | ||
} | ||
} else { | ||
echo "Error\n"; | ||
echo "Invalid License Key!\n"; | ||
} | ||
} | ||
else | ||
{ | ||
} else { | ||
echo "Error\n"; | ||
echo "Verification secret key is required!\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
global $wpdb; | ||
define('WP_LICENSE_MANAGER_LICENSE_TABLE_NAME', $wpdb->prefix . "lic_key_tbl"); | ||
define('WP_LICENSE_MANAGER_REG_DOMAIN_TABLE_NAME', $wpdb->prefix . "lic_reg_domain_tbl"); | ||
|
||
class LicMgrDbAccess { | ||
|
||
function __construct() { | ||
die(); | ||
} | ||
|
||
function LicMgrDbAccess() { | ||
die(); | ||
} | ||
|
||
function find($inTable, $condition) { | ||
global $wpdb; | ||
|
||
if (empty($condition)) { | ||
return null; | ||
} | ||
$resultset = $wpdb->get_row("SELECT * FROM $inTable WHERE $condition", OBJECT); | ||
return $resultset; | ||
} | ||
|
||
function findAll($inTable, $condition = null, $orderby = null) { | ||
global $wpdb; | ||
$condition = empty($condition) ? '' : ' WHERE ' . $condition; | ||
$condition .= empty($orderby) ? '' : ' ORDER BY ' . $orderby; | ||
$resultSet = $wpdb->get_results("SELECT * FROM $inTable $condition ", OBJECT); | ||
return $resultSet; | ||
} | ||
|
||
function delete($fromTable, $condition) { | ||
global $wpdb; | ||
$resultSet = $wpdb->query("DELETE FROM $fromTable WHERE $condition "); | ||
return $resultSet; | ||
} | ||
|
||
function update($inTable, $condition, $fields) { | ||
global $wpdb; | ||
$query = " UPDATE $inTable SET "; | ||
$first = true; | ||
foreach ($fields as $field => $value) { | ||
if ($first) | ||
$first = false; | ||
else | ||
$query .= ' , '; | ||
$query .= " $field = '" . $wpdb->escape($value) . "' "; | ||
} | ||
|
||
$query .= empty($condition) ? '' : " WHERE $condition "; | ||
$results = $wpdb->query($query); | ||
return $results; | ||
} | ||
|
||
function insert($inTable, $fields) { | ||
global $wpdb; | ||
$fieldss = ''; | ||
$valuess = ''; | ||
$first = true; | ||
foreach ($fields as $field => $value) { | ||
if ($first) | ||
$first = false; | ||
else { | ||
$fieldss .= ' , '; | ||
$valuess .= ' , '; | ||
} | ||
$fieldss .= " $field "; | ||
$valuess .= " '" . $wpdb->escape($value) . "' "; | ||
} | ||
|
||
$query .= " INSERT INTO $inTable ($fieldss) VALUES ($valuess)"; | ||
|
||
$results = $wpdb->query($query); | ||
return $results; | ||
} | ||
|
||
function findCount($inTable, $fields = null, $condition = null, $orderby = null, $groupby = null) { | ||
global $wpdb; | ||
$fieldss = ''; | ||
$first = true; | ||
|
||
if (empty($fields)) { | ||
$fieldss = 'count(*) as count'; | ||
} else { | ||
foreach ($fields as $key => $value) { | ||
if ($first) | ||
$first = false; | ||
else { | ||
$fieldss .= ' , '; | ||
} | ||
$fieldss .= " $key AS $value"; | ||
} | ||
} | ||
$condition = $condition ? " WHERE $condition " : null; | ||
$condition.= empty($orderby) ? '' : ' ORDER BY ' . $orderby; | ||
$condition.= empty($groupby) ? '' : ' GROUP BY ' . $groupby; | ||
|
||
$resultset = $wpdb->get_results("SELECT $fieldss FROM $inTable $condition ", OBJECT); | ||
return $resultset; | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.