- foreach my $i ( @config_items ) {
- my @touch = ();
- my @delete = ();
- my $n = 0;
- foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
- if ( $type eq '' ) {
- } elsif ( $type eq 'textarea' ) {
- if ( $cgi->param($i->key. $n) ne '' ) {
- my $value = $cgi->param($i->key. $n);
- $value =~ s/\r\n/\n/g; #browsers?
- $conf->set($i->key, $value);
- } else {
- $conf->delete($i->key);
+# errant GET/POST protection
+my $Vars = scalar($cgi->Vars);
+my $num_Vars = scalar(keys %$Vars);
+die "only received $num_Vars params; errant or truncated GET/POST?".
+ " aborting - not updating config\n"
+ unless $num_Vars > 100;
+
+my $conf = new FS::Conf;
+$FS::Conf::DEBUG = 1;
+my @config_items = $conf->config_items;
+
+foreach my $i ( @config_items ) {
+ my @touch = ();
+ my @delete = ();
+ my $n = 0;
+ foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
+ if ( $type eq '' ) {
+ } elsif ( $type eq 'textarea' ) {
+ if ( $cgi->param($i->key. $n) ne '' ) {
+ my $value = $cgi->param($i->key. $n);
+ $value =~ s/\r\n/\n/g; #browsers?
+ $conf->set($i->key, $value);
+ } else {
+ $conf->delete($i->key);
+ }
+ } elsif ( $type eq 'binary' ) {
+ if ( defined($cgi->param($i->key. $n)) && $cgi->param($i->key. $n) ) {
+ my $fh = $cgi->upload($i->key. $n);
+ if (defined($fh)) {
+ local $/;
+ $conf->set_binary($i->key, <$fh>);