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