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