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