aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/develop/check_flash_bbcodes.php
blob: 6e1b415bb67d7e445b823237957421b9dc50f0ec (plain)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/

/**
* This script will check your database for potentially dangerous flash BBCode tags
*/

//
// Security message:
//
// This script is potentially dangerous.
// Remove or comment the next line (die(".... ) to enable this script.
// Do NOT FORGET to either remove this script or disable it after you have used it.
//
die("Please read the first lines of this script for instructi
Diffstat (limited to 'perl-install/printerdrake.pm')
-rw-r--r--perl-install/printerdrake.pm401
1 files changed, 242 insertions, 159 deletions
diff --git a/perl-install/printerdrake.pm b/perl-install/printerdrake.pm
index bd74efba6..a6a2061f1 100644
--- a/perl-install/printerdrake.pm
+++ b/perl-install/printerdrake.pm
@@ -5,7 +5,6 @@ use strict;
use common qw(:common :file :functional :system);
use detect_devices;
-use run_program;
use commands;
use modules;
use network;
@@ -16,157 +15,147 @@ use printer;
sub getinfo($) {
my ($prefix) = @_;
- my $entry = {};
+ my $printer = {};
printer::set_prefix($prefix);
- printer::read_configured_queue($entry);
-
- add2hash($entry, {
- want => 0,
- complete => 0,
- str_type => $printer::printer_type_default,
- QUEUE => "lp",
- SPOOLDIR => "/var/spool/lpd/lp",
- DBENTRY => "PostScript",
- PAPERSIZE => "legal",
- CRLF => 0,
- AUTOSENDEOF => 1,
-
- DEVICE => "/dev/lp0",
-
- REMOTEHOST => "",
- REMOTEQUEUE => "",
-
- NCPHOST => "", #-"printerservername",
- NCPQUEUE => "", #-"queuename",
- NCPUSER => "", #-"user",
- NCPPASSWD => "", #-"pass",
-
- SMBHOST => "", #-"hostname",
- SMBHOSTIP => "", #-"1.2.3.4",
- SMBSHARE => "", #-"printername",
- SMBUSER => "", #-"user",
- SMBPASSWD => "", #-"passowrd",
- SMBWORKGROUP => "", #-"AS3",
- });
- $entry;
+ printer::read_configured_queue($printer);
+
+ add2hash($printer, {
+ want => 0,
+ complete => 0,
+ str_type => $printer::printer_type_default,
+ QUEUE => "lp",
+ SPOOLDIR => "/var/spool/lpd/lp",
+ DBENTRY => "PostScript",
+ PAPERSIZE => "letter",
+ ASCII_TO_PS => undef,
+ CRLF => undef,
+ NUP => 1,
+ RTLFTMAR => 18,
+ TOPBOTMAR => 18,
+ AUTOSENDEOF => 1,
+
+ DEVICE => "/dev/lp0",
+
+ REMOTEHOST => "",
+ REMOTEQUEUE => "",
+
+ NCPHOST => "", #-"printerservername",
+ NCPQUEUE => "", #-"queuename",
+ NCPUSER => "", #-"user",
+ NCPPASSWD => "", #-"pass",
+
+ SMBHOST => "", #-"hostname",
+ SMBHOSTIP => "", #-"1.2.3.4",
+ SMBSHARE => "", #-"printername",
+ SMBUSER => "", #-"user",
+ SMBPASSWD => "", #-"passowrd",
+ SMBWORKGROUP => "", #-"AS3",
+ });
+ $printer;
}
sub copy_printer_params($$) {
my ($from, $to) = @_;
-
- foreach (keys %$from) {
- $to->{$_} = $fr $ids = get_table_flash_bbcode_pkids($table_name, $id_field, $content_field, $uid_field, $bitfield_field); $size = sizeof($ids); if ($size) { echo "Found $size potentially dangerous flash bbcodes.\n"; echo "$id_field: " . implode(', ', $ids) . "\n"; } else { echo "No potentially dangerous flash bbcodes found.\n"; } echo "\n"; } function get_table_flash_bbcode_pkids($table_name, $id_field, $content_field, $uid_field, $bitfield_field) { global $db; $ids = array(); $sql = "SELECT $id_field, $content_field, $uid_field, $bitfield_field FROM $table_name WHERE $content_field LIKE '%[/flash:%' AND $bitfield_field <> ''"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $uid = $row[$uid_field]; // thanks support toolkit $content = html_entity_decode_utf8($row[$content_field]); set_var($content, $content, 'string', true); $content = utf8_normalize_nfc($content); $bitfield_data = $row[$bitfield_field]; if (!is_valid_flash_bbcode($content, $uid) && has_flash_enabled($bitfield_data)) { $ids[] = (int) $row[$id_field]; } } $db->sql_freeresult($result); return $ids; } function get_flash_regex($uid) { return "#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#"; } // extract all valid flash bbcodes // check if the bbcode content is a valid URL for each match function is_valid_flash_bbcode($cleaned_content, $uid) { $regex = get_flash_regex($uid); $url_regex = get_preg_expression('url'); $www_url_regex = get_preg_expression('www_url'); if (preg_match_all($regex, $cleaned_content, $matches)) { foreach ($matches[3] as $flash_url) { if (!preg_match("#^($url_regex|$www_url_regex)$#i", $flash_url)) { return false; } } } return true; } // check if a bitfield includes flash // 11 = flash bit function has_flash_enabled($bitfield_data) { $bitfield = new bitfield($bitfield_data); return $bitfield->get(11); } // taken from support toolkit function html_entity_decode_utf8($string) { static $trans_tbl; // replace numeric entities $string = preg_replace('~&#x([0-9a-f]+);~ei', 'code2utf8(hexdec("\\1"))', $string); $string = preg_replace('~&#([0-9]+);~e', 'code2utf8(\\1)', $string); // replace literal entities if (!isset($trans_tbl)) { $trans_tbl = array(); foreach (get_html_translation_table(HTML_ENTITIES) as $val=>$key) $trans_tbl[$key] = utf8_encode($val); } return strtr($string, $trans_tbl); } // taken from support toolkit // Returns the utf string corresponding to the unicode value (from php.net, courtesy - romans@void.lv) function code2utf8($num) { if ($num < 128) return chr($num); if ($num < 2048) return chr(($num >> 6) + 192) . chr(($num & 63) + 128); if ($num < 65536) return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); if ($num < 2097152) return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); return ''; }
iv class='add'>+) : (),
+$::expert && $db_entry{GSDRIVER} ne 'POSTSCRIPT' ? (
+_("Extra Text options") => \$printer->{TEXTONLYOPTIONS},
+) : (),
+]);
+
+ $printer->{BITSPERPIXEL} = $col_to_depth{$printer->{BITSPERPIXEL}} || $printer->{BITSPERPIXEL}; #- translate back.
$printer->{complete} = 1;
copy_printer_params($printer, $printer->{configured}{$printer->{QUEUE}} ||= {});
@@ -223,7 +234,6 @@ _("Color depth options") => { val => \$printer->{BITSPERPIXEL}, type => 'list',
$action = ${{reverse %action}}{$in->ask_from_list('', _("Do you want to test printing?"),
[ map { $action{$_} } @action ], $action{'done'})};
- my $pidlpd;
my @testpages;
push @testpages, "/usr/lib/rhs/rhs-printfilters/testpage.asc"
if $action eq "ascii" || $action eq "both";
@@ -231,23 +241,14 @@ _("Color depth options") => { val => \$printer->{BITSPERPIXEL}, type => 'list',
if $action eq "ps" || $action eq "both";
if (@testpages) {
- my $w = $in->wait_message('', _("Printing test page(s)..."));
+ my @lpq_output;
+ {
+ my $w = $in->wait_message('', _("Printing test page(s)..."));
- #- restart lpd with blank spool queue.
- foreach (("/var/spool/lpd/$printer->{QUEUE}/lock", "/var/spool/lpd/lpd.lock")) {
- $pidlpd = (cat_("$prefix$_"))[0]; kill 'TERM', $pidlpd if $pidlpd;
- unlink "$prefix$_";
+ printer::restart_queue($printer->{QUEUE});
+ @lpq_output = printer::print_pages($printer->{QUEUE}, @testpages);
}
- run_program::rooted($prefix, "lprm", "-P$printer->{QUEUE}", "-"); sleep 1;
- run_program::rooted($prefix, "lpd"); sleep 1;
-
- run_program::rooted($prefix, "lpr", "-P$printer->{QUEUE}", $_) foreach @testpages;
- sleep 5; #- allow lpr to send pages.
- local *F; open F, "chroot $prefix/ /usr/bin/lpq -P$printer->{QUEUE} |";
- my @lpq_output = grep { !/^no entries/ && !(/^Rank\s+Owner/ .. /^\s*$/) } <F>;
-
- undef $w; #- erase wait message window.
if (@lpq_output) {
$action = $in->ask_yesorno('', _("Test page(s) have been sent to the printer daemon.
This may take a little time before printer start.
@@ -261,3 +262,85 @@ Does it work properly?"), 1) ? 'done' : 'change';
} while ($action ne 'done');
$printer->{complete} = 1;
}
+
+#- Program entry point.
+sub main($$$) {
+ my ($printer, $in, $install) = @_;
+ my ($queue, $continue);
+
+ printer::read_printer_db();
+ do {
+ if ($::beginner || !(scalar keys %{$printer->{configured} || {}})) {
+ $queue = $in->ask_yesorno(_("Printer"),
+ _("Would you like to configure a printer?"),
+ $printer->{want}) ? 'lp' : 'Done';
+ } else {
+ $queue = $in->ask_from_list_([''],
+_("Here are the following print queue.
+You can add some more or change the existing ones."),
+ [ (sort keys %{$printer->{configured} || {}}), __("Add"), __("Done") ],
+ );
+ if ($queue eq 'Add') {
+ my $i = '';
+ while ($i < 99) {
+ last unless $printer->{configured}{"lp$i"};
+ ++$i;
+ }
+ unless ($printer->{configured}{"lp$i"}) {
+ $queue = "lp$i";
+ $printer->{QUEUE} = $queue;
+ $printer->{SPOOLDIR} = "$printer::spooldir/$printer->{QUEUE}";
+ }
+ }
+ }
+ $queue eq 'Done' and last;
+
+ copy_printer_params($printer->{configured}{$queue}, $printer) if $printer->{configured}{$queue};
+ $printer->{complete} = 0; #- ??? keep that
+
+ &$install('rhs-printfilters') unless $::testing;
+
+ do {
+ if ($::beginner) {
+ $printer->{str_type} =
+ $in->ask_from_list_(_("Select Printer Connection"),
+ _("How is the printer connected?"),
+ [ keys %printer::printer_type ],
+ $printer::printer_type_inv{$printer->{TYPE}},
+ );
+ $printer->{TYPE} = $printer::printer_type{$printer->{str_type}};
+ } else {
+ $in->ask_from_entries_refH([_("Select Printer Connection"), _("Ok"), _("Remove queue")],
+_("Every print queue (which print jobs are directed to) needs a
+name (often lp) and a spool directory associated with it. What
+name and directory should be used for this queue and how is the printer connected?"), [
+_("Name of queue:") => { val => \$printer->{QUEUE} },
+_("Spool directory:") => { val => \$printer->{SPOOLDIR} },
+_("Printer Connection") => { val => \$printer->{str_type}, list => [ keys %printer::printer_type ] },
+ ],
+ changed => sub {
+ $printer->{SPOOLDIR} = "$printer::spooldir/$printer->{QUEUE}" unless $_[0];
+ },
+ complete => sub {
+ $printer->{TYPE} = $printer::printer_type{$printer->{str_type}} or
+ $in->ask_warn('', _("Unknown printer connection!")), return (1, 2);
+ return 0;
+ }
+ ) or delete $printer->{configured}{$queue}, redo; #- global redo on steps
+ }
+
+ $continue = '';
+ for ($printer->{TYPE}) {
+ /LOCAL/ and setup_local ($printer, $in, $install) and last;
+ /REMOTE/ and setup_remote($printer, $in, $install) and last;
+ /SMB/ and setup_smb ($printer, $in, $install) and last;
+ /NCP/ and setup_ncp ($printer, $in, $install) and last;
+ $continue = 1; last;
+ }
+ } while ($continue);
+
+ #- configure ghostscript driver to be used.
+ setup_gsdriver($printer, $in);
+
+ } until ($::beginner || $queue eq 'Done');
+}