[2] | 1 | #!/usr/bin/perl -w -T
|
---|
| 2 | # dns/cgi-bin/dns.cgi
|
---|
| 3 | ###
|
---|
| 4 | # SVN revision info
|
---|
| 5 | # $Date: 2009-11-02 21:40:07 +0000 (Mon, 02 Nov 2009) $
|
---|
| 6 | # SVN revision $Rev: 25 $
|
---|
| 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;
|
---|
| 18 | use DBI;
|
---|
| 19 |
|
---|
| 20 | use lib '.';
|
---|
| 21 | # custom modules
|
---|
| 22 | use DNSDB qw(:ALL);
|
---|
| 23 |
|
---|
[13] | 24 | my @debugbits; # temp, to be spit out near the end of processing
|
---|
| 25 |
|
---|
[2] | 26 | # Let's do these templates right...
|
---|
| 27 | my $templatedir = "templates";
|
---|
| 28 | my $sessiondir = "session";
|
---|
| 29 |
|
---|
| 30 | # Set up the CGI object...
|
---|
| 31 | my $q = new CGI::Simple;
|
---|
| 32 | # ... and get query-string params as well as POST params if necessary
|
---|
| 33 | $q->parse_query_string;
|
---|
| 34 |
|
---|
| 35 | # This is probably excessive fiddling, but it puts the parameters somewhere my fingers know about...
|
---|
[7] | 36 | my %webvar = $q->Vars;
|
---|
[2] | 37 |
|
---|
[13] | 38 | # persistent stuff needed on most/all pages
|
---|
[2] | 39 | my $sid = ($webvar{sid} ? $webvar{sid} : undef);
|
---|
| 40 | my $session = new CGI::Session("driver:File", $sid, {Directory => $sessiondir});
|
---|
| 41 | #$sid = $session->id() if !$sid;
|
---|
| 42 | if (!$sid) {
|
---|
| 43 | # init stuff. can probably axe this down to just above if'n'when user manipulation happens
|
---|
| 44 | $sid = $session->id();
|
---|
| 45 | # need to know the "upper" group the user can deal with; may as well
|
---|
| 46 | # stick this in the session rather than calling out to the DB every time.
|
---|
[18] | 47 | $session->param('logingroup',1);
|
---|
| 48 | $session->param('curgroup',1); # yes, we *do* need to track this too. er, probably.
|
---|
[2] | 49 | }
|
---|
| 50 |
|
---|
[19] | 51 | my $logingroup = ($session->param('logingroup') ? $session->param('logingroup') : 1);
|
---|
| 52 | my $curgroup = ($session->param('curgroup') ? $session->param('curgroup') : $logingroup);
|
---|
[17] | 53 | my $group = ($webvar{group} ? $webvar{group} : 1);
|
---|
[18] | 54 |
|
---|
[2] | 55 | # handle login redirect
|
---|
| 56 | if ($webvar{action} && $webvar{action} eq 'login') {
|
---|
[11] | 57 | ##fixme: need to actually do a user/pass check
|
---|
| 58 | changepage(page => "domlist");
|
---|
[2] | 59 | }
|
---|
| 60 |
|
---|
[20] | 61 | if ($webvar{action} && $webvar{action} eq 'chgroup') {
|
---|
| 62 | # fiddle session-stored group data
|
---|
| 63 | # magic incantation to... uhhh...
|
---|
| 64 | $session->param('curgroup', $webvar{group});
|
---|
| 65 | $curgroup = ($webvar{group} ? $webvar{group} : $session->param('curgroup'));
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[2] | 68 | my $header = HTML::Template->new(filename => "$templatedir/header.tmpl");
|
---|
| 69 | my $footer = HTML::Template->new(filename => "$templatedir/footer.tmpl");
|
---|
| 70 |
|
---|
| 71 | # default
|
---|
[3] | 72 | #my $perpage = 15;
|
---|
[15] | 73 | my $perpage = 3;
|
---|
[2] | 74 | my $offset = ($webvar{offset} ? $webvar{offset} : 0);
|
---|
| 75 |
|
---|
| 76 | # NB: these must match the field name and SQL ascend/descend syntax respectively
|
---|
| 77 | my $sortfield = "domains";
|
---|
| 78 | my $sortorder = "asc";
|
---|
| 79 |
|
---|
| 80 | my ($dbh,$msg) = connectDB("dnsdb","dnsdb","secret");
|
---|
| 81 | #my $dbh = DBI->connect("DBI:mysql:database=vegadns","vegadns","secret",
|
---|
| 82 | # { AutoCommit => 0 }) or die $DBI::errstr;
|
---|
| 83 |
|
---|
| 84 | ##fixme. PLEASE! <G>
|
---|
| 85 | print $msg if !$dbh;
|
---|
| 86 |
|
---|
| 87 | # fiddle hardcoded "defaults" as per system/user (?) prefs
|
---|
| 88 | initGlobals($dbh);
|
---|
| 89 |
|
---|
[15] | 90 | ## Default page is a login page
|
---|
| 91 | #my $page; # to be initialized as an HTML::Template entity sooner or later
|
---|
[2] | 92 |
|
---|
[3] | 93 |
|
---|
| 94 |
|
---|
[2] | 95 | # decide which page to spit out...
|
---|
[15] | 96 | $webvar{page} = 'login' if !$webvar{page};
|
---|
| 97 | #if (!$webvar{page}) {
|
---|
| 98 | # $page = HTML::Template->new(filename => "$templatedir/login.tmpl");
|
---|
| 99 | #} else {
|
---|
| 100 | #}
|
---|
[2] | 101 |
|
---|
[15] | 102 | my $page = HTML::Template->new(filename => "$templatedir/$webvar{page}.tmpl");
|
---|
| 103 |
|
---|
[2] | 104 | $page->param(sid => $sid);
|
---|
| 105 |
|
---|
| 106 | if ($webvar{page} eq 'domlist' or $webvar{page} eq 'index') {
|
---|
[3] | 107 |
|
---|
| 108 | # hmm. seeing problems in some possibly-not-so-corner cases.
|
---|
[10] | 109 | # this currently only handles "domain on", "domain off"
|
---|
[3] | 110 | if (defined($webvar{action})) {
|
---|
| 111 | domStatus($dbh,$webvar{id},$webvar{action});
|
---|
| 112 | }
|
---|
| 113 |
|
---|
[18] | 114 | $page->param(curpage => $webvar{page});
|
---|
| 115 |
|
---|
[11] | 116 | listdomains();
|
---|
[2] | 117 |
|
---|
| 118 | } elsif ($webvar{page} eq 'reclist') {
|
---|
| 119 |
|
---|
[4] | 120 | # Handle record list for both default records (per-group) and live domain records
|
---|
[2] | 121 |
|
---|
| 122 | $page->param(defrec => $webvar{defrec});
|
---|
[4] | 123 | $page->param(id => $webvar{id});
|
---|
[18] | 124 | $page->param(curpage => $webvar{page});
|
---|
[2] | 125 |
|
---|
[4] | 126 | # select count(*) from (default_)?records where (group|domain)_id=?
|
---|
| 127 | my $sth = $dbh->prepare("SELECT count(*) FROM ".
|
---|
| 128 | ($webvar{defrec} eq 'y' ? 'default_' : '')."records ".
|
---|
| 129 | "WHERE ".($webvar{defrec} eq 'y' ? 'group' : 'domain')."_id=? ".
|
---|
| 130 | "AND NOT type=$reverse_typemap{SOA}");
|
---|
| 131 | $sth->execute($webvar{id});
|
---|
| 132 | my ($count) = ($sth->fetchrow_array);
|
---|
| 133 |
|
---|
[12] | 134 | # fill the page-count and first-previous-next-last-all details
|
---|
| 135 | fill_pgcount($count,"records",domainName($dbh,$webvar{id}));
|
---|
[7] | 136 | fill_fpnla($count); # should put some params on this sub...
|
---|
[4] | 137 |
|
---|
| 138 | $page->param(defrec => $webvar{defrec});
|
---|
[2] | 139 | if ($webvar{defrec} eq 'y') {
|
---|
[12] | 140 | ##fixme: hardcoded group
|
---|
[20] | 141 | showdomain('y',$curgroup);
|
---|
[2] | 142 | } else {
|
---|
| 143 | showdomain('n',$webvar{id});
|
---|
| 144 | }
|
---|
| 145 |
|
---|
[4] | 146 | } elsif ($webvar{page} eq 'newdomain') {
|
---|
[2] | 147 |
|
---|
| 148 |
|
---|
[11] | 149 | } elsif ($webvar{page} eq 'deldom') {
|
---|
| 150 |
|
---|
| 151 | $page->param(id => $webvar{id});
|
---|
| 152 | # first pass = confirm y/n (sorta)
|
---|
| 153 | if (!defined($webvar{del})) {
|
---|
| 154 | $page->param(del_getconf => 1);
|
---|
| 155 | $page->param(domain => domainName($dbh,$webvar{id}));
|
---|
| 156 | # print some neato things?
|
---|
| 157 |
|
---|
| 158 | # } else {
|
---|
| 159 | # #whether actually deleting or cancelling we redirect to the domain list, default format
|
---|
| 160 |
|
---|
| 161 | } elsif ($webvar{del} eq 'ok') {
|
---|
| 162 | my ($code,$msg) = delDomain($dbh, $webvar{id});
|
---|
| 163 | if ($code ne 'OK') {
|
---|
| 164 | # need to find failure mode
|
---|
| 165 | $page->param(del_failed => 1);
|
---|
| 166 | $page->param(errmsg => $msg);
|
---|
[22] | 167 | listdomains($curgroup);
|
---|
[11] | 168 | } else {
|
---|
| 169 | # success. go back to the domain list, do not pass "GO"
|
---|
| 170 | changepage(page => "domlist");
|
---|
| 171 | }
|
---|
| 172 | } else {
|
---|
| 173 | # cancelled. whee!
|
---|
| 174 | changepage(page => "domlist");
|
---|
| 175 | }
|
---|
| 176 |
|
---|
[13] | 177 | } elsif ($webvar{page} eq 'record') {
|
---|
[16] | 178 |
|
---|
[13] | 179 | if ($webvar{recact} eq 'new') {
|
---|
[16] | 180 |
|
---|
[15] | 181 | $page->param(todo => "Add record to");
|
---|
| 182 | $page->param(recact => "add");
|
---|
[16] | 183 | fill_rectypes();
|
---|
| 184 |
|
---|
[15] | 185 | } elsif ($webvar{recact} eq 'add') {
|
---|
| 186 |
|
---|
| 187 | my @recargs = ($dbh,$webvar{defrec},$webvar{parentid},$webvar{name},$webvar{type},$webvar{address},$webvar{ttl});
|
---|
| 188 | if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}) {
|
---|
| 189 | push @recargs, $webvar{distance};
|
---|
| 190 | if ($webvar{type} == $reverse_typemap{SRV}) {
|
---|
| 191 | push @recargs, $webvar{weight};
|
---|
| 192 | push @recargs, $webvar{port};
|
---|
| 193 | }
|
---|
| 194 | }
|
---|
| 195 | my ($code,$msg) = addRec(@recargs);
|
---|
| 196 |
|
---|
| 197 | if ($code eq 'OK') {
|
---|
| 198 | changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
|
---|
| 199 | } else {
|
---|
[24] | 200 |
|
---|
| 201 | $page->param(failed => 1);
|
---|
| 202 | $page->param(errmsg => $msg);
|
---|
| 203 | $page->param(wastrying => "adding");
|
---|
| 204 | $page->param(todo => "Add record to");
|
---|
| 205 | $page->param(recact => "add");
|
---|
| 206 | $page->param(parentid => $webvar{parentid});
|
---|
| 207 | $page->param(defrec => $webvar{defrec});
|
---|
| 208 | $page->param(id => $webvar{id});
|
---|
[16] | 209 | fill_recdata(); # populate the form... er, mostly.
|
---|
[15] | 210 | }
|
---|
| 211 |
|
---|
[13] | 212 | } elsif ($webvar{recact} eq 'edit') {
|
---|
[15] | 213 |
|
---|
[16] | 214 | $page->param(todo => "Update record");
|
---|
| 215 | $page->param(recact => "update");
|
---|
| 216 | $page->param(parentid => $webvar{parentid});
|
---|
[17] | 217 | $page->param(id => $webvar{id});
|
---|
[16] | 218 | $page->param(defrec => $webvar{defrec});
|
---|
[13] | 219 | my $sth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM ".
|
---|
| 220 | ($webvar{defrec} eq 'y' ? 'default_' : '')."records WHERE record_id=?");
|
---|
| 221 | $sth->execute($webvar{id});
|
---|
| 222 | my ($host,$type,$val,$distance,$weight,$port,$ttl) = $sth->fetchrow_array;
|
---|
| 223 | $page->param(name => $host);
|
---|
| 224 | $page->param(address => $val);
|
---|
| 225 | $page->param(distance => $distance);
|
---|
| 226 | $page->param(weight => $weight);
|
---|
| 227 | $page->param(port => $port);
|
---|
| 228 | $page->param(ttl => $ttl);
|
---|
[16] | 229 | fill_rectypes($type);
|
---|
| 230 |
|
---|
| 231 | } elsif ($webvar{recact} eq 'update') {
|
---|
| 232 |
|
---|
| 233 | my ($code,$msg) = updateRec($dbh,$webvar{defrec},$webvar{id},
|
---|
| 234 | $webvar{name},$webvar{type},$webvar{address},$webvar{ttl},
|
---|
| 235 | $webvar{distance},$webvar{weight},$webvar{port});
|
---|
| 236 |
|
---|
| 237 | if ($code eq 'OK') {
|
---|
[17] | 238 | changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
|
---|
[16] | 239 | } else {
|
---|
| 240 | $page->param(failed => 1);
|
---|
| 241 | $page->param(errmsg => $msg);
|
---|
| 242 | $page->param(wastrying => "updating");
|
---|
| 243 | $page->param(todo => "Update record");
|
---|
| 244 | $page->param(recact => "update");
|
---|
| 245 | $page->param(parentid => $webvar{parentid});
|
---|
| 246 | $page->param(defrec => $webvar{defrec});
|
---|
[17] | 247 | $page->param(id => $webvar{id});
|
---|
[16] | 248 | fill_recdata();
|
---|
| 249 | }
|
---|
[13] | 250 | }
|
---|
[16] | 251 |
|
---|
[13] | 252 | if ($webvar{defrec} eq 'y') {
|
---|
[20] | 253 | $page->param(dohere => "default records in group ".groupName($dbh,$webvar{parentid}));
|
---|
[13] | 254 | } else {
|
---|
[24] | 255 | $page->param(parentid => $webvar{parentid});
|
---|
| 256 | # $page->param(id => $webvar{id});
|
---|
[16] | 257 | $page->param(dohere => domainName($dbh,$webvar{parentid}));
|
---|
[13] | 258 | }
|
---|
| 259 |
|
---|
[2] | 260 | } elsif ($webvar{page} eq 'newrec') {
|
---|
[13] | 261 | push @debugbits, "whee!\n";
|
---|
[2] | 262 |
|
---|
[3] | 263 | # populate most fields as needed. (eg, type list.)
|
---|
[13] | 264 | stdrecs();
|
---|
[2] | 265 |
|
---|
| 266 | } elsif ($webvar{page} eq 'addrec') {
|
---|
| 267 |
|
---|
| 268 | my @recargs = ($dbh,$webvar{defrec},$webvar{parentid},$webvar{name},$webvar{type},$webvar{address},$webvar{ttl});
|
---|
| 269 | if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}) {
|
---|
| 270 | push @recargs, $webvar{distance};
|
---|
| 271 | if ($webvar{type} == $reverse_typemap{SRV}) {
|
---|
| 272 | push @recargs, $webvar{weight};
|
---|
| 273 | push @recargs, $webvar{port};
|
---|
| 274 | }
|
---|
| 275 | }
|
---|
[13] | 276 | # wtf?
|
---|
| 277 | # push @recargs,
|
---|
[2] | 278 | my ($code,$msg) = addRec(@recargs);
|
---|
| 279 |
|
---|
| 280 | if ($code eq 'OK') {
|
---|
| 281 | showdomain($webvar{defrec},$webvar{parentid});
|
---|
| 282 | # NB: should **really** redirect here, in case of reload. >_< eyowch.
|
---|
| 283 | } else {
|
---|
| 284 | $page->param(add_failed => 1);
|
---|
| 285 | $page->param(errmsg => $msg);
|
---|
[13] | 286 | stdrecs($webvar{type}); # populate the form... er, mostly.
|
---|
[2] | 287 | $page->param(name => $webvar{name});
|
---|
| 288 | $page->param(address => $webvar{address});
|
---|
| 289 | $page->param(distance => $webvar{distance})
|
---|
| 290 | if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV});
|
---|
| 291 | $page->param(weight => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV};
|
---|
| 292 | $page->param(port => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV};
|
---|
| 293 | }
|
---|
| 294 |
|
---|
[3] | 295 | $page->param(defrec => $webvar{defrec});
|
---|
| 296 |
|
---|
[2] | 297 | } elsif ($webvar{page} eq 'conf_del') {
|
---|
| 298 |
|
---|
| 299 | $page->param(id => $webvar{id});
|
---|
| 300 | $page->param(defrec => $webvar{defrec});
|
---|
| 301 |
|
---|
| 302 | my @tmp = getrecdata($dbh,$webvar{id},$webvar{defrec});
|
---|
| 303 |
|
---|
| 304 | } elsif ($webvar{page} eq 'delrec') {
|
---|
| 305 |
|
---|
| 306 | $page->param(id => $webvar{id});
|
---|
| 307 | $page->param(defrec => $webvar{defrec});
|
---|
| 308 | # first pass = confirm y/n (sorta)
|
---|
| 309 | if (!defined($webvar{del})) {
|
---|
| 310 | $page->param(del_getconf => 1);
|
---|
[3] | 311 | my %rec = getRecLine($dbh,$webvar{defrec},$webvar{id});
|
---|
| 312 | $page->param(host => $rec{host});
|
---|
| 313 | $page->param(ftype => $typemap{$rec{type}});
|
---|
| 314 | $page->param(recval => $rec{val});
|
---|
[2] | 315 | } else {
|
---|
[3] | 316 | my ($code,$msg) = delRec($dbh,$webvar{defrec},$webvar{id});
|
---|
| 317 | if ($code ne 'OK') {
|
---|
| 318 | ## need to find failure mode
|
---|
| 319 | $page->param(del_failed => 1);
|
---|
| 320 | $page->param(errmsg => $msg);
|
---|
| 321 | }
|
---|
| 322 | ##fixme: group/parent instead of hardcoded 1
|
---|
| 323 | showdomain('y',1);
|
---|
[2] | 324 | }
|
---|
| 325 |
|
---|
| 326 | } elsif ($webvar{page} eq 'editsoa') {
|
---|
| 327 |
|
---|
| 328 | fillsoa($webvar{defrec},$webvar{recid});
|
---|
| 329 |
|
---|
| 330 | } elsif ($webvar{page} eq 'updatesoa') {
|
---|
| 331 | print "ooooo!\n";
|
---|
| 332 |
|
---|
| 333 | my $sth;
|
---|
| 334 | my $sql = '';
|
---|
| 335 | # no domain ID, so we're editing the default SOA for a group (we don't care which one here)
|
---|
| 336 | # plus a bit of magic to update the appropriate table
|
---|
| 337 | $sql = "update ".($webvar{domainid} eq '' ? "default_records" : "records").
|
---|
| 338 | " set host='$webvar{prins}:$webvar{contact}',".
|
---|
| 339 | " val='$webvar{refresh}:$webvar{retry}:$webvar{expire}:$webvar{minttl}',".
|
---|
| 340 | " ttl=$webvar{ttl} where record_id=$webvar{recid}";
|
---|
| 341 | $sth = $dbh->prepare($sql);
|
---|
| 342 | $sth->execute;
|
---|
| 343 |
|
---|
| 344 | if ($sth->err) {
|
---|
| 345 | $page->param(update_failed => 1);
|
---|
| 346 | $page->param(msg => $DBI::errstr);
|
---|
| 347 | fillsoa($webvar{defrec},1);
|
---|
| 348 | } else {
|
---|
| 349 | $page->param(update_failed => 0);
|
---|
| 350 | ##fixme! need to set group ID properly here
|
---|
| 351 | showdomain('y',1);
|
---|
| 352 | }
|
---|
| 353 |
|
---|
| 354 | } elsif ($webvar{page} eq 'adddomain') {
|
---|
| 355 | # Need some magic here.
|
---|
| 356 |
|
---|
| 357 | ##fixme: Group should be variable
|
---|
[20] | 358 | my ($code,$msg) = addDomain($dbh,$webvar{domain},$webvar{group},($webvar{makeactive} eq 'on' ? 1 : 0));
|
---|
[2] | 359 |
|
---|
| 360 | # hokay, a bit of magic to decide which page we hit.
|
---|
| 361 | if ($code eq 'OK') {
|
---|
[11] | 362 | # redirect to dns.cgi?etc&page=reclist
|
---|
[12] | 363 | changepage(page => "reclist", id => $msg);
|
---|
[24] | 364 | # $page = HTML::Template->new(filename => "$templatedir/reclist.tmpl");
|
---|
| 365 | # showdomain(0,$msg);
|
---|
[2] | 366 | } else {
|
---|
| 367 | # oooh, yeah, this is supposed to be a redirect. er, maybe. whee.
|
---|
[24] | 368 | ##fixme: session ID
|
---|
[2] | 369 | $page = HTML::Template->new(filename => "$templatedir/newdomain.tmpl");
|
---|
| 370 | $page->param(add_failed => 1);
|
---|
| 371 | $page->param(domain => $webvar{domain});
|
---|
| 372 | $page->param(errmsg => $msg);
|
---|
| 373 | }
|
---|
| 374 |
|
---|
[17] | 375 | } elsif ($webvar{page} eq 'grpman') {
|
---|
[2] | 376 |
|
---|
[22] | 377 | listgroups();
|
---|
[18] | 378 | $page->param(curpage => $webvar{page});
|
---|
| 379 |
|
---|
[17] | 380 | } elsif ($webvar{page} eq 'newgrp') {
|
---|
[20] | 381 |
|
---|
[18] | 382 | # do.. uhh.. stuff.. if we have no webvar{action}
|
---|
| 383 | if ($webvar{action} && $webvar{action} eq 'add') {
|
---|
| 384 | # not gonna provide the 4th param: template-or-clone flag, just yet
|
---|
| 385 | my ($code,$msg) = addGroup($dbh, $webvar{newgroup}, $webvar{pargroup});
|
---|
| 386 | changepage(page => "grpman") if $code eq 'OK';
|
---|
| 387 | $page->param(add_failed => 1);
|
---|
| 388 | $page->param(errmsg => $msg);
|
---|
| 389 | $page->param(newgroup => $webvar{newgroup});
|
---|
[20] | 390 | fill_grouplist('pargroup',$webvar{pargroup});
|
---|
[19] | 391 | } else {
|
---|
| 392 | # $page->param
|
---|
[20] | 393 | fill_grouplist('pargroup',$curgroup);
|
---|
[19] | 394 |
|
---|
[18] | 395 | }
|
---|
[20] | 396 |
|
---|
[22] | 397 | } elsif ($webvar{page} eq 'delgrp') {
|
---|
[20] | 398 |
|
---|
| 399 | $page->param(id => $webvar{id});
|
---|
| 400 | # first pass = confirm y/n (sorta)
|
---|
| 401 | if (!defined($webvar{del})) {
|
---|
| 402 | $page->param(del_getconf => 1);
|
---|
[23] | 403 | # $page->param(groupname => groupName($dbh,$webvar{id}));
|
---|
[20] | 404 | # print some neato things?
|
---|
| 405 |
|
---|
| 406 | # } else {
|
---|
| 407 | # #whether actually deleting or cancelling we redirect to the group list, default format
|
---|
| 408 |
|
---|
| 409 | } elsif ($webvar{del} eq 'ok') {
|
---|
| 410 | my ($code,$msg) = delGroup($dbh, $webvar{id});
|
---|
[23] | 411 | push @debugbits, groupName($dbh, $webvar{id});
|
---|
[20] | 412 | if ($code ne 'OK') {
|
---|
| 413 | # need to find failure mode
|
---|
| 414 | $page->param(del_failed => 1);
|
---|
| 415 | $page->param(errmsg => $msg);
|
---|
[22] | 416 | $page->param(curpage => $webvar{page});
|
---|
| 417 | listgroups();
|
---|
[20] | 418 | } else {
|
---|
| 419 | # success. go back to the domain list, do not pass "GO"
|
---|
| 420 | changepage(page => "grpman");
|
---|
| 421 | }
|
---|
| 422 | } else {
|
---|
| 423 | # cancelled. whee!
|
---|
| 424 | changepage(page => "grpman");
|
---|
| 425 | }
|
---|
[23] | 426 | $page->param(delgroupname => groupName($dbh, $webvar{id}));
|
---|
[24] | 427 |
|
---|
| 428 | } elsif ($webvar{page} eq 'useradmin') {
|
---|
| 429 |
|
---|
| 430 | list_users();
|
---|
| 431 | $page->param(curpage => $webvar{page});
|
---|
| 432 |
|
---|
| 433 | } elsif ($webvar{page} eq 'newuser') {
|
---|
| 434 |
|
---|
| 435 | # foo?
|
---|
| 436 | fill_actypelist();
|
---|
| 437 |
|
---|
| 438 | } elsif ($webvar{page} eq 'adduser') {
|
---|
| 439 |
|
---|
| 440 | my ($code,$msg);
|
---|
| 441 |
|
---|
| 442 | if ($webvar{pass1} ne $webvar{pass2}) {
|
---|
| 443 | $code = 'FAIL';
|
---|
| 444 | $msg = "Passwords don't match";
|
---|
| 445 | } else {
|
---|
| 446 | ($code,$msg) = addUser($dbh,$webvar{username}, $webvar{group}, $webvar{pass1},
|
---|
[25] | 447 | ($webvar{makeactive} eq 'on' ? 1 : 0), $webvar{accttype},
|
---|
| 448 | $webvar{fname}, $webvar{lname}, $webvar{phone});
|
---|
[24] | 449 | }
|
---|
| 450 |
|
---|
| 451 | # hokay, a bit of magic to decide which page we hit.
|
---|
| 452 | if ($code eq 'OK') {
|
---|
| 453 | changepage(page => "useradmin");
|
---|
| 454 | } else {
|
---|
| 455 | # oooh, yeah, this is supposed to be a redirect. er, maybe. whee.
|
---|
| 456 | # $page = HTML::Template->new(filename => "$templatedir/newuser.tmpl");
|
---|
| 457 | $page->param(add_failed => 1);
|
---|
| 458 | $page->param(username => $webvar{username});
|
---|
| 459 | $page->param(fname => $webvar{fname});
|
---|
| 460 | $page->param(lname => $webvar{lname});
|
---|
| 461 | $page->param(pass1 => $webvar{pass1});
|
---|
| 462 | $page->param(pass2 => $webvar{pass2});
|
---|
| 463 | $page->param(errmsg => $msg);
|
---|
| 464 | fill_actypelist();
|
---|
| 465 | }
|
---|
| 466 |
|
---|
| 467 | $page->param(add_failed => 1);
|
---|
[25] | 468 |
|
---|
| 469 | } elsif ($webvar{page} eq 'deluser') {
|
---|
| 470 |
|
---|
| 471 | $page->param(id => $webvar{id});
|
---|
| 472 | # first pass = confirm y/n (sorta)
|
---|
| 473 | if (!defined($webvar{del})) {
|
---|
| 474 | $page->param(del_getconf => 1);
|
---|
| 475 | $page->param(user => userFullName($dbh,$webvar{id}));
|
---|
| 476 | } elsif ($webvar{del} eq 'ok') {
|
---|
| 477 | my ($code,$msg) = delUser($dbh, $webvar{id});
|
---|
| 478 | if ($code ne 'OK') {
|
---|
| 479 | # need to find failure mode
|
---|
| 480 | $page->param(del_failed => 1);
|
---|
| 481 | $page->param(errmsg => $msg);
|
---|
| 482 | list_users($curgroup);
|
---|
| 483 | } else {
|
---|
| 484 | # success. go back to the domain list, do not pass "GO"
|
---|
| 485 | changepage(page => "useradmin");
|
---|
| 486 | }
|
---|
| 487 | } else {
|
---|
| 488 | # cancelled. whee!
|
---|
| 489 | changepage(page => "useradmin");
|
---|
| 490 | }
|
---|
| 491 |
|
---|
[2] | 492 | }
|
---|
| 493 |
|
---|
| 494 |
|
---|
[17] | 495 | # start output here so we can redirect pages.
|
---|
[7] | 496 | print "Content-type: text/html\n\n", $header->output;
|
---|
| 497 |
|
---|
[20] | 498 | ##common bits
|
---|
[17] | 499 | if ($webvar{page} ne 'login') {
|
---|
[20] | 500 | $page->param(group => $curgroup);
|
---|
| 501 | $page->param(groupname => groupName($dbh,$curgroup));
|
---|
| 502 |
|
---|
[24] | 503 | # group tree. should go elsewhere, probably
|
---|
| 504 | my $tmpgrplist = fill_grptree($logingroup,$curgroup);
|
---|
| 505 | $page->param(grptree => $tmpgrplist);
|
---|
| 506 |
|
---|
[20] | 507 | # stuff for menu group change. nb: this is icky.
|
---|
| 508 | fill_grouplist("grouplist");
|
---|
| 509 | $page->param(whereami => $ENV{REQUEST_URI});
|
---|
[17] | 510 | }
|
---|
[13] | 511 |
|
---|
[24] | 512 | foreach (@debugbits) { print; }
|
---|
| 513 |
|
---|
[2] | 514 | # spit it out
|
---|
| 515 | print $page->output;
|
---|
| 516 |
|
---|
| 517 | print "<div id=debug>webvar keys: <pre>\n";
|
---|
| 518 | foreach my $key (keys %webvar) {
|
---|
| 519 | print "key: $key\tval: $webvar{$key}\n";
|
---|
| 520 | }
|
---|
[20] | 521 | print "</pre>\nsession:\n<pre>\n";
|
---|
| 522 | my $sesdata = $session->dataref();
|
---|
| 523 | foreach my $key (keys %$sesdata) {
|
---|
| 524 | print "key: $key\tval: ".$sesdata->{$key}."\n";
|
---|
| 525 | }
|
---|
[2] | 526 | print "</pre>\nENV:\n<pre>\n";
|
---|
| 527 | foreach my $key (keys %ENV) {
|
---|
| 528 | print "key: $key\tval: $ENV{$key}\n";
|
---|
| 529 | }
|
---|
| 530 | print "</pre></div>\n";
|
---|
| 531 |
|
---|
| 532 | print $footer->output;
|
---|
| 533 |
|
---|
[18] | 534 | # as per the docs, Just In Case
|
---|
| 535 | $session->flush();
|
---|
[2] | 536 |
|
---|
| 537 | exit 0;
|
---|
| 538 |
|
---|
| 539 |
|
---|
[24] | 540 | sub fill_grptree {
|
---|
| 541 | my $root = shift;
|
---|
| 542 | my $cur = shift;
|
---|
| 543 |
|
---|
| 544 | my @childlist;
|
---|
| 545 |
|
---|
| 546 | my $grptree = HTML::Template->new(filename => 'templates/grptree.tmpl');
|
---|
| 547 | getChildren($dbh,$root,\@childlist,'immediate');
|
---|
| 548 | return if $#childlist == -1;
|
---|
| 549 | my @grouplist;
|
---|
| 550 | foreach (@childlist) {
|
---|
| 551 | my %row;
|
---|
| 552 | $row{grpname} = groupName($dbh,$_);
|
---|
| 553 | $row{grpname} = "<b>$row{grpname}</b>" if $_ == $cur;
|
---|
| 554 | $row{subs} = fill_grptree($_,$cur);
|
---|
| 555 | push @grouplist, \%row;
|
---|
| 556 | }
|
---|
| 557 | $grptree->param(treelvl => \@grouplist);
|
---|
| 558 | return $grptree->output;
|
---|
| 559 | }
|
---|
| 560 |
|
---|
| 561 |
|
---|
[11] | 562 | sub changepage {
|
---|
| 563 | my %params = @_; # think this works the way I want...
|
---|
| 564 |
|
---|
| 565 | # handle user check
|
---|
| 566 | my $newurl = "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}?sid=$sid";
|
---|
| 567 | foreach (keys %params) {
|
---|
| 568 | $newurl .= "&$_=$params{$_}";
|
---|
| 569 | }
|
---|
| 570 |
|
---|
| 571 | print "Status: 302\nLocation: $newurl\n\n";
|
---|
| 572 | exit;
|
---|
| 573 | } # end changepage
|
---|
| 574 |
|
---|
| 575 |
|
---|
[2] | 576 | sub fillsoa {
|
---|
| 577 | my $def = shift;
|
---|
| 578 | my $id = shift;
|
---|
| 579 | my $domname;
|
---|
| 580 |
|
---|
| 581 | if ($webvar{domain} == 0) {
|
---|
| 582 | $domname = "DOMAIN";
|
---|
| 583 | } else {
|
---|
[17] | 584 | my $sth = $dbh->prepare("SELECT domain FROM domains WHERE domain_id=?");
|
---|
| 585 | $sth->execute($webvar{domain});
|
---|
[2] | 586 | ($domname) = $sth->fetchrow_array();
|
---|
| 587 | }
|
---|
| 588 |
|
---|
[17] | 589 | $page->param(domain => $domname);
|
---|
| 590 | $page->param(defrec => !$webvar{domain});
|
---|
| 591 | $page->param(group => $DNSDB::group);
|
---|
[2] | 592 |
|
---|
| 593 | # defaults
|
---|
[17] | 594 | $page->param(defcontact => $DNSDB::def{contact});
|
---|
| 595 | $page->param(defns => $DNSDB::def{prins});
|
---|
| 596 | $page->param(defsoattl => $DNSDB::def{soattl});
|
---|
| 597 | $page->param(defrefresh => $DNSDB::def{refresh});
|
---|
| 598 | $page->param(defretry => $DNSDB::def{retry});
|
---|
| 599 | $page->param(defexpire => $DNSDB::def{expire});
|
---|
| 600 | $page->param(defminttl => $DNSDB::def{minttl});
|
---|
[2] | 601 |
|
---|
| 602 | # there are probably better ways to do this. TMTOWTDI.
|
---|
| 603 | my %soa = getSOA($dbh,$def,$id);
|
---|
| 604 |
|
---|
| 605 | $page->param(domainid => $webvar{domain});
|
---|
| 606 | $page->param(recid => $soa{recid});
|
---|
| 607 | $page->param(prins => ($soa{prins} ? $soa{prins} : $DNSDB::def{prins}));
|
---|
| 608 | $page->param(contact => ($soa{contact} ? $soa{contact} : $DNSDB::def{contact}));
|
---|
| 609 | $page->param(refresh => ($soa{refresh} ? $soa{refresh} : $DNSDB::def{refresh}));
|
---|
| 610 | $page->param(retry => ($soa{retry} ? $soa{retry} : $DNSDB::def{retry}));
|
---|
| 611 | $page->param(expire => ($soa{expire} ? $soa{expire} : $DNSDB::def{expire}));
|
---|
| 612 | $page->param(minttl => ($soa{minttl} ? $soa{minttl} : $DNSDB::def{minttl}));
|
---|
| 613 | $page->param(ttl => ($soa{ttl} ? $soa{ttl} : $DNSDB::def{soattl}));
|
---|
| 614 | }
|
---|
| 615 |
|
---|
| 616 | sub showdomain {
|
---|
| 617 | my $def = shift;
|
---|
| 618 | my $id = shift;
|
---|
| 619 |
|
---|
| 620 | # get the SOA first
|
---|
| 621 | my %soa = getSOA($dbh,$def,$id);
|
---|
| 622 |
|
---|
| 623 | $page->param(recid => $soa{recid});
|
---|
| 624 | $page->param(contact => $soa{contact});
|
---|
| 625 | $page->param(prins => $soa{prins});
|
---|
| 626 | $page->param(refresh => $soa{refresh});
|
---|
| 627 | $page->param(retry => $soa{retry});
|
---|
| 628 | $page->param(expire => $soa{expire});
|
---|
| 629 | $page->param(minttl => $soa{minttl});
|
---|
| 630 | $page->param(ttl => $soa{ttl});
|
---|
| 631 |
|
---|
| 632 | # my @foo2 = getDomRecs($dbh,'def',1);
|
---|
[4] | 633 | my $foo2 = getDomRecs($dbh,$def,$id,$perpage,$webvar{offset});
|
---|
[2] | 634 |
|
---|
| 635 | my $row = 0;
|
---|
| 636 | foreach my $rec (@$foo2) {
|
---|
| 637 | $rec->{type} = $typemap{$rec->{type}};
|
---|
| 638 | $rec->{row} = $row % 2;
|
---|
| 639 | $rec->{defrec} = $webvar{defrec};
|
---|
| 640 | $rec->{sid} = $webvar{sid};
|
---|
[13] | 641 | $rec->{id} = $id;
|
---|
[23] | 642 | $rec->{distance} = 'n/a' unless ($rec->{type} eq 'MX' || $rec->{type} eq 'SRV');
|
---|
| 643 | $rec->{weight} = 'n/a' unless ($rec->{type} eq 'SRV');
|
---|
| 644 | $rec->{port} = 'n/a' unless ($rec->{type} eq 'SRV');
|
---|
[2] | 645 | $row++;
|
---|
| 646 | }
|
---|
| 647 | $page->param(reclist => $foo2);
|
---|
| 648 | }
|
---|
| 649 |
|
---|
[23] | 650 |
|
---|
[16] | 651 | # fill in record type list on add/update/edit record template
|
---|
| 652 | sub fill_rectypes {
|
---|
[13] | 653 | my $type = shift || $reverse_typemap{A};
|
---|
| 654 |
|
---|
[17] | 655 | my $sth = $dbh->prepare("SELECT val,name FROM rectypes WHERE stdflag=1 ORDER BY listorder");
|
---|
[2] | 656 | $sth->execute;
|
---|
| 657 | my @typelist;
|
---|
| 658 | while (my ($rval,$rname) = $sth->fetchrow_array()) {
|
---|
| 659 | my %row = ( recval => $rval, recname => $rname );
|
---|
[13] | 660 | $row{tselect} = 1 if $rval == $type;
|
---|
[2] | 661 | push @typelist, \%row;
|
---|
| 662 | }
|
---|
| 663 | $page->param(typelist => \@typelist);
|
---|
[16] | 664 | }
|
---|
| 665 |
|
---|
| 666 | sub fill_recdata {
|
---|
| 667 | fill_rectypes($webvar{type});
|
---|
| 668 |
|
---|
| 669 | $page->param(name => $webvar{name});
|
---|
| 670 | $page->param(address => $webvar{address});
|
---|
| 671 | $page->param(distance => $webvar{distance})
|
---|
| 672 | if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV});
|
---|
| 673 | $page->param(weight => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV};
|
---|
| 674 | $page->param(port => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV};
|
---|
[2] | 675 | $page->param(ttl => ($webvar{ttl} ? $webvar{ttl} : $DNSDB::def{minttl}));
|
---|
| 676 | }
|
---|
[7] | 677 |
|
---|
[24] | 678 |
|
---|
| 679 | sub fill_actypelist {
|
---|
| 680 | my @actypes;
|
---|
| 681 |
|
---|
| 682 | my %row1 = (actypeval => 'u', actypename => 'user');
|
---|
| 683 | $row1{typesel} = 1 if $webvar{accttype} eq 'u';
|
---|
| 684 | push @actypes, \%row1;
|
---|
| 685 |
|
---|
| 686 | my %row2 = (actypeval => 'S', actypename => 'superuser');
|
---|
| 687 | $row2{typesel} = 1 if $webvar{accttype} eq 'S';
|
---|
| 688 | push @actypes, \%row2;
|
---|
| 689 |
|
---|
| 690 | $page->param(actypelist => \@actypes);
|
---|
| 691 | }
|
---|
| 692 |
|
---|
| 693 |
|
---|
[7] | 694 | sub fill_fpnla {
|
---|
| 695 | my $count = shift;
|
---|
| 696 | ##fixme
|
---|
| 697 | if ($offset eq 'all') {
|
---|
[17] | 698 | push @debugbits, "foo! wanna see'em all\n";
|
---|
[7] | 699 | } else {
|
---|
| 700 | # all these bits only have sensible behaviour if offset is numeric. err, probably.
|
---|
| 701 | if ($count > $perpage) {
|
---|
| 702 | # if there are more results than the default, always show the "all" link
|
---|
| 703 | $page->param(navall => 1);
|
---|
| 704 |
|
---|
| 705 | if ($offset > 0) {
|
---|
| 706 | $page->param(navfirst => 1);
|
---|
| 707 | $page->param(navprev => 1);
|
---|
| 708 | $page->param(prevoffs => $offset-1);
|
---|
| 709 | }
|
---|
| 710 |
|
---|
| 711 | # show "next" and "last" links if we're not on the last page of results
|
---|
| 712 | if ( (($offset+1) * $perpage - $count) < 0 ) {
|
---|
| 713 | $page->param(navnext => 1);
|
---|
| 714 | $page->param(nextoffs => $offset+1);
|
---|
| 715 | $page->param(navlast => 1);
|
---|
[8] | 716 | $page->param(lastoffs => int (($count-1)/$perpage));
|
---|
[7] | 717 | }
|
---|
| 718 | }
|
---|
| 719 | }
|
---|
[10] | 720 | } # end fill_fpnla()
|
---|
| 721 |
|
---|
| 722 |
|
---|
[12] | 723 | sub fill_pgcount {
|
---|
| 724 | my $pgcount = shift;
|
---|
| 725 | my $pgtype = shift;
|
---|
| 726 | my $parent = shift;
|
---|
| 727 |
|
---|
| 728 | $page->param(ntot => $pgcount);
|
---|
| 729 | $page->param(nfirst => (($offset eq 'all' ? 0 : $offset)*$perpage+1));
|
---|
| 730 | $page->param(npglast => ($offset eq 'all' ? $pgcount :
|
---|
| 731 | ( (($offset+1)*$perpage) > $pgcount ? $pgcount : (($offset+1)*$perpage) )
|
---|
| 732 | ));
|
---|
| 733 | $page->param(pgtype => $pgtype);
|
---|
| 734 | $page->param(parent => $parent);
|
---|
| 735 | } # end fill_pgcount()
|
---|
| 736 |
|
---|
| 737 |
|
---|
[11] | 738 | sub listdomains {
|
---|
[17] | 739 | my $sth = $dbh->prepare("SELECT count(*) FROM domains WHERE group_id=?");
|
---|
[20] | 740 | $sth->execute($curgroup);
|
---|
[17] | 741 | my ($count) = $sth->fetchrow_array;
|
---|
| 742 |
|
---|
[12] | 743 | # fill page count and first-previous-next-last-all bits
|
---|
| 744 | ##fixme - hardcoded group bit
|
---|
[20] | 745 | fill_pgcount($count,"domains",groupName($dbh,$curgroup));
|
---|
[10] | 746 | fill_fpnla($count);
|
---|
| 747 |
|
---|
| 748 | ##fixme - group
|
---|
[20] | 749 | $page->param(group => $curgroup);
|
---|
[10] | 750 | my @domlist;
|
---|
[20] | 751 | $sth = $dbh->prepare("SELECT domain_id,domain,status,groups.group_name FROM domains".
|
---|
| 752 | " INNER JOIN groups ON domains.group_id=groups.group_id".
|
---|
| 753 | " WHERE domains.group_id=?".
|
---|
| 754 | " ORDER BY domain".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage));
|
---|
| 755 | $sth->execute($curgroup);
|
---|
[10] | 756 | my $rownum = 0;
|
---|
| 757 | while (my @data = $sth->fetchrow_array) {
|
---|
| 758 | my %row;
|
---|
| 759 | $row{domainid} = $data[0];
|
---|
| 760 | $row{domain} = $data[1];
|
---|
| 761 | $row{status} = ($data[2] ? 'Active' : 'Inactive');
|
---|
| 762 | $row{group} = $data[3];
|
---|
| 763 | $row{bg} = ($rownum++)%2;
|
---|
| 764 | # $row{mkactive} = ($data[2] eq 'inactive' ? 1 : 0);
|
---|
| 765 | $row{mkactive} = !$data[2];
|
---|
| 766 | $row{sid} = $sid;
|
---|
| 767 | $row{offset} = $offset;
|
---|
| 768 | ##fixme: need to clean up status indicator/usage/inversion
|
---|
| 769 | push @domlist, \%row;
|
---|
| 770 | }
|
---|
| 771 | $page->param(domtable => \@domlist);
|
---|
[11] | 772 | } # end listdomains()
|
---|
[18] | 773 |
|
---|
| 774 |
|
---|
[22] | 775 | sub listgroups {
|
---|
| 776 | my $sth = $dbh->prepare("select count(*) from groups");
|
---|
| 777 | $sth->execute;
|
---|
| 778 | my ($count) = ($sth->fetchrow_array);
|
---|
| 779 |
|
---|
| 780 | # fill page count and first-previous-next-last-all bits
|
---|
| 781 | ##fixme - hardcoded group bit
|
---|
| 782 | fill_pgcount($count,"groups",'');
|
---|
| 783 | fill_fpnla($count);
|
---|
| 784 |
|
---|
| 785 | my @grouplist;
|
---|
| 786 | $sth = $dbh->prepare("SELECT g.group_id, g.group_name, g2.group_name, ".
|
---|
| 787 | "count(distinct(u.email)), count(distinct(d.domain)) ".
|
---|
| 788 | "FROM groups g ".
|
---|
| 789 | "INNER JOIN groups g2 ON g2.group_id=g.parent_group_id ".
|
---|
| 790 | "LEFT OUTER JOIN users u ON u.group_id=g.group_id ".
|
---|
| 791 | "LEFT OUTER JOIN domains d ON d.group_id=g.group_id ".
|
---|
| 792 | "GROUP BY g.group_id, g.group_name, g2.group_name ".
|
---|
| 793 | "ORDER BY g.group_id".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage));
|
---|
| 794 | $sth->execute;
|
---|
| 795 |
|
---|
| 796 | my $rownum = 0;
|
---|
| 797 | while (my @data = $sth->fetchrow_array) {
|
---|
| 798 | my %row;
|
---|
| 799 | $row{groupid} = $data[0];
|
---|
| 800 | $row{groupname} = $data[1];
|
---|
| 801 | $row{pgroup} = $data[2];
|
---|
| 802 | $row{nusers} = $data[3];
|
---|
| 803 | $row{ndomains} = $data[4];
|
---|
| 804 | $row{bg} = ($rownum++)%2;
|
---|
| 805 | $row{sid} = $sid;
|
---|
| 806 | push @grouplist, \%row;
|
---|
| 807 | }
|
---|
| 808 | $page->param(grouptable => \@grouplist);
|
---|
| 809 | } # end listgroups()
|
---|
| 810 |
|
---|
| 811 |
|
---|
[20] | 812 | sub fill_grouplist {
|
---|
[19] | 813 | my $template_var = shift;
|
---|
| 814 | my $cur = shift || $curgroup;
|
---|
[18] | 815 | # weesa gonna discard parent_group_id for now
|
---|
| 816 | my $sth = $dbh->prepare("SELECT group_id,parent_group_id,group_name FROM groups ORDER BY group_id");
|
---|
| 817 | $sth->execute;
|
---|
[20] | 818 | my @grouplist;
|
---|
| 819 | while (my ($groupid,$pargroup,$groupname) = $sth->fetchrow_array()) {
|
---|
[18] | 820 | my %row;
|
---|
[20] | 821 | $row{groupname} = $groupname;
|
---|
| 822 | $row{groupval} = $groupid;
|
---|
[18] | 823 | ##fixme: need magic
|
---|
[20] | 824 | # $row{defgroup} = '';
|
---|
| 825 | $row{groupactive} = 1 if $groupid == $cur;
|
---|
| 826 | push @grouplist, \%row;
|
---|
[18] | 827 | }
|
---|
| 828 |
|
---|
[20] | 829 | $page->param("$template_var" => \@grouplist);
|
---|
[18] | 830 |
|
---|
[24] | 831 | } # end fill_grouplist()
|
---|
| 832 |
|
---|
| 833 | sub list_users {
|
---|
| 834 | my $sth = $dbh->prepare("select count(*) from users where group_id=?");
|
---|
| 835 | $sth->execute($curgroup);
|
---|
| 836 | my ($count) = ($sth->fetchrow_array);
|
---|
| 837 |
|
---|
| 838 | # fill page count and first-previous-next-last-all bits
|
---|
| 839 | ##fixme - hardcoded group bit
|
---|
| 840 | fill_pgcount($count,"users",'');
|
---|
| 841 | fill_fpnla($count);
|
---|
| 842 |
|
---|
| 843 | my @userlist;
|
---|
[25] | 844 | $sth = $dbh->prepare("SELECT u.user_id, u.username, u.firstname, u.lastname, u.type, g.group_name, u.status ".
|
---|
[24] | 845 | "FROM users u ".
|
---|
| 846 | "INNER JOIN groups g ON u.group_id=g.group_id ".
|
---|
| 847 | "WHERE u.group_id=?".
|
---|
| 848 | ($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage));
|
---|
| 849 | $sth->execute($curgroup);
|
---|
| 850 |
|
---|
| 851 | my $rownum = 0;
|
---|
| 852 | while (my @data = $sth->fetchrow_array) {
|
---|
| 853 | my %row;
|
---|
| 854 | $row{userid} = $data[0];
|
---|
| 855 | $row{username} = $data[1];
|
---|
| 856 | $row{userfull} = "$data[2] $data[3]";
|
---|
| 857 | $row{usertype} = ($data[4] eq 'S' ? 'superuser' : "user");
|
---|
| 858 | $row{usergroup} = $data[5];
|
---|
| 859 | $row{mkactive} = $data[6];
|
---|
| 860 | $row{bg} = ($rownum++)%2;
|
---|
| 861 | $row{sid} = $sid;
|
---|
| 862 | push @userlist, \%row;
|
---|
| 863 | }
|
---|
| 864 | $page->param(usertable => \@userlist);
|
---|
[18] | 865 | }
|
---|