## DSPAM localStore CGI Hack

As mentioned in my previous DSPAM post, I replaced the horrible symlinks necessary to get the CGI working when following the appliance instructions (localStore pref) with a CGI hack, which appeared to do the trick. After trying to setup a new user on the appliance I noticed that this hack only seems to work for users who are admins (appear in the admins text file) and for the life of me I couldn’t figure out why this was. After much more hair pulling I decided to see if a ‘better’ fix had been applied in the latest development version of DSPAM and luckily for me one has! It’s very simple to apply the bits that need changing for this, I would provide a patch but I’m not really sure how to do that 😉 So here goes in kinda patch notation –

Block 1
```use Time::Local; use vars qw { %CONFIG %DATA %FORM \$MAILBOX \$CURRENT_USER \$USER \$TMPFILE}; +use vars qw { \$CURRENT_STORE }; require "ctime.pl";```

Block 2
`\$CONFIG{'DSPAM_ARGS'} =~ s/%CURRENT_USER%/\$CURRENT_USER/g;`

``` +# Current Store +do { + my(%PREF) = GetPrefs(\$CURRENT_USER); + \$CURRENT_STORE = \$PREF{"localStore"}; + if (\$CURRENT_STORE eq "") { \$CURRENT_STORE = \$CURRENT_USER; } +}; ```

```-\$USER = GetPath(\$CURRENT_USER); +\$USER = GetPath(\$CURRENT_STORE); \$MAILBOX = \$USER . ".mbox"; \$TMPFILE = \$USER . ".tmp";```

Block 3
```_END close(FILE); } }```

``` - if (\$CONFIG{'PREFERENCES_EXTENSION'} == 1) { - open(PIPE, "\$CONFIG{'DSPAM_BIN'}/dspam_admin l pref " . quotemeta(\$username) . "|"); - while() { - chomp; - my(\$directive, \$value) = split(/\=/); - \$PREFS{\$directive} = \$value; - } - close(PIPE); - } - - if (keys(%PREFS) eq "0" || \$CONFIG{'PREFERENCES_EXTENSION'} != 1) { - if (! -e \$FILE) { - \$FILE = "./default.prefs"; - } - - if (! -e \$FILE) { - &error("Unable to load default preferences"); - } - - open(FILE, "< \$FILE"); - while() { - chomp; - my(\$directive, \$value) = split(/\=/); - \$PREFS{\$directive} = \$value; - } - close(FILE); - } + %PREFS = GetPrefs(); ```

``` \$DATA{"SEDATION_\$PREFS{'statisticalSedation'}"} = "CHECKED"; \$DATA{"S_".\$PREFS{'trainingMode'}} = "CHECKED";```

Block 4
```&error("Unable to determine filesystem scale"); }```

``` ```

```+sub GetPrefs { + my(%PREFS); + + my(\$FILE) = "\$USER.prefs"; + + if (\$CONFIG{'PREFERENCES_EXTENSION'} == 1) { + open(PIPE, "\$CONFIG{'DSPAM_BIN'}/dspam_admin l pref " . quotemeta(\$CURRENT_USER) . "|"); + while() { + chomp; + my(\$directive, \$value) = split(/\=/); + \$PREFS{\$directive} = \$value; + } + close(PIPE); + } + + if (keys(%PREFS) eq "0" || \$CONFIG{'PREFERENCES_EXTENSION'} != 1) { + if (! -e \$FILE) { + \$FILE = "./default.prefs"; + } + + if (! -e \$FILE) { + &error("Unable to load default preferences"); + } + + open(FILE, "< \$FILE"); + while() { + chomp; + my(\$directive, \$value) = split(/\=/); + \$PREFS{\$directive} = \$value; + } + close(FILE); + } + + return %PREFS +} ```

That seemed to do the trick for me (YMMV).. Basically in each block above, find the first bit and then straight after that add or remove lines as denoted by the +/- symbols.
{"ft_lang_label":"__label__en","ft_lang_prob":0.5977752,"math_prob":0.9679656,"size":2918,"snap":"2019-26-2019-30","text_gpt3_token_len":877,"char_repetition_ratio":0.11358957,"word_repetition_ratio":0.1802935,"special_character_ratio":0.3594928,"punctuation_ratio":0.1793249,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98076785,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-07-21T19:53:08Z\",\"WARC-Record-ID\":\"<urn:uuid:7750dc1e-ffd3-493a-a6c8-1cc08b0d3659>\",\"Content-Length\":\"33398\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:70ca5b3c-e55c-4ce0-a545-5067858d9cd4>\",\"WARC-Concurrent-To\":\"<urn:uuid:7d712070-f527-4882-87c5-a802b888b38c>\",\"WARC-IP-Address\":\"192.0.78.25\",\"WARC-Target-URI\":\"https://osblues.com/2005/07/18/\",\"WARC-Payload-Digest\":\"sha1:L4TD67CC52GX2VTVXCWRMEVV6Y2PVVYG\",\"WARC-Block-Digest\":\"sha1:6MRWVKUR4RID5QYPUXDCTRTMKQBTF3OP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-30/CC-MAIN-2019-30_segments_1563195527196.68_warc_CC-MAIN-20190721185027-20190721211027-00181.warc.gz\"}"}