- Timestamp:
- 07/29/12 22:02:48 (12 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r368 r370 47 47 &addUser &updateUser &delUser &userFullName &userStatus &getUserData 48 48 &getUserCount &getUserList &getUserDropdown 49 &addLoc &updateLoc &delLoc 50 &getLocCount &getLocList &getLocDropdown 49 51 &getSOA &updateSOA &getRecLine &getDomRecs &getRecCount 50 52 &addRec &updateRec &delRec … … 72 74 &addUser &updateUser &delUser &userFullName &userStatus &getUserData 73 75 &getUserCount &getUserList &getUserDropdown 76 &addLoc &updateLoc &delLoc 77 &getLocCount &getLocList &getLocDropdown 74 78 &getSOA &updateSOA &getRecLine &getDomRecs &getRecCount 75 79 &addRec &updateRec &delRec … … 106 110 107 111 # Arguably defined wholly in the db, but little reason to change without supporting code changes 112 # group_view, user_view permissions? separate rDNS permission(s)? 108 113 our @permtypes = qw ( 109 114 group_edit group_create group_delete … … 111 116 domain_edit domain_create domain_delete 112 117 record_edit record_create record_delete 118 location_edit location_create location_delete location_view 113 119 self_edit admin 114 120 ); … … 2891 2897 2892 2898 } # end getUserData() 2899 2900 2901 ## DNSDB::addLoc() 2902 sub addLoc {} 2903 2904 ## DNSDB::updateLoc() 2905 sub updateLoc {} 2906 2907 ## DNSDB::delLoc() 2908 sub delLoc {} 2909 2910 2911 ## DNSDB::getLocCount() 2912 # Get count of locations/views 2913 # Takes a database handle and hash containing at least the current group, and optionally: 2914 # - a reference list of secondary groups 2915 # - a filter string 2916 # - a "Starts with" string 2917 sub getLocCount { 2918 my $dbh = shift; 2919 2920 my %args = @_; 2921 2922 my @filterargs; 2923 2924 $args{startwith} = undef if $args{startwith} && $args{startwith} !~ /^(?:[a-z]|0-9)$/; 2925 push @filterargs, "^$args{startwith}" if $args{startwith}; 2926 push @filterargs, $args{filter} if $args{filter}; 2927 2928 2929 my $sql = "SELECT count(*) FROM locations ". 2930 "WHERE group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")". 2931 ($args{startwith} ? " AND description ~* ?" : ''). 2932 ($args{filter} ? " AND description ~* ?" : ''); 2933 my ($count) = $dbh->selectrow_array($sql, undef, (@filterargs) ); 2934 $errstr = $dbh->errstr if !$count; 2935 return $count; 2936 } # end getLocCount() 2937 2938 2939 ## DNSDB::getLocList() 2940 sub getLocList { 2941 my $dbh = shift; 2942 2943 my %args = @_; 2944 2945 my @filterargs; 2946 2947 $args{startwith} = undef if $args{startwith} && $args{startwith} !~ /^(?:[a-z]|0-9)$/; 2948 push @filterargs, "^$args{startwith}" if $args{startwith}; 2949 push @filterargs, $args{filter} if $args{filter}; 2950 2951 # better to request sorts on "simple" names, but it means we need to map it to real columns 2952 # my %sortmap = (user => 'u.username', type => 'u.type', group => 'g.group_name', status => 'u.status', 2953 # fname => 'fname'); 2954 # $args{sortby} = $sortmap{$args{sortby}}; 2955 2956 # protection against bad or missing arguments 2957 $args{sortorder} = 'ASC' if !$args{sortorder}; 2958 $args{sortby} = 'l.description' if !$args{sortby}; 2959 $args{offset} = 0 if !$args{offset}; 2960 2961 my $sql = "SELECT l.location, l.description, l.iplist, g.group_name ". 2962 "FROM locations l ". 2963 "INNER JOIN groups g ON l.group_id=g.group_id ". 2964 "WHERE l.group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")". 2965 ($args{startwith} ? " AND l.description ~* ?" : ''). 2966 ($args{filter} ? " AND l.description ~* ?" : ''). 2967 " ORDER BY $args{sortby} $args{sortorder} ". 2968 ($args{offset} eq 'all' ? '' : " LIMIT $config{perpage} OFFSET ".$args{offset}*$config{perpage}); 2969 my $ulist = $dbh->selectall_arrayref($sql, { Slice => {} }, (@filterargs) ); 2970 $errstr = $dbh->errstr if !$ulist; 2971 return $ulist; 2972 } # end getLocList() 2973 2974 2975 ## DNSDB::getLocDropdown() 2893 2976 2894 2977 -
trunk/dns-1.0-1.2.sql
r369 r370 1 1 -- SQL table/record type upgrade file for dnsadmin 1.0 to 1.2 migration 2 3 -- need this before we add any other bits 4 CREATE TABLE locations ( 5 loc character varying (4) PRIMARY KEY, 6 group_id integer NOT NULL DEFAULT 1, 7 iplist text NOT NULL DEFAULT '', 8 description text NOT NULL DEFAULT '' 9 ); 10 11 ALTER TABLE ONLY locations 12 ADD CONSTRAINT "locations_group_id_fkey" FOREIGN KEY (group_id) REFERENCES groups(group_id); 13 14 ALTER TABLE permissions ADD COLUMN location_create boolean DEFAULT false NOT NULL; 15 ALTER TABLE permissions ADD COLUMN location_edit boolean DEFAULT false NOT NULL; 16 ALTER TABLE permissions ADD COLUMN location_delete boolean DEFAULT false NOT NULL; 17 ALTER TABLE permissions ADD COLUMN location_view boolean DEFAULT false NOT NULL; 2 18 3 19 -- Minor buglet; domains must be unique … … 23 39 SELECT pg_catalog.setval('default_rev_records_record_id_seq', 5, false); 24 40 25 ALTER TABLE domains ADD COLUMN changed boolean; 26 UPDATE domains SET changed=false; 27 ALTER TABLE domains ALTER COLUMN changed SET DEFAULT true; 28 ALTER TABLE domains ALTER COLUMN changed SET NOT NULL; 41 ALTER TABLE domains ADD COLUMN changed boolean DEFAULT true NOT NULL; 42 ALTER TABLE domains ADD COLUMN default_location character varying (4) DEFAULT '' NOT NULL; 29 43 -- ~2x performance boost iff most zones are fed to output from the cache 30 44 CREATE INDEX dom_status_index ON domains (status); … … 38 52 zserial integer, 39 53 sertype character(1) DEFAULT 'D'::bpchar, 40 changed boolean DEFAULT true NOT NULL 54 changed boolean DEFAULT true NOT NULL, 55 default_location character varying (4) DEFAULT '' NOT NULL 41 56 ); 42 57 CREATE INDEX rev_status_index ON revzones (status); … … 52 67 ALTER TABLE records DROP CONSTRAINT "$1"; 53 68 ALTER TABLE records ALTER COLUMN domain_id SET DEFAULT 0; 54 ALTER TABLE records ADD COLUMN rdns_id INTEGER DEFAULT 0 ;55 UPDATE records SET rdns_id=0;56 ALTER TABLE records ALTER COLUMN rdns_id SET NOT NULL; 69 ALTER TABLE records ADD COLUMN rdns_id INTEGER DEFAULT 0 NOT NULL; 70 ALTER TABLE records ADD COLUMN location character varying (4) DEFAULT '' NOT NULL; 71 57 72 -- ~120s -> 75s performance boost on 100K records when always exporting all records 58 73 CREATE INDEX rec_types_index ON records (type); -
trunk/dns.cgi
r338 r370 1342 1342 } 1343 1343 1344 } elsif ($webvar{page} eq 'loclist') { 1345 1346 # changepage(page => "domlist", errmsg => "You are not allowed access to this function") 1347 # unless $permissions{admin} || $permissions{ foo? }; 1348 1349 # security check - does the user have permission to access this entity? 1350 # if (!check_scope(id => $webvar{id}, type => 'loc')) { 1351 # changepage(page => "loclist", errmsg => "You are not permitted to <foo> the requested location/view"); 1352 # } 1353 list_locations(); 1354 1355 # Permissions! 1356 $page->param(addloc => $permissions{admin} || $permissions{loc_create}); 1357 $page->param(delloc => $permissions{admin} || $permissions{loc_delete}); 1358 1359 } elsif ($webvar{page} eq 'location') { 1360 1361 1344 1362 } elsif ($webvar{page} eq 'dnsq') { 1345 1363 … … 1586 1604 ##fixme 1587 1605 $page->param(mayrdns => 1); 1606 $page->param(mayloc => 1); 1588 1607 1589 1608 $page->param(maydefrec => $permissions{admin}); … … 2079 2098 2080 2099 2100 sub list_locations { 2101 2102 my @childgroups; 2103 getChildren($dbh, $curgroup, \@childgroups, 'all') if $searchsubs; 2104 my $childlist = join(',',@childgroups); 2105 2106 my $count = getLocCount($dbh, (childlist => $childlist, curgroup => $curgroup, 2107 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef) ) ); 2108 2109 # fill page count and first-previous-next-last-all bits 2110 fill_pgcount($count,"locations/views",''); 2111 fill_fpnla($count); 2112 2113 $sortby = 'user'; 2114 # sort/order 2115 $session->param($webvar{page}.'sortby', $webvar{sortby}) if $webvar{sortby}; 2116 $session->param($webvar{page}.'order', $webvar{order}) if $webvar{order}; 2117 2118 $sortby = $session->param($webvar{page}.'sortby') if $session->param($webvar{page}.'sortby'); 2119 $sortorder = $session->param($webvar{page}.'order') if $session->param($webvar{page}.'order'); 2120 2121 # set up the headers 2122 my @cols = ('description', 'iplist', 'group'); 2123 my %colnames = (description => 'Location/View Name', iplist => 'Permitted IPs/Ranges', group => 'Group'); 2124 fill_colheads($sortby, $sortorder, \@cols, \%colnames); 2125 2126 # waffle, waffle - keep state on these as well as sortby, sortorder? 2127 $page->param("start$startwith" => 1) if $startwith && $startwith =~ /^(?:[a-z]|0-9)$/; 2128 2129 $page->param(filter => $filter) if $filter; 2130 $page->param(searchsubs => $searchsubs) if $searchsubs; 2131 2132 my $loclist = getLocList($dbh, (childlist => $childlist, curgroup => $curgroup, 2133 filter => ($filter ? $filter : undef), startwith => ($startwith ? $startwith : undef), 2134 offset => $webvar{offset}, sortby => $sortby, sortorder => $sortorder) ); 2135 # Some UI things need to be done to the list 2136 foreach my $l (@{$loclist}) { 2137 $l->{edloc} = ($permissions{admin} || $permissions{loc_edit}); 2138 $l->{delloc} = ($permissions{admin} || $permissions{loc_delete}); 2139 } 2140 $page->param(loctable => $loclist); 2141 } # end list_locations() 2142 2143 2081 2144 # Generate all of the glop necessary to add or not the appropriate marker/flag for 2082 2145 # the sort order and column in domain, user, group, and record lists -
trunk/dns.sql
r369 r370 16 16 1 dbversion 1.2 17 17 \. 18 19 CREATE TABLE locations ( 20 location character varying (4) PRIMARY KEY, 21 group_id integer NOT NULL DEFAULT 1, 22 iplist text NOT NULL DEFAULT '', 23 description text NOT NULL DEFAULT '' 24 ); 18 25 19 26 CREATE TABLE default_records ( … … 66 73 zserial integer, 67 74 sertype character(1) DEFAULT 'D'::bpchar, 68 changed boolean DEFAULT true NOT NULL 75 changed boolean DEFAULT true NOT NULL, 76 default_location character varying (4) DEFAULT '' NOT NULL 69 77 ); 70 78 … … 77 85 zserial integer, 78 86 sertype character(1) DEFAULT 'D'::bpchar, 79 changed boolean DEFAULT true NOT NULL 87 changed boolean DEFAULT true NOT NULL, 88 default_location character varying (4) DEFAULT '' NOT NULL 80 89 ); 81 90 … … 123 132 record_edit boolean DEFAULT false NOT NULL, 124 133 record_delete boolean DEFAULT false NOT NULL, 134 location_create boolean DEFAULT false NOT NULL, 135 location_edit boolean DEFAULT false NOT NULL, 136 location_delete boolean DEFAULT false NOT NULL, 137 location_view boolean DEFAULT false NOT NULL, 125 138 user_id integer UNIQUE, 126 139 group_id integer UNIQUE … … 129 142 -- Need *two* basic permissions; one for the initial group, one for the default admin user 130 143 COPY permissions (permission_id, admin, self_edit, group_create, group_edit, group_delete, user_create, user_edit, user_delete, domain_create, domain_edit, domain_delete, record_create, record_edit, record_delete, user_id, group_id) FROM stdin; 131 1 f f f f f f f f t t t t t t \N 1132 2 t f f f f f f f f f f f f f 1 \N144 1 f f f f f f f f t t t t t t f f f f \N 1 145 2 t f f f f f f f f f f f f f f f f f 1 \N 133 146 \. 134 147 … … 145 158 port integer DEFAULT 0 NOT NULL, 146 159 ttl integer DEFAULT 7200 NOT NULL, 147 description text 160 description text, 161 default_location character varying (4) DEFAULT '' NOT NULL 148 162 ); 149 163 … … 289 303 -- foreign keys 290 304 -- fixme: permissions FK refs 305 ALTER TABLE ONLY locations 306 ADD CONSTRAINT "locations_group_id_fkey" FOREIGN KEY (group_id) REFERENCES groups(group_id); 307 291 308 ALTER TABLE ONLY domains 292 309 ADD CONSTRAINT "$1" FOREIGN KEY (group_id) REFERENCES groups(group_id); -
trunk/templates/menu.tmpl
r238 r370 9 9 <TMPL_IF maydefrec><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=reclist&id=<TMPL_VAR NAME=group>&defrec=y">Default Records</a><br /> 10 10 <TMPL_IF mayrdns><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=reclist&id=<TMPL_VAR NAME=group>&defrec=y&revrec=y">Default Reverse Records</a><br /></TMPL_IF></TMPL_IF> 11 <TMPL_IF mayloc><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=loclist&id=<TMPL_VAR NAME=group>">Locations/Views</a><br /></TMPL_IF> 11 12 <TMPL_IF mayimport><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=axfr">AXFR Import</a><br /></TMPL_IF> 12 13 <TMPL_IF maybulk><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=bulkdomain">Bulk Domain Operations</a><br /></TMPL_IF> -
trunk/templates/permlist.tmpl
r67 r370 25 25 </tr> 26 26 <tr> 27 <td align="right">Location/View:</td> 28 <td<TMPL_UNLESS may_location_edit> class="<TMPL_UNLESS info>noaccess<TMPL_ELSE>info</TMPL_UNLESS>"</TMPL_UNLESS>><input type="checkbox"<TMPL_UNLESS info> name="location_edit"</TMPL_UNLESS><TMPL_IF location_edit> checked="checked"</TMPL_IF><TMPL_UNLESS may_location_edit>disabled="disabled"</TMPL_UNLESS> /> Edit</td> 29 <td<TMPL_UNLESS may_location_create> class="<TMPL_UNLESS info>noaccess<TMPL_ELSE>info</TMPL_UNLESS>"</TMPL_UNLESS>><input type="checkbox"<TMPL_UNLESS info> name="location_create"</TMPL_UNLESS><TMPL_IF location_create> checked="checked"</TMPL_IF><TMPL_UNLESS may_location_create> disabled="disabled"</TMPL_UNLESS> /> Create</td> 30 <td<TMPL_UNLESS may_location_delete> class="<TMPL_UNLESS info>noaccess<TMPL_ELSE>info</TMPL_UNLESS>"</TMPL_UNLESS>><input type="checkbox"<TMPL_UNLESS info> name="location_delete"</TMPL_UNLESS><TMPL_IF location_delete> checked="checked"</TMPL_IF><TMPL_UNLESS may_location_delete> disabled="disabled"</TMPL_UNLESS> /> Delete</td> 31 <td<TMPL_UNLESS may_location_view> class="<TMPL_UNLESS info>noaccess<TMPL_ELSE>info</TMPL_UNLESS>"</TMPL_UNLESS>><input type="checkbox"<TMPL_UNLESS info> name="location_view"</TMPL_UNLESS><TMPL_IF location_view> checked="checked"</TMPL_IF><TMPL_UNLESS may_location_view> disabled="disabled"</TMPL_UNLESS> /> View</td> 32 </tr> 33 <tr> 27 34 <td align="right">Self:</td> 28 35 <td<TMPL_UNLESS may_self_edit> class="<TMPL_UNLESS info>noaccess<TMPL_ELSE>info</TMPL_UNLESS>"</TMPL_UNLESS>><input type="checkbox"<TMPL_UNLESS info> name="self_edit"</TMPL_UNLESS><TMPL_IF self_edit> checked="checked"</TMPL_IF><TMPL_UNLESS may_self_edit> disabled="disabled"</TMPL_UNLESS> /> Edit</td>
Note:
See TracChangeset
for help on using the changeset viewer.