Changeset 649 for branches/stable/dns.cgi
- Timestamp:
- 06/23/14 17:52:37 (11 years ago)
- Location:
- branches/stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable
-
branches/stable/dns.cgi
r587 r649 97 97 or die CGI::Session->errstr(); 98 98 99 if (!$sid || $session->is_expired ) {99 if (!$sid || $session->is_expired || !$session->param('uid') || !$dnsdb->userStatus($session->param('uid')) ) { 100 100 $webvar{page} = 'login'; 101 101 } else { … … 219 219 my $sesscookie = $q->cookie( -name => 'dnsadmin_session', 220 220 -value => $sid, 221 #-expires => "+".$dnsdb->{timeout},221 -expires => "+".$dnsdb->{timeout}, 222 222 -secure => 0, 223 223 ## fixme: need to extract root path for cookie, so as to limit cookie to dnsadmin instance … … 242 242 $sesscookie = $q->cookie( -name => 'dnsadmin_session', 243 243 -value => $sid, 244 #-expires => "+".$dnsdb->{timeout},244 -expires => "+".$dnsdb->{timeout}, 245 245 -secure => 0, 246 246 ## fixme: need to extract root path for cookie, so as to limit cookie to dnsadmin instance … … 254 254 $session->param('uid',$userdata->{user_id}); 255 255 $session->param('username',$webvar{username}); 256 $curgroup = $userdata->{group_id}; 256 257 257 258 # for reference. seems we don't need to set these on login any more. … … 742 743 my %pageparams = (page => "reclist", id => $webvar{parentid}, 743 744 defrec => $webvar{defrec}, revrec => $webvar{revrec}); 744 $pageparams{warnmsg} = $msg."<br ><br>\n".$DNSDB::resultstr if $code eq 'WARN';745 $pageparams{warnmsg} = $msg."<br />\n".$DNSDB::resultstr if $code eq 'WARN'; 745 746 $pageparams{resultmsg} = $DNSDB::resultstr if $code eq 'OK'; 746 747 changepage(%pageparams); … … 801 802 my %pageparams = (page => "reclist", id => $webvar{parentid}, 802 803 defrec => $webvar{defrec}, revrec => $webvar{revrec}); 803 $pageparams{warnmsg} = $msg."<br ><br>\n".$DNSDB::resultstr if $code eq 'WARN';804 $pageparams{warnmsg} = $msg."<br />\n".$DNSDB::resultstr if $code eq 'WARN'; 804 805 $pageparams{resultmsg} = $DNSDB::resultstr if $code eq 'OK'; 805 806 changepage(%pageparams); … … 1076 1077 fill_permissions($page, \%grpperms); 1077 1078 1078 } elsif ($webvar{page} eq 'bulkdomain' ) {1079 } elsif ($webvar{page} eq 'bulkdomain' || $webvar{page} eq 'bulkrev') { 1079 1080 # Bulk operations on domains. Note all but group move are available on the domain list. 1080 ##fixme: do we care about bulk operations on revzones? Move-to-group, activate, deactivate, 1081 # and delete should all be much rarer for revzones than for domains. 1082 1083 changepage(page => "domlist", errmsg => "You are not permitted to make bulk domain changes") 1081 1082 changepage(page => "domlist", errmsg => "You are not permitted to make bulk zone changes") 1084 1083 unless ($permissions{admin} || $permissions{domain_edit} || $permissions{domain_create} || $permissions{domain_delete}); 1085 1084 1086 1085 fill_grouplist("grouplist"); 1087 1086 1088 my $count = $dnsdb->getZoneCount(revrec => 'n', curgroup => $curgroup); 1087 $page->param(fwdzone => $webvar{page} eq 'bulkdomain'); 1088 1089 my $count = $dnsdb->getZoneCount(revrec => ($webvar{page} eq 'bulkdomain' ? 'n' : 'y'), 1090 curgroup => $curgroup); 1089 1091 1090 1092 $page->param(curpage => $webvar{page}); … … 1093 1095 $page->param(perpage => $perpage); 1094 1096 1095 my $domlist = $dnsdb->getZoneList(revrec => 'n', curgroup => $curgroup, offset => $offset); 1097 my $domlist = $dnsdb->getZoneList(revrec => ($webvar{page} eq 'bulkdomain' ? 'n' : 'y'), 1098 curgroup => $curgroup, offset => $offset); 1096 1099 my $rownum = 0; 1097 1100 foreach my $dom (@{$domlist}) { 1098 1101 delete $dom->{status}; 1099 1102 delete $dom->{group}; 1100 $dom->{newrow} = (++$rownum) % 5 == 0 ;1103 $dom->{newrow} = (++$rownum) % 5 == 0 && $rownum != $perpage; 1101 1104 } 1102 1105 … … 1107 1110 $page->param(maydelete => $permissions{admin} || $permissions{domain_delete}); 1108 1111 1112 #} elsif ($webvar{page} eq 'confirmbulkdom' || $webvar{page} eq 'confirmbulkrev') { 1113 } elsif ($webvar{page} eq 'confirmbulk') { 1114 1115 changepage(page => "domlist", errmsg => "You are not permitted to make bulk zone changes") 1116 unless ($permissions{admin} || $permissions{domain_edit} || $permissions{domain_create} || $permissions{domain_delete}); 1117 1118 $page->param(bulkaction => $webvar{bulkaction}); 1119 $page->param(destgroup => $webvar{destgroup}); 1120 my @zlist; 1121 my $rownum = 0; 1122 1123 ##fixme: this could probably be made more efficient, since this looks up 2 zone names for 1124 # each comparison during sort rather than slurping them in bulk once before doing the sort 1125 # sort zones by zone name, not ID 1126 sub zsort { 1127 my $tmpa = ($a =~ /^dom/ ? $dnsdb->domainName($webvar{$a}) : $dnsdb->revName($webvar{$a}) ); 1128 my $tmpb = ($b =~ /^dom/ ? $dnsdb->domainName($webvar{$b}) : $dnsdb->revName($webvar{$b}) ); 1129 return $tmpa cmp $tmpb; 1130 } 1131 # eugh. can't see a handy way to sort this mess by zone name the way it is on the submitting page. :( 1132 foreach my $input (sort zsort grep(/^(?:dom|rev)_/, keys %webvar) ) { 1133 next unless $input =~ /^(dom|rev)_\d+$/; 1134 my $fr = $1; 1135 my %row = (zoneid => $webvar{$input}, 1136 zone => ($fr eq 'dom' ? $dnsdb->domainName($webvar{$input}) : $dnsdb->revName($webvar{$input}) ), 1137 zvarname => $input, 1138 newrow => ( (++$rownum) % 5 == 0 && $rownum != $perpage), 1139 ); 1140 push @zlist, \%row; 1141 } 1142 $page->param(domtable => \@zlist); 1143 1109 1144 } elsif ($webvar{page} eq 'bulkchange') { 1110 1145 … … 1115 1150 } 1116 1151 1152 # skip the changes if user did not confirm 1153 my $wasrev = grep /^rev_/, keys %webvar; 1154 changepage(page => ($wasrev ? "bulkrev" : "bulkdomain")) unless $webvar{okdel} eq 'y'; 1155 1156 changepage(page => "domlist", errmsg => "You are not permitted to make bulk zone changes") 1157 unless ($permissions{admin} || $permissions{domain_edit} || $permissions{domain_create} || $permissions{domain_delete}); 1158 1117 1159 # per-action scope checks 1118 1160 if ($webvar{bulkaction} eq 'move') { 1119 changepage(page => "domlist", errmsg => "You are not permitted to bulk-move domains")1161 changepage(page => "domlist", errmsg => "You are not permitted to bulk-move zones") 1120 1162 unless ($permissions{admin} || ($permissions{domain_edit} && $permissions{domain_create} && $permissions{domain_delete})); 1121 1163 my $newgname = $dnsdb->groupName($webvar{destgroup}); 1122 1164 $page->param(action => "Move to group $newgname"); 1123 1165 } elsif ($webvar{bulkaction} eq 'deactivate' || $webvar{bulkaction} eq 'activate') { 1124 changepage(page => "domlist", errmsg => "You are not permitted to bulk-$webvar{bulkaction} domains")1166 changepage(page => "domlist", errmsg => "You are not permitted to bulk-$webvar{bulkaction} zones") 1125 1167 unless ($permissions{admin} || $permissions{domain_edit}); 1126 $page->param(action => "$webvar{bulkaction} domains");1168 $page->param(action => "$webvar{bulkaction} zones"); 1127 1169 } elsif ($webvar{bulkaction} eq 'delete') { 1128 changepage(page => "domlist", errmsg => "You are not permitted to bulk-delete domains")1170 changepage(page => "domlist", errmsg => "You are not permitted to bulk-delete zones") 1129 1171 unless ($permissions{admin} || $permissions{domain_delete}); 1130 $page->param(action => "$webvar{bulkaction} domains");1172 $page->param(action => "$webvar{bulkaction} zones"); 1131 1173 } else { 1132 1174 # unknown action, bypass actually doing anything. it should not be possible in … … 1139 1181 # order here, and since we don't have the domain names until we go around this 1140 1182 # loop, we can't alpha-sort them here. :( 1141 foreach (keys %webvar) {1183 foreach my $input (keys %webvar) { 1142 1184 my %row; 1143 next unless $_ =~ /^dom_\d+$/; 1185 next unless $input =~ /^(dom|rev)_\d+$/; 1186 my $fr = $1; 1144 1187 # second security check - does the user have permission to meddle with this domain? 1145 if (!check_scope(id => $webvar{$ _}, type => 'domain')) {1146 $row{domerr} = "You are not permitted to make changes to the requested domain";1147 $row{domain} = $webvar{$ _};1188 if (!check_scope(id => $webvar{$input}, type => ($fr eq 'dom' ? 'domain' : 'revzone'))) { 1189 $row{domerr} = "You are not permitted to make changes to the requested zone"; 1190 $row{domain} = $webvar{$input}; 1148 1191 push @bulkresults, \%row; 1149 1192 next; 1150 1193 } 1151 $row{domain} = $dnsdb->domainName($webvar{$_});1194 $row{domain} = ($fr eq 'dom' ? $dnsdb->domainName($webvar{$input}) : $dnsdb->revName($webvar{$input})); 1152 1195 1153 1196 # Do the $webvar{bulkaction} 1154 1197 my ($code, $msg); 1155 ($code, $msg) = $dnsdb->changeGroup( 'domain', $webvar{$_}, $webvar{destgroup})1198 ($code, $msg) = $dnsdb->changeGroup(($fr eq 'dom' ? 'domain' : 'revzone'), $webvar{$input}, $webvar{destgroup}) 1156 1199 if $webvar{bulkaction} eq 'move'; 1157 1200 if ($webvar{bulkaction} eq 'deactivate' || $webvar{bulkaction} eq 'activate') { 1158 my $stat = $dnsdb->zoneStatus($webvar{$_}, 'n', ($webvar{bulkaction} eq 'activate' ? 'domon' : 'domoff')); 1201 my $stat = $dnsdb->zoneStatus($webvar{$input}, ($fr eq 'dom' ? 'n' : 'y'), 1202 ($webvar{bulkaction} eq 'activate' ? 'domon' : 'domoff')); 1159 1203 $code = (defined($stat) ? 'OK' : 'FAIL'); 1160 1204 $msg = (defined($stat) ? $DNSDB::resultstr : $DNSDB::errstr); 1161 1205 } 1162 ($code, $msg) = $dnsdb->delZone($webvar{$ _}, 'n')1206 ($code, $msg) = $dnsdb->delZone($webvar{$input}, ($fr eq 'dom' ? 'n' : 'y')) 1163 1207 if $webvar{bulkaction} eq 'delete'; 1164 1208 … … 1190 1234 ($permissions{self_edit} && $webvar{id} == $session->param('uid')) )) { 1191 1235 my $stat = $dnsdb->userStatus($webvar{id}, $webvar{userstatus}); 1236 # kick user out if user disabled self 1237 # arguably there should be a more specific error message for this case 1238 changepage(page=> 'login', sessexpired => 1) if $webvar{id} == $session->param('uid'); 1192 1239 $page->param(resultmsg => $DNSDB::resultstr); 1193 1240 } else { … … 1246 1293 } else { 1247 1294 1248 # assemble a permission string - far simpler than trying to pass an 1249 # indeterminate set of permission flags individually 1250 1251 # But first, we have to see if the user can add any particular 1252 # permissions; otherwise we have a priviledge escalation. Whee. 1253 1295 my $permstring = 'i'; # start with "inherit" 1296 1297 # Remap passed checkbox states from webvar to integer/boolean values in %newperms 1298 foreach (@permtypes) { 1299 $newperms{$_} = (defined($webvar{$_}) && $webvar{$_} eq 'on' ? 1 : 0); 1300 } 1301 1302 # Check for chained permissions. Some permissions imply others; make sure they get set. 1303 foreach (keys %permchains) { 1304 if ($newperms{$_} && !$newperms{$permchains{$_}}) { 1305 $newperms{$permchains{$_}} = 1; 1306 } 1307 } 1308 1309 # check for possible priviledge escalations 1254 1310 if (!$permissions{admin}) { 1255 my %grpperms; 1256 $dnsdb->getPermissions('group', $curgroup, \%grpperms); 1257 my $ret = comparePermissions(\%permissions, \%grpperms); 1258 if ($ret eq '<' || $ret eq '!') { 1259 # User's permissions are not a superset or equivalent to group. Can't inherit 1260 # (and include access user doesn't currently have), so we force custom. 1311 if ($webvar{perms_type} eq 'inherit') { 1312 # Group permissions are only relevant if inheriting 1313 my %grpperms; 1314 $dnsdb->getPermissions('group', $curgroup, \%grpperms); 1315 my $ret = $dnsdb->comparePermissions(\%permissions, \%grpperms); 1316 if ($ret eq '<' || $ret eq '!') { 1317 # User's permissions are not a superset or equivalent to group. Can't inherit 1318 # (and include access user doesn't currently have), so we force custom. 1319 $webvar{perms_type} = 'custom'; 1320 $alterperms = 1; 1321 } 1322 } 1323 my $ret = $dnsdb->comparePermissions(\%newperms, \%permissions); 1324 if ($ret eq '>' || $ret eq '!') { 1325 # User's new permissions are not a subset or equivalent to previous. Can't add 1326 # permissions user doesn't currently have, so we force custom. 1261 1327 $webvar{perms_type} = 'custom'; 1262 1328 $alterperms = 1; … … 1264 1330 } 1265 1331 1266 my $permstring; 1332 ##fixme: 1333 # could possibly factor building the meat of the permstring out of this if/elsif set, so 1334 # as to avoid running around @permtypes quite so many times 1267 1335 if ($webvar{perms_type} eq 'custom') { 1268 1336 $permstring = 'C:'; … … 1270 1338 if ($permissions{admin} || $permissions{$_}) { 1271 1339 $permstring .= ",$_" if defined($webvar{$_}) && $webvar{$_} eq 'on'; 1272 $newperms{$_} = (defined($webvar{$_}) && $webvar{$_} eq 'on' ? 1 : 0); 1340 } else { 1341 $newperms{$_} = 0; # remove permissions user doesn't currently have 1273 1342 } 1274 1343 } … … 1278 1347 $dnsdb->getPermissions('user', $webvar{clonesrc}, \%newperms); 1279 1348 $page->param(perm_clone => 1); 1280 } else {1281 $permstring = 'i';1282 1349 } 1283 # "Chained" permissions. Some permissions imply others; make sure they get set. 1350 # Recheck chained permissions, in the supposedly impossible case that the removals 1351 # above mangled one of them. This *should* be impossible via normal web UI operations. 1284 1352 foreach (keys %permchains) { 1285 1353 if ($newperms{$_} && !$newperms{$permchains{$_}}) { … … 1311 1379 $webvar{fname}, $webvar{lname}, $webvar{phone}); 1312 1380 if ($code eq 'OK') { 1313 $newperms{admin} = 1 if $ webvar{accttype} eq 'S';1381 $newperms{admin} = 1 if $permissions{admin} && $webvar{accttype} eq 'S'; 1314 1382 ($code2,$msg2) = $dnsdb->changePermissions('user', $webvar{uid}, \%newperms, ($permstring eq 'i')); 1315 1383 } … … 1461 1529 my %pageparams = (page => "loclist", id => $webvar{parentid}, 1462 1530 defrec => $webvar{defrec}, revrec => $webvar{revrec}); 1463 $pageparams{warnmsg} = $msg."<br ><br>\n".$DNSDB::resultstr if $code eq 'WARN';1531 $pageparams{warnmsg} = $msg."<br />\n".$DNSDB::resultstr if $code eq 'WARN'; 1464 1532 $pageparams{resultmsg} = $DNSDB::resultstr if $code eq 'OK'; 1465 1533 changepage(%pageparams); … … 1818 1886 $page->param(whereami => $uri_self); 1819 1887 # fill in general URL-to-self 1820 $page->param(script_self => "$ENV{SCRIPT_NAME}?" .($curgroup ? "curgroup=$curgroup" : ''));1888 $page->param(script_self => "$ENV{SCRIPT_NAME}?"); 1821 1889 } 1822 1890 … … 2047 2115 $page->param(name => ($webvar{name} ? $webvar{name} : $domroot)); 2048 2116 my $zname = ($webvar{defrec} eq 'y' ? 'ZONE' : $dnsdb->revName($webvar{parentid}, 'y')); 2049 my $cidr = new NetAddr::IP $zname;2050 2117 $zname =~ s|\d*/\d+$||; 2051 2118 $page->param(address => ($webvar{address} ? $webvar{address} : $zname)); 2052 2119 $page->param(typelist => $dnsdb->getTypelist($webvar{revrec}, 2053 $webvar{type} || ($ cidr->{isv6}? $reverse_typemap{'AAAA+PTR'} : $reverse_typemap{'A+PTR'})));2120 $webvar{type} || ($zname =~ /:/ ? $reverse_typemap{'AAAA+PTR'} : $reverse_typemap{'A+PTR'}))); 2054 2121 } 2055 2122 # retrieve the right ttl instead of falling (way) back to the hardcoded system default
Note:
See TracChangeset
for help on using the changeset viewer.