18 require_once SQ_LIB_PATH.
'/config/config.inc';
19 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
39 var $config_vars = Array(
41 'SQ_PA_ENABLED' => Array(
'editable' => 1,
'default' => FALSE),
42 'SQ_PA_HOSTNAME' => Array(
'editable' => 1,
'default' =>
''),
43 'SQ_PA_PORT' => Array(
'editable' => 1,
'default' =>
''),
44 'SQ_PA_USERNAME' => Array(
'editable' => 1,
'default' =>
''),
45 'SQ_PA_PASSWORD' => Array(
'editable' => 1,
'default' =>
''),
46 'SQ_PA_ALTERNATIVES' => Array(
'editable' => 1,
'default' =>
'a:0:{}'),
47 'SQ_PROXY_URL_PORT_STRIP' => Array(
'editable' => 1,
'default' => FALSE),
49 'SQ_SSLA_ENABLED' => Array(
'editable' => 1,
'default' => FALSE),
50 'SQ_SSLA_MATCH' => Array(
'editable' => 1,
'default' =>
'ip'),
51 'SQ_SSLA_IP' => Array(
'editable' => 1,
'default' =>
''),
52 'SQ_SSLA_HEADER_NAME' => Array(
'editable' => 1,
'default' =>
''),
53 'SQ_SSLA_HEADER_VALUE' => Array(
'editable' => 1,
'default' =>
''),
54 'SQ_SSLA_FORCE_SECURE' => Array(
'editable' => 1,
'default' => FALSE),
64 parent::__construct();
65 $this->config_file = SQ_DATA_PATH.
'/private/conf/proxy_authentication.inc';
84 parent::paintBackend($o);
87 $class = get_class_lower($this);
89 $o->openSection(
'Primary Proxy Configuration');
90 $o->openField(translate(
'proxy_authentication_status'));
92 require_once(SQ_INCLUDE_PATH.
'/general_occasional.inc');
93 $socket = open_socket_connection(
'http://matrix.squiz.net', $errno, $errstr);
94 if ($socket !== FALSE && !is_null($socket)) {
95 $response = fread($socket, 128);
96 if (preg_match(
'|407 proxy authentication required|i', $response)) {
97 echo
'<font color="red"><strong>'.translate(
'proxy_authentication_failed').
'</strong></font>';
99 echo
'<font color="green"><strong>'.translate(
'proxy_authentication_passed').
'</strong></font>';
103 echo
'<strong class="sq-backend-warning">'.translate(
'proxy_configuration_problem').
'</font>';
106 echo
'<strong>'.translate(
'proxy_authentication_disabled').
'</font>';
110 $o->openField(translate(
'proxy_authentication_enable'));
112 combo_box($class.
'[SQ_PA_ENABLED]', Array(translate(
'no'), translate(
'yes')), FALSE, SQ_PA_ENABLED);
114 echo (SQ_PA_ENABLED ? translate(
'yes') : translate(
'no'));
117 $o->openField(translate(
'hostname'));
119 text_box($class.
'[SQ_PA_HOSTNAME]', SQ_PA_HOSTNAME, 25);
124 $o->openField(translate(
'port'));
126 text_box($class.
'[SQ_PA_PORT]', SQ_PA_PORT, 5);
131 $o->openField(translate(
'username'));
133 text_box($class.
'[SQ_PA_USERNAME]', SQ_PA_USERNAME, 15);
138 $o->openField(translate(
'password'));
140 password_box($class.
'[SQ_PA_PASSWORD]', base64_decode(SQ_PA_PASSWORD), 15);
142 if (strlen(SQ_PA_PASSWORD)) {
143 echo translate(
'password_not_shown');
150 $o->openSection(translate(
'proxy_url_manipulation'));
152 $o->openField(translate(
'proxy_url_strip_port'));
154 combo_box($class.
'[SQ_PROXY_URL_PORT_STRIP]', Array(translate(
'no'), translate(
'yes')), FALSE, SQ_PROXY_URL_PORT_STRIP);
156 echo (SQ_PROXY_URL_PORT_STRIP ? translate(
'yes') : translate(
'no'));
158 $o->note(translate(
'proxy_url_strip_port_note'));
163 $o->openSection(
'Alternative Proxy Configuration');
167 $o->sectionNote(
'Alternative proxies will be used if they are set to be Active, and their URL pattern matches the URL being requested through the proxy. Proxies are matched from top to bottom; only the first proxy that matches will be used.');
168 $o->closeSection(
'');
170 $o->openSection(
'SSL Accelerator Configuration');
171 $o->openField(translate(
'ssl_accelerator_handling_enabled'));
173 combo_box($class.
'[SQ_SSLA_ENABLED]', Array(translate(
'no'), translate(
'yes')), FALSE, SQ_SSLA_ENABLED);
175 echo (SQ_SSLA_ENABLED ? translate(
'yes') : translate(
'no'));
177 $o->note(translate(
'ssl_accelerator_handling_enabled_note'));
180 $o->openField(translate(
'ssl_accelerator_match_method'));
182 'ip' => translate(
'ssl_accelerator_match_method_ip'),
183 'header' => translate(
'ssl_accelerator_match_method_header'),
184 'both' => translate(
'ssl_accelerator_match_method_both'),
187 combo_box($class.
'[SQ_SSLA_MATCH]', $options, FALSE, SQ_SSLA_MATCH);
189 echo $options[SQ_SSLA_MATCH];
191 $o->note(translate(
'ssl_accelerator_match_method_note'));
194 $o->openField(translate(
'ssl_accelerator_ip_address'));
196 text_box($class.
'[SQ_SSLA_IP]', SQ_SSLA_IP, 15);
200 $o->note(translate(
'ssl_accelerator_ip_address_note'));
203 $o->openField(translate(
'ssl_accelerator_header_name'));
205 text_box($class.
'[SQ_SSLA_HEADER_NAME]', SQ_SSLA_HEADER_NAME, 15);
207 echo SQ_SSLA_HEADER_NAME;
209 $o->note(translate(
'ssl_accelerator_header_name_note'));
212 $o->openField(translate(
'ssl_accelerator_header_value'));
214 text_box($class.
'[SQ_SSLA_HEADER_VALUE]', SQ_SSLA_HEADER_VALUE, 15);
216 echo SQ_SSLA_HEADER_VALUE;
218 $o->note(translate(
'ssl_accelerator_header_value_note'));
221 $o->openField(translate(
'ssl_accelerator_force_secure'));
223 combo_box($class.
'[SQ_SSLA_FORCE_SECURE]', Array(translate(
'no'), translate(
'yes')), FALSE, SQ_SSLA_FORCE_SECURE);
225 echo (SQ_SSLA_FORCE_SECURE ? translate(
'yes') : translate(
'no'));
227 $o->note(translate(
'ssl_accelerator_force_secure_note'));
230 $o->sectionNote(translate(
'ssl_accelerator_section_note'));
233 if ($write_access) $o->commitButton(
'', TRUE);
247 $all_proxies = SQ_PA_ALTERNATIVES;
248 if (trim($all_proxies) !==
'') {
249 $all_proxies = unserialize(SQ_PA_ALTERNATIVES);
251 $all_proxies = Array();
257 $pattern_not_options = Array(
268 $pattern_type_options = Array(
270 'begins' =>
'begin with',
271 'ends' =>
'end with',
272 'contains' =>
'contain',
280 $pattern_type_desc = Array(
281 'equals' =>
'equals',
282 'begins' =>
'begins with',
283 'ends' =>
'ends with',
284 'contains' =>
'contains',
288 $class = get_class_lower($this);
291 foreach ($all_proxies as $proxy_key => $proxy_details) {
296 echo text_box($class.
'_alternative[proxy_url]['.$proxy_key.
']', array_get_index($proxy_details,
'proxy_url',
''), 30);
297 $o->
note(translate(
'proxy_leave_blank'));
299 echo (array_get_index($proxy_details,
'proxy_url',
'') ===
'') ?
'<i>' . translate(
'proxy_none_set') .
'</i>' : array_get_index($proxy_details,
'proxy_url',
'');
304 echo int_text_box($class.
'_alternative[proxy_port]['.$proxy_key.
']', array_get_index($proxy_details,
'proxy_port',
''), FALSE, 7, 0, 65535);
306 echo array_get_index($proxy_details,
'proxy_port',
'');
311 echo text_box($class.
'_alternative[username]['.$proxy_key.
']', array_get_index($proxy_details,
'username',
''), 10);
313 echo array_get_index($proxy_details,
'username',
'');
318 echo password_box($class.
'_alternative[password]['.$proxy_key.
']', base64_decode(array_get_index($proxy_details,
'password',
'')), 10);
320 if (trim(array_get_index($proxy_details,
'password',
'')) !==
'') {
321 ?><em>Password not shown</em><?php
328 echo combo_box($class.
'_alternative[pattern_not]['.$proxy_key.
']', $pattern_not_options, FALSE, array_get_index($proxy_details,
'pattern_not',
'0'));
330 echo combo_box($class.
'_alternative[pattern_type]['.$proxy_key.
']', $pattern_type_options, FALSE, array_get_index($proxy_details,
'pattern_type',
'equals'));
332 text_box($class.
'_alternative[pattern_url]['.$proxy_key.
']', array_get_index($proxy_details,
'pattern_url',
''), 30);
334 echo translate(
'comparison'.(array_get_index($proxy_details,
'pattern_not',
'0') ?
'_not_' :
'_').array_get_index($proxy_details,
'pattern_type',
'equals'),
'URL',
'"'.array_get_index($proxy_details,
'pattern_url',
'').
'"');
337 $o->
openField(translate(
'active_question'));
339 echo check_box($class.
'_alternative[active]['.$proxy_key.
']', 1, array_get_index($proxy_details,
'active', TRUE));
341 echo array_get_index($proxy_details,
'active', TRUE);
345 $o->
openField(translate(
'delete_question'));
346 echo check_box($class.
'_alternative[delete]['.$proxy_key.
']', 1, FALSE);
355 echo check_box($class.
'_alternative[add]', 1, FALSE);
365 parent::processBackend($o);
370 public function processAlternativeProxies(&$vars)
374 if (defined(
'SQ_PA_ALTERNATIVES')) {
375 $all_proxies = SQ_PA_ALTERNATIVES;
376 if (trim($all_proxies) !==
'') {
377 $all_proxies = unserialize(SQ_PA_ALTERNATIVES);
379 $all_proxies = Array();
382 $all_proxies = Array();
385 $class = get_class_lower($this);
387 $alt_post = array_get_index($_POST, $class.
'_alternative', Array());
389 if (!empty($alt_post)) {
390 $deletes = array_get_index($alt_post,
'delete', Array());
391 foreach ($deletes as $key => $value) {
392 unset($all_proxies[$key]);
395 $actives = array_get_index($alt_post,
'active', Array());
396 foreach ($all_proxies as $key => $value) {
397 $all_proxies[$key][
'active'] = isset($actives[$key]);
399 $all_proxies[$key][
'proxy_url'] = $alt_post[
'proxy_url'][$key];
400 $all_proxies[$key][
'proxy_port'] = $alt_post[
'proxy_port'][$key];
401 $all_proxies[$key][
'username'] = $alt_post[
'username'][$key];
402 $all_proxies[$key][
'password'] = base64_encode($alt_post[
'password'][$key]);
403 $all_proxies[$key][
'pattern_not'] = $alt_post[
'pattern_not'][$key];
404 $all_proxies[$key][
'pattern_type'] = $alt_post[
'pattern_type'][$key];
405 $all_proxies[$key][
'pattern_url'] = $alt_post[
'pattern_url'][$key];
410 $add = array_get_index($alt_post,
'add', 0);
414 if (!empty($all_proxies)) {
415 $new_key = max(array_keys($all_proxies)) + 1;
419 $all_proxies[$new_key] = Array();
422 $vars[
'SQ_PA_ALTERNATIVES'] = serialize($all_proxies);
439 function save($vars, $backup_existing=FALSE)
442 if (file_exists($this->config_file)) {
443 require_once $this->config_file;
446 $this->processAlternativeProxies($vars);
449 if (isset($vars[
'SQ_PA_PASSWORD']) && !empty($vars[
'SQ_PA_PASSWORD'])) {
450 $vars[
'SQ_PA_PASSWORD'] = base64_encode($vars[
'SQ_PA_PASSWORD']);
453 return parent::save($vars, $backup_existing);