Sunday, 28 December 2008

Drupal 6.6+ and Proxy related issues


To solve proxy related issues in drupal 6.X follow issues addressed at http://drupal.org/node/7881.

or

Step: 1
++++++
Apply patch: (http://drupal.org/files/issues/proxy6.6.patch)

--- includes/common.inc Wed Oct 22 20:26:02 2008
+++ includes/common.inc Fri Oct 24 10:22:30 2008
@@ -416,6 +416,11 @@
function drupal_http_request($url, $headers = array(), $method = 'GET', $data = NULL, $retry = 3) {
static $self_test = FALSE;
$result = new stdClass();
+
+ //PROXYHACK
+ $proxy_not_required = TRUE;
+ ///PROXYHACK
+
// Try to clear the drupal_http_request_fails variable if it's set. We
// can't tie this call to any error because there is no surefire way to
// tell whether a request has failed, so we add the check to places where
@@ -449,7 +454,19 @@
case 'http':
$port = isset($uri['port']) ? $uri['port'] : 80;
$host = $uri['host'] . ($port != 80 ? ':'. $port : '');
+ //PROXYHACK
+ $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 {
+ ///PROXYHACK
$fp = @fsockopen($uri['host'], $port, $errno, $errstr, 15);
+ //PROXYHACK
+ }
+ ///PROXYHACK
break;
case 'https':
// Note: Only works for PHP 4.3 compiled with OpenSSL.
@@ -472,10 +489,19 @@
}

// Construct the path to act on.
+ //PROXYHACK
+ if ((variable_get('proxy_server', '') != '') && (FALSE == $proxy_not_required)) {
+ $path = $url;
+ }
+ else {
+ ///PROXYHACK
$path = isset($uri['path']) ? $uri['path'] : '/';
if (isset($uri['query'])) {
$path .= '?'. $uri['query'];
}
+ //PROXYHACK
+ }
+ ///PROXYHACK

// Create HTTP request.
$defaults = array(
@@ -492,6 +518,15 @@
$defaults['Authorization'] = 'Authorization: Basic '. base64_encode($uri['user'] . (!empty($uri['pass']) ? ":". $uri['pass'] : ''));
}

+ //PROXYHACK
+ 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";
+ }
+ ///PROXYHACK
+
foreach ($headers as $header => $value) {
$defaults[$header] = $header .': '. $value;
}
@@ -569,6 +604,25 @@
$result->code = $code;
return $result;
}
+//PROXY_HACK
+function is_in_no_proxy_list($host) {
+ $rv = FALSE;
+
+ $proxy_exceptions = variable_get('proxy_exceptions', '');
+ if (FALSE == empty($proxy_exceptions)) {
+ $patterns = explode(",",$proxy_exceptions);
+ foreach ($patterns as $pattern) {
+ $pattern = trim($pattern, " ");
+ if (strstr($host,$pattern)) {
+ $rv = TRUE;
+ break;
+ }
+ }
+ }
+ return $rv;
+}
+///PROXY_HACK
+
/**
* @} End of "HTTP handling".
*/
--- modules/system/system.admin.inc Thu Oct 16 21:23:38 2008
+++ modules/system/system.admin.inc Fri Oct 24 10:19:54 2008
@@ -1362,6 +1362,79 @@
drupal_set_message(t('Caches cleared.'));
}

+//PROXYHACK
+/**
+ * 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'] <>= 65536) {
+ form_set_error('proxy_port', t('The proxy port is invalid. It must be between 0 and 65535.'));
+ }
+ }
+}
+///PROXY_HACK
+
/**
* Form builder; Configure the site file handling.
*
--- modules/system/system.module Wed Oct 22 20:26:02 2008
+++ modules/system/system.module Fri Oct 24 10:20:54 2008
@@ -406,6 +406,16 @@
'access arguments' => array('administer site configuration'),
'file' => 'system.admin.inc',
);
+ //PROXYHACK
+ $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',
+ );
+ ///PROXY_HACK
$items['admin/settings/file-system'] = array(
'title' => 'File system',
'description' => 'Tell Drupal where to store uploaded files and how they are accessed.',
@@ -1877,6 +1887,10 @@
// Check whether we can do any request at all. First get the results for
// a very simple page which has access TRUE set via the menu system. Then,
// try to drupal_http_request() the same page and compare.
+ //PROXYHACK
+ $skip_selftest = variable_get('proxy_skip_selftest', '0');
+ if (0 == $skip_selftest) {
+ ///PROXYHACK
ob_start();
$path = 'admin/reports/request-test';
menu_execute_active_handler($path);
@@ -1884,6 +1898,12 @@
ob_end_clean();
$result = drupal_http_request(url($path, array('absolute' => TRUE)));
$works = isset($result->data) && $result->data == $nothing;
+ //PROXYHACK
+ }
+ else {
+ $works = TRUE;
+ }
+ ///PROXYHACK
variable_set('drupal_http_request_fails', !$works);
return $works;
}

Step:2
++++++
Then download the module "Http Request Fail Reset" from 'http://drupal.org/project/http_request_fail_reset' and enable it.


Step:3
+++++
You will find a 'Proxy Server' link under Home / Administer / Site configuration


Enter proxy details and save your configurations !!!!!!!