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