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