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