2 # Functions for editing the mailertable database
5 # Returns the filename of the mailertable database and type, or undef if none
8 foreach $f (&find_type("K", $_[0])) {
9 if ($f->{'value'} =~ /^mailertable\s+(\S+)[^\/]+(\/\S+)$/) {
16 # mailers_file(&config)
17 # Returns the filename of the text mailertable file, or undef if none
20 return &find_textfile($config{'mailers_file'}, &mailers_dbm($_[0]));
23 # list_mailers(textfile)
26 if (!scalar(@list_mailers_cache)) {
28 @list_mailers_cache = ( );
32 s/\r|\n//g; # remove newlines
33 if (/^\s*#+\s*(.*)/) {
35 $cmt = &is_table_comment($_);
37 elsif (/^(\S+)\s+([^: ]+):(.*)/) {
38 # An actual mailer line
43 $virt{'line'} = $cmt ? $lnum-1 : $lnum;
44 $virt{'eline'} = $lnum;
45 $virt{'num'} = scalar(@list_mailers_cache);
47 push(@list_mailers_cache, \%virt);
57 return @list_mailers_cache;
60 # create_mailer(&details, textfile, dbmfile, dbmtype)
64 &list_mailers($_[1]); # force cache init
67 local $lref = &read_file_lines($_[1]);
68 $_[0]->{'line'} = scalar(@$lref);
69 push(@$lref, &make_table_comment($_[0]->{'cmt'}));
70 push(@$lref, "$_[0]->{'domain'}\t$_[0]->{'mailer'}:$_[0]->{'dest'}");
71 $_[0]->{'eline'} = scalar(@$lref)-1;
75 if (!&rebuild_map_cmd($_[1])) {
77 dbmopen(%mailer, $_[2], 0644);
78 $mailer{$_[0]->{'domain'}} = "$_[0]->{'mailer'}:$_[0]->{'dest'}";
81 else { &run_makemap($_[1], $_[2], $_[3]); }
85 $_[0]->{'num'} = scalar(@list_mailers_cache);
86 $_[0]->{'file'} = $_[1];
87 push(@list_mailers_cache, $_[0]);
90 # modify_mailer(&old, &details, textfile, dbmfile, dbmtype)
93 local(@mailer, %mailer);
96 local $lref = &read_file_lines($_[2]);
97 local $oldlen = $_[0]->{'eline'} - $_[0]->{'line'} + 1;
99 push(@newlines, &make_table_comment($_[1]->{'cmt'}));
100 push(@newlines, "$_[1]->{'domain'}\t$_[1]->{'mailer'}:$_[1]->{'dest'}");
101 splice(@$lref, $_[0]->{'line'}, $oldlen, @newlines);
102 &flush_file_lines($_[2]);
105 if (!&rebuild_map_cmd($_[2])) {
106 if ($_[3] eq "dbm") {
107 dbmopen(%mailer, $_[3], 0644);
108 delete($mailer{$_[0]->{'domain'}});
109 $mailer{$_[1]->{'domain'}} = "$_[1]->{'mailer'}:$_[1]->{'dest'}";
112 else { &run_makemap($_[2], $_[3], $_[4]); }
115 local $idx = &indexof($_[0], @list_mailers_cache);
116 $_[1]->{'line'} = $_[0]->{'line'};
117 $_[1]->{'eline'} = $_[1]->{'cmt'} ? $_[0]->{'line'}+1 : $_[0]->{'line'};
118 $list_mailers_cache[$idx] = $_[1] if ($idx != -1);
119 &renumber_list(\@list_mailers_cache, $_[0], scalar(@newlines)-$oldlen);
122 # delete_mailer(&old, textfile, dbmfile, dbmtype)
125 local(@mailer, %mailer);
127 # Delete from the file
128 local $len = $_[0]->{'eline'} - $_[0]->{'line'} + 1;
129 local $lref = &read_file_lines($_[1]);
130 splice(@$lref, $_[0]->{'line'}, $len);
131 &flush_file_lines($_[1]);
133 # Delete f rom the DBM
134 if (!&rebuild_map_cmd($_[1])) {
135 if ($_[3] eq "dbm") {
136 dbmopen(%mailer, $_[2], 0644);
137 delete($mailer{$_[0]->{'domain'}});
140 else { &run_makemap($_[1], $_[2], $_[3]); }
144 local $idx = &indexof($_[0], @list_mailers_cache);
145 splice(@list_mailers_cache, $idx, 1) if ($idx != -1);
146 &renumber_list(\@list_mailers_cache, $_[0], -$len);
149 # mailer_form([&details])
153 local ($mode, $addr, $conf, $ml, $dest, $nomx);
155 print &ui_form_start("save_mailer.cgi", "post");
157 print &ui_hidden("num", $m->{'num'});
160 print &ui_hidden("new", 1);
162 print &ui_table_start($m ? $text{'mform_edit'} : $text{'mform_create'},
166 print &ui_table_row($text{'vform_cmt'},
167 &ui_textbox("cmt", $m ? $m->{'cmt'} : undef, 50));
169 # Show 'mail for' input
170 local $dom = $m && $m->{'domain'} =~ /^\.(\S+)$/ ? $1 : undef;
171 print &ui_table_row($text{'mform_for'},
172 &ui_radio_table("from_type", $dom ? 1 : 0,
173 [ [ 0, $text{'mform_host2'},
174 &ui_textbox("from_host", $dom || !$m ? "" : $m->{'domain'},
176 [ 1, $text{'mform_domain2'},
177 &ui_textbox("from_dom", $dom, 20) ],
178 $m ? ( ) : ( [ 2, $text{'mform_domain3'},
179 &ui_textbox("from_all", undef ,20) ] ) ]));
181 # Show delivery input
182 $conf = &get_sendmailcf();
183 local @mailers = ( { 'value' => 'error' }, &find_type("M", $conf) );
184 print &ui_table_row($text{'mform_delivery'},
186 $m ? $m->{'mailer'} : "smtp",
187 [ map { $_->{'value'} =~ /^([^ ,]+)/;
188 [ $1, $text{"mform_$1"} ] } @mailers ]));
191 $dest = $m->{'dest'};
192 if ($dest =~ s/\[([^\]:]+)\]/$1/g) {
196 $dest = $m->{'dest'};
198 print &ui_table_row($text{'mform_to'},
199 &ui_textbox("dest", $dest, 30)."<br>".
200 &ui_checkbox("nomx", 1, $text{'mform_ignore'}, $nomx));
202 print &ui_table_end();
203 print &ui_form_end($_[0] ? [ [ "save", $text{'save'} ],
204 [ "delete", $text{'delete'} ] ]
205 : [ [ "create", $text{'create'} ] ]);