Revision e3349f9c
Added by Scott Ullrich over 16 years ago
usr/local/www/widgets/widgets/picture.widget.php | ||
---|---|---|
1 |
<?php |
|
2 |
/* |
|
3 |
$Id$ |
|
4 |
Copyright 2009 Scott Ullrich |
|
5 |
Part of pfSense widgets (www.pfsense.com) |
|
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without |
|
8 |
modification, are permitted provided that the following conditions are met: |
|
9 |
|
|
10 |
1. Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 |
|
|
13 |
2. Redistributions in binary form must reproduce the above copyright |
|
14 |
notice, this list of conditions and the following disclaimer in the |
|
15 |
documentation and/or other materials provided with the distribution. |
|
16 |
|
|
17 |
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
18 |
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
|
19 |
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
20 |
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
|
21 |
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
22 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
23 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
24 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
25 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 |
POSSIBILITY OF SUCH DAMAGE. |
|
27 |
*/ |
|
28 |
|
|
29 |
|
|
30 |
require_once("guiconfig.inc"); |
|
31 |
require_once("pfsense-utils.inc"); |
|
32 |
require_once("functions.inc"); |
|
33 |
|
|
34 |
if($_GET['getpic']=="true") { |
|
35 |
$pic_type_s = split("\.", $config['widgets']['picturewidget_filename']); |
|
36 |
$pic_type = $pic_type_s[1]; |
|
37 |
if($config['widgets']['picturewidget']) |
|
38 |
$data = base64_decode($config['widgets']['picturewidget']); |
|
39 |
header("Content-Disposition: inline; filename=\"{$config['widgets']['picturewidget_filename']}\""); |
|
40 |
header("Content-Type: image/{$pic_type}"); |
|
41 |
header("Content-Length: " . strlen($data)); |
|
42 |
echo $data; |
|
43 |
exit; |
|
44 |
} |
|
45 |
|
|
46 |
if($_POST) { |
|
47 |
if (is_uploaded_file($_FILES['pictfile']['tmp_name'])) { |
|
48 |
/* read the file contents */ |
|
49 |
$fd_pic = fopen($_FILES['pictfile']['tmp_name'], "rb"); |
|
50 |
while ( ($buf=fread( $fd_pic, 8192 )) != '' ) { |
|
51 |
// Here, $buf is guaranted to contain data |
|
52 |
$data .= $buf; |
|
53 |
} |
|
54 |
fclose($fd_pic); |
|
55 |
if(!$data) { |
|
56 |
log_error("Warning, could not read file " . $_FILES['pictfile']['tmp_name']); |
|
57 |
die("Cold not read temporary file"); |
|
58 |
} else { |
|
59 |
$picname = basename($_FILES['uploadedfile']['name']); |
|
60 |
$config['widgets']['picturewidget'] = base64_encode($data); |
|
61 |
$config['widgets']['picturewidget_filename'] = $_FILES['pictfile']['name']; |
|
62 |
write_config("Picture widget saved via Dashboard."); |
|
63 |
Header("Location: /index.php"); |
|
64 |
exit; |
|
65 |
} |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
?> |
|
70 |
|
|
71 |
<input type="hidden" id="picture-config" name="picture-config" value=""> |
|
72 |
|
|
73 |
<div id="picture-settings" name="picture-settings" class="widgetconfigdiv" style="display:none;"> |
|
74 |
</form> |
|
75 |
<form action="/widgets/widgets/picture.widget.php" method="post" name="iforma" enctype="multipart/form-data"> |
|
76 |
<input name="pictfile" type="file" class="formfld unknown" id="pictfile" size="20"></p> |
|
77 |
<input id="submita" name="submita" type="submit" class="formbtn" value="Upload" /><br/> |
|
78 |
NOTE: Best image size is 320x320 or smaller. |
|
79 |
</form> |
|
80 |
</div> |
|
81 |
|
|
82 |
<div id="picture-widgets" style="padding: 5px"> |
|
83 |
<a href='/widgets/widgets/picture.widget.php?getpic=true' target='_new'> |
|
84 |
<img border=0 width="350" height="350" src="/widgets/widgets/picture.widget.php?getpic=true"> |
|
85 |
</a> |
|
86 |
</div> |
|
87 |
|
|
88 |
<script language="javascript" type="text/javascript"> |
|
89 |
selectIntLink = "picture-configure"; |
|
90 |
textlink = document.getElementById(selectIntLink); |
|
91 |
textlink.style.display = "inline"; |
|
92 |
</script> |
Also available in: Unified diff
Adding picture viewer widget. Add a picture of your firewall, or a network
diagram, or a picture of your girlfriend... OR?