[2] | 1 | #!/usr/bin/perl -w -T
|
---|
| 2 | # dns/cgi-bin/dns.cgi
|
---|
| 3 | ###
|
---|
| 4 | # SVN revision info
|
---|
| 5 | # $Date: 2011-02-16 20:01:28 +0000 (Wed, 16 Feb 2011) $
|
---|
| 6 | # SVN revision $Rev: 70 $
|
---|
| 7 | # Last update by $Author: kdeugau $
|
---|
| 8 | ###
|
---|
[3] | 9 | # Copyright (C) 2008,2009 - 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;
|
---|
[30] | 19 | use Net::DNS;
|
---|
[2] | 20 | use DBI;
|
---|
| 21 |
|
---|
| 22 | use lib '.';
|
---|
| 23 | # custom modules
|
---|
| 24 | use DNSDB qw(:ALL);
|
---|
| 25 |
|
---|
[13] | 26 | my @debugbits; # temp, to be spit out near the end of processing
|
---|
[61] | 27 | my $debugenv = 1;
|
---|
[13] | 28 |
|
---|
[2] | 29 | # Let's do these templates right...
|
---|
| 30 | my $templatedir = "templates";
|
---|
| 31 | my $sessiondir = "session";
|
---|
| 32 |
|
---|
| 33 | # Set up the CGI object...
|
---|
| 34 | my $q = new CGI::Simple;
|
---|
| 35 | # ... and get query-string params as well as POST params if necessary
|
---|
| 36 | $q->parse_query_string;
|
---|
| 37 |
|
---|
| 38 | # This is probably excessive fiddling, but it puts the parameters somewhere my fingers know about...
|
---|
[7] | 39 | my %webvar = $q->Vars;
|
---|
[2] | 40 |
|
---|
[13] | 41 | # persistent stuff needed on most/all pages
|
---|
[2] | 42 | my $sid = ($webvar{sid} ? $webvar{sid} : undef);
|
---|
[68] | 43 | my $session = new CGI::Session("driver:File", $sid, {Directory => $sessiondir})
|
---|
| 44 | or die CGI::Session->errstr();
|
---|
[2] | 45 | #$sid = $session->id() if !$sid;
|
---|
| 46 | if (!$sid) {
|
---|
| 47 | # init stuff. can probably axe this down to just above if'n'when user manipulation happens
|
---|
| 48 | $sid = $session->id();
|
---|
| 49 | # need to know the "upper" group the user can deal with; may as well
|
---|
| 50 | # stick this in the session rather than calling out to the DB every time.
|
---|
[18] | 51 | $session->param('logingroup',1);
|
---|
| 52 | $session->param('curgroup',1); # yes, we *do* need to track this too. er, probably.
|
---|
[51] | 53 | $session->param('domlistsortby','domain');
|
---|
| 54 | $session->param('domlistorder','ASC');
|
---|
[54] | 55 | $session->param('useradminsortby','user');
|
---|
[51] | 56 | $session->param('useradminorder','ASC');
|
---|
| 57 | $session->param('grpmansortby','group');
|
---|
| 58 | $session->param('grpmanorder','ASC');
|
---|
| 59 | $session->param('reclistsortby','name');
|
---|
| 60 | $session->param('reclistorder','ASC');
|
---|
[53] | 61 | # $session->param('filter','login');
|
---|
| 62 | # $session->param('startwith','login');
|
---|
| 63 | # $session->param('searchsubs','login');
|
---|
[2] | 64 | }
|
---|
| 65 |
|
---|
[19] | 66 | my $logingroup = ($session->param('logingroup') ? $session->param('logingroup') : 1);
|
---|
| 67 | my $curgroup = ($session->param('curgroup') ? $session->param('curgroup') : $logingroup);
|
---|
[17] | 68 | my $group = ($webvar{group} ? $webvar{group} : 1);
|
---|
[18] | 69 |
|
---|
[54] | 70 | # per-page startwith, filter, searchsubs
|
---|
[64] | 71 | $session->param($webvar{page}.'startwith', $webvar{startwith}) if defined($webvar{startwith});
|
---|
[62] | 72 | $session->param($webvar{page}.'filter', $webvar{filter}) if defined($webvar{filter});
|
---|
[54] | 73 | $webvar{searchsubs} =~ s/^n ?// if $webvar{searchsubs};
|
---|
[57] | 74 | $session->param($webvar{page}.'searchsubs', $webvar{searchsubs}) if defined($webvar{searchsubs});
|
---|
[54] | 75 |
|
---|
[68] | 76 | # decide which page to spit out...
|
---|
| 77 | # also set $webvar{page} before we try to use it.
|
---|
| 78 | $webvar{page} = 'login' if !$webvar{page};
|
---|
| 79 |
|
---|
[54] | 80 | my $startwith = $session->param($webvar{page}.'startwith');
|
---|
| 81 | my $filter = $session->param($webvar{page}.'filter');
|
---|
| 82 | my $searchsubs = $session->param($webvar{page}.'searchsubs');
|
---|
| 83 |
|
---|
[26] | 84 | # nrgh, can't handle login here because we don't have a database handle to check the user/pass with yet
|
---|
[2] | 85 |
|
---|
| 86 | my $header = HTML::Template->new(filename => "$templatedir/header.tmpl");
|
---|
| 87 | my $footer = HTML::Template->new(filename => "$templatedir/footer.tmpl");
|
---|
| 88 |
|
---|
| 89 | # default
|
---|
[38] | 90 | #my $perpage = 15;
|
---|
| 91 | my $perpage = 3;
|
---|
[2] | 92 | my $offset = ($webvar{offset} ? $webvar{offset} : 0);
|
---|
| 93 |
|
---|
| 94 | # NB: these must match the field name and SQL ascend/descend syntax respectively
|
---|
[41] | 95 | my $sortby = "domain";
|
---|
| 96 | my $sortorder = "ASC";
|
---|
[2] | 97 |
|
---|
[68] | 98 | my ($dbh,$msg) = connectDB("dnsdb","dnsdb","secret","newdbhost");
|
---|
[2] | 99 | #my $dbh = DBI->connect("DBI:mysql:database=vegadns","vegadns","secret",
|
---|
| 100 | # { AutoCommit => 0 }) or die $DBI::errstr;
|
---|
| 101 |
|
---|
| 102 | ##fixme. PLEASE! <G>
|
---|
| 103 | print $msg if !$dbh;
|
---|
| 104 |
|
---|
| 105 | # fiddle hardcoded "defaults" as per system/user (?) prefs
|
---|
| 106 | initGlobals($dbh);
|
---|
| 107 |
|
---|
[26] | 108 | # handle login redirect
|
---|
[30] | 109 | if ($webvar{action}) {
|
---|
| 110 | if ($webvar{action} eq 'login') {
|
---|
[65] | 111 | # Snag ACL/permissions here too
|
---|
[30] | 112 | my $sth = $dbh->prepare("SELECT user_id,group_id,password,firstname,lastname FROM users WHERE username=?");
|
---|
| 113 | $sth->execute($webvar{username});
|
---|
| 114 | my ($uid,$gid,$pass,$fname,$lname) = $sth->fetchrow_array;
|
---|
| 115 | $webvar{loginfailed} = 1 if !defined($uid);
|
---|
[26] | 116 |
|
---|
[30] | 117 | if ($pass =~ m|^\$1\$([A-Za-z0-9/.]+)\$|) {
|
---|
| 118 | $webvar{loginfailed} = 1 if $pass ne unix_md5_crypt($webvar{password},$1);
|
---|
| 119 | } else {
|
---|
| 120 | $webvar{loginfailed} = 1 if $pass ne $webvar{password};
|
---|
| 121 | }
|
---|
[29] | 122 |
|
---|
[30] | 123 | # set session bits
|
---|
| 124 | $session->param('logingroup',$gid);
|
---|
| 125 | $session->param('curgroup',$gid);
|
---|
[65] | 126 | $session->param('uid',$uid);
|
---|
[30] | 127 | $session->param('username',$webvar{username});
|
---|
[26] | 128 |
|
---|
[30] | 129 | changepage(page => "domlist") if !defined($webvar{loginfailed});
|
---|
| 130 | } elsif ($webvar{action} eq 'logout') {
|
---|
| 131 | # delete the session
|
---|
| 132 | $session->delete();
|
---|
| 133 | $session->flush();
|
---|
| 134 |
|
---|
| 135 | my $newurl = "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}";
|
---|
| 136 | $newurl =~ s|/[^/]+$|/|;
|
---|
| 137 | print "Status: 302\nLocation: $newurl\n\n";
|
---|
| 138 | exit;
|
---|
| 139 |
|
---|
[57] | 140 | } elsif ($webvar{action} eq 'chgroup') {
|
---|
| 141 | # fiddle session-stored group data
|
---|
| 142 | # magic incantation to... uhhh...
|
---|
| 143 | $session->param('curgroup', $webvar{group});
|
---|
| 144 | $curgroup = ($webvar{group} ? $webvar{group} : $session->param('curgroup'));
|
---|
[30] | 145 | }
|
---|
[57] | 146 | } # handle global webvar{action}s
|
---|
[26] | 147 |
|
---|
[65] | 148 | initPermissions($dbh,$session->param('uid'));
|
---|
[57] | 149 |
|
---|
[15] | 150 | ## Default page is a login page
|
---|
| 151 | #my $page; # to be initialized as an HTML::Template entity sooner or later
|
---|
[2] | 152 |
|
---|
[3] | 153 |
|
---|
[15] | 154 | #if (!$webvar{page}) {
|
---|
| 155 | # $page = HTML::Template->new(filename => "$templatedir/login.tmpl");
|
---|
| 156 | #} else {
|
---|
| 157 | #}
|
---|
[2] | 158 |
|
---|
[15] | 159 | my $page = HTML::Template->new(filename => "$templatedir/$webvar{page}.tmpl");
|
---|
| 160 |
|
---|
[2] | 161 | $page->param(sid => $sid);
|
---|
| 162 |
|
---|
[26] | 163 | if ($webvar{page} eq 'login') {
|
---|
[3] | 164 |
|
---|
[26] | 165 | $page->param(loginfailed => 1) if $webvar{loginfailed};
|
---|
| 166 | ##fixme: set up session init to actually *check* for session timeout
|
---|
| 167 | $page->param(timeout => 1) if $webvar{sesstimeout};
|
---|
| 168 |
|
---|
| 169 | } elsif ($webvar{page} eq 'domlist' or $webvar{page} eq 'index') {
|
---|
| 170 |
|
---|
[3] | 171 | # hmm. seeing problems in some possibly-not-so-corner cases.
|
---|
[10] | 172 | # this currently only handles "domain on", "domain off"
|
---|
[3] | 173 | if (defined($webvar{action})) {
|
---|
[62] | 174 | my $stat = domStatus($dbh,$webvar{id},$webvar{action});
|
---|
| 175 | logaction($webvar{id}, $session->param("username"), parentID($webvar{id}, 'dom', 'group'),
|
---|
| 176 | "Changed ".domainName($dbh, $webvar{id})." state to ".($stat ? 'active' : 'inactive'));
|
---|
[3] | 177 | }
|
---|
| 178 |
|
---|
[18] | 179 | $page->param(curpage => $webvar{page});
|
---|
[62] | 180 | if ($webvar{del_failed}) {
|
---|
| 181 | $page->param(del_failed => 1);
|
---|
| 182 | $page->param(errmsg => $webvar{errmsg});
|
---|
| 183 | }
|
---|
[18] | 184 |
|
---|
[11] | 185 | listdomains();
|
---|
[2] | 186 |
|
---|
[4] | 187 | } elsif ($webvar{page} eq 'newdomain') {
|
---|
[2] | 188 |
|
---|
[57] | 189 | # hmm. nothing to do here?
|
---|
| 190 | # - group list is filled by the same bit that fills the group list in the menu
|
---|
[62] | 191 | if ($webvar{add_failed}) {
|
---|
| 192 | $page->param(add_failed => 1);
|
---|
| 193 | $page->param(errmsg => $webvar{errmsg});
|
---|
| 194 | $page->param(domain => $webvar{domain});
|
---|
| 195 | }
|
---|
[2] | 196 |
|
---|
[57] | 197 | } elsif ($webvar{page} eq 'adddomain') {
|
---|
| 198 |
|
---|
| 199 | my ($code,$msg) = addDomain($dbh,$webvar{domain},$webvar{group},($webvar{makeactive} eq 'on' ? 1 : 0));
|
---|
| 200 |
|
---|
| 201 | if ($code eq 'OK') {
|
---|
| 202 | logaction($msg, $session->param("username"), $webvar{group}, "Added domain $webvar{domain}");
|
---|
| 203 | changepage(page => "reclist", id => $msg);
|
---|
| 204 | } else {
|
---|
[62] | 205 | logaction(0, $session->param("username"), $webvar{group}, "Failed adding domain $webvar{domain} ($msg)");
|
---|
[57] | 206 | changepage(page => "newdomain", add_failed => 1, domain => $webvar{domain}, errmsg => $msg);
|
---|
| 207 | }
|
---|
| 208 |
|
---|
[11] | 209 | } elsif ($webvar{page} eq 'deldom') {
|
---|
| 210 |
|
---|
| 211 | $page->param(id => $webvar{id});
|
---|
| 212 | # first pass = confirm y/n (sorta)
|
---|
| 213 | if (!defined($webvar{del})) {
|
---|
| 214 | $page->param(del_getconf => 1);
|
---|
| 215 | $page->param(domain => domainName($dbh,$webvar{id}));
|
---|
| 216 | # print some neato things?
|
---|
| 217 |
|
---|
| 218 | # } else {
|
---|
| 219 | # #whether actually deleting or cancelling we redirect to the domain list, default format
|
---|
| 220 |
|
---|
| 221 | } elsif ($webvar{del} eq 'ok') {
|
---|
[57] | 222 | my $pargroup = parentID($webvar{id}, 'dom', 'group');
|
---|
[61] | 223 | my $dom = domainName($dbh, $webvar{id});
|
---|
[11] | 224 | my ($code,$msg) = delDomain($dbh, $webvar{id});
|
---|
| 225 | if ($code ne 'OK') {
|
---|
| 226 | # need to find failure mode
|
---|
[62] | 227 | logaction($webvar{id}, $session->param("username"), $pargroup, "Failed to delete domain $dom ($msg)");
|
---|
| 228 | changepage(page => "domlist", del_failed => 1, errmsg => $msg);
|
---|
[11] | 229 | } else {
|
---|
[61] | 230 | logaction($webvar{id}, $session->param("username"), $pargroup, "Deleted domain $dom");
|
---|
| 231 | changepage(page => "domlist");
|
---|
[11] | 232 | }
|
---|
| 233 | } else {
|
---|
| 234 | # cancelled. whee!
|
---|
| 235 | changepage(page => "domlist");
|
---|
| 236 | }
|
---|
| 237 |
|
---|
[47] | 238 | } elsif ($webvar{page} eq 'reclist') {
|
---|
| 239 |
|
---|
| 240 | # Handle record list for both default records (per-group) and live domain records
|
---|
| 241 |
|
---|
| 242 | $page->param(defrec => $webvar{defrec});
|
---|
| 243 | $page->param(id => $webvar{id});
|
---|
| 244 | $page->param(curpage => $webvar{page});
|
---|
| 245 |
|
---|
| 246 | # select count(*) from (default_)?records where (group|domain)_id=?
|
---|
| 247 | my $sth = $dbh->prepare("SELECT count(*) FROM ".
|
---|
| 248 | ($webvar{defrec} eq 'y' ? 'default_' : '')."records ".
|
---|
| 249 | "WHERE ".($webvar{defrec} eq 'y' ? 'group' : 'domain')."_id=? ".
|
---|
| 250 | "AND NOT type=$reverse_typemap{SOA}");
|
---|
| 251 | $sth->execute($webvar{id});
|
---|
| 252 | my ($count) = ($sth->fetchrow_array);
|
---|
| 253 |
|
---|
| 254 | # fill the page-count and first-previous-next-last-all details
|
---|
| 255 | fill_pgcount($count,"records",domainName($dbh,$webvar{id}));
|
---|
| 256 | fill_fpnla($count); # should put some params on this sub...
|
---|
| 257 |
|
---|
| 258 | $page->param(defrec => $webvar{defrec});
|
---|
| 259 | if ($webvar{defrec} eq 'y') {
|
---|
| 260 | ##fixme: hardcoded group
|
---|
| 261 | showdomain('y',$curgroup);
|
---|
| 262 | } else {
|
---|
| 263 | showdomain('n',$webvar{id});
|
---|
[60] | 264 | $page->param(logdom => 1);
|
---|
[47] | 265 | }
|
---|
| 266 |
|
---|
[63] | 267 | if ($webvar{del_failed}) {
|
---|
| 268 | $page->param(del_failed => 1);
|
---|
| 269 | $page->param(errmsg => $webvar{errmsg});
|
---|
| 270 | }
|
---|
| 271 |
|
---|
[13] | 272 | } elsif ($webvar{page} eq 'record') {
|
---|
[16] | 273 |
|
---|
[13] | 274 | if ($webvar{recact} eq 'new') {
|
---|
[16] | 275 |
|
---|
[15] | 276 | $page->param(todo => "Add record to");
|
---|
| 277 | $page->param(recact => "add");
|
---|
[59] | 278 | $page->param(parentid => $webvar{parentid});
|
---|
| 279 | $page->param(defrec => $webvar{defrec});
|
---|
[16] | 280 |
|
---|
[59] | 281 | fill_recdata();
|
---|
| 282 |
|
---|
[15] | 283 | } elsif ($webvar{recact} eq 'add') {
|
---|
| 284 |
|
---|
| 285 | my @recargs = ($dbh,$webvar{defrec},$webvar{parentid},$webvar{name},$webvar{type},$webvar{address},$webvar{ttl});
|
---|
| 286 | if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}) {
|
---|
| 287 | push @recargs, $webvar{distance};
|
---|
| 288 | if ($webvar{type} == $reverse_typemap{SRV}) {
|
---|
| 289 | push @recargs, $webvar{weight};
|
---|
| 290 | push @recargs, $webvar{port};
|
---|
| 291 | }
|
---|
| 292 | }
|
---|
[59] | 293 |
|
---|
[15] | 294 | my ($code,$msg) = addRec(@recargs);
|
---|
| 295 |
|
---|
| 296 | if ($code eq 'OK') {
|
---|
[57] | 297 | if ($webvar{defrec} eq 'y') {
|
---|
| 298 | logaction(0, $session->param("username"), $webvar{parentid},
|
---|
[63] | 299 | "Added default record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl}");
|
---|
[57] | 300 | } else {
|
---|
| 301 | logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'),
|
---|
[63] | 302 | "Added record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl}");
|
---|
[57] | 303 | }
|
---|
[15] | 304 | changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
|
---|
| 305 | } else {
|
---|
[24] | 306 | $page->param(failed => 1);
|
---|
| 307 | $page->param(errmsg => $msg);
|
---|
| 308 | $page->param(wastrying => "adding");
|
---|
| 309 | $page->param(todo => "Add record to");
|
---|
| 310 | $page->param(recact => "add");
|
---|
| 311 | $page->param(parentid => $webvar{parentid});
|
---|
| 312 | $page->param(defrec => $webvar{defrec});
|
---|
| 313 | $page->param(id => $webvar{id});
|
---|
[16] | 314 | fill_recdata(); # populate the form... er, mostly.
|
---|
[59] | 315 | if ($webvar{defrec} eq 'y') {
|
---|
| 316 | logaction(0, $session->param("username"), $webvar{parentid},
|
---|
[63] | 317 | "Failed adding default record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl} ($msg)");
|
---|
[59] | 318 | } else {
|
---|
| 319 | logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'),
|
---|
[63] | 320 | "Failed adding record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl} ($msg)");
|
---|
[59] | 321 | }
|
---|
[15] | 322 | }
|
---|
| 323 |
|
---|
[13] | 324 | } elsif ($webvar{recact} eq 'edit') {
|
---|
[15] | 325 |
|
---|
[16] | 326 | $page->param(todo => "Update record");
|
---|
| 327 | $page->param(recact => "update");
|
---|
| 328 | $page->param(parentid => $webvar{parentid});
|
---|
[17] | 329 | $page->param(id => $webvar{id});
|
---|
[16] | 330 | $page->param(defrec => $webvar{defrec});
|
---|
[57] | 331 | ##fixme: SQL does not belong!
|
---|
[13] | 332 | my $sth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM ".
|
---|
| 333 | ($webvar{defrec} eq 'y' ? 'default_' : '')."records WHERE record_id=?");
|
---|
| 334 | $sth->execute($webvar{id});
|
---|
| 335 | my ($host,$type,$val,$distance,$weight,$port,$ttl) = $sth->fetchrow_array;
|
---|
| 336 | $page->param(name => $host);
|
---|
| 337 | $page->param(address => $val);
|
---|
| 338 | $page->param(distance => $distance);
|
---|
| 339 | $page->param(weight => $weight);
|
---|
| 340 | $page->param(port => $port);
|
---|
| 341 | $page->param(ttl => $ttl);
|
---|
[16] | 342 | fill_rectypes($type);
|
---|
| 343 |
|
---|
| 344 | } elsif ($webvar{recact} eq 'update') {
|
---|
| 345 |
|
---|
| 346 | my ($code,$msg) = updateRec($dbh,$webvar{defrec},$webvar{id},
|
---|
| 347 | $webvar{name},$webvar{type},$webvar{address},$webvar{ttl},
|
---|
| 348 | $webvar{distance},$webvar{weight},$webvar{port});
|
---|
| 349 |
|
---|
| 350 | if ($code eq 'OK') {
|
---|
[55] | 351 | ##fixme: need more magic to get proper group - if domain was fiddled
|
---|
| 352 | # from search-subgroups listing, may not be "current" group
|
---|
[57] | 353 |
|
---|
| 354 | # SELECT d.group_id FROM domains d INNER JOIN records r ON d.domain_id=r.domain_id WHERE r.record_id=?
|
---|
| 355 | # $sth->execute($webvar{id});
|
---|
| 356 | ##log
|
---|
| 357 | if ($webvar{defrec} eq 'y') {
|
---|
| 358 | logaction(0, $session->param("username"), $webvar{parentid},
|
---|
| 359 | "Updated default record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl}");
|
---|
| 360 | } else {
|
---|
| 361 | logaction($webvar{parentid}, $session->param("username"), parentID($webvar{id}, 'rec', 'group'),
|
---|
| 362 | "Updated record '$webvar{name} $typemap{$webvar{type}} $webvar{address}', TTL $webvar{ttl}");
|
---|
| 363 | }
|
---|
[17] | 364 | changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
|
---|
[16] | 365 | } else {
|
---|
| 366 | $page->param(failed => 1);
|
---|
| 367 | $page->param(errmsg => $msg);
|
---|
| 368 | $page->param(wastrying => "updating");
|
---|
| 369 | $page->param(todo => "Update record");
|
---|
| 370 | $page->param(recact => "update");
|
---|
| 371 | $page->param(parentid => $webvar{parentid});
|
---|
| 372 | $page->param(defrec => $webvar{defrec});
|
---|
[17] | 373 | $page->param(id => $webvar{id});
|
---|
[16] | 374 | fill_recdata();
|
---|
[59] | 375 | if ($webvar{defrec} eq 'y') {
|
---|
| 376 | logaction(0, $session->param("username"), $webvar{parentid},
|
---|
[63] | 377 | "Failed updating default record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl} ($msg)");
|
---|
[59] | 378 | } else {
|
---|
| 379 | logaction($webvar{parentid}, $session->param("username"), parentID($webvar{parentid}, 'dom', 'group'),
|
---|
[63] | 380 | "Failed updating record '$typemap{$webvar{type}} $webvar{name} $webvar{address}', TTL $webvar{ttl} ($msg)");
|
---|
[59] | 381 | }
|
---|
[16] | 382 | }
|
---|
[13] | 383 | }
|
---|
[16] | 384 |
|
---|
[13] | 385 | if ($webvar{defrec} eq 'y') {
|
---|
[20] | 386 | $page->param(dohere => "default records in group ".groupName($dbh,$webvar{parentid}));
|
---|
[13] | 387 | } else {
|
---|
[24] | 388 | $page->param(parentid => $webvar{parentid});
|
---|
| 389 | # $page->param(id => $webvar{id});
|
---|
[16] | 390 | $page->param(dohere => domainName($dbh,$webvar{parentid}));
|
---|
[13] | 391 | }
|
---|
| 392 |
|
---|
[2] | 393 | } elsif ($webvar{page} eq 'delrec') {
|
---|
| 394 |
|
---|
| 395 | $page->param(id => $webvar{id});
|
---|
| 396 | $page->param(defrec => $webvar{defrec});
|
---|
[39] | 397 | $page->param(parentid => $webvar{parentid});
|
---|
[2] | 398 | # first pass = confirm y/n (sorta)
|
---|
| 399 | if (!defined($webvar{del})) {
|
---|
| 400 | $page->param(del_getconf => 1);
|
---|
[3] | 401 | my %rec = getRecLine($dbh,$webvar{defrec},$webvar{id});
|
---|
| 402 | $page->param(host => $rec{host});
|
---|
| 403 | $page->param(ftype => $typemap{$rec{type}});
|
---|
| 404 | $page->param(recval => $rec{val});
|
---|
[39] | 405 | } elsif ($webvar{del} eq 'ok') {
|
---|
[62] | 406 | # get rec data before we try to delete it
|
---|
| 407 | my %rec = getRecLine($dbh,$webvar{defrec},$webvar{id});
|
---|
[3] | 408 | my ($code,$msg) = delRec($dbh,$webvar{defrec},$webvar{id});
|
---|
| 409 | if ($code ne 'OK') {
|
---|
| 410 | ## need to find failure mode
|
---|
[62] | 411 | if ($webvar{defrec} eq 'y') {
|
---|
| 412 | logaction(0, $session->param("username"), $rec{parid},
|
---|
[63] | 413 | "Failed deleting default record '$rec{host} $typemap{$rec{type}} $rec{val}', TTL $rec{ttl} ($msg)");
|
---|
[62] | 414 | } else {
|
---|
| 415 | logaction($rec{parid}, $session->param("username"), parentID($rec{parid}, 'dom', 'group'),
|
---|
[63] | 416 | "Failed deleting record '$rec{host} $typemap{$rec{type}} $rec{val}', TTL $rec{ttl} ($msg)");
|
---|
[62] | 417 | }
|
---|
[63] | 418 | changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec}, del_failed => 1, errmsg => $msg);
|
---|
[3] | 419 | $page->param(del_failed => 1);
|
---|
| 420 | $page->param(errmsg => $msg);
|
---|
[39] | 421 | showdomain($webvar{defrec}, $webvar{parentid});
|
---|
| 422 | } else {
|
---|
[62] | 423 | if ($webvar{defrec} eq 'y') {
|
---|
| 424 | logaction(0, $session->param("username"), $rec{parid},
|
---|
| 425 | "Deleted default record '$rec{host} $typemap{$rec{type}} $rec{val}', TTL $rec{ttl}");
|
---|
| 426 | } else {
|
---|
| 427 | logaction($rec{parid}, $session->param("username"), parentID($rec{parid}, 'dom', 'group'),
|
---|
| 428 | "Deleted record '$rec{host} $typemap{$rec{type}} $rec{val}', TTL $rec{ttl}");
|
---|
| 429 | }
|
---|
[39] | 430 | changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
|
---|
[3] | 431 | }
|
---|
[39] | 432 | } else {
|
---|
| 433 | changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
|
---|
[2] | 434 | }
|
---|
| 435 |
|
---|
| 436 | } elsif ($webvar{page} eq 'editsoa') {
|
---|
| 437 |
|
---|
[39] | 438 | fillsoa($webvar{defrec},$webvar{id});
|
---|
[2] | 439 |
|
---|
| 440 | } elsif ($webvar{page} eq 'updatesoa') {
|
---|
| 441 |
|
---|
| 442 | my $sth;
|
---|
| 443 | my $sql = '';
|
---|
| 444 | # no domain ID, so we're editing the default SOA for a group (we don't care which one here)
|
---|
| 445 | # plus a bit of magic to update the appropriate table
|
---|
[39] | 446 | $sql = "update ".($webvar{defrec} eq 'y' ? "default_records" : "records").
|
---|
[2] | 447 | " set host='$webvar{prins}:$webvar{contact}',".
|
---|
| 448 | " val='$webvar{refresh}:$webvar{retry}:$webvar{expire}:$webvar{minttl}',".
|
---|
| 449 | " ttl=$webvar{ttl} where record_id=$webvar{recid}";
|
---|
| 450 | $sth = $dbh->prepare($sql);
|
---|
| 451 | $sth->execute;
|
---|
| 452 |
|
---|
| 453 | if ($sth->err) {
|
---|
| 454 | $page->param(update_failed => 1);
|
---|
| 455 | $page->param(msg => $DBI::errstr);
|
---|
[39] | 456 | fillsoa($webvar{defrec},$webvar{id});
|
---|
[2] | 457 | } else {
|
---|
[57] | 458 |
|
---|
| 459 | ##fixme! need to set group ID properly here
|
---|
| 460 | # SELECT group_id FROM domains WHERE domain_id=?
|
---|
| 461 | # $sth->execute($webvar{id});
|
---|
| 462 | ##log
|
---|
[55] | 463 | logaction(0, $session->param("username"), $webvar{group},
|
---|
| 464 | "Updated SOA (ns $webvar{prins}, contact $webvar{contact}, refresh $webvar{refresh},".
|
---|
| 465 | " retry $webvar{retry}, expire $webvar{expire}, minTTL $webvar{minttl}, TTL $webvar{ttl}");
|
---|
[39] | 466 | changepage(page => "reclist", id => $webvar{id}, defrec => $webvar{defrec});
|
---|
[57] | 467 | # $page->param(update_failed => 0);
|
---|
[39] | 468 | # showdomain('y',1);
|
---|
[2] | 469 | }
|
---|
| 470 |
|
---|
[17] | 471 | } elsif ($webvar{page} eq 'grpman') {
|
---|
[2] | 472 |
|
---|
[22] | 473 | listgroups();
|
---|
[18] | 474 | $page->param(curpage => $webvar{page});
|
---|
| 475 |
|
---|
[17] | 476 | } elsif ($webvar{page} eq 'newgrp') {
|
---|
[20] | 477 |
|
---|
[18] | 478 | # do.. uhh.. stuff.. if we have no webvar{action}
|
---|
| 479 | if ($webvar{action} && $webvar{action} eq 'add') {
|
---|
| 480 | # not gonna provide the 4th param: template-or-clone flag, just yet
|
---|
[66] | 481 | my %newperms;
|
---|
| 482 | foreach (@permtypes) {
|
---|
| 483 | $newperms{$_} = 0;
|
---|
| 484 | $newperms{$_} = 1 if $webvar{$_} eq 'on';
|
---|
| 485 | }
|
---|
| 486 | my ($code,$msg) = addGroup($dbh, $webvar{newgroup}, $webvar{pargroup}, \%newperms);
|
---|
[57] | 487 | if ($code eq 'OK') {
|
---|
[55] | 488 | logaction(0, $session->param("username"), $webvar{pargroup}, "Added group $webvar{newgroup}");
|
---|
| 489 | changepage(page => "grpman");
|
---|
| 490 | }
|
---|
[66] | 491 | # no point in doing extra work
|
---|
| 492 | fill_permissions($page, \%newperms);
|
---|
[18] | 493 | $page->param(add_failed => 1);
|
---|
| 494 | $page->param(errmsg => $msg);
|
---|
| 495 | $page->param(newgroup => $webvar{newgroup});
|
---|
[66] | 496 | fill_grouplist('pargroup',$webvar{pargroup});
|
---|
[19] | 497 | } else {
|
---|
| 498 | # $page->param
|
---|
[66] | 499 | fill_grouplist('pargroup',$curgroup);
|
---|
| 500 | # fill default permissions with immediate parent's current ones
|
---|
| 501 | my %parperms;
|
---|
| 502 | getPermissions($dbh, 'group', $curgroup, \%parperms);
|
---|
| 503 | fill_permissions($page, \%parperms);
|
---|
[18] | 504 | }
|
---|
[20] | 505 |
|
---|
[22] | 506 | } elsif ($webvar{page} eq 'delgrp') {
|
---|
[20] | 507 |
|
---|
| 508 | $page->param(id => $webvar{id});
|
---|
| 509 | # first pass = confirm y/n (sorta)
|
---|
| 510 | if (!defined($webvar{del})) {
|
---|
| 511 | $page->param(del_getconf => 1);
|
---|
[23] | 512 | # $page->param(groupname => groupName($dbh,$webvar{id}));
|
---|
[20] | 513 | # print some neato things?
|
---|
| 514 |
|
---|
| 515 | # } else {
|
---|
| 516 | # #whether actually deleting or cancelling we redirect to the group list, default format
|
---|
| 517 |
|
---|
| 518 | } elsif ($webvar{del} eq 'ok') {
|
---|
[57] | 519 | my $deleteme = groupName($dbh,$webvar{id}); # get this before we delete it...
|
---|
[20] | 520 | my ($code,$msg) = delGroup($dbh, $webvar{id});
|
---|
| 521 | if ($code ne 'OK') {
|
---|
| 522 | # need to find failure mode
|
---|
| 523 | $page->param(del_failed => 1);
|
---|
| 524 | $page->param(errmsg => $msg);
|
---|
[22] | 525 | $page->param(curpage => $webvar{page});
|
---|
| 526 | listgroups();
|
---|
[20] | 527 | } else {
|
---|
[57] | 528 | ##fixme: need to clean up log when deleting a major container
|
---|
| 529 | logaction(0, $session->param("username"), $webvar{curgroup}, "Deleted group $deleteme");
|
---|
[20] | 530 | # success. go back to the domain list, do not pass "GO"
|
---|
| 531 | changepage(page => "grpman");
|
---|
| 532 | }
|
---|
| 533 | } else {
|
---|
| 534 | # cancelled. whee!
|
---|
| 535 | changepage(page => "grpman");
|
---|
| 536 | }
|
---|
[23] | 537 | $page->param(delgroupname => groupName($dbh, $webvar{id}));
|
---|
[24] | 538 |
|
---|
[65] | 539 | } elsif ($webvar{page} eq 'edgroup') {
|
---|
| 540 |
|
---|
| 541 | if ($webvar{action} eq 'updperms') {
|
---|
| 542 | # extra safety check; make sure user can't construct a URL to bypass ACLs
|
---|
| 543 | my %curperms;
|
---|
| 544 | getPermissions($dbh, 'group', $webvar{gid}, \%curperms);
|
---|
[66] | 545 | my %chperms;
|
---|
| 546 | foreach (@permtypes) {
|
---|
[65] | 547 | $webvar{$_} = 0 if !defined($webvar{$_});
|
---|
| 548 | $webvar{$_} = 1 if $webvar{$_} eq 'on';
|
---|
[66] | 549 | $chperms{$_} = $webvar{$_} if $curperms{$_} ne $webvar{$_};
|
---|
[65] | 550 | }
|
---|
[66] | 551 | my ($code,$msg) = changePermissions($dbh, 'group', $webvar{gid}, \%chperms);
|
---|
| 552 | if ($code eq 'OK') {
|
---|
| 553 | logaction(0, $session->param("username"), $webvar{gid}, "Changed default permissions in group $webvar{gid}");
|
---|
| 554 | changepage(page => "grpman");
|
---|
| 555 | }
|
---|
| 556 | # no point in doing extra work
|
---|
| 557 | fill_permissions($page, \%chperms);
|
---|
| 558 | $page->param(errmsg => $msg);
|
---|
[65] | 559 | }
|
---|
| 560 | $page->param(gid => $webvar{gid});
|
---|
| 561 | $page->param(grpmeddle => groupName($dbh, $webvar{gid}));
|
---|
| 562 | my %grpperms;
|
---|
| 563 | getPermissions($dbh, 'group', $webvar{gid}, \%grpperms);
|
---|
[66] | 564 | fill_permissions($page, \%grpperms);
|
---|
[65] | 565 |
|
---|
[24] | 566 | } elsif ($webvar{page} eq 'useradmin') {
|
---|
| 567 |
|
---|
[51] | 568 | if (defined($webvar{action})) {
|
---|
| 569 | userStatus($dbh,$webvar{id},$webvar{action});
|
---|
| 570 | }
|
---|
| 571 |
|
---|
[24] | 572 | $page->param(curpage => $webvar{page});
|
---|
| 573 |
|
---|
[51] | 574 | list_users();
|
---|
| 575 |
|
---|
[67] | 576 | } elsif ($webvar{page} eq 'user') {
|
---|
| 577 |
|
---|
| 578 | fill_actypelist();
|
---|
| 579 | fill_clonemelist();
|
---|
| 580 | my %grpperms;
|
---|
| 581 | getPermissions($dbh, 'group', $curgroup, \%grpperms);
|
---|
| 582 | fill_permissions($page, \%grpperms);
|
---|
| 583 | my $grppermlist = new HTML::Template(filename => "$templatedir/permlist.tmpl");
|
---|
| 584 | my %noaccess;
|
---|
| 585 | fill_permissions($grppermlist, \%grpperms, \%noaccess);
|
---|
| 586 | $grppermlist->param(info => 1);
|
---|
| 587 | $page->param(grpperms => $grppermlist->output);
|
---|
| 588 | $page->param(is_admin => $permissions{admin});
|
---|
| 589 |
|
---|
| 590 | # if ($webvar{action} eq 'new') {
|
---|
| 591 | # } els
|
---|
| 592 | if ($webvar{action} eq 'add') {
|
---|
| 593 |
|
---|
| 594 | my ($code,$msg);
|
---|
| 595 |
|
---|
| 596 | my $alterperms = 0; # flag iff we need to force custom permissions due to user's current access limits
|
---|
| 597 |
|
---|
| 598 | if ($webvar{pass1} ne $webvar{pass2}) {
|
---|
| 599 | $code = 'FAIL';
|
---|
| 600 | $msg = "Passwords don't match";
|
---|
| 601 | } else {
|
---|
| 602 | # assemble a permission string - far simpler than trying to pass an
|
---|
| 603 | # indeterminate set of permission flags individually
|
---|
| 604 |
|
---|
| 605 | # ooooh.
|
---|
| 606 | # OOOOH.
|
---|
| 607 | # We have to see if the user can add any particular permissions; otherwise we have a priviledge escalation. Whee.
|
---|
| 608 |
|
---|
| 609 | if (!$permissions{admin}) {
|
---|
| 610 | my %grpperms;
|
---|
| 611 | getPermissions($dbh, 'group', $curgroup, \%grpperms);
|
---|
| 612 | my $ret = comparePermissions(\%permissions, \%grpperms);
|
---|
| 613 | if ($ret ne '<' && $ret ne '!') {
|
---|
| 614 | # User's permissions are not a superset or equivalent to group. Can't inherit
|
---|
| 615 | # (and include access user doesn't currently have), so we force custom.
|
---|
| 616 | $webvar{perms_type} = 'custom';
|
---|
| 617 | $alterperms = 1;
|
---|
| 618 | }
|
---|
| 619 | }
|
---|
| 620 | ##work
|
---|
| 621 | my $permstring;
|
---|
| 622 | if ($webvar{perms_type} eq 'custom') {
|
---|
| 623 | $permstring = 'C:';
|
---|
| 624 | foreach (@permtypes) {
|
---|
| 625 | if ($permissions{admin}) {
|
---|
| 626 | $permstring .= ",$_" if defined($webvar{$_}) && $webvar{$_} eq 'on';
|
---|
| 627 | } else {
|
---|
| 628 | $permstring .= ",$_" if $permissions{$_} && defined($webvar{$_}) && $webvar{$_} eq 'on';
|
---|
| 629 | }
|
---|
| 630 | }
|
---|
| 631 | $page->param(perm_custom => 1);
|
---|
| 632 | } elsif ($permissions{admin} && $webvar{perms_type} eq 'clone') {
|
---|
| 633 | $permstring = "c:$webvar{clonesrc}";
|
---|
| 634 | $page->param(perm_clone => 1);
|
---|
| 635 | } else {
|
---|
| 636 | $permstring = 'i';
|
---|
| 637 | }
|
---|
| 638 | ($code,$msg) = addUser($dbh,$webvar{uname}, $curgroup, $webvar{pass1},
|
---|
| 639 | ($webvar{makeactive} eq 'on' ? 1 : 0), $webvar{accttype}, $permstring,
|
---|
| 640 | $webvar{fname}, $webvar{lname}, $webvar{phone});
|
---|
| 641 | }
|
---|
| 642 |
|
---|
| 643 | # hokay, a bit of magic to decide which page we hit.
|
---|
| 644 | if ($code eq 'OK') {
|
---|
| 645 | ##log
|
---|
| 646 | logaction(0, $session->param("username"), $webvar{group},
|
---|
| 647 | "Added user $webvar{uname} ($webvar{fname} $webvar{lname})");
|
---|
| 648 | if ($alterperms) {
|
---|
| 649 | changepage(page => "useradmin", warnmsg =>
|
---|
| 650 | "You can only grant permissions you hold. $webvar{uname} added with reduced access.");
|
---|
| 651 | } else {
|
---|
| 652 | changepage(page => "useradmin");
|
---|
| 653 | }
|
---|
| 654 | } else {
|
---|
| 655 | # oddity - apparently, xhtml 1.0 strict swallows username as an HTML::Template var. O_o
|
---|
| 656 | $page->param(add_failed => 1);
|
---|
| 657 | $page->param(uname => $webvar{uname});
|
---|
| 658 | $page->param(fname => $webvar{fname});
|
---|
| 659 | $page->param(lname => $webvar{lname});
|
---|
| 660 | $page->param(pass1 => $webvar{pass1});
|
---|
| 661 | $page->param(pass2 => $webvar{pass2});
|
---|
| 662 | $page->param(errmsg => $msg);
|
---|
| 663 | fill_actypelist();
|
---|
| 664 | fill_clonemelist();
|
---|
| 665 | }
|
---|
| 666 |
|
---|
| 667 | } elsif ($webvar{action} eq 'edit') {
|
---|
| 668 | } elsif ($webvar{action} eq 'update') {
|
---|
| 669 | } else {
|
---|
| 670 | # default is "new"
|
---|
| 671 | }
|
---|
| 672 |
|
---|
[24] | 673 | } elsif ($webvar{page} eq 'newuser') {
|
---|
| 674 |
|
---|
| 675 | # foo?
|
---|
| 676 | fill_actypelist();
|
---|
[65] | 677 | fill_clonemelist();
|
---|
[24] | 678 |
|
---|
[67] | 679 | my %grpperms;
|
---|
| 680 | getPermissions($dbh, 'group', $curgroup, \%grpperms);
|
---|
| 681 | fill_permissions($page, \%grpperms);
|
---|
| 682 |
|
---|
| 683 | my $grppermlist = new HTML::Template(filename => "$templatedir/permlist.tmpl");
|
---|
| 684 | my %noaccess;
|
---|
| 685 | fill_permissions($grppermlist, \%grpperms, \%noaccess);
|
---|
| 686 | $grppermlist->param(info => 1);
|
---|
| 687 | $page->param(grpperms => $grppermlist->output);
|
---|
| 688 |
|
---|
[24] | 689 | } elsif ($webvar{page} eq 'adduser') {
|
---|
| 690 |
|
---|
| 691 | my ($code,$msg);
|
---|
| 692 |
|
---|
| 693 | if ($webvar{pass1} ne $webvar{pass2}) {
|
---|
| 694 | $code = 'FAIL';
|
---|
| 695 | $msg = "Passwords don't match";
|
---|
| 696 | } else {
|
---|
[65] | 697 | # assemble a permission string - far simpler than trying to pass an
|
---|
| 698 | # indeterminate set of permission flags individually
|
---|
| 699 | my $permstring;
|
---|
| 700 | if ($webvar{perms_type} eq 'custom') {
|
---|
| 701 | $permstring = 'C:,g:,u:,d:,r:';
|
---|
| 702 | $page->param(perm_custom => 1);
|
---|
| 703 | } elsif ($webvar{perms_type} eq 'clone') {
|
---|
| 704 | $permstring = 'c:';
|
---|
| 705 | $page->param(perm_clone => 1);
|
---|
| 706 | } else {
|
---|
| 707 | $permstring = 'i';
|
---|
| 708 | # $page->param(perm_inherit => 1);
|
---|
| 709 | }
|
---|
[38] | 710 | ($code,$msg) = addUser($dbh,$webvar{uname}, $webvar{group}, $webvar{pass1},
|
---|
[25] | 711 | ($webvar{makeactive} eq 'on' ? 1 : 0), $webvar{accttype},
|
---|
| 712 | $webvar{fname}, $webvar{lname}, $webvar{phone});
|
---|
[24] | 713 | }
|
---|
| 714 |
|
---|
| 715 | # hokay, a bit of magic to decide which page we hit.
|
---|
| 716 | if ($code eq 'OK') {
|
---|
[57] | 717 | ##log
|
---|
[55] | 718 | logaction(0, $session->param("username"), $webvar{group},
|
---|
| 719 | "Added user $webvar{uname} ($webvar{fname} $webvar{lname})");
|
---|
[24] | 720 | changepage(page => "useradmin");
|
---|
| 721 | } else {
|
---|
[38] | 722 | # oddity - apparently, xhtml 1.0 strict swallows username as an HTML::Template var. O_o
|
---|
[24] | 723 | $page->param(add_failed => 1);
|
---|
[38] | 724 | $page->param(uname => $webvar{uname});
|
---|
[24] | 725 | $page->param(fname => $webvar{fname});
|
---|
| 726 | $page->param(lname => $webvar{lname});
|
---|
| 727 | $page->param(pass1 => $webvar{pass1});
|
---|
| 728 | $page->param(pass2 => $webvar{pass2});
|
---|
| 729 | $page->param(errmsg => $msg);
|
---|
| 730 | fill_actypelist();
|
---|
[65] | 731 | fill_clonemelist();
|
---|
[24] | 732 | }
|
---|
| 733 |
|
---|
[38] | 734 | # $page->param(add_failed => 1);
|
---|
[25] | 735 |
|
---|
| 736 | } elsif ($webvar{page} eq 'deluser') {
|
---|
| 737 |
|
---|
| 738 | $page->param(id => $webvar{id});
|
---|
| 739 | # first pass = confirm y/n (sorta)
|
---|
| 740 | if (!defined($webvar{del})) {
|
---|
| 741 | $page->param(del_getconf => 1);
|
---|
| 742 | $page->param(user => userFullName($dbh,$webvar{id}));
|
---|
| 743 | } elsif ($webvar{del} eq 'ok') {
|
---|
[57] | 744 | ##fixme: find group id user is in (for logging) *before* we delete the user
|
---|
[25] | 745 | my ($code,$msg) = delUser($dbh, $webvar{id});
|
---|
| 746 | if ($code ne 'OK') {
|
---|
| 747 | # need to find failure mode
|
---|
| 748 | $page->param(del_failed => 1);
|
---|
| 749 | $page->param(errmsg => $msg);
|
---|
| 750 | list_users($curgroup);
|
---|
| 751 | } else {
|
---|
[65] | 752 | # success. go back to the user list, do not pass "GO"
|
---|
[57] | 753 | ##log
|
---|
| 754 | logaction(0, $session->param("username"), $webvar{group}, "Added domain $webvar{domain}");
|
---|
[25] | 755 | changepage(page => "useradmin");
|
---|
| 756 | }
|
---|
| 757 | } else {
|
---|
| 758 | # cancelled. whee!
|
---|
| 759 | changepage(page => "useradmin");
|
---|
| 760 | }
|
---|
| 761 |
|
---|
[65] | 762 | } elsif ($webvar{page} eq 'edituser') {
|
---|
| 763 |
|
---|
[30] | 764 | } elsif ($webvar{page} eq 'dnsq') {
|
---|
| 765 |
|
---|
| 766 | $page->param(qfor => $webvar{qfor}) if $webvar{qfor};
|
---|
[31] | 767 | fill_rectypes($webvar{type} ? $webvar{type} : '', 1);
|
---|
| 768 | $page->param(nrecurse => $webvar{nrecurse}) if $webvar{nrecurse};
|
---|
[30] | 769 | $page->param(resolver => $webvar{resolver}) if $webvar{resolver};
|
---|
| 770 |
|
---|
| 771 | if ($webvar{qfor}) {
|
---|
| 772 | my $resolv = Net::DNS::Resolver->new;
|
---|
[31] | 773 | $resolv->tcp_timeout(5); # make me adjustable!
|
---|
| 774 | $resolv->udp_timeout(5); # make me adjustable!
|
---|
| 775 | $resolv->recurse(0) if $webvar{nrecurse};
|
---|
| 776 | $resolv->nameservers($webvar{resolver}) if $webvar{resolver};
|
---|
[30] | 777 | my $query = $resolv->query($webvar{qfor}, $typemap{$webvar{type}});
|
---|
| 778 | if ($query) {
|
---|
| 779 |
|
---|
| 780 | $page->param(showresults => 1);
|
---|
| 781 |
|
---|
| 782 | my @answer;
|
---|
| 783 | foreach my $rr ($query->answer) {
|
---|
| 784 | # next unless $rr->type eq "A" or $rr->type eq 'NS';
|
---|
| 785 | my %row;
|
---|
| 786 | my ($host,$ttl,$class,$type,$data) =
|
---|
[31] | 787 | ($rr->string =~ /^([0-9a-zA-Z_.-]+)\s+(\d+)\s+([A-Za-z]+)\s+([A-Za-z]+)\s+(.+)$/s);
|
---|
[30] | 788 | $row{host} = $host;
|
---|
| 789 | $row{ftype} = $type;
|
---|
[31] | 790 | $row{rdata} = ($type eq 'SOA' ? "<pre>$data</pre>" : $data);
|
---|
[30] | 791 | push @answer, \%row;
|
---|
| 792 | }
|
---|
| 793 | $page->param(answer => \@answer);
|
---|
| 794 |
|
---|
| 795 | my @additional;
|
---|
| 796 | foreach my $rr ($query->additional) {
|
---|
| 797 | # next unless $rr->type eq "A" or $rr->type eq 'NS';
|
---|
| 798 | my %row;
|
---|
| 799 | my ($host,$ttl,$class,$type,$data) =
|
---|
| 800 | ($rr->string =~ /^([0-9a-zA-Z_.-]+)\s+(\d+)\s+([A-Za-z]+)\s+([A-Za-z]+)\s+(.+)$/);
|
---|
| 801 | $row{host} = $host;
|
---|
| 802 | $row{ftype} = $type;
|
---|
| 803 | $row{rdata} = $data;
|
---|
| 804 | push @additional, \%row;
|
---|
| 805 | }
|
---|
| 806 | $page->param(additional => \@additional);
|
---|
| 807 |
|
---|
| 808 | my @authority;
|
---|
| 809 | foreach my $rr ($query->authority) {
|
---|
| 810 | # next unless $rr->type eq "A" or $rr->type eq 'NS';
|
---|
| 811 | my %row;
|
---|
| 812 | my ($host,$ttl,$class,$type,$data) =
|
---|
| 813 | ($rr->string =~ /^([0-9a-zA-Z_.-]+)\s+(\d+)\s+([A-Za-z]+)\s+([A-Za-z]+)\s+(.+)$/);
|
---|
| 814 | $row{host} = $host;
|
---|
| 815 | $row{ftype} = $type;
|
---|
| 816 | $row{rdata} = $data;
|
---|
| 817 | push @authority, \%row;
|
---|
| 818 | }
|
---|
| 819 | $page->param(authority => \@authority);
|
---|
| 820 |
|
---|
| 821 | $page->param(usedresolver => $resolv->answerfrom);
|
---|
| 822 | $page->param(frtype => $typemap{$webvar{type}});
|
---|
| 823 |
|
---|
| 824 | } else {
|
---|
| 825 | $page->param(errmsg => $resolv->errorstring);
|
---|
| 826 | }
|
---|
| 827 | }
|
---|
| 828 | ## done DNS query
|
---|
| 829 |
|
---|
[31] | 830 | } elsif ($webvar{page} eq 'axfr') {
|
---|
| 831 |
|
---|
| 832 | # don't need this while we've got the dropdown in the menu. hmm.
|
---|
| 833 | #fill_grouplist;
|
---|
| 834 |
|
---|
| 835 | $page->param(ifrom => $webvar{ifrom}) if $webvar{ifrom};
|
---|
| 836 | $page->param(rwsoa => $webvar{rwsoa}) if $webvar{rwsoa};
|
---|
| 837 | $page->param(rwns => $webvar{rwns}) if $webvar{rwns};
|
---|
[37] | 838 | $page->param(dominactive => 1) if (!$webvar{domactive} && $webvar{doit}); # eww.
|
---|
[31] | 839 | $page->param(importdoms => $webvar{importdoms}) if $webvar{importdoms};
|
---|
[33] | 840 |
|
---|
| 841 | ##fixme: check group too?
|
---|
| 842 | if ($webvar{doit} eq 'y' && !$webvar{ifrom}) {
|
---|
| 843 | $page->param(errmsg => "Need to set host to import from");
|
---|
| 844 | } elsif ($webvar{doit} eq 'y' && !$webvar{importdoms}) {
|
---|
| 845 | $page->param(errmsg => "Need domains to import");
|
---|
| 846 | } else {
|
---|
| 847 | my @domlist = split /\s+/, $webvar{importdoms};
|
---|
| 848 | my @results;
|
---|
| 849 | my $rnum = 0;
|
---|
| 850 | foreach my $domain (@domlist) {
|
---|
[34] | 851 | my %row;
|
---|
| 852 | my ($code,$msg) = importAXFR($dbh, $webvar{ifrom}, $domain, $webvar{group},
|
---|
| 853 | $webvar{domstatus}, $webvar{rwsoa}, $webvar{rwns});
|
---|
[35] | 854 | $row{domok} = $msg if $code eq 'OK';
|
---|
| 855 | if ($code eq 'WARN') {
|
---|
| 856 | $msg =~ s|\n|<br />|g;
|
---|
| 857 | $row{domwarn} = $msg;
|
---|
| 858 | }
|
---|
[37] | 859 | if ($code eq 'FAIL') {
|
---|
| 860 | $msg =~ s|\n|<br />|g;
|
---|
| 861 | $row{domerr} = $msg;
|
---|
| 862 | }
|
---|
[33] | 863 | # do stuff! DNSDB::importAXFR($webvar{ifrom}, $webvar{rwsoa}, $webvar{rwns}, $domain, <flags>)
|
---|
| 864 | $row{domain} = $domain;
|
---|
| 865 | # $row{row} = $rnum++;
|
---|
| 866 | push @results, \%row;
|
---|
| 867 | }
|
---|
| 868 | $page->param(axfrresults => \@results);
|
---|
| 869 | }
|
---|
| 870 |
|
---|
[48] | 871 | } elsif ($webvar{page} eq 'whoisq') {
|
---|
[47] | 872 |
|
---|
[48] | 873 | if ($webvar{qfor}) {
|
---|
| 874 | use Net::Whois::Raw;
|
---|
| 875 | use Text::Wrap;
|
---|
| 876 |
|
---|
| 877 | # caching useful?
|
---|
| 878 | #$Net::Whois::Raw::CACHE_DIR = "/var/spool/pwhois/";
|
---|
| 879 | #$Net::Whois::Raw::CACHE_TIME = 60;
|
---|
| 880 |
|
---|
| 881 | my ($dominfo, $whois_server) = whois($webvar{qfor});
|
---|
| 882 | ##fixme: if we're given an IP, try rwhois as well as whois so we get the real final data
|
---|
| 883 |
|
---|
| 884 | # le sigh. idjits spit out data without linefeeds...
|
---|
| 885 | $Text::Wrap::columns = 88;
|
---|
| 886 |
|
---|
| 887 | # &%$@%@# high-bit crap. We should probably find a way to properly recode these instead of one-by-one.
|
---|
| 888 | # Mainly an XHTML validation thing.
|
---|
| 889 | $dominfo =~ s/\xa9/\©/g;
|
---|
| 890 | $dominfo =~ s/\xae/\®/g;
|
---|
| 891 |
|
---|
| 892 | $page->param(qfor => $webvar{qfor});
|
---|
| 893 | $page->param(dominfo => wrap('','',$dominfo));
|
---|
| 894 | $page->param(whois_server => $whois_server);
|
---|
| 895 | } else {
|
---|
| 896 | $page->param(errmsg => "Missing host or domain to query in WHOIS") if $webvar{askaway};
|
---|
| 897 | }
|
---|
| 898 |
|
---|
[47] | 899 | } elsif ($webvar{page} eq 'log') {
|
---|
| 900 |
|
---|
| 901 | ##fixme put in some real log-munching stuff
|
---|
| 902 | ##fixme need to add bits to *create* log entries...
|
---|
[59] | 903 | my $sql = "SELECT user_id, email, name, entry, date_trunc('second',stamp) FROM log WHERE ";
|
---|
[60] | 904 | my $id = $curgroup; # we do this because the group log may be called from (almost) any page,
|
---|
| 905 | # but the others are much more limited. this is probably non-optimal.
|
---|
[61] | 906 | if ($webvar{ltype} && $webvar{ltype} eq 'user') {
|
---|
[60] | 907 | $sql .= "user_id=?";
|
---|
| 908 | $id = $webvar{id};
|
---|
| 909 | $page->param(logfor => 'user '.userFullName($dbh,$id));
|
---|
| 910 | } elsif ($webvar{ltype} && $webvar{ltype} eq 'dom') {
|
---|
[59] | 911 | $sql .= "domain_id=?";
|
---|
| 912 | $id = $webvar{id};
|
---|
[60] | 913 | $page->param(logfor => 'domain '.domainName($dbh,$id));
|
---|
[59] | 914 | } else {
|
---|
| 915 | # Default to listing curgroup log
|
---|
| 916 | $sql .= "group_id=?";
|
---|
[60] | 917 | $page->param(logfor => 'group '.groupName($dbh,$id));
|
---|
[59] | 918 | }
|
---|
| 919 | my $sth = $dbh->prepare($sql);
|
---|
| 920 | $sth->execute($id);
|
---|
[47] | 921 | my @logbits;
|
---|
[59] | 922 | while (my ($uid, $email, $name, $entry, $stamp) = $sth->fetchrow_array) {
|
---|
[47] | 923 | my %row;
|
---|
[59] | 924 | $row{userfname} = $name;
|
---|
| 925 | $row{userid} = $uid;
|
---|
| 926 | $row{useremail} = $email;
|
---|
| 927 | $row{logentry} = $entry;
|
---|
| 928 | ($row{logtime}) = ($stamp =~ /^(.+)-\d\d$/);
|
---|
[47] | 929 | push @logbits, \%row;
|
---|
| 930 | }
|
---|
| 931 | $page->param(logentries => \@logbits);
|
---|
| 932 |
|
---|
[60] | 933 | } # end $webvar{page} dance
|
---|
[2] | 934 |
|
---|
| 935 |
|
---|
[17] | 936 | # start output here so we can redirect pages.
|
---|
[7] | 937 | print "Content-type: text/html\n\n", $header->output;
|
---|
| 938 |
|
---|
[20] | 939 | ##common bits
|
---|
[17] | 940 | if ($webvar{page} ne 'login') {
|
---|
[30] | 941 | $page->param(username => $session->param("username"));
|
---|
| 942 |
|
---|
[20] | 943 | $page->param(group => $curgroup);
|
---|
| 944 | $page->param(groupname => groupName($dbh,$curgroup));
|
---|
[43] | 945 | $page->param(logingrp => groupName($dbh,$logingroup));
|
---|
[20] | 946 |
|
---|
[24] | 947 | # group tree. should go elsewhere, probably
|
---|
| 948 | my $tmpgrplist = fill_grptree($logingroup,$curgroup);
|
---|
| 949 | $page->param(grptree => $tmpgrplist);
|
---|
[65] | 950 | $page->param(subs => ($tmpgrplist ? 1 : 0)); # probably not useful to pass gobs of data in for a boolean
|
---|
[42] | 951 | $page->param(inlogingrp => $curgroup == $logingroup);
|
---|
| 952 |
|
---|
[20] | 953 | # stuff for menu group change. nb: this is icky.
|
---|
| 954 | fill_grouplist("grouplist");
|
---|
[53] | 955 |
|
---|
| 956 | ## set up "URL to self"
|
---|
[38] | 957 | # @#$%@%@#% XHTML - & in a URL must be escaped. >:(
|
---|
| 958 | my $tmp_ruri = $ENV{REQUEST_URI};
|
---|
| 959 | $tmp_ruri =~ s/\&([a-z])/\&\;$1/g;
|
---|
[53] | 960 |
|
---|
[39] | 961 | # le sigh. and we need to strip any previous action
|
---|
| 962 | $tmp_ruri =~ s/\&action=[^&]+//g;
|
---|
[52] | 963 |
|
---|
[53] | 964 | # and search filter options. these get stored in the session, but discarded
|
---|
| 965 | # as soon as you switch to a different page.
|
---|
| 966 | ##fixme: think about retaining these on a per-page basis, as well as offset; same as the sort-order bits
|
---|
| 967 | no warnings qw(uninitialized);
|
---|
| 968 | $tmp_ruri =~ s/\&startwith=[a-z09-]*(\&)?/$1/g;
|
---|
| 969 | $tmp_ruri =~ s/\&searchsubs=[a-z09-]*(\&)?/$1/g;
|
---|
| 970 | $tmp_ruri =~ s/\&filter=[a-z09-]*(\&)?/$1/g;
|
---|
| 971 | use warnings qw(uninitialized);
|
---|
[52] | 972 |
|
---|
[53] | 973 | # fill in the URL-to-self
|
---|
[38] | 974 | $page->param(whereami => $tmp_ruri);
|
---|
[17] | 975 | }
|
---|
[13] | 976 |
|
---|
[24] | 977 | foreach (@debugbits) { print; }
|
---|
| 978 |
|
---|
[2] | 979 | # spit it out
|
---|
| 980 | print $page->output;
|
---|
| 981 |
|
---|
[38] | 982 | if ($debugenv) {
|
---|
| 983 | print "<div id=\"debug\">webvar keys: <pre>\n";
|
---|
| 984 | foreach my $key (keys %webvar) {
|
---|
| 985 | print "key: $key\tval: $webvar{$key}\n";
|
---|
| 986 | }
|
---|
| 987 | print "</pre>\nsession:\n<pre>\n";
|
---|
| 988 | my $sesdata = $session->dataref();
|
---|
| 989 | foreach my $key (keys %$sesdata) {
|
---|
| 990 | print "key: $key\tval: ".$sesdata->{$key}."\n";
|
---|
| 991 | }
|
---|
| 992 | print "</pre>\nENV:\n<pre>\n";
|
---|
| 993 | foreach my $key (keys %ENV) {
|
---|
| 994 | print "key: $key\tval: $ENV{$key}\n";
|
---|
| 995 | }
|
---|
| 996 | print "</pre></div>\n";
|
---|
[2] | 997 | }
|
---|
| 998 |
|
---|
| 999 | print $footer->output;
|
---|
| 1000 |
|
---|
[18] | 1001 | # as per the docs, Just In Case
|
---|
| 1002 | $session->flush();
|
---|
[2] | 1003 |
|
---|
| 1004 | exit 0;
|
---|
| 1005 |
|
---|
| 1006 |
|
---|
[24] | 1007 | sub fill_grptree {
|
---|
| 1008 | my $root = shift;
|
---|
| 1009 | my $cur = shift;
|
---|
[69] | 1010 | my $indent = shift || ' ';
|
---|
[24] | 1011 |
|
---|
| 1012 | my @childlist;
|
---|
| 1013 |
|
---|
| 1014 | my $grptree = HTML::Template->new(filename => 'templates/grptree.tmpl');
|
---|
| 1015 | getChildren($dbh,$root,\@childlist,'immediate');
|
---|
| 1016 | return if $#childlist == -1;
|
---|
| 1017 | my @grouplist;
|
---|
| 1018 | foreach (@childlist) {
|
---|
| 1019 | my %row;
|
---|
| 1020 | $row{grpname} = groupName($dbh,$_);
|
---|
[69] | 1021 | # for all that HTML::Template is supposed to keep the HTML out of the Perl, this is so much more compact...
|
---|
| 1022 | $row{grpdisp} = ($_ == $cur ? "<b>$row{grpname}</b>" : $row{grpname});
|
---|
| 1023 | $row{subs} = fill_grptree($_,$cur,$indent.' ');
|
---|
| 1024 | $row{indent} = $indent;
|
---|
[24] | 1025 | push @grouplist, \%row;
|
---|
| 1026 | }
|
---|
[69] | 1027 | $grptree->param(indent => $indent);
|
---|
[24] | 1028 | $grptree->param(treelvl => \@grouplist);
|
---|
| 1029 | return $grptree->output;
|
---|
| 1030 | }
|
---|
| 1031 |
|
---|
[11] | 1032 | sub changepage {
|
---|
| 1033 | my %params = @_; # think this works the way I want...
|
---|
| 1034 |
|
---|
| 1035 | # handle user check
|
---|
| 1036 | my $newurl = "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}?sid=$sid";
|
---|
| 1037 | foreach (keys %params) {
|
---|
| 1038 | $newurl .= "&$_=$params{$_}";
|
---|
| 1039 | }
|
---|
| 1040 |
|
---|
[30] | 1041 | # Just In Case
|
---|
| 1042 | $session->flush();
|
---|
| 1043 |
|
---|
[11] | 1044 | print "Status: 302\nLocation: $newurl\n\n";
|
---|
| 1045 | exit;
|
---|
| 1046 | } # end changepage
|
---|
| 1047 |
|
---|
[2] | 1048 | sub fillsoa {
|
---|
| 1049 | my $def = shift;
|
---|
| 1050 | my $id = shift;
|
---|
[39] | 1051 | my $domname = ($def eq 'y' ? '' : "DOMAIN");
|
---|
[2] | 1052 |
|
---|
[39] | 1053 | $page->param(defrec => $def);
|
---|
[2] | 1054 |
|
---|
[39] | 1055 | # i had a good reason to do this when I wrote it...
|
---|
| 1056 | # $page->param(domain => $domname);
|
---|
| 1057 | # $page->param(group => $DNSDB::group);
|
---|
| 1058 | $page->param(isgrp => 1) if $def eq 'y';
|
---|
| 1059 | $page->param(parent => ($def eq 'y' ? groupName($dbh, $DNSDB::group) : domainName($dbh, $id)) );
|
---|
[2] | 1060 |
|
---|
| 1061 | # defaults
|
---|
[17] | 1062 | $page->param(defcontact => $DNSDB::def{contact});
|
---|
| 1063 | $page->param(defns => $DNSDB::def{prins});
|
---|
| 1064 | $page->param(defsoattl => $DNSDB::def{soattl});
|
---|
| 1065 | $page->param(defrefresh => $DNSDB::def{refresh});
|
---|
| 1066 | $page->param(defretry => $DNSDB::def{retry});
|
---|
| 1067 | $page->param(defexpire => $DNSDB::def{expire});
|
---|
| 1068 | $page->param(defminttl => $DNSDB::def{minttl});
|
---|
[2] | 1069 |
|
---|
| 1070 | # there are probably better ways to do this. TMTOWTDI.
|
---|
| 1071 | my %soa = getSOA($dbh,$def,$id);
|
---|
| 1072 |
|
---|
[39] | 1073 | $page->param(id => $id);
|
---|
[2] | 1074 | $page->param(recid => $soa{recid});
|
---|
| 1075 | $page->param(prins => ($soa{prins} ? $soa{prins} : $DNSDB::def{prins}));
|
---|
| 1076 | $page->param(contact => ($soa{contact} ? $soa{contact} : $DNSDB::def{contact}));
|
---|
| 1077 | $page->param(refresh => ($soa{refresh} ? $soa{refresh} : $DNSDB::def{refresh}));
|
---|
| 1078 | $page->param(retry => ($soa{retry} ? $soa{retry} : $DNSDB::def{retry}));
|
---|
| 1079 | $page->param(expire => ($soa{expire} ? $soa{expire} : $DNSDB::def{expire}));
|
---|
| 1080 | $page->param(minttl => ($soa{minttl} ? $soa{minttl} : $DNSDB::def{minttl}));
|
---|
| 1081 | $page->param(ttl => ($soa{ttl} ? $soa{ttl} : $DNSDB::def{soattl}));
|
---|
| 1082 | }
|
---|
| 1083 |
|
---|
| 1084 | sub showdomain {
|
---|
| 1085 | my $def = shift;
|
---|
| 1086 | my $id = shift;
|
---|
| 1087 |
|
---|
| 1088 | # get the SOA first
|
---|
| 1089 | my %soa = getSOA($dbh,$def,$id);
|
---|
| 1090 |
|
---|
| 1091 | $page->param(recid => $soa{recid});
|
---|
| 1092 | $page->param(contact => $soa{contact});
|
---|
| 1093 | $page->param(prins => $soa{prins});
|
---|
| 1094 | $page->param(refresh => $soa{refresh});
|
---|
| 1095 | $page->param(retry => $soa{retry});
|
---|
| 1096 | $page->param(expire => $soa{expire});
|
---|
| 1097 | $page->param(minttl => $soa{minttl});
|
---|
| 1098 | $page->param(ttl => $soa{ttl});
|
---|
| 1099 |
|
---|
| 1100 | # my @foo2 = getDomRecs($dbh,'def',1);
|
---|
[4] | 1101 | my $foo2 = getDomRecs($dbh,$def,$id,$perpage,$webvar{offset});
|
---|
[2] | 1102 |
|
---|
| 1103 | my $row = 0;
|
---|
| 1104 | foreach my $rec (@$foo2) {
|
---|
| 1105 | $rec->{type} = $typemap{$rec->{type}};
|
---|
| 1106 | $rec->{row} = $row % 2;
|
---|
[62] | 1107 | $rec->{defrec} = $def;
|
---|
[2] | 1108 | $rec->{sid} = $webvar{sid};
|
---|
[13] | 1109 | $rec->{id} = $id;
|
---|
[23] | 1110 | $rec->{distance} = 'n/a' unless ($rec->{type} eq 'MX' || $rec->{type} eq 'SRV');
|
---|
| 1111 | $rec->{weight} = 'n/a' unless ($rec->{type} eq 'SRV');
|
---|
| 1112 | $rec->{port} = 'n/a' unless ($rec->{type} eq 'SRV');
|
---|
[2] | 1113 | $row++;
|
---|
| 1114 | }
|
---|
| 1115 | $page->param(reclist => $foo2);
|
---|
| 1116 | }
|
---|
| 1117 |
|
---|
[16] | 1118 | # fill in record type list on add/update/edit record template
|
---|
| 1119 | sub fill_rectypes {
|
---|
[13] | 1120 | my $type = shift || $reverse_typemap{A};
|
---|
[31] | 1121 | my $soaflag = shift || 0;
|
---|
[13] | 1122 |
|
---|
[17] | 1123 | my $sth = $dbh->prepare("SELECT val,name FROM rectypes WHERE stdflag=1 ORDER BY listorder");
|
---|
[2] | 1124 | $sth->execute;
|
---|
| 1125 | my @typelist;
|
---|
| 1126 | while (my ($rval,$rname) = $sth->fetchrow_array()) {
|
---|
| 1127 | my %row = ( recval => $rval, recname => $rname );
|
---|
[13] | 1128 | $row{tselect} = 1 if $rval == $type;
|
---|
[2] | 1129 | push @typelist, \%row;
|
---|
| 1130 | }
|
---|
[31] | 1131 | if ($soaflag) {
|
---|
| 1132 | my %row = ( recval => $reverse_typemap{SOA}, recname => 'SOA' );
|
---|
| 1133 | $row{tselect} = 1 if $reverse_typemap{SOA} == $type;
|
---|
| 1134 | push @typelist, \%row;
|
---|
| 1135 | }
|
---|
[2] | 1136 | $page->param(typelist => \@typelist);
|
---|
[31] | 1137 | } # fill_rectypes
|
---|
[16] | 1138 |
|
---|
| 1139 | sub fill_recdata {
|
---|
| 1140 | fill_rectypes($webvar{type});
|
---|
| 1141 |
|
---|
| 1142 | $page->param(name => $webvar{name});
|
---|
| 1143 | $page->param(address => $webvar{address});
|
---|
| 1144 | $page->param(distance => $webvar{distance})
|
---|
| 1145 | if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV});
|
---|
| 1146 | $page->param(weight => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV};
|
---|
| 1147 | $page->param(port => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV};
|
---|
[2] | 1148 | $page->param(ttl => ($webvar{ttl} ? $webvar{ttl} : $DNSDB::def{minttl}));
|
---|
| 1149 | }
|
---|
[7] | 1150 |
|
---|
[24] | 1151 | sub fill_actypelist {
|
---|
| 1152 | my @actypes;
|
---|
| 1153 |
|
---|
| 1154 | my %row1 = (actypeval => 'u', actypename => 'user');
|
---|
| 1155 | $row1{typesel} = 1 if $webvar{accttype} eq 'u';
|
---|
| 1156 | push @actypes, \%row1;
|
---|
| 1157 |
|
---|
| 1158 | my %row2 = (actypeval => 'S', actypename => 'superuser');
|
---|
| 1159 | $row2{typesel} = 1 if $webvar{accttype} eq 'S';
|
---|
| 1160 | push @actypes, \%row2;
|
---|
| 1161 |
|
---|
| 1162 | $page->param(actypelist => \@actypes);
|
---|
| 1163 | }
|
---|
| 1164 |
|
---|
[65] | 1165 | sub fill_clonemelist {
|
---|
| 1166 | my $sth = $dbh->prepare("SELECT username,user_id FROM users WHERE group_id=$curgroup");
|
---|
| 1167 | $sth->execute;
|
---|
| 1168 |
|
---|
| 1169 | my @clonesrc;
|
---|
| 1170 | while (my ($username,$uid) = $sth->fetchrow_array) {
|
---|
| 1171 | my %row = (
|
---|
| 1172 | username => $username,
|
---|
| 1173 | uid => $uid,
|
---|
| 1174 | selected => ($webvar{clonesrc} == $uid ? 1 : 0)
|
---|
| 1175 | );
|
---|
| 1176 | push @clonesrc, \%row;
|
---|
| 1177 | }
|
---|
| 1178 | $page->param(clonesrc => \@clonesrc);
|
---|
| 1179 | }
|
---|
| 1180 |
|
---|
[7] | 1181 | sub fill_fpnla {
|
---|
| 1182 | my $count = shift;
|
---|
| 1183 | ##fixme
|
---|
| 1184 | if ($offset eq 'all') {
|
---|
[70] | 1185 | $page->param(perpage => $perpage);
|
---|
[41] | 1186 | # uhm....
|
---|
[7] | 1187 | } else {
|
---|
| 1188 | # all these bits only have sensible behaviour if offset is numeric. err, probably.
|
---|
| 1189 | if ($count > $perpage) {
|
---|
| 1190 | # if there are more results than the default, always show the "all" link
|
---|
| 1191 | $page->param(navall => 1);
|
---|
| 1192 |
|
---|
| 1193 | if ($offset > 0) {
|
---|
| 1194 | $page->param(navfirst => 1);
|
---|
| 1195 | $page->param(navprev => 1);
|
---|
| 1196 | $page->param(prevoffs => $offset-1);
|
---|
| 1197 | }
|
---|
| 1198 |
|
---|
| 1199 | # show "next" and "last" links if we're not on the last page of results
|
---|
| 1200 | if ( (($offset+1) * $perpage - $count) < 0 ) {
|
---|
| 1201 | $page->param(navnext => 1);
|
---|
| 1202 | $page->param(nextoffs => $offset+1);
|
---|
| 1203 | $page->param(navlast => 1);
|
---|
[8] | 1204 | $page->param(lastoffs => int (($count-1)/$perpage));
|
---|
[7] | 1205 | }
|
---|
| 1206 | }
|
---|
| 1207 | }
|
---|
[10] | 1208 | } # end fill_fpnla()
|
---|
| 1209 |
|
---|
[12] | 1210 | sub fill_pgcount {
|
---|
| 1211 | my $pgcount = shift;
|
---|
| 1212 | my $pgtype = shift;
|
---|
| 1213 | my $parent = shift;
|
---|
| 1214 |
|
---|
| 1215 | $page->param(ntot => $pgcount);
|
---|
| 1216 | $page->param(nfirst => (($offset eq 'all' ? 0 : $offset)*$perpage+1));
|
---|
| 1217 | $page->param(npglast => ($offset eq 'all' ? $pgcount :
|
---|
| 1218 | ( (($offset+1)*$perpage) > $pgcount ? $pgcount : (($offset+1)*$perpage) )
|
---|
| 1219 | ));
|
---|
| 1220 | $page->param(pgtype => $pgtype);
|
---|
| 1221 | $page->param(parent => $parent);
|
---|
| 1222 | } # end fill_pgcount()
|
---|
| 1223 |
|
---|
[11] | 1224 | sub listdomains {
|
---|
[41] | 1225 |
|
---|
[62] | 1226 | $startwith = $session->param($webvar{page}.'startwith');
|
---|
| 1227 | $filter = $session->param($webvar{page}.'filter');
|
---|
| 1228 | $searchsubs = $session->param($webvar{page}.'searchsubs');
|
---|
| 1229 |
|
---|
[53] | 1230 | ##fixme: $logingroup or $curgroup?
|
---|
[52] | 1231 | my @childgroups;
|
---|
[61] | 1232 | getChildren($dbh, $curgroup, \@childgroups, 'all') if $searchsubs;
|
---|
[52] | 1233 | my $childlist = join(',',@childgroups);
|
---|
| 1234 |
|
---|
[57] | 1235 | my $sql = "SELECT count(*) FROM domains WHERE group_id IN ($curgroup".($childlist ? ",$childlist" : '').")".
|
---|
[53] | 1236 | ($startwith ? " AND domain ~* '^[$startwith]'" : '').
|
---|
| 1237 | ($filter ? " AND domain ~* '$filter'" : '');
|
---|
[52] | 1238 | my $sth = $dbh->prepare($sql);
|
---|
| 1239 | $sth->execute;
|
---|
[17] | 1240 | my ($count) = $sth->fetchrow_array;
|
---|
| 1241 |
|
---|
[12] | 1242 | # fill page count and first-previous-next-last-all bits
|
---|
| 1243 | ##fixme - hardcoded group bit
|
---|
[20] | 1244 | fill_pgcount($count,"domains",groupName($dbh,$curgroup));
|
---|
[10] | 1245 | fill_fpnla($count);
|
---|
| 1246 |
|
---|
[41] | 1247 | # sort/order
|
---|
[51] | 1248 | $session->param($webvar{page}.'sortby', $webvar{sortby}) if $webvar{sortby};
|
---|
| 1249 | $session->param($webvar{page}.'order', $webvar{order}) if $webvar{order};
|
---|
[41] | 1250 |
|
---|
[51] | 1251 | $sortby = $session->param($webvar{page}.'sortby');
|
---|
| 1252 | $sortorder = $session->param($webvar{page}.'order');
|
---|
| 1253 |
|
---|
[44] | 1254 | # set up the headers
|
---|
| 1255 | my @cols = ('domain', 'status', 'group');
|
---|
| 1256 | my %colheads = (domain => 'Domain', status => 'Status', group => 'Group');
|
---|
[54] | 1257 | fill_colheads($sortby, $sortorder, \@cols, \%colheads);
|
---|
[41] | 1258 |
|
---|
[47] | 1259 | # $page->param(sortorder => $sortorder);
|
---|
[41] | 1260 | # hack! hack! pthbttt. have to rethink the status column storage,
|
---|
| 1261 | # or inactive comes "before" active. *sigh*
|
---|
| 1262 | $sortorder = ($sortorder eq 'ASC' ? 'DESC' : 'ASC') if $sortby eq 'status';
|
---|
| 1263 |
|
---|
[51] | 1264 | # waffle, waffle - keep state on these as well as sortby, sortorder?
|
---|
[53] | 1265 | $page->param("start$startwith" => 1) if $startwith && $startwith =~ /^(?:[a-z]|0-9)$/;
|
---|
[41] | 1266 |
|
---|
[53] | 1267 | $page->param(filter => $filter) if $filter;
|
---|
| 1268 | $page->param(searchsubs => $searchsubs) if $searchsubs;
|
---|
[41] | 1269 |
|
---|
| 1270 | ##fixme
|
---|
| 1271 | ##fixme push the SQL and direct database fiddling off into a sub in DNSDB.pm
|
---|
| 1272 | ##fixme
|
---|
| 1273 |
|
---|
[20] | 1274 | $page->param(group => $curgroup);
|
---|
[10] | 1275 | my @domlist;
|
---|
[52] | 1276 | $sql = "SELECT domain_id,domain,status,groups.group_name AS group FROM domains".
|
---|
[20] | 1277 | " INNER JOIN groups ON domains.group_id=groups.group_id".
|
---|
[57] | 1278 | " WHERE domains.group_id IN ($curgroup".($childlist ? ",$childlist" : '').")".
|
---|
[41] | 1279 | ##fixme: don't do variable subs in SQL, use placeholders and params in ->execute()
|
---|
[53] | 1280 | ($startwith ? " AND domain ~* '^[$startwith]'" : '').
|
---|
| 1281 | ($filter ? " AND domain ~* '$filter'" : '').
|
---|
[41] | 1282 | " ORDER BY ".($sortby eq 'group' ? 'groups.group_name' : $sortby).
|
---|
| 1283 | " $sortorder ".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage);
|
---|
| 1284 | $sth = $dbh->prepare($sql);
|
---|
[52] | 1285 | $sth->execute;
|
---|
[10] | 1286 | my $rownum = 0;
|
---|
| 1287 | while (my @data = $sth->fetchrow_array) {
|
---|
| 1288 | my %row;
|
---|
| 1289 | $row{domainid} = $data[0];
|
---|
| 1290 | $row{domain} = $data[1];
|
---|
| 1291 | $row{status} = ($data[2] ? 'Active' : 'Inactive');
|
---|
| 1292 | $row{group} = $data[3];
|
---|
| 1293 | $row{bg} = ($rownum++)%2;
|
---|
| 1294 | # $row{mkactive} = ($data[2] eq 'inactive' ? 1 : 0);
|
---|
| 1295 | $row{mkactive} = !$data[2];
|
---|
| 1296 | $row{sid} = $sid;
|
---|
| 1297 | $row{offset} = $offset;
|
---|
| 1298 | ##fixme: need to clean up status indicator/usage/inversion
|
---|
| 1299 | push @domlist, \%row;
|
---|
| 1300 | }
|
---|
| 1301 | $page->param(domtable => \@domlist);
|
---|
[11] | 1302 | } # end listdomains()
|
---|
[18] | 1303 |
|
---|
[22] | 1304 | sub listgroups {
|
---|
[53] | 1305 |
|
---|
[26] | 1306 | my @childgroups;
|
---|
[53] | 1307 | getChildren($dbh, $logingroup, \@childgroups, 'all') if $searchsubs;
|
---|
[26] | 1308 | my $childlist = join(',',@childgroups);
|
---|
| 1309 |
|
---|
[54] | 1310 | my $sql = "SELECT count(*) FROM groups WHERE parent_group_id IN ($logingroup".($childlist ? ",$childlist" : '').")".
|
---|
[53] | 1311 | ($startwith ? " AND group_name ~* '^[$startwith]'" : '').
|
---|
| 1312 | ($filter ? " AND group_name ~* '$filter'" : '');
|
---|
[26] | 1313 | my $sth = $dbh->prepare($sql);
|
---|
| 1314 |
|
---|
[22] | 1315 | $sth->execute;
|
---|
| 1316 | my ($count) = ($sth->fetchrow_array);
|
---|
| 1317 | # fill page count and first-previous-next-last-all bits
|
---|
| 1318 | ##fixme - hardcoded group bit
|
---|
| 1319 | fill_pgcount($count,"groups",'');
|
---|
| 1320 | fill_fpnla($count);
|
---|
| 1321 |
|
---|
[51] | 1322 | # $sortby = 'group';
|
---|
[42] | 1323 | # sort/order
|
---|
[51] | 1324 | $session->param($webvar{page}.'sortby', $webvar{sortby}) if $webvar{sortby};
|
---|
| 1325 | $session->param($webvar{page}.'order', $webvar{order}) if $webvar{order};
|
---|
[42] | 1326 |
|
---|
[51] | 1327 | $sortby = $session->param($webvar{page}.'sortby');
|
---|
| 1328 | $sortorder = $session->param($webvar{page}.'order');
|
---|
| 1329 |
|
---|
[44] | 1330 | # set up the headers
|
---|
| 1331 | my @cols = ('group','parent','nusers','ndomains');
|
---|
| 1332 | my %colnames = (group => 'Group', parent => 'Parent Group', nusers => 'Users', ndomains => 'Domains');
|
---|
[54] | 1333 | fill_colheads($sortby, $sortorder, \@cols, \%colnames);
|
---|
[42] | 1334 |
|
---|
[51] | 1335 | # waffle, waffle - keep state on these as well as sortby, sortorder?
|
---|
[64] | 1336 | $page->param("start$startwith" => 1) if $startwith && $startwith =~ /^(?:[a-z]|0-9)$/;
|
---|
[51] | 1337 |
|
---|
[53] | 1338 | $page->param(filter => $filter) if $filter;
|
---|
| 1339 | $page->param(searchsubs => $searchsubs) if $searchsubs;
|
---|
[51] | 1340 |
|
---|
| 1341 | # munge sortby for columns in database
|
---|
| 1342 | $sortby = 'g.group_name' if $sortby eq 'group';
|
---|
| 1343 | $sortby = 'g2.group_name' if $sortby eq 'parent';
|
---|
| 1344 |
|
---|
[22] | 1345 | my @grouplist;
|
---|
| 1346 | $sth = $dbh->prepare("SELECT g.group_id, g.group_name, g2.group_name, ".
|
---|
[51] | 1347 | "count(distinct(u.username)) AS nusers, count(distinct(d.domain)) AS ndomains ".
|
---|
[22] | 1348 | "FROM groups g ".
|
---|
| 1349 | "INNER JOIN groups g2 ON g2.group_id=g.parent_group_id ".
|
---|
| 1350 | "LEFT OUTER JOIN users u ON u.group_id=g.group_id ".
|
---|
| 1351 | "LEFT OUTER JOIN domains d ON d.group_id=g.group_id ".
|
---|
[54] | 1352 | "WHERE g.parent_group_id IN ($logingroup".($childlist ? ",$childlist" : '').") ".
|
---|
[51] | 1353 | ##fixme: don't do variable subs in SQL, use placeholders and params in ->execute()
|
---|
[53] | 1354 | ($startwith ? " AND g.group_name ~* '^[$startwith]'" : '').
|
---|
| 1355 | ($filter ? " AND g.group_name ~* '$filter'" : '').
|
---|
[51] | 1356 | " GROUP BY g.group_id, g.group_name, g2.group_name ".
|
---|
| 1357 | " ORDER BY $sortby $sortorder ".
|
---|
| 1358 | ($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage));
|
---|
[22] | 1359 | $sth->execute;
|
---|
| 1360 |
|
---|
| 1361 | my $rownum = 0;
|
---|
| 1362 | while (my @data = $sth->fetchrow_array) {
|
---|
| 1363 | my %row;
|
---|
| 1364 | $row{groupid} = $data[0];
|
---|
| 1365 | $row{groupname} = $data[1];
|
---|
| 1366 | $row{pgroup} = $data[2];
|
---|
| 1367 | $row{nusers} = $data[3];
|
---|
| 1368 | $row{ndomains} = $data[4];
|
---|
| 1369 | $row{bg} = ($rownum++)%2;
|
---|
| 1370 | $row{sid} = $sid;
|
---|
| 1371 | push @grouplist, \%row;
|
---|
| 1372 | }
|
---|
| 1373 | $page->param(grouptable => \@grouplist);
|
---|
| 1374 | } # end listgroups()
|
---|
| 1375 |
|
---|
[20] | 1376 | sub fill_grouplist {
|
---|
[19] | 1377 | my $template_var = shift;
|
---|
| 1378 | my $cur = shift || $curgroup;
|
---|
[26] | 1379 |
|
---|
| 1380 | my @childgroups;
|
---|
| 1381 | getChildren($dbh, $logingroup, \@childgroups, 'all');
|
---|
| 1382 | my $childlist = join(',',@childgroups);
|
---|
| 1383 |
|
---|
[18] | 1384 | # weesa gonna discard parent_group_id for now
|
---|
[26] | 1385 | my $sth = $dbh->prepare("SELECT group_id,parent_group_id,group_name FROM groups ".
|
---|
| 1386 | "WHERE group_id IN ($logingroup".($childlist ? ",$childlist" : '').")".
|
---|
| 1387 | "ORDER BY group_id");
|
---|
[18] | 1388 | $sth->execute;
|
---|
[20] | 1389 | my @grouplist;
|
---|
| 1390 | while (my ($groupid,$pargroup,$groupname) = $sth->fetchrow_array()) {
|
---|
[18] | 1391 | my %row;
|
---|
[20] | 1392 | $row{groupname} = $groupname;
|
---|
| 1393 | $row{groupval} = $groupid;
|
---|
[18] | 1394 | ##fixme: need magic
|
---|
[20] | 1395 | # $row{defgroup} = '';
|
---|
| 1396 | $row{groupactive} = 1 if $groupid == $cur;
|
---|
| 1397 | push @grouplist, \%row;
|
---|
[18] | 1398 | }
|
---|
| 1399 |
|
---|
[20] | 1400 | $page->param("$template_var" => \@grouplist);
|
---|
[18] | 1401 |
|
---|
[24] | 1402 | } # end fill_grouplist()
|
---|
| 1403 |
|
---|
| 1404 | sub list_users {
|
---|
[52] | 1405 |
|
---|
| 1406 | my @childgroups;
|
---|
[53] | 1407 | getChildren($dbh, $curgroup, \@childgroups, 'all') if $searchsubs;
|
---|
[52] | 1408 | my $childlist = join(',',@childgroups);
|
---|
| 1409 |
|
---|
| 1410 | my $sql = "SELECT count(*) FROM users WHERE group_id IN ($curgroup".($childlist ? ",$childlist" : '').")".
|
---|
[53] | 1411 | ($startwith ? " AND username ~* '^[$startwith]'" : '').
|
---|
| 1412 | ($filter ? " AND username ~* '$filter'" : '');
|
---|
[52] | 1413 | my $sth = $dbh->prepare($sql);
|
---|
| 1414 | $sth->execute;
|
---|
[24] | 1415 | my ($count) = ($sth->fetchrow_array);
|
---|
| 1416 |
|
---|
| 1417 | # fill page count and first-previous-next-last-all bits
|
---|
| 1418 | ##fixme - hardcoded group bit
|
---|
| 1419 | fill_pgcount($count,"users",'');
|
---|
| 1420 | fill_fpnla($count);
|
---|
| 1421 |
|
---|
[51] | 1422 | # $sortby = 'user';
|
---|
[44] | 1423 | # sort/order
|
---|
[51] | 1424 | $session->param($webvar{page}.'sortby', $webvar{sortby}) if $webvar{sortby};
|
---|
| 1425 | $session->param($webvar{page}.'order', $webvar{order}) if $webvar{order};
|
---|
[44] | 1426 |
|
---|
[51] | 1427 | $sortby = $session->param($webvar{page}.'sortby');
|
---|
| 1428 | $sortorder = $session->param($webvar{page}.'order');
|
---|
| 1429 |
|
---|
[44] | 1430 | # set up the headers
|
---|
| 1431 | my @cols = ('user','fname','type','group','status');
|
---|
| 1432 | my %colnames = (user => 'Username', fname => 'Full Name', type => 'Type', group => 'Group', status => 'Status');
|
---|
[54] | 1433 | fill_colheads($sortby, $sortorder, \@cols, \%colnames);
|
---|
[44] | 1434 |
|
---|
[51] | 1435 | # waffle, waffle - keep state on these as well as sortby, sortorder?
|
---|
[64] | 1436 | $page->param("start$startwith" => 1) if $startwith && $startwith =~ /^(?:[a-z]|0-9)$/;
|
---|
[51] | 1437 |
|
---|
[53] | 1438 | $page->param(filter => $filter) if $filter;
|
---|
| 1439 | $page->param(searchsubs => $searchsubs) if $searchsubs;
|
---|
[51] | 1440 |
|
---|
| 1441 | # munge sortby for columns in database
|
---|
| 1442 | $sortby = 'u.username' if $sortby eq 'user';
|
---|
| 1443 | $sortby = 'u.type' if $sortby eq 'type';
|
---|
| 1444 | $sortby = 'g.group_name' if $sortby eq 'group';
|
---|
| 1445 | $sortby = 'u.status' if $sortby eq 'status';
|
---|
| 1446 |
|
---|
[24] | 1447 | my @userlist;
|
---|
[52] | 1448 | $sql = "SELECT u.user_id, u.username, u.firstname || ' ' || u.lastname AS fname, u.type, g.group_name, u.status ".
|
---|
[24] | 1449 | "FROM users u ".
|
---|
| 1450 | "INNER JOIN groups g ON u.group_id=g.group_id ".
|
---|
[52] | 1451 | "WHERE u.group_id IN ($curgroup".($childlist ? ",$childlist" : '').")".
|
---|
[51] | 1452 | ##fixme: don't do variable subs in SQL, use placeholders and params in ->execute()
|
---|
[53] | 1453 | ($startwith ? " AND u.username ~* '^[$startwith]'" : '').
|
---|
| 1454 | ($filter ? " AND u.username ~* '$filter'" : '').
|
---|
[51] | 1455 | " ORDER BY $sortby $sortorder ".
|
---|
[52] | 1456 | ($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage);
|
---|
[51] | 1457 |
|
---|
[52] | 1458 | $sth = $dbh->prepare($sql);
|
---|
| 1459 | $sth->execute;
|
---|
[24] | 1460 |
|
---|
| 1461 | my $rownum = 0;
|
---|
| 1462 | while (my @data = $sth->fetchrow_array) {
|
---|
[41] | 1463 | no warnings "uninitialized"; # Just In Case something stupid happens and a user gets no first or last name
|
---|
[24] | 1464 | my %row;
|
---|
| 1465 | $row{userid} = $data[0];
|
---|
| 1466 | $row{username} = $data[1];
|
---|
[51] | 1467 | $row{userfull} = $data[2];
|
---|
| 1468 | $row{usertype} = ($data[3] eq 'S' ? 'superuser' : "user");
|
---|
| 1469 | $row{usergroup} = $data[4];
|
---|
| 1470 | $row{active} = $data[5];
|
---|
[24] | 1471 | $row{bg} = ($rownum++)%2;
|
---|
| 1472 | $row{sid} = $sid;
|
---|
| 1473 | push @userlist, \%row;
|
---|
| 1474 | }
|
---|
| 1475 | $page->param(usertable => \@userlist);
|
---|
[55] | 1476 | } # end list_users()
|
---|
[43] | 1477 |
|
---|
| 1478 | # Generate all of the glop necessary to add or not the appropriate marker/flag for
|
---|
| 1479 | # the sort order and column in domain, user, group, and record lists
|
---|
| 1480 | # Takes an array ref and hash ref
|
---|
| 1481 | sub fill_colheads {
|
---|
[54] | 1482 | my $sortby = shift;
|
---|
| 1483 | my $sortorder = shift;
|
---|
[43] | 1484 | my $cols = shift;
|
---|
| 1485 | my $colnames = shift;
|
---|
| 1486 |
|
---|
| 1487 | my @headings;
|
---|
| 1488 |
|
---|
| 1489 | foreach my $col (@$cols) {
|
---|
| 1490 | my %coldata;
|
---|
| 1491 | $coldata{firstcol} = 1 if $col eq $cols->[0];
|
---|
| 1492 | $coldata{sid} = $sid;
|
---|
| 1493 | $coldata{page} = $webvar{page};
|
---|
| 1494 | $coldata{offset} = $webvar{offset} if $webvar{offset};
|
---|
| 1495 | $coldata{sortby} = $col;
|
---|
| 1496 | $coldata{colname} = $colnames->{$col};
|
---|
| 1497 | if ($col eq $sortby) {
|
---|
| 1498 | $coldata{order} = ($sortorder eq 'ASC' ? 'DESC' : 'ASC');
|
---|
| 1499 | $coldata{sortorder} = $sortorder;
|
---|
| 1500 | } else {
|
---|
| 1501 | $coldata{order} = 'ASC';
|
---|
| 1502 | }
|
---|
| 1503 | push @headings, \%coldata;
|
---|
| 1504 | }
|
---|
| 1505 |
|
---|
| 1506 | $page->param(colheads => \@headings);
|
---|
| 1507 |
|
---|
[54] | 1508 | } # end fill_colheads()
|
---|
[55] | 1509 |
|
---|
| 1510 | sub logaction {
|
---|
[59] | 1511 | my $domid = shift;
|
---|
| 1512 | my $username = shift;
|
---|
| 1513 | my $groupid = shift;
|
---|
| 1514 | my $entry = shift;
|
---|
[55] | 1515 |
|
---|
[59] | 1516 | ##fixme: ooohhh, nasty. what if we get a failure *here*? PTHBTT!
|
---|
| 1517 | my $sth = $dbh->prepare("SELECT user_id, firstname || ' ' || lastname FROM users WHERE username=?");
|
---|
[55] | 1518 | $sth->execute($username);
|
---|
| 1519 | my ($user_id, $fullname) = $sth->fetchrow_array;
|
---|
| 1520 |
|
---|
| 1521 | $sth = $dbh->prepare("INSERT INTO log (domain_id,user_id,group_id,email,name,entry) ".
|
---|
| 1522 | "VALUES (?,?,?,?,?,?)");
|
---|
[57] | 1523 | $sth->execute($domid,$user_id,$groupid,$username,$fullname,$entry);
|
---|
[55] | 1524 | } # end logaction()
|
---|
[57] | 1525 |
|
---|
[59] | 1526 | ##fixme: generalize to return appropriate id on all cases (ie, use $partype)
|
---|
[57] | 1527 | sub parentID {
|
---|
| 1528 | my $id = shift;
|
---|
| 1529 | my $idtype = shift;
|
---|
| 1530 | my $partype = shift;
|
---|
| 1531 | my $defrec = shift || '';
|
---|
| 1532 |
|
---|
| 1533 | my $sql = '';
|
---|
| 1534 |
|
---|
| 1535 | if ($idtype eq 'dom') {
|
---|
[59] | 1536 | return $id if $defrec eq 'y'; # "domain" + default records, we're really looking at a group.
|
---|
[57] | 1537 | $sql = "SELECT group_id FROM domains WHERE domain_id=?";
|
---|
| 1538 | } elsif ($idtype eq 'rec') {
|
---|
[59] | 1539 | if ($defrec eq 'y') {
|
---|
| 1540 | $sql = "SELECT group_id FROM default_records WHERE record_id=?";
|
---|
[57] | 1541 | } else {
|
---|
| 1542 | return
|
---|
| 1543 | $sql = "SELECT d.group_id FROM domains d".
|
---|
| 1544 | " INNER JOIN records r ON d.domain_id=r.domain_id".
|
---|
| 1545 | " WHERE r.record_id=?";
|
---|
| 1546 | }
|
---|
| 1547 | } elsif ($idtype eq 'group') {
|
---|
| 1548 | $sql = "SELECT parent_group_id FROM groups WHERE group_id=?";
|
---|
| 1549 | } elsif ($idtype eq 'user') {
|
---|
| 1550 | $sql = "SELECT group_id FROM users WHERE user_id=?";
|
---|
| 1551 | } else {
|
---|
| 1552 | return "FOO", "BAR"; # can't get here.... we think.
|
---|
| 1553 | }
|
---|
[59] | 1554 | my $sth = $dbh->prepare($sql);
|
---|
| 1555 | $sth->execute($id);
|
---|
| 1556 | my ($retid) = $sth->fetchrow_array;
|
---|
| 1557 | return $retid if $retid;
|
---|
| 1558 | # ahh! fall of the edge of the world if things went sideways
|
---|
| 1559 | ##fixme: really need to do a little more error handling, I think
|
---|
[64] | 1560 | } # end parentID()
|
---|
[66] | 1561 |
|
---|
| 1562 | # we have to do this in a variety of places; let's make it consistent
|
---|
| 1563 | sub fill_permissions {
|
---|
| 1564 | my $template = shift; # may need to do several sets on a single page
|
---|
| 1565 | my $permset = shift; # hashref to permissions on object
|
---|
[67] | 1566 | my $usercan = shift || \%permissions; # allow alternate user-is-allowed permission block
|
---|
[66] | 1567 |
|
---|
| 1568 | foreach (@permtypes) {
|
---|
[67] | 1569 | $template->param("may_$_" => ($usercan->{admin} || $usercan->{$_}));
|
---|
[66] | 1570 | $template->param($_ => $permset->{$_});
|
---|
| 1571 | }
|
---|
| 1572 | }
|
---|