kibana 破解

import { createHash } from 'crypto';
import moment from 'moment';
import { get, set, includes, forIn } from 'lodash';
import Poller from './poller';
import { LICENSE_EXPIRY_SOON_DURATION, XPACK_INFO_API_DEFAULT_POLL_FREQUENCY } from './constants';

export default function _xpackInfo(server, pollFrequencyInMillis) {
  pollFrequencyInMillis = pollFrequencyInMillis || XPACK_INFO_API_DEFAULT_POLL_FREQUENCY.asMilliseconds();

  let _cachedResponseFromElasticsearch;

  const _licenseCheckResultsGenerators = {};
  const _licenseCheckResults = {};
  let _cachedXPackInfoJSON;
  let _cachedXPackInfoJSONSignature;

  const poller = new Poller({
    functionToPoll: _callElasticsearchXPackAPI,
    successFunction: _handleResponseFromElasticsearch,
    errorFunction: _handleErrorFromElasticsearch,
    pollFrequencyInMillis,
    continuePollingOnError: true
  });

  const xpackInfoObject = {
    license: {
      getUid: function () {
        return get(_cachedResponseFromElasticsearch, 'license.uid');
      },
      isActive: function () {
    return true;
        //return get(_cachedResponseFromElasticsearch, 'license.status') === 'active';
      },
      expiresSoon: function () {
        //const expiryDateMillis = get(_cachedResponseFromElasticsearch, 'license.expiry_date_in_millis');
        //const expirySoonDate = moment.utc(expiryDateMillis).subtract(LICENSE_EXPIRY_SOON_DURATION);
        //return moment.utc().isAfter(expirySoonDate);
  return false;
      },
      getExpiryDateInMillis: function () {
        return get(_cachedResponseFromElasticsearch, 'license.expiry_date_in_millis');
      },
      isOneOf: function (candidateLicenses) {
        if (!Array.isArray(candidateLicenses)) {
          candidateLicenses = [ candidateLicenses ];
        }
        return includes(candidateLicenses, get(_cachedResponseFromElasticsearch, 'license.mode'));
      },
      getType: function () {
        return get(_cachedResponseFromElasticsearch, 'license.type');
      }
    },
    feature: function (feature) {
      return {
        isAvailable: function () {
   return true;
          //return get(_cachedResponseFromElasticsearch, 'features.' + feature + '.available');
        },
        isEnabled: function () {
   return true;
          //return get(_cachedResponseFromElasticsearch, 'features.' + feature + '.enabled');
        },
        registerLicenseCheckResultsGenerator: function (generator) {
          _licenseCheckResultsGenerators[feature] = generator;
          _updateXPackInfoJSON();
        },
        getLicenseCheckResults: function () {
          return _licenseCheckResults[feature];
        }
      };
    },
    isAvailable: function () {
  return true;
      //return !!_cachedResponseFromElasticsearch && !!get(_cachedResponseFromElasticsearch, 'license');
    },
    getSignature: function () {
      return _cachedXPackInfoJSONSignature;
    },
    refreshNow: function () {
      const self = this;
      return _callElasticsearchXPackAPI()
      .then(_handleResponseFromElasticsearch)
      .catch(_handleErrorFromElasticsearch)
      .then(() => self);
    },
    stopPolling: function () {
      // This method exists primarily for unit testing
      poller.stop();
    },
    toJSON: function () {
      return _cachedXPackInfoJSON;
    }
  };

  const cluster = server.plugins.elasticsearch.getCluster('data');

  function _callElasticsearchXPackAPI() {
    server.log([ 'license', 'debug', 'xpack' ], 'Calling Elasticsearch _xpack API');
    return cluster.callWithInternalUser('transport.request', {
      method: 'GET',
      path: '/_xpack'
    });
  };

  function _updateXPackInfoJSON() {
    const json = {};

    // Set response elements common to all features
    set(json, 'license.type', xpackInfoObject.license.getType());
    set(json, 'license.isActive', xpackInfoObject.license.isActive());
    set(json, 'license.expiryDateInMillis', xpackInfoObject.license.getExpiryDateInMillis());

    // Set response elements specific to each feature. To do this,
    // call the license check results generator for each feature, passing them
    // the xpack info object
    forIn(_licenseCheckResultsGenerators, (generator, feature) => {
      _licenseCheckResults[feature] = generator(xpackInfoObject); // return value expected to be a dictionary object
    });
    set(json, 'features', _licenseCheckResults);

    _cachedXPackInfoJSON = json;
    _cachedXPackInfoJSONSignature = createHash('md5')
    .update(JSON.stringify(json))
    .digest('hex');
  }

  function _hasLicenseInfoFromElasticsearchChanged(response) {
    const cachedResponse = _cachedResponseFromElasticsearch;
    return (get(response, 'license.mode') !== get(cachedResponse, 'license.mode')
      || get(response, 'license.status') !== get(cachedResponse, 'license.status')
      || get(response, 'license.expiry_date_in_millis') !== get(cachedResponse, 'license.expiry_date_in_millis'));
  }

  function _getLicenseInfoForLog(response) {
    const mode = get(response, 'license.mode');
    const status = get(response, 'license.status');
    const expiryDateInMillis = get(response, 'license.expiry_date_in_millis');

    return [
      'mode: ' + mode,
      'status: ' + status,
      'expiry date: ' + moment(expiryDateInMillis, 'x').format()
    ].join(' | ');
  }

  function _handleResponseFromElasticsearch(response) {

    if (_hasLicenseInfoFromElasticsearchChanged(response)) {
      let changed = '';
      if (_cachedResponseFromElasticsearch) {
        changed = 'changed ';
      }

      const licenseInfo = _getLicenseInfoForLog(response);
      const logMessage = `Imported ${changed}license information from Elasticsearch: ${licenseInfo}`;
      server.log([ 'license', 'info', 'xpack'  ], logMessage);
    }

    _cachedResponseFromElasticsearch = response;
    _updateXPackInfoJSON();
  }

  function _handleErrorFromElasticsearch(error) {
    server.log([ 'license', 'warning', 'xpack' ], 'License information could not be obtained from Elasticsearch. ' + error);
    _cachedResponseFromElasticsearch = null;
    _updateXPackInfoJSON();

    // allow tests to shutdown
    error.info = xpackInfoObject;

    throw error;
  }

  // Start polling for changes
  return poller.start()
  .then(() => xpackInfoObject);
}

 

破解文件:x-pack-5.2.1\kibana\x-pack\server\lib\_xpack_info

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值