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