Project

General

Profile

« Previous | Next » 

Revision 6c55c1d0

Added by Andreas Kohlbecker over 2 years ago

ref #9776 enfocing https for webservice requests and notifying user about misconfiguration

View differences:

modules/cdm_dataportal/cdm_api/cdm_api.module
102 102
}
103 103

  
104 104
/**
105
 * info hook implementation for the CDM web service debug block
106
 *
105 107
 * Implements hook_block_info().
108
 *
109
 * @see \cdm_api_block_view()
106 110
 */
107 111
function cdm_api_block_info() {
108 112

  
......
114 118
}
115 119

  
116 120
/**
121
 * block_view hook implementation for the CDM web service debug block
122
 *
117 123
 * Implements hook_block_view().
124
 *
125
 * @see  cdm_api_block_info()
118 126
 */
119 127
function cdm_api_block_view($delta) {
120 128
  switch ($delta) {
121 129
    case 'cdm_ws_debug':
122 130

  
123
    $cdm_ws_url = variable_get('cdm_webservice_url', '');
131
    $cdm_ws_url = cdm_webservice_url();
124 132

  
125 133
    $field_map = array(
126 134
        'ws_uri' => t('URI') . ' <code>(' . $cdm_ws_url .'...)</code>',
......
658 666
    $pathParameters = array();
659 667
  }
660 668
  $path = cdm_compose_url($uri_pattern, $pathParameters, $query);
669
  $url = cdm_webservice_url() . $path;
670
  return $url;
671
}
661 672

  
662
  $uri = variable_get('cdm_webservice_url', '') . $path;
663
  return $uri;
673
/**
674
 * Wrapper to access the 'cdm_webservice_url' and to ensure that
675
 * the returned webservice url scheme conforms to the scheme of the
676
 * page request.
677
 *
678
 * @param string $default optional parameter to set the default, by default an empty string is returned
679
 */
680
function cdm_webservice_url($default = ''){
681
  static $conform_ws_url = null;
682
  if($conform_ws_url === null) {
683
    $ws_url = variable_get('cdm_webservice_url', $default);
684
    if($ws_url && $_SERVER['REQUEST_SCHEME'] == 'https' && parse_url($ws_url, PHP_URL_SCHEME) === 'http'){
685
      $conform_ws_url = preg_replace("/^http\:/", "https:", $ws_url);
686
      drupal_set_message('The <stong>CDM web service URL</stong> scheme should be set to <strong>HTTPS</strong> the '
687
        . l('CDM Data Portal settings', 'admin/config/cdm_dataportal/settings'), 'warning');
688
    } else {
689
      $conform_ws_url = $ws_url;
690
    }
691
  }
692
  return $conform_ws_url;
664 693
}
665 694

  
666 695
/**
......
2298 2327
    $xml_uri = $json_uri . '.xml';
2299 2328
  }
2300 2329

  
2301
  // data links to make data accecsible as json and xml
2330
  // data links to make data accessible as json and xml
2302 2331
  $data_links = '';
2303 2332
  if (_is_cdm_ws_uri($path)) {
2304 2333

  
......
2747 2776
 *   True if the uri starts with a cdm webservice url.
2748 2777
 */
2749 2778
function _is_cdm_ws_uri($uri) {
2750
  return str_beginsWith($uri, variable_get('cdm_webservice_url', '#EMPTY#'));
2779
  return str_beginsWith($uri, cdm_webservice_url('#EMPTY#'));
2751 2780
}
2752 2781

  
2753 2782
/**
modules/cdm_dataportal/cdm_api/cdm_node.php
84 84

  
85 85
  // Try to find node id.
86 86
  $cdmnode = db_query('SELECT nid, cdmtype FROM {node_cdm} WHERE wsuri = :wsuri AND cdmtype = :cdmtype AND uuid = :uuid', array(
87
    ':wsuri' => variable_get('cdm_webservice_url', NULL),
87
    ':wsuri' => cdm_webservice_url(),
88 88
    ':cdmtype' => $nodetype,
89 89
    ':uuid' => $uuid,
90 90
  ))->fetch();
......
155 155
      }
156 156

  
157 157
      // Hash as a 32-character hexadecimal number.
158
      $hash = md5(variable_get('cdm_webservice_url') . $uuid);
158
      $hash = md5(cdm_webservice_url() . $uuid);
159 159

  
160 160
      $id = db_insert('node_cdm')->fields(array(
161 161
        'nid' => $node->nid,
162
        'wsuri' => variable_get('cdm_webservice_url'),
162
        'wsuri' => cdm_webservice_url(),
163 163
        'hash' => $hash,
164 164
        'cdmtype' => $nodetype,
165 165
        'uuid' => $uuid,
modules/cdm_dataportal/cdm_dataportal.module
94 94

  
95 95
    $callback = "jQuery('" . $link_element_selector . "').cdm_ws_progress('" . $progress_element_selector . "');";
96 96

  
97
    drupal_add_js_async(variable_get('cdm_webservice_url', '').'js/cdm_ws_progress.js', $callback);
97
    drupal_add_js_async(cdm_webservice_url(). 'js/cdm_ws_progress.js', $callback);
98 98

  
99 99
    //   drupal_add_js("
100 100
    //   	  if (Drupal.jsEnabled) {
......
293 293
          // activeClass: "fa-rotate-90",
294 294
          classificationUuid: "' . get_current_classification_uuid() . '",
295 295
          taxonUuid: "' . get_current_taxon_uuid() . '",
296
          cdmWebappBaseUri: "' . variable_get('cdm_webservice_url', '') . '",
296
          cdmWebappBaseUri: "' . cdm_webservice_url() . '",
297 297
          proxyBaseUri: "' . $base_url . '",
298 298
          
299 299
        });

Also available in: Unified diff