1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 /* Basic setup, remove eventually registered sessions */
24 @require_once ("../../../include/php_setup.inc");
25 @require_once ("functions.inc");
26 error_reporting (0);
27 session::start();
28 session::set('errorsAlreadyPosted',array());
30 /* Logged in? Simple security check */
31 if (!session::is_set('ui')){
32 new log("security","users/viewFaxEntries","",array(),"Error: getfax.php called without session") ;
33 header ("Location: ../../index.php");
34 exit;
35 }
36 $ui= session::is_set("ui");
38 /* Get loaded servers */
39 foreach (array("FAX_SERVER", "FAX_LOGIN", "FAX_PASSWORD") as $val){
40 if (session::is_set($val)){
41 $$val= session::get($val);
42 }
43 }
45 /* Load fax entry */
46 $config= session::get('config');
47 restore_error_handler();
49 $cfg= $config->data['SERVERS']['FAX'];
50 $link = mysql_pconnect($cfg['SERVER'], $cfg['LOGIN'], $cfg['PASSWORD'])
51 or die(_("Could not connect to database server!"));
53 mysql_select_db("gofax") or die(_("Could not select database!"));
56 /* Permission to view? */
57 $query = "SELECT id,uid FROM faxlog WHERE id = '".validate(stripcslashes($_GET['id']))."'";
58 $result = mysql_query($query) or die(_("Database query failed!"));
59 $line = mysql_fetch_array($result, MYSQL_ASSOC);
61 $query = "SELECT id,fax_data FROM faxdata WHERE id = '".validate(stripcslashes($_GET['id']))."'";
62 $result = mysql_query($query) or die(_("Database query failed!"));
64 /* Load pic */
65 $data = mysql_result ($result, 0, "fax_data");
66 mysql_close ($link);
70 if (!isset($_GET['download'])){
72 /* display picture */
73 header("Content-type: image/png");
75 /* Fallback if there's no image magick support in PHP */
76 if (!function_exists("imagick_blob2image")){
78 /* Write to temporary file and call convert, because TIFF sucks */
79 $tmpfname = tempnam ("/tmp", "GOsa");
80 $temp= fopen($tmpfname, "w");
81 fwrite($temp, $data);
82 fclose($temp);
84 /* Read data written by convert */
85 $output= "";
86 $query= "convert -size 420x594 $tmpfname -resize 420x594 +profile \"*\" png:- 2> /dev/null";
87 $sh= popen($query, 'r');
88 $data= "";
89 while (!feof($sh)){
90 $data.= fread($sh, 4096);
91 }
92 pclose($sh);
94 unlink($tmpfname);
96 } else {
98 /* Loading image */
99 if(!$handle = imagick_blob2image($data)) {
100 new log("view","faxreport/faxreport","",array(), "Cannot load fax image") ;
101 }
103 /* Converting image to PNG */
104 if(!imagick_convert($handle,"PNG")) {
105 new log("view","faxreport/faxreport","",array(),"Cannot convert fax image to png") ;
106 }
108 /* Resizing image to 420x594 and blur */
109 if(!imagick_resize($handle,420,594,IMAGICK_FILTER_GAUSSIAN,1)){
110 new log("view","faxreport/faxreport","",array(),"Cannot resize fax image") ;
111 }
113 /* Creating binary Code for the Image */
114 if(!$data = imagick_image2blob($handle)){
115 new log("view","faxreport/faxreport","",array(),"Reading fax image image failed") ;
116 }
117 }
119 } else {
121 /* force download dialog */
122 header("Content-type: application/tiff\n");
123 if (preg_match('/MSIE 5.5/', $HTTP_USER_AGENT) ||
124 preg_match('/MSIE 6.0/', $HTTP_USER_AGENT)) {
125 header('Content-Disposition: filename="fax.tif"');
126 } else {
127 header('Content-Disposition: attachment; filename="fax.tif"');
128 }
129 header("Content-transfer-encoding: binary\n");
130 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
131 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
132 header("Cache-Control: no-cache");
133 header("Pragma: no-cache");
134 header("Cache-Control: post-check=0, pre-check=0");
136 }
138 // Get ALL valid FAX-Accounts and their dns, this allows us to perform correct
139 // permissions checks later.
140 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(objectClass=goFaxAccount)(uid=*))";
141 $tmp= get_list($filter, "users/viewFaxEntries", $config->current['BASE'],
142 array("uid"), GL_SUBSEARCH | GL_NO_ACL_CHECK);
143 $uidToDN = array();
144 $uid = $line['uid'];
145 foreach($tmp as $attrs){
146 $uidToDN[$attrs['uid'][0]] = $attrs['dn'];
147 }
149 // Detect dn to check for
150 $dn = $config->current['BASE'];
151 if(isset($uidToDN[$uid])){
152 $dn = $uidToDN[$uid];
153 }
155 // We do not have any ACLs for this entry, so continue.
156 $ui = session::get('ui');
157 $acls = $ui->get_permissions($dn,"users/viewFaxEntries","detailedView");
158 if(!preg_match("/r/",$acls)){
159 $data = file_get_contents("../../images/lists/locked.png");
160 }
161 /* print the tiff image and close the connection */
162 echo "$data";
164 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
165 ?>