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