[Privoxy-users] some help please writing a filter for a phpbb forum
Fabian Keil
fk at fabiankeil.de
Thu Dec 8 17:36:16 CET 2022
René J.V. Bertin <rjvbertin at gmail.com> wrote on 2022-12-06 at 21:30:45:
> I'm active on a forum run by an admin who prefers to let members deal with broken/disabled features rather than setting up the software properly.
>
> I've been trying to use a privoxy filter to suppress a few buttons of the posting editor which insert unsupported BBCodes. I know what html code to remove and have confirmed that it has the required effect:
>
> From the line
>
> ```
> var bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]','[flash=]', '[/flash]','[size=]','[/size]', '[font]', '[/font]', '[anchor]', '[/anchor]', '[goto]', '[/goto]');
> ```
>
> the string ", '[anchor]', '[/anchor]', '[goto]', '[/goto]'" should be removed (for good measure)
>
> And the following 2 button definitions from `<div id="format-buttons" class="format-buttons">` should also be removed:
>
> ```
> <button type="button" class="button button-secondary bbcode-anchor" name="addbbcode24" value="anchor" onclick="bbstyle(24)" title="Anchor: [anchor]Name of the anchor[/anchor]">
> anchor
> </button>
> <button type="button" class="button button-secondary bbcode-goto" name="addbbcode26" value="goto" onclick="bbstyle(26)" title="Goto: [goto=Anchor Name]Link tekst[/goto]">
> goto
> </button>
> ```
>
> I'm not exactly familiar with perl, but I had hoped that the following filter definition would do it (as you can see I experimented with a different approach for the 2 buttons:
>
> ```
> FILTER: delcamp-forbidden-bbcodes Try to hide buttons for forbidden bbcodes on the delcamp cg forum
> s|, '\[anchor\]', '\[/anchor\]', '\[goto\]', '\[/goto\]'||Uig
> s|<button type="button" class="button button-secondary bbcode-anchor".*\n\
> .*anchor.*\n\
> .*</button>||ig
> s|<button type="button" class="button button-secondary bbcode-goto".*</button>||im
>
> ```
>
> My user.action file has
>
> ```
>
> { +filter{delcamp-forbidden-bbcodes} }
> .classicalguitardelcamp.com
>
>
> ```
>
> somewhere near the end, just above the `fragile` section. I can see that the rule is applied to the forum URLs but I see no trace of it being invoked if I activate debug 64 as suggested.
>
> Ergo, I must be doing something wrong, or have missed something. Are these the "external filters" mentioned in the description of the `temporary-directory` feature, for instance?
I tested your pcrs commands with Privoxy-Filter-Test (available at
<https://www.fabiankeil.de/sourcecode/pft/>) and the result was:
--- /home/fk/privoxy/privoxy-filter-test/original-851028837104426112-file-received.html Thu Dec 8 17:16:11 2022
+++ /home/fk/privoxy/privoxy-filter-test/filtered-851028837104426112-file-received.html Thu Dec 8 17:16:11 2022
@@ -1,9 +1,7 @@
-var bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]','[flash=]', '[/flash]','[size=]','[/size]', '[font]', '[/font]', '[anchor]', '[/anchor]', '[goto]', '[/goto]');
+var bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]','[flash=]', '[/flash]','[size=]','[/size]', '[font]', '[/font]');
- <button type="button" class="button button-secondary bbcode-anchor" name="addbbcode24" value="anchor" onclick="bbstyle(24)" title="Anchor: [anchor]Name of the anchor[/anchor]">
- anchor
- </button>
+
<button type="button" class="button button-secondary bbcode-goto" name="addbbcode26" value="goto" onclick="bbstyle(26)" title="Goto: [goto=Anchor Name]Link tekst[/goto]">
goto
</button>
The last pcrs command in your filter doesn't apply because the text is split
across multiple lines. It works for me if I add the "s" option:
--- /home/fk/privoxy/privoxy-filter-test/original-851028837104426112-file-received.html Thu Dec 8 17:20:09 2022
+++ /home/fk/privoxy/privoxy-filter-test/filtered-851028837104426112-file-received.html Thu Dec 8 17:20:09 2022
@@ -1,9 +1,5 @@
-var bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]','[flash=]', '[/flash]','[size=]','[/size]', '[font]', '[/font]', '[anchor]', '[/anchor]', '[goto]', '[/goto]');
+var bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]','[flash=]', '[/flash]','[size=]','[/size]', '[font]', '[/font]');
- <button type="button" class="button button-secondary bbcode-anchor" name="addbbcode24" value="anchor" onclick="bbstyle(24)" title="Anchor: [anchor]Name of the anchor[/anchor]">
+
- anchor
+
- </button>
- <button type="button" class="button button-secondary bbcode-goto" name="addbbcode26" value="goto" onclick="bbstyle(26)" title="Goto: [goto=Anchor Name]Link tekst[/goto]">
- goto
- </button>
The pcrs commands used were:
s|, '\[anchor\]', '\[/anchor\]', '\[goto\]', '\[/goto\]'||Uig
s|<button type="button" class="button button-secondary bbcode-anchor".*\n\
.*anchor.*\n\
.*</button>||ig
s|<button type="button" class="button button-secondary bbcode-goto".*</button>||ims
Note the "s" added at the end of the last line.
The website <https://www.classicalguitardelcamp.com/> uses https so you
need a Privoxy version compiled with FEATURE_HTTPS_INSPECTION
(you can check at <http://config.privoxy.org/show-status>) and enable
https inspection which is documented at:
<https://www.privoxy.org/user-manual/config.html#HTTPS-INSPECTION-DIRECTIVES>
<https://www.privoxy.org/user-manual/actions-file.html#HTTPS-INSPECTION>
Do you have https inspection configured already?
Fabian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.privoxy.org/pipermail/privoxy-users/attachments/20221208/95dad349/attachment.bin>
More information about the Privoxy-users
mailing list