Gossamer Forum
Home : Products : DBMan : Customization :

Work Around / Admin - Help!!

(Page 1 of 4)
> >
Quote Reply
Work Around / Admin - Help!!
<input type=submit name=userdetails value="Get Dealer Details" onSubmit="http://192.172.1.99/imvda/db.cgi?db=user&uid=$username&view_records=1">

I want to have a button like the one above on the admin page so you can check the users details in user.cfg before you remove the user and all their details/records.

Can someone please help me with this asap.

Quote Reply
Re: Work Around / Admin - Help!! In reply to
Just to explain it a little more. You would select a user in the drop down menu and then click the "Get Dealer Details" button and it would display the users details (in user.cfg).

Quote Reply
Re: Work Around / Admin - Help!! In reply to
What's wrong with the "Inquire" button?

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Work Around / Admin - Help!! In reply to
The inquire button only shows the "password though". I want it to shown all the users details as well from the (users.db/users.cfg) file.

Quote Reply
Re: Work Around / Admin - Help!! In reply to
If the "inquire" button could show all that information, that would be great.

Quote Reply
Re: Work Around / Admin - Help!! In reply to
Ahh OK, I see. Sorry, I didn't realise you had more information in your .cfg file.
(BTW: by users.cfg, I take it this is the same as users.pass?)

What you can do, is edit the Admin function so that pressing "Inquire" pulls out more than just the password for the selected user.

It's quite simple, you just need to make a few changes to sub admin_display in db.cgi.
(for this example, I'll assume that you have 2 extra fields in your users.cfg file - "first name" and "last name")

1) Find the lines:
# If we are inquiring, let's look for the specified user.
my (@data, $user_list, $perm, $password);


And add in some new variables for each value. eg:
# If we are inquiring, let's look for the specified user.
my (@data, $user_list, $perm, $password, $first_name, $last_name);


2) Find the green code and add the red code:
Code:
if ($in{'inquire'} and ($in{'username'} eq $data[0])) {
$user_list .= qq~<option value="$data[0]" SELECTED>$data[0]</option>\n~;
$perm = qq|
View <input type=checkbox name="per_view" value="1" |; ($data[2] and $perm .= "CHECKED"); $perm .= qq|>
Add <input type=checkbox name="per_add" value="1" |; ($data[3] and $perm .= "CHECKED"); $perm .= qq|>
Delete <input type=checkbox name="per_del" value="1" |; ($data[4] and $perm .= "CHECKED"); $perm .= qq|>
Modify <input type=checkbox name="per_mod" value="1" |; ($data[5] and $perm .= "CHECKED"); $perm .= qq|>
Admin <input type=checkbox name="per_admin" value="1" |; ($data[6] and $perm .= "CHECKED"); $perm .= qq|>|;
$password = $data[1];

open (PASS, "<users.cfg") or &cgierr ("unable to open: users.cfg.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
my @user_data = <PASS>;
close PASS;

foreach $line (@user_data) {
@user_info = split(/\|/, $line);
last if ($user_info[0] eq $password);
}

$first_name = $user_info[1];
$last_name = $user_info[2];

}
3) Find the line:
&html_admin_display ($message, $user_list, $password, $perm);

And as in step 1, add the variables:
&html_admin_display ($message, $user_list, $password, $perm, $first_name, $last_name);

That's it for db.cgi, now just one quick change to sub html_admin_display in html.pl:

Find the line:
my ($message, $user_list, $password, $permissions) = @_;

And once again, add the variables:
my ($message, $user_list, $password, $permissions, $first_name, $last_name) = @_;


Now you can add some extra HTML to the same sub-routine, eg:
print qq|
First Name: $first_name
Last Name: $last_name
|;



I hope this is what you we're looking to do. At the moment, the changes are only good for getting the values from users.cfg (not the database as well), with some additional editing, you could make extra INPUT boxes and change these values via the Admin form.

Good luck! Let me know if you run into trouble.

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Work Around / Admin - Help!! In reply to
I have the following files in my database:

db.cgi
user.cfg
item.cfg
user.db
item.db
default.pass
format.pl
auth.pl

I'm wanting to get all the data from users.cfg displayed and all the data from default.pass displayed on the admin page.

Thanks so much for doing that for me. I can't say thankyou enough!!

Can I change it so that I can have as many fields as possible displaying instead of just two?
I have about 10 I want displayed as well as the username and password.

In the code below is the [7] part the location of the field in users.cfg?

$first_name = $data[7];
$last_name = $data[8];}

I'll try out the code in the morning and let you know whether I was successfull or not.

Thanks again Mark!!!!

Quote Reply
Re: Work Around / Admin - Help!! In reply to
Ok, hold up! Smile

Sorry, I mis-interepreted the problem, I thought you had just re-nammed "default.pass" to "users.cfg", and wrote the code accordingly.

Don't use what I've posted (yet), I'll have to tweak the code a bit before it will work. I'll update it and let you know, I should have something for you tomorrow. Sorry for the confusion.

Regards,

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Work Around / Admin - Help!! In reply to
Oh ok.

I don't explain things very well do I :(

Thanks for bearing with me!! :)

Quote Reply
Re: Work Around / Admin - Help!! In reply to
Another thing I want to have in the "admin display" procedure is instead of having the select box showing all the users usernames it shows all the users passwords in the drop down select box.

Quote Reply
Re: Work Around / Admin - Help!! In reply to
Just to let you know that I'll be also adding the mod below to the admin section:

-----
http://webmagic.hypermart.net/dbman/

Deleting user records in relational database
===============================================

Thread reference: http://gossamer-threads.com/p/001153
Topic: Deleting user records in relational database
fharris - posted October 05, 1999 06:52 AM PST
------------------------------------------------------------------------------------
Question:

I have setup two seperate databases: a "user" and "item" database.
Since there are actually two different places to store user information (default.pass) and (user.db),
I'm interested to know how I can remove a user from both of these files using the "Admin" menu?

Currently when I remove a user, it only affects the default.pass file.
-----------------------------------
Response:

You would want to delete the user's info from the .pass file, the user.db file and anything in the item.db file, wouldn't you?

This one's gonna take me a little while. I've got a list where I keep "pending" mods (I kept forgetting! ), so I'll add this to the list and get back to you as soon as I can.
-----------------------------------
Question:

*smiles* sorry to keep filling up your plate with these little projects, but I do appreciate your time.
I suppose I would want to remove the user information from both databases, including the .pass file.
Let me know what you come up with.
-----------------------------------
Response:

First, I seem to recall you said that the $auth_user_field was in a different position in the two databases.
If that's true, you need to add lines to the switch_to subroutines:

code: $auth_user_field = #;

Naturally, you would replace # with the appropriate number for each of the configurations.

Then you need to replace some of the code in db.cgi, sub admin_display.
I've included the comment lines that are in the original to help you find the appropriate place.

code:

# If we've been passed in delete, then we are removing a user.
Check to make sure a user was selected then try and remove him.
###########################
$in{'delete'} and do {
unless ($in{'username'}) {
$message = "No username selected to delete.";
last CASE;
}
open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1) }
@lines = <PASS>;
close PASS;

open (PASS, ">$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) {
flock(PASS, 2) or &cgierr("unable to get exclusive lock on $auth_pw_file.\nReason: $!");
}
my $found = 0;
foreach $line (@lines) {
($line =~ /^$in{'username'}:/) ?
($found = 1) :
print PASS $line;
}
close PASS;
if ($found) {
$message = "User: $in{'username'} deleted.";
&switch_to_user;
open (DB, "<$db_file_name") or &cgierr("unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;

LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { $output .= $line; next LINE; }
chomp ($line);
@data = &split_decode($line);

unless ($data[$auth_user_field] eq $in{'username'}) {
$output .= $line . "\n";
}
}
open (DB, ">$db_file_name") or &cgierr("unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_name.\nReason: $!");
}
print DB $output;
close DB; # automatically removes file lock

$output = '';
&switch_to_item;
open (DB, "<$db_file_name") or &cgierr("unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;

LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { $output .= $line; next LINE; }
chomp ($line);
@data = &split_decode($line);

unless ($data[$auth_user_field] eq $in{'username'}) {
$output .= $line . "\n";
}
}
open (DB, ">$db_file_name") or &cgierr("unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_name.\nReason: $!");
}
print DB $output;
close DB; # automatically removes file lock

}
else {
$message = "Unable to find userid: $in{'username'} in password file.";
}
last CASE;
};
# If we have a username, and the admin didn't press inquire, then
################

I've only checked it for syntax errors, so be sure you back up all your data before you try this!
-----------------------------------
Question:

Carol, It worked like a charm! I appreciate the help on this!

Thanks, Frank


Quote Reply
Re: Work Around / Admin - Help!! In reply to
Ok, I've put something together, and thankfully it only affects step 2 of my code.

But before I post it, I just need a few details:
- How is the data stored in users.cfg? (pipe delimited? etc...)
- Is the Username stored in users.cfg?
- And if so, where?

Oh, and that MOD you have can be installed no problems, we're editing the "Inquire" section, where as that MOD is for the "Delete" section.

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Work Around / Admin - Help!! In reply to
Cool

Yes it's pipe delimited.

No the username is not stored in users.cfg. Does it need to be?

Here is a copy of .cfg:

%db_def = (
'UserID' => [0, 'alpha', 20, 255, 1, '', ''],
'Ref' => [1, 'alpha', 20, 30, 1, '', ''],
'CompanyName' => [2, 'alpha', 20, 50, 1, '', ''],
'PhysicalAddress' => [3, 'alpha', 40x3, 255, 0, '', ''],
'PostalAddress' => [4, 'alpha', 40x3, 255, 0, '', ''],
'Region' => [5, 'alpha', 20, 255, 1, '', ''],
'DealerDescription' => [6, 'alpha', 40x3, 255, 0, '', ''],
'Phone' => [7, 'alpha', 20, 15, 0, '', ''],
'Fax' => [8, 'alpha', 20, 15, 0, '', ''],
'CellPhone' => [9, 'alpha', 20, 15, 0, '', ''],
'Email' => [10, 'alpha', 20, 60, 0, '', '.+@.+..+'],
'Website' => [11, 'alpha', 20, 60, 0, 'http://', ''],
'DealerFilename' => [12, 'alpha', 0, 255, 0, '', ''],
'DealerGraphic' => [13, 'alpha', 0, 3, 0, '', 'Yes']
);

Sweet. Thanks so much for this!! Really is appreciated.



Quote Reply
Re: Work Around / Admin - Help!! In reply to
In Reply To:
No the username is not stored in users.cfg. Does it need to be?
No, not neccessarily, but we do need some common link between default.pass and users.cfg.

For example, if we pull up the user information for "Fred" from default.pass, how will we know which line in users.cfg has Fred's information?

Just need that common field, then we're home free Smile

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Work Around / Admin - Help!! In reply to
What could I do so there is a common link between the two? Where should I add an extra field? In the signup process?

Quote Reply
Re: Work Around / Admin - Help!! In reply to
Hang on, There is a link between the two. The "password" field and the "Ref" field have exactly the same value in them, e.g. 1111. That should make things easier.

Quote Reply
Re: Work Around / Admin - Help!! In reply to
Remember that instead of having a drop down box of "users" I want that replaced with a drop down box of "passwords".

Just thought I'd let you know now.

Quote Reply
Re: Work Around / Admin - Help!! In reply to
In Reply To:
Hang on, There is a link between the two. The "password" field and the "Ref" field have exactly the same value in them, e.g. 1111. That should make things easier.
That will do perfectly Smile

Ok, I've updated the code in my previous post and It's ready to go.

I've bolded a few Items in red, these are things you'll need to change:
- users.cfg only if you have a variable like $user_file or something...
- 0 replace with the position of the password in users.cfg
- 1, 2 replace with the fields respective position

(remember, postitions start from "0")


In Reply To:
Remember that instead of having a drop down box of "users" I want that replaced with a drop down box of "passwords".
Ok that's easy to fix.

if ($in{'inquire'} and ($in{'username'} eq $data[0])) {
$user_list .= qq~<option value="$data[0]" SELECTED>$data[1]</option>\n~;

and

else {
$user_list .= qq~<option value="$data[0]">$data[1]</option>\n~;



That should do it. Let me know how it all goes.

Good luck!

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Work Around / Admin - Help!! In reply to
Hi Mark,

Thanks very much for all your help!!

I have to wait until next Tuesday before I can try out your code because I don't have access to a pc over the long weekend (Labour weekend here in NZ).

I'll let you know how I get on Tuesday.

Thanks again.

Quote Reply
Re: Work Around / Admin - Help!! In reply to
With the green code you listed it isn't in my admin_display procedure... Can you tell me where it is:

---
sub admin_display {
# --------------------------------------------------------
# Let's an admin add/update/remove users from the authorization file.
#
my ($message, @lines, $line);

# Do we have anything to do?
CASE: {
# If we've been passed in new_username, then we are adding a new user. Do
# some basic error checking and then add him into the password file.
$in{'new_username'} and do {
unless ((length($in{'new_username'}) >= 3) and (length($in{'new_username'}) <= 30) and ($in{'new_username'} =~ /^[a-zA-Z0-9]+$/)) {
$message = "Invalid username: $in{'new_username'}. Must only contain letters and numbers and be less then 12 and greater then 3 characters.";
last CASE;
}
unless ((length($in{'password'}) >= 3) and (length($in{'password'}) <= 30)) {
$message = "Invalid password: '$in{'password'}'. Must be less then 12 and greater then 3 characters.";
last CASE;
}
open (PASS, ">>$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) {
flock(PASS, 2) or &cgierr("unable to get exclusive lock on $auth_pw_file.\nReason: $!");
}
my @salt_chars = ('A' .. 'Z', 0 .. 9, 'a' .. 'z', '.', '/');
my $salt = join '', @salt_chars[rand 64, rand 64];
my $encrypted = crypt($in{'password'}, $salt);
print PASS "$in{'new_username'}:$in{'password'}:$in{'per_view'}:$in{'per_add'}:$in{'per_del'}:$in{'per_mod'}:$in{'per_admin'}\n";
close PASS;
$message = "User: $in{'new_username'} created.";
last CASE;
};
# If we've been passed in delete, then we are removing a user. Check
# to make sure a user was selected then try and remove him.
$in{'delete'} and do {
unless ($in{'username'}) {
$message = "No username selected to delete.";
last CASE;
}
open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1) }
@lines = <PASS>;
close PASS;

open (PASS, ">$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) {
flock(PASS, 2) or &cgierr("unable to get exclusive lock on $auth_pw_file.\nReason: $!");
}
my $found = 0;
foreach $line (@lines) {
($line =~ /^$in{'username'}:/) ?
($found = 1) :
print PASS $line;
}
close PASS;
$found ?
($message = "User: $in{'username'} deleted.") :
($message = "Unable to find userid: $in{'username'} in password file.");
last CASE;
};
# If we have a username, and the admin didn't press inquire, then
# we are updating a user.
($in{'username'} && !$in{'inquire'}) and do {
open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
@lines = <PASS>;
close PASS;

open (PASS, ">$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) {
flock(PASS, 2) or &cgierr("unable to get exclusive lock on $auth_pw_file.\nReason: $!");
}
my $found = 0;
foreach $line (@lines) {
if ($line =~ /^$in{'username'}:/) {
my $password = (split (/:/, $line))[1];
unless ($password eq $in{'password'}) {
my @salt_chars = ('A' .. 'Z', 0 .. 9, 'a' .. 'z', '.', '/');
my $salt = join '', @salt_chars[rand 64, rand 64];
$password = crypt($in{'password'}, $salt);
}
print PASS "$in{'username'}:$in{'password'}:$in{'per_view'}:$in{'per_add'}:$in{'per_del'}:$in{'per_mod'}:$in{'per_admin'}\n";
$found = 1;
}
else {
print PASS $line;
}
}
$in{'inquire'} = $in{'username'};
$found ?
($message = "User: $in{'username'} updated.") :
($message = "Unable to find user: '$in{'username'}' in the password file.");
last CASE;
};
};

# Now let's load the list of users.
open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
@lines = <PASS>;
close PASS;

if ($in{'userdetails'}) {
$db_script_link_url = "http://192.172.1.99/imvda/db.cgi?db=user&uid=$username&view_records=1";
}

# If we are inquiring, let's look for the specified user.
my (@data, $user_list, $perm, $password, $Phone, $Fax);
$user_list = qq~<select name="username"><option> </option>~;
LINE: foreach $line (@lines) {
$line =~ /^#/ and next LINE;
$line =~ /^\s*$/ and next LINE;
chomp $line;
@data = split (/:/, $line);
push (@users,$data[0]);
if ($in{'inquire'} and ($in{'username'} eq $data[0])) {
$password = $data[1];
$perm = qq|
View <input type=checkbox name="per_view" value="1" |;
($data[2] and $perm .= "CHECKED"); $perm .= qq|>
Add <input type=checkbox name="per_add" value="1" |;
($data[3] and $perm .= "CHECKED"); $perm .= qq|>
Delete <input type=checkbox name="per_del" value="1" |;
($data[4] and $perm .= "CHECKED"); $perm .= qq|>
Modify <input type=checkbox name="per_mod" value="1" |;
($data[5] and $perm .= "CHECKED"); $perm .= qq|>
Admin <input type=checkbox name="per_admin" value="1" |;
($data[6] and $perm .= "CHECKED"); $perm .= qq|>|;
}
}
foreach $user (sort @users) {
if ($in{'inquire'} and ($in{'username'} eq $user)) {
$user_list .= qq~<option value="$user" SELECTED>$user</option>\n~;
}
else {
$user_list .= qq~<option value="$user">$user</option>\n~;
}
}
$user_list .= "</select>";
# Build the permissions list if we haven't inquired in someone.
if (!$perm) {
$perm = qq|
View <input type=checkbox name="per_view" value="1" |; ($auth_default_perm[0] and $perm .= "CHECKED"); $perm .= qq|>
Add <input type=checkbox name="per_add" value="1" |; ($auth_default_perm[1] and $perm .= "CHECKED"); $perm .= qq|>
Delete <input type=checkbox name="per_del" value="1" |; ($auth_default_perm[2] and $perm .= "CHECKED"); $perm .= qq|>
Modify <input type=checkbox name="per_mod" value="1" |; ($auth_default_perm[3] and $perm .= "CHECKED"); $perm .= qq|>
Admin <input type=checkbox name="per_admin" value="1" |; ($auth_default_perm[4] and $perm .= "CHECKED"); $perm .= qq|>|;
}
&html_admin_display ($message, $user_list, $password, $perm);
}


Quote Reply
Re: Work Around / Admin - Help!! In reply to
I've just added the code in like this but I get an internal server error:

---
sub admin_display {
# --------------------------------------------------------
# Let's an admin add/update/remove users from the authorization file.
#
my ($message, @lines, $line);

# Do we have anything to do?
CASE: {
# If we've been passed in new_username, then we are adding a new user. Do
# some basic error checking and then add him into the password file.
$in{'new_username'} and do {
unless ((length($in{'new_username'}) >= 3) and (length($in{'new_username'}) <= 30) and ($in{'new_username'} =~ /^[a-zA-Z0-9]+$/)) {
$message = "Invalid username: $in{'new_username'}. Must only contain letters and numbers and be less then 12 and greater then 3 characters.";
last CASE;
}
unless ((length($in{'password'}) >= 3) and (length($in{'password'}) <= 30)) {
$message = "Invalid password: '$in{'password'}'. Must be less then 12 and greater then 3 characters.";
last CASE;
}
open (PASS, ">>$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) {
flock(PASS, 2) or &cgierr("unable to get exclusive lock on $auth_pw_file.\nReason: $!");
}
my @salt_chars = ('A' .. 'Z', 0 .. 9, 'a' .. 'z', '.', '/');
my $salt = join '', @salt_chars[rand 64, rand 64];
my $encrypted = crypt($in{'password'}, $salt);
print PASS "$in{'new_username'}:$in{'password'}:$in{'per_view'}:$in{'per_add'}:$in{'per_del'}:$in{'per_mod'}:$in{'per_admin'}\n";
close PASS;
$message = "User: $in{'new_username'} created.";
last CASE;
};
# If we've been passed in delete, then we are removing a user. Check
# to make sure a user was selected then try and remove him.
$in{'delete'} and do {
unless ($in{'username'}) {
$message = "No username selected to delete.";
last CASE;
}
open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1) }
@lines = <PASS>;
close PASS;

open (PASS, ">$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) {
flock(PASS, 2) or &cgierr("unable to get exclusive lock on $auth_pw_file.\nReason: $!");
}
my $found = 0;
foreach $line (@lines) {
($line =~ /^$in{'username'}:/) ?
($found = 1) :
print PASS $line;
}
close PASS;
$found ?
($message = "User: $in{'username'} deleted.") :
($message = "Unable to find userid: $in{'username'} in password file.");
last CASE;
};
# If we have a username, and the admin didn't press inquire, then
# we are updating a user.
($in{'username'} && !$in{'inquire'}) and do {
open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
@lines = <PASS>;
close PASS;

open (PASS, ">$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) {
flock(PASS, 2) or &cgierr("unable to get exclusive lock on $auth_pw_file.\nReason: $!");
}
my $found = 0;
foreach $line (@lines) {
if ($line =~ /^$in{'username'}:/) {
my $password = (split (/:/, $line))[1];
unless ($password eq $in{'password'}) {
my @salt_chars = ('A' .. 'Z', 0 .. 9, 'a' .. 'z', '.', '/');
my $salt = join '', @salt_chars[rand 64, rand 64];
$password = crypt($in{'password'}, $salt);
}
print PASS "$in{'username'}:$in{'password'}:$in{'per_view'}:$in{'per_add'}:$in{'per_del'}:$in{'per_mod'}:$in{'per_admin'}\n";
$found = 1;
}
else {
print PASS $line;
}
}
$in{'inquire'} = $in{'username'};
$found ?
($message = "User: $in{'username'} updated.") :
($message = "Unable to find user: '$in{'username'}' in the password file.");
last CASE;
};
};

# Now let's load the list of users.
open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
@lines = <PASS>;
close PASS;

if ($in{'userdetails'}) {
$db_script_link_url = "http://192.172.1.99/imvda/db.cgi?db=user&uid=$username&view_records=1";
}

# If we are inquiring, let's look for the specified user.
my (@data, $user_list, $perm, $password, $Phone, $Fax);
$user_list = qq~<select name="username"><option> </option>~;
LINE: foreach $line (@lines) {
$line =~ /^#/ and next LINE;
$line =~ /^\s*$/ and next LINE;
chomp $line;
@data = split (/:/, $line);
push (@users,$data[0]);
if ($in{'inquire'} and ($in{'username'} eq $data[0])) {
$password = $data[1];
$perm = qq|
View <input type=checkbox name="per_view" value="1" |;
($data[2] and $perm .= "CHECKED"); $perm .= qq|>
Add <input type=checkbox name="per_add" value="1" |;
($data[3] and $perm .= "CHECKED"); $perm .= qq|>
Delete <input type=checkbox name="per_del" value="1" |;
($data[4] and $perm .= "CHECKED"); $perm .= qq|>
Modify <input type=checkbox name="per_mod" value="1" |;
($data[5] and $perm .= "CHECKED"); $perm .= qq|>
Admin <input type=checkbox name="per_admin" value="1" |;
($data[6] and $perm .= "CHECKED"); $perm .= qq|>|;
open (PASS, "<users.cfg") or &cgierr ("unable to open: users.cfg.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
my @user_data = <PASS>;
close PASS;
foreach $line (@user_data) {
@user_info = split(/\|/, $line);
last if ($user_info[1] eq $password);

}

$Phone = $user_info[7];
$Fax = $user_info[8];

}
foreach $user (sort @users) {
if ($in{'inquire'} and ($in{'username'} eq $user)) {
$user_list .= qq~<option value="$user" SELECTED>$user</option>\n~;
}
else {
$user_list .= qq~<option value="$user">$user</option>\n~;
}
}
$user_list .= "</select>";
# Build the permissions list if we haven't inquired in someone.
if (!$perm) {
$perm = qq|
View <input type=checkbox name="per_view" value="1" |; ($auth_default_perm[0] and $perm .= "CHECKED"); $perm .= qq|>
Add <input type=checkbox name="per_add" value="1" |; ($auth_default_perm[1] and $perm .= "CHECKED"); $perm .= qq|>
Delete <input type=checkbox name="per_del" value="1" |; ($auth_default_perm[2] and $perm .= "CHECKED"); $perm .= qq|>
Modify <input type=checkbox name="per_mod" value="1" |; ($auth_default_perm[3] and $perm .= "CHECKED"); $perm .= qq|>
Admin <input type=checkbox name="per_admin" value="1" |; ($auth_default_perm[4] and $perm .= "CHECKED"); $perm .= qq|>|;
}
&html_admin_display ($message, $user_list, $password, $perm, $Phone, $Fax);
}


Quote Reply
Re: Work Around / Admin - Help!! In reply to
Alright its all working now. The reason I was getting an internal server error because I was missing a right "}" and also you had "users.cfg" instead of "user.db". Once I changed that it worked like a dream.

Thanks so much for your help. You rock Mark!!!! :)

Quote Reply
Re: Work Around / Admin - Help!! In reply to
Hmm... It's working with 2 fields but if I add anymore it won't display them. Why would it be doing this? Here is the code again:

sub admin_display {
# --------------------------------------------------------
# Let's an admin add/update/remove users from the authorization file.
#
my ($message, @lines, $line);

# Do we have anything to do?
CASE: {
# If we've been passed in new_username, then we are adding a new user. Do
# some basic error checking and then add him into the password file.
$in{'new_username'} and do {
unless ((length($in{'new_username'}) >= 3) and (length($in{'new_username'}) <= 30) and ($in{'new_username'} =~ /^[a-zA-Z0-9]+$/)) {
$message = "Invalid username: $in{'new_username'}. Must only contain letters and numbers and be less then 12 and greater then 3 characters.";
last CASE;
}
unless ((length($in{'password'}) >= 3) and (length($in{'password'}) <= 30)) {
$message = "Invalid password: '$in{'password'}'. Must be less then 12 and greater then 3 characters.";
last CASE;
}
open (PASS, ">>$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) {
flock(PASS, 2) or &cgierr("unable to get exclusive lock on $auth_pw_file.\nReason: $!");
}
my @salt_chars = ('A' .. 'Z', 0 .. 9, 'a' .. 'z', '.', '/');
my $salt = join '', @salt_chars[rand 64, rand 64];
my $encrypted = crypt($in{'password'}, $salt);
print PASS "$in{'new_username'}:$in{'password'}:$in{'per_view'}:$in{'per_add'}:$in{'per_del'}:$in{'per_mod'}:$in{'per_admin'}\n";
close PASS;
$message = "User: $in{'new_username'} created.";
last CASE;
};
# If we've been passed in delete, then we are removing a user. Check
# to make sure a user was selected then try and remove him.
$in{'delete'} and do {
unless ($in{'username'}) {
$message = "No username selected to delete.";
last CASE;
}
open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1) }
@lines = <PASS>;
close PASS;

open (PASS, ">$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) {
flock(PASS, 2) or &cgierr("unable to get exclusive lock on $auth_pw_file.\nReason: $!");
}
my $found = 0;
foreach $line (@lines) {
($line =~ /^$in{'username'}:/) ?
($found = 1) :
print PASS $line;
}
close PASS;
$found ?
($message = "User: $in{'username'} deleted.") :
($message = "Unable to find userid: $in{'username'} in password file.");
last CASE;
};
# If we have a username, and the admin didn't press inquire, then
# we are updating a user.
($in{'username'} && !$in{'inquire'}) and do {
open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
@lines = <PASS>;
close PASS;

open (PASS, ">$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) {
flock(PASS, 2) or &cgierr("unable to get exclusive lock on $auth_pw_file.\nReason: $!");
}
my $found = 0;
foreach $line (@lines) {
if ($line =~ /^$in{'username'}:/) {
my $password = (split (/:/, $line))[1];
unless ($password eq $in{'password'}) {
my @salt_chars = ('A' .. 'Z', 0 .. 9, 'a' .. 'z', '.', '/');
my $salt = join '', @salt_chars[rand 64, rand 64];
$password = crypt($in{'password'}, $salt);
}
print PASS "$in{'username'}:$in{'password'}:$in{'per_view'}:$in{'per_add'}:$in{'per_del'}:$in{'per_mod'}:$in{'per_admin'}\n";
$found = 1;
}
else {
print PASS $line;
}
}
$in{'inquire'} = $in{'username'};
$found ?
($message = "User: $in{'username'} updated.") :
($message = "Unable to find user: '$in{'username'}' in the password file.");
last CASE;
};
};

# Now let's load the list of users.
open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
@lines = <PASS>;
close PASS;

if ($in{'userdetails'}) {
$db_script_link_url = "http://192.172.1.99/imvda/db.cgi?db=user&uid=$username&view_records=1";
}

# If we are inquiring, let's look for the specified user.
my (@data, $user_list, $perm, $password, $CompanyName, $PhysicalAddress, $Region, $Phone, $Fax, $CellPhone, $Email, $Website);
$user_list = qq~<select name="username"><option> </option>~;
LINE: foreach $line (@lines) {
$line =~ /^#/ and next LINE;
$line =~ /^\s*$/ and next LINE;
chomp $line;
@data = split (/:/, $line);
push (@users,$data[0]);
if ($in{'inquire'} and ($in{'username'} eq $data[0])) {
$password = $data[1];
$perm = qq|
View <input type=checkbox name="per_view" value="1" |;
($data[2] and $perm .= "CHECKED"); $perm .= qq|>
Add <input type=checkbox name="per_add" value="1" |;
($data[3] and $perm .= "CHECKED"); $perm .= qq|>
Delete <input type=checkbox name="per_del" value="1" |;
($data[4] and $perm .= "CHECKED"); $perm .= qq|>
Modify <input type=checkbox name="per_mod" value="1" |;
($data[5] and $perm .= "CHECKED"); $perm .= qq|>
Admin <input type=checkbox name="per_admin" value="1" |;
($data[6] and $perm .= "CHECKED"); $perm .= qq|>|;
open (PASS, "<user.db") or &cgierr ("unable to open: user.db.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
my @user_data = <PASS>;
close PASS;
foreach $line (@user_data) {
@user_info = split(/\|/, $line);
last if ($user_info[1] eq $password);

}

$CompanyName = $user_info[2];
$PhyscialAddress = $user_info[3];
$Region = $user_info[5];
$Phone = $user_info[7];
$Fax = $user_info[8];
$CellPhone = $user_info[9];
$Email = $user_info[10];
$Website = $user_info[11];

}
}
foreach $user (sort @users) {
if ($in{'inquire'} and ($in{'username'} eq $user)) {
$user_list .= qq~<option value="$user" SELECTED>$user</option>\n~;
}
else {
$user_list .= qq~<option value="$user">$user</option>\n~;
}
}
$user_list .= "</select>";
# Build the permissions list if we haven't inquired in someone.
if (!$perm) {
$perm = qq|
View <input type=checkbox name="per_view" value="1" |; ($auth_default_perm[0] and $perm .= "CHECKED"); $perm .= qq|>
Add <input type=checkbox name="per_add" value="1" |; ($auth_default_perm[1] and $perm .= "CHECKED"); $perm .= qq|>
Delete <input type=checkbox name="per_del" value="1" |; ($auth_default_perm[2] and $perm .= "CHECKED"); $perm .= qq|>
Modify <input type=checkbox name="per_mod" value="1" |; ($auth_default_perm[3] and $perm .= "CHECKED"); $perm .= qq|>
Admin <input type=checkbox name="per_admin" value="1" |; ($auth_default_perm[4] and $perm .= "CHECKED"); $perm .= qq|>|;
}
&html_admin_display ($message, $user_list, $password, $perm, $CompanyName, $PhysicalAddress, $Region, $Phone, $Fax, $CellPhone, $Email, $Website);
}

sub html_admin_display {
# --------------------------------------------------------
# The displays the list of current users.

my ($message, $user_list, $password, $permissions, $CompanyName, $PhysicalAddress, $Region, $Phone, $Fax, $CellPhone, $Email, $Website) = @_;


Quote Reply
Re: Work Around / Admin - Help!! In reply to
Ok its all working now with more than two records. Don't know what happened before.

Quote Reply
Re: Work Around / Admin - Help!! In reply to
One more thing though. The code below doesn't work. It's supposed to be a drop down list
of passwords instead of a drop down list of users usernames. It just has one long list
of "password" when that isn't even a users password. Any ideas?

foreach $user (sort @users) {
if ($in{'inquire'} and ($in{'username'} eq $data[1])) {
$user_list .= qq~<option value="$data[0]" SELECTED>$data[1]</option>\n~;
}
else {
$user_list .= qq~<option value="$data[0]">$data[1]</option>\n~;
}
}
$user_list .= "</select>";

> >