]> git.donarmstrong.com Git - roundcube.git/blob - bin/modcss.php
Imported Upstream version 0.2~alpha
[roundcube.git] / bin / modcss.php
1 <?php
2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/bin/modcss.php                                                |
6  |                                                                       |
7  | This file is part of the RoundCube Webmail client                     |
8  | Copyright (C) 2007, RoundCube Dev. - Switzerland                      |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Modify CSS source from a URL                                        |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id:  $
19
20 */
21
22 define('INSTALL_PATH', realpath('./../') . '/');
23 require INSTALL_PATH.'program/include/iniset.php';
24
25 $source = "";
26 if ($url = preg_replace('/[^a-z0-9.-_\?\$&=%]/i', '', $_GET['u']))
27 {
28         $a_uri = parse_url($url);
29         $port = $a_uri['port'] ? $a_uri['port'] : 80;
30         $host = $a_uri['host'];
31         $path = $a_uri['path'] . ($a_uri['query'] ? '?'.$a_uri['query'] : '');
32
33
34         if ($fp = fsockopen($host, $port, $errno, $errstr, 30))
35         {
36                 $out = "GET $path HTTP/1.0\r\n";
37                 $out .= "Host: $host\r\n";
38                 $out .= "Connection: Close\r\n\r\n";
39                 fwrite($fp, $out);
40
41                 $header = true;
42                 while (!feof($fp))
43                 {
44                         $line = trim(fgets($fp, 4048));
45                         
46                         if ($header && preg_match('/^HTTP\/1\..\s+(\d+)/', $line, $regs) && intval($regs[1]) != 200)
47                                 break;
48                         else if (empty($line) && $header)
49                                 $header = false;
50                         else if (!$header)
51                                 $source .= "$line\n";
52                 }
53                 fclose($fp);
54          }
55 }
56
57 if (!empty($source))
58 {
59         header("Content-Type: text/css");
60         echo rcmail_mod_css_styles($source, preg_replace('/[^a-z0-9]/i', '', $_GET['c']), $url);
61 }
62 else
63         header("HTTP/1.0 404 Not Found");
64
65 ?>