Plugin Directory

Changeset 2778568


Ignore:
Timestamp:
09/01/2022 05:33:37 AM (4 years ago)
Author:
crowdaa
Message:

Added tag 1.4.1

Location:
crowdaa-sync
Files:
7 edited
74 copied

Legend:

Unmodified
Added
Removed
  • crowdaa-sync/tags/1.4.1/CHANGELOG

    r2776976 r2778568  
    66
    77## [Unreleased]
     8
     9## [1.4.1] - 2022-09-01
     10
     11### Added
     12
     13- Plugin API key (not currently used, preparing it for 1.5.0)
    814
    915## [1.4.0] - 2022-08-29
  • crowdaa-sync/tags/1.4.1/README.txt

    r2776976 r2778568  
    66Requires PHP: 7.3
    77Tested up to: 5.9
    8 Stable tag: 1.4.0
     8Stable tag: 1.4.1
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • crowdaa-sync/tags/1.4.1/admin/class-crowdaa-sync-admin-display.php

    r2776976 r2778568  
    200200          update_option('crowdaa_user_id', $json->data->userId);
    201201          update_option('crowdaa_auth_token', $json->data->authToken);
     202          Crowdaa_Sync_Utils::generate_plugin_api_key();
    202203
    203204          add_action(
  • crowdaa-sync/tags/1.4.1/admin/js/crowdaa-sync-admin.js

    r2744975 r2778568  
    180180    $('#crowdaa-sync-categories-mode-whitelist-checkbox').on('change', updateSyncCategoriesSelect);
    181181    updateSyncCategoriesSelect();
     182
     183    let pluginApiKeyDisplayTimeout = null;
     184    $('#plugin_api_key').focus(function(e) {
     185      e.preventDefault();
     186
     187      $(e.target).select();
     188      document.execCommand("copy");
     189
     190      const $display = $('#plugin_api_key-copied');
     191      $display.text('Copied!');
     192
     193      if (pluginApiKeyDisplayTimeout !== null) clearTimeout(pluginApiKeyDisplayTimeout);
     194      pluginApiKeyDisplayTimeout = setTimeout(() => {
     195        $display.text('');
     196        pluginApiKeyDisplayTimeout = null;
     197      }, 3000);
     198    });
    182199
    183200    $('#crowdaa-reset-request').click(function(e) {
  • crowdaa-sync/tags/1.4.1/admin/partials/crowdaa-sync-admin-display.php

    r2776976 r2778568  
    2323
    2424  <h2><?php esc_html_e('Connect to Crowdaa', CROWDAA_SYNC_PLUGIN_NAME); ?></h2>
    25   <?php
     25  <form method="post" action="<?php $admin_utils->login(); ?>">
     26<?php
    2627  $api_url            = get_option('crowdaa_api_url');
    2728  $user_email         = get_option('crowdaa_user_email');
     
    3031  $user_api_key       = get_option('crowdaa_user_api_key');
    3132  $auth_token         = get_option('crowdaa_auth_token');
    32   ?>
    33   <form method="post" action="<?php $admin_utils->login(); ?>">
     33  $plugin_api_key     = Crowdaa_Sync_Utils::get_plugin_api_key();
     34?>
    3435    <div class="crowdaa-html-container">
    3536      <p>
     
    5253        <label class="text-label" for="user_password"><?php esc_html_e('Password', CROWDAA_SYNC_PLUGIN_NAME); ?></label>
    5354        <input type="password" required id="user_password" name="user_password" value="<?php echo esc_attr(($user_password && $auth_token) ? $user_password : ''); ?>"/>
     55      </p>
     56      <p>
     57        <label class="text-label" for="plugin_api_key"><?php esc_html_e('Plugin API Key', CROWDAA_SYNC_PLUGIN_NAME); ?></label>
     58        <input readonly type="text" required id="plugin_api_key" name="plugin_api_key" value="<?php echo esc_attr(($plugin_api_key && $auth_token) ? $plugin_api_key : ''); ?>"/>
     59        <span id="plugin_api_key-copied"></span>
    5460      </p>
    5561    </div>
  • crowdaa-sync/tags/1.4.1/crowdaa-sync.php

    r2776976 r2778568  
    1414 * Plugin URI:       
    1515 * Description:       Plugin for synchronizing WordPress site and Crowdaa CMS
    16  * Version:           1.4.0
     16 * Version:           1.4.1
    1717 * Requires at least: 5.5
    1818 * Requires PHP:      7.2
     
    3434 * Uses SemVer - https://semver.org
    3535 */
    36 define('CROWDAA_SYNC_VERSION', '1.4.0');
     36define('CROWDAA_SYNC_VERSION', '1.4.1');
    3737define('CROWDAA_SYNC_PLUGIN_DIR', __DIR__);
    3838define('CROWDAA_SYNC_PLUGIN_NAME', 'crowdaa-sync');
  • crowdaa-sync/tags/1.4.1/includes/class-crowdaa-sync-utils.php

    r2776976 r2778568  
    162162    return ($ret);
    163163  }
     164
     165  /**
     166   * Generates and returns a new token with the given length
     167   */
     168  public static function random_token($length) {
     169    $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_';
     170    $pass = '';
     171    $alphaLength = strlen($alphabet) - 1;
     172    while (strlen($pass) < $length) {
     173      $c = rand(0, $alphaLength);
     174      $pass .= $alphabet[$c];
     175    }
     176    return $pass;
     177  }
     178
     179  /**
     180   * Generates and returns a new Crowdaa API token
     181   */
     182  public static function generate_plugin_api_key() {
     183    $internalApiToken = self::random_token(97);
     184    update_option('crowdaa_plugin_api_key', $internalApiToken);
     185
     186    return ($internalApiToken);
     187  }
     188
     189  /**
     190   * Returns the current Crowdaa API token
     191   */
     192  public static function get_plugin_api_key() {
     193    $apiKey = get_option('crowdaa_plugin_api_key', null);
     194    if (!$apiKey) {
     195      $apiKey = self::generate_plugin_api_key();
     196    }
     197
     198    return ($apiKey);
     199  }
     200
     201  /**
     202   * Checks if the current execution was called from the Crowdaa API
     203   */
     204  public static function is_crowdaa_api_request() {
     205    if (!isset($_SERVER['HTTP_X_CROWDAA_API_KEY'])) {
     206      return (false);
     207    }
     208
     209    $clientApiKey = $_SERVER['HTTP_X_CROWDAA_API_KEY'];
     210    $ourApiKey = self::get_plugin_api_key();
     211
     212    return ($clientApiKey === $ourApiKey);
     213  }
    164214}
  • crowdaa-sync/trunk/CHANGELOG

    r2776976 r2778568  
    66
    77## [Unreleased]
     8
     9## [1.4.1] - 2022-09-01
     10
     11### Added
     12
     13- Plugin API key (not currently used, preparing it for 1.5.0)
    814
    915## [1.4.0] - 2022-08-29
  • crowdaa-sync/trunk/README.txt

    r2776976 r2778568  
    66Requires PHP: 7.3
    77Tested up to: 5.9
    8 Stable tag: 1.4.0
     8Stable tag: 1.4.1
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • crowdaa-sync/trunk/admin/class-crowdaa-sync-admin-display.php

    r2776976 r2778568  
    200200          update_option('crowdaa_user_id', $json->data->userId);
    201201          update_option('crowdaa_auth_token', $json->data->authToken);
     202          Crowdaa_Sync_Utils::generate_plugin_api_key();
    202203
    203204          add_action(
  • crowdaa-sync/trunk/admin/js/crowdaa-sync-admin.js

    r2744975 r2778568  
    180180    $('#crowdaa-sync-categories-mode-whitelist-checkbox').on('change', updateSyncCategoriesSelect);
    181181    updateSyncCategoriesSelect();
     182
     183    let pluginApiKeyDisplayTimeout = null;
     184    $('#plugin_api_key').focus(function(e) {
     185      e.preventDefault();
     186
     187      $(e.target).select();
     188      document.execCommand("copy");
     189
     190      const $display = $('#plugin_api_key-copied');
     191      $display.text('Copied!');
     192
     193      if (pluginApiKeyDisplayTimeout !== null) clearTimeout(pluginApiKeyDisplayTimeout);
     194      pluginApiKeyDisplayTimeout = setTimeout(() => {
     195        $display.text('');
     196        pluginApiKeyDisplayTimeout = null;
     197      }, 3000);
     198    });
    182199
    183200    $('#crowdaa-reset-request').click(function(e) {
  • crowdaa-sync/trunk/admin/partials/crowdaa-sync-admin-display.php

    r2776976 r2778568  
    2323
    2424  <h2><?php esc_html_e('Connect to Crowdaa', CROWDAA_SYNC_PLUGIN_NAME); ?></h2>
    25   <?php
     25  <form method="post" action="<?php $admin_utils->login(); ?>">
     26<?php
    2627  $api_url            = get_option('crowdaa_api_url');
    2728  $user_email         = get_option('crowdaa_user_email');
     
    3031  $user_api_key       = get_option('crowdaa_user_api_key');
    3132  $auth_token         = get_option('crowdaa_auth_token');
    32   ?>
    33   <form method="post" action="<?php $admin_utils->login(); ?>">
     33  $plugin_api_key     = Crowdaa_Sync_Utils::get_plugin_api_key();
     34?>
    3435    <div class="crowdaa-html-container">
    3536      <p>
     
    5253        <label class="text-label" for="user_password"><?php esc_html_e('Password', CROWDAA_SYNC_PLUGIN_NAME); ?></label>
    5354        <input type="password" required id="user_password" name="user_password" value="<?php echo esc_attr(($user_password && $auth_token) ? $user_password : ''); ?>"/>
     55      </p>
     56      <p>
     57        <label class="text-label" for="plugin_api_key"><?php esc_html_e('Plugin API Key', CROWDAA_SYNC_PLUGIN_NAME); ?></label>
     58        <input readonly type="text" required id="plugin_api_key" name="plugin_api_key" value="<?php echo esc_attr(($plugin_api_key && $auth_token) ? $plugin_api_key : ''); ?>"/>
     59        <span id="plugin_api_key-copied"></span>
    5460      </p>
    5561    </div>
  • crowdaa-sync/trunk/crowdaa-sync.php

    r2776976 r2778568  
    1414 * Plugin URI:       
    1515 * Description:       Plugin for synchronizing WordPress site and Crowdaa CMS
    16  * Version:           1.4.0
     16 * Version:           1.4.1
    1717 * Requires at least: 5.5
    1818 * Requires PHP:      7.2
     
    3434 * Uses SemVer - https://semver.org
    3535 */
    36 define('CROWDAA_SYNC_VERSION', '1.4.0');
     36define('CROWDAA_SYNC_VERSION', '1.4.1');
    3737define('CROWDAA_SYNC_PLUGIN_DIR', __DIR__);
    3838define('CROWDAA_SYNC_PLUGIN_NAME', 'crowdaa-sync');
  • crowdaa-sync/trunk/includes/class-crowdaa-sync-utils.php

    r2776976 r2778568  
    162162    return ($ret);
    163163  }
     164
     165  /**
     166   * Generates and returns a new token with the given length
     167   */
     168  public static function random_token($length) {
     169    $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_';
     170    $pass = '';
     171    $alphaLength = strlen($alphabet) - 1;
     172    while (strlen($pass) < $length) {
     173      $c = rand(0, $alphaLength);
     174      $pass .= $alphabet[$c];
     175    }
     176    return $pass;
     177  }
     178
     179  /**
     180   * Generates and returns a new Crowdaa API token
     181   */
     182  public static function generate_plugin_api_key() {
     183    $internalApiToken = self::random_token(97);
     184    update_option('crowdaa_plugin_api_key', $internalApiToken);
     185
     186    return ($internalApiToken);
     187  }
     188
     189  /**
     190   * Returns the current Crowdaa API token
     191   */
     192  public static function get_plugin_api_key() {
     193    $apiKey = get_option('crowdaa_plugin_api_key', null);
     194    if (!$apiKey) {
     195      $apiKey = self::generate_plugin_api_key();
     196    }
     197
     198    return ($apiKey);
     199  }
     200
     201  /**
     202   * Checks if the current execution was called from the Crowdaa API
     203   */
     204  public static function is_crowdaa_api_request() {
     205    if (!isset($_SERVER['HTTP_X_CROWDAA_API_KEY'])) {
     206      return (false);
     207    }
     208
     209    $clientApiKey = $_SERVER['HTTP_X_CROWDAA_API_KEY'];
     210    $ourApiKey = self::get_plugin_api_key();
     211
     212    return ($clientApiKey === $ourApiKey);
     213  }
    164214}
Note: See TracChangeset for help on using the changeset viewer.