Changeset 3 for trunk/dns.cgi
- Timestamp:
- 08/18/09 18:04:14 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dns.cgi
r2 r3 7 7 # Last update by $Author$ 8 8 ### 9 # Copyright (C) 2008 - Kris Deugau <kdeugau@deepnet.cx>9 # Copyright (C) 2008,2009 - Kris Deugau <kdeugau@deepnet.cx> 10 10 11 11 use strict; … … 63 63 64 64 # default 65 my $perpage = 15; 65 #my $perpage = 15; 66 my $perpage = 3; 66 67 my $offset = ($webvar{offset} ? $webvar{offset} : 0); 67 68 … … 82 83 # Default page is a login page 83 84 my $page; # to be initialized as an HTML::Template entity sooner or later 85 86 84 87 85 88 # decide which page to spit out... … … 93 96 94 97 if ($webvar{page} eq 'domlist' or $webvar{page} eq 'index') { 98 99 # hmm. seeing problems in some possibly-not-so-corner cases. 100 if (defined($webvar{action})) { 101 domStatus($dbh,$webvar{id},$webvar{action}); 102 } 103 95 104 my $sth = $dbh->prepare("select count(*) from domains"); 96 105 $sth->execute; 97 106 my ($count) = ($sth->fetchrow_array); 98 107 99 if ($count > $perpage) { 100 # if there are more results than the default, always show the "all" link 101 $page->param(navall => 1); 102 103 if ($offset > 0) { 104 $page->param(navfirst => 1); 105 $page->param(navprev => 1); 106 $page->param(prevoffs => $offset-1); 108 ##fixme 109 if ($offset eq 'all') { 110 print "foo! wanna see'em all\n"; 111 } else { 112 # all these bits only have sensible behaviour if offset is numeric. err, probably. 113 if ($count > $perpage) { 114 # if there are more results than the default, always show the "all" link 115 $page->param(navall => 1); 116 117 if ($offset > 0) { 118 $page->param(navfirst => 1); 119 $page->param(navprev => 1); 120 $page->param(prevoffs => $offset-1); 121 } 122 123 # show "next" and "last" links if we're not on the last page of results 124 if ( (($offset+1) * $perpage - $count) < 0 ) { 125 $page->param(navnext => 1); 126 $page->param(nextoffs => $offset+1); 127 $page->param(navlast => 1); 128 $page->param(lastoffs => int $count/$perpage); 129 } 107 130 } 108 109 # show "next" and "last" links if we're not on the last page of results110 if ( (($offset+1) * $perpage - $count) < 0 ) {111 $page->param(navnext => 1);112 $page->param(nextoffs => $offset+1);113 $page->param(navlast => 1);114 $page->param(lastoffs => int $count/$perpage);115 }116 131 } 117 132 118 133 $page->param(ndomains => $count); 119 134 $page->param(nstart => (($offset eq 'all' ? 0 : $offset)*$perpage+1)); 135 $page->param(npglast => ($offset eq 'all' ? $count : 136 ( (($offset+1)*$perpage) > $count ? $count : (($offset+1)*$perpage) ) 137 )); 120 138 my @domlist; 121 139 $sth = $dbh->prepare("select domain_id,domain,status,groups.name from domains". 122 140 " inner join groups on domains.group_id=groups.group_id". 123 " order by domain limit $perpage offset ".$offset*$perpage);141 " order by domain".($offset eq 'all' ? '' : " limit $perpage offset ".$offset*$perpage)); 124 142 $sth->execute; 125 143 my $rownum = 0; … … 128 146 $row{domainid} = $data[0]; 129 147 $row{domain} = $data[1]; 130 $row{status} = $data[2];148 $row{status} = ($data[2] ? 'Active' : 'Inactive'); 131 149 $row{group} = $data[3]; 132 150 $row{bg} = ($rownum++)%2; 133 $row{mkactive} = ($data[2] eq 'inactive' ? 1 : 0); 151 # $row{mkactive} = ($data[2] eq 'inactive' ? 1 : 0); 152 $row{mkactive} = !$data[2]; 134 153 $row{sid} = $sid; 154 $row{offset} = $offset; 135 155 ##fixme: need to clean up status indicator/usage/inversion 136 156 push @domlist, \%row; … … 190 210 print "whee!\n"; 191 211 192 newrec(); 212 # populate most fields as needed. (eg, type list.) 213 newrec(); 193 214 194 215 } elsif ($webvar{page} eq 'addrec') { … … 221 242 } 222 243 244 $page->param(defrec => $webvar{defrec}); 245 223 246 } elsif ($webvar{page} eq 'conf_del') { 224 247 … … 236 259 if (!defined($webvar{del})) { 237 260 $page->param(del_getconf => 1); 238 } else { 239 # $page->param( 240 } 241 ##work 261 my %rec = getRecLine($dbh,$webvar{defrec},$webvar{id}); 262 $page->param(host => $rec{host}); 263 $page->param(ftype => $typemap{$rec{type}}); 264 $page->param(recval => $rec{val}); 265 } else { 266 my ($code,$msg) = delRec($dbh,$webvar{defrec},$webvar{id}); 267 if ($code ne 'OK') { 268 ## need to find failure mode 269 $page->param(del_failed => 1); 270 $page->param(errmsg => $msg); 271 } 272 ##fixme: group/parent instead of hardcoded 1 273 showdomain('y',1); 274 } 242 275 243 276 } elsif ($webvar{page} eq 'editsoa') { … … 258 291 $sth = $dbh->prepare($sql); 259 292 $sth->execute; 260 print "DEBUG: $sql<br>\n";261 #print "DEBUG: ".$DBI::errstr;262 293 263 294 if ($sth->err) { … … 279 310 # hokay, a bit of magic to decide which page we hit. 280 311 if ($code eq 'OK') { 281 $page = HTML::Template->new(filename => "$templatedir/domlist.tmpl"); 312 $page = HTML::Template->new(filename => "$templatedir/reclist.tmpl"); 313 showdomain(0,$msg); 314 ##work 282 315 } else { 283 316 # oooh, yeah, this is supposed to be a redirect. er, maybe. whee. … … 288 321 } 289 322 290 # my $sth = $dbh->prepare("insert into domains (domain,group_id,status) values (?,?,?)"); 291 # $sth->execute($webvar{domain},1,($webvar{makeactive} ? 'active' : 'inactive')) or die $DBI::errstr; 292 # $sth = $dbh->prepare("select domain_id from domains where domain='$webvar{domain}'"); 293 # $sth->execute; 294 # my ($dom_id) = $sth->fetchrow_array(); 295 # $sth = $dbh->prepare("select host,type,val,distance,ttl from default_records where group_id=1"); 296 # my $sth_in = $dbh->prepare("insert into records (domain_id,host,type,val,distance,ttl)". 297 # " values ($dom_id,?,?,?,?,?)"); 298 # $sth->execute; 299 # while (my ($host,$type,$val,$dist,$ttl) = $sth->fetchrow_array()) { 300 # $host =~ s/DOMAIN/$webvar{domain}/g; 301 # $sth_in->execute($host,$type,$val,$dist,$ttl); 302 # } 303 # $dbh->commit or print "failed to add $webvar{domain}: ".$DBI::errstr."\n"; 304 305 # $page->param(add_failed => 1); 323 306 324 } 307 325 … … 410 428 $page->param(typelist => \@typelist); 411 429 $page->param(domain => domainName($dbh,$webvar{domainid})); 412 $page->param(parentid => $webvar{parentid});413 430 $page->param(defrec => $webvar{defrec}); 414 431 $page->param(ttl => ($webvar{ttl} ? $webvar{ttl} : $DNSDB::def{minttl})); 415 } 432 if ($webvar{defrec} eq 'y') { 433 ##fixme - should be groupid 434 $page->param(parentid => 1); 435 } else { 436 $page->param(parentid => $webvar{parentid}); 437 } 438 }
Note:
See TracChangeset
for help on using the changeset viewer.