2 # Functions for the access_db table
5 # Returns the filename and type of the access database, or undef if none
8 foreach $f (&find_type("K", $_[0])) {
9 if ($f->{'value'} =~ /^access\s+(\S+)[^\/]+(\S+)$/) {
16 # access_file(&config)
17 # Returns the filename of the text access file, or undef if none
20 return &find_textfile($config{'access_file'}, &access_dbm($_[0]));
23 # list_access(textfile)
26 if (!scalar(@list_access_cache)) {
27 @list_access_cache = ( );
31 s/\r|\n//g; # remove newlines
32 if (/^\s*#+\s*(.*)/) {
34 $cmt = &is_table_comment($_);
36 elsif (/^(\S+)\s+(.*)/) {
40 $acc{'line'} = $cmt ? $lnum-1 : $lnum;
41 $acc{'eline'} = $lnum;
42 $acc{'num'} = scalar(@list_access_cache);
43 if ($acc{'from'} =~ /^(Connect|From|To):(.*)/i) {
48 push(@list_access_cache, \%acc);
58 return @list_access_cache;
61 # create_access(&details, textfile, dbmfile, dbmtype)
62 # Create a new access database entry
65 &list_access($_[1]); # force cache init
69 local $lref = &read_file_lines($_[1]);
70 $_[0]->{'line'} = scalar(@$lref);
71 push(@$lref, &make_table_comment($_[0]->{'cmt'}));
72 local $from = $_[0]->{'tag'} ? "$_[0]->{'tag'}:$_[0]->{'from'}"
74 push(@$lref, "$from\t$_[0]->{'action'}");
75 $_[0]->{'eline'} = scalar(@$lref)-1;
76 &flush_file_lines($_[1]);
79 if (!&rebuild_map_cmd($_[1])) {
81 dbmopen(%acc, $_[2], 0644);
82 $acc{$from} = $_[0]->{'action'};
85 else { &run_makemap($_[1], $_[2], $_[3]); }
89 $_[0]->{'num'} = scalar(@list_access_cache);
90 $_[0]->{'file'} = $_[1];
91 push(@list_access_cache, $_[0]);
94 # delete_access(&details, textfile, dbmfile, dbmtype)
95 # Delete an existing access entry
101 local $lref = &read_file_lines($_[1]);
102 local $len = $_[0]->{'eline'} - $_[0]->{'line'} + 1;
103 splice(@$lref, $_[0]->{'line'}, $len);
104 &flush_file_lines($_[1]);
107 local $oldfrom = $_[0]->{'tag'} ? "$_[0]->{'tag'}:$_[0]->{'from'}"
109 if (!&rebuild_map_cmd($_[1])) {
110 if ($_[3] eq "dbm") {
111 dbmopen(%acc, $_[2], 0644);
112 delete($acc{$oldfrom});
115 else { &run_makemap($_[1], $_[2], $_[3]); }
119 local $idx = &indexof($_[0], @list_access_cache);
120 splice(@list_access_cache, $idx, 1) if ($idx != -1);
121 &renumber_list(\@list_access_cache, $_[0], -$len);
124 # modify_access(&old, &details, textfile, dbmfile, dbmtype)
125 # Change an existing access entry
129 local $oldfrom = $_[0]->{'tag'} ? "$_[0]->{'tag'}:$_[0]->{'from'}"
131 local $from = $_[1]->{'tag'} ? "$_[1]->{'tag'}:$_[1]->{'from'}"
135 local $lref = &read_file_lines($_[2]);
136 local $oldlen = $_[0]->{'eline'} - $_[0]->{'line'} + 1;
138 push(@newlines, &make_table_comment($_[1]->{'cmt'}));
139 push(@newlines, "$from\t$_[1]->{'action'}");
140 splice(@$lref, $_[0]->{'line'}, $oldlen, @newlines);
141 &flush_file_lines($_[2]);
144 if (!&rebuild_map_cmd($_[2])) {
145 if ($_[4] eq "dbm") {
146 dbmopen(%virt, $_[3], 0644);
147 delete($virt{$oldfrom});
148 $virt{$from} = $_[1]->{'action'};
151 else { &run_makemap($_[2], $_[3], $_[4]); }
155 local $idx = &indexof($_[0], @list_generics_cache);
156 $_[1]->{'line'} = $_[0]->{'line'};
157 $_[1]->{'eline'} = $_[1]->{'cmt'} ? $_[0]->{'line'}+1 : $_[0]->{'line'};
158 $list_generics_cache[$idx] = $_[1] if ($idx != -1);
159 &renumber_list(\@list_generics_cache, $_[0], scalar(@newlines)-$oldlen);
162 # access_form([&details])
166 local ($mode, $addr);
168 print &ui_form_start("save_access.cgi", "post");
170 print &ui_hidden("num", $v->{'num'}),"\n";
173 print &ui_hidden("new", 1),"\n";
175 print &ui_table_start($v ? $text{'sform_edit'} : $text{'sform_create'},
179 print &ui_table_row($text{'vform_cmt'},
180 &ui_textbox("cmt", $v->{'cmt'}, 50));
183 local $src = $v->{'from'} =~ /^\S+\@\S+$/ ? 0 :
184 $v->{'from'} =~ /^[0-9\.]+$/ ? 1 :
185 $v->{'from'} =~ /^\S+\@$/ ? 2 :
186 $v->{'from'} =~ /^[A-z0-9\-\.]+$/ ? 3 : 0;
187 print &ui_table_row($text{'sform_source'},
188 &ui_select("from_type", $src,
189 [ map { [ $_, $text{"sform_type$_"} ] } (0 .. 3) ])."\n".
190 &ui_textbox("from", $v->{'from'}, 25));
193 local $ver = &get_sendmail_version();
194 if ($v->{'tag'} || $ver >= 8.10) {
195 print &ui_table_row($text{'sform_tag'},
196 &ui_select("tag", $v->{'tag'},
197 [ [ "", $text{'sform_tag_'} ],
198 [ "From", $text{'sform_tag_from'} ],
199 [ "To", $text{'sform_tag_to'} ],
200 [ "Connect", $text{'sform_tag_connect'} ],
201 [ "Spam", $text{'sform_tag_spam'} ] ]));
205 local $atable = "<table>\n";
207 $atable .= "<td>".&ui_oneradio("action", "OK", $text{'sform_ok'},
208 $v->{'action'} eq "OK" || !$v->{'action'})."</td>\n";
209 $atable .= "<td>".&ui_oneradio("action", "RELAY", $text{'sform_relay'},
210 $v->{'action'} eq "RELAY")."</td>\n";
213 $atable .= "<td>".&ui_oneradio("action", "REJECT", $text{'sform_reject'},
214 $v->{'action'} eq "REJECT")."</td>\n";
215 $atable .= "<td>".&ui_oneradio("action", "DISCARD", $text{'sform_discard'},
216 $v->{'action'} eq "DISCARD")."</td>\n";
219 local ($err, $msg) = $v->{'action'} =~ /(\d+)\s*(.*)$/ ? ($1, $2) : ( );
220 $atable .= "<td colspan=2>".&ui_oneradio("action", 0, $text{'sform_err'},
222 $atable .= &ui_textbox("err", $err, 4)." ".$text{'sform_msg'}."\n";
223 $atable .= &ui_textbox("msg", $msg, 20)."</td>\n";
225 $atable .= "</table>\n";
226 print &ui_table_row($text{'sform_action'}, $atable);
228 print &ui_table_end();
229 print &ui_form_end($_[0] ? [ [ "save", $text{'save'} ],
230 [ "delete", $text{'delete'} ] ]
231 : [ [ "create", $text{'create'} ] ]);
237 return $access{'smode'} == 1 ||
238 $access{'smode'} == 2 && $g->{'from'} =~ /$access{'saddrs'}/;