putting the C in ACL
[freeside.git] / httemplate / config / config-process.cgi
1 <%init>
2
3 die "access denied\n"
4   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
5
6 # errant GET/POST protection
7 my $Vars = scalar($cgi->Vars);
8 my $num_Vars = scalar(keys %$Vars);
9 die "only received $num_Vars params; errant or truncated GET/POST?".
10     "  aborting - not updating config\n"
11   unless $num_Vars > 100;
12
13 my $conf = new FS::Conf;
14 $FS::Conf::DEBUG = 1;
15 my @config_items = $conf->config_items;
16
17 foreach my $i ( @config_items ) {
18   my @touch = ();
19   my @delete = ();
20   my $n = 0;
21   foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
22     if ( $type eq '' ) {
23     } elsif ( $type eq 'textarea' ) {
24       if ( $cgi->param($i->key. $n) ne '' ) {
25         my $value = $cgi->param($i->key. $n);
26         $value =~ s/\r\n/\n/g; #browsers?
27         $conf->set($i->key, $value);
28       } else {
29         $conf->delete($i->key);
30       }
31     } elsif ( $type eq 'checkbox' ) {
32 #        if ( defined($cgi->param($i->key. $n)) && $cgi->param($i->key. $n) ) {
33       if ( defined $cgi->param($i->key. $n) ) {
34         #$conf->touch($i->key);
35         push @touch, $i->key;
36       } else {
37         #$conf->delete($i->key);
38         push @delete, $i->key;
39       }
40     } elsif ( $type eq 'text' || $type eq 'select' || $type eq 'select-sub' )  {
41       if ( $cgi->param($i->key. $n) ne '' ) {
42         $conf->set($i->key, $cgi->param($i->key. $n));
43       } else {
44         $conf->delete($i->key);
45       }
46     } elsif ( $type eq 'editlist' || $type eq 'selectmultiple' )  {
47       if ( scalar(@{[ $cgi->param($i->key. $n) ]}) ) {
48         $conf->set($i->key, join("\n", @{[ $cgi->param($i->key. $n) ]} ));
49       } else {
50         $conf->delete($i->key);
51       }
52     } else {
53     }
54     $n++;
55   }
56  # warn @touch;
57   $conf->touch($_) foreach @touch;
58   $conf->delete($_) foreach @delete;
59 }
60
61 </%init>
62 <% $cgi->redirect("config-view.cgi") %>