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