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