Skip to content

Commit

Permalink
[New] Reset IAPI key in case domain is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-hai committed Jan 5, 2018
1 parent ee379f4 commit c0df03c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
39 changes: 39 additions & 0 deletions litespeed-cache/admin/admin-api.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class LiteSpeed_Cache_Admin_API
const TYPE_NOTIFY_IMG = 'notify_img' ;
const TYPE_CHECK_IMG = 'check_img' ;
const TYPE_IMG_DESTROY_CALLBACK = 'imgoptm_destroy' ;
const TYPE_RESET_KEY = 'reset_key' ;

const IAPI_ACTION_REQUEST_KEY = 'request_key' ;
const IAPI_ACTION_MEDIA_SYNC_DATA = 'media_sync_data' ;
Expand All @@ -41,6 +42,30 @@ private function __construct()
$this->_iapi_key = get_option( self::DB_API_KEY ) ?: '' ;
}

/**
* Handle all request actions from main cls
*
* @since 1.7.2
* @access public
*/
public static function handler()
{
$instance = self::get_instance() ;

$type = LiteSpeed_Cache_Router::verify_type() ;

switch ( $type ) {
case self::TYPE_RESET_KEY :
$instance->_reset_key() ;
break ;

default:
break ;
}

LiteSpeed_Cache_Admin::redirect() ;
}

/**
* Handle aggressive callback requests from LiteSpeed image server
*
Expand Down Expand Up @@ -220,7 +245,21 @@ private function _request_key()
LiteSpeed_Cache_Log::debug( 'IAPI applied auth_key' ) ;

$this->_iapi_key = $json[ 'auth_key' ] ;
}

/**
* delete key
*
* @since 1.7.2
* @access private
*/
private function _reset_key()
{
delete_option( self::DB_API_KEY ) ;
LiteSpeed_Cache_Log::debug( 'IAPI delete auth_key' ) ;

$msg = __( 'Reset IAPI key successfully.', 'litespeed-cache' ) ;
LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions litespeed-cache/admin/tpl/image_optimization.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@
<?php echo __( 'Scan for any new unoptimized image thumbnail sizes and resend necessary image optimization requests.', 'litespeed-cache' ) ; ?>
</span>

<br />
<a href="<?php echo LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_IAPI, LiteSpeed_Cache_Admin_API::TYPE_RESET_KEY ) ; ?>" class="litespeed-btn-warning">
<?php echo __( 'Reset The IAPI Key', 'litespeed-cache' ) ; ?>
</a>
<span class="litespeed-desc">
<?php echo __( 'If the home URL or domain is changed, this action is needed to reset your current IAPI key before next request.', 'litespeed-cache' ) ; ?>
</span>

<br />
<a href="<?php echo LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_MEDIA, LiteSpeed_Cache_Media::TYPE_IMG_OPTIMIZE_DESTROY ) ; ?>" class="litespeed-btn-danger">
<?php echo __( 'Destroy All Optimization Data!', 'litespeed-cache' ) ; ?>
Expand Down
5 changes: 5 additions & 0 deletions litespeed-cache/inc/litespeed-cache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class LiteSpeed_Cache
const ACTION_LOG = 'log' ;

const ACTION_MEDIA = 'media' ;
const ACTION_IAPI = 'iapi' ;
const ACTION_CDN = 'cdn' ;
const ACTION_REPORT = 'report' ;
const ACTION_SAPI_PASSIVE_CALLBACK = 'sapi_passive_callback' ;
Expand Down Expand Up @@ -308,6 +309,10 @@ public function proceed_action( $action )
$msg = LiteSpeed_Cache_Media::handler() ;
break ;

case LiteSpeed_Cache::ACTION_IAPI:
$msg = LiteSpeed_Cache_Admin_API::handler() ;
break ;

case LiteSpeed_Cache::ACTION_CDN:
$msg = LiteSpeed_Cache_CDN::handler() ;
break ;
Expand Down
1 change: 1 addition & 0 deletions litespeed-cache/inc/router.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ private function verify_action()
case LiteSpeed_Cache::ACTION_DO_CRAWL:
case LiteSpeed_Cache::ACTION_BLACKLIST_SAVE:
case LiteSpeed_Cache::ACTION_MEDIA:
case LiteSpeed_Cache::ACTION_IAPI:
case LiteSpeed_Cache::ACTION_CDN:
if ( defined( 'LITESPEED_ON' ) && $_can_option && ! $_is_network_admin ) {
self::$_action = $action ;
Expand Down

0 comments on commit c0df03c

Please sign in to comment.