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