From e75d5e813a900d65ad3e853d3f3f214c0536dba7 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli <thomas@roundcube.net> Date: Tue, 03 Jun 2014 12:43:05 -0400 Subject: [PATCH] Simplify CSS boder/background styles for listing elements with focus indicator --- program/steps/utils/modcss.inc | 109 +++++++++++++++++++++++------------------------------- 1 files changed, 47 insertions(+), 62 deletions(-) diff --git a/program/steps/utils/modcss.inc b/program/steps/utils/modcss.inc index 7817795..f3d8d89 100644 --- a/program/steps/utils/modcss.inc +++ b/program/steps/utils/modcss.inc @@ -5,94 +5,79 @@ | program/steps/utils/modcss.inc | | | | This file is part of the Roundcube Webmail client | - | Copyright (C) 2007-2010, Roundcube Dev. - Switzerland | - | Licensed under the GNU GPL | + | Copyright (C) 2007-2014, The Roundcube Dev Team | + | | + | Licensed under the GNU General Public License version 3 or | + | any later version with exceptions for skins & plugins. | + | See the README file for a full license statement. | | | | PURPOSE: | | Modify CSS source from a URL | | | +-----------------------------------------------------------------------+ | Author: Thomas Bruederli <roundcube@gmail.com> | + | Author: Aleksander Machniak <alec@alec.pl> | +-----------------------------------------------------------------------+ - - $Id$ - */ -$source = ''; +$url = preg_replace('![^a-z0-9.-]!i', '', $_GET['_u']); -$url = preg_replace('![^a-z0-9:./\-_?$&=%]!i', '', $_GET['u']); -if ($url === null) { +if ($url === null || !($realurl = $_SESSION['modcssurls'][$url])) { header('HTTP/1.1 403 Forbidden'); - echo $error; - exit; + exit("Unauthorized request"); } - -$a_uri = parse_url($url); -$port = $a_uri['port'] ? $a_uri['port'] : 80; -$host = $a_uri['host']; -$path = $a_uri['path'] . ($a_uri['query'] ? '?'.$a_uri['query'] : ''); // don't allow any other connections than http(s) -if (strtolower(substr($a_uri['scheme'], 0, 4)) != 'http') { +if (!preg_match('~^(https?)://~i', $realurl, $matches)) { header('HTTP/1.1 403 Forbidden'); - echo "Invalid URL"; - exit; + exit("Invalid URL"); } -// try to open socket connection -if (!($fp = fsockopen($host, $port, $errno, $error, 15))) { - header('HTTP/1.1 500 Internal Server Error'); - echo $error; - exit; +if (ini_get('allow_url_fopen')) { + $scheme = strtolower($matches[1]); + $options = array( + $scheme => array( + 'method' => 'GET', + 'timeout' => 15, + ) + ); + + $context = stream_context_create($options); + $source = @file_get_contents($realurl, false, $context); + + // php.net/manual/en/reserved.variables.httpresponseheader.php + $headers = implode("\n", (array) $http_response_header); } +else if (function_exists('curl_init')) { + $curl = curl_init($realurl); + curl_setopt($curl, CURLOPT_TIMEOUT, 15); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15); + curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); + curl_setopt($curl, CURLOPT_ENCODING, ''); + curl_setopt($curl, CURLOPT_HEADER, true); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + $data = curl_exec($curl); -// set timeout for socket -stream_set_timeout($fp, 30); - -// send request -$out = "GET $path HTTP/1.0\r\n"; -$out .= "Host: $host\r\n"; -$out .= "Connection: Close\r\n\r\n"; -fwrite($fp, $out); - -// read response -$header = true; -$headers = array(); -while (!feof($fp)) { - $line = trim(fgets($fp, 4048)); - - if ($header) { - if (preg_match('/^HTTP\/1\..\s+(\d+)/', $line, $regs) - && intval($regs[1]) != 200) { - break; - } - else if (empty($line)) { - $header = false; - } - else { - list($key, $value) = explode(': ', $line); - $headers[strtolower($key)] = $value; - } + if ($data !== false) { + list($headers, $source) = explode("\r\n\r\n", $data, 2); } else { - $source .= "$line\n"; + $headers = false; + $source = false; } } -fclose($fp); +else { + header('HTTP/1.1 403 Forbidden'); + exit("HTTP connections disabled"); +} -// check content-type header and mod styles -$mimetype = strtolower($headers['content-type']); -if (!empty($source) && in_array($mimetype, array('text/css','text/plain'))) { +$ctype_regexp = '~Content-Type:\s+text/(css|plain)~i'; + +if ($source !== false && preg_match($ctype_regexp, $headers)) { header('Content-Type: text/css'); - echo rcmail_mod_css_styles($source, preg_replace('/[^a-z0-9]/i', '', $_GET['c'])); + echo rcube_utils::mod_css_styles($source, preg_replace('/[^a-z0-9]/i', '', $_GET['_c'])); exit; } -else - $error = "Invalid response returned by server"; header('HTTP/1.0 404 Not Found'); -echo $error; -exit; - - +exit("Invalid response returned by server"); -- Gitblit v1.9.1