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