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