4 +-----------------------------------------------------------------------+
5 | program/steps/utils/modcss.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2007-2011, Roundcube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Modify CSS source from a URL |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: modcss.inc 4509 2011-02-09 10:51:50Z thomasb $
24 $url = preg_replace('![^a-z0-9.-]!i', '', $_GET['_u']);
25 if ($url === null || !($realurl = $_SESSION['modcssurls'][$url])) {
26 header('HTTP/1.1 403 Forbidden');
27 echo "Unauthorized request";
31 $a_uri = parse_url($realurl);
32 $port = $a_uri['port'] ? $a_uri['port'] : 80;
33 $host = $a_uri['host'];
34 $path = $a_uri['path'] . ($a_uri['query'] ? '?'.$a_uri['query'] : '');
36 // don't allow any other connections than http(s)
37 if (strtolower(substr($a_uri['scheme'], 0, 4)) != 'http') {
38 header('HTTP/1.1 403 Forbidden');
43 // try to open socket connection
44 if (!($fp = fsockopen($host, $port, $errno, $error, 15))) {
45 header('HTTP/1.1 500 Internal Server Error');
50 // set timeout for socket
51 stream_set_timeout($fp, 30);
54 $out = "GET $path HTTP/1.0\r\n";
55 $out .= "Host: $host\r\n";
56 $out .= "Connection: Close\r\n\r\n";
63 $line = trim(fgets($fp, 4048));
66 if (preg_match('/^HTTP\/1\..\s+(\d+)/', $line, $regs)
67 && intval($regs[1]) != 200) {
70 else if (empty($line)) {
74 list($key, $value) = explode(': ', $line);
75 $headers[strtolower($key)] = $value;
84 // check content-type header and mod styles
85 $mimetype = strtolower($headers['content-type']);
86 if (!empty($source) && in_array($mimetype, array('text/css','text/plain'))) {
87 header('Content-Type: text/css');
88 echo rcmail_mod_css_styles($source, preg_replace('/[^a-z0-9]/i', '', $_GET['_c']));
92 $error = "Invalid response returned by server";
94 header('HTTP/1.0 404 Not Found');