| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: WP Cassify |
| 5 |
* Plugin URI: https://wpcassify.wordpress.com/ |
| 6 |
* Description: CAS Authentication Client for Wordpress. Also, it handle custom authorizations rules from cas user attributes. |
| 7 |
* Version: 2.4.5 |
| 8 |
* Requires PHP: 7.0 |
| 9 |
* Author: Alain-Aymerick FRANCOIS |
| 10 |
* Author URI: https://wpcassify.wordpress.com/about-me/ |
| 11 |
* License: GPLv2 |
| 12 |
*/ |
| 13 |
|
| 14 |
defined( 'ABSPATH' ) || exit; |
| 15 |
|
| 16 |
/** |
| 17 |
* Current plugin version. Used for option migration tracking. |
| 18 |
*/ |
| 19 |
define( 'WP_CASSIFY_VERSION', '2.4.5' ); |
| 20 |
|
| 21 |
if (! function_exists( 'get_plugin_data' ) ) { |
| 22 |
require_once ABSPATH . '/wp-admin/includes/plugin.php'; |
| 23 |
} |
| 24 |
|
| 25 |
$wp_cassify_plugin_datas = get_plugin_data( __FILE__, false, false); |
| 26 |
$wp_cassify_plugin_directory = plugin_dir_url( __FILE__ ); |
| 27 |
$wp_cassify_network_activated = false; |
| 28 |
|
| 29 |
include( plugin_dir_path( __FILE__ ) . 'config.php' ); |
| 30 |
include( plugin_dir_path( __FILE__ ) . 'classes/wp_cassify_utils.php' ); |
| 31 |
include( plugin_dir_path( __FILE__ ) . 'classes/wp_cassify_rule_solver.php' ); |
| 32 |
include( plugin_dir_path( __FILE__ ) . 'classes/wp_cassify_plugin.php' ); |
| 33 |
include( plugin_dir_path( __FILE__ ) . 'classes/wp_cassify_shortcodes.php' ); |
| 34 |
|
| 35 |
include( plugin_dir_path( __FILE__ ) . 'admin/admin-menu.php' ); |
| 36 |
|
| 37 |
global $wpdb; |
| 38 |
|
| 39 |
|
| 40 |
/** |
| 41 |
* Uninstall script of the plugin |
| 42 |
*/ |
| 43 |
register_deactivation_hook( __FILE__, 'wp_cassify_deactivation' ); |
| 44 |
register_uninstall_hook( __FILE__, 'wp_cassify_uninstall' ); |
| 45 |
|
| 46 |
function wp_cassify_deactivation() { |
| 47 |
// Nothing here. |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Runs option migration tasks when the plugin version changes. |
| 52 |
* |
| 53 |
* Called on 'plugins_loaded' to handle silent upgrades (i.e. updates made |
| 54 |
* through the WordPress update mechanism without manual deactivation/reactivation). |
| 55 |
* |
| 56 |
* Migration added in 2.4.1: |
| 57 |
* In 2.4.0, the default value of wp_cassify_enable_url_bypass was changed from |
| 58 |
* 'enabled' to 'disabled'. Users who had never explicitly saved this option relied |
| 59 |
* on the old default being 'enabled'. If we detect a pre-2.4.1 upgrade on an |
| 60 |
* already-configured site (i.e. wp_cassify_base_url is set), we write 'enabled' |
| 61 |
* explicitly so their access is not silently broken. |
| 62 |
* Fresh installs of 2.4.1 (wp_cassify_base_url is empty) are not affected and |
| 63 |
* correctly start with the 'disabled' default. |
| 64 |
*/ |
| 65 |
function wp_cassify_maybe_migrate_options() { |
| 66 |
global $wp_cassify_network_activated; |
| 67 |
|
| 68 |
$stored_version = $wp_cassify_network_activated |
| 69 |
? get_site_option( 'wp_cassify_plugin_version', '' ) |
| 70 |
: get_option( 'wp_cassify_plugin_version', '' ); |
| 71 |
|
| 72 |
// Nothing to do when already on the current version. |
| 73 |
if ( $stored_version === WP_CASSIFY_VERSION ) { |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
// --- Migration: any version prior to 2.4.1 --- |
| 78 |
// In 2.4.0, wp_cassify_enable_url_bypass was changed to default to 'disabled'. |
| 79 |
// Restore 'enabled' for existing sites that never explicitly configured this option. |
| 80 |
if ( version_compare( $stored_version, '2.4.1', '<' ) ) { |
| 81 |
$existing_bypass = $wp_cassify_network_activated |
| 82 |
? get_site_option( 'wp_cassify_enable_url_bypass', '' ) |
| 83 |
: get_option( 'wp_cassify_enable_url_bypass', '' ); |
| 84 |
|
| 85 |
$existing_base_url = $wp_cassify_network_activated |
| 86 |
? get_site_option( 'wp_cassify_base_url', '' ) |
| 87 |
: get_option( 'wp_cassify_base_url', '' ); |
| 88 |
|
| 89 |
// Only migrate when the option was never explicitly saved AND the plugin |
| 90 |
// was already configured (base URL set), meaning this is a real upgrade, |
| 91 |
// not a brand-new installation. |
| 92 |
if ( ( $existing_bypass === '' || $existing_bypass === false ) && ! empty( $existing_base_url ) ) { |
| 93 |
\wp_cassify\WP_Cassify_Utils::wp_cassify_update_option( |
| 94 |
$wp_cassify_network_activated, |
| 95 |
'wp_cassify_enable_url_bypass', |
| 96 |
'enabled' |
| 97 |
); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
// Persist the current plugin version so this migration only runs once. |
| 102 |
if ( $wp_cassify_network_activated ) { |
| 103 |
update_site_option( 'wp_cassify_plugin_version', WP_CASSIFY_VERSION ); |
| 104 |
} else { |
| 105 |
update_option( 'wp_cassify_plugin_version', WP_CASSIFY_VERSION ); |
| 106 |
} |
| 107 |
} |
| 108 |
add_action( 'plugins_loaded', 'wp_cassify_maybe_migrate_options' ); |
| 109 |
|
| 110 |
function wp_cassify_uninstall() { |
| 111 |
|
| 112 |
global $wpdb; |
| 113 |
$option_prefix_like = 'wp_cassify%'; |
| 114 |
|
| 115 |
// Delete network activated options |
| 116 |
$network_meta_table = $wpdb->base_prefix . 'sitemeta'; |
| 117 |
if ( preg_match( '/^[A-Za-z0-9_]+$/', $network_meta_table ) === 1 ) { |
| 118 |
$network_table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $network_meta_table ) ); |
| 119 |
|
| 120 |
if ( $network_table_exists === $network_meta_table ) { |
| 121 |
$wpdb->query( $wpdb->prepare( "DELETE FROM `{$network_meta_table}` WHERE `meta_key` LIKE %s", $option_prefix_like ) ); |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
// Delete blog options |
| 126 |
$blogs = get_sites(); |
| 127 |
|
| 128 |
for( $i = 0; $i <= count( $blogs ) - 1; $i++ ) { |
| 129 |
// 1 is network |
| 130 |
if ( $blogs[ $i ]->blog_id > 1 ) { |
| 131 |
$blog_id = absint( $blogs[ $i ]->blog_id ); |
| 132 |
$_tbl_name = $wpdb->base_prefix . $blog_id . '_options'; |
| 133 |
|
| 134 |
if ( preg_match( '/^[A-Za-z0-9_]+$/', $_tbl_name ) === 1 ) { |
| 135 |
$blog_table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $_tbl_name ) ); |
| 136 |
|
| 137 |
if ( $blog_table_exists === $_tbl_name ) { |
| 138 |
$wpdb->query( $wpdb->prepare( "DELETE FROM `{$_tbl_name}` WHERE `option_name` LIKE %s", $option_prefix_like ) ); |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* Test if plugin is network activated. |
| 147 |
* |
| 148 |
*/ |
| 149 |
if ( ! function_exists( 'is_plugin_active_for_network' ) ) { |
| 150 |
require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); |
| 151 |
} |
| 152 |
|
| 153 |
if ( is_plugin_active_for_network( 'wp-cassify/wp-cassify.php' ) ) { |
| 154 |
$wp_cassify_network_activated = true; |
| 155 |
} |
| 156 |
|
| 157 |
$wp_cassify_admin_page = new \wp_cassify\WP_Cassify_Admin_Page(); |
| 158 |
$wp_cassify_admin_page->init_parameters( |
| 159 |
$wp_cassify_plugin_datas, |
| 160 |
$wp_cassify_plugin_directory, |
| 161 |
$wp_cassify_network_activated, |
| 162 |
$wp_cassify_plugin_options_list, |
| 163 |
$wp_cassify_default_protocol_version_values, |
| 164 |
$wp_cassify_default_login_servlet, |
| 165 |
$wp_cassify_default_logout_servlet, |
| 166 |
$wp_cassify_default_service_validate_servlet, |
| 167 |
$wp_cassify_default_ssl_cipher_values, |
| 168 |
$wp_cassify_default_ssl_check_certificate, |
| 169 |
$wp_cassify_default_xpath_query_to_extact_cas_user, |
| 170 |
$wp_cassify_default_xpath_query_to_extact_cas_attributes, |
| 171 |
$wp_cassify_default_notifications_options, |
| 172 |
$wp_cassify_default_expirations_options, |
| 173 |
$wp_cassify_default_allow_deny_order, |
| 174 |
$wp_cassify_wordpress_user_meta_list |
| 175 |
); |
| 176 |
|
| 177 |
$GLOBALS['wp-cassify'] = new \wp_cassify\WP_Cassify_Plugin(); |
| 178 |
$GLOBALS['wp-cassify']->init_parameters( |
| 179 |
$wp_cassify_network_activated, |
| 180 |
$wp_cassify_default_xpath_query_to_extact_cas_user, |
| 181 |
$wp_cassify_default_xpath_query_to_extact_cas_attributes, |
| 182 |
$wp_cassify_default_redirect_parameter_name, |
| 183 |
$wp_cassify_default_service_ticket_parameter_name, |
| 184 |
$wp_cassify_default_service_service_parameter_name, |
| 185 |
$wp_cassify_default_gateway_parameter_name, |
| 186 |
$wp_cassify_default_bypass_parameter_name, |
| 187 |
$wp_cassify_default_cachetimes_for_authrecheck, |
| 188 |
$wp_cassify_default_wordpress_blog_http_port, |
| 189 |
$wp_cassify_default_wordpress_blog_https_port, |
| 190 |
$wp_cassify_default_ssl_check_certificate, |
| 191 |
$wp_cassify_default_login_servlet, |
| 192 |
$wp_cassify_default_logout_servlet, |
| 193 |
$wp_cassify_default_service_validate_servlet, |
| 194 |
$wp_cassify_default_notifications_options, |
| 195 |
$wp_cassify_default_allow_deny_order, |
| 196 |
$wp_cassify_match_first_level_parenthesis_group_pattern, |
| 197 |
$wp_cassify_match_second_level_parenthesis_group_pattern, |
| 198 |
$wp_cassify_match_cas_variable_pattern, |
| 199 |
$wp_cassify_allowed_operators, |
| 200 |
$wp_cassify_operator_prefix, |
| 201 |
$wp_cassify_allowed_parenthesis, |
| 202 |
$wp_cassify_allowed_get_parameters, |
| 203 |
$wp_cassify_error_messages, |
| 204 |
$wp_cassify_user_error_codes, |
| 205 |
$wp_cassify_service_ticket_salt, |
| 206 |
$wp_cassify_default_bypass_parameter_value, |
| 207 |
$wp_cassify_default_enable_url_bypass |
| 208 |
); |
| 209 |
|
| 210 |
$wp_cassify_shortcodes = new \wp_cassify\WP_Cassify_Shortcodes(); |
| 211 |
$wp_cassify_shortcodes->init_parameters( |
| 212 |
$wp_cassify_network_activated, |
| 213 |
$wp_cassify_default_redirect_parameter_name, |
| 214 |
$wp_cassify_default_service_service_parameter_name, |
| 215 |
$wp_cassify_default_wordpress_blog_http_port, |
| 216 |
$wp_cassify_default_wordpress_blog_https_port, |
| 217 |
$wp_cassify_default_login_servlet, |
| 218 |
$wp_cassify_default_logout_servlet |
| 219 |
); |
| 220 |
|
| 221 |
?> |
| 222 |
|