Changeset 401 for trunk/DNSDB.pm


Ignore:
Timestamp:
10/03/12 18:17:51 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Begin updating dns-rpc.cgi. See #43.

Add initRPC() in DNSDB.pm. This sets up the userdata needed
for logging. Prevent the pseudousers added in initRPC() from
being displayed in the user management UI. Sooner or later
this will need to be cleaned up so stale users can be deleted.
Closes #33.

Bring a bit more consistency to error messages, and eliminate
references to odd depths of the code, by adding "\n" to the end
of a few lurking die strings in DNSDB.pm, and all method-sub ones
in dns-rpc.cgi.

Clean up a handful of gross syntax and scope errors from copy-paste
work apparently never checked.

Call new loadConfig() and initRPC() on startup. Add a utility sub
to call from the method subs to check the RPC caller+IP pair against
the new config option.

Update call for delDomain to delZone. Update call to getDomRecs()
to match normalized hash-argument form from r397.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r400 r401  
    14071407
    14081408
     1409## DNSDB::initRPC()
     1410# Takes a database handle, remote username, and remote fullname.
     1411# Sets up the RPC logging-pseudouser if needed.
     1412# Sets the %userdata hash for logging.
     1413# Returns undef on failure
     1414sub initRPC {
     1415  my $dbh = shift;
     1416  my %args  = @_;
     1417
     1418  return if !$args{username};
     1419  return if !$args{fullname};
     1420
     1421  %userdata = %{$dbh->selectrow_hashref("SELECT user_id,group_id,firstname,lastname,status FROM users".
     1422        " WHERE username=?", undef, ($args{username}) )};
     1423  if (!%userdata) {
     1424    $dbh->do("INSERT INTO users (username,password,firstname,type) VALUES (?,'RPC',?,'R')", undef,
     1425        ($args{username}, $args{fullname}) );
     1426    %userdata = %{$dbh->selectrow_hashref("SELECT user_id,group_id,firstname,lastname,status FROM users".
     1427        " WHERE username=?", undef, ($args{username}) )};
     1428  }
     1429  $userdata{fullname} = "$userdata{firstname} $userdata{lastname}/$args{rpcsys}";
     1430  return 1 if %userdata;
     1431} # end initRPC()
     1432
     1433
    14091434## DNSDB::login()
    14101435# Takes a database handle, username and password
     
    25852610
    25862611# Permissions!  Gotta set'em all!
    2587     die "Invalid permission string $permstring"
     2612    die "Invalid permission string $permstring\n"
    25882613        if $permstring !~ /^(?:
    25892614                i       # inherit
     
    27032728        ($args{startwith} ? " AND u.username ~* ?" : '').
    27042729        ($args{filter} ? " AND u.username ~* ?" : '').
     2730        " AND NOT u.type = 'R' ".
    27052731        " ORDER BY $args{sortby} $args{sortorder} ".
    27062732        ($args{offset} eq 'all' ? '' : " LIMIT $config{perpage} OFFSET ".$args{offset}*$config{perpage});
     
    42254251          # revzones have records more or less reversed from forward zones.
    42264252          my ($tmpcode,$tmpmsg) = _zone2cidr($host);
    4227           die "Error converting NS record: $tmpmsg" if $tmpcode eq 'FAIL';      # hmm.  may not make sense...
     4253          die "Error converting NS record: $tmpmsg\n" if $tmpcode eq 'FAIL';    # hmm.  may not make sense...
    42284254          $val = "$tmpmsg";
    42294255          $host = $rr->nsdname;
Note: See TracChangeset for help on using the changeset viewer.