1 | #!/usr/bin/perl -w -T
|
---|
2 | # dns/cgi-bin/dns.cgi
|
---|
3 | ###
|
---|
4 | # SVN revision info
|
---|
5 | # $Date: 2009-09-15 12:51:42 +0000 (Tue, 15 Sep 2009) $
|
---|
6 | # SVN revision $Rev: 15 $
|
---|
7 | # Last update by $Author: kdeugau $
|
---|
8 | ###
|
---|
9 | # Copyright (C) 2008,2009 - Kris Deugau <kdeugau@deepnet.cx>
|
---|
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 |
|
---|
24 | my @debugbits; # temp, to be spit out near the end of processing
|
---|
25 |
|
---|
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...
|
---|
36 | my %webvar = $q->Vars;
|
---|
37 |
|
---|
38 | # persistent stuff needed on most/all pages
|
---|
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.
|
---|
47 | $session->param('logingroupid',1);
|
---|
48 | $session->param('workinggroupid',1); # yes, we *do* need to track this too. er, probably.
|
---|
49 | }
|
---|
50 |
|
---|
51 | my $group = ($webvar{grp} ? $webvar{grp} : 1);
|
---|
52 | # handle login redirect
|
---|
53 | if ($webvar{action} && $webvar{action} eq 'login') {
|
---|
54 | ##fixme: need to actually do a user/pass check
|
---|
55 | changepage(page => "domlist");
|
---|
56 | }
|
---|
57 |
|
---|
58 | my $header = HTML::Template->new(filename => "$templatedir/header.tmpl");
|
---|
59 | my $footer = HTML::Template->new(filename => "$templatedir/footer.tmpl");
|
---|
60 |
|
---|
61 | # default
|
---|
62 | #my $perpage = 15;
|
---|
63 | my $perpage = 3;
|
---|
64 | my $offset = ($webvar{offset} ? $webvar{offset} : 0);
|
---|
65 |
|
---|
66 | # NB: these must match the field name and SQL ascend/descend syntax respectively
|
---|
67 | my $sortfield = "domains";
|
---|
68 | my $sortorder = "asc";
|
---|
69 |
|
---|
70 | my ($dbh,$msg) = connectDB("dnsdb","dnsdb","secret");
|
---|
71 | #my $dbh = DBI->connect("DBI:mysql:database=vegadns","vegadns","secret",
|
---|
72 | # { AutoCommit => 0 }) or die $DBI::errstr;
|
---|
73 |
|
---|
74 | ##fixme. PLEASE! <G>
|
---|
75 | print $msg if !$dbh;
|
---|
76 |
|
---|
77 | # fiddle hardcoded "defaults" as per system/user (?) prefs
|
---|
78 | initGlobals($dbh);
|
---|
79 |
|
---|
80 | ## Default page is a login page
|
---|
81 | #my $page; # to be initialized as an HTML::Template entity sooner or later
|
---|
82 |
|
---|
83 |
|
---|
84 |
|
---|
85 | # decide which page to spit out...
|
---|
86 | $webvar{page} = 'login' if !$webvar{page};
|
---|
87 | #if (!$webvar{page}) {
|
---|
88 | # $page = HTML::Template->new(filename => "$templatedir/login.tmpl");
|
---|
89 | #} else {
|
---|
90 | #}
|
---|
91 |
|
---|
92 | my $page = HTML::Template->new(filename => "$templatedir/$webvar{page}.tmpl");
|
---|
93 |
|
---|
94 | $page->param(sid => $sid);
|
---|
95 |
|
---|
96 | if ($webvar{page} eq 'domlist' or $webvar{page} eq 'index') {
|
---|
97 |
|
---|
98 | # hmm. seeing problems in some possibly-not-so-corner cases.
|
---|
99 | # this currently only handles "domain on", "domain off"
|
---|
100 | if (defined($webvar{action})) {
|
---|
101 | domStatus($dbh,$webvar{id},$webvar{action});
|
---|
102 | }
|
---|
103 |
|
---|
104 | listdomains();
|
---|
105 |
|
---|
106 | } elsif ($webvar{page} eq 'reclist') {
|
---|
107 |
|
---|
108 | # Handle record list for both default records (per-group) and live domain records
|
---|
109 |
|
---|
110 | $page->param(defrec => $webvar{defrec});
|
---|
111 | $page->param(id => $webvar{id});
|
---|
112 | $page->param(curpage => 'reclist');
|
---|
113 |
|
---|
114 | # select count(*) from (default_)?records where (group|domain)_id=?
|
---|
115 | my $sth = $dbh->prepare("SELECT count(*) FROM ".
|
---|
116 | ($webvar{defrec} eq 'y' ? 'default_' : '')."records ".
|
---|
117 | "WHERE ".($webvar{defrec} eq 'y' ? 'group' : 'domain')."_id=? ".
|
---|
118 | "AND NOT type=$reverse_typemap{SOA}");
|
---|
119 | $sth->execute($webvar{id});
|
---|
120 | my ($count) = ($sth->fetchrow_array);
|
---|
121 |
|
---|
122 | # fill the page-count and first-previous-next-last-all details
|
---|
123 | fill_pgcount($count,"records",domainName($dbh,$webvar{id}));
|
---|
124 | fill_fpnla($count); # should put some params on this sub...
|
---|
125 |
|
---|
126 | $page->param(defrec => $webvar{defrec});
|
---|
127 | if ($webvar{defrec} eq 'y') {
|
---|
128 | ##fixme: hardcoded group
|
---|
129 | showdomain('y',1);
|
---|
130 | } else {
|
---|
131 | showdomain('n',$webvar{id});
|
---|
132 | }
|
---|
133 |
|
---|
134 | } elsif ($webvar{page} eq 'newdomain') {
|
---|
135 |
|
---|
136 | # weesa gonna discard parent_group_id for now
|
---|
137 | my $sth = $dbh->prepare("select group_id,parent_group_id,name from groups order by group_id");
|
---|
138 | $sth->execute;
|
---|
139 | my @grplist;
|
---|
140 | while (my ($grpid,$pargrp,$grpname) = $sth->fetchrow_array()) {
|
---|
141 | my %row;
|
---|
142 | $row{grpname} = $grpname;
|
---|
143 | $row{grpval} = $grpid;
|
---|
144 | ##fixme: need magic
|
---|
145 | # $row{defgrp} = '';
|
---|
146 | push @grplist, \%row;
|
---|
147 | }
|
---|
148 |
|
---|
149 | $page->param(grplist => \@grplist);
|
---|
150 |
|
---|
151 | } elsif ($webvar{page} eq 'deldom') {
|
---|
152 |
|
---|
153 | $page->param(id => $webvar{id});
|
---|
154 | # first pass = confirm y/n (sorta)
|
---|
155 | if (!defined($webvar{del})) {
|
---|
156 | $page->param(del_getconf => 1);
|
---|
157 | $page->param(domain => domainName($dbh,$webvar{id}));
|
---|
158 | # print some neato things?
|
---|
159 |
|
---|
160 | # } else {
|
---|
161 | # #whether actually deleting or cancelling we redirect to the domain list, default format
|
---|
162 |
|
---|
163 | } elsif ($webvar{del} eq 'ok') {
|
---|
164 | my ($code,$msg) = delDomain($dbh, $webvar{id});
|
---|
165 | if ($code ne 'OK') {
|
---|
166 | # need to find failure mode
|
---|
167 | $page->param(del_failed => 1);
|
---|
168 | $page->param(errmsg => $msg);
|
---|
169 | } else {
|
---|
170 | # success. go back to the domain list, do not pass "GO"
|
---|
171 | changepage(page => "domlist");
|
---|
172 | }
|
---|
173 | } else {
|
---|
174 | # cancelled. whee!
|
---|
175 | changepage(page => "domlist");
|
---|
176 | }
|
---|
177 |
|
---|
178 | } elsif ($webvar{page} eq 'record') {
|
---|
179 | if ($webvar{recact} eq 'new') {
|
---|
180 | $page->param(todo => "Add record to");
|
---|
181 | $page->param(recact => "add");
|
---|
182 | stdrecs();
|
---|
183 | } elsif ($webvar{recact} eq 'add') {
|
---|
184 |
|
---|
185 | my @recargs = ($dbh,$webvar{defrec},$webvar{parentid},$webvar{name},$webvar{type},$webvar{address},$webvar{ttl});
|
---|
186 | if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}) {
|
---|
187 | push @recargs, $webvar{distance};
|
---|
188 | if ($webvar{type} == $reverse_typemap{SRV}) {
|
---|
189 | push @recargs, $webvar{weight};
|
---|
190 | push @recargs, $webvar{port};
|
---|
191 | }
|
---|
192 | }
|
---|
193 | # wtf?
|
---|
194 | # push @recargs,
|
---|
195 | my ($code,$msg) = addRec(@recargs);
|
---|
196 |
|
---|
197 | if ($code eq 'OK') {
|
---|
198 | changepage(page => "reclist", id => $webvar{parentid}, defrec => $webvar{defrec});
|
---|
199 | # showdomain($webvar{defrec},$webvar{parentid});
|
---|
200 | # NB: should **really** redirect here, in case of reload. >_< eyowch.
|
---|
201 | } else {
|
---|
202 | $page->param(add_failed => 1);
|
---|
203 | $page->param(errmsg => $msg);
|
---|
204 | stdrecs($webvar{type}); # populate the form... er, mostly.
|
---|
205 | $page->param(name => $webvar{name});
|
---|
206 | $page->param(address => $webvar{address});
|
---|
207 | $page->param(distance => $webvar{distance})
|
---|
208 | if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV});
|
---|
209 | $page->param(weight => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV};
|
---|
210 | $page->param(port => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV};
|
---|
211 | }
|
---|
212 |
|
---|
213 | $page->param(defrec => $webvar{defrec});
|
---|
214 |
|
---|
215 | } elsif ($webvar{recact} eq 'edit') {
|
---|
216 |
|
---|
217 | $page->param(todo => "Edit record in");
|
---|
218 | my $sth = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM ".
|
---|
219 | ($webvar{defrec} eq 'y' ? 'default_' : '')."records WHERE record_id=?");
|
---|
220 | $sth->execute($webvar{id});
|
---|
221 | my ($host,$type,$val,$distance,$weight,$port,$ttl) = $sth->fetchrow_array;
|
---|
222 | $page->param(name => $host);
|
---|
223 | $page->param(address => $val);
|
---|
224 | $page->param(distance => $distance);
|
---|
225 | $page->param(weight => $weight);
|
---|
226 | $page->param(port => $port);
|
---|
227 | $page->param(ttl => $ttl);
|
---|
228 | stdrecs($type);
|
---|
229 | }
|
---|
230 | if ($webvar{defrec} eq 'y') {
|
---|
231 | $page->param(domain => "group ".grpName($dbh,$webvar{parentid}));
|
---|
232 | } else {
|
---|
233 | $page->param(domain => domainName($dbh,$webvar{parentid}));
|
---|
234 | }
|
---|
235 |
|
---|
236 | } elsif ($webvar{page} eq 'newrec') {
|
---|
237 | push @debugbits, "whee!\n";
|
---|
238 |
|
---|
239 | # populate most fields as needed. (eg, type list.)
|
---|
240 | stdrecs();
|
---|
241 |
|
---|
242 | } elsif ($webvar{page} eq 'addrec') {
|
---|
243 |
|
---|
244 | my @recargs = ($dbh,$webvar{defrec},$webvar{parentid},$webvar{name},$webvar{type},$webvar{address},$webvar{ttl});
|
---|
245 | if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV}) {
|
---|
246 | push @recargs, $webvar{distance};
|
---|
247 | if ($webvar{type} == $reverse_typemap{SRV}) {
|
---|
248 | push @recargs, $webvar{weight};
|
---|
249 | push @recargs, $webvar{port};
|
---|
250 | }
|
---|
251 | }
|
---|
252 | # wtf?
|
---|
253 | # push @recargs,
|
---|
254 | my ($code,$msg) = addRec(@recargs);
|
---|
255 |
|
---|
256 | if ($code eq 'OK') {
|
---|
257 | showdomain($webvar{defrec},$webvar{parentid});
|
---|
258 | # NB: should **really** redirect here, in case of reload. >_< eyowch.
|
---|
259 | } else {
|
---|
260 | $page->param(add_failed => 1);
|
---|
261 | $page->param(errmsg => $msg);
|
---|
262 | stdrecs($webvar{type}); # populate the form... er, mostly.
|
---|
263 | $page->param(name => $webvar{name});
|
---|
264 | $page->param(address => $webvar{address});
|
---|
265 | $page->param(distance => $webvar{distance})
|
---|
266 | if ($webvar{type} == $reverse_typemap{MX} or $webvar{type} == $reverse_typemap{SRV});
|
---|
267 | $page->param(weight => $webvar{weight}) if $webvar{type} == $reverse_typemap{SRV};
|
---|
268 | $page->param(port => $webvar{port}) if $webvar{type} == $reverse_typemap{SRV};
|
---|
269 | }
|
---|
270 |
|
---|
271 | $page->param(defrec => $webvar{defrec});
|
---|
272 |
|
---|
273 | } elsif ($webvar{page} eq 'conf_del') {
|
---|
274 |
|
---|
275 | $page->param(id => $webvar{id});
|
---|
276 | $page->param(defrec => $webvar{defrec});
|
---|
277 |
|
---|
278 | my @tmp = getrecdata($dbh,$webvar{id},$webvar{defrec});
|
---|
279 |
|
---|
280 | } elsif ($webvar{page} eq 'delrec') {
|
---|
281 |
|
---|
282 | $page->param(id => $webvar{id});
|
---|
283 | $page->param(defrec => $webvar{defrec});
|
---|
284 | # first pass = confirm y/n (sorta)
|
---|
285 | if (!defined($webvar{del})) {
|
---|
286 | $page->param(del_getconf => 1);
|
---|
287 | my %rec = getRecLine($dbh,$webvar{defrec},$webvar{id});
|
---|
288 | $page->param(host => $rec{host});
|
---|
289 | $page->param(ftype => $typemap{$rec{type}});
|
---|
290 | $page->param(recval => $rec{val});
|
---|
291 | } else {
|
---|
292 | my ($code,$msg) = delRec($dbh,$webvar{defrec},$webvar{id});
|
---|
293 | if ($code ne 'OK') {
|
---|
294 | ## need to find failure mode
|
---|
295 | $page->param(del_failed => 1);
|
---|
296 | $page->param(errmsg => $msg);
|
---|
297 | }
|
---|
298 | ##fixme: group/parent instead of hardcoded 1
|
---|
299 | showdomain('y',1);
|
---|
300 | }
|
---|
301 |
|
---|
302 | } elsif ($webvar{page} eq 'editsoa') {
|
---|
303 |
|
---|
304 | fillsoa($webvar{defrec},$webvar{recid});
|
---|
305 |
|
---|
306 | } elsif ($webvar{page} eq 'updatesoa') {
|
---|
307 | print "ooooo!\n";
|
---|
308 |
|
---|
309 | my $sth;
|
---|
310 | my $sql = '';
|
---|
311 | # no domain ID, so we're editing the default SOA for a group (we don't care which one here)
|
---|
312 | # plus a bit of magic to update the appropriate table
|
---|
313 | $sql = "update ".($webvar{domainid} eq '' ? "default_records" : "records").
|
---|
314 | " set host='$webvar{prins}:$webvar{contact}',".
|
---|
315 | " val='$webvar{refresh}:$webvar{retry}:$webvar{expire}:$webvar{minttl}',".
|
---|
316 | " ttl=$webvar{ttl} where record_id=$webvar{recid}";
|
---|
317 | $sth = $dbh->prepare($sql);
|
---|
318 | $sth->execute;
|
---|
319 |
|
---|
320 | if ($sth->err) {
|
---|
321 | $page->param(update_failed => 1);
|
---|
322 | $page->param(msg => $DBI::errstr);
|
---|
323 | fillsoa($webvar{defrec},1);
|
---|
324 | } else {
|
---|
325 | $page->param(update_failed => 0);
|
---|
326 | ##fixme! need to set group ID properly here
|
---|
327 | showdomain('y',1);
|
---|
328 | }
|
---|
329 |
|
---|
330 | } elsif ($webvar{page} eq 'adddomain') {
|
---|
331 | # Need some magic here.
|
---|
332 |
|
---|
333 | ##fixme: Group should be variable
|
---|
334 | my ($code,$msg) = addDomain($dbh,$webvar{domain},1,($webvar{makeactive} eq 'on' ? 1 : 0));
|
---|
335 |
|
---|
336 | # hokay, a bit of magic to decide which page we hit.
|
---|
337 | if ($code eq 'OK') {
|
---|
338 | # redirect to dns.cgi?etc&page=reclist
|
---|
339 | changepage(page => "reclist", id => $msg);
|
---|
340 | $page = HTML::Template->new(filename => "$templatedir/reclist.tmpl");
|
---|
341 | showdomain(0,$msg);
|
---|
342 | ##work
|
---|
343 | } else {
|
---|
344 | # oooh, yeah, this is supposed to be a redirect. er, maybe. whee.
|
---|
345 | $page = HTML::Template->new(filename => "$templatedir/newdomain.tmpl");
|
---|
346 | $page->param(add_failed => 1);
|
---|
347 | $page->param(domain => $webvar{domain});
|
---|
348 | $page->param(errmsg => $msg);
|
---|
349 | }
|
---|
350 |
|
---|
351 |
|
---|
352 | }
|
---|
353 |
|
---|
354 |
|
---|
355 | ## hmm. may want to move this so we can redirect after adding/deleting/etc
|
---|
356 | print "Content-type: text/html\n\n", $header->output;
|
---|
357 |
|
---|
358 | foreach (@debugbits) { print; }
|
---|
359 |
|
---|
360 | $page->param(grp => $group) if $webvar{page} ne 'login';
|
---|
361 |
|
---|
362 | # spit it out
|
---|
363 | print $page->output;
|
---|
364 |
|
---|
365 | print "<div id=debug>webvar keys: <pre>\n";
|
---|
366 | foreach my $key (keys %webvar) {
|
---|
367 | print "key: $key\tval: $webvar{$key}\n";
|
---|
368 | }
|
---|
369 | print "</pre>\nENV:\n<pre>\n";
|
---|
370 | foreach my $key (keys %ENV) {
|
---|
371 | print "key: $key\tval: $ENV{$key}\n";
|
---|
372 | }
|
---|
373 | print "</pre></div>\n";
|
---|
374 |
|
---|
375 | print $footer->output;
|
---|
376 |
|
---|
377 |
|
---|
378 | exit 0;
|
---|
379 |
|
---|
380 |
|
---|
381 | sub changepage {
|
---|
382 | my %params = @_; # think this works the way I want...
|
---|
383 |
|
---|
384 | # handle user check
|
---|
385 | my $newurl = "http://$ENV{HTTP_HOST}$ENV{SCRIPT_NAME}?sid=$sid";
|
---|
386 | foreach (keys %params) {
|
---|
387 | $newurl .= "&$_=$params{$_}";
|
---|
388 | }
|
---|
389 |
|
---|
390 | print "Status: 302\nLocation: $newurl\n\n";
|
---|
391 | exit;
|
---|
392 | } # end changepage
|
---|
393 |
|
---|
394 |
|
---|
395 | sub fillsoa {
|
---|
396 | my $def = shift;
|
---|
397 | my $id = shift;
|
---|
398 | my $domname;
|
---|
399 |
|
---|
400 | if ($webvar{domain} == 0) {
|
---|
401 | $domname = "DOMAIN";
|
---|
402 | } else {
|
---|
403 | my $sth = $dbh->prepare("select domain from domains where domain_id=$webvar{domain}");
|
---|
404 | $sth->execute();
|
---|
405 | ($domname) = $sth->fetchrow_array();
|
---|
406 | }
|
---|
407 |
|
---|
408 | $page->param(domain => $domname);
|
---|
409 | $page->param(defrec => !$webvar{domain});
|
---|
410 | $page->param(group => $DNSDB::group);
|
---|
411 |
|
---|
412 | # defaults
|
---|
413 | $page->param(defcontact => $DNSDB::def{contact});
|
---|
414 | $page->param(defns => $DNSDB::def{prins});
|
---|
415 | $page->param(defsoattl => $DNSDB::def{soattl});
|
---|
416 | $page->param(defrefresh => $DNSDB::def{refresh});
|
---|
417 | $page->param(defretry => $DNSDB::def{retry});
|
---|
418 | $page->param(defexpire => $DNSDB::def{expire});
|
---|
419 | $page->param(defminttl => $DNSDB::def{minttl});
|
---|
420 |
|
---|
421 | # there are probably better ways to do this. TMTOWTDI.
|
---|
422 | my %soa = getSOA($dbh,$def,$id);
|
---|
423 |
|
---|
424 | $page->param(domainid => $webvar{domain});
|
---|
425 | $page->param(recid => $soa{recid});
|
---|
426 | $page->param(prins => ($soa{prins} ? $soa{prins} : $DNSDB::def{prins}));
|
---|
427 | $page->param(contact => ($soa{contact} ? $soa{contact} : $DNSDB::def{contact}));
|
---|
428 | $page->param(refresh => ($soa{refresh} ? $soa{refresh} : $DNSDB::def{refresh}));
|
---|
429 | $page->param(retry => ($soa{retry} ? $soa{retry} : $DNSDB::def{retry}));
|
---|
430 | $page->param(expire => ($soa{expire} ? $soa{expire} : $DNSDB::def{expire}));
|
---|
431 | $page->param(minttl => ($soa{minttl} ? $soa{minttl} : $DNSDB::def{minttl}));
|
---|
432 | $page->param(ttl => ($soa{ttl} ? $soa{ttl} : $DNSDB::def{soattl}));
|
---|
433 | }
|
---|
434 |
|
---|
435 | sub showdomain {
|
---|
436 | my $def = shift;
|
---|
437 | my $id = shift;
|
---|
438 |
|
---|
439 | # get the SOA first
|
---|
440 | my %soa = getSOA($dbh,$def,$id);
|
---|
441 |
|
---|
442 | $page->param(recid => $soa{recid});
|
---|
443 | $page->param(contact => $soa{contact});
|
---|
444 | $page->param(prins => $soa{prins});
|
---|
445 | $page->param(refresh => $soa{refresh});
|
---|
446 | $page->param(retry => $soa{retry});
|
---|
447 | $page->param(expire => $soa{expire});
|
---|
448 | $page->param(minttl => $soa{minttl});
|
---|
449 | $page->param(ttl => $soa{ttl});
|
---|
450 |
|
---|
451 | # my @foo2 = getDomRecs($dbh,'def',1);
|
---|
452 | my $foo2 = getDomRecs($dbh,$def,$id,$perpage,$webvar{offset});
|
---|
453 |
|
---|
454 | my $row = 0;
|
---|
455 | foreach my $rec (@$foo2) {
|
---|
456 | $rec->{type} = $typemap{$rec->{type}};
|
---|
457 | $rec->{row} = $row % 2;
|
---|
458 | $rec->{defrec} = $webvar{defrec};
|
---|
459 | $rec->{sid} = $webvar{sid};
|
---|
460 | $rec->{id} = $id;
|
---|
461 | $row++;
|
---|
462 | }
|
---|
463 | $page->param(reclist => $foo2);
|
---|
464 | }
|
---|
465 |
|
---|
466 | sub stdrecs {
|
---|
467 | my $type = shift || $reverse_typemap{A};
|
---|
468 |
|
---|
469 | my $sth = $dbh->prepare("select val,name from rectypes where stdflag=1 order by listorder");
|
---|
470 | $sth->execute;
|
---|
471 |
|
---|
472 | push @debugbits, "DEBUG: type $type\n";
|
---|
473 | my @typelist;
|
---|
474 | while (my ($rval,$rname) = $sth->fetchrow_array()) {
|
---|
475 | my %row = ( recval => $rval, recname => $rname );
|
---|
476 | $row{tselect} = 1 if $rval == $type;
|
---|
477 | push @typelist, \%row;
|
---|
478 | }
|
---|
479 | $page->param(typelist => \@typelist);
|
---|
480 | $page->param(domain => domainName($dbh,$webvar{domainid}));
|
---|
481 | $page->param(defrec => $webvar{defrec});
|
---|
482 | $page->param(ttl => ($webvar{ttl} ? $webvar{ttl} : $DNSDB::def{minttl}));
|
---|
483 | if ($webvar{defrec} eq 'y') {
|
---|
484 | ##fixme - should be groupid
|
---|
485 | $page->param(parentid => 1);
|
---|
486 | } else {
|
---|
487 | print "DEBUG: foobar: parentid $webvar{parentid}<br>\n";
|
---|
488 | $page->param(parentid => $webvar{parentid});
|
---|
489 | }
|
---|
490 | }
|
---|
491 |
|
---|
492 | sub fill_fpnla {
|
---|
493 | my $count = shift;
|
---|
494 | ##fixme
|
---|
495 | if ($offset eq 'all') {
|
---|
496 | #print "foo! wanna see'em all\n";
|
---|
497 | } else {
|
---|
498 | # all these bits only have sensible behaviour if offset is numeric. err, probably.
|
---|
499 | if ($count > $perpage) {
|
---|
500 | # if there are more results than the default, always show the "all" link
|
---|
501 | $page->param(navall => 1);
|
---|
502 |
|
---|
503 | if ($offset > 0) {
|
---|
504 | $page->param(navfirst => 1);
|
---|
505 | $page->param(navprev => 1);
|
---|
506 | $page->param(prevoffs => $offset-1);
|
---|
507 | }
|
---|
508 |
|
---|
509 | # show "next" and "last" links if we're not on the last page of results
|
---|
510 | if ( (($offset+1) * $perpage - $count) < 0 ) {
|
---|
511 | $page->param(navnext => 1);
|
---|
512 | $page->param(nextoffs => $offset+1);
|
---|
513 | $page->param(navlast => 1);
|
---|
514 | $page->param(lastoffs => int (($count-1)/$perpage));
|
---|
515 | }
|
---|
516 | }
|
---|
517 | }
|
---|
518 | } # end fill_fpnla()
|
---|
519 |
|
---|
520 |
|
---|
521 | sub fill_pgcount {
|
---|
522 | my $pgcount = shift;
|
---|
523 | my $pgtype = shift;
|
---|
524 | my $parent = shift;
|
---|
525 |
|
---|
526 | $page->param(ntot => $pgcount);
|
---|
527 | $page->param(nfirst => (($offset eq 'all' ? 0 : $offset)*$perpage+1));
|
---|
528 | $page->param(npglast => ($offset eq 'all' ? $pgcount :
|
---|
529 | ( (($offset+1)*$perpage) > $pgcount ? $pgcount : (($offset+1)*$perpage) )
|
---|
530 | ));
|
---|
531 | $page->param(pgtype => $pgtype);
|
---|
532 | $page->param(parent => $parent);
|
---|
533 | } # end fill_pgcount()
|
---|
534 |
|
---|
535 |
|
---|
536 | sub listdomains {
|
---|
537 | my $sth = $dbh->prepare("select count(*) from domains");
|
---|
538 | $sth->execute;
|
---|
539 | my ($count) = ($sth->fetchrow_array);
|
---|
540 |
|
---|
541 | # fill page count and first-previous-next-last-all bits
|
---|
542 | ##fixme - hardcoded group bit
|
---|
543 | fill_pgcount($count,"domains","default group");
|
---|
544 | fill_fpnla($count);
|
---|
545 |
|
---|
546 | ##fixme - group
|
---|
547 | $page->param(grp => 1);
|
---|
548 | my @domlist;
|
---|
549 | $sth = $dbh->prepare("select domain_id,domain,status,groups.name from domains".
|
---|
550 | " inner join groups on domains.group_id=groups.group_id".
|
---|
551 | " order by domain".($offset eq 'all' ? '' : " limit $perpage offset ".$offset*$perpage));
|
---|
552 | $sth->execute;
|
---|
553 | my $rownum = 0;
|
---|
554 | while (my @data = $sth->fetchrow_array) {
|
---|
555 | my %row;
|
---|
556 | $row{domainid} = $data[0];
|
---|
557 | $row{domain} = $data[1];
|
---|
558 | $row{status} = ($data[2] ? 'Active' : 'Inactive');
|
---|
559 | $row{group} = $data[3];
|
---|
560 | $row{bg} = ($rownum++)%2;
|
---|
561 | # $row{mkactive} = ($data[2] eq 'inactive' ? 1 : 0);
|
---|
562 | $row{mkactive} = !$data[2];
|
---|
563 | $row{sid} = $sid;
|
---|
564 | $row{offset} = $offset;
|
---|
565 | ##fixme: need to clean up status indicator/usage/inversion
|
---|
566 | push @domlist, \%row;
|
---|
567 | }
|
---|
568 | $page->param(domtable => \@domlist);
|
---|
569 | } # end listdomains()
|
---|