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