- Timestamp:
- 02/17/12 17:55:18 (13 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r236 r237 30 30 &loadConfig &connectDB &finish 31 31 &addDomain &delDomain &domainName &domainID 32 &getZoneCount &getZoneList 32 33 &addGroup &delGroup &getChildren &groupName 33 34 &addUser &updateUser &delUser &userFullName &userStatus &getUserData … … 51 52 &loadConfig &connectDB &finish 52 53 &addDomain &delDomain &domainName &domainID 54 &getZoneCount &getZoneList 53 55 &addGroup &delGroup &getChildren &groupName 54 56 &addUser &updateUser &delUser &userFullName &userStatus &getUserData … … 1184 1186 return $domid if $domid; 1185 1187 } # end domainID() 1188 1189 1190 ## DNSDB::getZoneCount 1191 # Get count of zones in group or groups 1192 # Takes a database handle and hash containing: 1193 # - the "current" group 1194 # - an array of "acceptable" groups 1195 # - a flag for forward/reverse zones 1196 # - Optionally accept a "starts with" and/or "contains" filter argument 1197 # Returns an integer count of the resulting zone list. 1198 sub getZoneCount { 1199 my $dbh = shift; 1200 1201 my %args = @_; 1202 1203 my @filterargs; 1204 $args{filter} =~ s/\./\[\.\]/g if $args{filter}; 1205 push @filterargs, $args{startwith} if $args{startwith}; 1206 push @filterargs, $args{filter} if $args{filter}; 1207 1208 my $sql; 1209 # Not as compact, and fix-me-twice if the common bits get wrong, but much easier to read 1210 if ($args{revrec} eq 'n') { 1211 $sql = "SELECT count(*) FROM domains". 1212 " WHERE group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")". 1213 ($args{startwith} ? " AND domain ~* ?" : ''). 1214 ($args{filter} ? " AND domain ~* ?" : ''); 1215 } else { 1216 $sql = "SELECT count(*) FROM revzones". 1217 " WHERE group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")". 1218 ($args{startwith} ? " AND CAST(revnet AS VARCHAR) ~* ?" : ''). 1219 ($args{filter} ? " AND CAST(revnet AS VARCHAR) ~* ?" : ''); 1220 } 1221 my ($count) = $dbh->selectrow_array($sql, undef, @filterargs); 1222 return $count; 1223 } # end getZoneCount() 1224 1225 1226 ## DNSDB::getZoneList() 1227 # Get a list of zones in the specified group(s) 1228 # Takes the same arguments as getZoneCount() above 1229 # Returns a reference to an array of hashrefs suitable for feeding to HTML::Template 1230 sub getZoneList { 1231 my $dbh = shift; 1232 1233 my %args = @_; 1234 1235 my @zonelist; 1236 1237 $args{sortorder} = 'ASC' if !grep $args{sortorder}, ('ASC','DESC'); 1238 $args{offset} = 0 if !$args{offset}; 1239 1240 my @filterargs; 1241 $args{filter} =~ s/\./\[\.\]/g if $args{filter}; 1242 push @filterargs, $args{startwith} if $args{startwith}; 1243 push @filterargs, $args{filter} if $args{filter}; 1244 1245 my $sql; 1246 # Not as compact, and fix-me-twice if the common bits get wrong, but much easier to read 1247 if ($args{revrec} eq 'n') { 1248 $args{sortby} = 'domain' if !grep $args{sortby}, ('revnet','group','status'); 1249 $sql = "SELECT domain_id,domain,status,groups.group_name AS group FROM domains". 1250 " INNER JOIN groups ON domains.group_id=groups.group_id". 1251 " WHERE domains.group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")". 1252 ($args{startwith} ? " AND domain ~* ?" : ''). 1253 ($args{filter} ? " AND domain ~* ?" : ''); 1254 } else { 1255 $args{sortby} = 'revnet' if !grep $args{sortby}, ('domain','group','status'); 1256 $sql = "SELECT rdns_id,revnet,status,groups.group_name AS group FROM revzones". 1257 " INNER JOIN groups ON revzones.group_id=groups.group_id". 1258 " WHERE revzones.group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")". 1259 ($args{startwith} ? " AND CAST(revnet AS VARCHAR) ~* ?" : ''). 1260 ($args{filter} ? " AND CAST(revnet AS VARCHAR) ~* ?" : ''); 1261 } 1262 # A common tail. 1263 $sql .= " ORDER BY ".($args{sortby} eq 'group' ? 'groups.group_name' : $args{sortby}). 1264 " $args{sortorder} ".($args{offset} eq 'all' ? '' : " LIMIT $config{perpage}". 1265 " OFFSET ".$args{offset}*$config{perpage}); 1266 my $sth = $dbh->prepare($sql); 1267 $sth->execute(@filterargs); 1268 my $rownum = 0; 1269 1270 while (my @data = $sth->fetchrow_array) { 1271 my %row; 1272 $row{domainid} = $data[0]; 1273 $row{domain} = $data[1]; 1274 $row{status} = ($data[2] ? 'Active' : 'Inactive'); 1275 $row{group} = $data[3]; 1276 $row{bg} = ($rownum++)%2; 1277 $row{mkactive} = !$data[2]; 1278 # $row{sid} = $args{sid}; 1279 $row{offset} = $args{offset}; 1280 # ACLs 1281 # $row{domain_edit} = ($permissions{admin} || $permissions{domain_edit}); 1282 # $row{domain_delete} = ($permissions{admin} || $permissions{domain_delete}); 1283 push @zonelist, \%row; 1284 } 1285 1286 return \@zonelist; 1287 } # end getZoneList() 1186 1288 1187 1289 -
trunk/dns.cgi
r234 r237 408 408 changepage(page => "domlist"); 409 409 } 410 411 } elsif ($webvar{page} eq 'revzones') { 412 413 $webvar{revrec} = 'y'; 414 $page->param(curpage => $webvar{page}); 415 listzones(); 410 416 411 417 } elsif ($webvar{page} eq 'reclist') { … … 1881 1887 # on a page showing nothing. 1882 1888 # For bonus points, this reverts to the original offset on clicking the "All" link (mostly) 1883 if ($offset ne 'all') { 1889 if ($offset ne 'all') { 1884 1890 $offset-- while ($offset * $perpage) >= $pgcount; 1885 1891 } … … 1895 1901 } # end fill_pgcount() 1896 1902 1897 sub listdomains { 1898 1903 1904 sub listdomains { listzones(); } # temp 1905 1906 sub listzones { 1899 1907 # ACLs 1900 1908 $page->param(domain_create => ($permissions{admin} || $permissions{domain_create}) ); … … 1906 1914 my $childlist = join(',',@childgroups); 1907 1915 1908 my $sql = "SELECT count(*) FROM domains WHERE group_id IN ($curgroup".($childlist ? ",$childlist" : '').")". 1909 ($startwith ? " AND domain ~* ?" : ''). 1910 ($filter ? " AND domain ~* ?" : ''); 1911 my $sth = $dbh->prepare($sql); 1912 $sth->execute(@filterargs); 1913 my ($count) = $sth->fetchrow_array; 1916 my $count = getZoneCount($dbh, (childlist => $childlist, curgroup => $curgroup, revrec => $webvar{revrec}, 1917 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) ) ); 1914 1918 1915 1919 # fill page count and first-previous-next-last-all bits 1916 fill_pgcount($count, "domains",groupName($dbh,$curgroup));1920 fill_pgcount($count,($webvar{revrec} eq 'n' ? 'domains' : 'revzones'),groupName($dbh,$curgroup)); 1917 1921 fill_fpnla($count); 1918 1922 … … 1925 1929 1926 1930 # set up the headers 1927 my @cols = ( 'domain', 'status', 'group');1928 my %colheads = (domain => 'Domain', status => 'Status', group => 'Group');1931 my @cols = (($webvar{revrec} eq 'n' ? 'domain' : 'revnet'), 'status', 'group'); 1932 my %colheads = (domain => 'Domain', revnet => 'Reverse Zone', status => 'Status', group => 'Group'); 1929 1933 fill_colheads($sortby, $sortorder, \@cols, \%colheads); 1930 1934 … … 1934 1938 1935 1939 # waffle, waffle - keep state on these as well as sortby, sortorder? 1940 ##fixme: put this higher so the count doesn't get munched? 1936 1941 $page->param("start$startwith" => 1) if $startwith && $startwith =~ /^(?:[a-z]|0-9)$/; 1937 1942 … … 1939 1944 $page->param(searchsubs => $searchsubs) if $searchsubs; 1940 1945 1941 ##fixme1942 ##fixme push the SQL and direct database fiddling off into a sub in DNSDB.pm1943 ##fixme1944 1945 1946 $page->param(group => $curgroup); 1946 my @domlist; 1947 $sql = "SELECT domain_id,domain,status,groups.group_name AS group FROM domains". 1948 " INNER JOIN groups ON domains.group_id=groups.group_id". 1949 " WHERE domains.group_id IN ($curgroup".($childlist ? ",$childlist" : '').")". 1950 ($startwith ? " AND domain ~* ?" : ''). 1951 ($filter ? " AND domain ~* ?" : ''). 1952 " ORDER BY ".($sortby eq 'group' ? 'groups.group_name' : $sortby). 1953 " $sortorder ".($offset eq 'all' ? '' : " LIMIT $perpage OFFSET ".$offset*$perpage); 1954 $sth = $dbh->prepare($sql); 1955 $sth->execute(@filterargs); 1956 my $rownum = 0; 1957 while (my @data = $sth->fetchrow_array) { 1958 my %row; 1959 $row{domainid} = $data[0]; 1960 $row{domain} = $data[1]; 1961 $row{status} = ($data[2] ? 'Active' : 'Inactive'); 1962 $row{group} = $data[3]; 1963 $row{bg} = ($rownum++)%2; 1964 $row{mkactive} = !$data[2]; 1965 $row{sid} = $sid; 1966 $row{offset} = $offset; 1967 # ACLs 1968 $row{domain_edit} = ($permissions{admin} || $permissions{domain_edit}); 1969 $row{domain_delete} = ($permissions{admin} || $permissions{domain_delete}); 1970 push @domlist, \%row; 1971 } 1972 $page->param(domtable => \@domlist); 1947 1948 my $zonelist = getZoneList($dbh, (childlist => $childlist, curgroup => $curgroup, 1949 revrec => $webvar{revrec}, 1950 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef), 1951 offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder 1952 ) ); 1953 foreach (@$zonelist) { 1954 $_->{sid} = $sid; 1955 $_->{domain_edit} = ($permissions{admin} || $permissions{domain_edit}); 1956 $_->{domain_delete} = ($permissions{admin} || $permissions{domain_delete}); 1957 } 1958 $page->param(domtable => $zonelist); 1973 1959 } # end listdomains() 1974 1960
Note:
See TracChangeset
for help on using the changeset viewer.