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