Changeset 3386274
- Timestamp:
- 10/29/2025 08:53:13 AM (5 months ago)
- Location:
- sitesignal/trunk
- Files:
-
- 6 edited
-
admin/partials/dreamcore-monitor-admin-settings.php (modified) (1 diff)
-
includes/admin/class-dreamcore-monitor-admin.php (modified) (6 diffs)
-
includes/class-dreamcore-monitor-activator.php (modified) (3 diffs)
-
includes/class-dreamcore-monitor-integrity.php (modified) (3 diffs)
-
includes/class-dreamcore-monitor.php (modified) (2 diffs)
-
wp-site-monitor.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
sitesignal/trunk/admin/partials/dreamcore-monitor-admin-settings.php
r3386234 r3386274 217 217 </tr> 218 218 219 <tr> 220 221 <th scope="row"> 222 223 <label for="dreamcore_monitor_enable_useragent_tracking"><?php esc_html_e( 'Enable User Agent Tracking', 'sitesignal' ); ?></label> 224 225 </th> 226 227 <td> 228 229 <label> 230 231 <input type="checkbox" 232 233 name="dreamcore_monitor_enable_useragent_tracking" 234 235 id="dreamcore_monitor_enable_useragent_tracking" 236 237 value="1" 238 239 <?php checked( absint( get_option( 'dreamcore_monitor_enable_useragent_tracking', 1 ) ), 1 ); ?> /> 240 241 <?php esc_html_e( 'Track user agents (browsers, bots, crawlers) visiting your site', 'sitesignal' ); ?> 242 243 </label> 244 245 <p class="description"> 246 247 <?php esc_html_e( 'This tracks all visitors including browsers, AI bots, search engine bots, and crawlers.', 'sitesignal' ); ?> 248 249 </p> 250 251 </td> 252 253 </tr> 254 219 255 </table> 220 256 -
sitesignal/trunk/includes/admin/class-dreamcore-monitor-admin.php
r3386234 r3386274 67 67 'sitesignal_page_dreamcore-monitor-settings', 68 68 'sitesignal_page_dreamcore-monitor-security', 69 'sitesignal_page_dreamcore-monitor-about' 69 'sitesignal_page_dreamcore-monitor-about', 70 'sitesignal_page_dreamcore-monitor-useragents' 70 71 ); 71 72 … … 495 496 'sitesignal_page_dreamcore-monitor-settings', 496 497 'sitesignal_page_dreamcore-monitor-security', 497 'sitesignal_page_dreamcore-monitor-about' 498 'sitesignal_page_dreamcore-monitor-about', 499 'sitesignal_page_dreamcore-monitor-useragents' 498 500 ); 499 501 … … 562 564 ); 563 565 566 // User Agents submenu 567 add_submenu_page( 568 'sitesignal', 569 __( 'User Agents', 'sitesignal' ), 570 __( 'User Agents', 'sitesignal' ), 571 'manage_options', 572 'dreamcore-monitor-useragents', 573 array( $this, 'display_useragents' ) 574 ); 575 564 576 // API Settings submenu 565 577 add_submenu_page( … … 594 606 register_setting( 'dreamcore_monitor_settings', 'dreamcore_monitor_enable_api', array('sanitize_callback' => 'rest_sanitize_boolean') ); 595 607 register_setting( 'dreamcore_monitor_settings', 'dreamcore_monitor_enable_geolocation', array('sanitize_callback' => 'rest_sanitize_boolean') ); 608 register_setting( 'dreamcore_monitor_settings', 'dreamcore_monitor_enable_useragent_tracking', array('sanitize_callback' => 'rest_sanitize_boolean') ); 596 609 } 597 610 … … 649 662 650 663 /** 651 * Display the about page. 652 * 653 * @since 1.0.0 654 */ 664 * Display the user agents page. 665 * 666 * @since 1.0.0 667 */ 668 public function display_useragents() { 669 // Check user capabilities 670 if ( ! current_user_can( 'manage_options' ) ) { 671 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'sitesignal' ) ); 672 } 673 674 include_once DREAMCORE_MONITOR_PLUGIN_DIR . 'admin/partials/dreamcore-monitor-admin-useragents.php'; 675 } 676 677 /** 678 * Display the about page. 679 * 680 * @since 1.0.0 681 */ 655 682 public function display_about() { 656 683 // Check user capabilities … … 722 749 } else { 723 750 update_option( 'dreamcore_monitor_enable_geolocation', 0 ); 751 } 752 753 // Validate and sanitize enable user agent tracking 754 if ( isset( $_POST['dreamcore_monitor_enable_useragent_tracking'] ) ) { 755 $enable_useragent_tracking = absint( $_POST['dreamcore_monitor_enable_useragent_tracking'] ); 756 update_option( 'dreamcore_monitor_enable_useragent_tracking', $enable_useragent_tracking ); 757 } else { 758 update_option( 'dreamcore_monitor_enable_useragent_tracking', 0 ); 724 759 } 725 760 } -
sitesignal/trunk/includes/class-dreamcore-monitor-activator.php
r3386234 r3386274 32 32 // Create the login tracking table 33 33 self::create_login_table(); 34 35 // Create the user agents tracking table 36 self::create_useragents_table(); 34 37 35 38 // Generate site ID if not exists … … 120 123 121 124 /** 125 * Create the user agents tracking table. 126 * 127 * @since 1.0.0 128 * @access private 129 */ 130 private static function create_useragents_table() { 131 global $wpdb; 132 133 $charset_collate = $wpdb->get_charset_collate(); 134 $table_name = $wpdb->prefix . 'dreamcore_monitor_useragents'; 135 136 $sql = "CREATE TABLE {$wpdb->prefix}dreamcore_monitor_useragents ( 137 id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, 138 user_agent VARCHAR(500) NOT NULL, 139 ip_address VARCHAR(45) NOT NULL, 140 page_url VARCHAR(500) NOT NULL, 141 referer VARCHAR(500) NULL, 142 category VARCHAR(50) NOT NULL, 143 browser VARCHAR(100) NULL, 144 os VARCHAR(100) NULL, 145 device_type VARCHAR(50) NULL, 146 visited_at DATETIME DEFAULT CURRENT_TIMESTAMP, 147 INDEX idx_category (category), 148 INDEX idx_visited_at (visited_at), 149 INDEX idx_ip_address (ip_address), 150 INDEX idx_browser (browser), 151 INDEX idx_device_type (device_type) 152 ) {$charset_collate}"; 153 154 // Safe loading of upgrade.php with proper path handling 155 $upgrade_file = wp_normalize_path( ABSPATH . 'wp-admin/includes/upgrade.php' ); 156 if ( file_exists( $upgrade_file ) && is_readable( $upgrade_file ) ) { 157 $expected_admin_includes = wp_normalize_path( ABSPATH . 'wp-admin/includes' ); 158 if ( strpos( $upgrade_file, $expected_admin_includes ) === 0 ) { 159 require_once $upgrade_file; 160 } 161 } 162 163 if ( function_exists( 'dbDelta' ) ) { 164 dbDelta( $sql ); 165 } else { 166 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching 167 $result = $wpdb->query( $sql ); 168 if ( false === $result ) { 169 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { 170 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log 171 // error_log( 'Dreamcore Monitor: Failed to create user agents table - ' . $wpdb->last_error ); 172 } 173 } 174 } 175 } 176 177 /** 122 178 * Set default plugin options. 123 179 * … … 133 189 'dreamcore_monitor_enable_api' => 0, 134 190 'dreamcore_monitor_enable_geolocation' => 1, 191 'dreamcore_monitor_enable_useragent_tracking' => 1, 135 192 ); 136 193 -
sitesignal/trunk/includes/class-dreamcore-monitor-integrity.php
r3386234 r3386274 457 457 // Security check: Ensure path is within WordPress root 458 458 459 if ( ! str_starts_with( $full_path, $wp_root )) {459 if ( strpos( $full_path, $wp_root ) !== 0 ) { 460 460 461 461 return false; … … 643 643 return array_filter( array_keys( $checksums ), function ( $file ) { 644 644 645 return ! str_starts_with( $file, 'wp-content/themes/' )&&646 647 ! str_starts_with( $file, 'wp-content/plugins/' );645 return strpos( $file, 'wp-content/themes/' ) !== 0 && 646 647 strpos( $file, 'wp-content/plugins/' ) !== 0; 648 648 649 649 }); … … 681 681 return array_filter( array_keys( $data['checksums'] ), function ( $file ) { 682 682 683 return ! str_starts_with( $file, 'wp-content/themes/' )&&684 685 ! str_starts_with( $file, 'wp-content/plugins/' );683 return strpos( $file, 'wp-content/themes/' ) !== 0 && 684 685 strpos( $file, 'wp-content/plugins/' ) !== 0; 686 686 687 687 }); -
sitesignal/trunk/includes/class-dreamcore-monitor.php
r3386234 r3386274 329 329 $this->safe_require_file( 'includes/class-dreamcore-monitor-orders.php', false ); 330 330 331 $this->safe_require_file( 'includes/class-dreamcore-monitor-useragents.php', false ); 332 331 333 // Initialize loader if the class was successfully loaded 332 334 … … 463 465 } 464 466 467 if ( class_exists( 'Dreamcore_Monitor_UserAgents' ) ) { 468 469 $useragents_monitor = new Dreamcore_Monitor_UserAgents( $this->get_plugin_name(), $this->get_version() ); 470 471 $this->loader->add_action( 'wp', $useragents_monitor, 'track_page_visit' ); 472 473 $this->loader->add_action( 'rest_api_init', $useragents_monitor, 'register_rest_routes' ); 474 475 } 476 465 477 } 466 478 -
sitesignal/trunk/wp-site-monitor.php
r3386240 r3386274 11 11 * Domain Path: /languages 12 12 * Requires at least: 5.0 13 * Tested up to: 6. 813 * Tested up to: 6.7 14 14 * Requires PHP: 7.4 15 15 *
Note: See TracChangeset
for help on using the changeset viewer.