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