#!/usr/bin/perl $password = 'password'; ################################################## # for more info on the TOS please see the readme # ################################################## use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard); print "Content-type: text/html \n\n"; $input = new CGI; $new_admin_password = crypt($admin_password, "MM"); &do; ############################################################# ### DO THE NORMAL STUFF...LIKE LOADING THE HEADER, MENU ETC # ############################################################# sub do { ¶ms; # Load up the parameters &menu; # Get the menu code &rates; # Load ratings code &decide; # Decide what we need to do. } ####################################################################### ### ALL SUBS DONE NOW INTEGRATE INTO EACH OTHER, THE ABOVE 3 SHOULD ## ### HAVE LOADED EVERYTHING WE WILL NEED ############################### ####################################################################### # Menu sub to load the menu HTML sub menu { $menu = qq~
Setup .htaccess
Add User
Modify User
Delete User
Help
View All Users
~; } # End menu sub routine # Define the HTMLfor the rating boxes that appear on the right of every main page. sub rates { $ratings = qq~
Rate Our Program
at HotScripts.com
 

Rate Our Program
at CGI-Resources.com

 

Rate Our Program
at TheCGISite

~; } # End the rate HTML code sub # Get all the paramaters that should exist with the script. Also include the encrypting of the files sub params { $admin_username = $input->param('admin_username'); # admin username entered when creating the original .htacess files $admin_password = $input->param('admin_password'); # admin password entered when creating the original .htaccess file $crypted_admin_password = crypt($admin_password, "MM"); # encrypted password from admin password entered when creating the .htaccess files. $enc_password = crypt($password, "MM"); # The origianl password set at the top of this file, now encxrypted for comparrison to other passwords entered. $path = $input->param('root'); # The path they enter WHEN creating original .HTACCESS files. $title = $input->param('title'); # The title for the first settings up of the .htaccess file $action = $input->param('action'); # Tells us what we need to do :) $iscobalt = $input->param('cobalt'); # Tells us if they are on a coablt server, so we can add the extra lines where needed to support .htaccess on them! $modusername = $input->param('usernamemodify'); # Username when modifying users passwords $modpassword = $input->param('passwordmodify'); # password for when modifying usernames $delusername = $input->param('usernamedelete'); # The username we look for if we are deleting one! if ($input->param('uidpass') eq $enc_password) { $sent_enc_pass = $input->param('uidpass'); } else { $sent_enc_pass = crypt($input->param('uidpass'), "MM"); } } # The error sub incase we encounter unexpected errors sub error { $error = shift; &error_template; } # Now we need to decide what we want to do. sub decide { if ($sent_enc_pass eq "") { &password_entry; exit; } else { &login_ok; exit; } } sub password_entry { &password_welcome; } # This is the sub where we have successfully logged in with. Now we show them the welcome stuff etc and decide what we want to do. sub login_ok { if ($action eq "") { &password_welcome; } elsif ($action eq "login") { &welcome_html; } elsif ($action eq "setuphtaccess") { &setup_htaccess_html; } elsif ($action eq "writehtaccess") { &write_htaccess; } # Write the .htacess files and .htpasswd for first time! elsif ($action eq "adduser") { &add_user; } # Sub to show the HTMlfor it! elsif ($action eq "send_add_user") { &write_add_user; } # Sub for creating a new user (writing files and verifying) elsif ($action eq "modifyuser") { &modify_user_html; } # sub to print out the HTMl for the modifying of users elsif ($action eq "modify_user_write") { &write_modified_username; } # write the new passwordfor a selected username elsif ($action eq "deleteuser") { &delete_user_html; } # Goto the HTMl for deleting a username... elsif ($action eq "delete_user_write") { &delete_username; } # Sub to delete the username and do the checking etc. elsif ($action eq "help") { &redirect_to_help; } # sub that will redirect them to help.ace-installer.com elsif ($action eq "allusers") { &allusers; } else { &error("You didn't specify a correct action!"); } # if there is an action that does not exist we use this sub! } # end the login_ok sub ####################### ## BELOW HERE IS WHERE THE TEMPLATES ARE DEFINED! ###################### # The main login page sub password_welcome { print qq~ Ace Password (.htaccess Generator)

-
Ace Password v3
-

MENU

You can't see any
options yet as you
are not logged in!

 

 

 

Please enter your admin password to gain access to the control panel.

 

 

Rate This Script

$ratings

Ace Password V3 by Ace Installer. 1999-2001.

~; } # end the welcome template # The error template sub error_template { print qq~ Ace Password (.htaccess Generator)

-
Ace Password v3
-

MENU

$menu

 

 

 

There was an error. It was:

$error

Rate This Script

$ratings

 

 

 

 

 

 

Ace Password V3 by Ace Installer. 1999-2001.

~; exit; } # end the error subs HTML #HTML to show them when they have successfully logged in! sub welcome_html { if ($sent_enc_pass ne $enc_password) { &error("The password you entered was not correct!"); exit; } print qq~ Ace Password (.htaccess Generator)

-
Ace Password v3
-

MENU

$menu

 

 

 

Welcome to the Ace Password Admin Center. Thank you for choosing our script to manage your users and password. This script will enable you to create, manage and delete users from your .htpasswd file.

Please select an option from the left hand menu to decide what to do.

Rate This Script

$ratings

 

 

 

 

 

 

Ace Password V3 by Ace Installer. 1999-2001.

~; } # End the HTML template for when they have successfully logged in! sub setup_htaccess_html { if ($sent_enc_pass ne $enc_password) { &error("The password you entered was not correct!"); exit; } print qq~ Ace Password (.htaccess Generator)

-
Ace Password v3
-

MENU

$menu

 

 

 

Please complete the information below and click on the submit option!

 

Path for generated file :  
NOTE: This needs no / at the end of it. What is in the box MAY NOT be your path! Please double check with your host.

Are you on a cobalt server? (tick if yes) 

Area Title :

-----------------------------

Admin Username :

Admin Password :

Rate This Script

$ratings

 

 

 

 

 

 

Ace Password V3 by Ace Installer. 1999-2001.

~; } # End the HTML for the setup_htaccess_html sub! # sub for HTML to be shown with the sub add_user sub add_user_html { print qq~ Ace Password (.htaccess Generator) - .htaccess and .htpasswd files written successfully!

-
Ace Password v3
-

MENU

$menu

 

 

 

To create a new username please complete the below form;

Username :

Password :

 

Rate This Script

$ratings

 

 

 

 

 

 

Ace Password V3 by Ace Installer. 1999-2001.

~; } # End sub that shows HTML for adding users.... # Sub for HTML to be shown when the.htaccess files were made properly sub htaccess_creation_successful_html { print qq~ Ace Password (.htaccess Generator) - .htaccess and .htpasswd files written successfully!

-
Ace Password v3
-

MENU

$menu

 

 

 

The files were written successfully. 

The username $admin_username was also successfully added. 

Rate This Script

$ratings

 

 

 

 

 

 

Ace Password V3 by Ace Installer. 1999-2001.

~; } # End HTMLto be shown when .htaccess files have been made successfully. # HTMl to show when they want to edit a username.... sub modify_user_html { print qq~ Ace Password (.htaccess Generator)

-
Ace Password v3
-

MENU

$menu

 

 

 

To modify a usernames password please enter the username and the new password you want for it!

Existing Username :

 New Password :   

 

Rate This Script

$ratings

 

 

 

 

 

 

Ace Password V3 by Ace Installer. 1999-2001.

~; } # End sub to show HTMl for modifying a username... # sub for showing HTML to delete a username with sub delete_user_html { print qq~ Ace Password (.htaccess Generator)

-
Ace Password v3
-

MENU

$menu

 

 

 

To delete a username, please enter the username in the box, and then click the delete button. This is not a reversible function, so you will need to recreate the username manually if you do again decide you want it still!

Existing Username :

 

Rate This Script

$ratings

 

 

 

 

 

 

Ace Password V3 by Ace Installer. 1999-2001.

~; } ############################################ # END SUBS FOR TEMPLATE DEFINING! ########## ############################################ # Code needed to write the .htacess file! sub write_htaccess { if ($sent_enc_pass ne $enc_password) { &error("The password you entered was not correct!"); exit; } if ($iscobalt ne "") { $cobaltcode = "AuthPAM_enabled off \n"; } else { $cobaltcode = ""; } if ($admin_username eq "") { &error("You need to specify an admin username!"); } if ($path eq "") { &error("You need to specify a path!"); } if ($title eq "") { &error("There was no title specified!"); } open(WRITEHTACCESS, ">$path/.htaccess") || die &error("There was an error writing to .htaccess. $path/.htaccess. Reason : $!"); print WRITEHTACCESS "AuthUserFile $path/.htpasswd \n"; print WRITEHTACCESS "AuthName \"$title\"\n"; print WRITEHTACCESS "AuthType Basic \n"; print WRITEHTACCESS $cobaltcode; print WRITEHTACCESS "require valid-user \n"; close (WRITEHTACCESS) || die &error("Unable to close .htaccess. Reason: $!"); open(WRITEHTPASSWD, ">$path/.htpasswd") || die &error("There was an error writing to .htaccess. Reason : $!"); print WRITEHTPASSWD "$admin_username:$crypted_admin_password\n"; close (WRITEHTPASSWD) || die &error("Unable to close .htaccess. $path/.htpasswd. Reason: $!"); &htaccess_creation_successful_html; } # End htacecss sub creation! # Sub that adds new users... sub add_user { if ($sent_enc_pass ne $enc_password) { &error("The password you entered was not correct!"); exit; } &add_user_html; } # This is where we verify the username etc and write it to the file. We use the same varialbe names as we did when we set up the original .htaccess sub write_add_user { if ($admin_username eq "") { &error("You need to specify a username to write to the file!"); } open (CHECKUSERS, ".htpasswd") || die &error("Unable to open .htpasswd for checking. Reason: $!"); @checklist = ; close(CHECKUSERS) || die &error("Unable to close .htpasswd file. Reason: $!"); # Now we have all the info in an array, we need to go through, split the lines and varialbes and see if another one already exists! foreach $line (@checklist) { my ($username, $password) = split (/:/, $line); if ($admin_username eq $username) { &error("Username already exists!"); } } # end the foreach loop! open (ADDUSERS, ">>.htpasswd") || die &error("Unable to open .htpasswd for addition. Reason: $!"); print ADDUSERS "$admin_username:$crypted_admin_password\n"; close(ADDUSERS) || die &error("Unable to close .htpasswd file. Reason: $!"); print "Username $admin_username added!"; } # Sub for modifying the usernames sub write_modified_username { open(MOD, ".htpasswd") || die &error("Unable to open .htpasswd file. Reason : $!"); @check = ; close(MOD) || die &error("Unable to close .htpasswd. Reason: $!"); foreach $line (@check) { my ($username, $password) = split(/:/, $line); if ($username eq $modusername) { $status = "ok"; last; } else { $status = "not found"; } } # end foreach loop if ($status eq "not found") { &error("Username not found! You can only edit an existing username!"); } # if they are not redirected to the error sub then we need to do something down here (as it means the username does exist! $new_password = crypt($modpassword, "MM"); open(MODIFY, ">.htpasswd") || die &error("Unable to open .htpasswd. Reason: $!"); # first of all we need to open the file # now we need a foreach loop to go through and if it finds the line, upload the new info instead! foreach $line (@check) { my ($username, $password) = split(/:/, $line); if ($username eq $modusername) { print MODIFY "$username:$new_password"; } else { print MODIFY "$username:$password"; } } close(MODIFY) || die &error("Unable to close .htpasswd. Reason : $!"); print "Done"; } # end of the modifying sub # the sub that will delete usernames from the file! sub delete_username { open(DEL, ".htpasswd") || die &error("Unable to open .htpasswd file. Reason : $!"); @check = ; close(DEL) || die &error("Unable to close .htpasswd. Reason: $!"); foreach $line (@check) { my ($username, $password) = split(/:/, $line); if ($username eq $delusername) { $status = "ok"; last; } else { $status = "not found"; } } # end foreach loop if ($status eq "not found") { &error("Username not found! You can only edit an existing username!"); } # If we get to here then the username exits, so we need to do the foreach loop to add all usernames and possword EXCEPT this one! open(DEL, ">.htpasswd") || die &error("Unable to open .htpassd. Reason: $!"); foreach $line (@check) { my ($username, $password) = split(/:/, $line); if ($username eq $delusername) { } else { print DEL "$username:$password"; } } # end foreach loop close(DEL) || &error("Unable to close .htpasswd after username deletion. Reason:L $!"); print "Username $delusername was deleted successfully!"; } # end the delete sub sub allusers # Sub to show all users.... { if ($sent_enc_pass ne $enc_password) { &error("The password you entered was not correct!"); exit; } open(SHOW, ".htpasswd") || die &error("Unable to open .htpasswd file. Reason : $!"); @check = ; close(SHOW) || die &error("Unable to close .htpasswd. Reason: $!"); foreach $line (@check) { my ($username, $password) = split(/:/, $line); print "$username...
"; } }