|
|
|
@ -3,12 +3,12 @@
|
|
|
|
|
/**
|
|
|
|
|
* Global and Local Hooks for the API key Management plugin
|
|
|
|
|
* Global Hooks are defined with the prefix(name of the plugin)
|
|
|
|
|
* Local Hooks are defined with normal function name
|
|
|
|
|
*
|
|
|
|
|
* Local Hooks are defined with normal function name
|
|
|
|
|
*
|
|
|
|
|
* All the Global Hooks are called during the page load
|
|
|
|
|
* and Local Hooks are called according to conditions
|
|
|
|
|
*
|
|
|
|
|
* @author shubham meena mentored by Matthew Lagoe
|
|
|
|
|
*
|
|
|
|
|
* @author shubham meena mentored by Matthew Lagoe
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Global variable to store the data which is
|
|
|
|
@ -27,7 +27,7 @@ function api_key_management_hook_display()
|
|
|
|
|
global $return_set;
|
|
|
|
|
// to display plugin name in menu bar
|
|
|
|
|
$return_set['menu_display'] = 'API Key Management';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Local Hook to validate the posted data
|
|
|
|
@ -37,12 +37,12 @@ function hook_validate( $var )
|
|
|
|
|
if ( isset( $var ) && !empty( $var ) )
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Local Hook to set the POST variables and validate them
|
|
|
|
@ -51,7 +51,7 @@ function hook_variables()
|
|
|
|
|
{
|
|
|
|
|
global $var_set;
|
|
|
|
|
global $return_set;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( hook_validate( $_POST['expDate'] ) && hook_validate( $_POST['sp_name'] ) && hook_validate( $_POST['api_type'] )
|
|
|
|
|
&& hook_validate( $_POST['character_name'] ) )
|
|
|
|
|
{
|
|
|
|
@ -63,12 +63,12 @@ function hook_variables()
|
|
|
|
|
$var_set['AddedOn'] = date( "Y-m-d H:i:s" );
|
|
|
|
|
$var_set['Items'] = '';
|
|
|
|
|
$return_set['gen_key_validate'] = 'true';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$return_set['gen_key_validate'] = 'false';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Global Hook to create table of the API_key_management
|
|
|
|
@ -108,12 +108,12 @@ function api_key_management_hook_create_tb()
|
|
|
|
|
--
|
|
|
|
|
ALTER TABLE `ams_api_keys`
|
|
|
|
|
ADD CONSTRAINT `ams_api_keys_ibfk_1` FOREIGN KEY (`User`) REFERENCES `ryzom_ams`.`ams_user` (`Login`);";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$dbl -> executeWithoutParams( $sql );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Hook to store data to database which is sent as post
|
|
|
|
|
* Hook to store data to database which is sent as post
|
|
|
|
|
* method from the forms in this plugin
|
|
|
|
|
* It also calls the local hook
|
|
|
|
|
*/
|
|
|
|
@ -121,63 +121,63 @@ function api_key_management_hook_store_db()
|
|
|
|
|
{
|
|
|
|
|
global $var_set;
|
|
|
|
|
global $return_set;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if the form been submited move forward
|
|
|
|
|
if ( @hook_validate( $_POST['gen_key'] ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// local hook to validate the POST variables
|
|
|
|
|
hook_variables();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if validation successfull move forward
|
|
|
|
|
if ( $return_set['gen_key_validate'] == 'true' && $_GET['plugin_action'] == 'generate_key' )
|
|
|
|
|
{
|
|
|
|
|
// this part generated the access token
|
|
|
|
|
include 'generate_key.php';
|
|
|
|
|
$var_set['AccessToken'] = generate_key :: randomToken( 56, false, true, false );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// database connection
|
|
|
|
|
$db = new DBLayer( 'lib' );
|
|
|
|
|
// insert the form data to the database
|
|
|
|
|
$db -> insert( 'ams_api_keys', $var_set );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// redirect to the the main page with success code
|
|
|
|
|
// 1 refers to the successfull addition of key to the database
|
|
|
|
|
header( "Location: index.php?page=layout_plugin&&name=API_key_management&&success=1" );
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
throw new SystemExit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Global Hook to load the data from db and set it
|
|
|
|
|
* Global Hook to load the data from db and set it
|
|
|
|
|
* into the global array to return it to the template
|
|
|
|
|
*/
|
|
|
|
|
function api_key_management_hook_load_db()
|
|
|
|
|
{
|
|
|
|
|
global $var_set;
|
|
|
|
|
global $return_set;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$db = new DBLayer( 'lib' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( isset( $_SESSION['user'] ) )
|
|
|
|
|
{
|
|
|
|
|
// returns the registered keys
|
|
|
|
|
$sth = $db -> select( 'ams_api_keys', array( 'user' => $_SESSION['user'] ), 'User = :user' );
|
|
|
|
|
$row = $sth -> fetchAll();
|
|
|
|
|
$return_set['api_keys'] = $row;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fetch the character from the array to compare
|
|
|
|
|
$com = array_column( $return_set['api_keys'], 'UserCharacter' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// returns the characters with respect to the user id in the ring_tool->characters
|
|
|
|
|
$db = new DBLayer( 'ring' );
|
|
|
|
|
$sth = $db -> selectWithParameter( 'char_name', 'characters' , array(), '1' );
|
|
|
|
|
$row = $sth -> fetch();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// loop through the character list and remove the character if already have an api key
|
|
|
|
|
$return_set['characters'] = array_diff( $row, $com );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Global Hook to update or delete the data from db
|
|
|
|
@ -186,24 +186,24 @@ function api_key_management_hook_update_db()
|
|
|
|
|
{
|
|
|
|
|
global $var_set;
|
|
|
|
|
global $return_set;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$db = new DBLayer( 'lib' );
|
|
|
|
|
if ( isset( $_GET['delete_id'] ) )
|
|
|
|
|
{
|
|
|
|
|
// removes the registered key using get variable which contains the id of the registered key
|
|
|
|
|
$db -> delete( 'ams_api_keys', array( 'SNo' => $_GET['delete_id'] ), 'SNo = :SNo' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// redirecting to the API_key_management plugins template with success code
|
|
|
|
|
// 2 refers to the succssfull delete condition
|
|
|
|
|
header( "Location: index.php?page=layout_plugin&&name=API_key_management&&success=2" );
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
throw new SystemExit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Global Hook to return global variables which contains
|
|
|
|
|
* the content to use in the smarty templates
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @return $return_set global array returns the template data
|
|
|
|
|
*/
|
|
|
|
|
function api_key_management_hook_return_global()
|
|
|
|
|