Projet

Général

Profil

Télécharger (3,61 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / widgets / widgets / picture.widget.php @ 6f3d2063

1
<?php
2
/*
3
        $Id$
4
        Copyright 2009 Scott Ullrich
5
        Part of pfSense widgets (https://www.pfsense.org)
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
$nocsrf = true;
30

    
31
require_once("guiconfig.inc");
32
require_once("pfsense-utils.inc");
33
require_once("functions.inc");
34

    
35
if($_GET['getpic']=="true") {
36
	$pic_type_s = explode(".", $config['widgets']['picturewidget_filename']);
37
	$pic_type = $pic_type_s[1];
38
	if($config['widgets']['picturewidget'])
39
		$data = base64_decode($config['widgets']['picturewidget']);
40
	header("Content-Disposition: inline; filename=\"{$config['widgets']['picturewidget_filename']}\"");
41
	header("Content-Type: image/{$pic_type}");
42
	header("Content-Length: " . strlen($data));
43
	echo $data;
44
	exit;
45
}
46

    
47
if($_POST) {
48
	if (is_uploaded_file($_FILES['pictfile']['tmp_name'])) {
49
		/* read the file contents */
50
		$fd_pic = fopen($_FILES['pictfile']['tmp_name'], "rb");
51
		while ( ($buf=fread( $fd_pic, 8192 )) != '' ) {
52
		    // Here, $buf is guaranteed to contain data
53
		    $data .= $buf;
54
		}
55
		fclose($fd_pic);
56
		if(!$data) {
57
			log_error("Warning, could not read file " . $_FILES['pictfile']['tmp_name']);
58
			die("Could not read temporary file");
59
		} else {
60
			$picname = basename($_FILES['uploadedfile']['name']);
61
			$config['widgets']['picturewidget'] = base64_encode($data);
62
			$config['widgets']['picturewidget_filename'] = $_FILES['pictfile']['name'];
63
			write_config("Picture widget saved via Dashboard.");
64
			header("Location: /index.php");
65
			exit;
66
		}
67
	}
68
}
69

    
70
?>
71

    
72
<input type="hidden" id="picture-config" name="picture-config" value="" />
73

    
74
<div id="picture-settings" class="widgetconfigdiv" style="display:none;">
75
	<form action="/widgets/widgets/picture.widget.php" method="post" name="iforma" enctype="multipart/form-data">
76
		<input name="pictfile" type="file" class="formbtn" id="pictfile" size="20" />
77
		<input id="submita" name="submita" type="submit" class="formbtn" value="Upload" />
78
	</form>
79
</div>
80

    
81
<div id="picture-widgets" style="padding: 5px">
82
	<a href='/widgets/widgets/picture.widget.php?getpic=true' target='_blank'>
83
		<img border="0" width="100%" height="100%" src="/widgets/widgets/picture.widget.php?getpic=true" alt="picture" />
84
	</a>
85
</div>
86

    
87
<!-- needed to show the settings widget icon -->
88
<script type="text/javascript">
89
//<![CDATA[
90
	selectIntLink = "picture-configure";
91
	textlink = document.getElementById(selectIntLink);
92
	textlink.style.display = "inline";
93
//]]>
94
</script>
(14-14/21)