Script to view dbm'ized users file

John Storms (jstorms@livingston.com)
Thu, 07 Aug 1997 14:32:21 -0700

At 12:45 PM 8/7/97 -0500, Larry Vaden wrote:
>Do you know of any perl fragments to deal with the users file in flat ascii
>or db mode?
>
>I'm putting together a web based registration page (adds are easy), but
>would like to have change and delete functions available for internal use.
>
>I've looked around on the net and not found anything.

Here's a PERL script that will display the contents of a dbm'ized users file.

#!/usr/local/bin/perl

############################################################
#### dbmdump.pl
#### This PERL script reads a RADIUS users database, formats
#### the output and displays it to standard out.
#### John Storms, August 7, 1997
############################################################

## Semi-Constants
$USERFILE = "users";
$PERMISSION = "0644";
$DBMERROR = "ERROR! Cannot open dbm file:";
$CHAR_CR = "\n";
$CHAR_TAB = "\t";
$CHAR_COMMA = ",";
$CHAR_SPACE = " ";

############################################################
#### OPEN USERS DATABASE
############################################################
dbmopen(%RADIUS, $USERFILE, $PERMISSION) || die $DBMERROR;

############################################################
#### LOOP THROUGH DATABASE ARRAY & DISPLAY USER PROFILES
############################################################
while(($username, $vectors) = each(%RADIUS)) {
# Initialize Check Vector Flag
$flag = 0;

# Display Username
print "$CHAR_CR$CHAR_CR$username";

# Split up attribute/value data by using a comma as the deliminator
@vreply = split(/$CHAR_COMMA/,$vectors);

# Loop through each comman deliminated item
for($i=0;$i<@vreply;$i++) {

# If this isn't the last check item add a comma
if($i != @vreply-1) {
$vreply[$i] = $vreply[$i].$CHAR_COMMA;
}

# Split up each comma separated line into lines using a RETURN
# as the deliminator
@elements = split(/$CHAR_CR/, $vreply[$i]);

# Loop through each line
for($j=0;$j<@elements;$j++) {

# CASE WHEN ATTR/VALUE IS AN ADDITIONAL CHECK ITEM
if(substr($elements[$j],0,1) eq $CHAR_SPACE) {
print $CHAR_SPACE;
}
# CASE WHEN ATTR/VALUE IS FIRST CHECK ITEM
elsif($i == 0 && $flag ne 1) {
print "$CHAR_TAB";
$flag = 1;
}
# CASE WHEN ATTR/VALUE IS A REPLY ITEM
else {
print "$CHAR_CR$CHAR_TAB";
}

# Display Attriubute/Value pair
print $elements[$j];
}
}
}

############################################################
### CLOSE USERS DATABASE
############################################################
dbmclose(%RADIUS);

---
jstorms@livingston.com
Diplomacy:  The art of saying good doggie
while seaching for a big rock.