drupal.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. Fix Reverse Proxy Support:
  2. http://drupal.org/node/244593
  3. http://drupal.org/files/issues/drupal_80.patch
  4. Index: includes/bootstrap.inc
  5. --- includes/bootstrap.inc.orig 2008-02-11 15:36:21 +0100
  6. +++ includes/bootstrap.inc 2008-04-09 20:47:49 +0200
  7. @@ -272,6 +272,7 @@
  8. */
  9. function conf_init() {
  10. global $base_url, $base_path, $base_root;
  11. + global $base_url_local;
  12. // Export the following settings.php variables to the global namespace
  13. global $db_url, $db_prefix, $cookie_domain, $conf, $installed_profile, $update_free_access;
  14. @@ -723,9 +724,22 @@
  15. * generate an equivalent using other environment variables.
  16. */
  17. function request_uri() {
  18. + global $base_url;
  19. + global $base_url_local;
  20. if (isset($_SERVER['REQUEST_URI'])) {
  21. $uri = $_SERVER['REQUEST_URI'];
  22. + if (isset($base_url) && isset($base_url_local)) {
  23. + $parts = parse_url($base_url_local);
  24. + if ( strlen($uri) >= strlen($base_url_local)
  25. + && substr($uri, 0, strlen($base_url_local)) == $base_url_local) {
  26. + $uri = $base_url . substr($uri, strlen($base_url_local));
  27. + }
  28. + elseif ( strlen($uri) >= strlen($parts["path"])
  29. + && substr($uri, 0, strlen($parts["path"])) == $parts["path"]) {
  30. + $uri = $base_url . substr($uri, strlen($parts["path"]));
  31. + }
  32. + }
  33. }
  34. else {
  35. if (isset($_SERVER['argv'])) {
  36. Index: sites/default/default.settings.php
  37. --- sites/default/default.settings.php.orig 2007-12-20 10:35:10 +0100
  38. +++ sites/default/default.settings.php 2008-04-09 20:47:32 +0200
  39. @@ -126,6 +126,24 @@
  40. # $base_url = 'http://www.example.com'; // NO trailing slash!
  41. /**
  42. + * Local Base URL (optional).
  43. + *
  44. + * If you are running Drupal behind a reverse proxy, $base_url (see above)
  45. + * usually points to the URL of the reverse proxy. Drupal uses this for
  46. + * all sorts of external URLs. In order to correctly calculate sub-URLs
  47. + * below $base_url for embedded HTML forms, Drupal also has to know the
  48. + * URL on the local/origin server under which Drupal is contacted by the
  49. + * reverse proxy. This is what $base_url_local is for.
  50. + *
  51. + * Examples:
  52. + * $base_url_local = 'http://www.example.com:8080/drupal';
  53. + *
  54. + * It is not allowed to have a trailing slash; Drupal will add it
  55. + * for you.
  56. + */
  57. +# $base_url_local = 'http://www.example.com:8080/drupal'; // NO trailing slash!
  58. +
  59. +/**
  60. * PHP settings:
  61. *
  62. * To see what PHP settings are possible, including whether they can
  63. -----------------------------------------------------------------------------
  64. Support HTTP Proxies (mainly for update checks, RSS fetching, etc)
  65. http://drupal.org/node/7881
  66. http://drupal.org/files/issues/proxy_11.patch
  67. (post-adjusted and improved by RSE)
  68. Index: includes/common.inc
  69. --- includes/common.inc.orig 2008-04-09 23:11:44 +0200
  70. +++ includes/common.inc 2008-04-24 11:41:40 +0200
  71. @@ -439,13 +439,27 @@
  72. case 'http':
  73. $port = isset($uri['port']) ? $uri['port'] : 80;
  74. $host = $uri['host'] . ($port != 80 ? ':'. $port : '');
  75. - $fp = @fsockopen($uri['host'], $port, $errno, $errstr, 15);
  76. + if (variable_get('proxy_server', '') != '') {
  77. + $proxy_server = variable_get('proxy_server', '');
  78. + $proxy_port = variable_get('proxy_port', 8080);
  79. + $fp = @fsockopen($proxy_server, $proxy_port, $errno, $errstr, 15);
  80. + }
  81. + else {
  82. + $fp = @fsockopen($uri['host'], $port, $errno, $errstr, 15);
  83. + }
  84. break;
  85. case 'https':
  86. // Note: Only works for PHP 4.3 compiled with OpenSSL.
  87. $port = isset($uri['port']) ? $uri['port'] : 443;
  88. $host = $uri['host'] . ($port != 443 ? ':'. $port : '');
  89. - $fp = @fsockopen('ssl://'. $uri['host'], $port, $errno, $errstr, 20);
  90. + if (variable_get('proxy_server', '') != '') {
  91. + $proxy_server = variable_get('proxy_server', '');
  92. + $proxy_port = variable_get('proxy_port', 8080);
  93. + $fp = @fsockopen($proxy_server, $proxy_port, $errno, $errstr, 15);
  94. + }
  95. + else {
  96. + $fp = @fsockopen('ssl://'. $uri['host'], $port, $errno, $errstr, 20);
  97. + }
  98. break;
  99. default:
  100. $result->error = 'invalid schema '. $uri['scheme'];
  101. @@ -462,9 +476,14 @@
  102. }
  103. // Construct the path to act on.
  104. - $path = isset($uri['path']) ? $uri['path'] : '/';
  105. - if (isset($uri['query'])) {
  106. - $path .= '?'. $uri['query'];
  107. + if (variable_get('proxy_server', '') != '') {
  108. + $path = $url;
  109. + }
  110. + else {
  111. + $path = isset($uri['path']) ? $uri['path'] : '/';
  112. + if (isset($uri['query'])) {
  113. + $path .= '?'. $uri['query'];
  114. + }
  115. }
  116. // Create HTTP request.
  117. @@ -482,6 +501,14 @@
  118. $defaults['Authorization'] = 'Authorization: Basic '. base64_encode($uri['user'] . (!empty($uri['pass']) ? ":". $uri['pass'] : ''));
  119. }
  120. + // If the proxy server required a username then attempt to authenticate with it
  121. + if (variable_get('proxy_username', '') != '') {
  122. + $username = variable_get('proxy_username', '');
  123. + $password = variable_get('proxy_password', '');
  124. + $auth_string = base64_encode($username . ($password != '' ? ':'. $password : ''));
  125. + $defaults['Proxy-Authorization'] = 'Proxy-Authorization: Basic '. $auth_string ."\r\n";
  126. + }
  127. +
  128. foreach ($headers as $header => $value) {
  129. $defaults[$header] = $header .': '. $value;
  130. }
  131. Index: modules/system/system.admin.inc
  132. --- modules/system/system.admin.inc.orig 2008-03-25 12:58:16 +0100
  133. +++ modules/system/system.admin.inc 2008-04-24 11:43:07 +0200
  134. @@ -1363,6 +1363,65 @@
  135. }
  136. /**
  137. + * Form builder; Configure the site proxy settings.
  138. + *
  139. + * @ingroup forms
  140. + * @see system_settings_form()
  141. + */
  142. +function system_proxy_settings() {
  143. +
  144. + $form['forward_proxy'] = array(
  145. + '#type' => 'fieldset',
  146. + '#title' => t('Forward proxy settings'),
  147. + '#description' => t('The proxy server used when Drupal needs to connect to other sites on the Internet.'),
  148. + );
  149. + $form['forward_proxy']['proxy_server'] = array(
  150. + '#type' => 'textfield',
  151. + '#title' => t('Proxy host name'),
  152. + '#default_value' => variable_get('proxy_server', ''),
  153. + '#description' => t('The host name of the proxy server, eg. localhost. If this is empty Drupal will connect directly to the internet.')
  154. + );
  155. + $form['forward_proxy']['proxy_port'] = array(
  156. + '#type' => 'textfield',
  157. + '#title' => t('Proxy port number'),
  158. + '#default_value' => variable_get('proxy_port', 8080),
  159. + '#description' => t('The port number of the proxy server, eg. 8080'),
  160. + );
  161. + $form['forward_proxy']['proxy_username'] = array(
  162. + '#type' => 'textfield',
  163. + '#title' => t('Proxy username'),
  164. + '#default_value' => variable_get('proxy_username', ''),
  165. + '#description' => t('The username used to authenticate with the proxy server.'),
  166. + );
  167. + $form['forward_proxy']['proxy_password'] = array(
  168. + '#type' => 'textfield',
  169. + '#title' => t('Proxy password'),
  170. + '#default_value' => variable_get('proxy_password', ''),
  171. + '#description' => t('The password used to connect to the proxy server. This is kept as plain text.', '')
  172. + );
  173. + $form['#validate'][] = 'system_proxy_settings_validate';
  174. +
  175. + return system_settings_form($form);
  176. +}
  177. +
  178. +/**
  179. + * Validate the submitted proxy form.
  180. + */
  181. +function system_proxy_settings_validate($form, &$form_state) {
  182. + // Validate the proxy settings
  183. + $form_state['values']['proxy_server'] = trim($form_state['values']['proxy_server']);
  184. + if ($form_state['values']['proxy_server'] != '') {
  185. + // TCP allows the port to be between 0 and 65536 inclusive
  186. + if (!is_numeric($form_state['values']['proxy_port'])) {
  187. + form_set_error('proxy_port', t('The proxy port is invalid. It must be a number between 0 and 65535.'));
  188. + }
  189. + elseif ($form_state['values']['proxy_port'] < 0 || $form_state['values']['proxy_port'] >= 65536) {
  190. + form_set_error('proxy_port', t('The proxy port is invalid. It must be between 0 and 65535.'));
  191. + }
  192. + }
  193. +}
  194. +
  195. +/**
  196. * Form builder; Configure the site file handling.
  197. *
  198. * @ingroup forms
  199. Index: modules/system/system.module
  200. --- modules/system/system.module.orig 2008-04-09 23:11:49 +0200
  201. +++ modules/system/system.module 2008-04-24 11:43:47 +0200
  202. @@ -55,7 +55,7 @@
  203. $output .= '<li>'. t('support for enabling and disabling <a href="@themes">themes</a>, which determine the design and presentation of your site. Drupal comes packaged with several core themes and additional contributed themes are available at the <a href="@drupal-themes">Drupal.org theme page</a>.', array('@themes' => url('admin/build/themes'), '@drupal-themes' => 'http://drupal.org/project/themes')) .'</li>';
  204. $output .= '<li>'. t('a robust <a href="@cache-settings">caching system</a> that allows the efficient re-use of previously-constructed web pages and web page components. Drupal stores the pages requested by anonymous users in a compressed format; depending on your site configuration and the amount of your web traffic tied to anonymous visitors, Drupal\'s caching system may significantly increase the speed of your site.', array('@cache-settings' => url('admin/settings/performance'))) .'</li>';
  205. $output .= '<li>'. t('a set of routine administrative operations that rely on a correctly-configured <a href="@cron">cron maintenance task</a> to run automatically. A number of other modules, including the feed aggregator, ping module and search also rely on <a href="@cron">cron maintenance tasks</a>. For more information, see the online handbook entry for <a href="@handbook">configuring cron jobs</a>.', array('@cron' => url('admin/reports/status'), '@handbook' => 'http://drupal.org/cron')) .'</li>';
  206. - $output .= '<li>'. t('basic configuration options for your site, including <a href="@date-settings">date and time settings</a>, <a href="@file-system">file system settings</a>, <a href="@clean-url">clean URL support</a>, <a href="@site-info">site name and other information</a>, and a <a href="@site-maintenance">site maintenance</a> function for taking your site temporarily off-line.', array('@date-settings' => url('admin/settings/date-time'), '@file-system' => url('admin/settings/file-system'), '@clean-url' => url('admin/settings/clean-urls'), '@site-info' => url('admin/settings/site-information'), '@site-maintenance' => url('admin/settings/site-maintenance'))) .'</li></ul>';
  207. + $output .= '<li>'. t('basic configuration options for your site, including <a href="@date-settings">date and time settings</a>, <a href="@file-system">file system settings</a>, <a href="@clean-url">clean URL support</a>, <a href="@proxy-server">proxy server settings</a>, a href="@site-info">site name and other information</a>, and a <a href="@site-maintenance">site maintenance</a> function for taking your site temporarily off-line.', array('@date-settings' => url('admin/settings/date-time'), '@file-system' => url('admin/settings/file-system'), '@clean-url' => url('admin/settings/clean-urls'), '@site-info' => url('admin/settings/site-information'), '@site-maintenance' => url('admin/settings/site-maintenance'))) .'</li></ul>';
  208. $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@system">System module</a>.', array('@system' => 'http://drupal.org/handbook/modules/system/')) .'</p>';
  209. return $output;
  210. case 'admin':
  211. @@ -406,6 +406,14 @@
  212. 'access arguments' => array('administer site configuration'),
  213. 'file' => 'system.admin.inc',
  214. );
  215. + $items['admin/settings/proxy'] = array(
  216. + 'title' => 'Proxy server',
  217. + 'description' => 'Configure settings when the site is behind a proxy server.',
  218. + 'page callback' => 'drupal_get_form',
  219. + 'page arguments' => array('system_proxy_settings'),
  220. + 'access arguments' => array('administer site configuration'),
  221. + 'file' => 'system.admin.inc',
  222. + );
  223. $items['admin/settings/file-system'] = array(
  224. 'title' => 'File system',
  225. 'description' => 'Tell Drupal where to store uploaded files and how they are accessed.',