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