File: showblob.php

package info (click to toggle)
ibwebadmin 0.98-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,916 kB
  • ctags: 1,950
  • sloc: php: 12,454; makefile: 7
file content (128 lines) | stat: -rw-r--r-- 3,851 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
// File           showblob.php / ibWebAdmin
// Purpose        displays the blob specified through the GET-varibles
// Author         Lutz Brueckner <irie@gmx.de>
// Copyright      (c) 2000, 2001, 2002, 2003, 2004 by Lutz Brueckner,
//                published under the terms of the GNU General Public Licence v.2,
//                see file LICENCE for details
// Created        <01/10/21 13:25:50 lb>
//
// $Id: showblob.php,v 1.13 2004/03/07 17:08:37 lbrueckner Exp $


// GET-Variables specifying the blob to display:
//
//       $table: table containing the blob
//       $col  : column containing the blob
//       $where: sql-where-clause specifying the primary keys to fetch the blob

require('inc/script_start.inc.php');

globalize_session_vars();

if ($HTTP_SERVER_VARS['REQUEST_METHOD'] == 'GET') {
    $table = $HTTP_GET_VARS['table'];
    $col   = $HTTP_GET_VARS['col'];
    $where = urldecode($HTTP_GET_VARS['where']);
}
else { 
    $table = $HTTP_POST_VARS['table'];
    $col   = $HTTP_POST_VARS['col'];
    $where = $HTTP_POST_VARS['where'];

    $s_watch_blobas[$col] = $HTTP_POST_VARS['blobtype'];
}
if (get_magic_quotes_gpc()) {
    $where = stripslashes($where);
}

$imageurl =  'showimage.php?where='.urlencode($where).'&table='.$table.'&col='.$col;
$imageurl .= '&'.uniqid('UNIQ_');

$blob = get_blob_content(sprintf('SELECT %s FROM %s %s', $col, $table, $where));

$title = build_title("Blob from $table $where", FALSE);
echo html_head($title);

echo '<body bgcolor="'.$s_cust['color']['area']."\">\n";
echo js_window_resize(BLOB_WINDOW_WIDTH, BLOB_WINDOW_HEIGHT);
echo '<form method="post" action="'.$HTTP_SERVER_VARS['PHP_SELF'].'" name="showblob_form">'."\n";
hidden_session_field();
hidden_field('table', $table);
hidden_field('col', $col);
hidden_field('where', $where);

echo "<table>\n<tr>\n<td>\n";
echo get_selectlist('blobtype', $blob_types, $s_watch_blobas[$col], TRUE);
echo "</td>\n<td>\n";
echo '<input type="submit" name="change_blobtype" value="Change Type">'."\n";
echo "</td>\n<td width=\"50\">\n</td>\n<td>\n";
echo '<input type="button" value="Close" onClick="self.close()">'."\n";
echo "</td>\n</tr>\n<table>\n";
echo "</form>\n";

$blobas = (isset($s_watch_blobas[$col])  &&  $s_watch_blobas[$col] != '') ? $s_watch_blobas[$col] : 'hex';
switch ($blobas) {
    case 'png':
    case 'jpg':
    case 'gif':
        echo '<img src="'.$imageurl."\">\n";
        break;
    case 'text':
        echo '<pre align="left">'.$blob."</pre>\n";
        break;
    case 'html':
        echo $blob;
        break;
    case 'hex':
        echo hex_view($blob);
        break;
}

echo html_bottom();


function &hex_view(&$data) {
    global $s_cust;

    $len   = strlen($data);
    $lines = ceil($len / 16);
    $offset = $values = $ascii = '';
    $p = 0;
    for ($i=1; $i<=$lines; $i++) {
        $offset .= sprintf('%08x', $p);
        
        for ($j=0; $j<16; $j++) {
            if ($p > $len -1) {
                break;
            }
            $values .= sprintf('%02x', ord($data[$p])).'&nbsp;';
            $ascii  .= hex2ascii($data[$p]);
            $p++;
        }

        $offset .= "<br>\n";
        $values .= "<br>\n";
        $ascii  .= "<br>\n";
    }

     return "<table>\n<tr>\n"
         ."<td>\n<table>\n<tr>\n<td bgcolor=\"".$s_cust['color']['area']."\" class=\"hex\">\n"
         .$offset
         ."</td>\n</tr>\n</table>\n</td>\n"
         ."<td>\n<table>\n<tr>\n<td class=\"hex\">\n"
         .$values
         ."</td>\n</tr>\n</table>\n</td>\n"
         ."<td>\n<table>\n<tr>\n<td bgcolor=\"".$s_cust['color']['area']."\" class=\"hex\">\n"
         .$ascii
         ."</td>\n</tr>\n</table>\n</td>\n"
         ."</tr>\n</table>\n";
}


function hex2ascii($val) {

    return (ord($val) > 31  && ord($val) < 128) ? str_replace(' ', '&nbsp;', htmlspecialchars($val)) : '.';
}

?>