1 | #!/usr/bin/perl -w -T
|
---|
2 | # Main web UI script for DeepNet DNS Administrator
|
---|
3 | ##
|
---|
4 | # $Id: dns.cgi 543 2013-12-10 21:22:10Z kdeugau $
|
---|
5 | # Copyright 2008-2013 Kris Deugau <kdeugau@deepnet.cx>
|
---|
6 | #
|
---|
7 | # This program is free software: you can redistribute it and/or modify
|
---|
8 | # it under the terms of the GNU General Public License as published by
|
---|
9 | # the Free Software Foundation, either version 3 of the License, or
|
---|
10 | # (at your option) any later version.
|
---|
11 | #
|
---|
12 | # This program is distributed in the hope that it will be useful,
|
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | # GNU General Public License for more details.
|
---|
16 | #
|
---|
17 | # You should have received a copy of the GNU General Public License
|
---|
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | ##
|
---|
20 |
|
---|
21 | use strict;
|
---|
22 | use warnings;
|
---|
23 |
|
---|
24 | use CGI::Carp qw (fatalsToBrowser);
|
---|
25 | use CGI::Simple;
|
---|
26 | use HTML::Template;
|
---|
27 | use CGI::Session;
|
---|
28 | use Crypt::PasswdMD5;
|
---|
29 | use Digest::MD5 qw(md5_hex);
|
---|
30 | use Net::DNS;
|
---|
31 | use DBI;
|
---|
32 |
|
---|
33 | use Data::Dumper;
|
---|
34 |
|
---|
35 | #sub is_tainted {
|
---|
36 | # # from perldoc perlsec
|
---|
37 | # return ! eval { eval("#" . substr(join("", @_), 0, 0)); 1 };
|
---|
38 | #}
|
---|
39 | #use Cwd 'abs_path';
|
---|
40 | #use File::Basename;
|
---|
41 | #use lib dirname( abs_path $0 );
|
---|
42 | #die "argh! tainted!" if is_tainted($0);
|
---|
43 | #die "argh! \@INC got tainted!" if is_tainted(@INC);
|
---|
44 |
|
---|
45 | # don't remove! required for GNU/FHS-ish install from tarball
|
---|
46 | use lib '.'; ##uselib##
|
---|
47 |
|
---|
48 | use DNSDB;
|
---|
49 |
|
---|
50 | my @debugbits; # temp, to be spit out near the end of processing
|
---|
51 | my $debugenv = 0;
|
---|
52 |
|
---|
53 | # Let's do these templates right...
|
---|
54 | my $templatedir = "templates";
|
---|
55 |
|
---|
56 | # Set up the CGI object...
|
---|
57 | my $q = new CGI::Simple;
|
---|
58 | # ... and get query-string params as well as POST params if necessary
|
---|
59 | $q->parse_query_string;
|
---|
60 |
|
---|
61 | # This is probably excessive fiddling, but it puts the parameters somewhere my fingers know about...
|
---|
62 | my %webvar = $q->Vars;
|
---|
63 |
|
---|
64 | # shut up some warnings, in case we arrive somewhere we forgot to set this
|
---|
65 | $webvar{defrec} = 'n' if !$webvar{defrec}; # non-default records
|
---|
66 | $webvar{revrec} = 'n' if !$webvar{revrec}; # non-reverse (domain) records
|
---|
67 |
|
---|
68 | # create a DNSDB object. this loads some local system defaults and connects to the DB
|
---|
69 | # with the credentials configured
|
---|
70 | ##fixme: pass params for loadConfig, and use them there, to allow one codebase to support multiple sites
|
---|
71 | my $dnsdb = new DNSDB;
|
---|
72 |
|
---|
73 | my $header = HTML::Template->new(filename => "$templatedir/header.tmpl");
|
---|
74 | my $footer = HTML::Template->new(filename => "$templatedir/footer.tmpl");
|
---|
75 | $footer->param(version => $DNSDB::VERSION);
|
---|
76 |
|
---|
77 | ##fixme: slim chance this could be triggered on errors other than DB failure?
|
---|
78 | if (!$dnsdb) {
|
---|
79 | print "Content-type: text/html\n\n";
|
---|
80 | print $header->output;
|
---|
81 | my $errpage = HTML::Template->new(filename => "$templatedir/dberr.tmpl");
|
---|
82 | $errpage->param(errmsg => $DNSDB::errstr);
|
---|
83 | print $errpage->output;
|
---|
84 | print $footer->output;
|
---|
85 | exit;
|
---|
86 | }
|
---|
87 |
|
---|
88 | $header->param(orgname => $dnsdb->{orgname}) if $dnsdb->{orgname} ne 'Example Corp';
|
---|
89 |
|
---|
90 | my $logingroup;
|
---|
91 | my $curgroup;
|
---|
92 | my @viewablegroups;
|
---|
93 |
|
---|
94 | # retrieve the session ID from our cookie, if possible
|
---|
95 | my $sid = $q->cookie('dnsadmin_session');
|
---|
96 |
|
---|
97 | # see if the session loads
|
---|
98 | my $session = CGI::Session->load("driver:File", $sid, {Directory => $dnsdb->{sessiondir}})
|
---|
99 | or die CGI::Session->errstr();
|
---|
100 |
|
---|
101 | if (!$sid) {
|
---|
102 | $webvar{page} = 'login';
|
---|
103 | } else {
|
---|
104 | # we have a session to load from, maybe
|
---|
105 | $logingroup = ($session->param('logingroup') ? $session->param('logingroup') : 1);
|
---|
106 | $curgroup = ($session->param('curgroup') ? $session->param('curgroup') : $logingroup);
|
---|
107 | # security check - does the user have permission to view this entity?
|
---|
108 | # this is a prep step used "many" places
|
---|
109 | $dnsdb->getChildren($logingroup, \@viewablegroups, 'all');
|
---|
110 | push @viewablegroups, $logingroup;
|
---|
111 | ##fixme: make sessions persist through closing the site?
|
---|
112 | # this even bridges browser close too. hmm...
|
---|
113 | $webvar{page} = 'domlist' if !$webvar{page};
|
---|
114 | }
|
---|
115 |
|
---|
116 | # set $webvar{page} before we try to use it.
|
---|
117 | $webvar{page} = 'login' if !$webvar{page};
|
---|
118 |
|
---|
119 | ## per-page startwith, filter, searchsubs
|
---|
120 |
|
---|
121 | ##fixme: complain-munge-and-continue with non-"[a-z0-9-.]" filter and startwith
|
---|
122 | $webvar{startwith} =~ s/^(0-9|[a-z]).*/$1/ if $webvar{startwith};
|
---|
123 | # not much call for chars not allowed in domain names
|
---|
124 | $webvar{filter} =~ s/[^a-zA-Z0-9_.:\@-]//g if $webvar{filter};
|
---|
125 | ## only set 'y' if box is checked, no other values legal
|
---|
126 | ## however, see https://secure.deepnet.cx/trac/dnsadmin/ticket/31
|
---|
127 | # first, drop obvious fakes
|
---|
128 | delete $webvar{searchsubs} if $webvar{searchsubs} && $webvar{searchsubs} !~ /^[ny]/;
|
---|
129 | # strip the known "turn me off!" bit.
|
---|
130 | $webvar{searchsubs} =~ s/^n\s?// if $webvar{searchsubs};
|
---|
131 | # strip non-y/n - note this legitimately allows {searchsubs} to go empty
|
---|
132 | $webvar{searchsubs} =~ s/[^yn]//g if $webvar{searchsubs};
|
---|
133 |
|
---|
134 | # pagination
|
---|
135 | my $perpage = 15; # Just In Case
|
---|
136 | $perpage = $dnsdb->{perpage} if $dnsdb->{perpage};
|
---|
137 | my $offset = ($webvar{offset} ? $webvar{offset} : 0);
|
---|
138 |
|
---|
139 | ## set up "URL to self" (whereami edition)
|
---|
140 | # @#$%@%@#% XHTML - & in a URL must be escaped. >:(
|
---|
141 | my $uri_self = $ENV{REQUEST_URI};
|
---|
142 | $uri_self =~ s/\&([a-z])/\&\;$1/g;
|
---|
143 |
|
---|
144 | # le sigh. and we need to strip any previous action
|
---|
145 | $uri_self =~ s/\&action=[^&]+//g;
|
---|
146 |
|
---|
147 | # much magic happens. if startwith or a search string change (to, from, or
|
---|
148 | # across, in the request vs whatever's in the session) then the offset should
|
---|
149 | # be reset to 0 so that the first/prev/next/last widget populates correctly,
|
---|
150 | # and so that the list of whatever we're looking at actually shows things
|
---|
151 | # (since we may have started on page 42 of 300 with a LOOOOONG list, but we
|
---|
152 | # now only need 3 pages for the filtered list).
|
---|
153 | # while we're at it, plonk these into the session for safekeeping.
|
---|
154 | if (defined($webvar{startwith})) {
|
---|
155 | if ($webvar{startwith} ne $session->param($webvar{page}.'startwith')) {
|
---|
156 | $uri_self =~ s/\&offset=[^&]//;
|
---|
157 | $offset = 0;
|
---|
158 | }
|
---|
159 | $session->param($webvar{page}.'startwith', $webvar{startwith});
|
---|
160 | }
|
---|
161 | if (defined($webvar{filter})) {
|
---|
162 | if ($webvar{filter} ne $session->param($webvar{page}.'filter')) {
|
---|
163 | $uri_self =~ s/\&offset=[^&]//;
|
---|
164 | $offset = 0;
|
---|
165 | }
|
---|
166 | $session->param($webvar{page}.'filter', $webvar{filter})
|
---|
167 | }
|
---|
168 | $session->param($webvar{page}.'searchsubs', $webvar{searchsubs}) if defined($webvar{searchsubs});
|
---|
169 |
|
---|
170 | # and now that the search/filter criteria for this page are set, put them in some globals for actual use.
|
---|
171 | my $startwith = $session->param($webvar{page}.'startwith');
|
---|
172 | my $filter = $session->param($webvar{page}.'filter');
|
---|
173 | my $searchsubs = $session->param($webvar{page}.'searchsubs');
|
---|
174 |
|
---|
175 | # ... and assemble the args
|
---|
176 | my @filterargs;
|
---|
177 | push @filterargs, "^[$startwith]" if $startwith;
|
---|
178 | push @filterargs, $filter if $filter;
|
---|
179 |
|
---|
180 | # and search filter options. these get stored in the session, but discarded
|
---|
181 | # as soon as you switch to a different page.
|
---|
182 | ##fixme: think about retaining these on a per-page basis, as well as offset; same as the sort-order bits
|
---|
183 | no warnings qw(uninitialized);
|
---|
184 | $uri_self =~ s/\&startwith=[a-z09-]*(\&)?/$1/g;
|
---|
185 | $uri_self =~ s/\&searchsubs=[a-z09-]*(\&)?/$1/g;
|
---|
186 | $uri_self =~ s/\&filter=[a-z09-]*(\&)?/$1/g;
|
---|
187 | use warnings qw(uninitialized);
|
---|
188 |
|
---|
189 | # Fix up $uri_self so we don't lose the session/page
|
---|
190 | $uri_self .= "?page=$webvar{page}" if $uri_self =~ m{/dns.cgi$};
|
---|
191 | $uri_self = "$ENV{SCRIPT_NAME}?page=$webvar{page}$1" if $uri_self =~ m{/dns.cgi\&(.+)$};
|
---|
192 |
|
---|
193 | ## end uri_self monkeying
|
---|
194 |
|
---|
195 | # NB: these must match the field name and SQL ascend/descend syntax respectively
|
---|
196 | # sortby is reset to a suitable "default", then re-reset to whatever the user has
|
---|
197 | # clicked on last in the record=listing subs, but best to put a default here.
|
---|
198 | my $sortby = "domain";
|
---|
199 | my $sortorder = "ASC";
|
---|
200 |
|
---|
201 | # Create the page template object. Display a reasonable error page and whine if the template doesn't exist.
|
---|
202 | my $page;
|
---|
203 | eval {
|
---|
204 | # sigh. can't set loop_context_vars or global_vars once instantiated.
|
---|
205 | $page = HTML::Template->new(filename => "$templatedir/$webvar{page}.tmpl",
|
---|
206 | loop_context_vars => 1, global_vars => 1);
|
---|
207 | };
|
---|
208 | if ($@) {
|
---|
209 | my $msg = $@;
|
---|
210 | $page = HTML::Template->new(filename => "$templatedir/badpage.tmpl");
|
---|
211 | if (-e "$templatedir/$webvar{page}.tmpl") {
|
---|
212 | $page->param(badtemplate => $q->escapeHTML($msg));
|
---|
213 | } else {
|
---|
214 | warn "Bad page $webvar{page} requested";
|
---|
215 | $page->param(badpage => $q->escapeHTML($webvar{page}));
|
---|
216 | }
|
---|
217 | $webvar{page} = 'badpage';
|
---|
218 | }
|
---|
219 |
|
---|
220 | my $sesscookie;
|
---|
221 |
|
---|
222 | # handle can-happen-on-(almost)-any-page actions
|
---|
223 | if ($webvar{action}) {
|
---|
224 |
|
---|
225 | if ($webvar{action} eq 'login') {
|
---|
226 | # Snag ACL/permissions here too
|
---|
227 |
|
---|
228 | my $userdata = $dnsdb->login($webvar{username}, $webvar{password});
|
---|
229 |
|
---|
230 | if ($userdata) {
|
---|
231 |
|
---|
232 | # (re)create the session
|
---|
233 | $session = new CGI::Session("driver:File", $sid, {Directory => $dnsdb->{sessiondir}})
|
---|
234 | or die CGI::Session->errstr();
|
---|
235 | $sid = $session->id();
|
---|
236 |
|
---|
237 | $sesscookie = $q->cookie( -name => 'dnsadmin_session',
|
---|
238 | -value => $sid,
|
---|
239 | -expires => "+".$dnsdb->{timeout},
|
---|
240 | -secure => 0,
|
---|
241 | ## fixme: need to extract root path for cookie, so as to limit cookie to dnsadmin instance
|
---|
242 | # -path => $url
|
---|
243 | );
|
---|
244 |
|
---|
245 | # set session bits
|
---|
246 | $session->expire($dnsdb->{timeout});
|
---|
247 | $session->param('logingroup',$userdata->{group_id});
|
---|
248 | $session->param('curgroup',$userdata->{group_id});
|
---|
249 | $session->param('uid',$userdata->{user_id});
|
---|
250 | $session->param('username',$webvar{username});
|
---|
251 |
|
---|
252 | # for reference. seems we don't need to set these on login any more.
|
---|
253 | # $session->param('domlistsortby','domain');
|
---|
254 | # $session->param('domlistorder','ASC');
|
---|
255 | # $session->param('revzonessortby','revnet');
|
---|
256 | # $session->param('revzonesorder','ASC');
|
---|
257 | # $session->param('useradminsortby','user');
|
---|
258 | # $session->param('useradminorder','ASC');
|
---|
259 | # $session->param('grpmansortby','group');
|
---|
260 | # $session->param('grpmanorder','ASC');
|
---|
261 | # $session->param('reclistsortby','host');
|
---|
262 | # $session->param('reclistorder','ASC');
|
---|
263 | # $session->param('loclistsortby','description');
|
---|
264 | # $session->param('loclistorder','ASC');
|
---|
265 | # $session->param('logsortby','stamp');
|
---|
266 | # $session->param('logorder','DESC');
|
---|
267 |
|
---|
268 | ## "recover my link" - tack on request bits and use requested page instead of hardcoding domlist
|
---|
269 | # this could possibly be compacted by munging changepage a little so we don't have to deconstruct
|
---|
270 | # and reconstruct the URI argument list.
|
---|
271 | my %target = (page => "domlist");
|
---|
272 | if ($webvar{target} && $webvar{target} =~ /\?/) {
|
---|
273 | my $tmp = (split /\?/, $webvar{target})[1];
|
---|
274 | $tmp =~ s/^\&//;
|
---|
275 | my @targs = split /\&/, $tmp;
|
---|
276 | foreach (@targs) {
|
---|
277 | my ($k,$v) = split /=/;
|
---|
278 | $target{$k} = $v if $k;
|
---|
279 | # if we're going through a "session expired" login, we may have a different
|
---|
280 | # "current group" than the login group.
|
---|
281 | $session->param('curgroup', $v) if $k eq 'curgroup';
|
---|
282 | ##fixme: page=record goes "FOOM", sometimes - cause/fix?
|
---|
283 | }
|
---|
284 | }
|
---|
285 | changepage(%target);
|
---|
286 |
|
---|
287 | } else {
|
---|
288 | $webvar{loginfailed} = 1;
|
---|
289 | } # user data fetch check
|
---|
290 |
|
---|
291 | } elsif ($webvar{action} eq 'logout') {
|
---|
292 | # delete the session
|
---|
293 | $session->delete();
|
---|
294 | $session->flush();
|
---|
295 |
|
---|
296 | my $sesscookie = $q->cookie( -name => 'dnsadmin_session',
|
---|
297 | -value => $sid,
|
---|
298 | -expires => "-1",
|
---|
299 | -secure => 0,
|
---|
300 | ## fixme: need to extract root path for cookie, so as to limit cookie to dnsadmin instance
|
---|
301 | # -path => $url
|
---|
302 | );
|
---|
303 |
|
---|
304 | my $newurl = "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}";
|
---|
305 | $newurl =~ s|/[^/]+$|/|;
|
---|
306 | print $q->redirect( -uri => $newurl, -cookie => $sesscookie);
|
---|
307 | exit;
|
---|
308 |
|
---|
309 | } elsif ($webvar{action} eq 'chgroup' && $webvar{page} ne 'login') {
|
---|
310 | # fiddle session-stored group data
|
---|
311 | # magic incantation to... uhhh...
|
---|
312 |
|
---|
313 | # ... and the "change group" bits...
|
---|
314 | $uri_self =~ s/\&group=[^&]*//g;
|
---|
315 |
|
---|
316 | # security check - does the user have permission to view this entity?
|
---|
317 | my $errmsg;
|
---|
318 | if (!(grep /^$webvar{group}$/, @viewablegroups)) {
|
---|
319 | # hmm. Reset the current group to the login group? Yes. Prevents confusing behaviour elsewhere.
|
---|
320 | $session->param('curgroup',$logingroup);
|
---|
321 | $webvar{group} = $logingroup;
|
---|
322 | $curgroup = $logingroup;
|
---|
323 | $errmsg = "You are not permitted to view or make changes in the requested group";
|
---|
324 | $page->param(errmsg => $errmsg);
|
---|
325 | }
|
---|
326 |
|
---|
327 | $session->param('curgroup', $webvar{group});
|
---|
328 | $curgroup = ($webvar{group} ? $webvar{group} : $session->param('curgroup'));
|
---|
329 |
|
---|
330 | # I hate special cases.
|
---|
331 | ##fixme: probably need to handle webvar{revrec}=='y' too
|
---|
332 | if ($webvar{page} eq 'reclist' && $webvar{defrec} eq 'y') {
|
---|
333 | my %args = (page => $webvar{page}, id => $curgroup, defrec => $webvar{defrec}, revrec => $webvar{revrec});
|
---|
334 | $args{errmsg} = $errmsg if $errmsg;
|
---|
335 | changepage(%args);
|
---|
336 | }
|
---|
337 | # add offset back *into* $uri_self if we're also currently looking at a live record list.
|
---|
338 | if ($webvar{page} eq 'reclist' && $webvar{defrec} eq 'n') {
|
---|
339 | $uri_self .= "\&offset=$offset";
|
---|
340 | }
|
---|
341 | } # done action=chgroup
|
---|
342 | } # handle global webvar{action}s
|
---|
343 |
|
---|
344 |
|
---|
345 | # finally check if the user was disabled. we could just leave this for logout/session expiry,
|
---|
346 | # but if they keep the session active they'll continue to have access long after being disabled. :/
|
---|
347 | # Treat it as a session expiry.
|
---|
348 | if ($session->param('uid') && !$dnsdb->userStatus($session->param('uid')) ) {
|
---|
349 | $sid = '';
|
---|
350 | $session->delete; # force expiry of the session Right Away
|
---|
351 | $session->flush; # make sure it hits storage
|
---|
352 | changepage(page=> "login", sessexpired => 1);
|
---|
353 | }
|
---|
354 |
|
---|
355 | # Misc Things To Do on most pages
|
---|
356 | my %permissions;
|
---|
357 | $dnsdb->getPermissions('user', $session->param('uid'), \%permissions);
|
---|
358 | $dnsdb->initActionLog($session->param('uid'));
|
---|
359 |
|
---|
360 | ##
|
---|
361 | ## Per-page processing
|
---|
362 | ##
|
---|
363 |
|
---|
364 | if ($webvar{page} eq 'login') {
|
---|
365 |
|
---|
366 | my $target = $ENV{REQUEST_URI};
|
---|
367 | $target =~ s/\&/\&/g;
|
---|
368 | $page->param(target => $target); # needs to be trimmed a little, maybe?
|
---|
369 |
|
---|
370 | $page->param(sessexpired => 1) if (!$sid && $target !~ m|/$|);
|
---|
371 |
|
---|
372 | if ($webvar{loginfailed}) {
|
---|
373 | $page->param(loginfailed => 1);
|
---|
374 | $webvar{target} =~ s/\&/\&/g; # XHTML we do (not) love you so
|
---|
375 | $page->param(target => $webvar{target}) if $webvar{target};
|
---|
376 | }
|
---|
377 | # if $webvar{sessexpired}; # or this with below?
|
---|
378 | if ($session->is_expired) {
|
---|
379 | $page->param(sessexpired => 1);
|
---|
380 | $session->delete(); # Just to make sure
|
---|
381 | $session->flush();
|
---|
382 | }
|
---|
383 | $page->param(version => $DNSDB::VERSION);
|
---|
384 | $page->param(script_self => ($ENV{SCRIPT_NAME} =~ m|/([^/]+)$|)[0]);
|
---|
385 |
|
---|
386 | } elsif ($webvar{page} eq 'domlist' or $webvar{page} eq 'index') {
|
---|
387 |
|
---|
388 | $page->param(domlist => 1);
|
---|
389 |
|
---|
390 | # hmm. seeing problems in some possibly-not-so-corner cases.
|
---|
391 | # this currently only handles "domain on", "domain off"
|
---|
392 | if (defined($webvar{zonestatus})) {
|
---|
393 | # security check - does the user have permission to access this entity?
|
---|
394 | my $flag = 0;
|
---|
395 | foreach (@viewablegroups) {
|
---|
396 | $flag = 1 if $dnsdb->isParent($_, 'group', $webvar{id}, 'domain');
|
---|
397 | }
|
---|
398 | if ($flag && ($permissions{admin} || $permissions{domain_edit})) {
|
---|
399 | my $stat = $dnsdb->zoneStatus($webvar{id}, 'n', $webvar{zonestatus});
|
---|
400 | $page->param(resultmsg => $DNSDB::resultstr);
|
---|
401 | } else {
|
---|
402 | $page->param(errmsg => "You are not permitted to view or change the requested domain");
|
---|
403 | }
|
---|
404 | $uri_self =~ s/\&zonestatus=[^&]*//g; # clean up URL for stuffing into templates
|
---|
405 | }
|
---|
406 |
|
---|
407 | show_msgs();
|
---|
408 |
|
---|
409 | $page->param(curpage => $webvar{page});
|
---|
410 |
|
---|
411 | listdomains();
|
---|
412 |
|
---|
413 | } elsif ($webvar{page} eq 'newdomain') {
|
---|
414 |
|
---|
415 | changepage(page => "domlist", errmsg => "You are not permitted to add domains")
|
---|
416 | unless ($permissions{admin} || $permissions{domain_create});
|
---|
417 |
|
---|
418 | $webvar{group} = $curgroup if !$webvar{group};
|
---|
419 | fill_grouplist("grouplist", $webvar{group});
|
---|
420 | fill_loclist($curgroup, $webvar{defloc} ? $webvar{defloc} : '');
|
---|
421 |
|
---|
422 | if ($session->param('add_failed')) {
|
---|
423 | $session->clear('add_failed');
|
---|
424 | $page->param(add_failed => 1);
|
---|
425 | $page->param(errmsg => $session->param('errmsg'));
|
---|
426 | $session->clear('errmsg');
|
---|
427 | $page->param(domain => $webvar{domain});
|
---|
428 | $page->param(addinactive => $webvar{makeactive} eq 'n');
|
---|
429 | }
|
---|
430 |
|
---|
431 | } elsif ($webvar{page} eq 'adddomain') {
|
---|
432 |
|
---|
433 | changepage(page => "domlist", errmsg => "You are not permitted to add domains")
|
---|
434 | unless ($permissions{admin} || $permissions{domain_create});
|
---|
435 |
|
---|
436 | # security check - does the user have permission to access this entity?
|
---|
437 | if (!check_scope(id => $webvar{group}, type => 'group')) {
|
---|
438 | $session->param('add_failed', 1);
|
---|
439 | ##fixme: domain a security risk for XSS?
|
---|
440 | changepage(page => "newdomain", domain => $webvar{domain},
|
---|
441 | errmsg => "You do not have permission to add a domain to the requested group");
|
---|
442 | }
|
---|
443 |
|
---|
444 | $webvar{makeactive} = 0 if !defined($webvar{makeactive});
|
---|
445 |
|
---|
446 | my ($code,$msg) = $dnsdb->addDomain($webvar{domain}, $webvar{group}, ($webvar{makeactive} eq 'on' ? 1 : 0),
|
---|
447 | $webvar{defloc});
|
---|
448 |
|
---|
449 | if ($code eq 'OK') {
|
---|
450 | $dnsdb->mailNotify("New ".($webvar{makeactive} eq 'on' ? 'Active' : 'Inactive')." Domain Created",
|
---|
451 | ($webvar{makeactive} eq 'on' ? 'Active' : 'Inactive').qq( domain "$webvar{domain}" added by ).
|
---|
452 | $session->param("username"));
|
---|
453 | changepage(page => "reclist", id => $msg);
|
---|
454 | } else {
|
---|
455 | $session->param('add_failed', 1);
|
---|
456 | ##fixme: domain a security risk for XSS?
|
---|
457 | changepage(page => "newdomain", errmsg => $msg, domain => $webvar{domain},
|
---|
458 | group => $webvar{group}, makeactive => ($webvar{makeactive} ? 'y' : 'n'), defloc => $webvar{defloc});
|
---|
459 | }
|
---|
460 |
|
---|
461 | } elsif ($webvar{page} eq 'deldom') {
|
---|
462 |
|
---|
463 | changepage(page => "domlist", errmsg => "You are not permitted to delete domains")
|
---|
464 | unless ($permissions{admin} || $permissions{domain_delete});
|
---|
465 |
|
---|
466 | # security check - does the user have permission to access this entity?
|
---|
467 | if (!check_scope(id => $webvar{id}, type => 'domain')) {
|
---|
468 | changepage(page => "domlist", errmsg => "You do not have permission to delete the requested domain");
|
---|
469 | }
|
---|
470 |
|
---|
471 | $page->param(id => $webvar{id});
|
---|
472 |
|
---|
473 | # first pass = confirm y/n (sorta)
|
---|
474 | if (!defined($webvar{del})) {
|
---|
475 |
|
---|
476 | $page->param(del_getconf => 1);
|
---|
477 | $page->param(domain => $dnsdb->domainName($webvar{id}));
|
---|
478 |
|
---|
479 | } elsif ($webvar{del} eq 'ok') {
|
---|
480 | my $pargroup = $dnsdb->parentID(id => $webvar{id}, type => 'domain', revrec => $webvar{revrec});
|
---|
481 | my ($code,$msg) = $dnsdb->delZone($webvar{id}, $webvar{revrec});
|
---|
482 | if ($code eq 'OK') {
|
---|
483 | changepage(page => "domlist", resultmsg => $msg);
|
---|
484 | } else {
|
---|
485 | changepage(page => "domlist", errmsg => $msg);
|
---|
486 | }
|
---|
487 |
|
---|
488 | } else {
|
---|
489 | # cancelled. whee!
|
---|
490 | changepage(page => "domlist");
|
---|
491 | }
|
---|
492 |
|
---|
493 | } elsif ($webvar{page} eq 'revzones') {
|
---|
494 |
|
---|
495 | $webvar{revrec} = 'y';
|
---|
496 |
|
---|
497 | if (defined($webvar{zonestatus})) {
|
---|
498 | # security check - does the user have permission to access this entity?
|
---|
499 | my $flag = 0;
|
---|
500 | foreach (@viewablegroups) {
|
---|
501 | $flag = 1 if $dnsdb->isParent($_, 'group', $webvar{id}, 'revzone');
|
---|
502 | }
|
---|
503 | if ($flag && ($permissions{admin} || $permissions{domain_edit})) {
|
---|
504 | my $stat = $dnsdb->zoneStatus($webvar{id}, 'y', $webvar{zonestatus});
|
---|
505 | $page->param(resultmsg => $DNSDB::resultstr);
|
---|
506 | } else {
|
---|
507 | $page->param(errmsg => "You are not permitted to view or change the requested reverse zone");
|
---|
508 | }
|
---|
509 | $uri_self =~ s/\&zonestatus=[^&]*//g; # clean up URL for stuffing into templates
|
---|
510 | }
|
---|
511 |
|
---|
512 | show_msgs();
|
---|
513 |
|
---|
514 | $page->param(curpage => $webvar{page});
|
---|
515 | listzones();
|
---|
516 |
|
---|
517 | } elsif ($webvar{page} eq 'newrevzone') {
|
---|
518 |
|
---|
519 | ## scope/access check - use domain settings? invent new (bleh)
|
---|
520 | changepage(page => "revzones", errmsg => "You are not permitted to add reverse zones")
|
---|
521 | unless ($permissions{admin} || $permissions{domain_create});
|
---|
522 |
|
---|
523 | fill_grouplist("grouplist");
|
---|
524 | my $loclist = $dnsdb->getLocDropdown($curgroup);
|
---|
525 | $page->param(loclist => $loclist);
|
---|
526 |
|
---|
527 | # prepopulate revpatt with the matching default record
|
---|
528 | # $dnsdb->getRecByName(revrec => $webvar{revrec}, defrec => $webvar{defrec}, host => 'string');
|
---|
529 |
|
---|
530 | if ($session->param('add_failed')) {
|
---|
531 | $session->clear('add_failed');
|
---|
532 | $page->param(errmsg => $session->param('errmsg'));
|
---|
533 | $session->clear('errmsg');
|
---|
534 | $page->param(revzone => $webvar{revzone});
|
---|
535 | $page->param(revpatt => $webvar{revpatt});
|
---|
536 | }
|
---|
537 |
|
---|
538 | } elsif ($webvar{page} eq 'addrevzone') {
|
---|
539 |
|
---|
540 | changepage(page => "revzones", errmsg => "You are not permitted to add reverse zones")
|
---|
541 | unless ($permissions{admin} || $permissions{domain_create});
|
---|
542 |
|
---|
543 | # security check - does the user have permission to access this entity?
|
---|
544 | if (!check_scope(id => $webvar{group}, type => 'group')) {
|
---|
545 | changepage(page => "newrevzone", add_failed => 1, revzone => $webvar{revzone}, revpatt => $webvar{revpatt},
|
---|
546 | errmsg => "You do not have permission to add a reverse zone to the requested group");
|
---|
547 | }
|
---|
548 |
|
---|
549 | my ($code,$msg) = $dnsdb->addRDNS($webvar{revzone}, $webvar{revpatt}, $webvar{group},
|
---|
550 | ($webvar{makeactive} eq 'on' ? 1 : 0), $webvar{location});
|
---|
551 |
|
---|
552 | if ($code eq 'OK') {
|
---|
553 | changepage(page => "reclist", id => $msg, revrec => 'y');
|
---|
554 | } elsif ($code eq 'WARN') {
|
---|
555 | changepage(page => "reclist", id => $msg, revrec => 'y', warnmsg => $DNSDB::resultstr);
|
---|
556 | } else {
|
---|
557 | $session->param('add_failed', 1);
|
---|
558 | changepage(page => "newrevzone", revzone => $webvar{revzone}, revpatt => $webvar{revpatt}, errmsg => $msg);
|
---|
559 | }
|
---|
560 |
|
---|
561 | } elsif ($webvar{page} eq 'delrevzone') {
|
---|
562 |
|
---|
563 | changepage(page => "revzones", errmsg => "You are not permitted to delete reverse zones")
|
---|
564 | unless ($permissions{admin} || $permissions{domain_delete});
|
---|
565 |
|
---|
566 | # security check - does the user have permission to access this entity?
|
---|
567 | if (!check_scope(id => $webvar{id}, type => 'revzone')) {
|
---|
568 | changepage(page => "revzones", errmsg => "You do not have permission to delete the requested reverse zone");
|
---|
569 | }
|
---|
570 |
|
---|
571 | $page->param(id => $webvar{id});
|
---|
572 |
|
---|
573 | # first pass = confirm y/n (sorta)
|
---|
574 | if (!defined($webvar{del})) {
|
---|
575 |
|
---|
576 | $page->param(del_getconf => 1);
|
---|
577 | $page->param(revzone => $dnsdb->revName($webvar{id}));
|
---|
578 |
|
---|
579 | } elsif ($webvar{del} eq 'ok') {
|
---|
580 | my $pargroup = $dnsdb->parentID(id => $webvar{id}, type => 'revzone', revrec => $webvar{revrec});
|
---|
581 | my $zone = $dnsdb->revName($webvar{id});
|
---|
582 | my ($code,$msg) = $dnsdb->delZone($webvar{id}, 'y');
|
---|
583 | if ($code eq 'OK') {
|
---|
584 | changepage(page => "revzones", resultmsg => $msg);
|
---|
585 | } else {
|
---|
586 | changepage(page => "revzones", errmsg => $msg);
|
---|
587 | }
|
---|
588 |
|
---|
589 | } else {
|
---|
590 | # cancelled. whee!
|
---|
591 | changepage(page => "revzones");
|
---|
592 | }
|
---|
593 |
|
---|
594 | } elsif ($webvar{page} eq 'reclist') {
|
---|
595 |
|
---|
596 | # security check - does the user have permission to view this entity?
|
---|
597 | if (!check_scope(id => $webvar{id}, type =>
|
---|
598 | ($webvar{defrec} eq 'y' ? 'group' : ($webvar{revrec} eq 'y' ? 'revzone' : 'domain')))) {
|
---|
599 | $page->param(errmsg => "You are not permitted to view or change the requested ".
|
---|
600 | ($webvar{defrec} eq 'y' ? "group's default records" :
|
---|
601 | ($webvar{revrec} eq 'y' ? "reverse zone's records" : "domain's records")));
|
---|
602 | $page->param(perm_err => 1); # this causes the template to skip the record listing output.
|
---|
603 | goto DONERECLIST; # and now we skip filling in the content which is not printed due to perm_err above
|
---|
604 | }
|
---|
605 |
|
---|
606 | # hmm. where do we send them?
|
---|
607 | if ($webvar{defrec} eq 'y' && !$permissions{admin}) {
|
---|
608 | $page->param(errmsg => "You are not permitted to edit default records");
|
---|
609 | $page->param(perm_err => 1);
|
---|
610 | } else {
|
---|
611 |
|
---|
612 | $page->param(mayeditsoa => $permissions{admin} || $permissions{domain_edit});
|
---|
613 | ##fixme: ACL needs pondering. Does "edit domain" interact with record add/remove/etc?
|
---|
614 | # Note this seems to be answered "no" in Vega.
|
---|
615 | # ACLs
|
---|
616 | $page->param(record_create => ($permissions{admin} || $permissions{record_create}) );
|
---|
617 | # we don't have any general edit links on the page; they're all embedded in the TMPL_LOOP
|
---|
618 | # $page->param(record_edit => ($permissions{admin} || $permissions{record_edit}) );
|
---|
619 | $page->param(record_delete => ($permissions{admin} || $permissions{record_delete}) );
|
---|
620 |
|
---|
621 | # Handle record list for both default records (per-group) and live domain records
|
---|
622 |
|
---|
623 | $page->param(defrec => $webvar{defrec});
|
---|
624 | $page->param(revrec => $webvar{revrec});
|
---|
625 | $page->param(id => $webvar{id});
|
---|
626 | $page->param(curpage => $webvar{page});
|
---|
627 |
|
---|
628 | my $count = $dnsdb->getRecCount($webvar{defrec}, $webvar{revrec}, $webvar{id}, $filter);
|
---|
629 |
|
---|
630 | $sortby = 'host';
|
---|
631 | # sort/order
|
---|
632 | $session->param($webvar{page}.'sortby', $webvar{sortby}) if $webvar{sortby};
|
---|
633 | $session->param($webvar{page}.'order', $webvar{order}) if $webvar{order};
|
---|
634 |
|
---|
635 | $sortby = $session->param($webvar{page}.'sortby') if $session->param($webvar{page}.'sortby');
|
---|
636 | $sortorder = $session->param($webvar{page}.'order') if $session->param($webvar{page}.'order');
|
---|
637 |
|
---|
638 | # set up the headers
|
---|
639 | my @cols;
|
---|
640 | my %colheads;
|
---|
641 | if ($webvar{revrec} eq 'n') {
|
---|
642 | @cols = ('host', 'type', 'val', 'distance', 'weight', 'port', 'ttl');
|
---|
643 | %colheads = (host => 'Name', type => 'Type', val => 'Address',
|
---|
644 | distance => 'Distance', weight => 'Weight', port => 'Port', ttl => 'TTL');
|
---|
645 | } else {
|
---|
646 | @cols = ('val', 'type', 'host', 'ttl');
|
---|
647 | %colheads = (val => 'IP Address', type => 'Type', host => 'Hostname', ttl => 'TTL');
|
---|
648 | }
|
---|
649 | my %custom = (id => $webvar{id}, defrec => $webvar{defrec}, revrec => $webvar{revrec});
|
---|
650 | fill_colheads($sortby, $sortorder, \@cols, \%colheads, \%custom);
|
---|
651 |
|
---|
652 | # fill the page-count and first-previous-next-last-all details
|
---|
653 | fill_pgcount($count,"records",
|
---|
654 | ($webvar{defrec} eq 'y' ? "group ".$dnsdb->groupName($webvar{id}) :
|
---|
655 | ($webvar{revrec} eq 'y' ? $dnsdb->revName($webvar{id}) : $dnsdb->domainName($webvar{id}))
|
---|
656 | ));
|
---|
657 | fill_fpnla($count); # should put some params on this sub...
|
---|
658 |
|
---|
659 | $page->param(defrec => $webvar{defrec});
|
---|
660 | showzone($webvar{defrec}, $webvar{revrec}, $webvar{id});
|
---|
661 | if ($webvar{defrec} eq 'n') {
|
---|
662 | if ($webvar{revrec} eq 'n') {
|
---|
663 | $page->param(logdom => 1);
|
---|
664 | } else {
|
---|
665 | $page->param(logrdns => 1);
|
---|
666 | }
|
---|
667 | }
|
---|
668 |
|
---|
669 | show_msgs();
|
---|
670 |
|
---|
671 | } # close "you can't edit default records" check
|
---|
672 |
|
---|
673 | # Yes, this is a GOTO target. PTBHTTT.
|
---|
674 | DONERECLIST: ;
|
---|
675 |
|
---|
676 | } elsif ($webvar{page} eq 'record') {
|
---|
677 |
|
---|
678 | # security check - does the user have permission to access this entity?
|
---|
679 | if (!check_scope(id => $webvar{id}, type =>
|
---|
680 | ($webvar{defrec} eq 'y' ? ($webvar{revrec} eq 'y' ? 'defrevrec' : 'defrec') : 'record'))) {
|
---|
681 | $page->param(perm_err => "You are not permitted to edit the requested record");
|
---|
682 | goto DONEREC;
|
---|
683 | }
|
---|
684 | # round 2, check the parent.
|
---|
685 | if (!check_scope(id => $webvar{parentid}, type =>
|
---|
686 | ($webvar{defrec} eq 'y' ? 'group' : ($webvar{revrec} eq 'y' ? 'revzone' : 'domain')))) {
|
---|
687 | my $msg = ($webvar{defrec} eq 'y' ?
|
---|
688 | "You are not permitted to add or edit default records in the requested group" :
|
---|
689 | "You are not permitted to add or edit records in the requested domain/zone");
|
---|
690 | $page->param(perm_err => $msg);
|
---|
691 | goto DONEREC;
|
---|
692 | }
|
---|
693 |
|
---|
694 | $page->param(defrec => $webvar{defrec});
|
---|
695 | $page->param(revrec => $webvar{revrec});
|
---|
696 | $page->param(fwdzone => $webvar{revrec} eq 'n');
|
---|
697 |
|
---|
698 | if ($webvar{recact} eq 'new') {
|
---|
699 |
|
---|
700 | changepage(page => "reclist", errmsg => "You are not permitted to add records", id => $webvar{parentid})
|
---|
701 | unless ($permissions{admin} || $permissions{record_create});
|
---|
702 |
|
---|
703 | $page->param(todo => "Add record");
|
---|
704 | $page->param(recact => "add");
|
---|
705 | $page->param(parentid => $webvar{parentid});
|
---|
706 |
|
---|
707 | fill_recdata();
|
---|
708 |
|
---|
709 | if ($webvar{defrec} eq 'n') {
|
---|
710 | my $defloc = $dnsdb->getZoneLocation($webvar{revrec}, $webvar{parentid});
|
---|
711 | fill_loclist($curgroup, $defloc);
|
---|
712 | }
|
---|
713 |
|
---|
714 | } elsif ($webvar{recact} eq 'add') {
|
---|
715 |
|
---|
716 | changepage(page => "reclist", errmsg => "You are not permitted to add records", id => $webvar{parentid})
|
---|
717 | unless ($permissions{admin} || $permissions{record_create});
|
---|
718 |
|
---|
719 | # location check - if user does not have record_locchg, set $webvar{location} to default location for zone
|
---|
720 | my $parloc = $dnsdb->getZoneLocation($webvar{revrec}, $webvar{parentid});
|
---|
721 | $webvar{location} = $parloc unless ($permissions{admin} || $permissions{record_locchg});
|
---|
722 |
|
---|
723 | my @recargs = ($webvar{defrec}, $webvar{revrec}, $webvar{parentid},
|
---|
724 | \$webvar{name}, \$webvar{type}, \$webvar{address}, $webvar{ttl}, $webvar{location},
|
---|
725 | $webvar{expires}, $webvar{stamp});
|
---|
726 | if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}) {
|
---|
727 | push @recargs, $webvar{distance};
|
---|
728 | if ($webvar{type} == $reverse_typemap{SRV}) {
|
---|
729 | push @recargs, $webvar{weight};
|
---|
730 | push @recargs, $webvar{port};
|
---|
731 | }
|
---|
732 | }
|
---|
733 |
|
---|
734 | my ($code,$msg) = $dnsdb->addRec(@recargs);
|
---|
735 |
|
---|
736 | if ($code eq 'OK' || $code eq 'WARN') {
|
---|
737 | my %pageparams = (page => "reclist", id => $webvar{parentid},
|
---|
738 | defrec => $webvar{defrec}, revrec => $webvar{revrec});
|
---|
739 | $pageparams{warnmsg} = $msg."<br><br>\n".$DNSDB::resultstr if $code eq 'WARN';
|
---|
740 | $pageparams{resultmsg} = $DNSDB::resultstr if $code eq 'OK';
|
---|
741 | changepage(%pageparams);
|
---|
742 | } else {
|
---|
743 | $page->param(failed => 1);
|
---|
744 | $page->param(errmsg => $msg);
|
---|
745 | $page->param(wastrying => "adding");
|
---|
746 | $page->param(todo => "Add record");
|
---|
747 | $page->param(recact => "add");
|
---|
748 | $page->param(parentid => $webvar{parentid});
|
---|
749 | $page->param(id => $webvar{id});
|
---|
750 | fill_recdata(); # populate the form... er, mostly.
|
---|
751 | if ($webvar{defrec} eq 'n') {
|
---|
752 | fill_loclist($curgroup, $webvar{location});
|
---|
753 | }
|
---|
754 | }
|
---|
755 |
|
---|
756 | } elsif ($webvar{recact} eq 'edit') {
|
---|
757 |
|
---|
758 | changepage(page => "reclist", errmsg => "You are not permitted to edit records", id => $webvar{parentid})
|
---|
759 | unless ($permissions{admin} || $permissions{record_edit});
|
---|
760 |
|
---|
761 | $page->param(todo => "Update record");
|
---|
762 | $page->param(recact => "update");
|
---|
763 | $page->param(parentid => $webvar{parentid});
|
---|
764 | $page->param(id => $webvar{id});
|
---|
765 | my $recdata = $dnsdb->getRecLine($webvar{defrec}, $webvar{revrec}, $webvar{id});
|
---|
766 | $page->param(name => $recdata->{host});
|
---|
767 | $page->param(address => $recdata->{val});
|
---|
768 | $page->param(distance => $recdata->{distance});
|
---|
769 | $page->param(weight => $recdata->{weight});
|
---|
770 | $page->param(port => $recdata->{port});
|
---|
771 | $page->param(ttl => $recdata->{ttl});
|
---|
772 | $page->param(typelist => $dnsdb->getTypelist($webvar{revrec}, $recdata->{type}));
|
---|
773 | if ($recdata->{stampactive}) {
|
---|
774 | $page->param(stamp => $recdata->{stamp});
|
---|
775 | $page->param(stamp_until => $recdata->{expires});
|
---|
776 | }
|
---|
777 | if ($webvar{defrec} eq 'n') {
|
---|
778 | fill_loclist($curgroup, $recdata->{location});
|
---|
779 | }
|
---|
780 |
|
---|
781 | } elsif ($webvar{recact} eq 'update') {
|
---|
782 |
|
---|
783 | changepage(page => "reclist", errmsg => "You are not permitted to edit records", id => $webvar{parentid})
|
---|
784 | unless ($permissions{admin} || $permissions{record_edit});
|
---|
785 |
|
---|
786 | # retain old location if user doesn't have permission to fiddle locations
|
---|
787 | my $oldrec = $dnsdb->getRecLine($webvar{defrec}, $webvar{revrec}, $webvar{id});
|
---|
788 | $webvar{location} = $oldrec->{location} unless ($permissions{admin} || $permissions{record_locchg});
|
---|
789 |
|
---|
790 | my ($code,$msg) = $dnsdb->updateRec($webvar{defrec}, $webvar{revrec}, $webvar{id}, $webvar{parentid},
|
---|
791 | \$webvar{name}, \$webvar{type}, \$webvar{address}, $webvar{ttl}, $webvar{location},
|
---|
792 | $webvar{expires}, $webvar{stamp},
|
---|
793 | $webvar{distance}, $webvar{weight}, $webvar{port});
|
---|
794 |
|
---|
795 | if ($code eq 'OK' || $code eq 'WARN') {
|
---|
796 | my %pageparams = (page => "reclist", id => $webvar{parentid},
|
---|
797 | defrec => $webvar{defrec}, revrec => $webvar{revrec});
|
---|
798 | $pageparams{warnmsg} = $msg."<br><br>\n".$DNSDB::resultstr if $code eq 'WARN';
|
---|
799 | $pageparams{resultmsg} = $DNSDB::resultstr if $code eq 'OK';
|
---|
800 | changepage(%pageparams);
|
---|
801 | } else {
|
---|
802 | $page->param(failed => 1);
|
---|
803 | $page->param(errmsg => $msg);
|
---|
804 | $page->param(wastrying => "updating");
|
---|
805 | $page->param(todo => "Update record");
|
---|
806 | $page->param(recact => "update");
|
---|
807 | $page->param(parentid => $webvar{parentid});
|
---|
808 | $page->param(id => $webvar{id});
|
---|
809 | fill_recdata();
|
---|
810 | }
|
---|
811 | }
|
---|
812 |
|
---|
813 | if ($webvar{defrec} eq 'y') {
|
---|
814 | $page->param(dohere => "default records in group ".$dnsdb->groupName($webvar{parentid}));
|
---|
815 | } else {
|
---|
816 | $page->param(dohere => $dnsdb->domainName($webvar{parentid})) if $webvar{revrec} eq 'n';
|
---|
817 | $page->param(dohere => $dnsdb->revName($webvar{parentid})) if $webvar{revrec} eq 'y';
|
---|
818 | }
|
---|
819 |
|
---|
820 | # Yes, this is a GOTO target. PTBHTTT.
|
---|
821 | DONEREC: ;
|
---|
822 |
|
---|
823 | } elsif ($webvar{page} eq 'delrec') {
|
---|
824 |
|
---|
825 | # This is a complete separate segment since it uses a different template from add/edit records above
|
---|
826 |
|
---|
827 | changepage(page => "reclist", errmsg => "You are not permitted to delete records", id => $webvar{parentid},
|
---|
828 | defrec => $webvar{defrec}, revrec => $webvar{revrec})
|
---|
829 | unless ($permissions{admin} || $permissions{record_delete});
|
---|
830 |
|
---|
831 | if (!check_scope(id => $webvar{id}, type =>
|
---|
832 | ($webvar{defrec} eq 'y' ? ($webvar{revrec} eq 'y' ? 'defrevrec' : 'defrec') : 'record'))) {
|
---|
833 | # redirect to domlist because we don't have permission for the entity requested
|
---|
834 | changepage(page => 'domlist', revrec => $webvar{revrec},
|
---|
835 | errmsg => "You do not have permission to delete records in the requested ".
|
---|
836 | ($webvar{defrec} eq 'y' ? 'group' : 'domain'));
|
---|
837 | }
|
---|
838 |
|
---|
839 | $page->param(id => $webvar{id});
|
---|
840 | $page->param(defrec => $webvar{defrec});
|
---|
841 | $page->param(revrec => $webvar{revrec});
|
---|
842 | $page->param(parentid => $webvar{parentid});
|
---|
843 | # first pass = confirm y/n (sorta)
|
---|
844 | if (!defined($webvar{del})) {
|
---|
845 | $page->param(del_getconf => 1);
|
---|
846 | my $rec = $dnsdb->getRecLine($webvar{defrec}, $webvar{revrec}, $webvar{id});
|
---|
847 | $page->param(host => $rec->{host});
|
---|
848 | $page->param(ftype => $typemap{$rec->{type}});
|
---|
849 | $page->param(recval => $rec->{val});
|
---|
850 | } elsif ($webvar{del} eq 'ok') {
|
---|
851 | my ($code,$msg) = $dnsdb->delRec($webvar{defrec}, $webvar{revrec}, $webvar{id});
|
---|
852 | if ($code eq 'OK') {
|
---|
853 | changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec},
|
---|
854 | revrec => $webvar{revrec}, resultmsg => $msg);
|
---|
855 | } else {
|
---|
856 | ## need to find failure mode
|
---|
857 | changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec},
|
---|
858 | revrec => $webvar{revrec}, errmsg => $msg);
|
---|
859 | }
|
---|
860 | } else {
|
---|
861 | changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, revrec => $webvar{revrec});
|
---|
862 | }
|
---|
863 |
|
---|
864 | } elsif ($webvar{page} eq 'editsoa') {
|
---|
865 |
|
---|
866 | # security check - does the user have permission to view this entity?
|
---|
867 | # id is domain/revzone/group id
|
---|
868 | if (!check_scope(id => $webvar{id}, type =>
|
---|
869 | ($webvar{defrec} eq 'y' ? 'group' : ($webvar{revrec} eq 'y' ? 'revzone' : 'domain')))) {
|
---|
870 | changepage(page => 'domlist', errmsg => "You do not have permission to edit the ".
|
---|
871 | ($webvar{defrec} eq 'y' ? 'default ' : '')."SOA record for the requested ".
|
---|
872 | ($webvar{defrec} eq 'y' ? 'group' : 'domain'));
|
---|
873 | }
|
---|
874 |
|
---|
875 | if ($webvar{defrec} eq 'y') {
|
---|
876 | changepage(page => "domlist", errmsg => "You are not permitted to edit default records")
|
---|
877 | unless $permissions{admin};
|
---|
878 | } else {
|
---|
879 | changepage(page => "reclist", errmsg => "You are not permitted to edit domain SOA records", id => $webvar{id})
|
---|
880 | unless ($permissions{admin} || $permissions{domain_edit});
|
---|
881 | }
|
---|
882 |
|
---|
883 | fillsoa($webvar{defrec},$webvar{revrec},$webvar{id});
|
---|
884 |
|
---|
885 | } elsif ($webvar{page} eq 'updatesoa') {
|
---|
886 |
|
---|
887 | # security check - does the user have permission to view this entity?
|
---|
888 | # pass 1, record ID
|
---|
889 | if (!check_scope(id => $webvar{recid}, type =>
|
---|
890 | ($webvar{defrec} eq 'y' ? ($webvar{revrec} eq 'y' ? 'defrevrec' : 'defrec') : 'record'))) {
|
---|
891 | ##fixme: should we redirect to the requested record list page instead of the domain list?
|
---|
892 | changepage(page => 'domlist', errmsg => "You do not have permission to edit the requested SOA record");
|
---|
893 | }
|
---|
894 | # pass 2, parent (group or domain) ID
|
---|
895 | if (!check_scope(id => $webvar{id}, type =>
|
---|
896 | ($webvar{defrec} eq 'y' ? 'group' : ($webvar{revrec} eq 'y' ? 'revzone' : 'domain')))) {
|
---|
897 | changepage(page => ($webvar{revrec} eq 'y' ? 'revzones' : 'domlist'),
|
---|
898 | errmsg => "You do not have permission to edit the ".
|
---|
899 | ($webvar{defrec} eq 'y' ? 'default ' : '')."SOA record for the requested ".
|
---|
900 | ($webvar{defrec} eq 'y' ? 'group' : ($webvar{revrec} eq 'y' ? 'reverse zone' : 'domain')) );
|
---|
901 | }
|
---|
902 |
|
---|
903 | changepage(page => "reclist", errmsg => "You are not permitted to edit domain SOA records", id => $webvar{id})
|
---|
904 | unless ($permissions{admin} || $permissions{domain_edit});
|
---|
905 |
|
---|
906 | my ($code, $msg) = $dnsdb->updateSOA($webvar{defrec}, $webvar{revrec},
|
---|
907 | (contact => $webvar{contact}, prins => $webvar{prins}, refresh => $webvar{refresh},
|
---|
908 | retry => $webvar{retry}, expire => $webvar{expire}, minttl => $webvar{minttl},
|
---|
909 | ttl => $webvar{ttl}, id => $webvar{id}) );
|
---|
910 | if ($code eq 'OK') {
|
---|
911 | changepage(page => "reclist", id => $webvar{id}, defrec => $webvar{defrec}, revrec => $webvar{revrec},
|
---|
912 | resultmsg => "SOA record updated");
|
---|
913 | } else {
|
---|
914 | $page->param(update_failed => 1);
|
---|
915 | $page->param(msg => $msg);
|
---|
916 | fillsoa($webvar{defrec}, $webvar{revrec}, $webvar{id}, 'w');
|
---|
917 | }
|
---|
918 |
|
---|
919 | } elsif ($webvar{page} eq 'grpman') {
|
---|
920 |
|
---|
921 | listgroups();
|
---|
922 |
|
---|
923 | # Permissions!
|
---|
924 | $page->param(addgrp => $permissions{admin} || $permissions{group_create});
|
---|
925 | $page->param(edgrp => $permissions{admin} || $permissions{group_edit});
|
---|
926 | $page->param(delgrp => $permissions{admin} || $permissions{group_delete});
|
---|
927 |
|
---|
928 | show_msgs();
|
---|
929 | $page->param(curpage => $webvar{page});
|
---|
930 |
|
---|
931 | } elsif ($webvar{page} eq 'newgrp') {
|
---|
932 |
|
---|
933 | changepage(page => "grpman", errmsg => "You are not permitted to add groups")
|
---|
934 | unless ($permissions{admin} || $permissions{group_create});
|
---|
935 |
|
---|
936 | # do.. uhh.. stuff.. if we have no webvar{grpaction}
|
---|
937 | if ($webvar{grpaction} && $webvar{grpaction} eq 'add') {
|
---|
938 |
|
---|
939 | # security check - does the user have permission to access this entity?
|
---|
940 | if (!check_scope(id => $webvar{pargroup}, type => 'group')) {
|
---|
941 | changepage(page => "grpman", errmsg => "You are not permitted to add a group to the requested parent group");
|
---|
942 | }
|
---|
943 |
|
---|
944 | my %newperms;
|
---|
945 | my $alterperms = 0;
|
---|
946 | foreach (@permtypes) {
|
---|
947 | $newperms{$_} = 0;
|
---|
948 | if ($permissions{admin} || $permissions{$_}) {
|
---|
949 | $newperms{$_} = (defined($webvar{$_}) && $webvar{$_} eq 'on' ? 1 : 0);
|
---|
950 | } else {
|
---|
951 | $alterperms = 1;
|
---|
952 | }
|
---|
953 | }
|
---|
954 | # "Chained" permissions. Some permissions imply others; make sure they get set.
|
---|
955 | foreach (keys %permchains) {
|
---|
956 | if ($newperms{$_} && !$newperms{$permchains{$_}}) {
|
---|
957 | $newperms{$permchains{$_}} = 1;
|
---|
958 | }
|
---|
959 | }
|
---|
960 | # force inheritance of parent group's default records with inherit flag,
|
---|
961 | # otherwise we end up with the hardcoded defaults from DNSDB.pm. See
|
---|
962 | # https://secure.deepnet.cx/trac/dnsadmin/ticket/8 for the UI enhancement
|
---|
963 | # that will make this variable.
|
---|
964 | my ($code,$msg) = $dnsdb->addGroup($webvar{newgroup}, $webvar{pargroup}, \%newperms, 1);
|
---|
965 | if ($code eq 'OK') {
|
---|
966 | if ($alterperms) {
|
---|
967 | changepage(page => "grpman", warnmsg =>
|
---|
968 | "You can only grant permissions you hold. New group $webvar{newgroup} added with reduced access.");
|
---|
969 | } else {
|
---|
970 | changepage(page => "grpman", resultmsg => "Added group $webvar{newgroup}");
|
---|
971 | }
|
---|
972 | } # fallthrough else
|
---|
973 | # no point in doing extra work
|
---|
974 | fill_permissions($page, \%newperms);
|
---|
975 | $page->param(add_failed => 1);
|
---|
976 | $page->param(errmsg => $msg);
|
---|
977 | $page->param(newgroup => $webvar{newgroup});
|
---|
978 | fill_grouplist('pargroup',$webvar{pargroup});
|
---|
979 | } else {
|
---|
980 | fill_grouplist('pargroup',$curgroup);
|
---|
981 | # fill default permissions with immediate parent's current ones
|
---|
982 | my %parperms;
|
---|
983 | $dnsdb->getPermissions('group', $curgroup, \%parperms);
|
---|
984 | fill_permissions($page, \%parperms);
|
---|
985 | }
|
---|
986 |
|
---|
987 | } elsif ($webvar{page} eq 'delgrp') {
|
---|
988 |
|
---|
989 | changepage(page => "grpman", errmsg => "You are not permitted to delete groups", id => $webvar{parentid})
|
---|
990 | unless ($permissions{admin} || $permissions{group_delete});
|
---|
991 |
|
---|
992 | # security check - does the user have permission to access this entity?
|
---|
993 | if (!check_scope(id => $webvar{id}, type => 'group')) {
|
---|
994 | changepage(page => "grpman", errmsg => "You are not permitted to delete the requested group");
|
---|
995 | }
|
---|
996 |
|
---|
997 | $page->param(id => $webvar{id});
|
---|
998 | # first pass = confirm y/n (sorta)
|
---|
999 | if (!defined($webvar{del})) {
|
---|
1000 | $page->param(del_getconf => 1);
|
---|
1001 |
|
---|
1002 | ##fixme
|
---|
1003 | # do a check for "group has stuff in it", and splatter a big warning
|
---|
1004 | # up along with an unchecked-by-default check box to YES DAMMIT DELETE THE WHOLE THING
|
---|
1005 |
|
---|
1006 | } elsif ($webvar{del} eq 'ok') {
|
---|
1007 | my ($code,$msg) = $dnsdb->delGroup($webvar{id});
|
---|
1008 | if ($code eq 'OK') {
|
---|
1009 | ##fixme: need to clean up log when deleting a major container
|
---|
1010 | changepage(page => "grpman", resultmsg => $msg);
|
---|
1011 | } else {
|
---|
1012 | # need to find failure mode
|
---|
1013 | changepage(page => "grpman", errmsg => $msg);
|
---|
1014 | }
|
---|
1015 | } else {
|
---|
1016 | # cancelled. whee!
|
---|
1017 | changepage(page => "grpman");
|
---|
1018 | }
|
---|
1019 | $page->param(delgroupname => $dnsdb->groupName($webvar{id}));
|
---|
1020 |
|
---|
1021 | } elsif ($webvar{page} eq 'edgroup') {
|
---|
1022 |
|
---|
1023 | changepage(page => "grpman", errmsg => "You are not permitted to edit groups")
|
---|
1024 | unless ($permissions{admin} || $permissions{group_edit});
|
---|
1025 |
|
---|
1026 | # security check - does the user have permission to access this entity?
|
---|
1027 | if (!check_scope(id => $webvar{gid}, type => 'group')) {
|
---|
1028 | changepage(page => "grpman", errmsg => "You are not permitted to edit the requested group");
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | if ($webvar{grpaction} && $webvar{grpaction} eq 'updperms') {
|
---|
1032 | # extra safety check; make sure user can't construct a URL to bypass ACLs
|
---|
1033 | my %curperms;
|
---|
1034 | $dnsdb->getPermissions('group', $webvar{gid}, \%curperms);
|
---|
1035 | my %chperms;
|
---|
1036 | my $alterperms = 0;
|
---|
1037 | foreach (@permtypes) {
|
---|
1038 | $webvar{$_} = 0 if !defined($webvar{$_});
|
---|
1039 | $webvar{$_} = 1 if $webvar{$_} eq 'on';
|
---|
1040 | if ($permissions{admin} || $permissions{$_}) {
|
---|
1041 | $chperms{$_} = $webvar{$_} if $curperms{$_} ne $webvar{$_};
|
---|
1042 | } else {
|
---|
1043 | $alterperms = 1;
|
---|
1044 | $chperms{$_} = 0;
|
---|
1045 | }
|
---|
1046 | }
|
---|
1047 | # "Chained" permissions. Some permissions imply others; make sure they get set.
|
---|
1048 | foreach (keys %permchains) {
|
---|
1049 | if ($chperms{$_} && !$chperms{$permchains{$_}}) {
|
---|
1050 | $chperms{$permchains{$_}} = 1;
|
---|
1051 | }
|
---|
1052 | }
|
---|
1053 | my ($code,$msg) = $dnsdb->changePermissions('group', $webvar{gid}, \%chperms);
|
---|
1054 | if ($code eq 'OK') {
|
---|
1055 | if ($alterperms) {
|
---|
1056 | changepage(page => "grpman", warnmsg =>
|
---|
1057 | "You can only grant permissions you hold. Default permissions in group ".
|
---|
1058 | $dnsdb->groupName($webvar{gid})." updated with reduced access");
|
---|
1059 | } else {
|
---|
1060 | changepage(page => "grpman", resultmsg => $msg);
|
---|
1061 | }
|
---|
1062 | } # fallthrough else
|
---|
1063 | # no point in doing extra work
|
---|
1064 | fill_permissions($page, \%chperms);
|
---|
1065 | $page->param(errmsg => $msg);
|
---|
1066 | }
|
---|
1067 | $page->param(gid => $webvar{gid});
|
---|
1068 | $page->param(grpmeddle => $dnsdb->groupName($webvar{gid}));
|
---|
1069 | my %grpperms;
|
---|
1070 | $dnsdb->getPermissions('group', $webvar{gid}, \%grpperms);
|
---|
1071 | fill_permissions($page, \%grpperms);
|
---|
1072 |
|
---|
1073 | } elsif ($webvar{page} eq 'bulkdomain') {
|
---|
1074 | # Bulk operations on domains. Note all but group move are available on the domain list.
|
---|
1075 | ##fixme: do we care about bulk operations on revzones? Move-to-group, activate, deactivate,
|
---|
1076 | # and delete should all be much rarer for revzones than for domains.
|
---|
1077 |
|
---|
1078 | changepage(page => "domlist", errmsg => "You are not permitted to make bulk domain changes")
|
---|
1079 | unless ($permissions{admin} || $permissions{domain_edit} || $permissions{domain_create} || $permissions{domain_delete});
|
---|
1080 |
|
---|
1081 | fill_grouplist("grouplist");
|
---|
1082 |
|
---|
1083 | my $count = $dnsdb->getZoneCount(revrec => 'n', curgroup => $curgroup);
|
---|
1084 |
|
---|
1085 | $page->param(curpage => $webvar{page});
|
---|
1086 | fill_pgcount($count, 'domains', $dnsdb->groupName($curgroup));
|
---|
1087 | fill_fpnla($count);
|
---|
1088 | $page->param(perpage => $perpage);
|
---|
1089 |
|
---|
1090 | my $domlist = $dnsdb->getZoneList(revrec => 'n', curgroup => $curgroup, offset => $offset);
|
---|
1091 | my $rownum = 0;
|
---|
1092 | foreach my $dom (@{$domlist}) {
|
---|
1093 | delete $dom->{status};
|
---|
1094 | delete $dom->{group};
|
---|
1095 | $dom->{newrow} = (++$rownum) % 5 == 0;
|
---|
1096 | }
|
---|
1097 |
|
---|
1098 | $page->param(domtable => $domlist);
|
---|
1099 | # ACLs
|
---|
1100 | $page->param(maymove => ($permissions{admin} || ($permissions{domain_edit} && $permissions{domain_create} && $permissions{domain_delete})));
|
---|
1101 | $page->param(maystatus => $permissions{admin} || $permissions{domain_edit});
|
---|
1102 | $page->param(maydelete => $permissions{admin} || $permissions{domain_delete});
|
---|
1103 |
|
---|
1104 | } elsif ($webvar{page} eq 'bulkchange') {
|
---|
1105 |
|
---|
1106 | # security check - does the user have permission to access this entity?
|
---|
1107 | if (!check_scope(id => $webvar{destgroup}, type => 'group')) {
|
---|
1108 | $page->param(errmsg => "You are not permitted to make bulk changes in the requested group");
|
---|
1109 | goto DONEBULK;
|
---|
1110 | }
|
---|
1111 |
|
---|
1112 | # per-action scope checks
|
---|
1113 | if ($webvar{bulkaction} eq 'move') {
|
---|
1114 | changepage(page => "domlist", errmsg => "You are not permitted to bulk-move domains")
|
---|
1115 | unless ($permissions{admin} || ($permissions{domain_edit} && $permissions{domain_create} && $permissions{domain_delete}));
|
---|
1116 | my $newgname = $dnsdb->groupName($webvar{destgroup});
|
---|
1117 | $page->param(action => "Move to group $newgname");
|
---|
1118 | } elsif ($webvar{bulkaction} eq 'deactivate' || $webvar{bulkaction} eq 'activate') {
|
---|
1119 | changepage(page => "domlist", errmsg => "You are not permitted to bulk-$webvar{bulkaction} domains")
|
---|
1120 | unless ($permissions{admin} || $permissions{domain_edit});
|
---|
1121 | $page->param(action => "$webvar{bulkaction} domains");
|
---|
1122 | } elsif ($webvar{bulkaction} eq 'delete') {
|
---|
1123 | changepage(page => "domlist", errmsg => "You are not permitted to bulk-delete domains")
|
---|
1124 | unless ($permissions{admin} || $permissions{domain_delete});
|
---|
1125 | $page->param(action => "$webvar{bulkaction} domains");
|
---|
1126 | } else {
|
---|
1127 | # unknown action, bypass actually doing anything. it should not be possible in
|
---|
1128 | # normal operations, and anyone who meddles with the URL gets what they deserve.
|
---|
1129 | goto DONEBULK;
|
---|
1130 | } # move/(de)activate/delete if()
|
---|
1131 |
|
---|
1132 | my @bulkresults;
|
---|
1133 | # nngh. due to alpha-sorting on the previous page, we can't use domid-numeric
|
---|
1134 | # order here, and since we don't have the domain names until we go around this
|
---|
1135 | # loop, we can't alpha-sort them here. :(
|
---|
1136 | foreach (keys %webvar) {
|
---|
1137 | my %row;
|
---|
1138 | next unless $_ =~ /^dom_\d+$/;
|
---|
1139 | # second security check - does the user have permission to meddle with this domain?
|
---|
1140 | if (!check_scope(id => $webvar{$_}, type => 'domain')) {
|
---|
1141 | $row{domerr} = "You are not permitted to make changes to the requested domain";
|
---|
1142 | $row{domain} = $webvar{$_};
|
---|
1143 | push @bulkresults, \%row;
|
---|
1144 | next;
|
---|
1145 | }
|
---|
1146 | $row{domain} = $dnsdb->domainName($webvar{$_});
|
---|
1147 |
|
---|
1148 | # Do the $webvar{bulkaction}
|
---|
1149 | my ($code, $msg);
|
---|
1150 | ($code, $msg) = $dnsdb->changeGroup('domain', $webvar{$_}, $webvar{destgroup})
|
---|
1151 | if $webvar{bulkaction} eq 'move';
|
---|
1152 | if ($webvar{bulkaction} eq 'deactivate' || $webvar{bulkaction} eq 'activate') {
|
---|
1153 | my $stat = $dnsdb->zoneStatus($webvar{$_}, 'n', ($webvar{bulkaction} eq 'activate' ? 'domon' : 'domoff'));
|
---|
1154 | $code = (defined($stat) ? 'OK' : 'FAIL');
|
---|
1155 | $msg = (defined($stat) ? $DNSDB::resultstr : $DNSDB::errstr);
|
---|
1156 | }
|
---|
1157 | ($code, $msg) = $dnsdb->delZone($webvar{$_}, 'n')
|
---|
1158 | if $webvar{bulkaction} eq 'delete';
|
---|
1159 |
|
---|
1160 | # Set the result output from the action
|
---|
1161 | if ($code eq 'OK') {
|
---|
1162 | $row{domok} = $msg;
|
---|
1163 | } elsif ($code eq 'WARN') {
|
---|
1164 | $row{domwarn} = $msg;
|
---|
1165 | } else {
|
---|
1166 | $row{domerr} = $msg;
|
---|
1167 | }
|
---|
1168 | push @bulkresults, \%row;
|
---|
1169 |
|
---|
1170 | } # foreach (keys %webvar)
|
---|
1171 | $page->param(bulkresults => \@bulkresults);
|
---|
1172 |
|
---|
1173 | # Yes, this is a GOTO target. PTHBTTT.
|
---|
1174 | DONEBULK: ;
|
---|
1175 |
|
---|
1176 | } elsif ($webvar{page} eq 'useradmin') {
|
---|
1177 |
|
---|
1178 | if (defined($webvar{userstatus})) {
|
---|
1179 | # security check - does the user have permission to access this entity?
|
---|
1180 | my $flag = 0;
|
---|
1181 | foreach (@viewablegroups) {
|
---|
1182 | $flag = 1 if $dnsdb->isParent($_, 'group', $webvar{id}, 'user');
|
---|
1183 | }
|
---|
1184 | if ($flag && ($permissions{admin} || $permissions{user_edit} ||
|
---|
1185 | ($permissions{self_edit} && $webvar{id} == $session->param('uid')) )) {
|
---|
1186 | my $stat = $dnsdb->userStatus($webvar{id}, $webvar{userstatus});
|
---|
1187 | $page->param(resultmsg => $DNSDB::resultstr);
|
---|
1188 | } else {
|
---|
1189 | $page->param(errmsg => "You are not permitted to view or change the requested user");
|
---|
1190 | }
|
---|
1191 | $uri_self =~ s/\&userstatus=[^&]*//g; # clean up URL for stuffing into templates
|
---|
1192 | }
|
---|
1193 |
|
---|
1194 | list_users();
|
---|
1195 |
|
---|
1196 | # Permissions!
|
---|
1197 | $page->param(adduser => $permissions{admin} || $permissions{user_create});
|
---|
1198 | # should we block viewing other users? Vega blocks "editing"...
|
---|
1199 | # NB: no "edit self" link as with groups here. maybe there should be?
|
---|
1200 | # $page->param(eduser => $permissions{admin} || $permissions{user_edit});
|
---|
1201 | $page->param(deluser => $permissions{admin} || $permissions{user_delete});
|
---|
1202 |
|
---|
1203 | show_msgs();
|
---|
1204 | $page->param(curpage => $webvar{page});
|
---|
1205 |
|
---|
1206 | } elsif ($webvar{page} eq 'user') {
|
---|
1207 |
|
---|
1208 | # All user add/edit actions fall through the same page, since there aren't
|
---|
1209 | # really any hard differences between the templates
|
---|
1210 |
|
---|
1211 | #fill_actypelist($webvar{accttype});
|
---|
1212 | fill_clonemelist();
|
---|
1213 | my %grpperms;
|
---|
1214 | $dnsdb->getPermissions('group', $curgroup, \%grpperms);
|
---|
1215 |
|
---|
1216 | my $grppermlist = new HTML::Template(filename => "$templatedir/permlist.tmpl");
|
---|
1217 | my %noaccess;
|
---|
1218 | fill_permissions($grppermlist, \%grpperms, \%noaccess);
|
---|
1219 | $grppermlist->param(info => 1);
|
---|
1220 | $page->param(grpperms => $grppermlist->output);
|
---|
1221 |
|
---|
1222 | $page->param(is_admin => $permissions{admin});
|
---|
1223 |
|
---|
1224 | $webvar{useraction} = '' if !$webvar{useraction};
|
---|
1225 |
|
---|
1226 | if ($webvar{useraction} eq 'add' or $webvar{useraction} eq 'update') {
|
---|
1227 |
|
---|
1228 | $page->param(add => 1) if $webvar{useraction} eq 'add';
|
---|
1229 |
|
---|
1230 | # can't re-use $code and $msg for update if we want to be able to identify separate failure states
|
---|
1231 | my ($code,$code2,$msg,$msg2) = ('OK','OK','OK','OK');
|
---|
1232 |
|
---|
1233 | my $alterperms = 0; # flag iff we need to force custom permissions due to user's current access limits
|
---|
1234 |
|
---|
1235 | my %newperms; # we're going to prefill the existing permissions, so we can change them.
|
---|
1236 | $dnsdb->getPermissions('user', $webvar{uid}, \%newperms);
|
---|
1237 |
|
---|
1238 | if ($webvar{pass1} ne $webvar{pass2}) {
|
---|
1239 | $code = 'FAIL';
|
---|
1240 | $msg = "Passwords don't match";
|
---|
1241 | } else {
|
---|
1242 |
|
---|
1243 | # assemble a permission string - far simpler than trying to pass an
|
---|
1244 | # indeterminate set of permission flags individually
|
---|
1245 |
|
---|
1246 | # But first, we have to see if the user can add any particular
|
---|
1247 | # permissions; otherwise we have a priviledge escalation. Whee.
|
---|
1248 |
|
---|
1249 | if (!$permissions{admin}) {
|
---|
1250 | my %grpperms;
|
---|
1251 | $dnsdb->getPermissions('group', $curgroup, \%grpperms);
|
---|
1252 | my $ret = comparePermissions(\%permissions, \%grpperms);
|
---|
1253 | if ($ret eq '<' || $ret eq '!') {
|
---|
1254 | # User's permissions are not a superset or equivalent to group. Can't inherit
|
---|
1255 | # (and include access user doesn't currently have), so we force custom.
|
---|
1256 | $webvar{perms_type} = 'custom';
|
---|
1257 | $alterperms = 1;
|
---|
1258 | }
|
---|
1259 | }
|
---|
1260 |
|
---|
1261 | my $permstring;
|
---|
1262 | if ($webvar{perms_type} eq 'custom') {
|
---|
1263 | $permstring = 'C:';
|
---|
1264 | foreach (@permtypes) {
|
---|
1265 | if ($permissions{admin} || $permissions{$_}) {
|
---|
1266 | $permstring .= ",$_" if defined($webvar{$_}) && $webvar{$_} eq 'on';
|
---|
1267 | $newperms{$_} = (defined($webvar{$_}) && $webvar{$_} eq 'on' ? 1 : 0);
|
---|
1268 | }
|
---|
1269 | }
|
---|
1270 | $page->param(perm_custom => 1);
|
---|
1271 | } elsif ($permissions{admin} && $webvar{perms_type} eq 'clone') {
|
---|
1272 | $permstring = "c:$webvar{clonesrc}";
|
---|
1273 | $dnsdb->getPermissions('user', $webvar{clonesrc}, \%newperms);
|
---|
1274 | $page->param(perm_clone => 1);
|
---|
1275 | } else {
|
---|
1276 | $permstring = 'i';
|
---|
1277 | }
|
---|
1278 | # "Chained" permissions. Some permissions imply others; make sure they get set.
|
---|
1279 | foreach (keys %permchains) {
|
---|
1280 | if ($newperms{$_} && !$newperms{$permchains{$_}}) {
|
---|
1281 | $newperms{$permchains{$_}} = 1;
|
---|
1282 | $permstring .= ",$permchains{$_}";
|
---|
1283 | }
|
---|
1284 | }
|
---|
1285 | if ($webvar{useraction} eq 'add') {
|
---|
1286 | changepage(page => "useradmin", errmsg => "You do not have permission to add new users")
|
---|
1287 | unless $permissions{admin} || $permissions{user_create};
|
---|
1288 | # no scope check; user is created in the current group
|
---|
1289 | ($code,$msg) = $dnsdb->addUser($webvar{uname}, $curgroup, $webvar{pass1},
|
---|
1290 | ($webvar{makeactive} eq 'on' ? 1 : 0), $webvar{accttype}, $permstring,
|
---|
1291 | $webvar{fname}, $webvar{lname}, $webvar{phone});
|
---|
1292 | } else {
|
---|
1293 | changepage(page => "useradmin", errmsg => "You do not have permission to edit users")
|
---|
1294 | unless $permissions{admin} || $permissions{user_edit} ||
|
---|
1295 | ($permissions{self_edit} && $session->param('uid') == $webvar{uid});
|
---|
1296 | # security check - does the user have permission to access this entity?
|
---|
1297 | if (!check_scope(id => $webvar{user}, type => 'user')) {
|
---|
1298 | changepage(page => "useradmin", errmsg => "You do not have permission to edit the requested user");
|
---|
1299 | }
|
---|
1300 | # User update is icky. I'd really like to do this in one atomic operation,
|
---|
1301 | # but that gets hairy by either duplicating a **lot** of code in DNSDB.pm
|
---|
1302 | # or self-torture trying to not commit the transaction until we're really done.
|
---|
1303 | # Allowing for changing group, but not coding web support just yet.
|
---|
1304 | ($code,$msg) = $dnsdb->updateUser($webvar{uid}, $webvar{uname}, $webvar{gid}, $webvar{pass1},
|
---|
1305 | ($webvar{makeactive} eq 'on' ? 1 : 0), $webvar{accttype},
|
---|
1306 | $webvar{fname}, $webvar{lname}, $webvar{phone});
|
---|
1307 | if ($code eq 'OK') {
|
---|
1308 | $newperms{admin} = 1 if $webvar{accttype} eq 'S';
|
---|
1309 | ($code2,$msg2) = $dnsdb->changePermissions('user', $webvar{uid}, \%newperms, ($permstring eq 'i'));
|
---|
1310 | }
|
---|
1311 | }
|
---|
1312 | }
|
---|
1313 |
|
---|
1314 | if ($code eq 'OK' && $code2 eq 'OK') {
|
---|
1315 | my %pageparams = (page => "useradmin");
|
---|
1316 | if ($alterperms) {
|
---|
1317 | $pageparams{warnmsg} = "You can only grant permissions you hold.\nUser ".
|
---|
1318 | ($webvar{useraction} eq 'add' ? "$webvar{uname} added" : "info updated for $webvar{uname}").
|
---|
1319 | ".\nPermissions ".($webvar{useraction} eq 'add' ? 'added' : 'updated')." with reduced access.";
|
---|
1320 | } else {
|
---|
1321 | $pageparams{resultmsg} = "$msg".($webvar{useraction} eq 'add' ? '' : "\n$msg2");
|
---|
1322 | }
|
---|
1323 | changepage(%pageparams);
|
---|
1324 |
|
---|
1325 | # add/update failed:
|
---|
1326 | } else {
|
---|
1327 | $page->param(add_failed => 1);
|
---|
1328 | $page->param(action => $webvar{useraction});
|
---|
1329 | $page->param(set_permgroup => 1);
|
---|
1330 | if ($webvar{perms_type} eq 'inherit') { # set permission class radio
|
---|
1331 | $page->param(perm_inherit => 1);
|
---|
1332 | } elsif ($webvar{perms_type} eq 'clone') {
|
---|
1333 | $page->param(perm_clone => 1);
|
---|
1334 | } else {
|
---|
1335 | $page->param(perm_custom => 1);
|
---|
1336 | }
|
---|
1337 | $page->param(uname => $webvar{uname});
|
---|
1338 | $page->param(fname => $webvar{fname});
|
---|
1339 | $page->param(lname => $webvar{lname});
|
---|
1340 | $page->param(pass1 => $webvar{pass1});
|
---|
1341 | $page->param(pass2 => $webvar{pass2});
|
---|
1342 | $page->param(errmsg => "User info updated but permissions update failed: $msg2") if $code eq 'OK';
|
---|
1343 | $page->param(errmsg => $msg) if $code ne 'OK';
|
---|
1344 | fill_permissions($page, \%newperms);
|
---|
1345 | fill_actypelist($webvar{accttype});
|
---|
1346 | fill_clonemelist();
|
---|
1347 | }
|
---|
1348 |
|
---|
1349 | } elsif ($webvar{useraction} eq 'edit') {
|
---|
1350 |
|
---|
1351 | changepage(page => "useradmin", errmsg => "You do not have permission to edit users")
|
---|
1352 | unless $permissions{admin} || $permissions{user_edit} ||
|
---|
1353 | ($permissions{self_edit} && $session->param('uid') == $webvar{user});
|
---|
1354 |
|
---|
1355 | # security check - does the user have permission to access this entity?
|
---|
1356 | if (!check_scope(id => $webvar{user}, type => 'user')) {
|
---|
1357 | changepage(page => "useradmin", errmsg => "You do not have permission to edit the requested user");
|
---|
1358 | }
|
---|
1359 |
|
---|
1360 | $page->param(set_permgroup => 1);
|
---|
1361 | $page->param(action => 'update');
|
---|
1362 | $page->param(uid => $webvar{user});
|
---|
1363 | fill_clonemelist();
|
---|
1364 |
|
---|
1365 | my $userinfo = $dnsdb->getUserData($webvar{user});
|
---|
1366 | fill_actypelist($userinfo->{type});
|
---|
1367 | # not using this yet, but adding it now means we can *much* more easily do so later.
|
---|
1368 | $page->param(gid => $userinfo->{group_id});
|
---|
1369 |
|
---|
1370 | my %curperms;
|
---|
1371 | $dnsdb->getPermissions('user', $webvar{user}, \%curperms);
|
---|
1372 | fill_permissions($page, \%curperms);
|
---|
1373 |
|
---|
1374 | $page->param(uname => $userinfo->{username});
|
---|
1375 | $page->param(fname => $userinfo->{firstname});
|
---|
1376 | $page->param(lname => $userinfo->{lastname});
|
---|
1377 | $page->param(set_permgroup => 1);
|
---|
1378 | if ($userinfo->{inherit_perm}) {
|
---|
1379 | $page->param(perm_inherit => 1);
|
---|
1380 | } else {
|
---|
1381 | $page->param(perm_custom => 1);
|
---|
1382 | }
|
---|
1383 | } else {
|
---|
1384 | changepage(page => "useradmin", errmsg => "You are not allowed to add new users")
|
---|
1385 | unless $permissions{admin} || $permissions{user_create};
|
---|
1386 | # default is "new"
|
---|
1387 | $page->param(add => 1);
|
---|
1388 | $page->param(action => 'add');
|
---|
1389 | fill_permissions($page, \%grpperms);
|
---|
1390 | fill_actypelist();
|
---|
1391 | }
|
---|
1392 |
|
---|
1393 | } elsif ($webvar{page} eq 'deluser') {
|
---|
1394 |
|
---|
1395 | changepage(page=> "useradmin", errmsg => "You are not allowed to delete users")
|
---|
1396 | unless $permissions{admin} || $permissions{user_delete};
|
---|
1397 |
|
---|
1398 | # security check - does the user have permission to access this entity?
|
---|
1399 | if (!check_scope(id => $webvar{id}, type => 'user')) {
|
---|
1400 | changepage(page => "useradmin", errmsg => "You are not permitted to delete the requested user");
|
---|
1401 | }
|
---|
1402 |
|
---|
1403 | $page->param(id => $webvar{id});
|
---|
1404 | # first pass = confirm y/n (sorta)
|
---|
1405 | if (!defined($webvar{del})) {
|
---|
1406 | $page->param(del_getconf => 1);
|
---|
1407 | $page->param(user => $dnsdb->userFullName($webvar{id}));
|
---|
1408 | } elsif ($webvar{del} eq 'ok') {
|
---|
1409 | my ($code,$msg) = $dnsdb->delUser($webvar{id});
|
---|
1410 | if ($code eq 'OK') {
|
---|
1411 | # success. go back to the user list, do not pass "GO"
|
---|
1412 | changepage(page => "useradmin", resultmsg => $msg);
|
---|
1413 | } else {
|
---|
1414 | changepage(page => "useradmin", errmsg => $msg);
|
---|
1415 | }
|
---|
1416 | } else {
|
---|
1417 | # cancelled. whee!
|
---|
1418 | changepage(page => "useradmin");
|
---|
1419 | }
|
---|
1420 |
|
---|
1421 | } elsif ($webvar{page} eq 'loclist') {
|
---|
1422 |
|
---|
1423 | changepage(page => "domlist", errmsg => "You are not allowed access to this function")
|
---|
1424 | unless $permissions{admin} || $permissions{location_view};
|
---|
1425 |
|
---|
1426 | # security check - does the user have permission to access this entity?
|
---|
1427 | # if (!check_scope(id => $webvar{id}, type => 'loc')) {
|
---|
1428 | # changepage(page => "loclist", errmsg => "You are not permitted to <foo> the requested location/view");
|
---|
1429 | # }
|
---|
1430 | list_locations();
|
---|
1431 | show_msgs();
|
---|
1432 |
|
---|
1433 | # Permissions!
|
---|
1434 | $page->param(addloc => $permissions{admin} || $permissions{location_create});
|
---|
1435 | $page->param(delloc => $permissions{admin} || $permissions{location_delete});
|
---|
1436 |
|
---|
1437 | } elsif ($webvar{page} eq 'location') {
|
---|
1438 |
|
---|
1439 | changepage(page => "domlist", errmsg => "You are not allowed access to this function")
|
---|
1440 | unless $permissions{admin} || $permissions{location_view};
|
---|
1441 |
|
---|
1442 | # security check - does the user have permission to access this entity?
|
---|
1443 | # if (!check_scope(id => $webvar{id}, type => 'loc')) {
|
---|
1444 | # changepage(page => "loclist", errmsg => "You are not permitted to <foo> the requested location/view");
|
---|
1445 | # }
|
---|
1446 |
|
---|
1447 | $webvar{locact} = '' if !$webvar{locact};
|
---|
1448 |
|
---|
1449 | if ($webvar{locact} eq 'add') {
|
---|
1450 | changepage(page => "loclist", errmsg => "You are not permitted to add locations/views", id => $webvar{parentid})
|
---|
1451 | unless ($permissions{admin} || $permissions{location_create});
|
---|
1452 |
|
---|
1453 | my ($code,$msg) = $dnsdb->addLoc($curgroup, $webvar{locname}, $webvar{comments}, $webvar{iplist});
|
---|
1454 |
|
---|
1455 | if ($code eq 'OK' || $code eq 'WARN') {
|
---|
1456 | my %pageparams = (page => "loclist", id => $webvar{parentid},
|
---|
1457 | defrec => $webvar{defrec}, revrec => $webvar{revrec});
|
---|
1458 | $pageparams{warnmsg} = $msg."<br><br>\n".$DNSDB::resultstr if $code eq 'WARN';
|
---|
1459 | $pageparams{resultmsg} = $DNSDB::resultstr if $code eq 'OK';
|
---|
1460 | changepage(%pageparams);
|
---|
1461 | } else {
|
---|
1462 | $page->param(failed => 1);
|
---|
1463 | $page->param(errmsg => $msg);
|
---|
1464 | $page->param(wastrying => "adding");
|
---|
1465 | $page->param(todo => "Add location/view");
|
---|
1466 | $page->param(locact => "add");
|
---|
1467 | $page->param(id => $webvar{id});
|
---|
1468 | $page->param(locname => $webvar{locname});
|
---|
1469 | $page->param(comments => $webvar{comments});
|
---|
1470 | $page->param(iplist => $webvar{iplist});
|
---|
1471 | }
|
---|
1472 |
|
---|
1473 | } elsif ($webvar{locact} eq 'edit') {
|
---|
1474 | changepage(page => "loclist", errmsg => "You are not permitted to edit locations/views", id => $webvar{parentid})
|
---|
1475 | unless ($permissions{admin} || $permissions{location_edit});
|
---|
1476 |
|
---|
1477 | my $loc = $dnsdb->getLoc($webvar{loc});
|
---|
1478 | $page->param(wastrying => "editing");
|
---|
1479 | $page->param(todo => "Edit location/view");
|
---|
1480 | $page->param(locact => "update");
|
---|
1481 | $page->param(id => $webvar{loc});
|
---|
1482 | $page->param(locname => $loc->{description});
|
---|
1483 | $page->param(comments => $loc->{comments});
|
---|
1484 | $page->param(iplist => $loc->{iplist});
|
---|
1485 |
|
---|
1486 | } elsif ($webvar{locact} eq 'update') {
|
---|
1487 | changepage(page => "loclist", errmsg => "You are not permitted to edit locations/views", id => $webvar{parentid})
|
---|
1488 | unless ($permissions{admin} || $permissions{location_edit});
|
---|
1489 |
|
---|
1490 | my ($code,$msg) = $dnsdb->updateLoc($webvar{id}, $curgroup, $webvar{locname}, $webvar{comments}, $webvar{iplist});
|
---|
1491 |
|
---|
1492 | if ($code eq 'OK') {
|
---|
1493 | changepage(page => "loclist", resultmsg => $msg);
|
---|
1494 | } else {
|
---|
1495 | $page->param(failed => 1);
|
---|
1496 | $page->param(errmsg => $msg);
|
---|
1497 | $page->param(wastrying => "editing");
|
---|
1498 | $page->param(todo => "Edit location/view");
|
---|
1499 | $page->param(locact => "update");
|
---|
1500 | $page->param(id => $webvar{loc});
|
---|
1501 | $page->param(locname => $webvar{locname});
|
---|
1502 | $page->param(comments => $webvar{comments});
|
---|
1503 | $page->param(iplist => $webvar{iplist});
|
---|
1504 | }
|
---|
1505 | } else {
|
---|
1506 | changepage(page => "loclist", errmsg => "You are not permitted to add locations/views", id => $webvar{parentid})
|
---|
1507 | unless ($permissions{admin} || $permissions{location_create});
|
---|
1508 |
|
---|
1509 | $page->param(todo => "Add location/view");
|
---|
1510 | $page->param(locact => "add");
|
---|
1511 | $page->param(locname => ($webvar{locname} ? $webvar{locname} : ''));
|
---|
1512 | $page->param(iplist => ($webvar{iplist} ? $webvar{iplist} : ''));
|
---|
1513 |
|
---|
1514 | show_msgs();
|
---|
1515 | }
|
---|
1516 |
|
---|
1517 | } elsif ($webvar{page} eq 'delloc') {
|
---|
1518 |
|
---|
1519 | changepage(page=> "loclist", errmsg => "You are not allowed to delete locations")
|
---|
1520 | unless $permissions{admin} || $permissions{location_delete};
|
---|
1521 |
|
---|
1522 | # security check - does the user have permission to access this entity?
|
---|
1523 | # if (!check_scope(id => $webvar{id}, type => 'loc')) {
|
---|
1524 | # changepage(page => "loclist", errmsg => "You are not permitted to <foo> the requested location/view");
|
---|
1525 | # }
|
---|
1526 |
|
---|
1527 | $page->param(locid => $webvar{locid});
|
---|
1528 | my $locdata = $dnsdb->getLoc($webvar{locid});
|
---|
1529 | $locdata->{description} = $webvar{locid} if !$locdata->{description};
|
---|
1530 | # first pass = confirm y/n (sorta)
|
---|
1531 | if (!defined($webvar{del})) {
|
---|
1532 | $page->param(del_getconf => 1);
|
---|
1533 | $page->param(location => $locdata->{description});
|
---|
1534 | } elsif ($webvar{del} eq 'ok') {
|
---|
1535 | my ($code,$msg) = $dnsdb->delLoc($webvar{locid});
|
---|
1536 | if ($code eq 'OK') {
|
---|
1537 | # success. go back to the user list, do not pass "GO"
|
---|
1538 | changepage(page => "loclist", resultmsg => $msg);
|
---|
1539 | } else {
|
---|
1540 | changepage(page => "loclist", errmsg => $msg);
|
---|
1541 | }
|
---|
1542 | } else {
|
---|
1543 | # cancelled. whee!
|
---|
1544 | changepage(page => "loclist");
|
---|
1545 | }
|
---|
1546 |
|
---|
1547 | } elsif ($webvar{page} eq 'dnsq') {
|
---|
1548 |
|
---|
1549 | $page->param(qfor => $webvar{qfor}) if $webvar{qfor};
|
---|
1550 | $page->param(typelist => $dnsdb->getTypelist('l', ($webvar{type} ? $webvar{type} : undef)));
|
---|
1551 | $page->param(nrecurse => $webvar{nrecurse}) if $webvar{nrecurse};
|
---|
1552 | $page->param(resolver => $webvar{resolver}) if $webvar{resolver};
|
---|
1553 |
|
---|
1554 | if ($webvar{qfor}) {
|
---|
1555 | my $resolv = Net::DNS::Resolver->new;
|
---|
1556 | $resolv->tcp_timeout(5); # make me adjustable!
|
---|
1557 | $resolv->udp_timeout(5); # make me adjustable!
|
---|
1558 | $resolv->recurse(0) if $webvar{nrecurse};
|
---|
1559 | $resolv->nameservers($webvar{resolver}) if $webvar{resolver};
|
---|
1560 | my $query = $resolv->query($webvar{qfor}, $typemap{$webvar{type}});
|
---|
1561 | if ($query) {
|
---|
1562 |
|
---|
1563 | $page->param(showresults => 1);
|
---|
1564 |
|
---|
1565 | my @answer;
|
---|
1566 | foreach my $rr ($query->answer) {
|
---|
1567 | # next unless $rr->type eq "A" or $rr->type eq 'NS';
|
---|
1568 | my %row;
|
---|
1569 | my ($host,$ttl,$class,$type,$data) =
|
---|
1570 | ($rr->string =~ /^([0-9a-zA-Z_.-]+)\s+(\d+)\s+([A-Za-z]+)\s+([A-Za-z]+)\s+(.+)$/s);
|
---|
1571 | $row{host} = $host;
|
---|
1572 | $row{ftype} = $type;
|
---|
1573 | $row{rdata} = ($type eq 'SOA' ? "<pre>$data</pre>" : $data);
|
---|
1574 | push @answer, \%row;
|
---|
1575 | }
|
---|
1576 | $page->param(answer => \@answer);
|
---|
1577 |
|
---|
1578 | my @additional;
|
---|
1579 | foreach my $rr ($query->additional) {
|
---|
1580 | # next unless $rr->type eq "A" or $rr->type eq 'NS';
|
---|
1581 | my %row;
|
---|
1582 | my ($host,$ttl,$class,$type,$data) =
|
---|
1583 | ($rr->string =~ /^([0-9a-zA-Z_.-]+)\s+(\d+)\s+([A-Za-z]+)\s+([A-Za-z]+)\s+(.+)$/);
|
---|
1584 | $row{host} = $host;
|
---|
1585 | $row{ftype} = $type;
|
---|
1586 | $row{rdata} = $data;
|
---|
1587 | push @additional, \%row;
|
---|
1588 | }
|
---|
1589 | $page->param(additional => \@additional);
|
---|
1590 |
|
---|
1591 | my @authority;
|
---|
1592 | foreach my $rr ($query->authority) {
|
---|
1593 | # next unless $rr->type eq "A" or $rr->type eq 'NS';
|
---|
1594 | my %row;
|
---|
1595 | my ($host,$ttl,$class,$type,$data) =
|
---|
1596 | ($rr->string =~ /^([0-9a-zA-Z_.-]+)\s+(\d+)\s+([A-Za-z]+)\s+([A-Za-z]+)\s+(.+)$/);
|
---|
1597 | $row{host} = $host;
|
---|
1598 | $row{ftype} = $type;
|
---|
1599 | $row{rdata} = $data;
|
---|
1600 | push @authority, \%row;
|
---|
1601 | }
|
---|
1602 | $page->param(authority => \@authority);
|
---|
1603 |
|
---|
1604 | $page->param(usedresolver => $resolv->answerfrom);
|
---|
1605 | $page->param(frtype => $typemap{$webvar{type}});
|
---|
1606 |
|
---|
1607 | } else {
|
---|
1608 | $page->param(errmsg => $resolv->errorstring);
|
---|
1609 | }
|
---|
1610 | }
|
---|
1611 | ## done DNS query
|
---|
1612 |
|
---|
1613 | } elsif ($webvar{page} eq 'axfr') {
|
---|
1614 |
|
---|
1615 | changepage(page => "domlist", errmsg => "You are not permitted to import domains")
|
---|
1616 | unless ($permissions{admin} || $permissions{domain_create});
|
---|
1617 |
|
---|
1618 | # don't need this while we've got the dropdown in the menu. hmm.
|
---|
1619 | fill_grouplist("grouplist");
|
---|
1620 |
|
---|
1621 | $page->param(ifrom => $webvar{ifrom}) if $webvar{ifrom};
|
---|
1622 | $page->param(rwsoa => $webvar{rwsoa}) if $webvar{rwsoa};
|
---|
1623 | $page->param(rwns => $webvar{rwns}) if $webvar{rwns};
|
---|
1624 | $page->param(forcettl => $webvar{forcettl}) if $webvar{forcettl};
|
---|
1625 | $page->param(newttl => $webvar{newttl}) if $webvar{newttl};
|
---|
1626 | # This next one is arguably better on by default, but Breaking Things Is Bad, Mmmkay?
|
---|
1627 | $page->param(mergematching => $webvar{mergematching}) if $webvar{mergematching};
|
---|
1628 | $page->param(dominactive => 1) if (!$webvar{domactive} && $webvar{doit}); # eww.
|
---|
1629 | $page->param(importdoms => $webvar{importdoms}) if $webvar{importdoms};
|
---|
1630 |
|
---|
1631 | # shut up warning about uninitialized variable
|
---|
1632 | $webvar{doit} = '' if !defined($webvar{doit});
|
---|
1633 |
|
---|
1634 | if ($webvar{doit} eq 'y' && !$webvar{ifrom}) {
|
---|
1635 | $page->param(errmsg => "Need to set host to import from");
|
---|
1636 | } elsif ($webvar{doit} eq 'y' && !$webvar{importdoms}) {
|
---|
1637 | $page->param(errmsg => "Need domains to import");
|
---|
1638 | } elsif ($webvar{doit} eq 'y') {
|
---|
1639 |
|
---|
1640 | # security check - does the user have permission to access this entity?
|
---|
1641 | if (!check_scope(id => $webvar{group}, type => 'group')) {
|
---|
1642 | $page->param(errmsg => "You are not permitted to import domains into the requested group");
|
---|
1643 | goto DONEAXFR;
|
---|
1644 | }
|
---|
1645 |
|
---|
1646 | # Bizarre Things Happen when you AXFR a null-named zone.
|
---|
1647 | $webvar{importdoms} =~ s/^\s+//;
|
---|
1648 | my @domlist = split /\s+/, $webvar{importdoms};
|
---|
1649 | my @results;
|
---|
1650 | foreach my $domain (@domlist) {
|
---|
1651 | my %row;
|
---|
1652 | my ($code,$msg) = $dnsdb->importAXFR($webvar{ifrom}, $domain, $webvar{group},
|
---|
1653 | status => $webvar{domactive}, rwsoa => $webvar{rwsoa}, rwns => $webvar{rwns},
|
---|
1654 | newttl => ($webvar{forcettl} ? $webvar{newttl} : 0),
|
---|
1655 | merge => $webvar{mergematching});
|
---|
1656 | $row{domok} = $msg if $code eq 'OK';
|
---|
1657 | if ($code eq 'WARN') {
|
---|
1658 | $msg =~ s|\n|<br />|g;
|
---|
1659 | $row{domwarn} = $msg;
|
---|
1660 | }
|
---|
1661 | if ($code eq 'FAIL') {
|
---|
1662 | $msg =~ s|\n|<br />\n|g;
|
---|
1663 | $row{domerr} = $msg;
|
---|
1664 | }
|
---|
1665 | $msg = "<br />\n".$msg if $msg =~ m|<br />|;
|
---|
1666 | $row{domain} = $domain;
|
---|
1667 | push @results, \%row;
|
---|
1668 | }
|
---|
1669 | $page->param(axfrresults => \@results);
|
---|
1670 | }
|
---|
1671 |
|
---|
1672 | # Yes, this is a GOTO target. PTBHTTT.
|
---|
1673 | DONEAXFR: ;
|
---|
1674 |
|
---|
1675 | } elsif ($webvar{page} eq 'whoisq') {
|
---|
1676 |
|
---|
1677 | if ($webvar{qfor}) {
|
---|
1678 | use Net::Whois::Raw;
|
---|
1679 | use Text::Wrap;
|
---|
1680 |
|
---|
1681 | # caching useful?
|
---|
1682 | #$Net::Whois::Raw::CACHE_DIR = "/var/spool/pwhois/";
|
---|
1683 | #$Net::Whois::Raw::CACHE_TIME = 60;
|
---|
1684 |
|
---|
1685 | my ($dominfo, $whois_server) = whois($webvar{qfor});
|
---|
1686 | ##fixme: if we're given an IP, try rwhois as well as whois so we get the real final data
|
---|
1687 |
|
---|
1688 | # le sigh. idjits spit out data without linefeeds...
|
---|
1689 | $Text::Wrap::columns = 88;
|
---|
1690 |
|
---|
1691 | # &%$@%@# high-bit crap. We should probably find a way to properly recode these
|
---|
1692 | # instead of one-by-one. Note CGI::Simple's escapeHTML() doesn't do more than
|
---|
1693 | # the bare minimum. :/
|
---|
1694 | # Mainly an XHTML validation thing.
|
---|
1695 | $dominfo = $q->escapeHTML($dominfo);
|
---|
1696 | $dominfo =~ s/\xa9/\©/g;
|
---|
1697 | $dominfo =~ s/\xae/\®/g;
|
---|
1698 |
|
---|
1699 | $page->param(qfor => $webvar{qfor});
|
---|
1700 | $page->param(dominfo => wrap('','',$dominfo));
|
---|
1701 | $page->param(whois_server => $whois_server);
|
---|
1702 | } else {
|
---|
1703 | $page->param(errmsg => "Missing host or domain to query in WHOIS") if $webvar{askaway};
|
---|
1704 | }
|
---|
1705 |
|
---|
1706 | } elsif ($webvar{page} eq 'log') {
|
---|
1707 |
|
---|
1708 | my $id = $curgroup; # we do this because the group log may be called from (almost) any page,
|
---|
1709 | # but the others are much more limited. this is probably non-optimal.
|
---|
1710 |
|
---|
1711 | if ($webvar{ltype} && $webvar{ltype} eq 'user') {
|
---|
1712 | ##fixme: where should we call this from?
|
---|
1713 | $id = $webvar{id};
|
---|
1714 | if (!check_scope(id => $id, type => 'user')) {
|
---|
1715 | $page->param(errmsg => "You are not permitted to view log entries for the requested user");
|
---|
1716 | goto DONELOG;
|
---|
1717 | }
|
---|
1718 | $page->param(logfor => 'user '.$dnsdb->userFullName($id));
|
---|
1719 | } elsif ($webvar{ltype} && $webvar{ltype} eq 'dom') {
|
---|
1720 | $id = $webvar{id};
|
---|
1721 | if (!check_scope(id => $id, type => 'domain')) {
|
---|
1722 | $page->param(errmsg => "You are not permitted to view log entries for the requested domain");
|
---|
1723 | goto DONELOG;
|
---|
1724 | }
|
---|
1725 | $page->param(logfor => 'domain '.$dnsdb->domainName($id));
|
---|
1726 | } elsif ($webvar{ltype} && $webvar{ltype} eq 'rdns') {
|
---|
1727 | $id = $webvar{id};
|
---|
1728 | if (!check_scope(id => $id, type => 'revzone')) {
|
---|
1729 | $page->param(errmsg => "You are not permitted to view log entries for the requested reverse zone");
|
---|
1730 | goto DONELOG;
|
---|
1731 | }
|
---|
1732 | $page->param(logfor => 'reverse zone '.$dnsdb->revName($id));
|
---|
1733 | } else {
|
---|
1734 | # Default to listing curgroup log
|
---|
1735 | $page->param(logfor => 'group '.$dnsdb->groupName($id));
|
---|
1736 | # note that scope limitations are applied via the change-group check;
|
---|
1737 | # group log is always for the "current" group
|
---|
1738 | }
|
---|
1739 | $webvar{ltype} = 'group' if !$webvar{ltype};
|
---|
1740 | my $lcount = $dnsdb->getLogCount(id => $id, logtype => $webvar{ltype}) or push @debugbits, $dnsdb->errstr;
|
---|
1741 |
|
---|
1742 | $page->param(id => $id);
|
---|
1743 | $page->param(ltype => $webvar{ltype});
|
---|
1744 |
|
---|
1745 | fill_fpnla($lcount);
|
---|
1746 | fill_pgcount($lcount, "log entries", '');
|
---|
1747 | $page->param(curpage => $webvar{page}.($webvar{ltype} ? "&ltype=$webvar{ltype}" : ''));
|
---|
1748 |
|
---|
1749 | $sortby = 'stamp';
|
---|
1750 | $sortorder = 'DESC'; # newest-first; although filtering is probably going to be more useful than sorting
|
---|
1751 | # sort/order
|
---|
1752 | $session->param($webvar{page}.'sortby', $webvar{sortby}) if $webvar{sortby};
|
---|
1753 | $session->param($webvar{page}.'order', $webvar{order}) if $webvar{order};
|
---|
1754 |
|
---|
1755 | $sortby = $session->param($webvar{page}.'sortby') if $session->param($webvar{page}.'sortby');
|
---|
1756 | $sortorder = $session->param($webvar{page}.'order') if $session->param($webvar{page}.'order');
|
---|
1757 |
|
---|
1758 | # Set up the column headings with the sort info
|
---|
1759 | my @cols = ('fname','username','entry','stamp');
|
---|
1760 | my %colnames = (fname => 'Name', username => 'Username', entry => 'Log Entry', stamp => 'Date/Time');
|
---|
1761 | fill_colheads($sortby, $sortorder, \@cols, \%colnames);
|
---|
1762 |
|
---|
1763 | ##fixme: increase per-page limit or use separate limit for log? some ops give *lots* of entries...
|
---|
1764 | my $logentries = $dnsdb->getLogEntries(id => $id, logtype => $webvar{ltype},
|
---|
1765 | offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder);
|
---|
1766 | $page->param(logentries => $logentries);
|
---|
1767 |
|
---|
1768 | ##fixme:
|
---|
1769 | # - filtering
|
---|
1770 | # - show reverse zone column?
|
---|
1771 | # - on log record creation, bundle "parented" log actions (eg, "AXFR record blah for domain foo",
|
---|
1772 | # or "Add record bar for new domain baz") into one entry (eg, "AXFR domain foo", "Add domain baz")?
|
---|
1773 | # need a way to expand this into the complete list, and to exclude "child" entries
|
---|
1774 |
|
---|
1775 | # scope check fail target
|
---|
1776 | DONELOG: ;
|
---|
1777 |
|
---|
1778 | } # end $webvar{page} dance
|
---|
1779 |
|
---|
1780 |
|
---|
1781 | # start output here so we can redirect pages.
|
---|
1782 | print $q->header( -cookie => $sesscookie);
|
---|
1783 | print $header->output;
|
---|
1784 |
|
---|
1785 | ##common bits
|
---|
1786 | # mostly things in the menu
|
---|
1787 | if ($webvar{page} ne 'login' && $webvar{page} ne 'badpage') {
|
---|
1788 | $page->param(username => $session->param("username"));
|
---|
1789 |
|
---|
1790 | $page->param(group => $curgroup);
|
---|
1791 | $page->param(groupname => $dnsdb->groupName($curgroup));
|
---|
1792 | $page->param(logingrp => $dnsdb->groupName($logingroup));
|
---|
1793 | $page->param(logingrp_num => $logingroup);
|
---|
1794 |
|
---|
1795 | ##fixme
|
---|
1796 | $page->param(mayrdns => 1);
|
---|
1797 |
|
---|
1798 | $page->param(mayloc => ($permissions{admin} || $permissions{location_view}));
|
---|
1799 |
|
---|
1800 | $page->param(maydefrec => $permissions{admin});
|
---|
1801 | $page->param(mayimport => $permissions{admin} || $permissions{domain_create});
|
---|
1802 | $page->param(maybulk => $permissions{admin} || $permissions{domain_edit} || $permissions{domain_create} || $permissions{domain_delete});
|
---|
1803 |
|
---|
1804 | $page->param(chggrps => ($permissions{admin} || $permissions{group_create} || $permissions{group_edit} || $permissions{group_delete}));
|
---|
1805 |
|
---|
1806 | # group tree. should go elsewhere, probably
|
---|
1807 | my $tmpgrplist = fill_grptree($logingroup,$curgroup);
|
---|
1808 | $page->param(grptree => $tmpgrplist);
|
---|
1809 | $page->param(subs => ($tmpgrplist ? 1 : 0)); # probably not useful to pass gobs of data in for a boolean
|
---|
1810 | $page->param(inlogingrp => $curgroup == $logingroup);
|
---|
1811 |
|
---|
1812 | # fill in the URL-to-self for the group tree and search-by-letter
|
---|
1813 | $page->param(whereami => $uri_self);
|
---|
1814 | # fill in general URL-to-self
|
---|
1815 | $page->param(script_self => "$ENV{SCRIPT_NAME}?".($curgroup ? "curgroup=$curgroup" : ''));
|
---|
1816 | }
|
---|
1817 |
|
---|
1818 | if (@debugbits) {
|
---|
1819 | print "<pre>\n";
|
---|
1820 | foreach (@debugbits) { print; }
|
---|
1821 | print "</pre>\n";
|
---|
1822 | }
|
---|
1823 |
|
---|
1824 | # spit it out
|
---|
1825 | print $page->output;
|
---|
1826 |
|
---|
1827 | if ($debugenv) {
|
---|
1828 | print "<div id=\"debug\">webvar keys: <pre>\n";
|
---|
1829 | foreach my $key (keys %webvar) {
|
---|
1830 | print "key: $key\tval: $webvar{$key}\n";
|
---|
1831 | }
|
---|
1832 | print "</pre>\nsession:\n<pre>\n";
|
---|
1833 | my $sesdata = $session->dataref();
|
---|
1834 | foreach my $key (keys %$sesdata) {
|
---|
1835 | print "key: $key\tval: ".$sesdata->{$key}."\n";
|
---|
1836 | }
|
---|
1837 | print "</pre>\nENV:\n<pre>\n";
|
---|
1838 | foreach my $key (keys %ENV) {
|
---|
1839 | print "key: $key\tval: $ENV{$key}\n";
|
---|
1840 | }
|
---|
1841 | print "</pre></div>\n";
|
---|
1842 | }
|
---|
1843 |
|
---|
1844 | print $footer->output;
|
---|
1845 |
|
---|
1846 | # as per the docs, Just In Case
|
---|
1847 | $session->flush();
|
---|
1848 |
|
---|
1849 | exit 0;
|
---|
1850 |
|
---|
1851 |
|
---|
1852 | sub fill_grptree {
|
---|
1853 | my $root = shift;
|
---|
1854 | my $cur = shift;
|
---|
1855 | my $indent = shift || ' ';
|
---|
1856 |
|
---|
1857 | my @childlist;
|
---|
1858 |
|
---|
1859 | # some magic to control bad offsets on group change
|
---|
1860 | my $grp_uri_self = $uri_self;
|
---|
1861 | $grp_uri_self =~ s/\&offset=[^&]+// unless ($webvar{page} eq 'reclist' && $webvar{defrec} eq 'n');
|
---|
1862 |
|
---|
1863 | my $grptree = HTML::Template->new(filename => 'templates/grptree.tmpl');
|
---|
1864 | $dnsdb->getChildren($root, \@childlist, 'immediate');
|
---|
1865 | return if $#childlist == -1;
|
---|
1866 | my @grouplist;
|
---|
1867 | foreach (@childlist) {
|
---|
1868 | my %row;
|
---|
1869 | $row{grpname} = $dnsdb->groupName($_);
|
---|
1870 | $row{grpnum} = $_;
|
---|
1871 | $row{whereami} = $grp_uri_self;
|
---|
1872 | $row{curgrp} = ($_ == $cur);
|
---|
1873 | $row{expanded} = $dnsdb->isParent($_, 'group', $cur, 'group');
|
---|
1874 | $row{expanded} = 1 if $_ == $cur;
|
---|
1875 | $row{subs} = fill_grptree($_,$cur,$indent.' ');
|
---|
1876 | $row{indent} = $indent;
|
---|
1877 | push @grouplist, \%row;
|
---|
1878 | }
|
---|
1879 | $grptree->param(indent => $indent);
|
---|
1880 | $grptree->param(treelvl => \@grouplist);
|
---|
1881 | return $grptree->output;
|
---|
1882 | }
|
---|
1883 |
|
---|
1884 | sub changepage {
|
---|
1885 | my %params = @_; # think this works the way I want...
|
---|
1886 |
|
---|
1887 | # cross-site scripting fixup. instead of passing error messages by URL/form
|
---|
1888 | # variable, put them in the session where the nasty user can't meddle.
|
---|
1889 | # these are done here since it's far simpler to pass them in from wherever
|
---|
1890 | # than set them locally everywhere.
|
---|
1891 | foreach my $sessme ('resultmsg','warnmsg','errmsg') {
|
---|
1892 | if (my $tmp = $params{$sessme}) {
|
---|
1893 | $tmp =~ s/^\n//;
|
---|
1894 | $tmp =~ s|\n|<br />\n|g;
|
---|
1895 | $session->param($sessme, $tmp);
|
---|
1896 | delete $params{$sessme};
|
---|
1897 | }
|
---|
1898 | }
|
---|
1899 |
|
---|
1900 | # handle user check
|
---|
1901 | my $newurl = "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}?";
|
---|
1902 | foreach (sort keys %params) {
|
---|
1903 | ## fixme: something is undefined here on add location
|
---|
1904 | $newurl .= "&$_=".$q->url_encode($params{$_});
|
---|
1905 | }
|
---|
1906 |
|
---|
1907 | # Just In Case
|
---|
1908 | $session->flush();
|
---|
1909 |
|
---|
1910 | print $q->redirect ( -url => $newurl, -cookie => $sesscookie);
|
---|
1911 | exit;
|
---|
1912 | } # end changepage
|
---|
1913 |
|
---|
1914 | # wrap up the usual suspects for result, warning, or error messages to be displayed
|
---|
1915 | sub show_msgs {
|
---|
1916 | if ($session->param('resultmsg')) {
|
---|
1917 | $page->param(resultmsg => $session->param('resultmsg'));
|
---|
1918 | $session->clear('resultmsg');
|
---|
1919 | }
|
---|
1920 | if ($session->param('warnmsg')) {
|
---|
1921 | $page->param(warnmsg => $session->param('warnmsg'));
|
---|
1922 | $session->clear('warnmsg');
|
---|
1923 | }
|
---|
1924 | if ($session->param('errmsg')) {
|
---|
1925 | $page->param(errmsg => $session->param('errmsg'));
|
---|
1926 | $session->clear('errmsg');
|
---|
1927 | }
|
---|
1928 | } # end show_msgs
|
---|
1929 |
|
---|
1930 | sub fillsoa {
|
---|
1931 | my $defrec = shift;
|
---|
1932 | my $revrec = shift;
|
---|
1933 | my $id = shift;
|
---|
1934 | my $preserve = shift || 'd'; # Flag to use webvar fields or retrieve from database
|
---|
1935 |
|
---|
1936 | my $domname = ($defrec eq 'y' ? '' : "DOMAIN");
|
---|
1937 |
|
---|
1938 | $page->param(defrec => $defrec);
|
---|
1939 | $page->param(revrec => $revrec);
|
---|
1940 |
|
---|
1941 | # i had a good reason to do this when I wrote it...
|
---|
1942 | # $page->param(domain => $domname);
|
---|
1943 | # $page->param(group => $DNSDB::group);
|
---|
1944 | $page->param(isgrp => 1) if $defrec eq 'y';
|
---|
1945 | $page->param(parent => ($defrec eq 'y' ? $dnsdb->groupName($id) :
|
---|
1946 | ($revrec eq 'n' ? $dnsdb->domainName($id) : $dnsdb->revName($id)) ) );
|
---|
1947 |
|
---|
1948 | # defaults
|
---|
1949 | $page->param(defcontact => $DNSDB::def{contact});
|
---|
1950 | $page->param(defns => $DNSDB::def{prins});
|
---|
1951 | $page->param(defsoattl => $DNSDB::def{soattl});
|
---|
1952 | $page->param(defrefresh => $DNSDB::def{refresh});
|
---|
1953 | $page->param(defretry => $DNSDB::def{retry});
|
---|
1954 | $page->param(defexpire => $DNSDB::def{expire});
|
---|
1955 | $page->param(defminttl => $DNSDB::def{minttl});
|
---|
1956 |
|
---|
1957 | $page->param(id => $id);
|
---|
1958 |
|
---|
1959 | if ($preserve eq 'd') {
|
---|
1960 | # there are probably better ways to do this. TMTOWTDI.
|
---|
1961 | my $soa = $dnsdb->getSOA($defrec, $revrec, $id);
|
---|
1962 |
|
---|
1963 | $page->param(prins => ($soa->{prins} ? $soa->{prins} : $DNSDB::def{prins}));
|
---|
1964 | $page->param(contact => ($soa->{contact} ? $soa->{contact} : $DNSDB::def{contact}));
|
---|
1965 | $page->param(refresh => ($soa->{refresh} ? $soa->{refresh} : $DNSDB::def{refresh}));
|
---|
1966 | $page->param(retry => ($soa->{retry} ? $soa->{retry} : $DNSDB::def{retry}));
|
---|
1967 | $page->param(expire => ($soa->{expire} ? $soa->{expire} : $DNSDB::def{expire}));
|
---|
1968 | $page->param(minttl => ($soa->{minttl} ? $soa->{minttl} : $DNSDB::def{minttl}));
|
---|
1969 | $page->param(ttl => ($soa->{ttl} ? $soa->{ttl} : $DNSDB::def{soattl}));
|
---|
1970 | } else {
|
---|
1971 | $page->param(prins => ($webvar{prins} ? $webvar{prins} : $DNSDB::def{prins}));
|
---|
1972 | $page->param(contact => ($webvar{contact} ? $webvar{contact} : $DNSDB::def{contact}));
|
---|
1973 | $page->param(refresh => ($webvar{refresh} ? $webvar{refresh} : $DNSDB::def{refresh}));
|
---|
1974 | $page->param(retry => ($webvar{retry} ? $webvar{retry} : $DNSDB::def{retry}));
|
---|
1975 | $page->param(expire => ($webvar{expire} ? $webvar{expire} : $DNSDB::def{expire}));
|
---|
1976 | $page->param(minttl => ($webvar{minttl} ? $webvar{minttl} : $DNSDB::def{minttl}));
|
---|
1977 | $page->param(ttl => ($webvar{ttl} ? $webvar{ttl} : $DNSDB::def{soattl}));
|
---|
1978 | }
|
---|
1979 | }
|
---|
1980 |
|
---|
1981 | sub showzone {
|
---|
1982 | my $def = shift;
|
---|
1983 | my $rev = shift;
|
---|
1984 | my $id = shift;
|
---|
1985 |
|
---|
1986 | # get the SOA first
|
---|
1987 | my $soa = $dnsdb->getSOA($def, $rev, $id);
|
---|
1988 |
|
---|
1989 | $page->param(contact => $soa->{contact});
|
---|
1990 | $page->param(prins => $soa->{prins});
|
---|
1991 | $page->param(refresh => $soa->{refresh});
|
---|
1992 | $page->param(retry => $soa->{retry});
|
---|
1993 | $page->param(expire => $soa->{expire});
|
---|
1994 | $page->param(minttl => $soa->{minttl});
|
---|
1995 | $page->param(ttl => $soa->{ttl});
|
---|
1996 |
|
---|
1997 | my $foo2 = $dnsdb->getRecList(defrec => $def, revrec => $rev, id => $id, offset => $webvar{offset},
|
---|
1998 | sortby => $sortby, sortorder => $sortorder, filter => $filter);
|
---|
1999 |
|
---|
2000 | foreach my $rec (@$foo2) {
|
---|
2001 | $rec->{type} = $typemap{$rec->{type}};
|
---|
2002 | $rec->{fwdzone} = $rev eq 'n';
|
---|
2003 | $rec->{distance} = 'n/a' unless ($rec->{type} eq 'MX' || $rec->{type} eq 'SRV');
|
---|
2004 | $rec->{weight} = 'n/a' unless ($rec->{type} eq 'SRV');
|
---|
2005 | $rec->{port} = 'n/a' unless ($rec->{type} eq 'SRV');
|
---|
2006 | # ACLs
|
---|
2007 | $rec->{record_edit} = ($permissions{admin} || $permissions{record_edit});
|
---|
2008 | $rec->{record_delete} = ($permissions{admin} || $permissions{record_delete});
|
---|
2009 | $rec->{locname} = '' unless ($permissions{admin} || $permissions{location_view});
|
---|
2010 | # Timestamps
|
---|
2011 | if ($rec->{expires}) {
|
---|
2012 | $rec->{stamptype} = $rec->{ispast} ? 'expired at' : 'expires at';
|
---|
2013 | } else {
|
---|
2014 | $rec->{stamptype} = 'valid after';
|
---|
2015 | }
|
---|
2016 | # strip seconds and timezone? no, not yet. could probably offer a config knob on this display at some point.
|
---|
2017 | # $rec->{stamp} =~ s/:\d\d-\d+$//;
|
---|
2018 | delete $rec->{expires};
|
---|
2019 | delete $rec->{ispast};
|
---|
2020 | }
|
---|
2021 | $page->param(reclist => $foo2);
|
---|
2022 | }
|
---|
2023 |
|
---|
2024 | sub fill_recdata {
|
---|
2025 | $page->param(typelist => $dnsdb->getTypelist($webvar{revrec}, $webvar{type}));
|
---|
2026 |
|
---|
2027 | # le sigh. we may get called with many empty %webvar keys
|
---|
2028 | no warnings qw( uninitialized );
|
---|
2029 |
|
---|
2030 | ##todo: allow BIND-style bare names, ASS-U-ME that the name is within the domain?
|
---|
2031 | # prefill <domain> or DOMAIN in "Host" space for new records
|
---|
2032 | if ($webvar{revrec} eq 'n') {
|
---|
2033 | my $domroot = ($webvar{defrec} eq 'y' ? 'DOMAIN' : $dnsdb->domainName($webvar{parentid}));
|
---|
2034 | $page->param(name => ($webvar{name} ? $webvar{name} : $domroot));
|
---|
2035 | $page->param(address => $webvar{address});
|
---|
2036 | $page->param(distance => $webvar{distance})
|
---|
2037 | if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV});
|
---|
2038 | $page->param(weight => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV};
|
---|
2039 | $page->param(port => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV};
|
---|
2040 | } else {
|
---|
2041 | my $domroot = ($webvar{defrec} eq 'y' ? 'ADMINDOMAIN' : ".$dnsdb->{domain}");
|
---|
2042 | $page->param(name => ($webvar{name} ? $webvar{name} : $domroot));
|
---|
2043 | my $zname = ($webvar{defrec} eq 'y' ? 'ZONE' : $dnsdb->revName($webvar{parentid}));
|
---|
2044 | $zname =~ s|\d*/\d+$||;
|
---|
2045 | $page->param(address => ($webvar{address} ? $webvar{address} : $zname));
|
---|
2046 | }
|
---|
2047 | # retrieve the right ttl instead of falling (way) back to the hardcoded system default
|
---|
2048 | my $soa = $dnsdb->getSOA($webvar{defrec}, $webvar{revrec}, $webvar{parentid});
|
---|
2049 | $page->param(ttl => ($webvar{ttl} ? $webvar{ttl} : $soa->{minttl}));
|
---|
2050 | $page->param(stamp_until => ($webvar{expires} eq 'until'));
|
---|
2051 | $page->param(stamp => $webvar{stamp});
|
---|
2052 | }
|
---|
2053 |
|
---|
2054 | sub fill_actypelist {
|
---|
2055 | my $curtype = shift || 'u';
|
---|
2056 |
|
---|
2057 | my @actypes;
|
---|
2058 |
|
---|
2059 | my %row1 = (actypeval => 'u', actypename => 'user');
|
---|
2060 | $row1{typesel} = 1 if $curtype eq 'u';
|
---|
2061 | push @actypes, \%row1;
|
---|
2062 |
|
---|
2063 | my %row2 = (actypeval => 'S', actypename => 'superuser');
|
---|
2064 | $row2{typesel} = 1 if $curtype eq 'S';
|
---|
2065 | push @actypes, \%row2;
|
---|
2066 |
|
---|
2067 | $page->param(actypelist => \@actypes);
|
---|
2068 | }
|
---|
2069 |
|
---|
2070 | sub fill_clonemelist {
|
---|
2071 | # shut up some warnings, but don't stomp on caller's state
|
---|
2072 | local $webvar{clonesrc} = 0 if !defined($webvar{clonesrc});
|
---|
2073 |
|
---|
2074 | my $clones = $dnsdb->getUserDropdown($curgroup, $webvar{clonesrc});
|
---|
2075 | $page->param(clonesrc => $clones);
|
---|
2076 | }
|
---|
2077 |
|
---|
2078 | sub fill_fpnla {
|
---|
2079 | my $count = shift;
|
---|
2080 | if ($offset eq 'all') {
|
---|
2081 | $page->param(perpage => $perpage);
|
---|
2082 | # uhm....
|
---|
2083 | } else {
|
---|
2084 | # all these bits only have sensible behaviour if offset is numeric. err, probably.
|
---|
2085 | if ($count > $perpage) {
|
---|
2086 | # if there are more results than the default, always show the "all" link
|
---|
2087 | $page->param(navall => 1);
|
---|
2088 |
|
---|
2089 | if ($offset > 0) {
|
---|
2090 | $page->param(navfirst => 1);
|
---|
2091 | $page->param(navprev => 1);
|
---|
2092 | $page->param(prevoffs => $offset-1);
|
---|
2093 | }
|
---|
2094 |
|
---|
2095 | # show "next" and "last" links if we're not on the last page of results
|
---|
2096 | if ( (($offset+1) * $perpage - $count) < 0 ) {
|
---|
2097 | $page->param(navnext => 1);
|
---|
2098 | $page->param(nextoffs => $offset+1);
|
---|
2099 | $page->param(navlast => 1);
|
---|
2100 | $page->param(lastoffs => int (($count-1)/$perpage));
|
---|
2101 | }
|
---|
2102 | } else {
|
---|
2103 | $page->param(onepage => 1);
|
---|
2104 | }
|
---|
2105 | }
|
---|
2106 | } # end fill_fpnla()
|
---|
2107 |
|
---|
2108 | sub fill_pgcount {
|
---|
2109 | my $pgcount = shift;
|
---|
2110 | my $pgtype = shift;
|
---|
2111 | my $parent = shift;
|
---|
2112 |
|
---|
2113 | $page->param(ntot => $pgcount);
|
---|
2114 | $page->param(nfirst => (($offset eq 'all' ? 0 : $offset)*$perpage+1));
|
---|
2115 | $page->param(npglast => ($offset eq 'all' ? $pgcount :
|
---|
2116 | ( (($offset+1)*$perpage) > $pgcount ? $pgcount : (($offset+1)*$perpage) )
|
---|
2117 | ));
|
---|
2118 | $page->param(pgtype => $pgtype);
|
---|
2119 | $page->param(parent => $parent);
|
---|
2120 | $page->param(filter => $filter);
|
---|
2121 | } # end fill_pgcount()
|
---|
2122 |
|
---|
2123 |
|
---|
2124 | sub listdomains { listzones(); } # temp
|
---|
2125 |
|
---|
2126 | sub listzones {
|
---|
2127 | # ACLs
|
---|
2128 | $page->param(domain_create => ($permissions{admin} || $permissions{domain_create}) );
|
---|
2129 | $page->param(domain_edit => ($permissions{admin} || $permissions{domain_edit}) );
|
---|
2130 | $page->param(domain_delete => ($permissions{admin} || $permissions{domain_delete}) );
|
---|
2131 |
|
---|
2132 | my @childgroups;
|
---|
2133 | $dnsdb->getChildren($curgroup, \@childgroups, 'all') if $searchsubs;
|
---|
2134 | my $childlist = join(',',@childgroups);
|
---|
2135 |
|
---|
2136 | my $count = $dnsdb->getZoneCount(childlist => $childlist, curgroup => $curgroup, revrec => $webvar{revrec},
|
---|
2137 | filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) );
|
---|
2138 |
|
---|
2139 | # fill page count and first-previous-next-last-all bits
|
---|
2140 | fill_pgcount($count,($webvar{revrec} eq 'n' ? 'domains' : 'revzones'),$dnsdb->groupName($curgroup));
|
---|
2141 | fill_fpnla($count);
|
---|
2142 |
|
---|
2143 | $sortby = ($webvar{revrec} eq 'n' ? 'domain' : 'revnet');
|
---|
2144 | # sort/order
|
---|
2145 | $session->param($webvar{page}.'sortby', $webvar{sortby}) if $webvar{sortby};
|
---|
2146 | $session->param($webvar{page}.'order', $webvar{order}) if $webvar{order};
|
---|
2147 |
|
---|
2148 | $sortby = $session->param($webvar{page}.'sortby') if $session->param($webvar{page}.'sortby');
|
---|
2149 | $sortorder = $session->param($webvar{page}.'order') if $session->param($webvar{page}.'order');
|
---|
2150 |
|
---|
2151 | # set up the headers
|
---|
2152 | my @cols = (($webvar{revrec} eq 'n' ? 'domain' : 'revnet'), 'status', 'group');
|
---|
2153 | my %colheads = (domain => 'Domain', revnet => 'Reverse Zone', status => 'Status', group => 'Group');
|
---|
2154 | fill_colheads($sortby, $sortorder, \@cols, \%colheads);
|
---|
2155 |
|
---|
2156 | # hack! hack! pthbttt. have to rethink the status column storage,
|
---|
2157 | # or inactive comes "before" active. *sigh*
|
---|
2158 | $sortorder = ($sortorder eq 'ASC' ? 'DESC' : 'ASC') if $sortby eq 'status';
|
---|
2159 |
|
---|
2160 | # waffle, waffle - keep state on these as well as sortby, sortorder?
|
---|
2161 | ##fixme: put this higher so the count doesn't get munched?
|
---|
2162 | $page->param("start$startwith" => 1) if $startwith && $startwith =~ /^(?:[a-z]|0-9)$/;
|
---|
2163 |
|
---|
2164 | $page->param(filter => $filter) if $filter;
|
---|
2165 | $page->param(searchsubs => $searchsubs) if $searchsubs;
|
---|
2166 |
|
---|
2167 | $page->param(group => $curgroup);
|
---|
2168 |
|
---|
2169 | my $zonelist = $dnsdb->getZoneList(childlist => $childlist, curgroup => $curgroup, revrec => $webvar{revrec},
|
---|
2170 | filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef),
|
---|
2171 | offset => $offset, sortby => $sortby, sortorder => $sortorder
|
---|
2172 | );
|
---|
2173 | # probably don't need this, keeping for reference for now
|
---|
2174 | # foreach (@$zonelist) {
|
---|
2175 | # }
|
---|
2176 | $page->param(domtable => $zonelist);
|
---|
2177 | } # end listdomains()
|
---|
2178 |
|
---|
2179 |
|
---|
2180 | sub listgroups {
|
---|
2181 |
|
---|
2182 | # security check - does the user have permission to view this entity?
|
---|
2183 | if (!(grep /^$curgroup$/, @viewablegroups)) {
|
---|
2184 | # hmm. Reset the current group to the login group? Yes. Prevents confusing behaviour elsewhere.
|
---|
2185 | $session->param('curgroup',$logingroup);
|
---|
2186 | $page->param(errmsg => "You are not permitted to view the requested group");
|
---|
2187 | $curgroup = $logingroup;
|
---|
2188 | }
|
---|
2189 |
|
---|
2190 | my @childgroups;
|
---|
2191 | $dnsdb->getChildren($curgroup, \@childgroups, 'all') if $searchsubs;
|
---|
2192 | my $childlist = join(',',@childgroups);
|
---|
2193 |
|
---|
2194 | my ($count) = $dnsdb->getGroupCount(childlist => $childlist, curgroup => $curgroup,
|
---|
2195 | filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) );
|
---|
2196 |
|
---|
2197 | # fill page count and first-previous-next-last-all bits
|
---|
2198 | fill_pgcount($count,"groups",'');
|
---|
2199 | fill_fpnla($count);
|
---|
2200 |
|
---|
2201 | $page->param(gid => $curgroup);
|
---|
2202 |
|
---|
2203 | $sortby = 'group';
|
---|
2204 | # sort/order
|
---|
2205 | $session->param($webvar{page}.'sortby', $webvar{sortby}) if $webvar{sortby};
|
---|
2206 | $session->param($webvar{page}.'order', $webvar{order}) if $webvar{order};
|
---|
2207 |
|
---|
2208 | $sortby = $session->param($webvar{page}.'sortby') if $session->param($webvar{page}.'sortby');
|
---|
2209 | $sortorder = $session->param($webvar{page}.'order') if $session->param($webvar{page}.'order');
|
---|
2210 |
|
---|
2211 | # set up the headers
|
---|
2212 | my @cols = ('group','parent','nusers','ndomains','nrevzones');
|
---|
2213 | my %colnames = (group => 'Group', parent => 'Parent Group', nusers => 'Users', ndomains => 'Domains', nrevzones => 'Reverse Zones');
|
---|
2214 | fill_colheads($sortby, $sortorder, \@cols, \%colnames);
|
---|
2215 |
|
---|
2216 | # waffle, waffle - keep state on these as well as sortby, sortorder?
|
---|
2217 | $page->param("start$startwith" => 1) if $startwith && $startwith =~ /^(?:[a-z]|0-9)$/;
|
---|
2218 |
|
---|
2219 | $page->param(filter => $filter) if $filter;
|
---|
2220 | $page->param(searchsubs => $searchsubs) if $searchsubs;
|
---|
2221 |
|
---|
2222 | # munge sortby for columns in database
|
---|
2223 | $sortby = 'g.group_name' if $sortby eq 'group';
|
---|
2224 | $sortby = 'g2.group_name' if $sortby eq 'parent';
|
---|
2225 |
|
---|
2226 | my $glist = $dnsdb->getGroupList(childlist => $childlist, curgroup => $curgroup,
|
---|
2227 | filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef),
|
---|
2228 | offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder);
|
---|
2229 |
|
---|
2230 | $page->param(grouptable => $glist);
|
---|
2231 | } # end listgroups()
|
---|
2232 |
|
---|
2233 |
|
---|
2234 | sub fill_grouplist {
|
---|
2235 | my $template_var = shift;
|
---|
2236 | my $cur = shift || $curgroup;
|
---|
2237 |
|
---|
2238 | # little recursive utility sub-sub
|
---|
2239 | sub getgroupdrop {
|
---|
2240 | my $root = shift;
|
---|
2241 | my $cur = shift; # to tag the selected group
|
---|
2242 | my $grplist = shift;
|
---|
2243 | my $indent = shift || ' ';
|
---|
2244 |
|
---|
2245 | my @childlist;
|
---|
2246 | $dnsdb->getChildren($root, \@childlist, 'immediate');
|
---|
2247 | return if $#childlist == -1;
|
---|
2248 | foreach (@childlist) {
|
---|
2249 | my %row;
|
---|
2250 | $row{groupval} = $_;
|
---|
2251 | $row{groupactive} = ($_ == $cur);
|
---|
2252 | $row{groupname} = $indent.$dnsdb->groupName($_);
|
---|
2253 | push @{$grplist}, \%row;
|
---|
2254 | getgroupdrop($_, $cur, $grplist, $indent.' ');
|
---|
2255 | }
|
---|
2256 | }
|
---|
2257 |
|
---|
2258 | my @grouplist;
|
---|
2259 | push @grouplist, { groupval => $logingroup, groupactive => $logingroup == $curgroup,
|
---|
2260 | groupname => $dnsdb->groupName($logingroup) };
|
---|
2261 | getgroupdrop($logingroup, $curgroup, \@grouplist);
|
---|
2262 |
|
---|
2263 | $page->param("$template_var" => \@grouplist);
|
---|
2264 | } # end fill_grouplist()
|
---|
2265 |
|
---|
2266 |
|
---|
2267 | sub fill_loclist {
|
---|
2268 | my $cur = shift || $curgroup;
|
---|
2269 | my $defloc = shift || '';
|
---|
2270 |
|
---|
2271 | return unless ($permissions{admin} || $permissions{location_view});
|
---|
2272 |
|
---|
2273 | $page->param(location_view => ($permissions{admin} || $permissions{location_view}));
|
---|
2274 |
|
---|
2275 | if ($permissions{admin} || $permissions{record_locchg}) {
|
---|
2276 | my $loclist = $dnsdb->getLocDropdown($cur, $defloc);
|
---|
2277 | $page->param(record_locchg => 1);
|
---|
2278 | $page->param(loclist => $loclist);
|
---|
2279 | } else {
|
---|
2280 | my $loc = $dnsdb->getLoc($defloc);
|
---|
2281 | $page->param(loc_name => $loc->{description});
|
---|
2282 | }
|
---|
2283 | } # end fill_loclist()
|
---|
2284 |
|
---|
2285 |
|
---|
2286 | sub list_users {
|
---|
2287 |
|
---|
2288 | my @childgroups;
|
---|
2289 | $dnsdb->getChildren($curgroup, \@childgroups, 'all') if $searchsubs;
|
---|
2290 | my $childlist = join(',',@childgroups);
|
---|
2291 |
|
---|
2292 | my $count = $dnsdb->getUserCount(childlist => $childlist, curgroup => $curgroup,
|
---|
2293 | filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) );
|
---|
2294 |
|
---|
2295 | # fill page count and first-previous-next-last-all bits
|
---|
2296 | fill_pgcount($count,"users",'');
|
---|
2297 | fill_fpnla($count);
|
---|
2298 |
|
---|
2299 | $sortby = 'user';
|
---|
2300 | # sort/order
|
---|
2301 | $session->param($webvar{page}.'sortby', $webvar{sortby}) if $webvar{sortby};
|
---|
2302 | $session->param($webvar{page}.'order', $webvar{order}) if $webvar{order};
|
---|
2303 |
|
---|
2304 | $sortby = $session->param($webvar{page}.'sortby') if $session->param($webvar{page}.'sortby');
|
---|
2305 | $sortorder = $session->param($webvar{page}.'order') if $session->param($webvar{page}.'order');
|
---|
2306 |
|
---|
2307 | # set up the headers
|
---|
2308 | my @cols = ('user','fname','type','group','status');
|
---|
2309 | my %colnames = (user => 'Username', fname => 'Full Name', type => 'Type', group => 'Group', status => 'Status');
|
---|
2310 | fill_colheads($sortby, $sortorder, \@cols, \%colnames);
|
---|
2311 |
|
---|
2312 | # waffle, waffle - keep state on these as well as sortby, sortorder?
|
---|
2313 | $page->param("start$startwith" => 1) if $startwith && $startwith =~ /^(?:[a-z]|0-9)$/;
|
---|
2314 |
|
---|
2315 | $page->param(filter => $filter) if $filter;
|
---|
2316 | $page->param(searchsubs => $searchsubs) if $searchsubs;
|
---|
2317 |
|
---|
2318 | my $ulist = $dnsdb->getUserList(childlist => $childlist, curgroup => $curgroup,
|
---|
2319 | filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef),
|
---|
2320 | offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder);
|
---|
2321 | # Some UI things need to be done to the list (unlike other lists)
|
---|
2322 | foreach my $u (@{$ulist}) {
|
---|
2323 | $u->{eduser} = ($permissions{admin} ||
|
---|
2324 | ($permissions{user_edit} && $u->{type} ne 'S') ||
|
---|
2325 | ($permissions{self_edit} && $u->{user_id} == $session->param('uid')) );
|
---|
2326 | $u->{deluser} = ($permissions{admin} || ($permissions{user_delete} && $u->{type} ne 'S'));
|
---|
2327 | $u->{type} = ($u->{type} eq 'S' ? 'superuser' : 'user');
|
---|
2328 | }
|
---|
2329 | $page->param(usertable => $ulist);
|
---|
2330 | } # end list_users()
|
---|
2331 |
|
---|
2332 |
|
---|
2333 | sub list_locations {
|
---|
2334 |
|
---|
2335 | my @childgroups;
|
---|
2336 | $dnsdb->getChildren($curgroup, \@childgroups, 'all') if $searchsubs;
|
---|
2337 | my $childlist = join(',',@childgroups);
|
---|
2338 |
|
---|
2339 | my $count = $dnsdb->getLocCount(childlist => $childlist, curgroup => $curgroup,
|
---|
2340 | filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) );
|
---|
2341 |
|
---|
2342 | # fill page count and first-previous-next-last-all bits
|
---|
2343 | fill_pgcount($count,"locations/views",'');
|
---|
2344 | fill_fpnla($count);
|
---|
2345 |
|
---|
2346 | $sortby = 'user';
|
---|
2347 | # sort/order
|
---|
2348 | $session->param($webvar{page}.'sortby', $webvar{sortby}) if $webvar{sortby};
|
---|
2349 | $session->param($webvar{page}.'order', $webvar{order}) if $webvar{order};
|
---|
2350 |
|
---|
2351 | $sortby = $session->param($webvar{page}.'sortby') if $session->param($webvar{page}.'sortby');
|
---|
2352 | $sortorder = $session->param($webvar{page}.'order') if $session->param($webvar{page}.'order');
|
---|
2353 |
|
---|
2354 | # set up the headers
|
---|
2355 | my @cols = ('description', 'iplist', 'group');
|
---|
2356 | my %colnames = (description => 'Location/View Name', iplist => 'Permitted IPs/Ranges', group => 'Group');
|
---|
2357 | fill_colheads($sortby, $sortorder, \@cols, \%colnames);
|
---|
2358 |
|
---|
2359 | # waffle, waffle - keep state on these as well as sortby, sortorder?
|
---|
2360 | $page->param("start$startwith" => 1) if $startwith && $startwith =~ /^(?:[a-z]|0-9)$/;
|
---|
2361 |
|
---|
2362 | $page->param(filter => $filter) if $filter;
|
---|
2363 | $page->param(searchsubs => $searchsubs) if $searchsubs;
|
---|
2364 |
|
---|
2365 | my $loclist = $dnsdb->getLocList(childlist => $childlist, curgroup => $curgroup,
|
---|
2366 | filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef),
|
---|
2367 | offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder);
|
---|
2368 | # Some UI things need to be done to the list
|
---|
2369 | foreach my $l (@{$loclist}) {
|
---|
2370 | $l->{iplist} = "(All IPs)" if !$l->{iplist};
|
---|
2371 | $l->{edloc} = ($permissions{admin} || $permissions{loc_edit});
|
---|
2372 | $l->{delloc} = ($permissions{admin} || $permissions{loc_delete});
|
---|
2373 | }
|
---|
2374 | $page->param(loctable => $loclist);
|
---|
2375 | } # end list_locations()
|
---|
2376 |
|
---|
2377 |
|
---|
2378 | # Generate all of the glop necessary to add or not the appropriate marker/flag for
|
---|
2379 | # the sort order and column in domain, user, group, and record lists
|
---|
2380 | # Takes an array ref and hash ref
|
---|
2381 | sub fill_colheads {
|
---|
2382 | my $sortby = shift;
|
---|
2383 | my $sortorder = shift;
|
---|
2384 | my $cols = shift;
|
---|
2385 | my $colnames = shift;
|
---|
2386 | my $custom = shift;
|
---|
2387 |
|
---|
2388 | my @headings;
|
---|
2389 |
|
---|
2390 | foreach my $col (@$cols) {
|
---|
2391 | my %coldata;
|
---|
2392 | $coldata{page} = $webvar{page};
|
---|
2393 | $coldata{offset} = $webvar{offset} if $webvar{offset};
|
---|
2394 | $coldata{sortby} = $col;
|
---|
2395 | $coldata{colname} = $colnames->{$col};
|
---|
2396 | if ($col eq $sortby) {
|
---|
2397 | $coldata{order} = ($sortorder eq 'ASC' ? 'DESC' : 'ASC');
|
---|
2398 | $coldata{sortorder} = $sortorder;
|
---|
2399 | } else {
|
---|
2400 | $coldata{order} = 'ASC';
|
---|
2401 | }
|
---|
2402 | if ($custom) {
|
---|
2403 | foreach my $ckey (keys %$custom) {
|
---|
2404 | $coldata{$ckey} = $custom->{$ckey};
|
---|
2405 | }
|
---|
2406 | }
|
---|
2407 | push @headings, \%coldata;
|
---|
2408 | }
|
---|
2409 |
|
---|
2410 | $page->param(colheads => \@headings);
|
---|
2411 |
|
---|
2412 | } # end fill_colheads()
|
---|
2413 |
|
---|
2414 |
|
---|
2415 | # we have to do this in a variety of places; let's make it consistent
|
---|
2416 | sub fill_permissions {
|
---|
2417 | my $template = shift; # may need to do several sets on a single page
|
---|
2418 | my $permset = shift; # hashref to permissions on object
|
---|
2419 | my $usercan = shift || \%permissions; # allow alternate user-is-allowed permission block
|
---|
2420 |
|
---|
2421 | foreach (@permtypes) {
|
---|
2422 | $template->param("may_$_" => ($usercan->{admin} || $usercan->{$_}));
|
---|
2423 | $template->param($_ => $permset->{$_});
|
---|
2424 | }
|
---|
2425 | }
|
---|
2426 |
|
---|
2427 | # so simple when defined as a sub instead of inline. O_o
|
---|
2428 | sub check_scope {
|
---|
2429 | my %args = @_;
|
---|
2430 | my $entity = $args{id} || 0; # prevent the shooting of feet with SQL "... intcolumn = '' ..."
|
---|
2431 | my $entype = $args{type} || '';
|
---|
2432 |
|
---|
2433 | if ($entype eq 'group') {
|
---|
2434 | return 1 if grep /^$entity$/, @viewablegroups;
|
---|
2435 | } else {
|
---|
2436 | foreach (@viewablegroups) {
|
---|
2437 | return 1 if $dnsdb->isParent($_, 'group', $entity, $entype);
|
---|
2438 | }
|
---|
2439 | }
|
---|
2440 | }
|
---|