Plugin Directory

Changeset 3477266


Ignore:
Timestamp:
03/08/2026 04:52:42 AM (4 weeks ago)
Author:
zubbin
Message:

Update plugin to version 1.4.51

Location:
zubbin-uptime-node/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • zubbin-uptime-node/trunk/includes/admin.php

    r3472274 r3477266  
    2929    add_action("admin_post_zubbin_un_force_sync", [__CLASS__, "force_sync"]);
    3030    add_action("admin_post_zubbin_un_test_auth", [__CLASS__, "test_auth"]);
     31    add_action("admin_post_zubbin_un_repair_pairing", [__CLASS__, "repair_pairing"]);
    3132    add_action("admin_post_zubbin_un_clear_logs", [__CLASS__, "clear_logs"]);
    3233    add_action("admin_post_zubbin_un_start_checkout", [__CLASS__, "start_checkout"]);
     
    6263
    6364    $s = ZUBBIN_UN_Settings::get();
     65    $flash = get_transient('zubbin_un_flash_notice');
     66    if (is_array($flash) && !empty($flash['type']) && !empty($flash['message'])) {
     67      delete_transient('zubbin_un_flash_notice');
     68      self::notice((string)$flash['type'], (string)$flash['message']);
     69    }
    6470    // Tab selection is a read-only UI concern (no state change). Nonce is not required.
    6571    // phpcs:ignore WordPress.Security.NonceVerification.Recommended
     
    225231      echo '<input type="hidden" name="action" value="zubbin_un_test_auth">';
    226232      submit_button('Test Central Auth','secondary');
     233      echo '</form>';
     234      echo '<form method="post" action="'.esc_url(admin_url('admin-post.php')).'" style="margin-top:10px;">';
     235      wp_nonce_field('zubbin_un_repair_pairing');
     236      echo '<input type="hidden" name="action" value="zubbin_un_repair_pairing">';
     237      submit_button('Re-pair with Central','secondary', 'submit', false);
     238      echo '<p class="description">Use this if Central rotated your node secret and this site is using stale credentials.</p>';
    227239      echo '</form></div>';
    228240    }
     
    661673
    662674    $r = ZUBBIN_UN_Client::test_auth($s);
    663     if ((int)$r['http'] === 200) {
     675    $ok = ((int)($r['http'] ?? 0) === 200 && !empty($r['body']['ok']));
     676    $msg = $ok ? 'Central auth succeeded.' : ('Central auth failed: ' . ZUBBIN_UN_Client::summarize_response($r));
     677    ZUBBIN_UN_Settings::save(['last_http' => (int)($r['http'] ?? 0), 'last_error' => $ok ? '' : $msg]);
     678    set_transient('zubbin_un_flash_notice', ['type' => $ok ? 'success' : 'error', 'message' => $msg], 60);
     679    if (class_exists('ZUBBIN_UN_Logger')) {
     680      ZUBBIN_UN_Logger::info('test_auth', $ok ? 'Central auth succeeded' : 'Central auth failed', ['http' => (int)($r['http'] ?? 0), 'error' => (string)($r['body']['error'] ?? '')]);
     681    }
     682    wp_safe_redirect(admin_url('admin.php?page=zubbin_un&tab=dashboard'));
     683    exit;
     684  }
     685
     686  static function repair_pairing() {
     687    if (!current_user_can('manage_options')) wp_die('Forbidden');
     688    check_admin_referer('zubbin_un_repair_pairing');
     689
     690    $s = ZUBBIN_UN_Settings::get();
     691    $central_url = (string)($s['central_url'] ?? '');
     692    if ($central_url === '') {
     693      set_transient('zubbin_un_flash_notice', ['type' => 'error', 'message' => 'Central URL is missing.'], 60);
     694      wp_safe_redirect(admin_url('admin.php?page=zubbin_un&tab=onboarding'));
     695      exit;
     696    }
     697
     698    $r = ZUBBIN_UN_Client::auto_bootstrap($central_url);
     699    if ((int)($r['http'] ?? 0) === 200 && !empty($r['body']['ok']) && !empty($r['body']['node_key']) && !empty($r['body']['node_secret'])) {
     700      ZUBBIN_UN_Settings::save([
     701        'node_key' => (string)$r['body']['node_key'],
     702        'node_secret' => (string)$r['body']['node_secret'],
     703        'last_error' => '',
     704        'last_http' => (int)($r['http'] ?? 0),
     705      ]);
     706      $s2 = ZUBBIN_UN_Settings::get();
     707      $sr = ZUBBIN_UN_Client::sync($s2);
     708      $sync_msg = ((int)($sr['http'] ?? 0) === 200 && !empty($sr['body']['ok'])) ? ' Central sync succeeded.' : (' Central sync result: ' . ZUBBIN_UN_Client::summarize_response($sr));
     709      set_transient('zubbin_un_flash_notice', ['type' => 'success', 'message' => 'Node credentials refreshed from Central.' . $sync_msg], 60);
     710      if (class_exists('ZUBBIN_UN_Logger')) {
     711        ZUBBIN_UN_Logger::info('repair_pairing', 'Node re-paired with Central', ['http' => (int)($r['http'] ?? 0), 'mode' => (string)($r['body']['mode'] ?? '')]);
     712      }
    664713      wp_safe_redirect(admin_url('admin.php?page=zubbin_un&tab=dashboard'));
    665714      exit;
    666715    }
    667716
     717    $msg = 'Re-pair failed: ' . ZUBBIN_UN_Client::summarize_response($r);
     718    ZUBBIN_UN_Settings::save(['last_error' => $msg, 'last_http' => (int)($r['http'] ?? 0)]);
     719    set_transient('zubbin_un_flash_notice', ['type' => 'error', 'message' => $msg], 60);
     720    if (class_exists('ZUBBIN_UN_Logger')) {
     721      ZUBBIN_UN_Logger::warn('repair_pairing', 'Node re-pair failed', ['http' => (int)($r['http'] ?? 0), 'error' => (string)($r['body']['error'] ?? '')]);
     722    }
     723    wp_safe_redirect(admin_url('admin.php?page=zubbin_un&tab=dashboard'));
     724    exit;
    668725  }
    669726
  • zubbin-uptime-node/trunk/includes/client.php

    r3472274 r3477266  
    5555  }
    5656
     57
     58
     59
     60  static function summarize_response($r) {
     61    $http = (int)($r['http'] ?? 0);
     62    $body = is_array($r['body'] ?? null) ? $r['body'] : [];
     63    $error = (string)($body['error'] ?? '');
     64    $message = (string)($body['message'] ?? '');
     65    $raw = (string)($body['raw'] ?? '');
     66
     67    $parts = [];
     68    if ($error !== '') $parts[] = $error;
     69    if ($message !== '' && $message !== $error) {
     70      $parts[] = $message;
     71    } elseif ($message === '' && $raw !== '') {
     72      $parts[] = $raw;
     73    }
     74
     75    $out = trim(implode(': ', array_filter($parts, function($v){ return $v !== ''; })));
     76    if ($out === '') {
     77      $out = $http > 0 ? ('http_' . $http) : 'request_failed';
     78    }
     79
     80    if (!empty($body['attempted_urls']) && is_array($body['attempted_urls'])) {
     81      $urls = implode(' | ', array_map('esc_url_raw', $body['attempted_urls']));
     82      if ($urls !== '') $out .= ' | attempted: ' . $urls;
     83    }
     84
     85    return $out;
     86  }
    5787
    5888  static function post_json_fallback($central_url, $route, $body=[], $headers=[], $timeout=20) {
  • zubbin-uptime-node/trunk/includes/cron.php

    r3458420 r3477266  
    107107      'last_message' => (string)$check['msg'],
    108108      'last_http' => (int)$hb['http'],
    109       'last_error' => (string)($hb['body']['error'] ?? ''),
     109      'last_error' => ZUBBIN_UN_Client::summarize_response($hb),
    110110    ];
    111111
  • zubbin-uptime-node/trunk/readme.txt

    r3472274 r3477266  
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 1.4.50
     7Stable tag: 1.4.51
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • zubbin-uptime-node/trunk/zubbin-uptime-node.php

    r3472274 r3477266  
    33 * Plugin Name: Z UpTime – Uptime Monitoring Node
    44 * Description: Lightweight WordPress uptime monitoring node that reports heartbeat and health to a Central dashboard. Alerts are handled by Central.
    5  * Version: 1.4.50
     5 * Version: 1.4.51
    66 * Author: Zubbin
    77 * Text Domain: zubbin-uptime-node
     
    1313if (!defined('ABSPATH')) exit;
    1414
    15 define('ZUBBIN_UN_VERSION', '1.4.48');
     15define('ZUBBIN_UN_VERSION', '1.4.51');
    1616
    1717// Default Central URL for client installs (override in wp-config.php if needed)
     
    3939add_action('admin_post_zubbin_un_force_sync', ['ZUBBIN_UN_Admin','force_sync']);;
    4040add_action('admin_post_zubbin_un_test_auth', ['ZUBBIN_UN_Admin','test_auth']);
     41add_action('admin_post_zubbin_un_repair_pairing', ['ZUBBIN_UN_Admin','repair_pairing']);
    4142add_action('admin_post_zubbin_un_clear_logs', ['ZUBBIN_UN_Admin','clear_logs']);
    4243
Note: See TracChangeset for help on using the changeset viewer.