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