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