Ignore:
Timestamp:
06/23/14 17:52:37 (11 years ago)
Author:
Kris Deugau
Message:

/branches/stable

Subtle bugfix merge! All changes from /trunk r589 through r648 merged.

Location:
branches/stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/stable

  • branches/stable/dns.cgi

    r587 r649  
    9797        or die CGI::Session->errstr();
    9898
    99 if (!$sid || $session->is_expired) {
     99if (!$sid || $session->is_expired || !$session->param('uid') || !$dnsdb->userStatus($session->param('uid')) ) {
    100100  $webvar{page} = 'login';
    101101} else {
     
    219219my $sesscookie = $q->cookie( -name => 'dnsadmin_session',
    220220        -value => $sid,
    221 #        -expires => "+".$dnsdb->{timeout},
     221        -expires => "+".$dnsdb->{timeout},
    222222        -secure => 0,
    223223## fixme:  need to extract root path for cookie, so as to limit cookie to dnsadmin instance
     
    242242      $sesscookie = $q->cookie( -name => 'dnsadmin_session',
    243243        -value => $sid,
    244 #        -expires => "+".$dnsdb->{timeout},
     244        -expires => "+".$dnsdb->{timeout},
    245245        -secure => 0,
    246246## fixme:  need to extract root path for cookie, so as to limit cookie to dnsadmin instance
     
    254254      $session->param('uid',$userdata->{user_id});
    255255      $session->param('username',$webvar{username});
     256      $curgroup = $userdata->{group_id};
    256257
    257258# for reference.  seems we don't need to set these on login any more.
     
    742743      my %pageparams = (page => "reclist", id => $webvar{parentid},
    743744        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';
    745746      $pageparams{resultmsg} = $DNSDB::resultstr if $code eq 'OK';
    746747      changepage(%pageparams);
     
    801802      my %pageparams = (page => "reclist", id => $webvar{parentid},
    802803        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';
    804805      $pageparams{resultmsg} = $DNSDB::resultstr if $code eq 'OK';
    805806      changepage(%pageparams);
     
    10761077  fill_permissions($page, \%grpperms);
    10771078
    1078 } elsif ($webvar{page} eq 'bulkdomain') {
     1079} elsif ($webvar{page} eq 'bulkdomain' || $webvar{page} eq 'bulkrev') {
    10791080  # 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")
    10841083        unless ($permissions{admin} || $permissions{domain_edit} || $permissions{domain_create} || $permissions{domain_delete});
    10851084
    10861085  fill_grouplist("grouplist");
    10871086
    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);
    10891091
    10901092  $page->param(curpage => $webvar{page});
     
    10931095  $page->param(perpage => $perpage);
    10941096
    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);
    10961099  my $rownum = 0;
    10971100  foreach my $dom (@{$domlist}) {
    10981101    delete $dom->{status};
    10991102    delete $dom->{group};
    1100     $dom->{newrow} = (++$rownum) % 5 == 0;
     1103    $dom->{newrow} = (++$rownum) % 5 == 0 && $rownum != $perpage;
    11011104  }
    11021105
     
    11071110  $page->param(maydelete => $permissions{admin} || $permissions{domain_delete});
    11081111
     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
    11091144} elsif ($webvar{page} eq 'bulkchange') {
    11101145
     
    11151150  }
    11161151
     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
    11171159  # per-action scope checks
    11181160  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")
    11201162        unless ($permissions{admin} || ($permissions{domain_edit} && $permissions{domain_create} && $permissions{domain_delete}));
    11211163    my $newgname = $dnsdb->groupName($webvar{destgroup});
    11221164    $page->param(action => "Move to group $newgname");
    11231165  } 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")
    11251167        unless ($permissions{admin} || $permissions{domain_edit});
    1126     $page->param(action => "$webvar{bulkaction} domains");
     1168    $page->param(action => "$webvar{bulkaction} zones");
    11271169  } 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")
    11291171        unless ($permissions{admin} || $permissions{domain_delete});
    1130     $page->param(action => "$webvar{bulkaction} domains");
     1172    $page->param(action => "$webvar{bulkaction} zones");
    11311173  } else {
    11321174    # unknown action, bypass actually doing anything.  it should not be possible in
     
    11391181  # order here, and since we don't have the domain names until we go around this
    11401182  # loop, we can't alpha-sort them here.  :(
    1141   foreach (keys %webvar) {
     1183  foreach my $input (keys %webvar) {
    11421184    my %row;
    1143     next unless $_ =~ /^dom_\d+$/;
     1185    next unless $input =~ /^(dom|rev)_\d+$/;
     1186    my $fr = $1;
    11441187    # 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};
    11481191      push @bulkresults, \%row;
    11491192      next;
    11501193    }
    1151     $row{domain} = $dnsdb->domainName($webvar{$_});
     1194    $row{domain} = ($fr eq 'dom' ? $dnsdb->domainName($webvar{$input}) : $dnsdb->revName($webvar{$input}));
    11521195
    11531196    # Do the $webvar{bulkaction}
    11541197    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})
    11561199        if $webvar{bulkaction} eq 'move';
    11571200    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'));
    11591203      $code = (defined($stat) ? 'OK' : 'FAIL');
    11601204      $msg = (defined($stat) ? $DNSDB::resultstr : $DNSDB::errstr);
    11611205    }
    1162     ($code, $msg) = $dnsdb->delZone($webvar{$_}, 'n')
     1206    ($code, $msg) = $dnsdb->delZone($webvar{$input}, ($fr eq 'dom' ? 'n' : 'y'))
    11631207        if $webvar{bulkaction} eq 'delete';
    11641208
     
    11901234        ($permissions{self_edit} && $webvar{id} == $session->param('uid')) )) {
    11911235      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');
    11921239      $page->param(resultmsg => $DNSDB::resultstr);
    11931240    } else {
     
    12461293    } else {
    12471294
    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
    12541310      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.
    12611327          $webvar{perms_type} = 'custom';
    12621328          $alterperms = 1;
     
    12641330      }
    12651331
    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
    12671335      if ($webvar{perms_type} eq 'custom') {
    12681336        $permstring = 'C:';
     
    12701338          if ($permissions{admin} || $permissions{$_}) {
    12711339            $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
    12731342          }
    12741343        }
     
    12781347        $dnsdb->getPermissions('user', $webvar{clonesrc}, \%newperms);
    12791348        $page->param(perm_clone => 1);
    1280       } else {
    1281         $permstring = 'i';
    12821349      }
    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.
    12841352      foreach (keys %permchains) {
    12851353        if ($newperms{$_} && !$newperms{$permchains{$_}}) {
     
    13111379                $webvar{fname}, $webvar{lname}, $webvar{phone});
    13121380        if ($code eq 'OK') {
    1313           $newperms{admin} = 1 if $webvar{accttype} eq 'S';
     1381          $newperms{admin} = 1 if $permissions{admin} && $webvar{accttype} eq 'S';
    13141382          ($code2,$msg2) = $dnsdb->changePermissions('user', $webvar{uid}, \%newperms, ($permstring eq 'i'));
    13151383        }
     
    14611529      my %pageparams = (page => "loclist", id => $webvar{parentid},
    14621530        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';
    14641532      $pageparams{resultmsg} = $DNSDB::resultstr if $code eq 'OK';
    14651533      changepage(%pageparams);
     
    18181886  $page->param(whereami => $uri_self);
    18191887# 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}?");
    18211889}
    18221890
     
    20472115    $page->param(name   => ($webvar{name} ? $webvar{name} : $domroot));
    20482116    my $zname = ($webvar{defrec} eq 'y' ? 'ZONE' : $dnsdb->revName($webvar{parentid}, 'y'));
    2049     my $cidr = new NetAddr::IP $zname;
    20502117    $zname =~ s|\d*/\d+$||;
    20512118    $page->param(address        => ($webvar{address} ? $webvar{address} : $zname));
    20522119    $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'})));
    20542121  }
    20552122# retrieve the right ttl instead of falling (way) back to the hardcoded system default
Note: See TracChangeset for help on using the changeset viewer.