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