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