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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: