Skip to content

Commit

Permalink
Merge v1.2.0: Published on WP.org; Added Config GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
lsthompson authored Mar 31, 2023
2 parents a5f6864 + c077102 commit 72d5804
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 106 deletions.
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 🐆 TNC Toolbox for WP (inc. NGINX Cache actions)

https://wordpress.org/plugins/tnc-toolbox

### What the WordPress Plugin does:

- Allows you to purge the EA-NGINX User Cache from within WordPress
Expand All @@ -9,36 +11,33 @@

### System Requirements for the plugin:

- ~/.tnc/cp-api-key file must contain a cPanel API Token (on its own)
- Hosting Environment must be cPanel+WHM, running NGINX + Apache stack
- cPanel API Key, cPanel Username & Server Hostname needed in Settings
- Hosting Environment must be cPanel+WHM, running NGINX + Apache stack!
- Bash script needs: WP-in-functional-CageFS; shell->on for each cP user

Note: EA-NGINX (Reverse Proxy) by cPanel is supported, not "old school" implementations.

### Installing the Plugin (within WordPress CMS):

1. Download the latest version of the TNC WP Toolbox
2. Extract the repository on your computer/server
3. ZIP the tnc-toolbox/ directory **on its own**
4. WP-Admin > Plugins > Add New > Upload ZIP
1. Head to WP-Admin > Plugins, search for "TNC Toolbox"
2. Click "Install" for the resulting plugin (this one)
3. Once installed, click "Activate" to make it live
4. Done! Head to Settings > TNC Toolbox for config
5. Configure your API Key, Username & Hostname

Server-side: Use the bash script (read it firstly) to deploy the plugin server-wide!

As always, restrict it suitably - add a WP-present check, etc - and run at your own risk.

### Configuring the API Key/s site- or server-wide:

- For single-site usage, create ~/.tnc/ and ~/.tnc/cp-api-key
- Create a cPanel API Token and place it (nothing else) in that file
- ROOT: prep-users-and-install-tnc-wp.sh to prep and install for all sites
- ROOT: Make sure you amend the "wp" URL as described in the script, to grab ZIP
### Using the script to prepare your sites server-wide:

https://docs.cpanel.net/knowledge-base/security/how-to-use-cpanel-api-tokens/#create-an-api-token
- Please note, the script requires amendments before it will work reliably again (code changes)
- Target is to complete this within April 2023; its pre-reqs will remain the same (CageFS & so on)

### Feature Requests, Improvements, Bug Reports, etc:

Please raise an Issue on the GitHub Repository! Include all info, screenshots, etc, to help our crew.

https://github.com/LEOPARD-host/TNC-WP-Toolbox/issues
https://github.com/LEOPARD-host/WordPress-Toolbox-by-TNC/issues

**The Network Crew Pty Ltd (TNC)**
6 changes: 5 additions & 1 deletion prep-users-and-install-tnc-wp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@ do
uapi --output=jsonpretty --user=${user} Tokens create_full_access name='TNC-WP-TOOLBOX' | jq -r '.result.data.token' > /home/${user}/.tnc/cp-api-key
chown ${user}:${user} -R /home/${user}/.tnc/
chmod 0600 /home/${user}/.tnc/cp-api-key
su - ${user} -c "cd public_html && wp plugin install https://insert.your.domain.here/plugin-only-zip-file.zip --activate"
su - ${user} -c "cd public_html && wp plugin install tnc-toolbox --activate"
done

# Musings pre-dev: /var/cpanel/users/$user should be referenced for homedir path, removing fixed /home/
# Same goes for API Key generation & cPanel Username. Then reference nix for hostname check into file.
# This needs to be completed post-activation so the files are present. Add chmod 600 as bypass plugin.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions tnc-toolbox/config/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php //Silence is golden
Empty file.
6 changes: 3 additions & 3 deletions tnc-toolbox/core/class-tnc-wp-toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ final class Tnc_Wp_Toolbox {
* @return void
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'You are not allowed to clone this class.', 'tnc-wp-toolbox' ), '1.0.0' );
_doing_it_wrong( __FUNCTION__, __( 'You are not allowed to clone this class.', 'tnc-toolbox' ), '1.0.0' );
}

/**
Expand All @@ -78,7 +78,7 @@ public function __clone() {
* @return void
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'You are not allowed to unserialize this class.', 'tnc-wp-toolbox' ), '1.0.0' );
_doing_it_wrong( __FUNCTION__, __( 'You are not allowed to unserialize this class.', 'tnc-toolbox' ), '1.0.0' );
}

/**
Expand Down Expand Up @@ -145,7 +145,7 @@ private function base_hooks() {
* @return void
*/
public function load_textdomain() {
load_plugin_textdomain( 'tnc-wp-toolbox', FALSE, dirname( plugin_basename( TNCWPTBOX_PLUGIN_FILE ) ) . '/languages/' );
load_plugin_textdomain( 'tnc-toolbox', FALSE, dirname( plugin_basename( TNCWPTBOX_PLUGIN_FILE ) ) . '/languages/' );
}

}
Expand Down
89 changes: 62 additions & 27 deletions tnc-toolbox/core/includes/classes/class-tnc-wp-toolbox-run.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function tnc_wp_toolbox_nginx_action_success_notice() {
*/
public function add_plugin_action_link( $links ) {

$links['our_shop'] = sprintf( '<a href="%s" title="my.LEOPARD" style="font-weight:700;">%s</a>', 'https://my.leopard.host', __( 'my.LEOPARD', 'tnc-wp-toolbox' ) );
$links['our_shop'] = sprintf( '<a href="%s" title="my.LEOPARD" style="font-weight:700;">%s</a>', 'https://my.leopard.host', __( 'my.LEOPARD', 'tnc-toolbox' ) );

return $links;
}
Expand Down Expand Up @@ -179,18 +179,30 @@ public function add_cache_on_button( $wp_admin_bar ) {
* @return Success/Failure
*/
function nginx_cache_purge() {
// Get the cPanel username
$cpanel_username = get_current_user();
// Get the API token, exit if not present
if( is_readable("/home/".$cpanel_username."/.tnc/cp-api-key") ) {
$api_token = file_get_contents("/home/".$cpanel_username."/.tnc/cp-api-key");
// Get the cPanel Username, exit if not present
if( is_readable( TNCWPTBOX_PLUGIN_DIR . 'config/cpanel-username' ) ) {
$cpanel_username = file_get_contents( TNCWPTBOX_PLUGIN_DIR . 'config/cpanel-username' );
} else {
set_transient( 'tnc_wp_toolbox_nginx_action_error', 'cPanel API Token could not be read - please set it in /home/USER/.tnc/cp-api-key');
set_transient( 'tnc_wp_toolbox_nginx_action_error', 'cPanel Username could not be read - please configure it in Settings');
wp_safe_redirect(admin_url());
exit;
}
// Get the API Token, exit if not present
if( is_readable( TNCWPTBOX_PLUGIN_DIR . 'config/cpanel-api-key' ) ) {
$api_token = file_get_contents( TNCWPTBOX_PLUGIN_DIR . 'config/cpanel-api-key' );
} else {
set_transient( 'tnc_wp_toolbox_nginx_action_error', 'cPanel API Token could not be read - please configure it in Settings');
wp_safe_redirect(admin_url());
exit;
}
// Get the hostname, exit is not present
if( is_readable( TNCWPTBOX_PLUGIN_DIR . 'config/server-hostname' ) ) {
$server_hostname = file_get_contents( TNCWPTBOX_PLUGIN_DIR . 'config/server-hostname' );
} else {
set_transient( 'tnc_wp_toolbox_nginx_action_error', 'Server Hostname could not be read - please configure it in Settings');
wp_safe_redirect(admin_url());
exit;
}
// Get the server hostname
$server_hostname = gethostname();
// Build the headers for the request
$headers = array(
'Authorization' => 'cpanel '. $cpanel_username . ':' . $api_token,
Expand Down Expand Up @@ -235,18 +247,30 @@ function nginx_cache_purge() {
* @return Success/Failure
*/
function nginx_cache_off() {
// Get the cPanel username
$cpanel_username = get_current_user();
// Get the API token, exit if not present
if( is_readable("/home/".$cpanel_username."/.tnc/cp-api-key") ) {
$api_token = file_get_contents("/home/".$cpanel_username."/.tnc/cp-api-key");
// Get the cPanel Username, exit if not present
if( is_readable( TNCWPTBOX_PLUGIN_DIR . 'config/cpanel-username' ) ) {
$cpanel_username = file_get_contents( TNCWPTBOX_PLUGIN_DIR . 'config/cpanel-username' );
} else {
set_transient( 'tnc_wp_toolbox_nginx_action_error', 'cPanel Username could not be read - please configure it in Settings');
wp_safe_redirect(admin_url());
exit;
}
// Get the API Token, exit if not present
if( is_readable( TNCWPTBOX_PLUGIN_DIR . 'config/cpanel-api-key' ) ) {
$api_token = file_get_contents( TNCWPTBOX_PLUGIN_DIR . 'config/cpanel-api-key' );
} else {
set_transient( 'tnc_wp_toolbox_nginx_action_error', 'cPanel API Token could not be read - please set it in /home/USER/.tnc/cp-api-key');
set_transient( 'tnc_wp_toolbox_nginx_action_error', 'cPanel API Token could not be read - please configure it in Settings');
wp_safe_redirect(admin_url());
exit;
}
// Get the hostname, exit is not present
if( is_readable( TNCWPTBOX_PLUGIN_DIR . 'config/server-hostname' ) ) {
$server_hostname = file_get_contents( TNCWPTBOX_PLUGIN_DIR . 'config/server-hostname' );
} else {
set_transient( 'tnc_wp_toolbox_nginx_action_error', 'Server Hostname could not be read - please configure it in Settings');
wp_safe_redirect(admin_url());
exit;
}
// Get the server hostname
$server_hostname = gethostname();
// Build the headers for the request
$headers = array(
'Authorization' => 'cpanel '. $cpanel_username . ':' . $api_token,
Expand Down Expand Up @@ -290,18 +314,30 @@ function nginx_cache_off() {
* @return Success/Failure
*/
function nginx_cache_on() {
// Get the cPanel username
$cpanel_username = get_current_user();
// Get the API token, exit if not present
if( is_readable("/home/".$cpanel_username."/.tnc/cp-api-key") ) {
$api_token = file_get_contents("/home/".$cpanel_username."/.tnc/cp-api-key");
// Get the cPanel Username, exit if not present
if( is_readable( TNCWPTBOX_PLUGIN_DIR . 'config/cpanel-username' ) ) {
$cpanel_username = file_get_contents( TNCWPTBOX_PLUGIN_DIR . 'config/cpanel-username' );
} else {
set_transient( 'tnc_wp_toolbox_nginx_action_error', 'cPanel Username could not be read - please configure it in Settings');
wp_safe_redirect(admin_url());
exit;
}
// Get the API Token, exit if not present
if( is_readable( TNCWPTBOX_PLUGIN_DIR . 'config/cpanel-api-key' ) ) {
$api_token = file_get_contents( TNCWPTBOX_PLUGIN_DIR . 'config/cpanel-api-key' );
} else {
set_transient( 'tnc_wp_toolbox_nginx_action_error', 'cPanel API Token could not be read - please configure it in Settings');
wp_safe_redirect(admin_url());
exit;
}
// Get the hostname, exit is not present
if( is_readable( TNCWPTBOX_PLUGIN_DIR . 'config/server-hostname' ) ) {
$server_hostname = file_get_contents( TNCWPTBOX_PLUGIN_DIR . 'config/server-hostname' );
} else {
set_transient( 'tnc_wp_toolbox_nginx_action_error', 'cPanel API Token could not be read - please set it in /home/USER/.tnc/cp-api-key');
set_transient( 'tnc_wp_toolbox_nginx_action_error', 'Server Hostname could not be read - please configure it in Settings');
wp_safe_redirect(admin_url());
exit;
}
// Get the server hostname
$server_hostname = gethostname();
// Build the headers for the request
$headers = array(
'Authorization' => 'cpanel '. $cpanel_username . ':' . $api_token,
Expand Down Expand Up @@ -335,5 +371,4 @@ function nginx_cache_on() {
exit;
}
}

}
}
Loading

0 comments on commit 72d5804

Please sign in to comment.