--- includes/common.inc Tue Mar 17 22:35:08 2009 +++ includes/common.inc Wed Mar 18 13:45:26 2009 @@ -468,6 +468,8 @@ $result = new stdClass(); + $proxy_not_required = TRUE; + // Parse the URL and make sure we can handle the schema. $uri = @parse_url($url); @@ -485,7 +487,16 @@ case 'http': $port = isset($uri['port']) ? $uri['port'] : 80; $host = $uri['host'] . ($port != 80 ? ':' . $port : ''); - $fp = @fsockopen($uri['host'], $port, $errno, $errstr, 15); + + $proxy_not_required = is_in_no_proxy_list($uri['host']); + if ((variable_get('proxy_server', '') != '') && (FALSE == $proxy_not_required)) { + $proxy_server = variable_get('proxy_server', ''); + $proxy_port = variable_get('proxy_port', 8080); + $fp = @fsockopen($proxy_server, $proxy_port, $errno, $errstr, 15); + } + else { + $fp = @fsockopen($uri['host'], $port, $errno, $errstr, 15); + } break; case 'https': // Note: Only works when PHP is compiled with OpenSSL support. @@ -515,9 +526,14 @@ } // Construct the path to act on. - $path = isset($uri['path']) ? $uri['path'] : '/'; - if (isset($uri['query'])) { - $path .= '?' . $uri['query']; + if ((variable_get('proxy_server', '') != '') && (FALSE == $proxy_not_required)) { + $path = $url; + } + else { + $path = isset($uri['path']) ? $uri['path'] : '/'; + if (isset($uri['query'])) { + $path .= '?' . $uri['query']; + } } // Merge the default options. @@ -541,6 +557,13 @@ // If the server url has a user then attempt to use basic authentication if (isset($uri['user'])) { $options['headers']['Authorization'] = 'Basic ' . base64_encode($uri['user'] . (!empty($uri['pass']) ? ":" . $uri['pass'] : '')); + } + + if ((variable_get('proxy_username', '') != '') && (FALSE == $proxy_not_required)) { + $username = variable_get('proxy_username', ''); + $password = variable_get('proxy_password', ''); + $auth_string = base64_encode($username . ($password != '' ? ':'. $password : '')); + $defaults['Proxy-Authorization'] = 'Proxy-Authorization: Basic '. $auth_string ."\r\n"; } // If the database prefix is being used by SimpleTest to run the tests in a copied --- modules/system/system.admin.inc Tue Mar 17 15:26:30 2009 +++ modules/system/system.admin.inc Wed Mar 18 13:47:18 2009 @@ -1418,6 +1418,77 @@ } /** + * Form builder; Configure the site proxy settings. + * + * @ingroup forms + * @see system_settings_form() + */ +function system_proxy_settings() { + + $form['forward_proxy'] = array( + '#type' => 'fieldset', + '#title' => t('Forward Proxy Settings'), + '#description' => t('The proxy server used when Drupal needs to connect to other sites on the Internet.'), + ); + $form['forward_proxy']['proxy_server'] = array( + '#type' => 'textfield', + '#title' => t('Proxy host name'), + '#default_value' => variable_get('proxy_server', ''), + '#description' => t('The host name of the proxy server, eg. localhost. If this is empty Drupal will connect directly to the internet.') + ); + $form['forward_proxy']['proxy_port'] = array( + '#type' => 'textfield', + '#title' => t('Proxy port number'), + '#default_value' => variable_get('proxy_port', 8080), + '#description' => t('The port number of the proxy server, eg. 8080'), + ); + $form['forward_proxy']['proxy_username'] = array( + '#type' => 'textfield', + '#title' => t('Proxy username'), + '#default_value' => variable_get('proxy_username', ''), + '#description' => t('The username used to authenticate with the proxy server.'), + ); + $form['forward_proxy']['proxy_password'] = array( + '#type' => 'textfield', + '#title' => t('Proxy password'), + '#default_value' => variable_get('proxy_password', ''), + '#description' => t('The password used to connect to the proxy server. This is kept as plain text.', '') + ); + $form['forward_proxy']['proxy_exceptions'] = array( + '#type' => 'textfield', + '#title' => t('No proxy for'), + '#default_value' => variable_get('proxy_exceptions', 'localhost'), + '#description' => t('Example: .example.com,localhost,192.168.1.2', '') + ); + $form['forward_proxy']['proxy_skip_selftest'] = array( + '#type' => 'checkbox', + '#title' => t('Skip HTTP self test'), + '#description' => t('Skip HTTP request self test.'), + '#default_value' => variable_get('proxy_skip_selftest', '0'), + ); + $form['#validate'][] = 'system_proxy_settings_validate'; + + return system_settings_form($form); +} + +/** + * Validate the submitted proxy form. + */ +function system_proxy_settings_validate($form, &$form_state) { + // Validate the proxy settings + $form_state['values']['proxy_server'] = trim($form_state['values']['proxy_server']); + if ($form_state['values']['proxy_server'] != '') { + // TCP allows the port to be between 0 and 65536 inclusive + if (!is_numeric($form_state['values']['proxy_port'])) { + form_set_error('proxy_port', t('The proxy port is invalid. It must be a number between 0 and 65535.')); + } + elseif ($form_state['values']['proxy_port'] < 0 || $form_state['values']['proxy_port'] >= 65536) { + form_set_error('proxy_port', t('The proxy port is invalid. It must be between 0 and 65535.')); + } + } +} + +/** * Form builder; Configure the site file handling. * * @ingroup forms --- modules/system/system.module Tue Mar 17 15:26:30 2009 +++ modules/system/system.module Wed Mar 18 13:49:28 2009 @@ -549,6 +549,16 @@ 'page arguments' => array('system_modules'), 'access arguments' => array('administer site configuration'), ); + + $items['admin/settings/proxy'] = array( + 'title' => 'Proxy Server', + 'description' => 'Configure settings when the site is behind a proxy server.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('system_proxy_settings'), + 'access arguments' => array('administer site configuration'), + 'file' => 'system.admin.inc', + ); + $items['admin/build/modules/list'] = array( 'title' => 'List', 'type' => MENU_DEFAULT_LOCAL_TASK,